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 | 111 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 93 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/se/nsl/controller/SimuController.java b/src/main/java/com/se/nsl/controller/SimuController.java index fc5389d..9ca589b 100644 --- a/src/main/java/com/se/nsl/controller/SimuController.java +++ b/src/main/java/com/se/nsl/controller/SimuController.java @@ -6,13 +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.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; 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; @@ -20,10 +18,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.io.IOException; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; import java.util.List; @Api(tags = "03锛嶆帹婕旀ā鎷�") @@ -39,7 +33,10 @@ ResolveService resolveService; @Resource - RealTimeSimulationService rts; + RealTimeSimulationAsyncService rtsas; + + @Resource + CrossSectionAnalysisService scas; /** * 鍒嗛〉鏌ヨ鎺ㄦ紨妯℃嫙 @@ -105,10 +102,13 @@ int rows = simuService.insert(simu); System.out.println(String.format("id:%s", simu.getId())); - - if (rows > 0 && (null == data.getRainfalls() || data.getRainfalls().size() < 2)) { - resolveService.createRainfall(simu); - simuService.updateById(simu); + Integer type = data.getType(); + SimulateType simulateType = SimulateType.of(type); + if (simulateType == SimulateType.HISTORY) { + if (rows > 0 && (null == data.getRainfalls() || data.getRainfalls().size() < 2)) { + resolveService.createRainfall(simu); + simuService.updateById(simu); + } } JSONObject json = new JSONObject(); json.put("id", simu.getId()); @@ -125,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); @@ -134,9 +134,16 @@ //if (simu.getStatus() != 0) return fail("鏂规姝e湪杩愯鎴栧凡瀹屾垚"); if (StringUtils.isEmpty(simu.getGeom())) return fail("鏂规鐨勫浘褰负绌�"); - int rows = resolveService.start(simu); - - return success("ok"); + Short type = simu.getType(); + SimulateType simulateType = SimulateType.of(type); + if (simulateType == SimulateType.HISTORY) { + int rows = resolveService.start(simu); + return success("ok"); + } else if (simulateType == SimulateType.REAL_TIME) { + rtsas.startSimulation(simu); + return success(null, "瀹炴椂妯℃嫙浠诲姟宸叉彁浜�"); + } + return fail("妯℃嫙绫诲瀷鏆備笉鏀寔"); } catch (Exception ex) { return fail(ex, null); } @@ -196,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