wuww
2025-04-25 9d26a531d6aaad86500e04cc750da15d292e9beb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package com.se.nsl.controller;
 
import com.se.nsl.domain.po.SimuPo;
import com.se.nsl.domain.vo.PondingVo;
import com.se.nsl.domain.vo.R;
import com.se.nsl.helper.StringHelper;
import com.se.nsl.helper.WebHelper;
import com.se.nsl.service.SimuPoService;
import com.se.nsl.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;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
 
@Api(tags = "08-内涝管理")
@Slf4j
@RestController
@SuppressWarnings("ALL")
@RequestMapping("/waterlogging")
public class WaterController extends BaseController {
    @Resource
    SimuPoService simuPoService;
 
    @Resource
    WaterService waterService;
 
    private final static int MIN_SIZE = 10;
 
    private final static int MAX_SIZE = 80000;
 
    private final static long Y2000 = 949334400000L;
 
    @ApiOperation(value = "获取元数据JSON")
    @GetMapping("/{serviceName}/layer.json")
    public void getLayerJson(@PathVariable String serviceName, HttpServletResponse res) {
        try {
            if (!validate(serviceName, res)) {
                return;
            }
 
            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) {
            log.error(ex.getMessage(), ex);
            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
        }
    }
 
    @ApiOperation(value = "获取积水JSON")
    @GetMapping("/{serviceName}/{timestamp}/water.json")
    public void getWaterJson(@PathVariable String serviceName, @PathVariable String timestamp, HttpServletResponse res) {
        try {
            if (!validate(serviceName, res)) {
                return;
            }
 
            byte[] bytes = waterService.getson(serviceName, "waters" + File.separator + timestamp + File.separator + "water.json");
 
            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}/terrain")
    public void getTerraMap(@PathVariable String serviceName, Integer width, Integer height, HttpServletResponse res) {
        try {
            if (!validate(serviceName, width, height, res)) {
                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());
        }
    }
 
    @ApiOperation(value = "获取水面高度图")
    @GetMapping("/{serviceName}/waterMap")
    public void getWaterMap(@PathVariable String serviceName, Integer width, Integer height, Long timestamp, HttpServletResponse res) {
        try {
            if (!validate(serviceName, width, height, timestamp, res)) {
                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());
        }
    }
 
    @ApiOperation(value = "获取水流向流速图")
    @GetMapping("/{serviceName}/flowMap")
    public void getFlowMap(@PathVariable String serviceName, Integer width, Integer height, Long timestamp, HttpServletResponse res) {
        try {
            if (!validate(serviceName, width, height, timestamp, res)) {
                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());
        }
    }
 
    @ApiOperation(value = "根据坐标查询积水深度")
    @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<Object> getWaterHeight(@PathVariable String serviceName, double x, double y, long timestamp, HttpServletResponse res) {
        try {
            SimuPo simu = simuPoService.getSimuByServiceName(serviceName);
            if (null == simu) {
                return null;
            }
 
            Double depth = waterService.getWaterHeight(simu, x, y, timestamp);
            Double area = waterService.getWaterArea(simu, x, y, timestamp);
 
            return success(new PondingVo(depth, area));
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return fail(ex);
        }
    }
 
    @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, "服务名不能为空");
        }
 
        return true;
    }
 
    private boolean validate(String serviceName, Integer width, Integer height, HttpServletResponse res) {
        return validate(serviceName, width, height, Y2000, res);
    }
 
    /**
     * 验证
     */
    private boolean validate(String serviceName, Integer width, Integer height, Long timestamp, HttpServletResponse res) {
        if (WebHelper.isEmpty(serviceName)) {
            return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "服务名不能为空");
        }
        if (null == width || width < MIN_SIZE || width > MAX_SIZE) {
            return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "图像宽度不能为空且取值范围为" + MIN_SIZE + "~" + MAX_SIZE + "之间");
        }
        if (null == height || height < MIN_SIZE || height > MAX_SIZE) {
            return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "图像高度不能为空且取值范围为" + MIN_SIZE + "~" + MAX_SIZE + "之间");
        }
        if (null == timestamp || timestamp < 0) {
            return WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, "时间不能为空且大于0");
        }
 
        return true;
    }
}