| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | 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.bpm.service.definition.BpmCategoryService; |
| | | import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.performanceappraise.vo.*; |
| | | import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.HrmEmployeeDO; |
| | | import cn.iocoder.yudao.module.hrm.dal.dataobject.performanceappraise.*; |
| | | import cn.iocoder.yudao.module.hrm.dal.mysql.employee.HrmEmployeeMapper; |
| | | 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; |
| | |
| | | private static final Integer SCORER_SUPERIOR = 2; |
| | | |
| | | /** |
| | | * 考核范围类型:1 全部员工 / 2 指定班组 |
| | | */ |
| | | private static final Integer SCOPE_ALL = 1; |
| | | private static final Integer SCOPE_TEAM = 2; |
| | | |
| | | /** |
| | | * 在职员工状态 |
| | | */ |
| | | private static final Integer EMPLOYEE_STATUS_ACTIVE = 1; |
| | | |
| | | /** |
| | | * BPM 绩效考核审批分类编码 |
| | | */ |
| | | private static final String APPRAISE_APPROVE_CATEGORY_CODE = "performance_appraise_approve"; |
| | |
| | | @Resource |
| | | private HrmPerformanceAppraiseResultItemMapper resultItemMapper; |
| | | @Resource |
| | | private HrmEmployeeMapper employeeMapper; |
| | | @Resource |
| | | private BpmProcessInstanceApi bpmProcessInstanceApi; |
| | | @Resource |
| | | private BpmCategoryService bpmCategoryService; |
| | |
| | | HrmPerformanceAppraiseDO appraise = BeanUtils.toBean(createReqVO, HrmPerformanceAppraiseDO.class, req -> req |
| | | .setStatus(STATUS_DRAFT) |
| | | .setAuditStatus(HrmAuditStatusEnum.DRAFT.getStatus())); |
| | | appraise.setScopeTeamIds(CollUtil.isEmpty(createReqVO.getScopeTeamIds()) |
| | | ? null : JSONUtil.toJsonStr(createReqVO.getScopeTeamIds())); |
| | | appraiseMapper.insert(appraise); |
| | | return appraise.getId(); |
| | | } |
| | |
| | | .setStatus(oldAppraise.getStatus()) |
| | | .setAuditStatus(oldAppraise.getAuditStatus()) |
| | | .setProcessInstanceId(oldAppraise.getProcessInstanceId())); |
| | | updateObj.setScopeTeamIds(CollUtil.isEmpty(updateReqVO.getScopeTeamIds()) |
| | | ? null : JSONUtil.toJsonStr(updateReqVO.getScopeTeamIds())); |
| | | appraiseMapper.updateById(updateObj); |
| | | } |
| | | |
| | |
| | | return resultItemMapper.selectListByResultId(resultId); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer generateAppraisees(Long appraiseId) { |
| | | HrmPerformanceAppraiseDO appraise = validateAppraiseExists(appraiseId); |
| | | // 1. 按考核范围筛选员工 |
| | | List<HrmEmployeeDO> employees; |
| | | if (Objects.equals(appraise.getScopeType(), SCOPE_TEAM)) { |
| | | List<Long> teamIds = StrUtil.isEmpty(appraise.getScopeTeamIds()) |
| | | ? Collections.emptyList() : JSONUtil.toList(appraise.getScopeTeamIds(), Long.class); |
| | | if (CollUtil.isEmpty(teamIds)) { |
| | | throw exception(ErrorCodeConstants.PERFORMANCE_APPRAISE_SCOPE_TEAM_EMPTY); |
| | | } |
| | | employees = employeeMapper.selectListByTeamIds(teamIds); |
| | | } else { |
| | | employees = employeeMapper.selectListByStatus(EMPLOYEE_STATUS_ACTIVE); |
| | | } |
| | | if (CollUtil.isEmpty(employees)) { |
| | | return 0; |
| | | } |
| | | // 2. 已存在结果的不再生成(幂等) |
| | | List<HrmPerformanceAppraiseResultDO> existing = resultMapper.selectList( |
| | | new LambdaQueryWrapperX<HrmPerformanceAppraiseResultDO>() |
| | | .eq(HrmPerformanceAppraiseResultDO::getAppraiseId, appraiseId)); |
| | | Set<Long> existingEmployeeIds = convertSet(existing, HrmPerformanceAppraiseResultDO::getEmployeeId); |
| | | // 3. 生成空白结果行 |
| | | int count = 0; |
| | | for (HrmEmployeeDO employee : employees) { |
| | | if (existingEmployeeIds.contains(employee.getId())) { |
| | | continue; |
| | | } |
| | | resultMapper.insert(new HrmPerformanceAppraiseResultDO() |
| | | .setAppraiseId(appraiseId) |
| | | .setEmployeeId(employee.getId())); |
| | | count++; |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | // ========== 私有方法 ========== |
| | | |
| | | private Integer calcGrade(BigDecimal finalScore) { |