From 208731a6c41b644186bb68c93c19ef7026284e3b Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Thu, 12 Mar 2026 16:04:43 +0800
Subject: [PATCH] 2026-03-09 优化标注功能 增加GeoCalculator计算工具类,算出面、圆的水平面积和水平周长,线的水平距离和直线距离。在调取按标注id获取标注详细信息接口给出,不入库。

---
 ard-admin/src/main/java/com/ard/web/controller/sample/AnnotationController.java |  164 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 129 insertions(+), 35 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 cd69d4d..22441b5 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
@@ -2,11 +2,13 @@
 
 import com.ard.sample.annotation.model.dto.AnnotationDTO;
 import com.ard.sample.annotation.model.dto.AnnotationDirectoryDTO;
+import com.ard.sample.annotation.model.dto.AnnotationPointsDTO;
 import com.ard.sample.annotation.model.entity.AnnotationDirectoryEntity;
 import com.ard.sample.annotation.model.entity.AnnotationEntity;
 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.GeoCalculator;
 import com.ard.sample.annotation.util.JsonSerializeUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -19,6 +21,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Api(tags = "标注管理")
 @Slf4j
@@ -45,12 +48,12 @@
             else {
                 re = 400;
             }
-            result.put("success", re);
+            result.put("code", re);
             result.put("msg", success ? "目录新增成功" : "目录新增失败");
             result.put("data", entity.getId()); // 返回新增ID
         } catch (Exception e) {
             log.error("新增目录异常", e);
-            result.put("success", 400);
+            result.put("code", 400);
             result.put("msg", "新增目录失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -70,11 +73,11 @@
             else {
                 re = 400;
             }
-            result.put("success", re);
+            result.put("code", re);
             result.put("msg", success ? "目录修改成功" : "目录修改失败");
         } catch (Exception e) {
             log.error("修改目录异常", e);
-            result.put("success", 400);
+            result.put("code", 400);
             result.put("msg", "修改目录失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -94,12 +97,12 @@
             else {
                 re = 400;
             }
-            result.put("success", re);
+            result.put("code", re);
             result.put("msg", success ? "修改目录是否可见成功" : "修改目录是否可见失败");
         }
         catch (Exception e) {
             log.error("修改目录是否可见异常", e);
-            result.put("success", 400);
+            result.put("code", 400);
             result.put("msg", "修改目录是否可见失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -118,11 +121,11 @@
             else {
                 re = 400;
             }
-            result.put("success", re);
+            result.put("code", re);
             result.put("msg", success ? "目录删除成功" : "目录删除失败");
         } catch (Exception e) {
             log.error("删除目录异常", e);
-            result.put("success", 400);
+            result.put("code", 400);
             result.put("msg", "删除目录失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -144,12 +147,12 @@
             else {
                 re = 400;
             }
-            result.put("success", re);
+            result.put("code", re);
             result.put("msg", success ? "标记新增成功" : "标记新增失败");
             result.put("data", entity.getId());
         } catch (Exception e) {
             log.error("新增标记异常", e);
-            result.put("success", 400);
+            result.put("code", 400);
             result.put("msg", "新增标记失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -169,11 +172,11 @@
             else {
                 re = 400;
             }
-            result.put("success", re);
+            result.put("code", re);
             result.put("msg", success ? "标记修改成功" : "标记修改失败");
         } catch (Exception e) {
             log.error("修改标记异常", e);
-            result.put("success", 400);
+            result.put("code", 400);
             result.put("msg", "修改标记失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -193,12 +196,12 @@
             else {
                 re = 400;
             }
-            result.put("success", re);
+            result.put("code", re);
             result.put("msg", success ? "修改标记是否可见成功" : "修改标记是否可见失败");
         }
         catch (Exception e) {
             log.error("修改标记是否可见异常", e);
-            result.put("success", 400);
+            result.put("code", 400);
             result.put("msg", "修改标记是否可见失败:" + e.getMessage());
         }
         //boolean result = annotationService.updateAnnotationVisible(id, isTrue);
@@ -218,11 +221,11 @@
             else {
                 re = 400;
             }
-            result.put("success", re);
+            result.put("code", re);
             result.put("msg", success ? "标记删除成功" : "标记删除失败");
         } catch (Exception e) {
             log.error("删除标记异常", e);
-            result.put("success", 400);
+            result.put("code", 400);
             result.put("msg", "删除标记失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -241,11 +244,11 @@
             else {
                 re = 400;
             }
-            result.put("success", re);
+            result.put("code", re);
             result.put("msg", success ? "标记批量删除成功" : "标记批量删除失败");
         } catch (Exception e) {
             log.error("批量删除标记异常", e);
-            result.put("success", 400);
+            result.put("code", 400);
             result.put("msg", "批量删除标记失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -260,7 +263,7 @@
             // 1. 查询目录
             AnnotationDirectoryEntity dirEntity = directoryService.getById(directoryId);
             if (dirEntity == null) {
-                result.put("success", 400);
+                result.put("code", 400);
                 result.put("msg", "目录不存在");
                 return ResponseEntity.ok(result);
             }
@@ -271,11 +274,11 @@
             List<AnnotationDTO> annoDtos = ConvertUtil.annotationEntityListToDtoList(annoEntities);
             dirDto.setAnnotations(annoDtos);
 
-            result.put("success", 200);
+            result.put("code", 200);
             result.put("data", dirDto);
         } catch (Exception e) {
             log.error("查询目录及标记异常", e);
-            result.put("success", 400);
+            result.put("code", 400);
             result.put("msg", "查询失败:" + e.getMessage());
         }
         return ResponseEntity.ok(result);
@@ -284,21 +287,20 @@
     /**
      * 新增:获取全部目录及下属标注数据
      */
-    @ApiOperation("获取全部目录及下属标注数据")
+    @ApiOperation("获取全部目录及下属标记数据")
     @GetMapping("/directory/all")
     public ResponseEntity<Map<String, Object>> listAllDirectoryWithAnnotations() {
         List<AnnotationDirectoryDTO> directoryList = directoryService.listAllDirectoryWithAnnotations();
 
         Map<String, Object> result = new HashMap<>();
-        result.put("success", 200);
-        result.put("msg", "查询全部目录及标注成功");
+        result.put("code", 200);
+        result.put("msg", "查询全部目录及标记成功");
         result.put("data", directoryList);
 
         return ResponseEntity.ok(result);
     }
 
-    // 新增:按标注ID查询详细信息(核心补充接口,返回格式统一为ResponseEntity<Map>)
-    @ApiOperation("按标注ID获取标注详细信息")
+    @ApiOperation("按标注ID获取标记详细信息,包含线的长度,面、圆的面积")
     @GetMapping("/{id}")
     public ResponseEntity<Map<String, Object>> getAnnotationDetailById(@PathVariable String id) {
         Map<String, Object> resultMap = new HashMap<>();
@@ -306,43 +308,135 @@
             // 1. 参数校验
             if (id == null || id.isEmpty()) {
                 resultMap.put("code", 400);
-                resultMap.put("msg", "标注ID不能为空");
+                resultMap.put("msg", "标记ID不能为空");
                 resultMap.put("data", null);
                 return new ResponseEntity<>(resultMap, HttpStatus.BAD_REQUEST);
             }
 
-            // 2. 查询标注实体
+            // 2. 查询标记数据
             AnnotationEntity annotationEntity = annotationService.getAnnotationById(id);
             if (annotationEntity == null) {
                 resultMap.put("code", 404);
-                resultMap.put("msg", "标注不存在或已删除");
+                resultMap.put("msg", "标记不存在或已删除");
                 resultMap.put("data", null);
                 return new ResponseEntity<>(resultMap, HttpStatus.NOT_FOUND);
             }
 
-            // 3. 实体转DTO(反序列化坐标数据)
+            // 3. 转换为DTO并反序列化坐标
             AnnotationDTO annotationDTO = AnnotationDTO.builder().build();
             org.springframework.beans.BeanUtils.copyProperties(annotationEntity, annotationDTO);
+            List<AnnotationPointsDTO> coordinateList = null;
+            List<GeoCalculator.Coordinate> geoPoints = new java.util.ArrayList<>();
             try {
-                annotationDTO.setCoordinateInfo(JsonSerializeUtil.deserialize(annotationEntity.getCoordinateInfo()));
+                coordinateList = JsonSerializeUtil.deserialize(annotationEntity.getCoordinateInfo());
+                annotationDTO.setCoordinateInfo(coordinateList);
+
+                // 转换为工具类坐标
+                if (coordinateList != null && !coordinateList.isEmpty()) {
+                    geoPoints = coordinateList.stream()
+                            .map(p -> new GeoCalculator.Coordinate(p.getLongitude(), p.getLatitude()))
+                            .collect(Collectors.toList());
+                }
             } catch (Exception e) {
-                log.error("反序列化标注坐标失败,标注ID:{}", id, e);
+                log.error("反序列化坐标失败,标注ID:{}", id, e);
                 annotationDTO.setCoordinateInfo(null);
             }
 
-            // 4. 统一返回格式
+            // 4. 按标注类型计算所有参数
+            String annotationType = annotationEntity.getAnnotationType();
+            switch (annotationType) {
+                case "2": // line 线:水平距离、直线距离
+                    annotationDTO.setLineHorizontalDistance(GeoCalculator.calculatePolylineHorizontalDistance(geoPoints));
+                    annotationDTO.setLineStraightDistance(GeoCalculator.calculatePolylineStraightDistance(geoPoints));
+                    break;
+
+                case "3": // polygon 面:水平面积、水平周长
+                    annotationDTO.setPolygonHorizontalArea(GeoCalculator.calculatePolygonHorizontalArea(geoPoints));
+                    annotationDTO.setPolygonHorizontalPerimeter(GeoCalculator.calculatePolygonHorizontalPerimeter(geoPoints));
+                    break;
+
+                case "4": // circle 圆:水平面积、水平周长(仅需半径)
+                    Double radius = annotationDTO.getCoordinateInfo().get(0).getRadius(); //annotationEntity.getRadius();
+                    if (radius == null) radius = 0.0;
+                    annotationDTO.setCircleHorizontalArea(GeoCalculator.calculateCircleHorizontalArea(radius));
+                    annotationDTO.setCircleHorizontalPerimeter(GeoCalculator.calculateCircleHorizontalPerimeter(radius));
+                    break;
+
+                case "1": // point 点:无计算项,赋值0
+                    annotationDTO.setLineHorizontalDistance(0.00);
+                    annotationDTO.setLineStraightDistance(0.00);
+                    annotationDTO.setPolygonHorizontalArea(0.00);
+                    annotationDTO.setPolygonHorizontalPerimeter(0.00);
+                    annotationDTO.setCircleHorizontalArea(0.00);
+                    annotationDTO.setCircleHorizontalPerimeter(0.00);
+                    break;
+
+                default: // 未知类型
+                    log.warn("未知标记类型:{},不计算地理参数", annotationType);
+                    break;
+            }
+
+            // 5. 返回结果
             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);
+            log.error("查询标记详情异常,ID:{}", id, e);
             resultMap.put("code", 500);
             resultMap.put("msg", "查询失败:" + e.getMessage());
             resultMap.put("data", null);
             return new ResponseEntity<>(resultMap, HttpStatus.INTERNAL_SERVER_ERROR);
         }
     }
+
+//    // 新增:按标注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);
+//        }
+//    }
 }

--
Gitblit v1.9.3