From e53252b99e7b49b435b7a6ee3eab21ae1bd7a055 Mon Sep 17 00:00:00 2001
From: dcb <xgybdcb@163.com>
Date: 星期三, 09 七月 2025 16:11:40 +0800
Subject: [PATCH] 断面分析功能实现

---
 src/main/java/com/se/nsl/controller/SimuController.java |   84 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/se/nsl/controller/SimuController.java b/src/main/java/com/se/nsl/controller/SimuController.java
index f4d0076..9ca589b 100644
--- a/src/main/java/com/se/nsl/controller/SimuController.java
+++ b/src/main/java/com/se/nsl/controller/SimuController.java
@@ -6,12 +6,11 @@
 import com.se.nsl.domain.po.Simu;
 import com.se.nsl.domain.po.SimuData;
 import com.se.nsl.domain.vo.*;
-import com.se.nsl.service.RealTimeSimulationService;
-import com.se.nsl.service.ResolveService;
-import com.se.nsl.service.SimuService;
+import com.se.nsl.service.*;
 import com.se.nsl.utils.SimulateType;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import io.swagger.v3.oas.annotations.Parameter;
 import lombok.extern.slf4j.Slf4j;
 import org.gdal.ogr.Geometry;
 import org.gdal.ogr.ogr;
@@ -34,7 +33,10 @@
     ResolveService resolveService;
 
     @Resource
-    RealTimeSimulationService rts;
+    RealTimeSimulationAsyncService rtsas;
+
+    @Resource
+    CrossSectionAnalysisService scas;
 
     /**
      * 鍒嗛〉鏌ヨ鎺ㄦ紨妯℃嫙
@@ -123,7 +125,7 @@
             if (null == id || id < 1) return fail("id涓虹┖");
 
             Simu simu = simuService.selectById(id);
-            if (null == simu) return fail("鏂规鎵句笉鍒�");
+            if (null == simu) return notFound("鏂规鎵句笉鍒�");
             if (StringUtils.isEmpty(simu.getData())) return fail("鏂规鏁版嵁(JSON)涓虹┖");
 
             SimuData data = JSON.parseObject(simu.getData(), SimuData.class);
@@ -138,8 +140,8 @@
                 int rows = resolveService.start(simu);
                 return success("ok");
             } else if (simulateType == SimulateType.REAL_TIME) {
-                String s = rts.realTimeSimulate(simu);
-                return success(s);
+                rtsas.startSimulation(simu);
+                return success(null, "瀹炴椂妯℃嫙浠诲姟宸叉彁浜�");
             }
             return fail("妯℃嫙绫诲瀷鏆備笉鏀寔");
         } catch (Exception ex) {
@@ -201,4 +203,72 @@
             return success(simuResults, simuResults.size());
         }
     }
+
+    @ApiOperation(value = "crossSection")
+    @GetMapping("/crossSection")
+    public R<Object> crossSection(@Parameter(description = "鏂规id锛岀ず渚嬶細50") Integer id,
+                                  @Parameter(description = "鏃堕棿鎴筹紝绀轰緥锛�1751552400000") Long time,
+                                  @Parameter(description = "璧风偣鍧愭爣锛岀ず渚嬶細116.59049537485063,40.564178548127686") String startPoint,
+                                  @Parameter(description = "缁堢偣鍧愭爣锛岀ず渚嬶細116.5901406492509,40.56499045715429") String endPoint) {
+        if (null == id || id < 1) return clientError("id涓嶈兘涓虹┖");
+        Simu simu = simuService.selectById(id);
+        if (simu == null) {
+            return clientError("鎵句笉鍒板搴旂殑鏈嶅姟");
+        }
+        String serviceName = simu.getServiceName();
+        if (serviceName == null) {
+            return fail("鎵句笉鍒板搴旂殑鏈嶅姟");
+        }
+        if (startPoint == null) {
+            return clientError("璧风偣涓嶈兘涓虹┖");
+        }
+        if (endPoint == null) {
+            return clientError("缁堢偣涓嶈兘涓虹┖");
+        }
+        String[] sp = startPoint.split(",");
+        double[] s = new double[] {Double.parseDouble(sp[0]), Double.parseDouble(sp[1])};
+        String[] ep = endPoint.split(",");
+        double[] e = new double[] {Double.parseDouble(ep[0]), Double.parseDouble(ep[1])};
+        try {
+            if (time == null) {
+                List<CrossSectionAnalysisResult> result = scas.crossSectionAnalysis(serviceName, s, e);
+                return success(result, result.size());
+            } else {
+                CrossSectionAnalysisResult res = scas.crossSectionAnalysis(serviceName, s, e, time);
+                return success(res, 1);
+            }
+        } catch (IllegalArgumentException ex) {
+            return fail(ex.getMessage(), null);
+        }
+    }
+
+    @ApiOperation(value = "stop")
+    @GetMapping("/stop")
+    public R<Object> stop(Integer id) {
+        if (id == null) {
+            return fail("id涓嶈兘涓虹┖");
+        }
+        try {
+            rtsas.stopSimulation(id);
+        } catch (IllegalArgumentException e) {
+            return notFound(e.getMessage());
+        }
+        return success(null, "姝e湪鍋滄id涓�" + id + "鐨勬ā鎷熶换鍔�");
+    }
+
+    @ApiOperation(value = "results")
+    @GetMapping("/results")
+    public R<Object> querySimulationResult(Integer id) {
+        if (null == id || id < 1) return clientError("id涓嶈兘涓虹┖");
+        Simu simu = simuService.selectById(id);
+        if (simu == null) {
+            return clientError("鎵句笉鍒板搴旂殑鏈嶅姟");
+        }
+        String serviceName = simu.getServiceName();
+        if (serviceName == null) {
+            return fail("鎵句笉鍒板搴旂殑鏈嶅姟");
+        }
+        List<String> results = resolveService.simulationResults(serviceName);
+        return success(results, results.size());
+    }
 }

--
Gitblit v1.9.3