feat(workflow): 预算项目流程结束后自动设置项目可见性
- 在 ActListenerService 中添加了流程结束后的处理逻辑,针对预算项目设置项目可见性 - 新增了 ActTaskDefService 中的 findCandidateUsersMap 方法,用于查询流程配置的审批人 - 通过动态获取审批人列表,实现了流程结束后自动设置项目可见性的功能dev_2.0.2
parent
baabb3c5bc
commit
8091bd16f1
|
@ -2,10 +2,9 @@ package cn.palmte.work.service;
|
||||||
|
|
||||||
|
|
||||||
import cn.palmte.work.config.activiti.ActApproveTypeEnum;
|
import cn.palmte.work.config.activiti.ActApproveTypeEnum;
|
||||||
|
import cn.palmte.work.config.activiti.ActProcessKeyEnum;
|
||||||
import cn.palmte.work.config.activiti.ActTaskIndexEnum;
|
import cn.palmte.work.config.activiti.ActTaskIndexEnum;
|
||||||
import cn.palmte.work.model.ActTaskDef;
|
import cn.palmte.work.model.*;
|
||||||
import cn.palmte.work.model.Admin;
|
|
||||||
import cn.palmte.work.model.AdminRepository;
|
|
||||||
import cn.palmte.work.model.enums.ProcessStatus;
|
import cn.palmte.work.model.enums.ProcessStatus;
|
||||||
import cn.palmte.work.utils.ActUtil;
|
import cn.palmte.work.utils.ActUtil;
|
||||||
import org.activiti.engine.RuntimeService;
|
import org.activiti.engine.RuntimeService;
|
||||||
|
@ -16,8 +15,12 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +49,9 @@ public class ActListenerService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ProjectProcessService projectProcessService;
|
ProjectProcessService projectProcessService;
|
||||||
|
@Autowired
|
||||||
|
private ProjectVisibleRepository projectVisibleRepository;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 任务节点创建后监听 动态设置审批人
|
* 任务节点创建后监听 动态设置审批人
|
||||||
|
@ -84,6 +90,7 @@ public class ActListenerService {
|
||||||
*
|
*
|
||||||
* @param delegateExecution
|
* @param delegateExecution
|
||||||
*/
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void end(DelegateExecution delegateExecution) {
|
public void end(DelegateExecution delegateExecution) {
|
||||||
String procInsId = delegateExecution.getProcessInstanceId();
|
String procInsId = delegateExecution.getProcessInstanceId();
|
||||||
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(procInsId).singleResult();
|
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(procInsId).singleResult();
|
||||||
|
@ -97,6 +104,42 @@ public class ActListenerService {
|
||||||
}else if (actUtil.isFourcalProcess(procDefId)){
|
}else if (actUtil.isFourcalProcess(procDefId)){
|
||||||
logger.info("fourcalProcess passed");
|
logger.info("fourcalProcess passed");
|
||||||
projectInstanceService.updateApproveStatus(projectId, procDefKey, ActApproveTypeEnum.APPROVAL_PASSED);
|
projectInstanceService.updateApproveStatus(projectId, procDefKey, ActApproveTypeEnum.APPROVAL_PASSED);
|
||||||
|
// projectBudgetService.getBudget(projectId);
|
||||||
|
//预算项目添加项目可见性
|
||||||
|
try {
|
||||||
|
if (procDefId.startsWith(ActProcessKeyEnum.BUDGET.getKey())) {
|
||||||
|
if (processInstance == null) {
|
||||||
|
logger.error("**** lcjsjt 流程结束监听 查询流程实例为空 procInsId:{} **** ", procInsId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, Object> variables = runtimeService.getVariables(procInsId);
|
||||||
|
List<ProjectVisible> projectVisibleList = new ArrayList<>();
|
||||||
|
Map<String, List<String>> candidateUsersMap = actTaskDefService.findCandidateUsersMap(procDefId);
|
||||||
|
for (Map.Entry<String, List<String>> entry : candidateUsersMap.entrySet()) {
|
||||||
|
//工程管理部
|
||||||
|
if ("工程管理部".equals(entry.getKey()) && variables.get("projectType") != null && !"1".equals(variables.get("projectType").toString())) {
|
||||||
|
//判断是否需要工程管理部的审批人审批
|
||||||
|
continue;
|
||||||
|
} else if ("解决方案协同".equals(entry.getKey()) && variables.get("resolvePlanSynergy") != null && !Boolean.parseBoolean(variables.get("resolvePlanSynergy").toString())) {
|
||||||
|
//判断是否需要解决方案协同审批人审批
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (String s : entry.getValue()) {
|
||||||
|
ProjectVisible projectVisible = new ProjectVisible();
|
||||||
|
projectVisible.setProjectId(projectId);
|
||||||
|
projectVisible.setType(ProjectVisible.TYPE_USER);
|
||||||
|
projectVisible.setTid(Integer.parseInt(s));
|
||||||
|
projectVisibleList.add(projectVisible);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!CollectionUtils.isEmpty(projectVisibleList)) {
|
||||||
|
projectVisibleRepository.save(projectVisibleList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("流程结束后设置项目可见性失败,错误信息为:{},错误详情为:{}", e.getMessage(), e.getStackTrace());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -375,6 +375,56 @@ public class ActTaskDefService {
|
||||||
return resList;
|
return resList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询流程配置的审批人
|
||||||
|
*
|
||||||
|
* @param procDefId
|
||||||
|
* @param procInsId
|
||||||
|
* @param taskDefKey
|
||||||
|
* @return key为流程名称 value为审批人列表
|
||||||
|
* @author ch
|
||||||
|
* @date 2024/12/25 11:30
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Map<String, List<String>> findCandidateUsersMap(String procDefId) {
|
||||||
|
List<ActTaskDef> byProcDefId = findByProcDefId(procDefId);
|
||||||
|
Map<String, List<String>> map = new HashMap<>();
|
||||||
|
for (ActTaskDef taskDef : byProcDefId) {
|
||||||
|
//去重
|
||||||
|
Set<String> res = new HashSet<>();
|
||||||
|
|
||||||
|
//通过人员id查询
|
||||||
|
List<String> candidateUserList = taskDef.getCandidateUserList();
|
||||||
|
logger.info("findCandidateUsers-1-task:{}, userList:{}", taskDef.getTaskName(), candidateUserList);
|
||||||
|
if (!candidateUserList.isEmpty()) {
|
||||||
|
res.addAll(candidateUserList);
|
||||||
|
}
|
||||||
|
|
||||||
|
//通过角色id查询
|
||||||
|
List<String> candidateRoleList = taskDef.getCandidateRoleList();
|
||||||
|
logger.info("findCandidateUsers-2-task:{}, roleList:{}", taskDef.getTaskName(), candidateRoleList);
|
||||||
|
List<String> list = accountService.getUserIsByRole(candidateRoleList);
|
||||||
|
logger.info("findCandidateUsers-3-task:{}, userIdListByRole:{}", taskDef.getTaskName(), list);
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
res.addAll(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
// //通过特殊类型查询 todo 暂不处理特殊类型数据
|
||||||
|
// List<String> candidateTypeList = taskDef.getCandidateTypeList();
|
||||||
|
// logger.info("findCandidateUsers-type-task:{}, typeList:{}", taskDef.getTaskName(), candidateTypeList);
|
||||||
|
// List<String> userListByType = queryCandidatesByTypes(candidateTypeList, taskDef.getProcInsId());
|
||||||
|
// logger.info("findCandidateUsers-type-task:{}, userListByType:{}", taskDef.getTaskName(), userListByType);
|
||||||
|
// if (!userListByType.isEmpty()) {
|
||||||
|
// res.addAll(userListByType);
|
||||||
|
// }
|
||||||
|
|
||||||
|
List<String> resList = new ArrayList<>(res);
|
||||||
|
logger.info("findCandidateUsers-4-task:{}, resIds:{}", taskDef.getTaskName(), resList);
|
||||||
|
map.put(taskDef.getTaskName(), resList);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过类型查找审批人
|
* 通过类型查找审批人
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue