| | |
| | | package cn.iocoder.yudao.module.hrm.controller.admin.performanceappraise; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| | | 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 io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import jakarta.validation.Valid; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Collections; |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | 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.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| | | |
| | | @Tag(name = "管理后台 - HRM 绩效考核方案") |
| | | @RestController |
| | |
| | | |
| | | // ========== 审批 ========== |
| | | |
| | | @PostMapping("/submit") |
| | | @Operation(summary = "提交绩效考核方案审批") |
| | | @PutMapping("/submit") |
| | | @Operation(summary = "提交审批(草稿/审核不通过→审批中),审批人由审批配置统一指定") |
| | | @Parameter(name = "id", description = "方案编号", required = true) |
| | | @Parameter(name = "processDefinitionKey", description = "流程定义Key", required = true) |
| | | @PreAuthorize("@ss.hasPermission('hrm:performance-appraise:submit')") |
| | | public CommonResult<Boolean> submitAppraise(@RequestParam("id") Long id, |
| | | @RequestParam("processDefinitionKey") String processDefinitionKey) { |
| | | appraiseService.submitAppraise(id, processDefinitionKey, getLoginUserId()); |
| | | @PreAuthorize("@ss.hasPermission('hrm:performance-appraise:update')") |
| | | public CommonResult<Boolean> submitAppraise(@RequestParam("id") Long id) { |
| | | appraiseService.submitAppraise(id); |
| | | return success(true); |
| | | } |
| | | |
| | | @PutMapping("/audit") |
| | | @Operation(summary = "审批绩效考核方案(通过/驳回)") |
| | | @Operation(summary = "审核(审批中→审核通过/审核不通过),仅审批人本人可操作") |
| | | @PreAuthorize("@ss.hasPermission('hrm:performance-appraise:audit')") |
| | | public CommonResult<Boolean> auditAppraise(@Valid @RequestBody HrmPerformanceAppraiseAuditReqVO auditReqVO) { |
| | | appraiseService.auditAppraise(auditReqVO); |
| | | appraiseService.auditAppraise(auditReqVO.getId(), auditReqVO.getPass(), auditReqVO.getReviewRemark()); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/approve-process-list") |
| | | @Operation(summary = "获得绩效考核方案审批流程定义列表") |
| | | @GetMapping("/approver-ids") |
| | | @Operation(summary = "获得审批人编号集合,供前端判断是否展示审核按钮") |
| | | @PreAuthorize("@ss.hasPermission('hrm:performance-appraise:query')") |
| | | public CommonResult<List<Map<String, Object>>> getAppraiseApproveProcessDefinitionList() { |
| | | return success(appraiseService.getAppraiseApproveProcessDefinitionList()); |
| | | public CommonResult<Set<Long>> getApproverUserIds() { |
| | | return success(appraiseService.getAppraiseApproverUserIds()); |
| | | } |
| | | |
| | | // ========== 评分/结果 ========== |
| | |
| | | return success(buildResultRespVO(result, employeeService.getEmployee(employeeId))); |
| | | } |
| | | |
| | | @PostMapping("/generate-appraisees") |
| | | @Operation(summary = "生成被考核人(按考核范围,幂等)") |
| | | @Parameter(name = "appraiseId", description = "方案编号", required = true, example = "1") |
| | | @PreAuthorize("@ss.hasPermission('hrm:performance-appraise:update')") |
| | | public CommonResult<Integer> generateAppraisees(@RequestParam("appraiseId") Long appraiseId) { |
| | | return success(appraiseService.generateAppraisees(appraiseId)); |
| | | } |
| | | |
| | | // ========== 内部方法:拼装 VO ========== |
| | | |
| | | private HrmPerformanceAppraiseRespVO buildAppraiseRespVO(HrmPerformanceAppraiseDO appraise) { |
| | | HrmPerformanceAppraiseRespVO vo = BeanUtils.toBean(appraise, HrmPerformanceAppraiseRespVO.class); |
| | | if (StrUtil.isNotEmpty(appraise.getScopeTeamIds())) { |
| | | vo.setScopeTeamIds(JSONUtil.toList(appraise.getScopeTeamIds(), Long.class)); |
| | | } |
| | | vo.setStatusName(convertAppraiseStatusName(appraise.getStatus())); |
| | | vo.setAuditStatusName(HrmAuditStatusEnum.getNameByStatus(appraise.getAuditStatus())); |
| | | vo.setItemCount(appraiseService.getAppraiseItemList(appraise.getId()).size()); |
| | |
| | | }; |
| | | } |
| | | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "获得导入绩效考核方案模板") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | // 手动创建导出 demo |
| | | List<HrmPerformanceAppraiseImportExcelVO> list = Arrays.asList( |
| | | HrmPerformanceAppraiseImportExcelVO.builder().name("2026年8月绩效考核").periodType(1) |
| | | .period("2026-08").scopeType(1).remark("").build() |
| | | ); |
| | | // 输出 |
| | | ExcelUtils.write(response, "绩效考核方案导入模板.xls", "绩效考核方案列表", HrmPerformanceAppraiseImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | @Operation(summary = "导入绩效考核方案") |
| | | @PreAuthorize("@ss.hasPermission('hrm:performance-appraise:import')") |
| | | public CommonResult<HrmPerformanceAppraiseImportRespVO> importExcel(@Valid HrmPerformanceAppraiseImportReqVO importReqVO) |
| | | throws Exception { |
| | | List<HrmPerformanceAppraiseImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), HrmPerformanceAppraiseImportExcelVO.class); |
| | | return success(appraiseService.importAppraiseList(list, importReqVO)); |
| | | } |
| | | |
| | | } |