3 天以前 b852254d90e7d1955db31db154193ec8ee84d8b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package cn.iocoder.yudao.module.hrm.controller.admin.training;
 
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.hrm.controller.admin.training.vo.HrmTrainingParticipantAddReqVO;
import cn.iocoder.yudao.module.hrm.controller.admin.training.vo.HrmTrainingParticipantRespVO;
import cn.iocoder.yudao.module.hrm.controller.admin.training.vo.HrmTrainingParticipantUpdateReqVO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.HrmEmployeeDO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.training.HrmTrainingParticipantDO;
import cn.iocoder.yudao.module.hrm.service.employee.HrmEmployeeService;
import cn.iocoder.yudao.module.hrm.service.training.HrmTrainingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
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.ArrayList;
import java.util.List;
import java.util.Map;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 
@Tag(name = "管理后台 - HRM 培训参训人员")
@RestController
@RequestMapping("/hrm/training-participant")
@Validated
public class HrmTrainingParticipantController {
 
    @Resource
    private HrmTrainingService trainingService;
    @Resource
    private HrmEmployeeService employeeService;
 
    @PostMapping("/add")
    @Operation(summary = "批量添加参训员工(自动跳过已在名单中的员工)")
    @PreAuthorize("@ss.hasPermission('hrm:training:update')")
    public CommonResult<Integer> addParticipants(@Valid @RequestBody HrmTrainingParticipantAddReqVO addReqVO) {
        return success(trainingService.addParticipants(addReqVO.getTrainingId(), addReqVO.getEmployeeIds()));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新参训记录(参加情况/考核成绩/是否合格)")
    @PreAuthorize("@ss.hasPermission('hrm:training:update')")
    public CommonResult<Boolean> updateParticipant(@Valid @RequestBody HrmTrainingParticipantUpdateReqVO updateReqVO) {
        trainingService.updateParticipant(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除参训记录")
    @Parameter(name = "ids", description = "参训记录编号数组", required = true)
    @PreAuthorize("@ss.hasPermission('hrm:training:update')")
    public CommonResult<Boolean> deleteParticipants(@RequestParam("ids") List<Long> ids) {
        trainingService.deleteParticipants(ids);
        return success(true);
    }
 
    @GetMapping("/list")
    @Operation(summary = "获得某次培训的参训人员列表")
    @Parameter(name = "trainingId", description = "培训活动编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('hrm:training:query')")
    public CommonResult<List<HrmTrainingParticipantRespVO>> getParticipantsByTrainingId(
            @RequestParam("trainingId") Long trainingId) {
        List<HrmTrainingParticipantDO> participants = trainingService.getParticipantsByTrainingId(trainingId);
        return success(buildParticipantList(participants));
    }
 
    private List<HrmTrainingParticipantRespVO> buildParticipantList(List<HrmTrainingParticipantDO> participants) {
        if (CollUtil.isEmpty(participants)) {
            return new ArrayList<>();
        }
        Map<Long, HrmEmployeeDO> employeeMap = employeeService.getEmployeeList(
                        convertSet(participants, HrmTrainingParticipantDO::getEmployeeId)).stream()
                .collect(java.util.stream.Collectors.toMap(HrmEmployeeDO::getId, e -> e, (a, b) -> a));
        List<HrmTrainingParticipantRespVO> voList = BeanUtils.toBean(participants, HrmTrainingParticipantRespVO.class);
        for (HrmTrainingParticipantRespVO vo : voList) {
            HrmEmployeeDO employee = employeeMap.get(vo.getEmployeeId());
            if (employee != null) {
                vo.setEmployeeName(employee.getName());
                vo.setEmployeeNo(employee.getEmployeeNo());
            }
        }
        return voList;
    }
 
}