1
13693261870
2024-11-01 a6415c0c5116172db31fd353032fdfd11ac91544
src/main/java/com/se/simu/controller/WaterController.java
@@ -1,6 +1,7 @@
package com.se.simu.controller;
import com.se.simu.domain.po.SimuPo;
import com.se.simu.domain.vo.R;
import com.se.simu.helper.WebHelper;
import com.se.simu.service.SimuService;
import com.se.simu.service.WaterService;
@@ -28,7 +29,7 @@
@Slf4j
@RestController
@RequestMapping("/waterlogging")
public class WaterController {
public class WaterController extends BaseController {
    @Resource
    SimuService simuService;
@@ -41,15 +42,49 @@
    private final static long Y2000 = 949334400000L;
    @ApiOperation(value = "获取元数据信息")
    @ApiOperation(value = "获取元数据JSON")
    @GetMapping("/{serviceName}/layer.json")
    public void getLayer(@PathVariable String serviceName, HttpServletResponse res) {
    public void getLayerJson(@PathVariable String serviceName, HttpServletResponse res) {
        try {
            if (!validate(serviceName, res)) {
                return;
            }
            byte[] bytes = waterService.getLayerJson(serviceName);
            byte[] bytes = waterService.getson(serviceName, "layer.json");
            WebHelper.writeBytes(bytes, res);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
        }
    }
    @ApiOperation(value = "获取降水曲线JSON")
    @GetMapping("/{serviceName}/rainfall.json")
    public void getRainfallJson(@PathVariable String serviceName, HttpServletResponse res) {
        try {
            if (!validate(serviceName, res)) {
                return;
            }
            byte[] bytes = waterService.getson(serviceName, "rainfall.json");
            WebHelper.writeBytes(bytes, res);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
        }
    }
    @ApiOperation(value = "获取建筑物涉水JSON")
    @GetMapping("/{serviceName}/building.json")
    public void getBuildingJson(@PathVariable String serviceName, HttpServletResponse res) {
        try {
            if (!validate(serviceName, res)) {
                return;
            }
            byte[] bytes = waterService.getson(serviceName, "building.json");
            WebHelper.writeBytes(bytes, res);
        } catch (Exception ex) {
@@ -109,23 +144,6 @@
        }
    }
    @ApiOperation(value = "获取降水曲线文件曲线图")
    @GetMapping("/{serviceName}/rainfall.json")
    public void getRainfall(@PathVariable String serviceName, HttpServletResponse res) {
        try {
            if (!validate(serviceName, res)) {
                return;
            }
            byte[] bytes = waterService.getRainfall(serviceName);
            WebHelper.writeBytes(bytes, res);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
        }
    }
    @ApiOperation(value = "根据坐标查询积水深度")
    @GetMapping("/{serviceName}/getWaterHeight")
    @ApiImplicitParams({
@@ -134,7 +152,7 @@
            @ApiImplicitParam(name = "y", value = "Y", dataType = "double", paramType = "query", example = "39.8868915"),
            @ApiImplicitParam(name = "timestamp", value = "时间戳", dataType = "long", paramType = "query", example = "1730217660000")
    })
    public Double getWaterHeight(@PathVariable String serviceName, double x, double y, long timestamp, HttpServletResponse res) {
    public R<Double> getWaterHeight(@PathVariable String serviceName, double x, double y, long timestamp, HttpServletResponse res) {
        try {
            SimuPo simu = simuService.getSimuByServiceName(serviceName);
            if (null == simu) {
@@ -142,10 +160,10 @@
            }
            // 根据服务名+时间戳+坐标,查询对应的积水深度
            return waterService.getWaterHeight(simu, x, y, timestamp);
            return success(waterService.getWaterHeight(simu, x, y, timestamp));
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return null;
            return fail(ex);
        }
    }