wuww
2025-04-18 bf298e5a8fa61e060c1bc18ad2db20a08f57b6b2
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
package com.se.nsl.controller;
 
import com.se.nsl.domain.po.DataPo;
import com.se.nsl.domain.po.Region;
import com.se.nsl.domain.vo.R;
import com.se.nsl.helper.GdalHelper;
import com.se.nsl.helper.ShpHelper;
import com.se.nsl.helper.StringHelper;
import com.se.nsl.mapper.RegionMapper;
import com.se.nsl.service.*;
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.gdal.ogr.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
 
@Api(tags = "Test")
@Slf4j
@RestController
@RequestMapping("/test")
@SuppressWarnings("ALL")
public class TestController extends BaseController {
    @Resource
    UwService uwService;
 
    @Resource
    TestService testService;
 
    @Resource
    GedbService gedbService;
 
    @Resource
    SimuPoService simuPoService;
 
    @Resource
    Hdf5Service hdf5Service;
 
    @Resource
    ResultService resultService;
 
    @Resource
    RegionMapper regionMapper;
 
    @ApiOperation(value = "当前时间 *")
    @GetMapping("/getTime")
    public Object getTime() {
        return System.currentTimeMillis();
    }
 
    @ApiOperation(value = "testCallExe *")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query", example = "20241010095328")
    })
    @GetMapping("/testCallExe")
    public R<Object> testCallExe(String path) {
        try {
            DataPo data = new DataPo();
            data.setInPath(path);
 
            String str = uwService.callExe(data);
 
            return success(str);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @ApiOperation(value = "testResuslt *")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query", example = "20241107092342"),
            @ApiImplicitParam(name = "time", value = "时间", dataType = "String", paramType = "query", example = "2024-11-07 09:23:42")
    })
    @GetMapping("/testResuslt")
    public R<Object> testResuslt(String path, String time) {
        try {
            DataPo data = new DataPo();
            data.setEpsg(4548);
            data.setInPath(path);
            data.setStartTime(StringHelper.YMDHMS_FORMAT.parse(time));
 
            resultService.process(data);
 
            return success("ok");
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @ApiOperation(value = "testSww2Tif *")
    @GetMapping("/testSww2Tif")
    public R<Object> testSww2Tif() {
        try {
            DataPo data = new DataPo();
            data.setEpsg(4548);
            data.setInPath("20241010095328");
            data.setStartTime(StringHelper.YMDHMS_FORMAT.parse("2024-09-30 00:00:00"));
 
            Object rs = uwService.copeDrainFiles(data);
 
            return success(rs);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @ApiOperation(value = "testRainfall *")
    @GetMapping("/testRainfall")
    public R<Object> testRainfall() {
        try {
            DataPo data = new DataPo();
            data.setEpsg(4548);
            data.setTotal(60.0);
            data.setDuration(60);
            data.setInPath("20241010095328");
            data.setStartTime(StringHelper.YMDHMS_FORMAT.parse("2024-07-01 00:00:00"));
 
            uwService.createRainFile(data);
 
            return success("ok");
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @ApiOperation(value = "testToken *")
    @GetMapping("/testToken")
    public R<Object> testToken() {
        try {
            String token = gedbService.getToken();
 
            return success(token);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @ApiOperation(value = "testPolygonize *")
    @GetMapping("/testPolygonize")
    public R<Object> testPolygonize() {
        try {
            ShpHelper.test();
 
            return success("ok");
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @ApiOperation(value = "testH5 *")
    @GetMapping("/testH5")
    public R<Object> testH5() {
        try {
            DataPo data = new DataPo();
            data.setEpsg(4548);
            data.setInPath("20241010095328");
            data.setStartTime(StringHelper.YMDHMS_FORMAT.parse("2024-09-30 00:00:00"));
 
            hdf5Service.test(data);
 
            return success("ok");
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @ApiOperation(value = "testNsl <")
    @GetMapping("/testNsl")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inPath", value = "输入路径", dataType = "String", paramType = "query", example = "20250412"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "Integer", paramType = "query", example = "2025-04-12 00:00:00"),
            @ApiImplicitParam(name = "epsg", value = "坐标系ID", dataType = "Integer", paramType = "query", example = "4548")
    })
    public R<Object> testNsl(String inPath, String startTime, Integer epsg) {
        try {
            DataPo data = new DataPo();
            data.setInPath(inPath);
            data.setStartTime(StringHelper.YMDHMS_FORMAT.parse(startTime));
            data.setEpsg(epsg);
 
            testService.test(data);
 
            return success("ok");
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @ApiOperation(value = "insertRegion <")
    @GetMapping("/insertRegion")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fileName", value = "文件名", dataType = "String", paramType = "query", example = "5.beijing.geoJson"),
            @ApiImplicitParam(name = "type", value = "类型", dataType = "Integer", paramType = "query", example = "1")
    })
    public R<Object> insertRegion(String fileName, Integer type) {
        return insertNsl(fileName, type);
    }
 
    private R<Object> insertNsl(String fileName, Integer type) {
        // 孙胡沟geometry.json,7.nsl_area.geojson,4.10000.geoJson,5.beijing.geoJson
        String path = "D:\\terrait\\NslServer\\data\\" + fileName;
        if (!new File(path).exists()) return fail(path + ",文件不存在", null);
 
        org.gdal.ogr.Driver driver = ogr.GetDriverByName("GeoJSON");
        if (null == driver) return fail("null");
        DataSource ds = driver.Open(path);
        if (null == ds) return fail("null");
 
        List<Region> list = new ArrayList<>();
        for (int i = 0, c = ds.GetLayerCount(); i < c; i++) {
            Layer layer = ds.GetLayer(i);
            for (long j = 0, d = layer.GetFeatureCount(); j <= d; j++) {
                Feature f = layer.GetFeature(j);
                if (null == f || null == f.GetGeometryRef()) continue;
 
                String wkt = f.GetGeometryRef().ExportToWkt().toUpperCase();
                if (!wkt.contains("POLYGON"))
                    continue; // g.GetGeometryType() == ogr.wkbPolygon || g.GetGeometryType() == ogr.wkbMultiPolygon
 
                if (!wkt.contains("MULTIPOLYGON")) wkt = wkt.replace("POLYGON (", "MULTIPOLYGON ((") + ")";
                list.add(new Region(f.GetFieldAsString("name"), type.shortValue(), wkt));
                if (path.contains("孙胡沟")) list.add(new Region(f.GetFieldAsString("name"), (short) 3, wkt));
            }
        }
        ds.delete();
        driver.delete();
 
        return success(list.size() > 0 ? regionMapper.inserts(list) : 0);
    }
}