feat: 企标已封存启用流程

This commit is contained in:
2023-11-09 17:48:30 +08:00
parent ada7cfc555
commit 1e6b94273d
5 changed files with 33 additions and 100 deletions
@@ -77,7 +77,7 @@ public class ESEnableController {
@ApiOperation(value="企标启用发起流程-同意", notes="企标启用发起流程-同意")
@PostMapping("/agree")
public Result<?> agree(@RequestBody ESEnableDataVO enableData) {
enableService.approvalInitChange(enableData, true);
enableService.approval(enableData, true);
return Result.OK();
}
@@ -90,7 +90,7 @@ public class ESEnableController {
@ApiOperation(value="企标启用发起流程-驳回", notes="企标启用发起流程-驳回")
@PostMapping("/reject")
public Result<?> reject(@RequestBody ESEnableDataVO enableData) {
enableService.approvalInitChange(enableData, false);
enableService.approval(enableData, false);
return Result.OK();
}
@@ -7,6 +7,7 @@ import com.jero.modules.activiti.process.esInitChange.entity.ProcessEsInitChange
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @author: Mzaxd
@@ -22,5 +23,5 @@ public class ESEnableDataVO {
ProcessEsEnable data;
@JsonProperty("flowUser")
ESEnableFlowUserVO flowUser;
Map<String, Object> flowUser;
}
@@ -1,34 +0,0 @@
package com.jero.modules.activiti.process.esEnable.entity.vo;
import com.jero.common.aspect.annotation.Dict;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author: Mzaxd
* @Date: 2023/10/9 16:57
*/
@Data
public class ESEnableFlowUserVO {
// 创建人
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "realname")
@ApiModelProperty("创建人")
private String createUser;
// 相关人员
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "realname")
@ApiModelProperty("相关人员")
private String relatedUser;
// 创建人
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "realname")
@ApiModelProperty("起草人和会签人主管级领导")
private String leader;
// 标准化审批人
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "realname")
@ApiModelProperty("标准化审批人")
private String standardizationUser;
}
@@ -17,6 +17,6 @@ public interface ProcessEsEnableService extends IService<ProcessEsEnable> {
ESEnableDataVO getHandleData(String taskId);
void approvalInitChange(ESEnableDataVO enableData, boolean pass);
void approval(ESEnableDataVO enableData, boolean pass);
}
@@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.exception.JeroBootException;
import com.jero.modules.activiti.entity.ProcessAll;
import com.jero.modules.activiti.entity.ProcessNode;
import com.jero.modules.activiti.enums.ProcessTypeEnum;
import com.jero.modules.activiti.process.common.entity.CommonVO;
import com.jero.modules.activiti.process.common.entity.ProcessDraft;
@@ -16,12 +15,10 @@ import com.jero.modules.activiti.process.common.service.ActFlowCommonService;
import com.jero.modules.activiti.process.common.service.ProcessDraftService;
import com.jero.modules.activiti.process.esEnable.entity.ProcessEsEnable;
import com.jero.modules.activiti.process.esEnable.entity.vo.ESEnableDataVO;
import com.jero.modules.activiti.process.esEnable.entity.vo.ESEnableFlowUserVO;
import com.jero.modules.activiti.process.esEnable.service.ProcessEsEnableService;
import com.jero.modules.activiti.process.esEnable.mapper.ProcessEsEnableMapper;
import com.jero.modules.activiti.service.ProcessAllService;
import com.jero.modules.activiti.service.ProcessNodeLinkService;
import com.jero.modules.activiti.service.ProcessNodeService;
import com.jero.modules.sys.utils.UserUtils;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.RuntimeService;
@@ -31,7 +28,6 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author ThinkBook
@@ -56,9 +52,6 @@ public class ProcessEsEnableServiceImpl extends ServiceImpl<ProcessEsEnableMappe
@Resource
private ProcessNodeLinkService processNodeLinkService;
@Resource
private ProcessNodeService processNodeService;
@Resource
private RuntimeService runtimeService;
@@ -67,7 +60,7 @@ public class ProcessEsEnableServiceImpl extends ServiceImpl<ProcessEsEnableMappe
// 执行流程发起前的操作
this.startRunTask(enableData);
// 流程Key
String processDefinitionKey = ProcessType.ES_INIT_CHANGE.getProcessKey();
String processDefinitionKey = ProcessType.ES_ENABLE.getProcessKey();
// 当前用户Id
String userId = UserUtils.getUserId();
// 业务数据
@@ -75,16 +68,16 @@ public class ProcessEsEnableServiceImpl extends ServiceImpl<ProcessEsEnableMappe
// 通用数据
CommonVO common = enableData.getCommon();
// 人员数据
ESEnableFlowUserVO flowUser = enableData.getFlowUser();
Map<String, Object> variables = enableData.getFlowUser();
// 设置流程变量
Map<String, Object> variables = this.setVariables(flowUser);
Map<String, Object> actVariables = this.setVariables(variables);
// 启动流程
ProcessInstance processInstance = actFlowCommonService.startProcess(processDefinitionKey, variables);
ProcessInstance processInstance = actFlowCommonService.startProcess(processDefinitionKey, actVariables);
// 获取流程实例ID
String processDefinitionId = processInstance.getProcessDefinitionId();
String processInstanceId = processInstance.getId();
// 手动设置所有流程变量
actFlowCommonService.setProcessVariables(processInstanceId, variables);
actFlowCommonService.setProcessVariables(processInstanceId, actVariables);
// 自动完成第一个任务
actFlowCommonService.autoCompleteFirstTask(userId, processInstanceId, processDefinitionId, common);
// 设置流程实例Id
@@ -101,30 +94,29 @@ public class ProcessEsEnableServiceImpl extends ServiceImpl<ProcessEsEnableMappe
actFlowCommonService.updateProcessAll(processInstanceId, userId, prcName, prcMes, prcType, dueTime);
}
public Map<String, Object> setVariables(ESEnableFlowUserVO flowUser) {
boolean counterSign = StrUtil.isNotBlank(flowUser.getRelatedUser());
HashMap<String, Object> map = new HashMap<>(this.setUserVariables(flowUser));
actFlowCommonService.putIfNotNull(map, "counterSign", counterSign);
return map;
}
public Map<String, Object> setUserVariables(ESEnableFlowUserVO flowUser) {
HashMap<String, Object> map = new HashMap<>();
// 使用一个通用方法来只在不为空时添加键值对
actFlowCommonService.putIfNotNull(map, "createUser", flowUser.getCreateUser());
actFlowCommonService.putIfNotNull(map, "leader", flowUser.getLeader());
actFlowCommonService.putIfNotNull(map, "standardizationApprovalUser", flowUser.getStandardizationUser());
actFlowCommonService.putIfNotNull(map, "relatedUserList", Optional.ofNullable(flowUser.getRelatedUser()).map(s -> Arrays.asList(s.split(","))).orElse(null));
return map;
public Map<String, Object> setVariables(Map<String, Object> flowUser) {
Map<String, Object> actVariables = new HashMap<>();
if (flowUser.get("relatedUserList") == null || StrUtil.isBlank((String)flowUser.get("relatedUserList"))) {
actFlowCommonService.putIfNotNull(actVariables, "countersign", false);
} else {
actFlowCommonService.putIfNotNull(actVariables, "countersign", true);
String relatedUsers = (String) flowUser.get("relatedUserList");
// 将relatedUserList从逗号拼接转为List
List<String> relatedUserList = StrUtil.split(relatedUsers, ',');
actFlowCommonService.putIfNotNull(actVariables, "relatedUserList", relatedUserList);
}
for (Map.Entry<String, Object> entry : flowUser.entrySet()) {
String key = entry.getKey();
if (!key.equals("relatedUserList")) {
actVariables.put(key, entry.getValue());
}
}
return actVariables;
}
private Map<String, Object> getUserMap(Map<String, Object> variables) {
variables.remove("pass");
variables.remove("counterSign");
// 转成逗号拼接
variables.put("relatedUserList", Optional.ofNullable((List<String>) variables.get("relatedUserList"))
.map(list -> String.join(",", list))
.orElse(""));
variables.remove("countersign");
return variables;
}
@@ -189,49 +181,23 @@ public class ProcessEsEnableServiceImpl extends ServiceImpl<ProcessEsEnableMappe
lambdaQueryWrapper.eq(ProcessEsEnable::getDelFlag, YesOrNoEnum.NO.getValue());
ProcessEsEnable data = getOne(lambdaQueryWrapper);
enableData.setData(data);
// 选人组件内容填充
enableData.setFlowUser(this.getProcessUserInfo(processDefinitionId, processInstanceId));
return enableData;
}
private ESEnableFlowUserVO getProcessUserInfo(String processDefinitionId, String processInstanceId) {
List<ProcessNode> nodeList = processNodeService.getNodeList(processDefinitionId, processInstanceId);
ESEnableFlowUserVO flowUser = new ESEnableFlowUserVO();
Map<String, ProcessNode> userMap = nodeList.stream().collect(Collectors.toMap(ProcessNode::getVariableName, node -> node));
Optional.ofNullable(userMap.get("createUser")).ifPresent(node -> flowUser.setCreateUser(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("leader")).ifPresent(node -> flowUser.setLeader(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("standardizationUser")).ifPresent(node -> flowUser.setStandardizationUser(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("relatedUserList")).ifPresent(node -> flowUser.setRelatedUser(node.getLinkUserIds()));
return flowUser;
}
@Override
public void approvalInitChange(ESEnableDataVO enableData, boolean pass) {
public void approval(ESEnableDataVO enableData, boolean pass) {
String userId = UserUtils.getUserId();
CommonVO commonVO = enableData.getCommon();
ProcessEsEnable data = enableData.getData();
String taskId = commonVO.getTaskId();
if (StrUtil.isBlank(taskId) && !actFlowCommonService.taskExists(taskId)) {
throw new JeroBootException("taskId为空或任务不存在");
}
String processInstanceId = actFlowCommonService.getProcessInstanceIdByTaskId(taskId);
String processDefinitionId = actFlowCommonService.getProcessDefId(processInstanceId);
if (pass) {
if (data != null) {
saveOrUpdate(data);
ESEnableFlowUserVO flowUserInfoVO = enableData.getFlowUser();
Map<String, Object> variables = this.setVariables(flowUserInfoVO);
processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, this.getUserMap(variables));
actFlowCommonService.setProcessVariables(processInstanceId, variables);
}
runtimeService.setVariable(processInstanceId, "pass", true);
} else {
// 设置流程变量
runtimeService.setVariable(processInstanceId, "pass", false);
}
// 设置流程变量
runtimeService.setVariable(processInstanceId, "pass", pass);
// 更新审批表为完成,填充数据
actFlowCommonService.updateApprovalInfo(commonVO, taskId, pass);
//审批节点
// 审批节点
actFlowCommonService.completeTask(taskId, userId);
}
}