13693261870
2025-06-24 8565bd83fcd670ec8379084d600eb97d18037d21
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
package com.terra.system.controller.data;
 
import com.terra.system.annotation.SysLog;
import com.terra.system.controller.all.BaseController;
import com.terra.system.entity.all.ResponseMsg;
import com.terra.system.entity.all.StaticData;
import com.terra.system.entity.ctrl.PubEntity;
import com.terra.system.entity.data.MetaEntity;
import com.terra.system.entity.data.PublishEntity;
import com.terra.system.entity.sys.UserEntity;
import com.terra.system.helper.PathHelper;
import com.terra.system.helper.StringHelper;
import com.terra.system.helper.WebHelper;
import com.terra.system.service.data.LayerService;
import com.terra.system.service.data.MetaService;
import com.terra.system.service.data.PublishService;
import com.terra.system.service.data.RasterService;
import com.terra.system.service.sys.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * 数据发布
 * @author WWW
 */
@Api(tags = "数据管理\\发布管理")
@RestController
@RequestMapping("/publish")
public class PublishController extends BaseController {
    @Resource
    PublishService publishService;
 
    @Resource
    TokenService tokenService;
 
    @Resource
    LayerService layerService;
 
    @Resource
    MetaService metaService;
 
    @Resource
    RasterService rasterService;
 
    @Resource
    PathHelper pathHelper;
 
