From dc0601492c12ea8009ab0e47ff25ec0e78f60903 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期六, 02 十一月 2024 08:29:14 +0800 Subject: [PATCH] 添加查询建筑物涉水深度接口 --- src/main/java/com/se/simu/domain/vo/BuildingDepthVo.java | 12 ++++-- src/main/java/com/se/simu/controller/WaterController.java | 44 +++++++++++++++++++++ src/main/java/com/se/simu/service/WaterService.java | 42 +++++++++++++++++++++ 3 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/se/simu/controller/WaterController.java b/src/main/java/com/se/simu/controller/WaterController.java index fdeba3f..4befa5a 100644 --- a/src/main/java/com/se/simu/controller/WaterController.java +++ b/src/main/java/com/se/simu/controller/WaterController.java @@ -2,6 +2,7 @@ import com.se.simu.domain.po.SimuPo; import com.se.simu.domain.vo.R; +import com.se.simu.helper.StringHelper; import com.se.simu.helper.WebHelper; import com.se.simu.service.SimuService; import com.se.simu.service.WaterService; @@ -145,13 +146,13 @@ } @ApiOperation(value = "鏍规嵁鍧愭爣鏌ヨ绉按娣卞害") - @GetMapping("/{serviceName}/getWaterHeight") @ApiImplicitParams({ @ApiImplicitParam(name = "serviceName", value = "鏈嶅姟鍚�", dataType = "String", paramType = "path", example = "20241010095328"), @ApiImplicitParam(name = "x", value = "X", dataType = "double", paramType = "query", example = "116.6447998"), @ApiImplicitParam(name = "y", value = "Y", dataType = "double", paramType = "query", example = "39.8868915"), @ApiImplicitParam(name = "timestamp", value = "鏃堕棿鎴�", dataType = "long", paramType = "query", example = "1730217660000") }) + @GetMapping("/{serviceName}/getWaterHeight") public R<Double> getWaterHeight(@PathVariable String serviceName, double x, double y, long timestamp, HttpServletResponse res) { try { SimuPo simu = simuService.getSimuByServiceName(serviceName); @@ -167,6 +168,47 @@ } } + @ApiOperation(value = "鏍规嵁seid鏌ヨ寤虹瓚鐗╂秹姘存繁搴�") + @ApiImplicitParams({ + @ApiImplicitParam(name = "serviceName", value = "鏈嶅姟鍚�", dataType = "String", paramType = "path", example = "20241010095328"), + @ApiImplicitParam(name = "seid", value = "X", dataType = "String", paramType = "query", example = "5_f128d8b1aba6455c88d2f42334ca62bb") + }) + @GetMapping("/{serviceName}/getBuildingDepthBySeid") + public R<Object> getBuildingDepthBySeid(@PathVariable String serviceName, String seid) { + try { + if (StringHelper.isEmpty(serviceName) || StringHelper.isEmpty(seid)) { + return null; + } + + // 鏍规嵁鏈嶅姟鍚�+鏃堕棿鎴�+鍧愭爣锛屾煡璇㈠搴旂殑绉按娣卞害 + return success(waterService.getBuildingDepthBySeid(serviceName, seid)); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + return fail(ex); + } + } + + + @ApiOperation(value = "鏍规嵁timestamp鏌ヨ寤虹瓚鐗╂秹姘存繁搴�") + @ApiImplicitParams({ + @ApiImplicitParam(name = "serviceName", value = "鏈嶅姟鍚�", dataType = "String", paramType = "path", example = "20241010095328"), + @ApiImplicitParam(name = "timestamp", value = "鏃堕棿鎴�", dataType = "Long", paramType = "query", example = "1730217660000") + }) + @GetMapping("/{serviceName}/getBuildingDepthByTime") + public R<Object> getBuildingDepthByTime(@PathVariable String serviceName, Long timestamp) { + try { + if (StringHelper.isEmpty(serviceName) || null == timestamp) { + return null; + } + + // 鏍规嵁鏈嶅姟鍚�+鏃堕棿鎴�+鍧愭爣锛屾煡璇㈠搴旂殑绉按娣卞害 + return success(waterService.getBuildingDepthByTime(serviceName, timestamp)); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + return fail(ex); + } + } + private boolean validate(String serviceName, HttpServletResponse res) { if (WebHelper.isEmpty(serviceName)) { return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "鏈嶅姟鍚嶄笉鑳戒负绌�"); diff --git a/src/main/java/com/se/simu/domain/vo/BuildingDepthVo.java b/src/main/java/com/se/simu/domain/vo/BuildingDepthVo.java index 262db17..21280a9 100644 --- a/src/main/java/com/se/simu/domain/vo/BuildingDepthVo.java +++ b/src/main/java/com/se/simu/domain/vo/BuildingDepthVo.java @@ -1,6 +1,7 @@ package com.se.simu.domain.vo; import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -18,16 +19,19 @@ public BuildingDepthVo() { } - public BuildingDepthVo(String seid, String timestamp, Double depth) { + public BuildingDepthVo(String seid, Long timestamp, Double depth) { this.seid = seid; this.timestamp = timestamp; this.depth = depth; } + @ApiModelProperty("SE涓婚敭") private String seid; - private String timestamp; + @ApiModelProperty("鏃堕棿鎴�") + private Long timestamp; + @ApiModelProperty("娑夋按灏濊瘯") private Double depth; public String getSeid() { @@ -38,11 +42,11 @@ this.seid = seid; } - public String getTimestamp() { + public Long getTimestamp() { return timestamp; } - public void setTimestamp(String timestamp) { + public void setTimestamp(Long timestamp) { this.timestamp = timestamp; } diff --git a/src/main/java/com/se/simu/service/WaterService.java b/src/main/java/com/se/simu/service/WaterService.java index 7d6061a..871df44 100644 --- a/src/main/java/com/se/simu/service/WaterService.java +++ b/src/main/java/com/se/simu/service/WaterService.java @@ -1,11 +1,13 @@ package com.se.simu.service; +import cn.hutool.core.io.FileUtil; import cn.hutool.json.JSONUtil; import com.se.simu.config.PropertiesConfig; import com.se.simu.domain.po.DataPo; import com.se.simu.domain.po.SimuPo; import com.se.simu.domain.vo.*; import com.se.simu.helper.GdalHelper; +import com.se.simu.helper.StringHelper; import lombok.extern.slf4j.Slf4j; import org.gdal.gdal.Dataset; import org.gdal.gdal.gdal; @@ -13,6 +15,7 @@ import org.gdal.osr.SpatialReference; import org.gdal.osr.osr; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.io.File; @@ -20,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; /** * 鍐呮稘鏈嶅姟绫� @@ -171,4 +175,42 @@ public static boolean isValid(double val) { return !Double.isNaN(val) && val > Integer.MIN_VALUE; } + + public List<BuildingDepthVo> getBuildingDepthBySeid(String serviceName, String seid) { + List<BuildingDepthVo> list = readBuildingJson(serviceName); + if (CollectionUtils.isEmpty(list)) return null; + + return list.parallelStream() + .filter(b -> seid.equals(b.getSeid())) + .sorted((a, b) -> a.getTimestamp().compareTo(b.getTimestamp())) + .collect(Collectors.toList()); + } + + public List<BuildingDepthVo> getBuildingDepthByTime(String serviceName, Long timestamp) { + List<BuildingDepthVo> list = readBuildingJson(serviceName); + if (CollectionUtils.isEmpty(list)) { + return null; + } + + return list.parallelStream().filter(b -> timestamp.equals(b.getTimestamp())).collect(Collectors.toList()); + } + + private List<BuildingDepthVo> readBuildingJson(String serviceName) { + String filePath = config.getOutPath() + File.separator + serviceName + File.separator + "building.json"; + String json = getText(filePath); + if (StringHelper.isEmpty(json)) { + return null; + } + + return JSONUtil.toList(json, BuildingDepthVo.class); + } + + private String getText(String filePath) { + File file = new File(filePath); + if (!file.exists()) { + return null; + } + + return FileUtil.readUtf8String(file); + } } -- Gitblit v1.9.3