src/main/java/com/se/simu/controller/WaterController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/simu/domain/vo/BuildingDepthVo.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/simu/service/WaterService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
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, "服务名不能为空"); 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; } 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); } }