| | |
| | | package com.se.nsl.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.se.nsl.domain.po.Simu; |
| | | import com.se.nsl.domain.po.SimuData; |
| | | import com.se.nsl.domain.vo.R; |
| | | import com.se.nsl.domain.vo.SimuVo; |
| | | import com.se.nsl.service.ResolveService; |
| | | import com.se.nsl.service.SimuService; |
| | | import com.se.nsl.domain.vo.*; |
| | | import com.se.nsl.service.*; |
| | | import com.se.nsl.utils.SimulateType; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.ogr.Geometry; |
| | | import org.gdal.ogr.ogr; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | |
| | | @Resource |
| | | ResolveService resolveService; |
| | | |
| | | @Resource |
| | | RealTimeSimulationAsyncService rtsas; |
| | | |
| | | @Resource |
| | | CrossSectionAnalysisService scas; |
| | | |
| | | /** |
| | | * 分页查询推演模拟 |
| | |
| | | |
| | | SimuData data = JSON.parseObject(simu.getData(), SimuData.class); |
| | | if (null == data) return fail("data数据格式(JSON)不正确"); |
| | | if (StringUtils.isEmpty(simu.getGeom())) return fail("geom字符串不是WKT格式"); |
| | | |
| | | Geometry geom = Geometry.CreateFromWkt(simu.getGeom()); |
| | | if (!(geom.GetGeometryType() == ogr.wkbMultiPolygon || geom.GetGeometryType() == ogr.wkbPolygon)) |
| | | return fail("geom对象不是多边形"); |
| | | |
| | | int rows = simuService.insert(simu); |
| | | |
| | | return success(rows); |
| | | System.out.println(String.format("id:%s", simu.getId())); |
| | | 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()); |
| | | return success(json); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | |
| | | 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 (null == data) return fail("方案数据格式(JSON)不正确"); |
| | | |
| | | if (simu.getStatus() != 0) return fail("方案正在运行或已完成"); |
| | | //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); |
| | | } |
| | |
| | | @PutMapping(value = "/updateById", produces = "application/json; charset=UTF-8") |
| | | public R<Object> updateById(@RequestBody Simu simu) { |
| | | try { |
| | | if (StringUtils.isEmpty(simu.getData())) return fail("data为空"); |
| | | |
| | | SimuData data = JSON.parseObject(simu.getData(), SimuData.class); |
| | | if (null == data) return fail("data数据格式(JSON)不正确"); |
| | | if (StringUtils.isEmpty(simu.getGeom())) return fail("geom字符串不是WKT格式"); |
| | | |
| | | Geometry geom = Geometry.CreateFromWkt(simu.getGeom()); |
| | | if (!(geom.GetGeometryType() == ogr.wkbMultiPolygon || geom.GetGeometryType() == ogr.wkbPolygon)) |
| | | return fail("geom对象不是多边形"); |
| | | |
| | | if (null == data.getRainfalls() || data.getRainfalls().size() < 2) resolveService.createRainfall(simu); |
| | | |
| | | return success(simuService.updateById(simu)); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "position") |
| | | @GetMapping("/position") |
| | | public R<Object> queryByPosition(double lon, double lat, Long time, String serviceName) { |
| | | if (lon > 180 || lon < -180) { |
| | | return clientError("经度范围应该在-180到180"); |
| | | } |
| | | if (lat > 90 || lat < -90) { |
| | | return clientError("纬度范围应该在-90到90"); |
| | | } |
| | | if (serviceName == null || serviceName.trim().isEmpty()) { |
| | | return clientError("服务名不能为空"); |
| | | } |
| | | if (time != null) { |
| | | SimuResult result = simuService.queryByPosition(lon, lat, time, serviceName); |
| | | if (result == null) { |
| | | return notFound("未查找到相关数据"); |
| | | } |
| | | return success(result, 1); |
| | | } else { |
| | | List<SimuResult> simuResults = simuService.queryByPosition(lon, lat, serviceName); |
| | | if (simuResults.isEmpty()) { |
| | | return notFound("未查找到相关数据"); |
| | | } |
| | | return success(simuResults, simuResults.size()); |
| | | } |
| | | } |
| | | |
| | | @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 = "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()); |
| | | } |
| | | } |