13693261870
2024-10-31 c738483367653c6485ddc9a6dcdea019ad08cc63
src/main/java/com/se/simu/controller/WaterController.java
@@ -1,8 +1,12 @@
package com.se.simu.controller;
import com.se.simu.domain.po.SimuPo;
import com.se.simu.helper.WebHelper;
import com.se.simu.service.SimuService;
import com.se.simu.service.WaterService;
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.springframework.http.HttpStatus;
@@ -25,6 +29,9 @@
@RestController
@RequestMapping("/waterlogging")
public class WaterController {
    @Resource
    SimuService simuService;
    @Resource
    WaterService waterService;
@@ -102,6 +109,46 @@
        }
    }
    @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({
            @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")
    })
    public Double getWaterHeight(@PathVariable String serviceName, double x, double y, long timestamp, HttpServletResponse res) {
        try {
            SimuPo simu = simuService.getSimuByServiceName(serviceName);
            if (null == simu) {
                return null;
            }
            // 根据服务名+时间戳+坐标,查询对应的积水深度
            return waterService.getWaterHeight(simu, x, y, timestamp);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return null;
        }
    }
    private boolean validate(String serviceName, HttpServletResponse res) {
        if (WebHelper.isEmpty(serviceName)) {
            return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "服务名不能为空");