¶Ô±ÈÐÂÎļþ |
| | |
| | | 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.*; |
| | | import com.se.nsl.service.RealTimeSimulationService; |
| | | import com.se.nsl.service.ResolveService; |
| | | import com.se.nsl.service.SimuService; |
| | | 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.gdal.ogr.ogr; |
| | | import org.springframework.util.StringUtils; |
| | | 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ï¼æ¨æ¼æ¨¡æ") |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/simu") |
| | | @SuppressWarnings("ALL") |
| | | public class SimuController extends BaseController { |
| | | @Resource |
| | | SimuService simuService; |
| | | |
| | | @Resource |
| | | ResolveService resolveService; |
| | | |
| | | @Resource |
| | | RealTimeSimulationService rts; |
| | | |
| | | /** |
| | | * å页æ¥è¯¢æ¨æ¼æ¨¡æ |
| | | * |
| | | * @param pageNum 页ç |
| | | * @param pageSize æ¯é¡µæ°é |
| | | * @return å页åçæ¨æ¼æ¨¡æ |
| | | */ |
| | | @ApiOperation(value = "selectPage") |
| | | @GetMapping("/selectPage") |
| | | public R<Object> selectPage(SimuVo vo, Integer pageNum, Integer pageSize) { |
| | | try { |
| | | if (null == pageNum || pageNum < 1) pageNum = 1; |
| | | if (null == pageSize || pageSize < 1) pageSize = 10; |
| | | if (pageSize > 1000) pageSize = 1000; |
| | | |
| | | IPage<Simu> paged = simuService.selectPage(vo, pageNum, pageSize); |
| | | if (null == paged) { |
| | | return success(null, 0); |
| | | } |
| | | |
| | | return success(paged.getRecords(), paged.getTotal()); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®IDæ¹éå 餿¨æ¼æ¨¡æ |
| | | * |
| | | * @param ids è¦å é¤çæ¨æ¼æ¨¡æIDå表 |
| | | * @return å 餿åçè®°å½æ° |
| | | */ |
| | | @ApiOperation(value = "deleteByIds") |
| | | @DeleteMapping("/deleteByIds") |
| | | public R<Object> deleteByIds(@RequestParam List<Integer> ids) { |
| | | try { |
| | | return success(simuService.deleteByIds(ids)); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢æ¨æ¼æ¨¡æ |
| | | * |
| | | * @param simu æ¨æ¼æ¨¡æå¯¹è±¡ |
| | | * @return æ°å¢æåçè®°å½æ° |
| | | */ |
| | | @ApiOperation(value = "insert") |
| | | @PostMapping(value = "/insert", produces = "application/json; charset=UTF-8") |
| | | public R<Object> insert(@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å¯¹è±¡ä¸æ¯å¤è¾¹å½¢"); |
| | | |
| | | 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); |
| | | } |
| | | JSONObject json = new JSONObject(); |
| | | json.put("id", simu.getId()); |
| | | return success(json); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "start") |
| | | @GetMapping(value = "/start", produces = "application/json; charset=UTF-8") |
| | | public R<Object> start(Integer id) { |
| | | try { |
| | | if (null == id || id < 1) return fail("id为空"); |
| | | |
| | | Simu simu = simuService.selectById(id); |
| | | if (null == simu) return fail("æ¹æ¡æ¾ä¸å°"); |
| | | 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 (StringUtils.isEmpty(simu.getGeom())) return fail("æ¹æ¡çå¾å½¢ä¸ºç©º"); |
| | | |
| | | int rows = resolveService.start(simu); |
| | | |
| | | return success("ok"); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹æ¨æ¼æ¨¡æ |
| | | * |
| | | * @param simu æ¨æ¼æ¨¡æå¯¹è±¡ |
| | | * @return ä¿®æ¹æåçè®°å½æ° |
| | | */ |
| | | @ApiOperation(value = "updateById") |
| | | @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 = "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 = "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("宿¶æ¨¡æå¼å¸¸"); |
| | | } |
| | | } |
| | | } |