# FdProcedureCheckCommentController.java

    package cloud.wconnect.workperformance.controller.fdprocedurecheck;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.workperformance.entity.fdprocedurecheck.FdProcedureCheck;
    import cloud.wconnect.workperformance.entity.fdprocedurecheck.FdProcedureCheckComment;
    import cloud.wconnect.workperformance.pojo.dto.fdprocedurecheck.FdProcedureCheckCommentDTO;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckCommentService;
    import cloud.wconnect.workperformance.service.fdprocedurecheck.IFdProcedureCheckService;
    import jakarta.annotation.Resource;
    import jakarta.validation.Valid;
    import org.springframework.web.bind.annotation.*;

    import java.util.Collections;
    import java.util.List;
    import java.util.Map;

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

        @Resource
        private IFdProcedureCheckService fdProcedureCheckService;
        @Resource
        private IFdProcedureCheckCommentService fdProcedureCheckCommentService;
        @Resource
        private SessionContext sessionContext;

        /**
         * 获取评论
         *
         * @param property 资产标识
         * @param id       FD Procedure Check 数据
         * @return FdProcedureCheckCommentDTO
         * @author zc
         * @date 2023/10/7
         */
        @ApiId(820)
        @GetMapping("/{id:\\d+}/comment")
        public List<FdProcedureCheckCommentDTO> list(String property, @PathVariable long id) {
            int tenantId = sessionContext.getTenantSymbolBO().getId();
            int propertyId = sessionContext.getPropertyId(property);

            // 校验数据是否存在
            FdProcedureCheck originData = fdProcedureCheckService.checkExist(id);
            // 校验数据归属
            fdProcedureCheckService.checkBelong(propertyId, originData);

            return fdProcedureCheckCommentService.list(tenantId, propertyId, id);
        }

        /**
         * 新增评论
         *
         * @param property   资产标识
         * @param id         FD Procedure Check 数据
         * @param commentDTO 评论内容
         * @return empty map
         * @author zc
         * @date 2023/10/7
         */
        @ApiId(821)
        @PostMapping("/{id:\\d+}/comment")
        public Map<Object, Object> save(String property, @PathVariable long id,
                                        @RequestBody @Valid FdProcedureCheckCommentDTO commentDTO) {
            int propertyId = sessionContext.getPropertyId(property);

            // 校验数据是否存在
            FdProcedureCheck originData = fdProcedureCheckService.checkExist(id);
            // 校验数据归属
            fdProcedureCheckService.checkBelong(propertyId, originData);

            fdProcedureCheckCommentService.save(propertyId, id, sessionContext.getLoginUserId(), commentDTO);

            return Collections.emptyMap();
        }

        /**
         * 删除评论
         *
         * @param property  资产标识
         * @param id        FD Procedure Check 数据
         * @param commentId 评论 id
         * @return empty map
         * @author zc
         * @date 2023/10/7
         */
        @ApiId(822)
        @DeleteMapping("/{id:\\d+}/comment/{commentId:\\d+}")
        public Map<Object, Object> delete(String property, @PathVariable long id, @PathVariable long commentId) {
            int propertyId = sessionContext.getPropertyId(property);

            // 校验数据是否存在
            FdProcedureCheck originFdData = fdProcedureCheckService.checkExist(id);
            // 校验数据归属
            fdProcedureCheckService.checkBelong(propertyId, originFdData);

            // 校验评论是否存在
            FdProcedureCheckComment originComment = fdProcedureCheckCommentService.checkExist(commentId);
            // 校验评论归属
            fdProcedureCheckCommentService.checkBelong(propertyId, id, originComment);

            // 校验评论是否可以删除
            fdProcedureCheckCommentService.checkCanDelete(originFdData.getHandledResult(), originComment,
                    sessionContext.getLoginUserId());

            // 删除评论
            fdProcedureCheckCommentService.removeById(commentId);

            return Collections.emptyMap();
        }
    }