# FdProcedureCheckErrorTypeController.java

    package cloud.wconnect.workperformance.controller.fdprocedurecheck;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.pojo.dto.ListPagedDTO;
    import cloud.wconnect.workperformance.entity.fdprocedurecheck.FdProcedureCheckErrorType;
    import cloud.wconnect.workperformance.pojo.dto.fdprocedurecheck.FdProcedureCheckErrorTypeDTO;
    import cloud.wconnect.workperformance.pojo.query.fdprocedurecheck.FdProcedureCheckErrorTypeQuery;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckErrorTypeService;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckService;
    import jakarta.annotation.Resource;
    import jakarta.validation.Valid;
    import org.springframework.util.Assert;
    import org.springframework.web.bind.annotation.*;

    import java.util.Collections;
    import java.util.Map;
    import java.util.Objects;

    /**
     * <p>
     * FD Procedure Check error type 前端控制器
     * </p>
     *
     * @author zc
     * @since 2023-10-05
     */
    @RestController
    @RequestMapping("/fd-procedure-check/error-type")
    public class FdProcedureCheckErrorTypeController {

        @Resource
        private IFdProcedureCheckErrorTypeService fdProcedureCheckErrorTypeService;
        @Resource
        private IFdProcedureCheckService fdProcedureCheckService;
        @Resource
        private SessionContext sessionContext;

        /**
         * 获取 Error Type
         *
         * @param property       资产标识
         * @param errorTypeQuery 查询条件
         * @return FdProcedureCheckErrorTypeDTO 集合
         * @author zc
         * @date 2023/10/5
         */
        @ApiId(808)
        @GetMapping
        public ListPagedDTO<FdProcedureCheckErrorTypeDTO> list(String property, FdProcedureCheckErrorTypeQuery errorTypeQuery) {
            int propertyId = sessionContext.getPropertyId(property);
            return fdProcedureCheckErrorTypeService.list(propertyId, errorTypeQuery);
        }

        /**
         * 保存 Error Type
         *
         * @param property     资产标识
         * @param errorTypeDTO Error Type 内容
         * @return empty map
         * @author zc
         * @date 2023/10/5
         */
        @ApiId(809)
        @PostMapping
        public Map<Object, Object> save(String property, @RequestBody @Valid FdProcedureCheckErrorTypeDTO errorTypeDTO) {
            int propertyId = sessionContext.getPropertyId(property);
            int loginUserId = sessionContext.getLoginUserId();
            if (Objects.isNull(errorTypeDTO.getId())) {
                Assert.isTrue(Objects.nonNull(errorTypeDTO.getSupportDesc()), "The supportDesc cannot be null");
                if (errorTypeDTO.getSupportDesc()) {
                    Assert.isTrue(Objects.nonNull(errorTypeDTO.getRequired()), "The required cannot be null");
                } else {
                    Assert.isTrue(Objects.isNull(errorTypeDTO.getRequired()), "The required cannot be set");
                }
                // 新增操作
                // 校验 Label 是否已存在
                fdProcedureCheckErrorTypeService.checkAlreadyExist(propertyId, errorTypeDTO.getLabel(), null);
                // 新增数据
                fdProcedureCheckErrorTypeService.add(propertyId, errorTypeDTO, loginUserId);
            } else {
                Assert.isTrue(Objects.isNull(errorTypeDTO.getSupportDesc()), "The supportDesc cannot be set");
                Assert.isTrue(Objects.isNull(errorTypeDTO.getRequired()), "The required cannot be set");
                // 编辑操作
                // 校验数据是否存在
                FdProcedureCheckErrorType originData = fdProcedureCheckErrorTypeService.checkExist(errorTypeDTO.getId());
                // 校验数据归属
                fdProcedureCheckErrorTypeService.checkBelong(propertyId, originData);
                // 校验 Label 是否已存在
                fdProcedureCheckErrorTypeService.checkAlreadyExist(propertyId, errorTypeDTO.getLabel(), errorTypeDTO.getId());
                // 更新数据
                fdProcedureCheckErrorTypeService.update(originData, errorTypeDTO, loginUserId);
            }

            return Collections.emptyMap();
        }

        /**
         * 删除 Error Type
         *
         * @param property 资产标识
         * @param id       Error Type id
         * @return empty map
         * @author zc
         * @date 2023/10/5
         */
        @ApiId(810)
        @DeleteMapping("/{id:\\d+}")
        public Map<Object, Object> delete(String property, @PathVariable int id) {
            int propertyId = sessionContext.getPropertyId(property);
            // 校验数据是否存在
            FdProcedureCheckErrorType originData = fdProcedureCheckErrorTypeService.checkExist(id);
            // 校验数据归属
            fdProcedureCheckErrorTypeService.checkBelong(propertyId, originData);
            // 校验 Error Type 是否已被使用
            fdProcedureCheckService.checkErrorTypeInUse(propertyId, id);
            // 删除数据
            fdProcedureCheckErrorTypeService.removeById(id);

            return Collections.emptyMap();
        }

    }