| | |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | |
| | | import cn.iocoder.yudao.module.hrm.dal.mysql.performanceappraise.*; |
| | | import cn.iocoder.yudao.module.hrm.enums.HrmAuditStatusEnum; |
| | | import cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants; |
| | | import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
| | | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| | | import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; |
| | | import cn.iocoder.yudao.module.system.api.approval.ApprovalConfigApi; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| | | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| | | |
| | | /** |
| | |
| | | */ |
| | | private static final String APPRAISE_APPROVE_BIZ_TYPE = "performance_appraise_approve"; |
| | | |
| | | /** |
| | | * 绩效考核方案审批的 BPM 流程定义 Key |
| | | */ |
| | | private static final String APPRAISE_APPROVE_PROCESS_KEY = "performance_appraise_approve"; |
| | | |
| | | @Resource |
| | | private HrmPerformanceAppraiseMapper appraiseMapper; |
| | | @Resource |
| | |
| | | private HrmEmployeeMapper employeeMapper; |
| | | @Resource |
| | | private ApprovalConfigApi approvalConfigApi; |
| | | @Resource |
| | | private BpmProcessInstanceApi bpmProcessInstanceApi; |
| | | @Resource |
| | | private AdminUserApi adminUserApi; |
| | | |
| | |
| | | approvalConfigApi.validateApprovalEnabledAndGetApprovers(APPRAISE_APPROVE_BIZ_TYPE); |
| | | |
| | | // 3. 审批状态置为审批中,并清空上一轮审核结果,避免残留「审核不通过」的原因 |
| | | appraiseMapper.submitAndResetAuditInfo(id, HrmAuditStatusEnum.PROCESS.getStatus()); |
| | | if (appraiseMapper.submitAndResetAuditInfo(id, HrmAuditStatusEnum.PROCESS.getStatus()) != 1) { |
| | | throw exception(ErrorCodeConstants.PERFORMANCE_APPRAISE_SUBMIT_FAIL_NOT_EDITABLE); |
| | | } |
| | | |
| | | // 4. 创建 BPM 流程实例,使审批出现在「协同办公 - 我的流程」 |
| | | bpmProcessInstanceApi.createProcessInstance(getLoginUserId(), |
| | | new BpmProcessInstanceCreateReqDTO() |
| | | .setProcessDefinitionKey(APPRAISE_APPROVE_PROCESS_KEY) |
| | | .setBusinessKey(String.valueOf(id))); |
| | | } |
| | | |
| | | @Override |
| | |
| | | throw exception(ErrorCodeConstants.PERFORMANCE_APPRAISE_AUDIT_REJECT_REASON_REQUIRED); |
| | | } |
| | | // 方案状态保持不变 |
| | | appraiseMapper.auditAppraise(id, HrmAuditStatusEnum.REJECT.getStatus(), appraise.getStatus(), |
| | | userId, getUserNickname(userId), reviewRemark); |
| | | if (appraiseMapper.auditAppraise(id, HrmAuditStatusEnum.REJECT.getStatus(), appraise.getStatus(), |
| | | userId, getUserNickname(userId), reviewRemark) != 1) { |
| | | throw exception(ErrorCodeConstants.PERFORMANCE_APPRAISE_AUDIT_FAIL_NOT_PROCESS); |
| | | } |
| | | return; |
| | | } |
| | | // 5. 审核通过:记录审核人与审核意见,审批状态置为审核通过 |
| | | // 6. 审核通过后置业务逻辑:方案状态流转为「已发布」 |
| | | appraiseMapper.auditAppraise(id, HrmAuditStatusEnum.APPROVE.getStatus(), STATUS_PUBLISHED, |
| | | userId, getUserNickname(userId), reviewRemark); |
| | | if (appraiseMapper.auditAppraise(id, HrmAuditStatusEnum.APPROVE.getStatus(), STATUS_PUBLISHED, |
| | | userId, getUserNickname(userId), reviewRemark) != 1) { |
| | | throw exception(ErrorCodeConstants.PERFORMANCE_APPRAISE_AUDIT_FAIL_NOT_PROCESS); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateAppraiseAuditStatus(Long id, Integer bpmStatus, String reason) { |
| | | // BPM 审批结果映射为方案审批状态:通过=20 / 不通过=30 / 取消=40 |
| | | Integer auditStatus; |
| | | if (BpmTaskStatusEnum.APPROVE.getStatus().equals(bpmStatus)) { |
| | | auditStatus = HrmAuditStatusEnum.APPROVE.getStatus(); |
| | | } else if (BpmTaskStatusEnum.REJECT.getStatus().equals(bpmStatus)) { |
| | | auditStatus = HrmAuditStatusEnum.REJECT.getStatus(); |
| | | } else if (BpmTaskStatusEnum.CANCEL.getStatus().equals(bpmStatus)) { |
| | | auditStatus = HrmAuditStatusEnum.CANCEL.getStatus(); |
| | | } else { |
| | | return; |
| | | } |
| | | // 审核通过后方案状态流转为「已发布」,其余情况保持原方案状态 |
| | | HrmPerformanceAppraiseDO appraise = appraiseMapper.selectById(id); |
| | | Integer status = HrmAuditStatusEnum.APPROVE.getStatus().equals(auditStatus) |
| | | ? STATUS_PUBLISHED |
| | | : (appraise != null ? appraise.getStatus() : null); |
| | | if (appraiseMapper.updateAuditStatusByBpm(id, auditStatus, status, reason) != 1) { |
| | | log.warn("[updateAppraiseAuditStatus] 绩效考核方案({}) 不处于审批中状态,忽略 BPM 结果({})", id, bpmStatus); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | .setWeight(weight) |
| | | .setSelfScore(selfScore) |
| | | .setSuperiorScore(superiorScore)); |
| | | } |
| | | // 权重合计为 0 时无法计算加权得分,避免除零 |
| | | if (sumWeight.compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw exception(ErrorCodeConstants.PERFORMANCE_APPRAISE_ITEM_WEIGHT_INVALID); |
| | | } |
| | | BigDecimal selfTotal = weightedSelf.divide(sumWeight, 1, RoundingMode.HALF_UP); |
| | | BigDecimal superiorTotal = weightedSuperior.divide(sumWeight, 1, RoundingMode.HALF_UP); |
| | |
| | | |
| | | private HrmPerformanceAppraiseDO validateAppraiseCanModify(Long id) { |
| | | HrmPerformanceAppraiseDO appraise = validateAppraiseExists(id); |
| | | if (ObjUtil.notEqual(appraise.getStatus(), STATUS_DRAFT)) { |
| | | // 以审批状态为准:仅草稿 / 审核不通过允许修改,审批中禁止修改 |
| | | if (ObjUtil.notEqual(appraise.getAuditStatus(), HrmAuditStatusEnum.DRAFT.getStatus()) |
| | | && ObjUtil.notEqual(appraise.getAuditStatus(), HrmAuditStatusEnum.REJECT.getStatus())) { |
| | | throw exception(ErrorCodeConstants.PERFORMANCE_APPRAISE_UPDATE_FAIL_NOT_DRAFT); |
| | | } |
| | | return appraise; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public HrmPerformanceAppraiseImportRespVO importAppraiseList( |
| | | List<HrmPerformanceAppraiseImportExcelVO> importList, HrmPerformanceAppraiseImportReqVO importReqVO) { |
| | | // 1. 校验非空 |
| | | importList = filterList(importList, item -> StrUtil.isNotBlank(item.getName())); |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(ErrorCodeConstants.PERFORMANCE_APPRAISE_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | // 2. 逐条处理 |
| | | HrmPerformanceAppraiseImportRespVO respVO = HrmPerformanceAppraiseImportRespVO.builder() |
| | | .createNames(new ArrayList<>()) |
| | | .updateNames(new ArrayList<>()) |
| | | .failureNames(new LinkedHashMap<>()) |
| | | .build(); |
| | | importList.forEach(importAppraise -> { |
| | | try { |
| | | // 2.1 判断是否存在(按名称唯一) |
| | | HrmPerformanceAppraiseDO existAppraise = appraiseMapper.selectByName(importAppraise.getName()); |
| | | if (existAppraise == null) { |
| | | // 2.1.1 新增(导入均为草稿) |
| | | HrmPerformanceAppraiseDO appraise = BeanUtils.toBean(importAppraise, HrmPerformanceAppraiseDO.class) |
| | | .setStatus(STATUS_DRAFT) |
| | | .setAuditStatus(HrmAuditStatusEnum.DRAFT.getStatus()); |
| | | if (appraise.getScopeType() == null) { |
| | | appraise.setScopeType(SCOPE_ALL); |
| | | } |
| | | appraiseMapper.insert(appraise); |
| | | respVO.getCreateNames().add(importAppraise.getName()); |
| | | return; |
| | | } |
| | | // 2.1.2 已存在,判断是否允许更新 |
| | | if (!importReqVO.getUpdateSupport()) { |
| | | respVO.getFailureNames().put(importAppraise.getName(), |
| | | StrUtil.format(ErrorCodeConstants.PERFORMANCE_APPRAISE_EXISTS.getMsg(), importAppraise.getName())); |
| | | return; |
| | | } |
| | | HrmPerformanceAppraiseDO updateAppraise = BeanUtils.toBean(importAppraise, HrmPerformanceAppraiseDO.class) |
| | | .setId(existAppraise.getId()) |
| | | .setStatus(existAppraise.getStatus()) |
| | | .setAuditStatus(existAppraise.getAuditStatus()); |
| | | if (updateAppraise.getScopeType() == null) { |
| | | updateAppraise.setScopeType(existAppraise.getScopeType()); |
| | | } |
| | | appraiseMapper.updateById(updateAppraise); |
| | | respVO.getUpdateNames().add(importAppraise.getName()); |
| | | } catch (ServiceException ex) { |
| | | respVO.getFailureNames().put(importAppraise.getName(), ex.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |