feat: 企标封存流程
This commit is contained in:
+1
-1
@@ -15,7 +15,7 @@ public interface ProcessEsArchiveService extends IService<ProcessEsArchive> {
|
||||
|
||||
void saveToDraft(ESArchiveDataVO archiveData);
|
||||
|
||||
ProcessEsArchive getHandleData(String taskId);
|
||||
ESArchiveDataVO getHandleData(String taskId);
|
||||
|
||||
void approvalInitChange(ESArchiveDataVO archiveData, boolean pass);
|
||||
}
|
||||
|
||||
+196
-6
@@ -1,15 +1,38 @@
|
||||
package com.jero.modules.activiti.process.esArchive.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.esArchive.entity.ProcessEsArchive;
|
||||
import com.jero.modules.activiti.process.esArchive.entity.vo.ESArchiveDataVO;
|
||||
import com.jero.modules.activiti.process.esArchive.entity.vo.ESArchiveFlowUserVO;
|
||||
import com.jero.modules.activiti.process.esArchive.service.ProcessEsArchiveService;
|
||||
import com.jero.modules.activiti.process.esArchive.mapper.ProcessEsArchiveMapper;
|
||||
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_archive(企业标准)】的数据库操作Service实现
|
||||
@@ -21,24 +44,191 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class ProcessEsArchiveServiceImpl extends ServiceImpl<ProcessEsArchiveMapper, ProcessEsArchive>
|
||||
implements ProcessEsArchiveService{
|
||||
|
||||
@Override
|
||||
public void startProcess(ESArchiveDataVO annualInitData) {
|
||||
@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(ESArchiveDataVO archiveData) {
|
||||
// 执行流程发起前的操作
|
||||
this.startRunTask(archiveData);
|
||||
// 流程Key
|
||||
String processDefinitionKey = ProcessType.ES_INIT_CHANGE.getProcessKey();
|
||||
// 当前用户Id
|
||||
String userId = UserUtils.getUserId();
|
||||
// 业务数据
|
||||
ProcessEsArchive esArchive = archiveData.getData();
|
||||
// 人员数据
|
||||
ESArchiveFlowUserVO flowUser = archiveData.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);
|
||||
// 设置流程实例Id
|
||||
esArchive.setProcessInstanceId(processInstanceId);
|
||||
// 保存到业务流程表
|
||||
save(esArchive);
|
||||
// 保存选人信息
|
||||
processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, this.getUserMap(variables));
|
||||
// 根据流程实例id更新流程总表
|
||||
String prcName = archiveData.getCommon().getPrcName();
|
||||
String prcMes = archiveData.getCommon().getPrcMes();
|
||||
Date dueTime = archiveData.getCommon().getDueTime();
|
||||
actFlowCommonService.updateProcessAll(processInstanceId, userId, prcName, prcMes, dueTime);
|
||||
}
|
||||
|
||||
public Map<String, Object> setVariables(ESArchiveFlowUserVO 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(ESArchiveFlowUserVO 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(ESArchiveDataVO archiveData) {
|
||||
public void saveToDraft(ESArchiveDataVO archiveDataVO) {
|
||||
CommonVO commonVO = archiveDataVO.getCommon();
|
||||
String taskId = commonVO.getTaskId();
|
||||
ProcessEsArchive esArchive = archiveDataVO.getData();
|
||||
saveOrUpdate(esArchive);
|
||||
// 先删后增
|
||||
LambdaUpdateWrapper<ProcessDraft> draftWrapper = new LambdaUpdateWrapper<>();
|
||||
if (StrUtil.isBlank(taskId)) {
|
||||
// 第一个节点点击保存没有taskId
|
||||
draftWrapper.eq(ProcessDraft::getPrcType, ProcessTypeEnum.B.getValue());
|
||||
draftWrapper.eq(ProcessDraft::getCreateBy, UserUtils.getUserId());
|
||||
processDraftService.remove(draftWrapper);
|
||||
List<ProcessDraft> draftList = new ArrayList<>();
|
||||
ProcessDraft draft = new ProcessDraft();
|
||||
draft.setProjectId(esArchive.getId());
|
||||
draft.setPrcType(ProcessTypeEnum.B.getValue());
|
||||
draftList.add(draft);
|
||||
processDraftService.saveBatch(draftList);
|
||||
} else {
|
||||
String processInstanceId = actFlowCommonService.getProcessInstanceIdByTaskId(taskId);
|
||||
draftWrapper.eq(ProcessDraft::getProjectId, esArchive.getId());
|
||||
processDraftService.remove(draftWrapper);
|
||||
List<ProcessDraft> draftList = new ArrayList<>();
|
||||
ProcessDraft draft = new ProcessDraft();
|
||||
draft.setProjectId(esArchive.getId());
|
||||
draft.setProcessInstanceId(processInstanceId);
|
||||
draft.setPrcName(commonVO.getPrcName());
|
||||
draft.setPrcType(ProcessTypeEnum.B.getValue());
|
||||
draftList.add(draft);
|
||||
processDraftService.saveBatch(draftList);
|
||||
}
|
||||
}
|
||||
|
||||
public void startRunTask(ESArchiveDataVO archiveData) {
|
||||
// do nothing now
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessEsArchive getHandleData(String taskId) {
|
||||
return null;
|
||||
public ESArchiveDataVO getHandleData(String taskId) {
|
||||
if (!actFlowCommonService.taskExists(taskId)) {
|
||||
throw new JeroBootException("任务不存在");
|
||||
}
|
||||
ESArchiveDataVO archiveData = new ESArchiveDataVO();
|
||||
// 使用流程引擎根据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());
|
||||
archiveData.setCommon(commonVO);
|
||||
// 获取流程实例数据
|
||||
LambdaQueryWrapper<ProcessEsArchive> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(ProcessEsArchive::getProcessInstanceId, processInstanceId);
|
||||
lambdaQueryWrapper.eq(ProcessEsArchive::getDelFlag, YesOrNoEnum.NO.getValue());
|
||||
ProcessEsArchive data = getOne(lambdaQueryWrapper);
|
||||
archiveData.setData(data);
|
||||
// 选人组件内容填充
|
||||
archiveData.setFlowUser(this.getProcessUserInfo(processDefinitionId, processInstanceId));
|
||||
return archiveData;
|
||||
}
|
||||
|
||||
private ESArchiveFlowUserVO getProcessUserInfo(String processDefinitionId, String processInstanceId) {
|
||||
List<ProcessNode> nodeList = processNodeService.getNodeList(processDefinitionId, processInstanceId);
|
||||
ESArchiveFlowUserVO flowUser = new ESArchiveFlowUserVO();
|
||||
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(ESArchiveDataVO archiveData, boolean pass) {
|
||||
|
||||
String userId = UserUtils.getUserId();
|
||||
CommonVO commonVO = archiveData.getCommon();
|
||||
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) {
|
||||
ESArchiveFlowUserVO flowUserInfoVO = archiveData.getFlowUser();
|
||||
if (flowUserInfoVO != null) {
|
||||
Map<String, Object> userMap = new HashMap<>(this.setUserVariables(flowUserInfoVO));
|
||||
processNodeLinkService.saveNodeUserLink(processDefinitionId, processInstanceId, userMap);
|
||||
Map<String, Object> variables = setUserVariables(flowUserInfoVO);
|
||||
actFlowCommonService.setProcessVariables(processInstanceId, variables);
|
||||
}
|
||||
runtimeService.setVariable(processInstanceId, "pass", true);
|
||||
} else {
|
||||
// 设置流程变量
|
||||
runtimeService.setVariable(processInstanceId, "pass", false);
|
||||
}
|
||||
// 更新审批表为完成,填充数据
|
||||
actFlowCommonService.updateApprovalInfo(commonVO, taskId, pass);
|
||||
//审批节点
|
||||
actFlowCommonService.completeTask(taskId, userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user