mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
feat(flow): FlowableUtils添加getFlowParamMap方法统一处理流程发起人参数
- BpmOaLeaveEntity继承BizFlowBaseDto以复用流程基础字段 - 新增BizFlowBaseDto作为流程基础数据传输对象 - - 优化BpmOaLeaveServiceImpl流程启动逻辑,使用工具类简化代码
This commit is contained in:
1 parent
ed6138b566
commit
883293cc2a
4 files changed
+834
-803
No files matched your search
@@ -0,0 +1,31 @@
|
||||
package com.pig4cloud.pigx.flow.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 自定义业务流基础数据传输对象
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2025/10/16
|
||||
*/
|
||||
@Data
|
||||
public class BizFlowBaseDto {
|
||||
|
||||
/**
|
||||
* 流程实例的编号
|
||||
*/
|
||||
@Schema(description = "流程实例的编号")
|
||||
private String processInstanceId;
|
||||
|
||||
/**
|
||||
* 流程参数 (用于存储用户选择的审批人等信息)
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "流程参数(审批人信息)")
|
||||
private Map<String, Object> flowParamMap = new HashMap<>();
|
||||
}
|
||||
+80
-83
@@ -2,6 +2,7 @@ package com.pig4cloud.pigx.flow.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.pig4cloud.pigx.common.core.util.TenantTable;
|
||||
import com.pig4cloud.pigx.flow.dto.BizFlowBaseDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -15,103 +16,99 @@ import java.time.LocalDateTime;
|
||||
@TenantTable
|
||||
@TableName("bpm_oa_leave")
|
||||
@Schema(description = "请假表单")
|
||||
public class BpmOaLeaveEntity {
|
||||
public class BpmOaLeaveEntity extends BizFlowBaseDto {
|
||||
|
||||
/**
|
||||
* 请假表单主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "请假表单主键")
|
||||
private Long id;
|
||||
/**
|
||||
* 请假表单主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "请假表单主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 申请人的用户编号
|
||||
*/
|
||||
@Schema(description = "申请人的用户编号")
|
||||
private String username;
|
||||
/**
|
||||
* 申请人的用户编号
|
||||
*/
|
||||
@Schema(description = "申请人的用户编号")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 请假类型
|
||||
*/
|
||||
@Schema(description = "请假类型")
|
||||
private Integer leaveType;
|
||||
/**
|
||||
* 请假类型
|
||||
*/
|
||||
@Schema(description = "请假类型")
|
||||
private Integer leaveType;
|
||||
|
||||
/**
|
||||
* 请假原因
|
||||
*/
|
||||
@Schema(description = "请假原因")
|
||||
private String leaveReason;
|
||||
/**
|
||||
* 请假原因
|
||||
*/
|
||||
@Schema(description = "请假原因")
|
||||
private String leaveReason;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
@Schema(description = "开始时间")
|
||||
private LocalDateTime startTime;
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
@Schema(description = "开始时间")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
@Schema(description = "结束时间")
|
||||
private LocalDateTime endTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
@Schema(description = "结束时间")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 请假天数
|
||||
*/
|
||||
@Schema(description = "请假天数")
|
||||
private Integer leaveDay;
|
||||
/**
|
||||
* 请假天数
|
||||
*/
|
||||
@Schema(description = "请假天数")
|
||||
private Integer leaveDay;
|
||||
|
||||
/**
|
||||
* 请假结果
|
||||
*/
|
||||
@Schema(description = "请假结果")
|
||||
private Integer leaveStatus;
|
||||
/**
|
||||
* 请假结果
|
||||
*/
|
||||
@Schema(description = "请假结果")
|
||||
private Integer leaveStatus;
|
||||
|
||||
/**
|
||||
* 流程实例的编号
|
||||
*/
|
||||
@Schema(description = "流程实例的编号")
|
||||
private String processInstanceId;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建者")
|
||||
private String createBy;
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建者")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新者")
|
||||
private String updateBy;
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新者")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "是否删除")
|
||||
private String delFlag;
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "是否删除")
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
@Schema(description = "租户编号")
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
@Schema(description = "租户编号")
|
||||
private Long tenantId;
|
||||
|
||||
}
|
||||
+44
-53
@@ -1,23 +1,18 @@
|
||||
package com.pig4cloud.pigx.flow.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import com.pig4cloud.pigx.flow.api.feign.RemoteFlowApiFlowService;
|
||||
import com.pig4cloud.pigx.flow.constant.NodeUserTypeEnum;
|
||||
import com.pig4cloud.pigx.flow.dto.ProcessInstanceParamDto;
|
||||
import com.pig4cloud.pigx.flow.entity.BpmOaLeaveEntity;
|
||||
import com.pig4cloud.pigx.flow.mapper.BpmOaLeaveMapper;
|
||||
import com.pig4cloud.pigx.flow.service.BpmOaLeaveService;
|
||||
import com.pig4cloud.pigx.flow.support.utils.FlowableUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 请假表单
|
||||
*
|
||||
@@ -27,57 +22,53 @@ import java.util.Map;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BpmOaLeaveServiceImpl extends ServiceImpl<BpmOaLeaveMapper, BpmOaLeaveEntity>
|
||||
implements BpmOaLeaveService {
|
||||
implements BpmOaLeaveService {
|
||||
|
||||
private final RemoteFlowApiFlowService flowApiFlowService;
|
||||
private final RemoteFlowApiFlowService flowApiFlowService;
|
||||
|
||||
/**
|
||||
* 获取监听的流程定义Key
|
||||
* @return 监听的流程定义Key
|
||||
*/
|
||||
@Override
|
||||
public String getFlowId() {
|
||||
return "LEAVE";
|
||||
}
|
||||
/**
|
||||
* 获取监听的流程定义Key
|
||||
*
|
||||
* @return 监听的流程定义Key
|
||||
*/
|
||||
@Override
|
||||
public String getFlowId() {
|
||||
return "LEAVE";
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理状态事件
|
||||
* @param paramDto 流程节点记录分配用户参数DTO
|
||||
*/
|
||||
@Override
|
||||
public void handleStatusEvent(ProcessInstanceParamDto paramDto) {
|
||||
this.update(Wrappers.<BpmOaLeaveEntity>lambdaUpdate()
|
||||
.set(BpmOaLeaveEntity::getLeaveStatus, paramDto.getStatus())
|
||||
.eq(BpmOaLeaveEntity::getProcessInstanceId, paramDto.getProcessInstanceId()));
|
||||
}
|
||||
/**
|
||||
* 处理状态事件
|
||||
*
|
||||
* @param paramDto 流程节点记录分配用户参数DTO
|
||||
*/
|
||||
@Override
|
||||
public void handleStatusEvent(ProcessInstanceParamDto paramDto) {
|
||||
this.update(Wrappers.<BpmOaLeaveEntity>lambdaUpdate()
|
||||
.set(BpmOaLeaveEntity::getLeaveStatus, paramDto.getStatus())
|
||||
.eq(BpmOaLeaveEntity::getProcessInstanceId, paramDto.getProcessInstanceId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存并启动请假流程
|
||||
* @param bpmOaLeave 请假实体对象
|
||||
* @return 保存后的请假实体对象
|
||||
*/
|
||||
@Override
|
||||
public BpmOaLeaveEntity saveAndStartProcess(BpmOaLeaveEntity bpmOaLeave) {
|
||||
bpmOaLeave.setUsername(SecurityUtils.getUser().getUsername());
|
||||
baseMapper.insert(bpmOaLeave);
|
||||
// 获取流程配置详情
|
||||
ProcessInstanceParamDto processInstanceParamDto = new ProcessInstanceParamDto();
|
||||
processInstanceParamDto.setFlowId(this.getFlowId());
|
||||
processInstanceParamDto.setStartUserId(String.valueOf(SecurityUtils.getUser().getId()));
|
||||
/**
|
||||
* 保存并启动请假流程
|
||||
*
|
||||
* @param bpmOaLeave 请假实体对象
|
||||
* @return 保存后的请假实体对象
|
||||
*/
|
||||
@Override
|
||||
public BpmOaLeaveEntity saveAndStartProcess(BpmOaLeaveEntity bpmOaLeave) {
|
||||
bpmOaLeave.setUsername(SecurityUtils.getUser().getUsername());
|
||||
baseMapper.insert(bpmOaLeave);
|
||||
// 获取流程配置详情
|
||||
ProcessInstanceParamDto processInstanceParamDto = new ProcessInstanceParamDto();
|
||||
// 发起哪个流程 (LEAVE)
|
||||
processInstanceParamDto.setFlowId(this.getFlowId());
|
||||
// 设置流程审批人/发起人信息
|
||||
processInstanceParamDto.setParamMap(FlowableUtils.getFlowParamMap(bpmOaLeave));
|
||||
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
// 设置发起人
|
||||
Dict rootUser = Dict.create()
|
||||
.set("id", processInstanceParamDto.getStartUserId())
|
||||
.set("name", SecurityUtils.getUser().getUsername())
|
||||
.set("type", NodeUserTypeEnum.USER.getKey());
|
||||
paramMap.put("root", CollUtil.newArrayList(rootUser));
|
||||
processInstanceParamDto.setParamMap(paramMap);
|
||||
|
||||
R<String> stringR = flowApiFlowService.startProcessInstance(processInstanceParamDto);
|
||||
bpmOaLeave.setProcessInstanceId(stringR.getData());
|
||||
baseMapper.updateById(bpmOaLeave);
|
||||
return bpmOaLeave;
|
||||
}
|
||||
R<String> stringR = flowApiFlowService.startProcessInstance(processInstanceParamDto);
|
||||
bpmOaLeave.setProcessInstanceId(stringR.getData());
|
||||
baseMapper.updateById(bpmOaLeave);
|
||||
return bpmOaLeave;
|
||||
}
|
||||
|
||||
}
|
||||
+679
-667
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user