From 7c7da33a6d10ebb3af4c4061dd02c5eb0f6b95ec Mon Sep 17 00:00:00 2001 From: caihaohan Date: Sat, 28 Oct 2023 22:43:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B9=B4=E5=BA=A6=E5=88=B6=E4=BF=AE?= =?UTF-8?q?=E8=AE=A2-=E4=B8=BB=E5=8A=A8=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/service/ActFlowCommonService.java | 10 ++ .../ProcessESAnnualInitEndListener.java | 110 ++++++++++++++++++ .../ProcessESAnnualReportEndListener.java | 110 ++++++++++++++++++ .../ProcessEsAnnualReportServiceImpl.java | 108 ++++++++--------- .../service/ProcessEsInitChangeService.java | 7 -- .../impl/ProcessEsInitChangeServiceImpl.java | 105 +++++------------ 6 files changed, 309 insertions(+), 141 deletions(-) create mode 100644 laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualInit/listener/ProcessESAnnualInitEndListener.java create mode 100644 laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualReport/listener/ProcessESAnnualReportEndListener.java diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/process/common/service/ActFlowCommonService.java b/laws-modules/src/main/java/com/jero/modules/activiti/process/common/service/ActFlowCommonService.java index 34a02dfb..3c73f2f3 100644 --- a/laws-modules/src/main/java/com/jero/modules/activiti/process/common/service/ActFlowCommonService.java +++ b/laws-modules/src/main/java/com/jero/modules/activiti/process/common/service/ActFlowCommonService.java @@ -62,6 +62,16 @@ public class ActFlowCommonService { return processInstance; } + /** + * Map工具 + * @param map + * @param key + * @param value + */ + public void putIfNotNull(Map map, String key, Object value) { + Optional.ofNullable(value).ifPresent(v -> map.put(key, v)); + } + /** * 循环设置流程变量 * @param processInstanceId diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualInit/listener/ProcessESAnnualInitEndListener.java b/laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualInit/listener/ProcessESAnnualInitEndListener.java new file mode 100644 index 00000000..b80a383b --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualInit/listener/ProcessESAnnualInitEndListener.java @@ -0,0 +1,110 @@ +package com.jero.modules.activiti.process.esAnnualInit.listener; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.jero.modules.activiti.process.esInitChange.entity.ProcessEsInitChange; +import com.jero.modules.activiti.process.esInitChange.entity.enums.ESPApplicationCategoryEnum; +import com.jero.modules.activiti.process.esInitChange.entity.enums.ESPChangeType; +import com.jero.modules.activiti.process.esInitChange.entity.enums.ESPProjectType; +import com.jero.modules.activiti.process.esInitChange.service.ProcessEsInitChangeService; +import com.jero.modules.laws.enterprise.entity.EnterpriseStandardPlan; +import com.jero.modules.laws.enterprise.service.EnterpriseStandardPlanService; +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; + +/** + * @author: Mzaxd + * @Date: 2023/10/10 14:14 + */ +@Slf4j +@Component +public class ProcessESAnnualInitEndListener implements ExecutionListener { + + @Resource + private EnterpriseStandardPlanService espService; + + @Resource + private ProcessEsInitChangeService esInitChangeService; + + /** + * 企标立项变更流程结束之后需要把数据存入企标计划数据库 然后自动发起企标制修订流程 + * @param delegateExecution + */ + @Override + public void notify(DelegateExecution delegateExecution) { +// log.info("企标立项变更流程结束 监听执行器开始执行"); +// // 获取流程实例ID +// String processInstanceId = delegateExecution.getProcessInstanceId(); +// // 根据流程实例Id找到所有流程业务数据 +// LambdaQueryWrapper esInitChangeWrapper = new LambdaQueryWrapper<>(); +// esInitChangeWrapper.eq(ProcessEsInitChange::getProcessInstanceId, processInstanceId); +// List processEsInitChanges = esInitChangeService.list(esInitChangeWrapper); +// String applicationCategory = processEsInitChanges.get(0).getApplicationCategory(); +// String projectType = processEsInitChanges.get(0).getProjectType(); +// List enterpriseStandardPlans; +// if (ESPApplicationCategoryEnum.INITIATION.getValue().equals(applicationCategory)) { +// // 立项新增-Id置空 +// for (ProcessEsInitChange processEsInitChange : processEsInitChanges) { +// processEsInitChange.setId(null); +// } +// // 转换为企标计划数据并入库 +// enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class); +// espService.saveBatch(enterpriseStandardPlans); +// } else { +// // 将Id设为企标计划的Id +// for (ProcessEsInitChange processEsInitChange : processEsInitChanges) { +// processEsInitChange.setId(processEsInitChange.getEspId()); +// } +// +// // 完成时间变更 +// if (ESPProjectType.COMPLETE_TIME_CHANGE.getValue().equals(projectType)) { +// enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class); +// espService.saveOrUpdateBatch(enterpriseStandardPlans); +// } +// +// // 工作中止 +// if (ESPProjectType.WORK_TERMINATE.getValue().equals(projectType)) { +// // 将企标计划变更状态设为取消 +// for (ProcessEsInitChange processEsInitChange : processEsInitChanges) { +// processEsInitChange.setProjectStatus(ESPChangeType.CANCEL.getValue()); +// } +// enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class); +// espService.saveOrUpdateBatch(enterpriseStandardPlans); +// } +// +// // 责任部门变更 +// if (ESPProjectType.RESPONSIBLE_DEPT_CHANGE.getValue().equals(projectType)) { +// // 将企标计划变更状态设为变更 +// for (ProcessEsInitChange processEsInitChange : processEsInitChanges) { +// processEsInitChange.setProjectStatus(ESPChangeType.CHANGE.getValue()); +// } +// enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class); +// espService.saveOrUpdateBatch(enterpriseStandardPlans); +// } +// +// // 合并 +// if (ESPProjectType.MERGE.getValue().equals(projectType)) { +// for (ProcessEsInitChange processEsInitChange : processEsInitChanges) { +// processEsInitChange.setId(null); +// } +// // 删除两个老企标计划 +// espService.deleteById(processEsInitChanges.get(0).getStandardIdOne()); +// espService.deleteById(processEsInitChanges.get(0).getStandardIdTwo()); +// // 生成新企标计划 +// enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class); +// espService.saveOrUpdateBatch(enterpriseStandardPlans); +// } +// } +// log.info("数据存入企标计划数据库"); +// // 软删除流程数据 +// esInitChangeService.removeByProcessInstanceId(processInstanceId); +// log.info("软删除流程数据"); +// //TODO 发起制修订流程 +// log.info("自动发起企标制修订流程"); + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualReport/listener/ProcessESAnnualReportEndListener.java b/laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualReport/listener/ProcessESAnnualReportEndListener.java new file mode 100644 index 00000000..748ceac7 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualReport/listener/ProcessESAnnualReportEndListener.java @@ -0,0 +1,110 @@ +package com.jero.modules.activiti.process.esAnnualReport.listener; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.jero.modules.activiti.process.esInitChange.entity.ProcessEsInitChange; +import com.jero.modules.activiti.process.esInitChange.entity.enums.ESPApplicationCategoryEnum; +import com.jero.modules.activiti.process.esInitChange.entity.enums.ESPChangeType; +import com.jero.modules.activiti.process.esInitChange.entity.enums.ESPProjectType; +import com.jero.modules.activiti.process.esInitChange.service.ProcessEsInitChangeService; +import com.jero.modules.laws.enterprise.entity.EnterpriseStandardPlan; +import com.jero.modules.laws.enterprise.service.EnterpriseStandardPlanService; +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; + +/** + * @author: Mzaxd + * @Date: 2023/10/10 14:14 + */ +@Slf4j +@Component +public class ProcessESAnnualReportEndListener implements ExecutionListener { + + @Resource + private EnterpriseStandardPlanService espService; + + @Resource + private ProcessEsInitChangeService esInitChangeService; + + /** + * 企标立项变更流程结束之后需要把数据存入企标计划数据库 然后自动发起企标制修订流程 + * @param delegateExecution + */ + @Override + public void notify(DelegateExecution delegateExecution) { +// log.info("企标立项变更流程结束 监听执行器开始执行"); +// // 获取流程实例ID +// String processInstanceId = delegateExecution.getProcessInstanceId(); +// // 根据流程实例Id找到所有流程业务数据 +// LambdaQueryWrapper esInitChangeWrapper = new LambdaQueryWrapper<>(); +// esInitChangeWrapper.eq(ProcessEsInitChange::getProcessInstanceId, processInstanceId); +// List processEsInitChanges = esInitChangeService.list(esInitChangeWrapper); +// String applicationCategory = processEsInitChanges.get(0).getApplicationCategory(); +// String projectType = processEsInitChanges.get(0).getProjectType(); +// List enterpriseStandardPlans; +// if (ESPApplicationCategoryEnum.INITIATION.getValue().equals(applicationCategory)) { +// // 立项新增-Id置空 +// for (ProcessEsInitChange processEsInitChange : processEsInitChanges) { +// processEsInitChange.setId(null); +// } +// // 转换为企标计划数据并入库 +// enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class); +// espService.saveBatch(enterpriseStandardPlans); +// } else { +// // 将Id设为企标计划的Id +// for (ProcessEsInitChange processEsInitChange : processEsInitChanges) { +// processEsInitChange.setId(processEsInitChange.getEspId()); +// } +// +// // 完成时间变更 +// if (ESPProjectType.COMPLETE_TIME_CHANGE.getValue().equals(projectType)) { +// enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class); +// espService.saveOrUpdateBatch(enterpriseStandardPlans); +// } +// +// // 工作中止 +// if (ESPProjectType.WORK_TERMINATE.getValue().equals(projectType)) { +// // 将企标计划变更状态设为取消 +// for (ProcessEsInitChange processEsInitChange : processEsInitChanges) { +// processEsInitChange.setProjectStatus(ESPChangeType.CANCEL.getValue()); +// } +// enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class); +// espService.saveOrUpdateBatch(enterpriseStandardPlans); +// } +// +// // 责任部门变更 +// if (ESPProjectType.RESPONSIBLE_DEPT_CHANGE.getValue().equals(projectType)) { +// // 将企标计划变更状态设为变更 +// for (ProcessEsInitChange processEsInitChange : processEsInitChanges) { +// processEsInitChange.setProjectStatus(ESPChangeType.CHANGE.getValue()); +// } +// enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class); +// espService.saveOrUpdateBatch(enterpriseStandardPlans); +// } +// +// // 合并 +// if (ESPProjectType.MERGE.getValue().equals(projectType)) { +// for (ProcessEsInitChange processEsInitChange : processEsInitChanges) { +// processEsInitChange.setId(null); +// } +// // 删除两个老企标计划 +// espService.deleteById(processEsInitChanges.get(0).getStandardIdOne()); +// espService.deleteById(processEsInitChanges.get(0).getStandardIdTwo()); +// // 生成新企标计划 +// enterpriseStandardPlans = BeanCopyUtils.copyBeanList(processEsInitChanges, EnterpriseStandardPlan.class); +// espService.saveOrUpdateBatch(enterpriseStandardPlans); +// } +// } +// log.info("数据存入企标计划数据库"); +// // 软删除流程数据 +// esInitChangeService.removeByProcessInstanceId(processInstanceId); +// log.info("软删除流程数据"); +// //TODO 发起制修订流程 +// log.info("自动发起企标制修订流程"); + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualReport/service/impl/ProcessEsAnnualReportServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualReport/service/impl/ProcessEsAnnualReportServiceImpl.java index 21747dd7..975ed569 100644 --- a/laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualReport/service/impl/ProcessEsAnnualReportServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/activiti/process/esAnnualReport/service/impl/ProcessEsAnnualReportServiceImpl.java @@ -12,7 +12,6 @@ import com.jero.modules.activiti.entity.ProcessNode; 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; -import com.jero.modules.activiti.process.common.service.ProcessDraftService; import com.jero.modules.activiti.process.esAnnualReport.entity.ProcessEsAnnualReport; import com.jero.modules.activiti.process.esAnnualReport.entity.vo.AnnualReportDataVO; import com.jero.modules.activiti.process.esAnnualReport.entity.vo.AnnualReportFlowUserVO; @@ -20,7 +19,6 @@ import com.jero.modules.activiti.process.esAnnualReport.mapper.ProcessEsAnnualRe import com.jero.modules.activiti.process.esAnnualReport.service.ProcessEsAnnualReportService; import com.jero.modules.activiti.process.esInitChange.entity.enums.ESPProjectType; import com.jero.modules.activiti.service.ProcessAllService; -import com.jero.modules.activiti.service.ProcessApprovalRecordService; import com.jero.modules.activiti.service.ProcessNodeLinkService; import com.jero.modules.activiti.service.ProcessNodeService; import com.jero.modules.activiti.util.ExcelUtils; @@ -67,26 +65,18 @@ public class ProcessEsAnnualReportServiceImpl extends ServiceImpl annualReportList = annualReportData.getDataList(); - + // 当前用户Id + String userId = UserUtils.getUserId(); // 设置流程变量 - Map variables = setVariables(annualReportData); + Map variables = this.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.setProcessVariables(processInstanceId, variables); // 自动完成第一个任务 actFlowCommonService.autoCompleteFirstTask(userId, processInstanceId, processDefinitionId); // 设置流程实例Id - for (ProcessEsAnnualReport annualReport : annualReportList) { - annualReport.setProcessInstanceId(processInstance.getId()); - } + annualReportList.forEach(annualReport -> annualReport.setProcessInstanceId(processInstanceId)); // 保存选人信息 processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, this.getUserMap(variables)); - // 根据流程实例id更新流程总表 - ProcessAll process = processAllService.getByProcessInstanceId(processInstanceId); - process.setCreateUserId(userId); - process.setPrcName(annualReportData.getCommonVO().getPrcName()); - process.setPrcMes(annualReportData.getCommonVO().getPrcMes()); - process.setDueTime(annualReportData.getCommonVO().getDueTime()); - processAllService.updateById(process); + String prcName = annualReportData.getCommonVO().getPrcName(); + String prcMes = annualReportData.getCommonVO().getPrcMes(); + Date dueTime = annualReportData.getCommonVO().getDueTime(); + actFlowCommonService.updateProcessAll(processInstanceId, userId, prcName, prcMes, dueTime); // 执行流程发起前的操作 this.startRunTask(annualReportData); } - private Map getUserMap(Map variables) { - variables.remove("distribute"); - variables.remove("processDescription"); - return variables; - } - public Map setVariables(AnnualReportDataVO annualReportData) { AnnualReportFlowUserVO annualReportFlowUserVO = annualReportData.getFlowUserVO(); CommonVO commonVO = annualReportData.getCommonVO(); - Map map = new HashMap<>(); // 设置流程中各个节点的人 - map.put("standardEngineer", annualReportFlowUserVO.getStandardEngineer()); - if (!annualReportFlowUserVO.getContactUserList().isEmpty()) { - map.put("contactUserList", Optional.of(annualReportFlowUserVO.getContactUserList()).map(s -> Arrays.asList(s.split(","))).orElse(Collections.emptyList())); - } - if (!annualReportFlowUserVO.getWorkGroupUserList().isEmpty()) { - map.put("workGroupUserList", Optional.of(annualReportFlowUserVO.getWorkGroupUserList()).map(s -> Arrays.asList(s.split(","))).orElse(Collections.emptyList())); - } - map.put("collectUserLeader", annualReportFlowUserVO.getContactUserLeaderLeader()); - map.put("contactUserLeaderLeader", annualReportFlowUserVO.getContactUserLeaderLeader()); + Map map = new HashMap<>(this.setUserVariables(annualReportFlowUserVO)); // 设置流程分支判断变量 - map.put("distribute", annualReportFlowUserVO.isDistribute()); map.put("processDescription", commonVO.getProcessDescription()); return map; } + public Map setUserVariables(AnnualReportFlowUserVO userVO) { + HashMap map = new HashMap<>(); + // 使用一个通用方法来只在不为空时添加键值对 + actFlowCommonService.putIfNotNull(map, "standardEngineer", userVO.getStandardEngineer()); + actFlowCommonService.putIfNotNull(map, "contactUserList", Optional.ofNullable(userVO.getContactUserList()).map(s -> Arrays.asList(s.split(","))).orElse(null)); + return map; + } + + private Map getUserMap(Map variables) { + variables.remove("processDescription"); + // 转成逗号拼接 + variables.put("contactUserList", Optional.ofNullable((List) variables.get("contactUserList")) + .map(list -> String.join(",", list)) + .orElse("")); + variables.put("workGroupUserList", Optional.ofNullable((List) variables.get("workGroupUserList")) + .map(list -> String.join(",", list)) + .orElse("")); + return variables; + } + public void startRunTask(AnnualReportDataVO annualReportDataVO) { // TODO info部长 } @@ -168,19 +158,23 @@ public class ProcessEsAnnualReportServiceImpl extends ServiceImpl variables = new HashMap<>(); String processInstanceId = actFlowCommonService.getProcessInstanceIdByTaskId(taskId); String processDefinitionId = actFlowCommonService.getProcessDefId(processInstanceId); switch (taskName) { case CONTACT_USER_DISTRIBUTE: + boolean distribute = flowUserVO.isDistribute(); + taskService.setVariableLocal(taskId, "distribute", distribute); // 获取是否分发 - if (!flowUserVO.isDistribute()) { + if (distribute) { + // 设置流程变量 + taskService.setVariableLocal(taskId, "workGroupUserList", flowUserVO.getWorkGroupUserList()); + }else { // 保存联络人主管级上级领导 dataList.forEach(data -> data.setContactUserLeaderLeader(flowUserVO.getContactUserLeaderLeader())); // 不分发,入库存表 saveBatch(dataList); + taskService.setVariableLocal(taskId, "contactUserLeaderLeader", flowUserVO.getContactUserLeaderLeader()); } - // 设置流程变量 break; case WORK_GROUP_COLLECT: String executionId = task.getExecutionId(); @@ -190,7 +184,8 @@ public class ProcessEsAnnualReportServiceImpl extends ServiceImpl data.setCollectUserLeader(flowUserVO.getCollectUserLeader())); dataList.forEach(data -> data.setWorkGroupUser(UserUtils.getUserId())); saveBatch(dataList); - // 设置流程变量 + // 设置下一个节点的审批人流程变量 + taskService.setVariableLocal(taskId, "collectUserLeader", flowUserVO.getCollectUserLeader()); break; case CONTACT_USER_COLLECT: case CONTACT_USER_EDIT: @@ -202,22 +197,20 @@ public class ProcessEsAnnualReportServiceImpl extends ServiceImpl userMap = this.getUserMap(variables); - processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, userMap); + if (flowUserVO != null) { + Map userMap = new HashMap<>(this.setUserVariables(flowUserVO)); + processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, userMap); + Map variables = setUserVariables(flowUserVO); + actFlowCommonService.setProcessVariables(processInstanceId, variables); + } + runtimeService.setVariable(processInstanceId, "pass", true); } else { // 设置流程变量 - variables.put("pass", false); + runtimeService.setVariable(processInstanceId, "pass", false); } - // 设置流程变量 - variables.put("pass", pass); - - //更新审批表为完成,填充数据 + // 更新审批表为完成,填充数据 actFlowCommonService.updateApprovalInfo(commonVO, taskId, pass); - //审批节点 + // 审批节点 actFlowCommonService.completeTask(taskId, userId); } @@ -289,6 +282,7 @@ public class ProcessEsAnnualReportServiceImpl extends ServiceImpl nodeList = processNodeService.getNodeList(processDefinitionId, processInstanceId); AnnualReportFlowUserVO annualReportFlowUserVO = new AnnualReportFlowUserVO(); Map userMap = nodeList.stream().collect(Collectors.toMap(ProcessNode::getVariableName, node -> node)); diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/process/esInitChange/service/ProcessEsInitChangeService.java b/laws-modules/src/main/java/com/jero/modules/activiti/process/esInitChange/service/ProcessEsInitChangeService.java index 9e6cbe9b..b58c33eb 100644 --- a/laws-modules/src/main/java/com/jero/modules/activiti/process/esInitChange/service/ProcessEsInitChangeService.java +++ b/laws-modules/src/main/java/com/jero/modules/activiti/process/esInitChange/service/ProcessEsInitChangeService.java @@ -21,13 +21,6 @@ public interface ProcessEsInitChangeService extends IService setVariables(InitChangeDataVO initChangeData) { InitChangeFlowUserVO initChangeFlowUserVO = initChangeData.getFlowUserInfoVO(); ProcessEsInitChange initChange = initChangeData.getDataList().get(0); - HashMap map = new HashMap<>(); - // 使用一个通用方法来只在不为空时添加键值对 - putIfNotNull(map, "createUser", initChangeFlowUserVO.getCreateUser()); - putIfNotNull(map, "contactUser", initChangeFlowUserVO.getContactUser()); - List 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()); + HashMap map = new HashMap<>(this.setUserVariables(initChangeFlowUserVO)); + actFlowCommonService.putIfNotNull(map, "applicationCategory", initChange.getApplicationCategory()); + actFlowCommonService.putIfNotNull(map, "projectType", initChange.getProjectType()); return map; } public Map setUserVariables(InitChangeFlowUserVO initChangeFlowUserVO) { HashMap 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()); + actFlowCommonService.putIfNotNull(map, "createUser", initChangeFlowUserVO.getCreateUser()); + actFlowCommonService.putIfNotNull(map, "contactUser", initChangeFlowUserVO.getContactUser()); + actFlowCommonService.putIfNotNull(map, "standardExpertList", Optional.ofNullable(initChangeFlowUserVO.getStandardExpert()).map(s -> Arrays.asList(s.split(","))).orElse(null)); + actFlowCommonService.putIfNotNull(map, "mainDraftUserLeader", initChangeFlowUserVO.getMainDraftUserLeader()); + actFlowCommonService.putIfNotNull(map, "mainDraftUserLeaderLeader", initChangeFlowUserVO.getMainDraftUserLeaderLeader()); + actFlowCommonService.putIfNotNull(map, "standardizationApprovalUser", initChangeFlowUserVO.getStandardizationApprovalUser()); + actFlowCommonService.putIfNotNull(map, "newMainDraftUserLeaderLeader", initChangeFlowUserVO.getNewMainDraftUserLeaderLeader()); + actFlowCommonService.putIfNotNull(map, "newMainDraftUserLeader", initChangeFlowUserVO.getNewMainDraftUserLeader()); + actFlowCommonService.putIfNotNull(map, "relatedUserList", Optional.ofNullable(initChangeFlowUserVO.getRelatedUser()).map(s -> Arrays.asList(s.split(","))).orElse(null)); + actFlowCommonService.putIfNotNull(map, "copyUser", initChangeFlowUserVO.getCopyUser()); return map; } - private void putIfNotNull(Map map, String key, Object value) { - Optional.ofNullable(value).ifPresent(v -> map.put(key, v)); + private Map getUserMap(Map variables) { + variables.remove("pass"); + variables.remove("applicationCategory"); + variables.remove("projectType"); + // 转成逗号拼接 + variables.put("standardExpertList", Optional.ofNullable((List) variables.get("standardExpertList")) + .map(list -> String.join(",", list)) + .orElse("")); + variables.put("relatedUserList", Optional.ofNullable((List) variables.get("relatedUserList")) + .map(list -> String.join(",", list)) + .orElse("")); + return variables; } @Override @@ -195,11 +186,6 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl userMap = new HashMap<>(); - this.setUserMap(userMap, flowUserInfoVO); + Map userMap = new HashMap<>(this.setUserVariables(flowUserInfoVO)); processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, userMap); Map variables = setUserVariables(flowUserInfoVO); actFlowCommonService.setProcessVariables(processInstanceId, variables); @@ -224,46 +209,12 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl getUserMap(Map variables) { - variables.remove("pass"); - variables.remove("applicationCategory"); - variables.remove("projectType"); - // 转成逗号拼接 - variables.put("standardExpertList", Optional.ofNullable((List) variables.get("standardExpertList")) - .map(list -> String.join(",", list)) - .orElse("")); - variables.put("relatedUserList", Optional.ofNullable((List) variables.get("relatedUserList")) - .map(list -> String.join(",", list)) - .orElse("")); - return variables; - } - - private void setUserMap(Map variables, InitChangeFlowUserVO initChangeFlowUserVO) { - // 设置流程中各个节点的人 - 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 public void saveToDraft(InitChangeDataVO initChangeData) { CommonVO commonVO = initChangeData.getCommonVO();