perf: 优化企标立项变更发起流程

This commit is contained in:
2023-10-26 11:06:10 +08:00
parent e8c3af4ea4
commit ef794cda8d
3 changed files with 39 additions and 102 deletions
@@ -44,7 +44,7 @@ public class ActFlowCommonService {
/** /**
* 启动流程实例 * 启动流程实例
*/ */
public ProcessInstance startProcess(String processDefinitionKey, InitChangeDataVO initChangeData, Map<String, Object> variables) { public ProcessInstance startProcess(String processDefinitionKey, Map<String, Object> variables) {
ProcessDefinition latestProcessDefinition = repositoryService.createProcessDefinitionQuery() ProcessDefinition latestProcessDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey(processDefinitionKey) .processDefinitionKey(processDefinitionKey)
.orderByProcessDefinitionVersion().desc() .orderByProcessDefinitionVersion().desc()
@@ -58,29 +58,25 @@ public class ActFlowCommonService {
// 流程定义ID // 流程定义ID
String processDefinitionId = processInstance.getProcessDefinitionId(); String processDefinitionId = processInstance.getProcessDefinitionId();
log.info("【启动流程】- 成功,processDefinitionId{}", processDefinitionId); log.info("【启动流程】- 成功,processDefinitionId{}", processDefinitionId);
log.info("启动流程实例成功,流程定义ID为:{}", processDefinitionId);
return processInstance; return processInstance;
} }
/** /**
* 完成提交任务 * 完成提交任务
*/ */
public void completeTask(String remark, String taskId, String userId, Map<String, Object> map) { public void completeTask(String taskId, String userId, Map<String, Object> map) {
//任务Id 查询任务对象 //任务Id 查询任务对象
Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (!taskExists(taskId)) {
if (task == null) {
log.error("找不到对应任务"); log.error("找不到对应任务");
throw new JeroBootException("找不到对应任务"); throw new JeroBootException("找不到对应任务");
} }
//任务对象 获取流程实例Id //任务对象 获取流程实例Id
String processInstanceId = task.getProcessInstanceId(); String processInstanceId = task.getProcessInstanceId();
//设置审批人的userId //设置审批人的userId
Authentication.setAuthenticatedUserId(userId); Authentication.setAuthenticatedUserId(userId);
//添加记录 //添加记录
taskService.addComment(taskId, processInstanceId, remark);
log.info("-----------完成任务操作 开始----------"); log.info("-----------完成任务操作 开始----------");
log.info("任务Id=" + taskId); log.info("任务Id=" + taskId);
log.info("负责人id=" + userId); log.info("负责人id=" + userId);
@@ -121,37 +117,6 @@ public class ActFlowCommonService {
return listMap; return listMap;
} }
/**
* 查看个人任务信息
*/
public List<Map<String, Object>> taskInfoList(String userid, CenterQueryVO centerQueryVO, Integer pageNo, Integer pageSize) {
//TODO 分页
TaskQuery taskQuery = taskService.createTaskQuery().taskAssignee(userid);
List<Task> list = taskQuery.orderByTaskCreateTime().desc().list();
List<Map<String, Object>> listMap = new ArrayList<>();
for (Task task : list) {
Map<String, Object> map = new HashMap<>();
map.put("taskId", task.getId());
map.put("prcId", task.getProcessInstanceId());
map.put("prcName", task.getProcessDefinitionId());
LoginUser assigneeUser = sysBaseAPI.getUserById(task.getAssignee());
map.put("assignee", assigneeUser.getId());
map.put("assigneeText", assigneeUser.getUsername());
map.put("claimTaskTime", task.getCreateTime());
ProcessInstance processInstance = runtimeService
.createProcessInstanceQuery()
.processInstanceId(task.getProcessInstanceId())
.singleResult();
//TODO 根据流程Id找到对应业务流程实体
listMap.add(map);
}
return listMap;
}
/** /**
* 转办 * 转办
*/ */
@@ -160,18 +125,6 @@ public class ActFlowCommonService {
log.info("转办 任务Id:{} 转办用户Id{}", taskId, userId); log.info("转办 任务Id:{} 转办用户Id{}", taskId, userId);
} }
/**
* 待办任务列表
* @param centerQueryVO
* @param pageNo
* @param pageSize
* @return
*/
public List<Map<String, Object>> todoTaskList(CenterQueryVO centerQueryVO, Integer pageNo, Integer pageSize) {
String userId = UserUtils.getUserId();
return this.taskInfoList(userId, centerQueryVO, pageNo, pageSize);
}
/** /**
* 判断任务是否存在 * 判断任务是否存在
* @param taskId * @param taskId
@@ -211,7 +164,7 @@ public class ActFlowCommonService {
log.info("当前用户ID:{},相关联的流程定义ID:{}", userId, map.get("processDefinitionId").toString()); log.info("当前用户ID:{},相关联的流程定义ID:{}", userId, map.get("processDefinitionId").toString());
log.info("匹配到的任务ID{}", map.get("taskId").toString()); log.info("匹配到的任务ID{}", map.get("taskId").toString());
this.completeTask("同意", map.get("taskId").toString(), userId, map); this.completeTask(map.get("taskId").toString(), userId, map);
break; break;
} }
} }
@@ -102,7 +102,7 @@ public class ProcessEsAnnualReportServiceImpl extends ServiceImpl<ProcessEsAnnua
// TODO 根据当前节点类型保存数据 // TODO 根据当前节点类型保存数据
// 设置流程变量 // 设置流程变量
// 完成任务 // 完成任务
actFlowCommonService.completeTask("同意", taskId, userId, null); actFlowCommonService.completeTask(taskId, userId, null);
} }
@Override @Override
@@ -28,8 +28,6 @@ import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task; import org.activiti.engine.task.Task;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -60,35 +58,6 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
@Resource @Resource
private EnterpriseStandardUtil esUtil; private EnterpriseStandardUtil esUtil;
public Map<String, Object> setVariables(InitChangeDataVO initChangeData) {
FlowUserInfoVO flowUserInfoVO = initChangeData.getFlowUserInfoVO();
ProcessEsInitChange initChange = initChangeData.getDataList().get(0);
Map<String, Object> map = new HashMap<>();
// 设置流程中各个节点的人
map.put("createUser", UserUtils.getUserIdByUserName(flowUserInfoVO.getCreateUser()));
map.put("contactUser", flowUserInfoVO.getContactUser());
map.put("standardExpertList", Optional.ofNullable(flowUserInfoVO.getStandardExpert()).map(s -> Arrays.asList(s.split(","))).orElse(Collections.emptyList()));
map.put("mainDraftUserLeader", flowUserInfoVO.getMainDraftUserLeader());
map.put("mainDraftUserLeaderLeader", flowUserInfoVO.getMainDraftUserLeaderLeader());
map.put("standardizationApprovalUser", flowUserInfoVO.getStandardizationApprovalUser());
map.put("newMainDraftUserLeaderLeader", flowUserInfoVO.getNewMainDraftUserLeaderLeader());
map.put("newMainDraftUserLeader", flowUserInfoVO.getNewMainDraftUserLeader());
map.put("relatedUserList", Optional.ofNullable(flowUserInfoVO.getRelatedUser()).map(s -> Arrays.asList(s.split(","))).orElse(Collections.emptyList()));
map.put("copyUser", flowUserInfoVO.getCopyUser());
// 设置流程分支判断变量
map.put("applicationCategory", initChange.getApplicationCategory());
map.put("projectType", initChange.getProjectType());
return map;
}
public void startRunTask(InitChangeDataVO initChangeData) {
List<ProcessEsInitChange> esInitChangeList = initChangeData.getDataList();
// 校验企标编号是否冲突
if (!esUtil.verifyEnStandardNumber(esInitChangeList.get(0).getOriginEnStandardNo())) {
throw new JeroBootException("企标编号冲突,请重新生成");
}
}
@Override @Override
public InitChangeDataVO getHandleData(String taskId) { public InitChangeDataVO getHandleData(String taskId) {
InitChangeDataVO initChangeDataVO = new InitChangeDataVO(); InitChangeDataVO initChangeDataVO = new InitChangeDataVO();
@@ -114,6 +83,7 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
@Override @Override
public void startInitChange(InitChangeDataVO initChangeData) { public void startInitChange(InitChangeDataVO initChangeData) {
// 执行流程发起前的操作
this.startRunTask(initChangeData); this.startRunTask(initChangeData);
// 流程Key // 流程Key
@@ -124,28 +94,13 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
// 设置流程变量 // 设置流程变量
Map<String, Object> variables = setVariables(initChangeData); Map<String, Object> variables = setVariables(initChangeData);
// 启动流程 // 启动流程
ProcessInstance processInstance = actFlowCommonService.startProcess(processDefinitionKey, initChangeData, variables); ProcessInstance processInstance = actFlowCommonService.startProcess(processDefinitionKey, variables);
// 获取流程实例ID // 获取流程实例ID
String processDefinitionId = processInstance.getProcessDefinitionId(); String processDefinitionId = processInstance.getProcessDefinitionId();
String processInstanceId = processInstance.getId(); String processInstanceId = processInstance.getId();
log.info("启动流程实例成功,流程定义ID为:{}", processDefinitionId); // 自动完成第一个任务
// 完成第一个任务 actFlowCommonService.autoCompleteFirstTask(userId, processInstanceId, processDefinitionId);
List<Map<String, Object>> taskList = actFlowCommonService.myTaskList(userId);
if (!CollectionUtils.isEmpty(taskList)) {
for (Map<String, Object> map : taskList) {
if (map.get("assignee").toString().equals(userId) &&
map.get("processDefinitionId").toString().equals(processDefinitionId) &&
map.get("processInstanceId").toString().equals(processInstanceId)) { // 添加这一行来进行更精确的匹配
log.info("当前用户ID:{},相关联的流程定义ID:{}", userId, map.get("processDefinitionId").toString());
log.info("匹配到的任务ID{}", map.get("taskId").toString());
actFlowCommonService.completeTask("同意", map.get("taskId").toString(), userId, map);
break;
}
}
}
// 设置流程实例Id // 设置流程实例Id
for (ProcessEsInitChange esInitChange : esInitChangeList) { for (ProcessEsInitChange esInitChange : esInitChangeList) {
esInitChange.setProcessInstanceId(processInstance.getId()); esInitChange.setProcessInstanceId(processInstance.getId());
@@ -215,6 +170,35 @@ public class ProcessEsInitChangeServiceImpl extends ServiceImpl<ProcessEsInitCha
// processDraftService.saveBatch(draftList); // processDraftService.saveBatch(draftList);
} }
public Map<String, Object> setVariables(InitChangeDataVO initChangeData) {
FlowUserInfoVO flowUserInfoVO = initChangeData.getFlowUserInfoVO();
ProcessEsInitChange initChange = initChangeData.getDataList().get(0);
Map<String, Object> map = new HashMap<>();
// 设置流程中各个节点的人
map.put("createUser", UserUtils.getUserIdByUserName(flowUserInfoVO.getCreateUser()));
map.put("contactUser", flowUserInfoVO.getContactUser());
map.put("standardExpertList", Optional.ofNullable(flowUserInfoVO.getStandardExpert()).map(s -> Arrays.asList(s.split(","))).orElse(Collections.emptyList()));
map.put("mainDraftUserLeader", flowUserInfoVO.getMainDraftUserLeader());
map.put("mainDraftUserLeaderLeader", flowUserInfoVO.getMainDraftUserLeaderLeader());
map.put("standardizationApprovalUser", flowUserInfoVO.getStandardizationApprovalUser());
map.put("newMainDraftUserLeaderLeader", flowUserInfoVO.getNewMainDraftUserLeaderLeader());
map.put("newMainDraftUserLeader", flowUserInfoVO.getNewMainDraftUserLeader());
map.put("relatedUserList", Optional.ofNullable(flowUserInfoVO.getRelatedUser()).map(s -> Arrays.asList(s.split(","))).orElse(Collections.emptyList()));
map.put("copyUser", flowUserInfoVO.getCopyUser());
// 设置流程分支判断变量
map.put("applicationCategory", initChange.getApplicationCategory());
map.put("projectType", initChange.getProjectType());
return map;
}
public void startRunTask(InitChangeDataVO initChangeData) {
List<ProcessEsInitChange> esInitChangeList = initChangeData.getDataList();
// 校验企标编号是否冲突
if (!esUtil.verifyEnStandardNumber(esInitChangeList.get(0).getOriginEnStandardNo())) {
throw new JeroBootException("企标编号冲突,请重新生成");
}
}
@Override @Override
public void removeByProcessInstanceId(String processInstanceId) { public void removeByProcessInstanceId(String processInstanceId) {
LambdaUpdateWrapper<ProcessEsInitChange> updateWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<ProcessEsInitChange> updateWrapper = new LambdaUpdateWrapper<>();