From 51d12c4cca7c9d4911a0037673bbd2dc210836d0 Mon Sep 17 00:00:00 2001 From: dcb <xgybdcb@163.com> Date: 星期五, 20 六月 2025 10:17:12 +0800 Subject: [PATCH] 根据位置查询Bug修复 --- src/main/java/com/se/nsl/controller/SimuController.java | 199 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 199 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/se/nsl/controller/SimuController.java b/src/main/java/com/se/nsl/controller/SimuController.java new file mode 100644 index 0000000..fc5389d --- /dev/null +++ b/src/main/java/com/se/nsl/controller/SimuController.java @@ -0,0 +1,199 @@ +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瀛楃涓蹭笉鏄疻KT鏍煎紡"); + + 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("鏂规姝e湪杩愯鎴栧凡瀹屾垚"); + 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瀛楃涓蹭笉鏄疻KT鏍煎紡"); + + 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()); + } + } +} -- Gitblit v1.9.3