From 2bc58be7a80281d157d914fe5777fbda21862d69 Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Tue, 10 Mar 2026 14:32:43 +0800
Subject: [PATCH] 2026-03-09 优化 新增按标注id获取标注详细信息接口

---
 ard-sample/src/main/java/com/ard/sample/annotation/service/impl/AnnotationServiceImpl.java |   14 ++++
 ard-sample/src/main/java/com/ard/sample/annotation/service/IAnnotationService.java         |    2 
 ard-admin/src/main/java/com/ard/web/controller/sample/AnnotationController.java            |  158 +++++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 152 insertions(+), 22 deletions(-)

diff --git a/ard-admin/src/main/java/com/ard/web/controller/sample/AnnotationController.java b/ard-admin/src/main/java/com/ard/web/controller/sample/AnnotationController.java
index 196d6c5..cd69d4d 100644
--- a/ard-admin/src/main/java/com/ard/web/controller/sample/AnnotationController.java
+++ b/ard-admin/src/main/java/com/ard/web/controller/sample/AnnotationController.java
@@ -7,10 +7,12 @@
 import com.ard.sample.annotation.service.IAnnotationDirectoryService;
 import com.ard.sample.annotation.service.IAnnotationService;
 import com.ard.sample.annotation.util.ConvertUtil;
