feat: 企标已封存启用流程

This commit is contained in:
2023-10-31 11:07:28 +08:00
parent 8f0db41939
commit 5112324140
3 changed files with 214 additions and 14 deletions
@@ -11,18 +11,24 @@ import lombok.Data;
@Data
public class ESEnableFlowUserVO {
// 创建人
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "username")
@ApiModelProperty("创建人")
private String createUser;
// 相关人员
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "username")
@ApiModelProperty("相关人员")
private String relatedUser;
// 创建人
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "username")
@ApiModelProperty("起草人和会签人主管级领导")
private String leader;
// 标准化审批人
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "username")
@ApiModelProperty("标准化审批人")
private String standardizationUser;
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "username")
@ApiModelProperty("主起草人")
private String mainDraftUser;
// 主起草人主管级领导
@Dict(dictTable = "sys_user", dicCode = "id", dicText = "username")
@ApiModelProperty("主起草人主管级领导")
private String mainDraftUserLeader;
}
@@ -15,7 +15,7 @@ public interface ProcessEsEnableService extends IService<ProcessEsEnable> {
void saveToDraft(ESEnableDataVO enableData);
ProcessEsEnable getHandleData(String taskId);
ESEnableDataVO getHandleData(String taskId);
void approvalInitChange(ESEnableDataVO enableData, boolean pass);
@@ -1,15 +1,38 @@
package com.jero.modules.activiti.process.esEnable.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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;
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.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;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author ThinkBook
* @description 针对表【process_es_enable(企业标准)】的数据库操作Service实现
@@ -21,24 +44,195 @@ import org.springframework.transaction.annotation.Transactional;
public class ProcessEsEnableServiceImpl extends ServiceImpl<ProcessEsEnableMapper, ProcessEsEnable>
implements ProcessEsEnableService{
@Resource
private ProcessAllService processAllService;
@Resource
private ActFlowCommonService actFlowCommonService;
@Resource
private ProcessDraftService processDraftService;
@Resource
private ProcessNodeLinkService processNodeLinkService;
@Resource
private ProcessNodeService processNodeService;
@Resource
private RuntimeService runtimeService;
@Override
public void startProcess(ESEnableDataVO enableData) {
// 执行流程发起前的操作
this.startRunTask(enableData);
// 流程Key
String processDefinitionKey = ProcessType.ES_INIT_CHANGE.getProcessKey();
// 当前用户Id
String userId = UserUtils.getUserId();
// 业务数据
ProcessEsEnable esEnable = enableData.getData();
// 通用数据
CommonVO common = enableData.getCommon();
// 人员数据
ESEnableFlowUserVO flowUser = enableData.getFlowUser();
// 设置流程变量
Map<String, Object> variables = this.setVariables(flowUser);
// 启动流程
ProcessInstance processInstance = actFlowCommonService.startProcess(processDefinitionKey, variables);
// 获取流程实例ID
String processDefinitionId = processInstance.getProcessDefinitionId();
String processInstanceId = processInstance.getId();
// 手动设置所有流程变量
actFlowCommonService.setProcessVariables(processInstanceId, variables);
// 自动完成第一个任务
actFlowCommonService.autoCompleteFirstTask(userId, processInstanceId, processDefinitionId, common);
// 设置流程实例Id
esEnable.setProcessInstanceId(processInstanceId);
// 保存到业务流程表
save(esEnable);
// 保存选人信息
processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, this.getUserMap(variables));
// 根据流程实例id更新流程总表
String prcName = common.getPrcName();
String prcMes = common.getPrcMes();
Date dueTime = common.getDueTime();
Integer prcType = ProcessTypeEnum.ES_ENABLE.getValue();
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;
}
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(""));
return variables;
}
@Override
public void saveToDraft(ESEnableDataVO enableData) {
public void saveToDraft(ESEnableDataVO enableDataVO) {
CommonVO commonVO = enableDataVO.getCommon();
String taskId = commonVO.getTaskId();
ProcessEsEnable esEnable = enableDataVO.getData();
saveOrUpdate(esEnable);
// 先删后增
LambdaUpdateWrapper<ProcessDraft> draftWrapper = new LambdaUpdateWrapper<>();
if (StrUtil.isBlank(taskId)) {
// 第一个节点点击保存没有taskId
draftWrapper.eq(ProcessDraft::getPrcType, ProcessTypeEnum.ES_ENABLE.getValue());
draftWrapper.eq(ProcessDraft::getCreateBy, UserUtils.getUserId());
processDraftService.remove(draftWrapper);
List<ProcessDraft> draftList = new ArrayList<>();
ProcessDraft draft = new ProcessDraft();
draft.setProjectId(esEnable.getId());
draft.setPrcType(ProcessTypeEnum.ES_ENABLE.getValue());
draftList.add(draft);
processDraftService.saveBatch(draftList);
} else {
String processInstanceId = actFlowCommonService.getProcessInstanceIdByTaskId(taskId);
draftWrapper.eq(ProcessDraft::getProjectId, esEnable.getId());
processDraftService.remove(draftWrapper);
List<ProcessDraft> draftList = new ArrayList<>();
ProcessDraft draft = new ProcessDraft();
draft.setProjectId(esEnable.getId());
draft.setProcessInstanceId(processInstanceId);
draft.setPrcName(commonVO.getPrcName());
draft.setPrcType(ProcessTypeEnum.ES_ENABLE.getValue());
draftList.add(draft);
processDraftService.saveBatch(draftList);
}
}
public void startRunTask(ESEnableDataVO enableData) {
// do nothing now
}
@Override
public ProcessEsEnable getHandleData(String taskId) {
return null;
public ESEnableDataVO getHandleData(String taskId) {
if (!actFlowCommonService.taskExists(taskId)) {
throw new JeroBootException("任务不存在");
}
ESEnableDataVO enableData = new ESEnableDataVO();
// 使用流程引擎根据taskId找到流程实例Id
String processInstanceId = actFlowCommonService.getProcessInstanceIdByTaskId(taskId);
String processDefinitionId = actFlowCommonService.getProcessDefId(processInstanceId);
// 获取流程通用数据
ProcessAll process = processAllService.getByProcessInstanceId(processInstanceId);
CommonVO commonVO = new CommonVO();
commonVO.setPrcName(process.getPrcName());
commonVO.setTaskId(process.getTaskId());
commonVO.setPrcMes(process.getPrcMes());
commonVO.setDueTime(process.getDueTime());
enableData.setCommon(commonVO);
// 获取流程实例数据
LambdaQueryWrapper<ProcessEsEnable> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(ProcessEsEnable::getProcessInstanceId, processInstanceId);
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) {
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);
}
// 更新审批表为完成,填充数据
actFlowCommonService.updateApprovalInfo(commonVO, taskId, pass);
//审批节点
actFlowCommonService.completeTask(taskId, userId);
}
}