| | |
| | | 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 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; |
| | | |
| | | /** |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | .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; |
| | | } |
| | | |
| | | } |