+import com.ard.sample.annotation.util.JsonSerializeUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
@@ -36,12 +38,19 @@
         try {
             //AnnotationDirectoryEntity entity = ConvertUtil.directoryDtoToEntity(dto);
             boolean success = directoryService.addDirectory(entity);
-            result.put("success", success);
+            int re=0;
+            if(success) {
+                re = 200;
+            }
+            else {
+                re = 400;
+            }
+            result.put("success", re);
             result.put("msg", success ? "目录新增成功" : "目录新增失败");
             result.put("data", entity.getId()); // 返回新增ID
         } catch (Exception e) {
             log.error("新增目录异常", e);
-            result.put("success", false);
+            result.put("success", 400);
             result.put("msg", "新增目录失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -54,11 +63,18 @@
         try {
 //            AnnotationDirectoryEntity entity = ConvertUtil.directoryDtoToEntity(dto);
             boolean success = directoryService.editDirectory(entity);
-            result.put("success", success);
+            int re=0;
+            if(success) {
+                re = 200;
+            }
+            else {
+                re = 400;
+            }
+            result.put("success", re);
             result.put("msg", success ? "目录修改成功" : "目录修改失败");
         } catch (Exception e) {
             log.error("修改目录异常", e);
-            result.put("success", false);
+            result.put("success", 400);
             result.put("msg", "修改目录失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -71,12 +87,19 @@
         Map<String, Object> result = new HashMap<>();
         try{
             boolean success = directoryService.updateDirectoryVisible(id, isTrue);
-            result.put("success", success);
+            int re=0;
+            if(success) {
+                re = 200;
+            }
+            else {
+                re = 400;
+            }
+            result.put("success", re);
             result.put("msg", success ? "修改目录是否可见成功" : "修改目录是否可见失败");
         }
         catch (Exception e) {
             log.error("修改目录是否可见异常", e);
-            result.put("success", false);
+            result.put("success", 400);
             result.put("msg", "修改目录是否可见失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -88,11 +111,18 @@
         Map<String, Object> result = new HashMap<>();
         try {
             boolean success = directoryService.deleteDirectory(id);
-            result.put("success", success);
+            int re=0;
+            if(success) {
+                re = 200;
+            }
+            else {
+                re = 400;
+            }
+            result.put("success", re);
             result.put("msg", success ? "目录删除成功" : "目录删除失败");
         } catch (Exception e) {
             log.error("删除目录异常", e);
-            result.put("success", false);
+            result.put("success", 400);
             result.put("msg", "删除目录失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -107,12 +137,19 @@
         try {
             AnnotationEntity entity = ConvertUtil.annotationDtoToEntity(dto);
             boolean success = annotationService.addAnnotation(entity);
-            result.put("success", success);
+            int re=0;
+            if(success) {
+                re = 200;
+            }
+            else {
+                re = 400;
+            }
+            result.put("success", re);
             result.put("msg", success ? "标记新增成功" : "标记新增失败");
             result.put("data", entity.getId());
         } catch (Exception e) {
             log.error("新增标记异常", e);
-            result.put("success", false);
+            result.put("success", 400);
             result.put("msg", "新增标记失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -125,11 +162,18 @@
         try {
             AnnotationEntity entity = ConvertUtil.annotationDtoToEntity(dto);
             boolean success = annotationService.editAnnotation(entity);
-            result.put("success", success);
+            int re=0;
+            if(success) {
+                re = 200;
+            }
+            else {
+                re = 400;
+            }
+            result.put("success", re);
             result.put("msg", success ? "标记修改成功" : "标记修改失败");
         } catch (Exception e) {
             log.error("修改标记异常", e);
-            result.put("success", false);
+            result.put("success", 400);
             result.put("msg", "修改标记失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -142,12 +186,19 @@
         Map<String, Object> result = new HashMap<>();
         try{
             boolean success = annotationService.updateAnnotationVisible(id, isTrue);
-            result.put("success", success);
+            int re=0;
+            if(success) {
+                re = 200;
+            }
+            else {
+                re = 400;
+            }
+            result.put("success", re);
             result.put("msg", success ? "修改标记是否可见成功" : "修改标记是否可见失败");
         }
         catch (Exception e) {
             log.error("修改标记是否可见异常", e);
-            result.put("success", false);
+            result.put("success", 400);
             result.put("msg", "修改标记是否可见失败:" + e.getMessage());
         }
         //boolean result = annotationService.updateAnnotationVisible(id, isTrue);
@@ -160,11 +211,18 @@
         Map<String, Object> result = new HashMap<>();
         try {
             boolean success = annotationService.deleteAnnotation(id);
-            result.put("success", success);
+            int re=0;
+            if(success) {
+                re = 200;
+            }
+            else {
+                re = 400;
+            }
+            result.put("success", re);
             result.put("msg", success ? "标记删除成功" : "标记删除失败");
         } catch (Exception e) {
             log.error("删除标记异常", e);
-            result.put("success", false);
+            result.put("success", 400);
             result.put("msg", "删除标记失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -176,11 +234,18 @@
         Map<String, Object> result = new HashMap<>();
         try {
             boolean success = annotationService.batchDeleteAnnotation(ids);
-            result.put("success", success);
+            int re=0;
+            if(success) {
+                re = 200;
+            }
+            else {
+                re = 400;
+            }
+            result.put("success", re);
             result.put("msg", success ? "标记批量删除成功" : "标记批量删除失败");
         } catch (Exception e) {
             log.error("批量删除标记异常", e);
-            result.put("success", false);
+            result.put("success", 400);
             result.put("msg", "批量删除标记失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -195,7 +260,7 @@
             // 1. 查询目录
             AnnotationDirectoryEntity dirEntity = directoryService.getById(directoryId);
             if (dirEntity == null) {
-                result.put("success", false);
+                result.put("success", 400);
                 result.put("msg", "目录不存在");
                 return ResponseEntity.ok(result);
             }
@@ -206,11 +271,11 @@
             List<AnnotationDTO> annoDtos = ConvertUtil.annotationEntityListToDtoList(annoEntities);
             dirDto.setAnnotations(annoDtos);
 
-            result.put("success", true);
+            result.put("success", 200);
             result.put("data", dirDto);
         } catch (Exception e) {
             log.error("查询目录及标记异常", e);
-            result.put("success", false);
+            result.put("success", 400);
             result.put("msg", "查询失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -225,10 +290,59 @@
         List<AnnotationDirectoryDTO> directoryList = directoryService.listAllDirectoryWithAnnotations();
 
         Map<String, Object> result = new HashMap<>();
-        result.put("success", true);
+        result.put("success", 200);
         result.put("msg", "查询全部目录及标注成功");
         result.put("data", directoryList);
 
         return ResponseEntity.ok(result);
     }
+
+    // 新增:按标注ID查询详细信息(核心补充接口,返回格式统一为ResponseEntity<Map>)
+    @ApiOperation("按标注ID获取标注详细信息")
+    @GetMapping("/{id}")
+    public ResponseEntity<Map<String, Object>> getAnnotationDetailById(@PathVariable String id) {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            // 1. 参数校验
+            if (id == null || id.isEmpty()) {
+                resultMap.put("code", 400);
+                resultMap.put("msg", "标注ID不能为空");
+                resultMap.put("data", null);
+                return new ResponseEntity<>(resultMap, HttpStatus.BAD_REQUEST);
+            }
+
+            // 2. 查询标注实体
+            AnnotationEntity annotationEntity = annotationService.getAnnotationById(id);
+            if (annotationEntity == null) {
+                resultMap.put("code", 404);
+                resultMap.put("msg", "标注不存在或已删除");
+                resultMap.put("data", null);
+                return new ResponseEntity<>(resultMap, HttpStatus.NOT_FOUND);
+            }
+
+            // 3. 实体转DTO(反序列化坐标数据)
+            AnnotationDTO annotationDTO = AnnotationDTO.builder().build();
+            org.springframework.beans.BeanUtils.copyProperties(annotationEntity, annotationDTO);
+            try {
+                annotationDTO.setCoordinateInfo(JsonSerializeUtil.deserialize(annotationEntity.getCoordinateInfo()));
+            } catch (Exception e) {
+                log.error("反序列化标注坐标失败,标注ID:{}", id, e);
+                annotationDTO.setCoordinateInfo(null);
+            }
+
+            // 4. 统一返回格式
+            resultMap.put("code", 200);
+            resultMap.put("msg", "查询成功");
+            resultMap.put("data", annotationDTO);
+            return new ResponseEntity<>(resultMap, HttpStatus.OK);
+
+        } catch (Exception e) {
+            // 全局异常捕获
+            log.error("按ID查询标注详情异常,标注ID:{}", id, e);
+            resultMap.put("code", 500);
+            resultMap.put("msg", "查询失败:" + e.getMessage());
+            resultMap.put("data", null);
+            return new ResponseEntity<>(resultMap, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
 }
diff --git a/ard-sample/src/main/java/com/ard/sample/annotation/service/IAnnotationService.java b/ard-sample/src/main/java/com/ard/sample/annotation/service/IAnnotationService.java
index 7ae06da..af59687 100644
--- a/ard-sample/src/main/java/com/ard/sample/annotation/service/IAnnotationService.java
+++ b/ard-sample/src/main/java/com/ard/sample/annotation/service/IAnnotationService.java
@@ -17,4 +17,6 @@
     boolean batchDeleteAnnotation(List<String> ids);
     // 按目录ID查询标记
     List<AnnotationEntity> listByDirectoryId(String directoryId);
+    // 新增:按标注ID获取详细信息(核心补充方法)
+    AnnotationEntity getAnnotationById(String id);
 }
\ No newline at end of file
diff --git a/ard-sample/src/main/java/com/ard/sample/annotation/service/impl/AnnotationServiceImpl.java b/ard-sample/src/main/java/com/ard/sample/annotation/service/impl/AnnotationServiceImpl.java
index acafbf7..ee16970 100644
--- a/ard-sample/src/main/java/com/ard/sample/annotation/service/impl/AnnotationServiceImpl.java
+++ b/ard-sample/src/main/java/com/ard/sample/annotation/service/impl/AnnotationServiceImpl.java
@@ -76,4 +76,18 @@
         }
         return lambdaQuery().eq(AnnotationEntity::getDirectoryId, directoryId).list();
     }
+
+    /**
+     * 按标注ID获取详细信息(核心实现)
+     */
+    @Override
+    public AnnotationEntity getAnnotationById(String id) {
+        // 1. 参数校验
+        if (id == null || id.isEmpty()) {
+            log.error("按ID查询标注失败:标注ID为空");
+            return null;
+        }
+        // 2. MyBatis-Plus通用查询(根据主键ID查询)
+        return getById(id);
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3