    @ApiOperation(value = "测试查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "seconds", value = "秒", dataType = "Integer", paramType = "query", example = "30")
    })
    @GetMapping(value = "/selectForTest")
    public ResponseMsg<Object> selectForTest(Integer seconds) {
        try {
            if (null == seconds || seconds < 1) {
                seconds = 1;
            }
 
            String str = publishService.selectForTest(seconds);
 
            return success(str);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "分页查询元数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "depcode", value = "单位编码", dataType = "String", paramType = "query", example = "00"),
            @ApiImplicitParam(name = "dircode", value = "目录编码", dataType = "String", paramType = "query", example = "01"),
            @ApiImplicitParam(name = "verid", value = "版本ID", dataType = "Integer", paramType = "query", example = "0"),
            @ApiImplicitParam(name = "type", value = "类别", dataType = "String", paramType = "query", example = "DOM"),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"),
            @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectMetasByPage")
    public ResponseMsg<Object> selectMetasByPage(String depcode, String dircode, Integer verid, String type, String name, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            if (StringHelper.isEmpty(type)) {
                return fail("数据类别为空", null);
            }
 
            String types = getType(dircode, type);
            int count = publishService.selectMetasByCount(depcode, dircode, verid, types, name);
            if (count == 0) {
                return success(0, null);
            }
 
            List<MetaEntity> rs = publishService.selectMetasByPage(depcode, dircode, verid, types, name, pageSize, pageSize * (pageIndex - 1));
 
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
 
    /**
     * 获取类型
     */
    private String getType(String dircode, String type) throws Exception {
        switch (type) {
            case "DOM":
                return "type in ('tif', 'tiff', 'img')" + getFilter(dircode, type);
            case "DEM":
                return "type in ('tif', 'tiff')" + getFilter(dircode, type);
            case "MPT":
                return "type = 'mpt'";
            case "3DML":
                return "type = '3dml'";
            case "CPT":
                return "type = 'cpt'";
            case "BIM":
                return "type in ('ifc', 'fbx', 'rvt')";
            case "LAS":
                return "type in ('las', 'laz')";
            case "OSGB":
                return "type = 'osgb'";
            default:
                throw new Exception("数据类型不匹配");
        }
    }
 
    /**
     * 获取过滤条件
     */
    private String getFilter(String dircode, String type) {
        dircode = StringHelper.isEmpty(dircode) ? "" : StringHelper.getRightLike(dircode);
 
        List<String> list = null;
        switch (type) {
            case "DOM":
                list = publishService.selectCodesForDir(dircode, 0);
                break;
            case "DEM":
                list = publishService.selectCodesForDir(dircode, 1);
                break;
            default:
                break;
        }
        if (null == list || list.isEmpty()) {
            return "";
        }
 
        for (int i = 0, c = list.size(); i < c; i++) {
            list.set(i, "'" + list.get(i) + "'");
        }
 
        return " and dircode not in (" + StringHelper.join(list, ",") + ")";
    }
 
    @SysLog()
    @ApiOperation(value = "分页查询并返回记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "dircode", value = "目录", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "type", value = "类别", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"),
            @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectByPageAndCount")
    public ResponseMsg<List<PublishEntity>> selectByPageAndCount(String name, String dircode, String type, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            type = getPubType(type);
 
            int count = publishService.selectCount(name, dircode, type);
            if (count == 0) {
                return success(0, null);
            }
 
            List<PublishEntity> rs = publishService.selectByPage(name, dircode, type, pageSize, pageSize * (pageIndex - 1));
 
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
 
    /**
     * 获取发布类型
     */
    private String getPubType(String type) {
        if (StringHelper.isEmpty(type)) {
            return null;
        }
 
        switch (type) {
            case "DOM":
                return "type = 'DOM'";
            case "DEM":
                return "type = 'DEM'";
            case "MPT":
                return "type = 'mpt'";
            case "3DML":
                return "type = '3dml'";
            case "CPT":
                return "type = 'cpt'";
            case "BIM":
                return "type in ('ifc', 'fbx', 'rvt')";
            case "LAS":
                return "type in ('las', 'laz')";
            case "OSGB":
                return "type = 'osgb'";
            default:
                return null;
        }
    }
 
    @SysLog()
    @ApiOperation(value = "根据ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectById")
    public ResponseMsg<PublishEntity> selectById(int id) {
        try {
            PublishEntity entity = publishService.selectById(id);
 
            return success(entity);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "查询Las文件坐标系ID")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "元数据ID集合", dataType = "Integer[]", paramType = "query", example = "10483,10481,10456,10285")
    })
    @GetMapping(value = "/selectLasCs")
    public ResponseMsg<Object> selectLasCs(Integer[] ids, HttpServletRequest req) {
        try {
            if (null == ids || ids.length == 0) {
                return fail("元数据ID集合不能为空");
            }
 
            PubEntity entity = new PubEntity();
            entity.setIds(Arrays.asList(ids));
            entity.setDircode("00");
            entity.setToken(WebHelper.getToken(req));
 
            List<Integer> list = publishService.selectLasCs(entity, "/Convert/ReadLasCs", req);
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "查询栅格数据的坐标系ID")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "元数据ID集合", dataType = "Integer[]", paramType = "query", example = "10531,10527,10526")
    })
    @GetMapping(value = "/selectRasterCs")
    public ResponseMsg<Object> selectRasterCs(Integer[] ids, HttpServletRequest req) {
        try {
            if (null == ids || ids.length == 0) {
                return fail("元数据ID集合不能为空");
            }
 
            List<MetaEntity> list = metaService.selectByIds(StringHelper.join(Arrays.asList(ids), ","));
            if (null == list || list.isEmpty()) {
                return fail("查无数据");
            }
 
            String basePath = pathHelper.getConfig().getUploadPath() + File.separator;
            List<MetaEntity> errList = new ArrayList<>();
            for (MetaEntity me : list) {
                if (!StaticData.RASTER_EXT.contains("." + me.getType())) {
                    me.setBak("不是栅格数据");
                    errList.add(me);
                    continue;
                }
 
                String filePath = basePath + me.getPath();
                File f = new File(filePath);
                if (!f.exists() || f.isDirectory()) {
                    me.setBak("文件不存在");
                    errList.add(me);
                    continue;
                }
 
                // Integer epsg = rasterService.getRaterEpsg(filePath)
                Integer epsg = rasterService.getEpsgByGdal(filePath);
                if (null == epsg || epsg < 1) {
                    me.setBak("坐标系ID无效");
                    errList.add(me);
                }
            }
 
            return success(errList.size(), errList);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "查询坐标转换")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "x", value = "X坐标", dataType = "double", paramType = "query", example = "400925.079"),
            @ApiImplicitParam(name = "y", value = "Y坐标", dataType = "double", paramType = "query", example = "2541768.173"),
            @ApiImplicitParam(name = "epsg", value = "EPSG编码", dataType = "int", paramType = "query", example = "4548")
    })
    @GetMapping(value = "/selectCsTransform")
    public Object selectCsTransform(double x, double y, int epsg) {
        try {
            return rasterService.transformByProj4j(x, y, epsg);
        } catch (Exception ex) {
            return null;
        }
    }
 
    @SysLog()
    @ApiOperation(value = "插入发布数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "PubEntity", paramType = "body")
    })
    @PostMapping(value = "/insertForPub", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Object> insertForPub(@RequestBody PubEntity entity, HttpServletRequest req) {
        try {
            if (null == entity || null == entity.getIds() || entity.getIds().isEmpty()) {
                return fail("实体类为空或找不到元数据ID", 0);
            }
            if (StringHelper.isEmpty(entity.getType())) {
                return fail("数据类别为空", null);
            }
 
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setUserId(ue.getId());
                entity.setToken(WebHelper.getToken(req));
            }
 
            layerService.clearCache();
            String method = getConvertMethod(entity.getType());
            long count = publishService.postForPub(entity, method, req);
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
 
    /**
     * 获取转换方法
     */
    private String getConvertMethod(String type) throws Exception {
        switch (type) {
            case "DOM":
                return "/Convert/ToTiles";
            case "DEM":
                return "/Convert/ToTerra";
            case "MPT":
            case "3DML":
            case "CPT":
                return "/Convert/ToSG";
            case "BIM":
                return "/Convert/ToTileset";
            case "LAS":
                return "/Convert/ToLasByPy";
            case "OSGB":
                return "/Convert/ToOsgb";
            default:
                throw new Exception("数据类型不匹配");
        }
    }
 
    @SysLog()
    @ApiOperation(value = "删除多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", allowMultiple = true, example = "1")
    })
    @GetMapping(value = "/deletes")
    public ResponseMsg<Integer> deletes(@RequestParam List<Integer> ids, HttpServletRequest req) {
        try {
            if (ids == null || ids.isEmpty()) {
                return fail("id数组不能为空", -1);
            }
 
            String strs = StringHelper.join(ids, ",");
            List<PublishEntity> list = publishService.selectByIds(strs);
            if (null == list || list.isEmpty()) {
                return fail("没有找到要删除的数据", -1);
            }
 
            // publishService.deleteFiles(list)
            layerService.clearCache();
            publishService.deleteFiles(ids, req);
 
            int count = publishService.deletes(ids, req);
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "更新一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "PublishEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/update", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> update(@RequestBody PublishEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setUpdateUser(ue.getId());
            }
 
            layerService.clearCache();
            int count = publishService.update(entity);
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
}