feat(bpm): 新增调薪人上级领导任务规则脚本- 在 BpmTaskRuleScriptEnum 中添加 LEADER_X9 枚举项

- 实现 BpmTaskSalaryAssignLeaderScript 类,用于计算调薪人上级领导
- 在 BpmOACashDO 和相关 VO 中添加 difference 字段,用于表示备用金差额
- 优化 BpmOASalaryAdjustmentServiceImpl 中的流程发起逻辑
This commit is contained in:
furongxin 2024-10-22 21:33:15 +08:00
parent 56b5828177
commit d100f546ef
2 changed files with 120 additions and 1 deletions

View File

@ -22,7 +22,8 @@ public enum BpmTaskRuleScriptEnum {
LEADER_X5(24L, "调岗部门领导"),
LEADER_X6(25L, "分配任务的责任人"),
LEADER_X7(26L, "入职部门领导"),
LEADER_X8(27L, "调薪部门领导");
LEADER_X8(27L, "调薪部门领导"),
LEADER_X9(28L, "调薪人上级领导");
/**
* 脚本编号

View File

@ -0,0 +1,118 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.behavior.script.impl;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASalaryAdjustmentDO;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmTaskRuleScriptEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.behavior.script.BpmTaskAssignScript;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOASalaryAdjustmentService;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
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.AdminUserRespDTO;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;
import static java.util.Collections.emptySet;
@Component
public class BpmTaskSalaryAssignLeaderScript implements BpmTaskAssignScript {
@Resource
private DeptApi deptApi;
@Resource
@Lazy // 解决循环依赖
private BpmOASalaryAdjustmentService salaryAdjustmentService;
@Resource
@Lazy // 解决循环依赖
private BpmProcessInstanceService bpmProcessInstanceService;
@Resource
@Lazy // 解决循环依赖
private BpmTaskService bpmTaskService ;
@Resource
private AdminUserApi adminUserApi;
@Override
public Set<Long> calculateTaskCandidateUsers(DelegateExecution execution) {
// 获得发起人
ProcessInstance processInstance = bpmProcessInstanceService.getProcessInstance(execution.getProcessInstanceId());
List<BpmTaskRespVO> bpmTaskRespVOs = bpmTaskService.getTaskListByProcessInstanceId(processInstance.getProcessInstanceId());
if (CollUtil.isEmpty(bpmTaskRespVOs)) {
return emptySet();
}
//根据流程实例ID 取到调岗流程表单
BpmOASalaryAdjustmentDO salaryAdjustmentDO = salaryAdjustmentService.getSalaryAdjustment(Long.valueOf(processInstance.getBusinessKey()));
Long startUserId = salaryAdjustmentDO.getAdjustmentUserId();
//获取最后一个Task任务相关数据
BpmTaskRespVO bpmTaskRespVO = bpmTaskRespVOs.get(0) ;
Long assigneeUserId = bpmTaskRespVO.getAssigneeUser().getId() ;
// 获得对应 发起人 的部门
DeptRespDTO dept = getUserDept(startUserId);
if (dept == null) { // 找不到发起人的部门所以无法使用该规则
return emptySet();
}
int count = 0;
Long parentId = dept.getParentId();
for (int i = 0; i < dept.getLevel(); i++) {
if (i == 0) { //第一次查找 判断审批人是否为发起人部门负责人
if (assigneeUserId.toString().equals(processInstance.getStartUserId())
&& !dept.getLeaderUserId().toString().equals(processInstance.getStartUserId())){ //如果发起人不是所在部门负责人时
count = 1;
break;
}
}
//获得发起人的上级部门
DeptRespDTO parentDept = deptApi.getDept(parentId).getCheckedData();
if (parentDept == null) { // 找不到父级部门所以只好结束寻找原因是例如说级别比较高的人所在部门层级比较少
return emptySet();
}
if (!parentDept.getLeaderUserId().toString().equals(assigneeUserId.toString())){ //如果发起人上级部门负责人不为当前审批人时
dept = parentDept;
count = 1;
break;
}
parentId = parentDept.getParentId();
}
if (count == 0){// 找不到父级部门原因是人的所属部门配在了最高节点了
return emptySet();
}
return dept.getLeaderUserId() != null ? asSet(dept.getLeaderUserId()) : emptySet();
}
@Override
public BpmTaskRuleScriptEnum getEnum() {
return BpmTaskRuleScriptEnum.LEADER_X9;
}
private DeptRespDTO getUserDept(Long userId) {
AdminUserRespDTO user = adminUserApi.getUser(userId).getCheckedData();
if (user.getDeptId() == null) { // 找不到部门所以无法使用该规则
return null;
}
return deptApi.getDept(user.getDeptId()).getCheckedData();
}
}