| | |
| | | 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 lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.ogr.Geometry; |
| | |
| | | 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-推演模拟") |
| | |
| | | ResolveService resolveService; |
| | | |
| | | @Resource |
| | | RealTimeSimulationService rts; |
| | | RealTimeSimulationAsyncService rtsas; |
| | | |
| | | @Resource |
| | | CrossSectionAnalysisService scas; |
| | | |
| | | /** |
| | | * 分页查询推演模拟 |
| | |
| | | |
| | | 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()); |
| | |
| | | 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); |
| | |
| | | //if (simu.getStatus() != 0) return fail("方案正在运行或已完成"); |
| | | 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); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "realTime") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "date1", value = "5分钟前的时间,格式为2025-05-31 14:15:20"), |
| | | @ApiImplicitParam(name = "rainfall1", value = "5分钟前的降雨强度"), |
| | | @ApiImplicitParam(name = "date2", value = "当前时间,格式为2025-05-31 14:20:20"), |
| | | @ApiImplicitParam(name = "rainfall2", value = "当前的降雨强度"), |
| | | @ApiImplicitParam(name = "serviceName", value = "服务名") |
| | | }) |
| | | @GetMapping("/realTime") |
| | | public R<Object> realTimeSimulate(String date1, double rainfall1, |
| | | String date2, double rainfall2, String serviceName) { |
| | | RealTimeInput input = new RealTimeInput(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDateTime t1 = LocalDateTime.parse(date1, formatter); |
| | | LocalDateTime t2 = LocalDateTime.parse(date2, formatter); |
| | | RealTimeInput.RealTimeData d1 = new RealTimeInput.RealTimeData(); |
| | | d1.setDateTime(t1); |
| | | d1.setIntensity(rainfall1); |
| | | RealTimeInput.RealTimeData d2 = new RealTimeInput.RealTimeData(); |
| | | d2.setDateTime(t2); |
| | | d2.setIntensity(rainfall2); |
| | | input.setData(Arrays.asList(d1, d2)); |
| | | input.setServiceName(serviceName); |
| | | |
| | | try { |
| | | String layerJsonName = resolveService.realTimeSimulate(input); |
| | | return success(layerJsonName); |
| | | } catch (IOException e) { |
| | | log.error("real-time simulate exception:", e); |
| | | return fail("实时模拟异常"); |
| | | @ApiOperation(value = "crossSection") |
| | | @GetMapping("/crossSection") |
| | | public R<Object> crossSection(String serviceName, double[] startPoint, double[] endPoint) { |
| | | if (serviceName == null) { |
| | | return clientError("服务名不能为空"); |
| | | } |
| | | if (startPoint == null) { |
| | | return clientError("起点不能为空"); |
| | | } |
| | | if (startPoint.length < 2) { |
| | | return clientError("起点至少包含x,y两个值"); |
| | | } |
| | | if (endPoint == null) { |
| | | return clientError("终点不能为空"); |
| | | } |
| | | if (endPoint.length < 2) { |
| | | return clientError("终点至少包含x,y两个值"); |
| | | } |
| | | List<CrossSectionAnalysisResult> result = scas.crossSectionAnalysis(serviceName, startPoint, endPoint); |
| | | return success(result); |
| | | } |
| | | |
| | | @ApiOperation(value = "realTime") |
| | | @PostMapping("/realTime2") |
| | | public R<Object> realTimeSimulate(@RequestBody RealTimeSimuParam param) { |
| | | try { |
| | | String layerJsonName = rts.realTimeSimulate(param); |
| | | return success(layerJsonName); |
| | | } catch (IOException e) { |
| | | log.error("real-time simulate exception:", e); |
| | | return fail("实时模拟异常"); |
| | | @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, "正在停止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()); |
| | | } |
| | | } |