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;
|
}
|
|
}
|