diff --git a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmTaskRuleScriptEnum.java b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmTaskRuleScriptEnum.java index da61c5f9..dccf2c7c 100644 --- a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmTaskRuleScriptEnum.java +++ b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmTaskRuleScriptEnum.java @@ -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, "调薪人上级领导"); /** * 脚本编号 diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskSalaryAssignLeaderScript.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskSalaryAssignLeaderScript.java new file mode 100644 index 00000000..48299639 --- /dev/null +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskSalaryAssignLeaderScript.java @@ -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 calculateTaskCandidateUsers(DelegateExecution execution) { + + // 获得发起人 + ProcessInstance processInstance = bpmProcessInstanceService.getProcessInstance(execution.getProcessInstanceId()); + List 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(); + } +}