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 694023d9..da61c5f9 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 @@ -21,7 +21,8 @@ public enum BpmTaskRuleScriptEnum { LEADER_X4(23L, "审批人的一级领导"), LEADER_X5(24L, "调岗部门领导"), LEADER_X6(25L, "分配任务的责任人"), - LEADER_X7(26L, "入职部门领导"); + LEADER_X7(26L, "入职部门领导"), + LEADER_X8(27L, "调薪部门领导"); /** * 脚本编号 diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskEntryLeaderScript.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskEntryLeaderScript.java index 7718cac3..1e0ef6ec 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskEntryLeaderScript.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskEntryLeaderScript.java @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; 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; @@ -21,11 +22,14 @@ import java.util.Set; import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; import static java.util.Collections.emptySet; +@Component public class BpmTaskEntryLeaderScript implements BpmTaskAssignScript { @Resource + @Lazy // 解决循环依赖 private DeptApi deptApi; @Resource + @Lazy // 解决循环依赖 private BpmOAEntryService entryService; @Resource @@ -47,7 +51,7 @@ public class BpmTaskEntryLeaderScript implements BpmTaskAssignScript { } //根据流程实例ID 取到调岗流程表单 - BpmOAEntryDO entryDO = entryService.getEntryByProcessInstanceId(processInstance.getProcessInstanceId()); + BpmOAEntryDO entryDO = entryService.getEntry(Long.valueOf(processInstance.getBusinessKey())); //获取调岗部门ID Long deptId = entryDO.getEntryDeptId(); @@ -56,7 +60,7 @@ public class BpmTaskEntryLeaderScript implements BpmTaskAssignScript { if (dept.getLevel() > 3) { //判断部门层级 String[] flag = dept.getFlag().split("-"); - dept = deptApi.getDept(Long.valueOf(flag[2])).getCheckedData(); + dept = deptApi.getDept(Long.valueOf(flag[3])).getCheckedData(); } return dept.getLeaderUserId() != null ? asSet(dept.getLeaderUserId()) : emptySet(); diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskSalaryLeaderScript.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskSalaryLeaderScript.java new file mode 100644 index 00000000..566d51f2 --- /dev/null +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/script/impl/BpmTaskSalaryLeaderScript.java @@ -0,0 +1,75 @@ +package cn.iocoder.yudao.module.bpm.framework.flowable.core.behavior.script.impl; + +import cn.hutool.core.collection.CollUtil; +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 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 BpmTaskSalaryLeaderScript implements BpmTaskAssignScript { + + @Resource + private DeptApi deptApi; + @Resource + @Lazy // 解决循环依赖 + private BpmOASalaryAdjustmentService salaryAdjustmentService; + + @Resource + @Lazy // 解决循环依赖 + private BpmProcessInstanceService bpmProcessInstanceService; + + @Resource + @Lazy // 解决循环依赖 + private BpmTaskService bpmTaskService ; + + @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())); + //获取调岗部门ID + Long deptId = salaryAdjustmentDO.getAdjustmentDeptId(); + + //根据部门ID 获取部门信息 + DeptRespDTO dept = deptApi.getDept(deptId).getCheckedData(); + // 调整人为部门负责人时 + if (dept.getLeaderUserId().equals(salaryAdjustmentDO.getAdjustmentUserId())) { + dept = deptApi.getDept(dept.getParentId()).getCheckedData(); + }else if (dept.getLevel() > 3) { //判断部门层级 + + String[] flag = dept.getFlag().split("-"); + dept = deptApi.getDept(Long.valueOf(flag[3])).getCheckedData(); + } + + return dept.getLeaderUserId() != null ? asSet(dept.getLeaderUserId()) : emptySet(); + } + + @Override + public BpmTaskRuleScriptEnum getEnum() { + return BpmTaskRuleScriptEnum.LEADER_X8; + } +} diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/oa/BpmOASalaryAdjustmentServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/oa/BpmOASalaryAdjustmentServiceImpl.java index 14dc2db0..31447f06 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/oa/BpmOASalaryAdjustmentServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/oa/BpmOASalaryAdjustmentServiceImpl.java @@ -9,6 +9,11 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASalaryAdjustmentDO; import cn.iocoder.yudao.module.bpm.dal.mysql.oa.BpmOASalaryAdjustmentMapper; import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum; import cn.iocoder.yudao.module.bpm.service.task.BpmHistoryProcessInstanceService; +import cn.iocoder.yudao.module.infra.api.config.ConfigApi; +import cn.iocoder.yudao.module.system.api.dept.DeptApi; +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; +import io.netty.util.internal.StringUtil; +import org.mapstruct.ap.internal.util.Strings; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -21,7 +26,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.OA_SALARY_NOT_EXISTS; /** - * OA 薪资付款申请 Service 实现类 + * OA 薪资调整申请 Service 实现类 * * @author 符溶馨 */ @@ -30,7 +35,7 @@ import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.OA_SALARY_NOT public class BpmOASalaryAdjustmentServiceImpl extends BpmOABaseService implements BpmOASalaryAdjustmentService{ /** - * OA 薪资付款对应的流程定义 KEY + * OA 薪资调整对应的流程定义 KEY */ public static final String PROCESS_KEY = "oa_salary_adjustment_2"; @@ -43,16 +48,39 @@ public class BpmOASalaryAdjustmentServiceImpl extends BpmOABaseService implement @Resource private BpmHistoryProcessInstanceService historyProcessInstanceService; + @Resource + private DeptApi deptApi; + + @Resource + private ConfigApi configApi; + @Override public Long createSalaryAdjustment(Long userId, BpmOASalaryAdjustmentCreateReqVO createReqVO) { - //插入OA 薪资付款申请 + //插入OA 薪资调整申请 BpmOASalaryAdjustmentDO salary = BpmOASalaryAdjustmentConvert.INSTANCE.convert(createReqVO).setUserId(userId) .setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()); salaryMapper.insert(salary) ; - // 发起 BPM 流程 + // 获取调整人所在部门信息 + DeptRespDTO deptRespDTO = deptApi.getDept(createReqVO.getAdjustmentDeptId()).getCheckedData(); + + // 配置变量 调整人部门flag Map processInstanceVariables = new HashMap<>(); + processInstanceVariables.put("company_dept_flag", deptRespDTO.getFlag()); + + if (deptRespDTO.getLevel() == 2 && deptRespDTO.getLeaderUserId().equals(createReqVO.getAdjustmentUserId())) { + processInstanceVariables.put("is_leader", 1); + }else { + processInstanceVariables.put("is_leader", 0); + } + + // 查询配置文件,获取行政部门编号 + String hrDeptId = configApi.getConfigKey("system_hr_dept").getCheckedData(); + if (Strings.isNotEmpty(hrDeptId)) { + processInstanceVariables.put("hr_dept", hrDeptId); + } + // 发起 BPM 流程 String processInstanceId = processInstanceApi.createProcessInstance(userId, new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY) .setVariables(processInstanceVariables).setBusinessKey(String.valueOf(salary.getId()))).getCheckedData();