优化流程实例变量配置和任务审批逻辑
- 将流程发起人和审批人的用户信息和部门信息的获取逻辑统一移至 BpmProcessInstanceServiceImpl 类 - 优化了入职、用章、薪资付款、转正等流程的变量配置逻辑,避免重复代码 -简化了任务审批逻辑,移除了不必要的判断条件和冗余代码 - 优化了 BpmTaskEntryLeaderScript 中的部门层级判断逻辑
This commit is contained in:
parent
7de24693c3
commit
5b31190d35
@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.entry;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.common.pojo.UploadUserFile;
|
||||
import cn.iocoder.yudao.framework.common.validation.IdCard;
|
||||
import cn.iocoder.yudao.framework.common.validation.Mobile;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
@ -39,9 +41,12 @@ public class BpmOAEntryCreateReqVO {
|
||||
|
||||
@Schema(description = "手机号码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "手机号码不能为空")
|
||||
@Mobile(message = "手机号码格式不正确")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "身份证号码")
|
||||
@NotNull(message = "身份证号码不能为空")
|
||||
@IdCard(message = "身份证号码格式不正确")
|
||||
private String idcard;
|
||||
|
||||
@Schema(description = "入职时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ -50,7 +55,7 @@ public class BpmOAEntryCreateReqVO {
|
||||
private LocalDate entryDate;
|
||||
|
||||
@Schema(description = "面试评价", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "面试评价不能为空")
|
||||
@NotNull(message = "面试评价不能为空")
|
||||
private String interviewEvaluation;
|
||||
|
||||
@Schema(description = "薪资情况", example = "27005")
|
||||
|
@ -55,8 +55,8 @@ public class BpmTaskEntryLeaderScript implements BpmTaskAssignScript {
|
||||
DeptRespDTO dept = deptApi.getDept(deptId).getCheckedData();
|
||||
if (dept.getLevel() > 3) { //判断部门层级
|
||||
|
||||
String [] flag = dept.getFlag().split("-");
|
||||
dept = deptApi.getDept(Long.valueOf(flag[3])).getCheckedData();
|
||||
String[] flag = dept.getFlag().split("-");
|
||||
dept = deptApi.getDept(Long.valueOf(flag[2])).getCheckedData();
|
||||
}
|
||||
|
||||
return dept.getLeaderUserId() != null ? asSet(dept.getLeaderUserId()) : emptySet();
|
||||
|
@ -16,6 +16,8 @@ import cn.iocoder.yudao.module.bpm.service.task.BpmHistoryProcessInstanceService
|
||||
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
|
||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
||||
import cn.iocoder.yudao.module.infra.api.file.dto.UserFileUpdateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.UserSaveRespDTO;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
@ -69,6 +71,9 @@ public class BpmOAEntryServiceImpl implements BpmOAEntryService{
|
||||
@Resource
|
||||
private BpmHistoryProcessInstanceService historyProcessInstanceService;
|
||||
|
||||
@Resource
|
||||
private DeptApi deptApi;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createEntry(BpmOAEntryCreateReqVO createReqVO) {
|
||||
@ -79,8 +84,13 @@ public class BpmOAEntryServiceImpl implements BpmOAEntryService{
|
||||
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||
entryMapper.insert(entry) ;
|
||||
|
||||
// 发起 BPM 流程
|
||||
// 获取入职部门信息
|
||||
DeptRespDTO dto = deptApi.getDept(entry.getEntryDeptId()).getCheckedData();
|
||||
|
||||
Map<String, Object> processInstanceVariables = new HashMap<>();
|
||||
//配置入职部门flag
|
||||
processInstanceVariables.put("entry_dept_flag", dto.getFlag());
|
||||
// 发起 BPM 流程
|
||||
String processInstanceId = processInstanceApi.createProcessInstance(entry.getUserId(),
|
||||
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(entry.getId()))).getCheckedData();
|
||||
|
@ -9,6 +9,8 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASalaryDO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.mysql.oa.BpmOaSalaryMapper;
|
||||
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import cn.iocoder.yudao.module.bpm.service.task.BpmHistoryProcessInstanceService;
|
||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@ -43,6 +45,9 @@ public class BpmOASalaryServiceImpl extends BpmOABaseService implements BpmOASal
|
||||
@Resource
|
||||
private BpmHistoryProcessInstanceService historyProcessInstanceService;
|
||||
|
||||
@Resource
|
||||
private DeptApi deptApi;
|
||||
|
||||
@Override
|
||||
public Long createSalary(Long userId, BpmOASalaryCreateReqVO createReqVO) {
|
||||
|
||||
@ -51,8 +56,13 @@ public class BpmOASalaryServiceImpl extends BpmOABaseService implements BpmOASal
|
||||
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||
salaryMapper.insert(salary) ;
|
||||
|
||||
// 发起 BPM 流程
|
||||
// 获取申请公司或工厂信息
|
||||
DeptRespDTO dto = deptApi.getDept(salary.getCompanyDeptId()).getCheckedData();
|
||||
|
||||
// 配置申请公司或工厂部门flag
|
||||
Map<String, Object> processInstanceVariables = new HashMap<>();
|
||||
processInstanceVariables.put("company_dept_flag", dto.getFlag());
|
||||
// 发起 BPM 流程
|
||||
String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
||||
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(salary.getId()))).getCheckedData();
|
||||
|
@ -9,6 +9,8 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASealDO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.mysql.oa.BpmOASealMapper;
|
||||
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import cn.iocoder.yudao.module.bpm.service.task.BpmHistoryProcessInstanceService;
|
||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@ -44,6 +46,9 @@ public class BpmOASealServiceImpl extends BpmOABaseService implements BpmOASealS
|
||||
@Resource
|
||||
private BpmHistoryProcessInstanceService historyProcessInstanceService;
|
||||
|
||||
@Resource
|
||||
private DeptApi deptApi;
|
||||
|
||||
@Override
|
||||
public Long createSeal(Long userId, BpmOASealCreateReqVO createReqVO) {
|
||||
|
||||
@ -52,8 +57,13 @@ public class BpmOASealServiceImpl extends BpmOABaseService implements BpmOASealS
|
||||
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||
sealMapper.insert(seal) ;
|
||||
|
||||
// 发起 BPM 流程
|
||||
// 获取用章公司的部门信息
|
||||
DeptRespDTO dto = deptApi.getDept(seal.getContractCompany()).getCheckedData();
|
||||
|
||||
//配置合同公司flag
|
||||
Map<String, Object> processInstanceVariables = new HashMap<>();
|
||||
processInstanceVariables.put("contract_company_flag", dto.getFlag());
|
||||
// 发起 BPM 流程
|
||||
String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
||||
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(seal.getId()))).getCheckedData();
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.task;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
@ -494,105 +495,42 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||
// 情况三:自己审批的任务,调用 complete 去完成任务
|
||||
// 完成任务,审批通过,并设置paramMap的post_id值
|
||||
// paramMap 中的值,可用于流程图中分支路线条件
|
||||
/**
|
||||
/*
|
||||
* 判定流程的走向,这里是流程审核节点(就是流程设计中的任意审核节点)
|
||||
* 根据当前审核人的岗位判定流程走向
|
||||
*/
|
||||
Map<String, Object> paramMap = instance.getProcessVariables();
|
||||
Map<String, Object> paramMap = processInstanceExtMapper.selectOne(BpmProcessInstanceExtDO::getProcessInstanceId, instance.getProcessInstanceId()).getFormVariables();
|
||||
|
||||
// // 获得 User
|
||||
// AdminUserRespDTO examineUser = adminUserApi.getUser(userId).getCheckedData();
|
||||
// 获得审批人User
|
||||
AdminUserRespDTO examineUser = adminUserApi.getUser(userId).getCheckedData();
|
||||
//获取流程审批人部门信息
|
||||
DeptRespDTO examineDept = deptApi.getDept(examineUser.getDeptId()).getCheckedData();
|
||||
|
||||
// // 获取部门信息
|
||||
// Long deptId = examineUser.getDeptId();
|
||||
|
||||
//获取流程发起人User
|
||||
AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(instance.getStartUserId())).getCheckedData();
|
||||
//获取流程发起人部门信息
|
||||
DeptRespDTO startDeptInfo = deptApi.getDept(startUser.getDeptId()).getCheckedData();
|
||||
// 获取岗位信息
|
||||
Set<Long> postIds = startUser.getPostIds();
|
||||
if (CollectionUtil.isEmpty(examineUser.getPostIds())) {
|
||||
// 当前审批用户未配置岗位
|
||||
// 操作失败,原因:您未配置岗位,请联系管理员操作
|
||||
throw exception(TASK_OPERATE_FAIL_USER_NO_POST);
|
||||
}
|
||||
if( examineUser.getDeptId() == null ) {
|
||||
// 当前审批用户未配置部门
|
||||
// 操作失败,原因:您未配置部门,请联系管理员操作
|
||||
throw exception(TASK_OPERATE_FAIL_USER_NO_DEPT);
|
||||
}
|
||||
|
||||
//根据审批人用户ID,获取审批人 担任的负责人的部门信息
|
||||
List<DeptRespDTO> deptRespDTOs = deptApi.getDeptByLeaderId(userId).getCheckedData();
|
||||
|
||||
// 设置审批人所在部门的负责人
|
||||
paramMap.put("leader_id", examineDept.getLeaderUserId().toString());
|
||||
//遍历查找, 发起人的上级部门
|
||||
for (DeptRespDTO deptRespDTO : deptRespDTOs) {
|
||||
if (startDeptInfo.getFlag().contains(deptRespDTO.getFlag())) {
|
||||
if (paramMap.get("dept_flag").toString().contains(deptRespDTO.getFlag())) {
|
||||
|
||||
paramMap.put("level", deptRespDTO.getLevel().toString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//如果审核人是发起人的时候
|
||||
if (userId.toString().equals(instance.getStartUserId())) {
|
||||
//获取发起人部门负责人编号和部门层级
|
||||
paramMap.put("leader_id", startDeptInfo.getLeaderUserId().toString());
|
||||
paramMap.put("level", startDeptInfo.getLevel().toString());
|
||||
}
|
||||
|
||||
if (postIds == null || postIds.isEmpty()) {
|
||||
// 当前审批用户未配置岗位
|
||||
// 操作失败,原因:您未配置岗位,请联系管理员操作
|
||||
throw exception(TASK_OPERATE_FAIL_USER_NO_POST);
|
||||
}
|
||||
// if( deptId == null ) {
|
||||
// // 当前审批用户未配置部门
|
||||
// // 操作失败,原因:您未配置部门,请联系管理员操作
|
||||
// throw exception(TASK_OPERATE_FAIL_USER_NO_DEPT);
|
||||
// }
|
||||
|
||||
// 判断 入职申请流程时
|
||||
if (instance.getProcessDefinitionId().contains("oa_entry")) {
|
||||
|
||||
BpmOAEntryDO entryDO = bpmOAEntryService.getEntryByProcessInstanceId(instance.getProcessInstanceId());
|
||||
if (entryDO != null) {
|
||||
|
||||
DeptRespDTO dto = deptApi.getDept(entryDO.getEntryDeptId()).getCheckedData();
|
||||
paramMap.put("entry_dept_flag", dto.getFlag()); //配置入职部门flag
|
||||
}
|
||||
}
|
||||
|
||||
// 判断 用章流程时
|
||||
if (instance.getProcessDefinitionId().contains("oa_seal")) {
|
||||
|
||||
BpmOASealDO sealDO = bpmOASealService.getByProcessInstanceId(instance.getProcessInstanceId());
|
||||
if (sealDO != null) {
|
||||
|
||||
DeptRespDTO dto = deptApi.getDept(sealDO.getContractCompany()).getCheckedData();
|
||||
paramMap.put("contract_company_flag", dto.getFlag()); //配置合同公司flag
|
||||
}
|
||||
}
|
||||
|
||||
// 判断 薪资付款流程时
|
||||
if (instance.getProcessDefinitionId().contains("oa_salary")) {
|
||||
BpmOASalaryDO salaryDO = bpmOASalaryService.getByProcessInstanceId(instance.getProcessInstanceId());
|
||||
if (salaryDO != null) {
|
||||
|
||||
DeptRespDTO dto = deptApi.getDept(salaryDO.getCompanyDeptId()).getCheckedData();
|
||||
paramMap.put("company_dept_flag", dto.getFlag()); //配置工厂idflag
|
||||
}
|
||||
}
|
||||
|
||||
// 判断 转正流程时
|
||||
if (instance.getProcessDefinitionId().contains("oa_regular")) {
|
||||
BpmOARegularDO regularDO = bpmOARegularService.getByProcessInstanceId(instance.getProcessInstanceId());
|
||||
if (regularDO != null) {
|
||||
|
||||
DeptRespDTO dto = deptApi.getDept(regularDO.getDeptId()).getCheckedData();
|
||||
paramMap.put("regular_dept_flag", dto.getFlag()); //配置工厂idflag
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<Long> list = new ArrayList<>(postIds);
|
||||
// 只获配置的首个岗位
|
||||
Long postId = list.get(0);
|
||||
paramMap.put("post_id", postId.toString());
|
||||
paramMap.put("user_id", userId.toString());
|
||||
paramMap.put("dept_id", startUser.getDeptId().toString()); //配置发起人部门id
|
||||
paramMap.put("dept_flag", startDeptInfo.getFlag()); //配置发起人部门flag
|
||||
|
||||
paramMap.put("approve_reason", reqVO.getReason()); //通过原因---因为Task任务的通过,是通过监听事件处理的,reason数据无法传递给监听函数。所以通过此中方法传递
|
||||
taskService.complete(task.getId(), paramMap);
|
||||
// 更新任务拓展表为通过
|
||||
|
Loading…
Reference in New Issue
Block a user