fix: 企标立项变更流程Bug

This commit is contained in:
2023-10-30 10:29:34 +08:00
parent 8ea75b9838
commit 5d39fe7043
7 changed files with 152 additions and 101 deletions
@@ -1,14 +1,13 @@
package com.jero.modules.activiti.process.common.service;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.modules.activiti.entity.ProcessAll;
import com.jero.modules.activiti.entity.ProcessApprovalRecord;
import com.jero.modules.activiti.entity.ProcessNode;
import com.jero.modules.activiti.enums.CommitFlagEnum;
import com.jero.modules.activiti.enums.FinishFlagEnum;
import com.jero.modules.activiti.process.common.entity.CommonVO;
import com.jero.modules.activiti.service.ProcessAllService;
import com.jero.modules.activiti.service.ProcessApprovalRecordService;
import com.jero.modules.activiti.service.ProcessNodeService;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
@@ -40,7 +39,7 @@ public class ActFlowCommonService {
private TaskService taskService;
@Resource
private ProcessNodeService processNodeService;
private ProcessAllService processAllService;
@Resource
private ProcessApprovalRecordService processApprovalRecordService;
@@ -63,8 +62,24 @@ public class ActFlowCommonService {
return processInstance;
}
/**
* 循环设置流程变量
* @param processInstanceId
* @param variables
*/
public void setProcessVariables(String processInstanceId, Map<String, Object> variables) {
for (Map.Entry<String, Object> entry : variables.entrySet()) {
runtimeService.setVariable(processInstanceId, entry.getKey(), entry.getValue());
}
}
/**
* 更新审批表为完成,填充数据
* @param commonVO
* @param taskId
* @param pass
*/
public void updateApprovalInfo(CommonVO commonVO, String taskId, boolean pass) {
//更新审批表为完成,填充数据
ProcessApprovalRecord approvalRecord = processApprovalRecordService.getToDoByTaskId(taskId);
approvalRecord.setCommitFlag(pass ? CommitFlagEnum.PASS.getValue() : CommitFlagEnum.REJECT.getValue());
approvalRecord.setCommitText(commonVO.getCommitText());
@@ -203,4 +218,21 @@ public class ActFlowCommonService {
throw new JeroBootException("未找到流程定义Id");
}
}
/**
* 更新流程主表
* @param processInstanceId
* @param userId
* @param prcName
* @param prcMes
* @param dueTime
*/
public void updateProcessAll(String processInstanceId, String userId, String prcName, String prcMes, Date dueTime) {
ProcessAll process = processAllService.getByProcessInstanceId(processInstanceId);
process.setCreateUserId(userId);
process.setPrcName(prcName);
process.setPrcMes(prcMes);
process.setDueTime(dueTime);
processAllService.updateById(process);
}
}
@@ -8,10 +8,7 @@ import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.SysDictItemCore;
import com.jero.modules.activiti.entity.ProcessAll;
import com.jero.modules.activiti.entity.ProcessApprovalRecord;
import com.jero.modules.activiti.entity.ProcessNode;
import com.jero.modules.activiti.enums.CommitFlagEnum;
import com.jero.modules.activiti.enums.FinishFlagEnum;
import com.jero.modules.activiti.process.common.entity.CommonVO;
import com.jero.modules.activiti.process.common.enums.ProcessType;
import com.jero.modules.activiti.process.common.service.ActFlowCommonService;
@@ -21,10 +18,7 @@ import com.jero.modules.activiti.process.esAnnualReport.entity.vo.AnnualReportDa
import com.jero.modules.activiti.process.esAnnualReport.entity.vo.AnnualReportFlowUserVO;
import com.jero.modules.activiti.process.esAnnualReport.mapper.ProcessEsAnnualReportMapper;
import com.jero.modules.activiti.process.esAnnualReport.service.ProcessEsAnnualReportService;
import com.jero.modules.activiti.process.esInitChange.entity.ProcessEsInitChange;
import com.jero.modules.activiti.process.esInitChange.entity.enums.ESPProjectType;
import com.jero.modules.activiti.process.esInitChange.entity.vo.InitChangeDataVO;
import com.jero.modules.activiti.process.esInitChange.entity.vo.InitChangeFlowUserVO;
import com.jero.modules.activiti.service.ProcessAllService;
import com.jero.modules.activiti.service.ProcessApprovalRecordService;
import com.jero.modules.activiti.service.ProcessNodeLinkService;
@@ -107,10 +101,10 @@ public class ProcessEsAnnualReportServiceImpl extends ServiceImpl<ProcessEsAnnua
Map<String, Object> variables = setVariables(annualReportData);
// 启动流程
ProcessInstance processInstance = actFlowCommonService.startProcess(processDefinitionKey, variables);
// 获取流程实例ID
String processDefinitionId = processInstance.getProcessDefinitionId();
String processInstanceId = processInstance.getId();
runtimeService.setVariable(processInstanceId, "contactUserList", variables.get("contactUserList"));
// 自动完成第一个任务
actFlowCommonService.autoCompleteFirstTask(userId, processInstanceId, processDefinitionId);
// 设置流程实例Id
@@ -158,7 +152,7 @@ public class ProcessEsAnnualReportServiceImpl extends ServiceImpl<ProcessEsAnnua
}
public void startRunTask(AnnualReportDataVO annualReportDataVO) {
//TODO info部长
// TODO info部长
}
@Override
@@ -14,6 +14,7 @@ import com.jero.modules.laws.enterprise.util.EnterpriseStandardUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
@@ -0,0 +1,19 @@
package com.jero.modules.activiti.process.esInitChange.entity;
/**
* @author: Mzaxd
* @Date: 2023/10/28 11:47
*/
public class EsInitChangeConstant {
public static final String MAIN_DRAFT_USER_INIT = "主起草人发起";
public static final String CONTACT_USER_CHECK = "部所联络人校对";
public static final String EXPERT_CHECK = "标准对应领域专家审核";
public static final String MAIN_DRAFT_USER_LEADER = "主起草人主管级领导审批";
public static final String MAIN_DRAFT_USER_LEADER_LEADER = "主起草人主管级上级领导审批";
public static final String STANDARDIZATION_CHECK = "标准化审批";
public static final String NEW_MAIN_DRAFT_LEADER_LEADER = "新起草部门主管级上一级领导下发主管级领导";
public static final String NEW_MAIN_DRAFT_LEADER = "新起草部门主管级领导确认新起草人";
public static final String RELATE_USER_SIGN = "相关人员会签";
public static final String AUTO_COPY = "自动抄送";
}
@@ -12,6 +12,7 @@ import com.jero.modules.laws.enterprise.util.BeanCopyUtils;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
@@ -21,6 +22,7 @@ import java.util.List;
* @Date: 2023/10/10 14:14
*/
@Slf4j
@Component
public class ProcessESInitChangeEndListener implements ExecutionListener {
@Resource
@@ -50,6 +52,9 @@ public class ProcessESInitChangeEndListener implements ExecutionListener {
for (ProcessEsInitChange processEsInitChange : processEsInitChanges) {
processEsInitChange.setId(null);
}
// 转换为企标计划数据并入库
enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class);
espService.saveBatch(enterpriseStandardPlans);
} else {
// 将Id设为企标计划的Id
for (ProcessEsInitChange processEsInitChange : processEsInitChanges) {
@@ -3,6 +3,7 @@ package com.jero.modules.activiti.process.esInitChange.service;
import com.jero.modules.activiti.process.esInitChange.entity.ProcessEsInitChange;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.modules.activiti.process.esInitChange.entity.vo.InitChangeDataVO;
import org.activiti.engine.runtime.ProcessInstance;
import java.util.List;
@@ -75,6 +75,81 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
private RuntimeService runtimeService;
@Override
public void startInitChange(InitChangeDataVO initChangeData) {
// 执行流程发起前的操作
this.startRunTask(initChangeData);
// 流程Key
String processDefinitionKey = ProcessType.ES_INIT_CHANGE.getProcessKey();
// 当前用户Id
String userId = UserUtils.getUserId();
// 业务数据
List<ProcessEsInitChange> esInitChangeList = initChangeData.getDataList();
// 设置流程变量
Map<String, Object> variables = this.setVariables(initChangeData);
// 启动流程
ProcessInstance processInstance = actFlowCommonService.startProcess(processDefinitionKey, variables);
// 获取流程实例ID
String processDefinitionId = processInstance.getProcessDefinitionId();
String processInstanceId = processInstance.getId();
// 手动设置所有流程变量
actFlowCommonService.setProcessVariables(processInstanceId, variables);
// 自动完成第一个任务
actFlowCommonService.autoCompleteFirstTask(userId, processInstanceId, processDefinitionId);
// 设置流程实例Id
esInitChangeList.forEach(e -> e.setProcessInstanceId(processInstanceId));
// 保存到业务流程表
saveBatch(esInitChangeList);
// 保存选人信息
processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, this.getUserMap(variables));
// 根据流程实例id更新流程总表
String prcName = initChangeData.getCommonVO().getPrcName();
String prcMes = initChangeData.getCommonVO().getPrcMes();
Date dueTime = initChangeData.getCommonVO().getDueTime();
actFlowCommonService.updateProcessAll(processInstanceId, userId, prcName, prcMes, dueTime);
}
public Map<String, Object> setVariables(InitChangeDataVO initChangeData) {
InitChangeFlowUserVO initChangeFlowUserVO = initChangeData.getFlowUserInfoVO();
ProcessEsInitChange initChange = initChangeData.getDataList().get(0);
HashMap<String, Object> map = new HashMap<>();
// 使用一个通用方法来只在不为空时添加键值对
putIfNotNull(map, "createUser", initChangeFlowUserVO.getCreateUser());
putIfNotNull(map, "contactUser", initChangeFlowUserVO.getContactUser());
List<String> standardExpertList = new ArrayList<>(Objects.requireNonNull(Optional.ofNullable(initChangeFlowUserVO.getStandardExpert()).map(s -> Arrays.asList(s.split(","))).orElse(null)));
putIfNotNull(map, "standardExpertList", standardExpertList);
putIfNotNull(map, "mainDraftUserLeader", initChangeFlowUserVO.getMainDraftUserLeader());
putIfNotNull(map, "mainDraftUserLeaderLeader", initChangeFlowUserVO.getMainDraftUserLeaderLeader());
putIfNotNull(map, "standardizationApprovalUser", initChangeFlowUserVO.getStandardizationApprovalUser());
putIfNotNull(map, "newMainDraftUserLeaderLeader", initChangeFlowUserVO.getNewMainDraftUserLeaderLeader());
putIfNotNull(map, "newMainDraftUserLeader", initChangeFlowUserVO.getNewMainDraftUserLeader());
putIfNotNull(map, "relatedUserList", Optional.ofNullable(initChangeFlowUserVO.getRelatedUser()).map(s -> Arrays.asList(s.split(","))).orElse(null));
putIfNotNull(map, "copyUser", initChangeFlowUserVO.getCopyUser());
putIfNotNull(map, "applicationCategory", initChange.getApplicationCategory());
putIfNotNull(map, "projectType", initChange.getProjectType());
return map;
}
public Map<String, Object> setUserVariables(InitChangeFlowUserVO initChangeFlowUserVO) {
HashMap<String, Object> map = new HashMap<>();
// 使用一个通用方法来只在不为空时添加键值对
putIfNotNull(map, "createUser", initChangeFlowUserVO.getCreateUser());
putIfNotNull(map, "contactUser", initChangeFlowUserVO.getContactUser());
putIfNotNull(map, "standardExpertList", Optional.ofNullable(initChangeFlowUserVO.getStandardExpert()).map(s -> Arrays.asList(s.split(","))).orElse(null));
putIfNotNull(map, "mainDraftUserLeader", initChangeFlowUserVO.getMainDraftUserLeader());
putIfNotNull(map, "mainDraftUserLeaderLeader", initChangeFlowUserVO.getMainDraftUserLeaderLeader());
putIfNotNull(map, "standardizationApprovalUser", initChangeFlowUserVO.getStandardizationApprovalUser());
putIfNotNull(map, "newMainDraftUserLeaderLeader", initChangeFlowUserVO.getNewMainDraftUserLeaderLeader());
putIfNotNull(map, "newMainDraftUserLeader", initChangeFlowUserVO.getNewMainDraftUserLeader());
putIfNotNull(map, "relatedUserList", Optional.ofNullable(initChangeFlowUserVO.getRelatedUser()).map(s -> Arrays.asList(s.split(","))).orElse(null));
putIfNotNull(map, "copyUser", initChangeFlowUserVO.getCopyUser());
return map;
}
private void putIfNotNull(Map<String, Object> map, String key, Object value) {
Optional.ofNullable(value).ifPresent(v -> map.put(key, v));
}
@Override
public InitChangeDataVO getHandleData(String taskId) {
if (!actFlowCommonService.taskExists(taskId)) {
@@ -120,52 +195,6 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
return initChangeFlowUserVO;
}
@Override
public void startInitChange(InitChangeDataVO initChangeData) {
// 执行流程发起前的操作
this.startRunTask(initChangeData);
// 流程Key
String processDefinitionKey = ProcessType.ES_INIT_CHANGE.getProcessKey();
String userId = UserUtils.getUserId();
List<ProcessEsInitChange> esInitChangeList = initChangeData.getDataList();
// 设置流程变量
Map<String, Object> variables = setVariables(initChangeData);
// 启动流程
ProcessInstance processInstance = actFlowCommonService.startProcess(processDefinitionKey, variables);
// 获取流程实例ID
String processDefinitionId = processInstance.getProcessDefinitionId();
String processInstanceId = processInstance.getId();
// 自动完成第一个任务
runtimeService.setVariable(processInstanceId, "createUser", variables.get("createUser"));
runtimeService.setVariable(processInstanceId, "contactUser", variables.get("contactUser"));
runtimeService.setVariable(processInstanceId, "projectType", variables.get("projectType"));
runtimeService.setVariable(processInstanceId, "mainDraftUserLeader", variables.get("mainDraftUserLeader"));
runtimeService.setVariable(processInstanceId, "contactUser", variables.get("contactUser"));
runtimeService.setVariable(processInstanceId, "standardExpertList", variables.get("standardExpertList"));
runtimeService.setVariable(processInstanceId, "standardizationApprovalUser", variables.get("standardizationApprovalUser"));
actFlowCommonService.autoCompleteFirstTask(userId, processInstanceId, processDefinitionId);
// 设置流程实例Id
for (ProcessEsInitChange esInitChange : esInitChangeList) {
esInitChange.setProcessInstanceId(processInstance.getId());
}
// 保存到业务流程表
saveBatch(esInitChangeList);
// 保存选人信息
processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, this.getUserMap(variables));
// 根据流程实例id更新流程总表
ProcessAll process = processAllService.getByProcessInstanceId(processInstanceId);
process.setCreateUserId(userId);
process.setPrcName(initChangeData.getCommonVO().getPrcName());
process.setPrcMes(initChangeData.getCommonVO().getPrcMes());
process.setDueTime(initChangeData.getCommonVO().getDueTime());
process.setProjectId(esInitChangeList.get(0).getId());
processAllService.updateById(process);
}
@Override
public void transfer(String taskId, String userId) {
actFlowCommonService.transfer(taskId, userId);
@@ -179,7 +208,6 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
if (StrUtil.isBlank(taskId) && !actFlowCommonService.taskExists(taskId)) {
throw new JeroBootException("taskId为空或任务不存在");
}
Map<String, Object> variables = new HashMap<>();
String processInstanceId = actFlowCommonService.getProcessInstanceIdByTaskId(taskId);
String processDefinitionId = actFlowCommonService.getProcessDefId(processInstanceId);
if (pass) {
@@ -188,14 +216,13 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
Map<String, Object> userMap = new HashMap<>();
this.setUserMap(userMap, flowUserInfoVO);
processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, userMap);
Map<String, Object> variables = setUserVariables(flowUserInfoVO);
actFlowCommonService.setProcessVariables(processInstanceId, variables);
}
runtimeService.setVariable(processInstanceId, "pass", true);
} else {
// 设置流程变量
// InitChangeFlowUserVO processUserInfo = this.getProcessUserInfo(processDefinitionId, processInstanceId);
// initChangeDataVO.setFlowUserInfoVO(processUserInfo);
runtimeService.setVariable(processInstanceId, "pass", false);
// variables.put("pass", false);
}
//更新审批表为完成,填充数据
ProcessApprovalRecord approvalRecord = processApprovalRecordService.getToDoByTaskId(taskId);
@@ -225,16 +252,16 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
private void setUserMap(Map<String, Object> variables, InitChangeFlowUserVO initChangeFlowUserVO) {
// 设置流程中各个节点的人
variables.put("createUser", initChangeFlowUserVO.getCreateUser());
variables.put("contactUser", initChangeFlowUserVO.getContactUser());
variables.put("standardExpertList", Optional.ofNullable(initChangeFlowUserVO.getStandardExpert()).map(s -> Arrays.asList(s.split(","))).orElse(Collections.emptyList()));
variables.put("mainDraftUserLeader", initChangeFlowUserVO.getMainDraftUserLeader());
variables.put("mainDraftUserLeaderLeader", initChangeFlowUserVO.getMainDraftUserLeaderLeader());
variables.put("standardizationApprovalUser", initChangeFlowUserVO.getStandardizationApprovalUser());
variables.put("newMainDraftUserLeaderLeader", initChangeFlowUserVO.getNewMainDraftUserLeaderLeader());
variables.put("newMainDraftUserLeader", initChangeFlowUserVO.getNewMainDraftUserLeader());
variables.put("relatedUserList", Optional.ofNullable(initChangeFlowUserVO.getRelatedUser()).map(s -> Arrays.asList(s.split(","))).orElse(Collections.emptyList()));
variables.put("copyUser", initChangeFlowUserVO.getCopyUser());
putIfNotNull(variables, "createUser", initChangeFlowUserVO.getCreateUser());
putIfNotNull(variables, "contactUser", initChangeFlowUserVO.getContactUser());
putIfNotNull(variables, "standardExpertList", Optional.ofNullable(initChangeFlowUserVO.getStandardExpert()).map(s -> Arrays.asList(s.split(","))).orElse(null));
putIfNotNull(variables, "mainDraftUserLeader", initChangeFlowUserVO.getMainDraftUserLeader());
putIfNotNull(variables, "mainDraftUserLeaderLeader", initChangeFlowUserVO.getMainDraftUserLeaderLeader());
putIfNotNull(variables, "standardizationApprovalUser", initChangeFlowUserVO.getStandardizationApprovalUser());
putIfNotNull(variables, "newMainDraftUserLeaderLeader", initChangeFlowUserVO.getNewMainDraftUserLeaderLeader());
putIfNotNull(variables, "newMainDraftUserLeader", initChangeFlowUserVO.getNewMainDraftUserLeader());
putIfNotNull(variables, "relatedUserList", Optional.ofNullable(initChangeFlowUserVO.getRelatedUser()).map(s -> Arrays.asList(s.split(","))).orElse(null));
putIfNotNull(variables, "copyUser", initChangeFlowUserVO.getCopyUser());
}
@Override
@@ -276,34 +303,6 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
}
}
public Map<String, Object> setVariables(InitChangeDataVO initChangeData) {
InitChangeFlowUserVO initChangeFlowUserVO = initChangeData.getFlowUserInfoVO();
ProcessEsInitChange initChange = initChangeData.getDataList().get(0);
Map<String, Object> map = new HashMap<>();
// 使用一个通用方法来只在不为空时添加键值对
putIfNotNull(map, "createUser", initChangeFlowUserVO.getCreateUser());
putIfNotNull(map, "contactUser", initChangeFlowUserVO.getContactUser());
putIfNotNull(map, "standardExpertList", Optional.ofNullable(initChangeFlowUserVO.getStandardExpert()).map(s -> Arrays.asList(s.split(","))).orElse(null));
putIfNotNull(map, "mainDraftUserLeader", initChangeFlowUserVO.getMainDraftUserLeader());
putIfNotNull(map, "mainDraftUserLeaderLeader", initChangeFlowUserVO.getMainDraftUserLeaderLeader());
putIfNotNull(map, "standardizationApprovalUser", initChangeFlowUserVO.getStandardizationApprovalUser());
putIfNotNull(map, "newMainDraftUserLeaderLeader", initChangeFlowUserVO.getNewMainDraftUserLeaderLeader());
putIfNotNull(map, "newMainDraftUserLeader", initChangeFlowUserVO.getNewMainDraftUserLeader());
putIfNotNull(map, "relatedUserList", Optional.ofNullable(initChangeFlowUserVO.getRelatedUser()).map(s -> Arrays.asList(s.split(","))).orElse(null));
putIfNotNull(map, "copyUser", initChangeFlowUserVO.getCopyUser());
putIfNotNull(map, "applicationCategory", initChange.getApplicationCategory());
putIfNotNull(map, "projectType", initChange.getProjectType());
return map;
}
private void putIfNotNull(Map<String, Object> map, String key, Object value) {
if (value != null) {
map.put(key, value);
}
}
public void startRunTask(InitChangeDataVO initChangeData) {
List<ProcessEsInitChange> esInitChangeList = initChangeData.getDataList();
// 校验企标编号是否冲突