13693261870
2024-09-13 d68ba69e9f4d8edb7b62da57749de052f203c9f0
src/main/java/com/se/simu/controller/WaterController.java
@@ -1,7 +1,7 @@
package com.se.simu.controller;
import com.se.simu.helper.StringHelper;
import com.se.simu.helper.WebHelper;
import com.se.simu.service.SedbService;
import com.se.simu.service.WaterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -21,17 +21,20 @@
 * @author WWW
 * @date   2024-07-16
 */
@Api(tags = "内涝管理")
@Api(tags = "内涝控制器")
@Slf4j
@RestController
@RequestMapping("/waterlogging")
public class WaterController {
    @Resource
    SedbService sedbService;
    @Resource
    WaterService waterService;
    private final static int MIN_SIZE = 10;
    private final static int MAX_SIZE = 10000000;
    private final static int MAX_SIZE = 80000;
    private final static long Y2000 = 949334400000L;
@@ -49,7 +52,9 @@
                return;
            }
            //
            byte[] bytes = waterService.getLayerJson(serviceName);
            WebHelper.writeBytes(bytes, res);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
@@ -64,7 +69,9 @@
                return;
            }
            //
            String file = waterService.getTerraMap(serviceName, width, height);
            WebHelper.writePng(file, res);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
@@ -79,7 +86,9 @@
                return;
            }
            //
            String file = waterService.getWaterMap(serviceName, width, height, timestamp);
            WebHelper.writePng(file, res);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
@@ -94,7 +103,9 @@
                return;
            }
            //
            String file = waterService.getFlowMap(serviceName, width, height, timestamp);
            WebHelper.writePng(file, res);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
@@ -102,7 +113,7 @@
    }
    private boolean validate(String serviceName, HttpServletResponse res) {
        if (StringHelper.isEmpty(serviceName)) {
        if (WebHelper.isEmpty(serviceName)) {
            return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "服务名不能为空");
        }
@@ -113,8 +124,11 @@
        return validate(serviceName, width, height, Y2000, res);
    }
    /**
     * 验证
     */
    private boolean validate(String serviceName, Integer width, Integer height, Long timestamp, HttpServletResponse res) {
        if (StringHelper.isEmpty(serviceName)) {
        if (WebHelper.isEmpty(serviceName)) {
            return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "服务名不能为空");
        }
        if (null == width || width < MIN_SIZE || width > MAX_SIZE) {
@@ -123,10 +137,21 @@
        if (null == height || height < MIN_SIZE || height > MAX_SIZE) {
            return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "图像高度不能为空且取值范围为" + MIN_SIZE + "~" + MAX_SIZE + "之间");
        }
        if (null == timestamp || timestamp < Y2000) {
            return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "时间不能为空且大于2000年");
        if (null == timestamp || timestamp < 0) {
            return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "时间不能为空且大于0");
        }
        return true;
    }
    @ApiOperation(value = "* 测试 *")
    @GetMapping("/test")
    public Object test() {
        try {
            return sedbService.test();
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return ex.getMessage();
        }
    }
}