# FdProcedureCheckProblemDescriptionController.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.FdProcedureCheckProblemDesc;
    import cloud.wconnect.workperformance.pojo.dto.fdprocedurecheck.FdProcedureCheckProblemDescriptionDTO;
    import cloud.wconnect.workperformance.pojo.query.fdprocedurecheck.FdProcedureCheckProblemDescriptionQuery;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckProblemDescService;
    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 Problem Description 前端控制器
     * </p>
     *
     * @author zc
     * @since 2023-10-05
     */
    @RestController
    @RequestMapping("/fd-procedure-check/problem-description")
    public class FdProcedureCheckProblemDescriptionController {

        @Resource
        private IFdProcedureCheckProblemDescService fdProcedureCheckProblemDescService;
        @Resource
        private IFdProcedureCheckService fdProcedureCheckService;
        @Resource
        private SessionContext sessionContext;

        /**
         * 获取 Problem Description
         *
         * @param property 资产标识
         * @param query    查询条件
         * @return FdProcedureCheckProblemDescriptionDTO 集合
         * @author zc
         * @date 2023/10/5
         */
        @ApiId(811)
        @GetMapping
        public ListPagedDTO<FdProcedureCheckProblemDescriptionDTO> list(String property, FdProcedureCheckProblemDescriptionQuery query) {
            int propertyId = sessionContext.getPropertyId(property);
            return fdProcedureCheckProblemDescService.list(propertyId, query);
        }

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

            return Collections.emptyMap();
        }

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

            return Collections.emptyMap();
        }

    }