feat: 立项变更流程切换到通用人员接口

This commit is contained in:
2023-11-02 17:13:44 +08:00
parent 6f6f92e005
commit 86f946765c
3 changed files with 55 additions and 49 deletions
@@ -16,6 +16,18 @@ import java.util.Date;
@ApiModel(value="流程通用信息对象", description="流程通用信息对象")
public class CommonVO {
/**
* 流程定义ID
*/
@ApiModelProperty("流程定义ID")
private String processDefinitionId;
/**
* 流程实例ID
*/
@ApiModelProperty("流程实例ID")
private String processInstanceId;
/**
* 任务ID
*/
@@ -71,4 +83,6 @@ public class CommonVO {
*/
@ApiModelProperty("制修订计划说明")
private String processDescription;
}
@@ -6,6 +6,7 @@ import com.jero.modules.activiti.process.esInitChange.entity.ProcessEsInitChange
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @author: Mzaxd
@@ -21,5 +22,5 @@ public class InitChangeDataVO {
List<ProcessEsInitChange> dataList;
@JsonProperty("flowUser")
InitChangeFlowUserVO flowUserInfoVO;
Map<String, Object> flowUserInfoVO;
}
@@ -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;
@@ -15,7 +14,6 @@ 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.esInitChange.entity.ProcessEsInitChange;
import com.jero.modules.activiti.process.esInitChange.entity.vo.InitChangeFlowUserVO;
import com.jero.modules.activiti.process.esInitChange.entity.vo.InitChangeDataVO;
import com.jero.modules.activiti.process.esInitChange.service.ProcessEsInitChangeService;
import com.jero.modules.activiti.process.esInitChange.mapper.ProcessEsInitChangeMapper;
@@ -106,27 +104,23 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
}
public Map<String, Object> setVariables(InitChangeDataVO initChangeData) {
InitChangeFlowUserVO initChangeFlowUserVO = initChangeData.getFlowUserInfoVO();
Map<String, Object> flowUserInfoVO = initChangeData.getFlowUserInfoVO();
HashMap<String, Object> map = new HashMap<>(flowUserInfoVO);
ProcessEsInitChange initChange = initChangeData.getDataList().get(0);
HashMap<String, Object> map = new HashMap<>(this.setUserVariables(initChangeFlowUserVO));
// 添加非列表类型的变量
actFlowCommonService.putIfNotNull(map, "applicationCategory", initChange.getApplicationCategory());
actFlowCommonService.putIfNotNull(map, "projectType", initChange.getProjectType());
// 添加列表类型的变量
convertAndPutList(map, flowUserInfoVO, "standardExpertList");
convertAndPutList(map, flowUserInfoVO, "relatedUserList");
return map;
}
public Map<String, Object> setUserVariables(InitChangeFlowUserVO initChangeFlowUserVO) {
HashMap<String, Object> map = new HashMap<>();
// 使用一个通用方法来只在不为空时添加键值对
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));
return map;
private void convertAndPutList(HashMap<String, Object> map, Map<String, Object> flowUserInfoVO, String key) {
Optional.ofNullable(flowUserInfoVO.get(key))
.map(Object::toString)
.map(s -> Arrays.asList(s.split(",")))
.ifPresent(list -> map.put(key, list));
}
private Map<String, Object> getUserMap(Map<String, Object> variables) {
@@ -159,6 +153,8 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
commonVO.setTaskId(process.getTaskId());
commonVO.setPrcMes(process.getPrcMes());
commonVO.setDueTime(process.getDueTime());
commonVO.setProcessDefinitionId(processDefinitionId);
commonVO.setProcessInstanceId(processInstanceId);
initChangeDataVO.setCommonVO(commonVO);
// 获取流程实例数据
LambdaQueryWrapper<ProcessEsInitChange> lambdaQueryWrapper = new LambdaQueryWrapper<>();
@@ -166,38 +162,36 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
lambdaQueryWrapper.eq(ProcessEsInitChange::getDelFlag, YesOrNoEnum.NO.getValue());
List<ProcessEsInitChange> dataList = list(lambdaQueryWrapper);
initChangeDataVO.setDataList(dataList);
// 选人组件内容填充
initChangeDataVO.setFlowUserInfoVO(this.getProcessUserInfo(processDefinitionId, processInstanceId));
return initChangeDataVO;
}
private InitChangeFlowUserVO getProcessUserInfo(String processDefinitionId, String processInstanceId) {
List<ProcessNode> nodeList = processNodeService.getNodeList(processDefinitionId, processInstanceId);
InitChangeFlowUserVO initChangeFlowUserVO = new InitChangeFlowUserVO();
Map<String, ProcessNode> userMap = nodeList.stream()
.collect(Collectors.groupingBy(ProcessNode::getVariableName))
.values()
.stream()
.map(nodes -> nodes.get(0)) // 选择每组的第一个元素
.collect(Collectors.toMap(ProcessNode::getVariableName, node -> node));
Optional.ofNullable(userMap.get("createUser")).ifPresent(node -> initChangeFlowUserVO.setCreateUser(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("contactUser")).ifPresent(node -> initChangeFlowUserVO.setContactUser(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("standardExpertList")).ifPresent(node -> initChangeFlowUserVO.setStandardExpert(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("mainDraftUserLeader")).ifPresent(node -> initChangeFlowUserVO.setMainDraftUserLeader(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("mainDraftUserLeaderLeader")).ifPresent(node -> initChangeFlowUserVO.setMainDraftUserLeaderLeader(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("standardizationApprovalUser")).ifPresent(node -> initChangeFlowUserVO.setStandardizationApprovalUser(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("newMainDraftUserLeaderLeader")).ifPresent(node -> initChangeFlowUserVO.setNewMainDraftUserLeaderLeader(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("newMainDraftUserLeader")).ifPresent(node -> initChangeFlowUserVO.setNewMainDraftUserLeader(node.getLinkUserIds()));
Optional.ofNullable(userMap.get("relatedUserList")).ifPresent(node -> initChangeFlowUserVO.setRelatedUser(node.getLinkUserIds()));
return initChangeFlowUserVO;
}
// private InitChangeFlowUserVO getProcessUserInfo(String processDefinitionId, String processInstanceId) {
// List<ProcessNode> nodeList = processNodeService.getNodeList(processDefinitionId, processInstanceId);
// InitChangeFlowUserVO initChangeFlowUserVO = new InitChangeFlowUserVO();
// Map<String, ProcessNode> userMap = nodeList.stream()
// .collect(Collectors.groupingBy(ProcessNode::getVariableName))
// .values()
// .stream()
// .map(nodes -> nodes.get(0)) // 选择每组的第一个元素
// .collect(Collectors.toMap(ProcessNode::getVariableName, node -> node));
// Optional.ofNullable(userMap.get("createUser")).ifPresent(node -> initChangeFlowUserVO.setCreateUser(node.getLinkUserIds()));
// Optional.ofNullable(userMap.get("contactUser")).ifPresent(node -> initChangeFlowUserVO.setContactUser(node.getLinkUserIds()));
// Optional.ofNullable(userMap.get("standardExpertList")).ifPresent(node -> initChangeFlowUserVO.setStandardExpert(node.getLinkUserIds()));
// Optional.ofNullable(userMap.get("mainDraftUserLeader")).ifPresent(node -> initChangeFlowUserVO.setMainDraftUserLeader(node.getLinkUserIds()));
// Optional.ofNullable(userMap.get("mainDraftUserLeaderLeader")).ifPresent(node -> initChangeFlowUserVO.setMainDraftUserLeaderLeader(node.getLinkUserIds()));
// Optional.ofNullable(userMap.get("standardizationApprovalUser")).ifPresent(node -> initChangeFlowUserVO.setStandardizationApprovalUser(node.getLinkUserIds()));
// Optional.ofNullable(userMap.get("newMainDraftUserLeaderLeader")).ifPresent(node -> initChangeFlowUserVO.setNewMainDraftUserLeaderLeader(node.getLinkUserIds()));
// Optional.ofNullable(userMap.get("newMainDraftUserLeader")).ifPresent(node -> initChangeFlowUserVO.setNewMainDraftUserLeader(node.getLinkUserIds()));
// Optional.ofNullable(userMap.get("relatedUserList")).ifPresent(node -> initChangeFlowUserVO.setRelatedUser(node.getLinkUserIds()));
// return initChangeFlowUserVO;
// }
@Override
public void approvalInitChange(InitChangeDataVO initChangeDataVO, boolean pass) {
String userId = UserUtils.getUserId();
CommonVO commonVO = initChangeDataVO.getCommonVO();
List<ProcessEsInitChange> initChangeList = initChangeDataVO.getDataList();
InitChangeFlowUserVO flowUserInfoVO = initChangeDataVO.getFlowUserInfoVO();
Map<String, Object> flowUserInfoVO = initChangeDataVO.getFlowUserInfoVO();
String taskId = commonVO.getTaskId();
if (StrUtil.isBlank(taskId) && !actFlowCommonService.taskExists(taskId)) {
throw new JeroBootException("taskId为空或任务不存在");
@@ -205,16 +199,13 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
String processInstanceId = actFlowCommonService.getProcessInstanceIdByTaskId(taskId);
String processDefinitionId = actFlowCommonService.getProcessDefId(processInstanceId);
if (pass) {
if (initChangeList != null && flowUserInfoVO != null) {
if (initChangeList != null) {
saveOrUpdateBatch(initChangeList);
Map<String, Object> variables = this.setVariables(initChangeDataVO);
actFlowCommonService.setProcessVariables(processInstanceId, variables);
processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, this.getUserMap(variables));
}
if (flowUserInfoVO != null) {
Map<String, Object> variables = this.setUserVariables(flowUserInfoVO);
if (flowUserInfoVO != null && !flowUserInfoVO.isEmpty()) {
Map<String, Object> variables = setVariables(initChangeDataVO);
actFlowCommonService.setProcessVariables(processInstanceId, variables);
processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, this.getUserMap(variables));
processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, getUserMap(variables));
}
runtimeService.setVariableLocal(processInstanceId, "pass", true);
} else {
@@ -268,7 +259,7 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
public void startRunTask(InitChangeDataVO initChangeData) {
List<ProcessEsInitChange> esInitChangeList = initChangeData.getDataList();
// 校验企标编号是否冲突
if (!esUtil.verifyEnStandardNumber(esInitChangeList.get(0).getOriginEnStandardNo())) {
if (!esUtil.verifyEnStandardNumber(esInitChangeList.get(0).getNewEnStandardNo())) {
throw new JeroBootException("企标编号冲突,请重新生成");
}
}