cnas-personnel/src/main/java/com/ruoyi/personnel/controller/PersonPersonnelCapacityController.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.exception.ErrorException;
import com.ruoyi.personnel.dto.PersonPersonnelCapacityDto;
import com.ruoyi.personnel.pojo.PersonPersonnelCapacity;
import com.ruoyi.personnel.service.PersonPersonnelCapacityService;
@@ -36,6 +37,18 @@
    @Operation(summary = "新增/更新 人员能力")
    @PostMapping("addOrUpdatePersonPersonnelCapacity")
    public Result<?> addOrUpdatePersonPersonnelCapacity(@RequestBody PersonPersonnelCapacity personPersonnelCapacity) {
        if (personPersonnelCapacity == null || personPersonnelCapacity.getUserId() == null) {
            throw new ErrorException("缺少人员");
        }
        if (personPersonnelCapacity.getId() != null) {
            PersonPersonnelCapacity existing = personPersonnelCapacityService.getById(personPersonnelCapacity.getId());
            if (existing == null) {
                throw new ErrorException("人员能力记录不存在或已被删除");
            }
            if (existing.getConfirmDate() != null) {
                throw new ErrorException("该记录已确认,不能修改");
            }
        }
        personPersonnelCapacityService.saveOrUpdate(personPersonnelCapacity);
        return Result.success();
    }
@@ -43,7 +56,16 @@
    @Operation(summary = "删除 人员能力")
    @DeleteMapping("deletePersonPersonnelCapacity")
    public Result<?> deletePersonPersonnelCapacity(@RequestParam("id") Integer id) {
        // 删除数据
        if (id == null) {
            throw new ErrorException("缺少人员能力记录id");
        }
        PersonPersonnelCapacity existing = personPersonnelCapacityService.getById(id);
        if (existing == null) {
            throw new ErrorException("人员能力记录不存在或已被删除");
        }
        if (existing.getConfirmDate() != null) {
            throw new ErrorException("该记录已确认,不能删除");
        }
        personPersonnelCapacityService.removeById(id);
        return Result.success();
    }
@@ -60,11 +82,24 @@
    @Operation(summary = "确认 人员能力")
    @PostMapping("confirmPersonnelCapability")
    public Result<?> confirmPersonnelCapability(@RequestBody PersonPersonnelCapacity personPersonnelCapacity) {
        if (personPersonnelCapacity == null || personPersonnelCapacity.getId() == null) {
            throw new ErrorException("缺少人员能力记录id");
        }
        PersonPersonnelCapacity record = personPersonnelCapacityService.getById(personPersonnelCapacity.getId());
        if (record == null) {
            throw new ErrorException("人员能力记录不存在或已被删除");
        }
        if (record.getConfirmDate() != null) {
            throw new ErrorException("该记录已确认,请勿重复确认");
        }
        Integer userId = SecurityUtils.getUserId().intValue();
        if (record.getConfirmOperatingPersonnelId() == null
                || !record.getConfirmOperatingPersonnelId().equals(userId)) {
            throw new ErrorException("您不是该记录指定的确认人,无法确认");
        }
        personPersonnelCapacityService.update(Wrappers.<PersonPersonnelCapacity>lambdaUpdate()
                .eq(PersonPersonnelCapacity::getId, personPersonnelCapacity.getId())
                .set(PersonPersonnelCapacity::getConfirmOperatingPersonnelId, userId)
                .set(PersonPersonnelCapacity::getConfirmDate, personPersonnelCapacity.getConfirmDate()));
                .eq(PersonPersonnelCapacity::getId, record.getId())
                .set(PersonPersonnelCapacity::getConfirmDate, LocalDateTime.now()));
        return Result.success();
    }