13693261870
昨天 32eb942e25aa366563b7f40b05a382c0c462213c
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
package com.terra.system.controller.data.upload;
 
import com.terra.common.annotation.SysLog;
import com.terra.common.entity.all.ResponseMsg;
import com.terra.system.entity.ctrl.KeyValueEntity;
import com.terra.system.entity.data.DirEntity;
import com.terra.system.entity.data.MetaEntity;
import com.terra.system.entity.data.MetaFileEntity;
import com.terra.system.entity.data.VerEntity;
import com.terra.system.entity.sys.UserEntity;
import com.terra.common.helper.StringHelper;
import com.terra.system.service.all.UploadAttachService;
import com.terra.system.service.data.UploadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import javax.annotation.Resource;
 
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
 
/**
 * 数据入库
 * @author WWW
 */
@Tag(name = "数据管理\\数据上传")
@RestController
@RequestMapping("/dataUpload")
public class UploadController extends QueryController {
    @Resource
    UploadService uploadService;
 
    @Resource
    UploadAttachService uploadAttachService;
 
    @SysLog()
    @Operation(summary = "查询路径")
    @GetMapping(value = "/selectPath")
    public ResponseMsg<String> selectPath() {
        try {
            String pathName = uploadService.selectPath();
 
            return success(pathName);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "上传文件")
    @Parameters({
            @Parameter(name = "path", description = "路径", in = ParameterIn.QUERY)
    })
    @ResponseBody
    @PostMapping(value = "/uploadFiles")
    public ResponseMsg<Object> uploadFiles(String path, HttpServletRequest req, HttpServletResponse res) {
        try {
            List<MetaFileEntity> list = uploadService.uploadData(null, path, false, req, res);
            if (null == list || list.isEmpty()) {
                return fail("没有找到上传文件", null);
            }
 
            uploadService.copePath(list);
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    /**
     * 接收数组1:@RequestParam(value = "ids")List<Integer> ids
     *          &ids=1209&ids=1180&ids=1387
     * 接收数据2:Integer[] ids
     *          formData.append("ids", 1209); formData.append("ids", 1180); formData.append("ids", 1387);
     */
    @SysLog()
    @Operation(summary = "上传Excel附件")
    @Parameters({
            @Parameter(name = "path", description = "路径", in = ParameterIn.QUERY),
            @Parameter(name = "ids", description = "元数据集合", schema = @Schema(type = "array"), in = ParameterIn.QUERY)
    })
    @ResponseBody
    @PostMapping(value = "/uploadXlsAnnex")
    public ResponseMsg<Object> uploadXlsAnnex(String path, Integer[] ids, HttpServletRequest req, HttpServletResponse res) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
            if (null == ids || ids.length == 0) {
                return fail("找不到元数据的ID集合");
            }
 
            List<MetaEntity> ms = metaService.selectXlsAnnex(ids, UploadAttachService.getTabs());
            if (null == ms || ms.isEmpty()) {
                return fail("找不到要上传附件的元数据");
            }
 
            List<MetaFileEntity> list = uploadService.uploadData(null, path, false, req, res);
            if (null == list || list.isEmpty()) {
                return fail("没有找到上传文件", null);
            }
 
            List<KeyValueEntity> rs = uploadAttachService.uploadXlsAnnex(ue, ms, list, path);
            if (null == rs || rs.size() == 0) {
                return fail("没有要更新的元数据");
            }
 
            return success(rs);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "查询文件")
    @Parameters({
            @Parameter(name = "path", description = "路径", in = ParameterIn.QUERY)
    })
    @GetMapping(value = "/selectFiles")
    public ResponseMsg<List<MetaFileEntity>> selectFiles(String path) {
        try {
            List<MetaFileEntity> list = uploadService.selectFiles(path, false);
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "删除文件")
    @Parameters({
            @Parameter(name = "list", description = "实体类集合")
    })
    @ResponseBody
    @PostMapping(value = "/deleteFiles")
    public ResponseMsg<Object> deleteFiles(@RequestBody List<MetaFileEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
            if (null == list || list.isEmpty()) {
                return fail("没有找到文件", null);
            }
 
            int rows = uploadService.deleteFiles(list);
 
            return success("成功", rows);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "查询映射")
    @Parameters({
            @Parameter(name = "path", description = "路径", in = ParameterIn.QUERY, example = "20230722"),
            @Parameter(name = "dirid", description = "目录ID", in = ParameterIn.QUERY, example = "1"),
            @Parameter(name = "verid", description = "版本ID", in = ParameterIn.QUERY, example = "0"),
            @Parameter(name = "epsgCode", description = "坐标编码", in = ParameterIn.QUERY, example = "EPSG:4490")
    })
    @GetMapping(value = "/selectMappers")
    public ResponseMsg<Object> selectMappers(String path, Integer dirid, Integer verid, String epsgCode, HttpServletRequest req) {
        try {
            if (StringHelper.isEmpty(path) || StringHelper.isEmpty(epsgCode) || null == dirid || null == verid) {
                return fail("路径、目录ID、版本ID和坐标编码不能为空");
            }
            if (1 > uploadService.selectCount4Coord(epsgCode)) {
                return fail("坐标编码" + epsgCode + "不存在");
            }
            DirEntity dir = dirService.selectDir(dirid);
            if (null == dir) {
                return fail("目录ID=" + dirid + "不存在");
            }
            VerEntity ver = verService.selectVersion(verid);
            if (null == ver) {
                return fail("版本ID=" + verid + "不存在");
            }
 
            UserEntity ue = tokenService.getCurrentUser(req);
            List<MetaFileEntity> list = uploadService.selectMappers(ue, path, dir, ver, epsgCode);
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "插入文件")
    @Parameters({
            @Parameter(name = "list", description = "元数据文件集合")
    })
    @ResponseBody
    @PostMapping(value = "/insertFiles")
    public ResponseMsg<Object> insertFiles(@RequestBody List<MetaFileEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (null == ue) {
                return fail("用户未登录", null);
            }
            if (null == list || list.isEmpty()) {
                return fail("元数据文件集合为空", null);
            }
 
            uploadService.insertFiles(ue, list, req);
 
            return success("成功", list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "插入KML文件")
    @Parameters({
            @Parameter(name = "list", description = "元数据文件集合")
    })
    @ResponseBody
    @PostMapping(value = "/insertKml")
    public ResponseMsg<Object> insertKml(@RequestBody List<MetaFileEntity> list, HttpServletRequest req){
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (null == ue) {
                return fail("用户未登录", null);
            }
            if (null == list || list.isEmpty()) {
                return fail("元数据文件集合为空", null);
            }
 
            uploadService.insertKml(ue, list);
 
            return success("成功", list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "删除元数据")
    @Parameters({
            @Parameter(name = "ids", description = "ID数组", in = ParameterIn.QUERY, schema = @Schema(type = "array"), example = "1")
    })
    @GetMapping(value = "/deleteMetas")
    public ResponseMsg<Integer> deleteMetas(@RequestParam List<Integer> ids) {
        try {
            if (ids == null || ids.isEmpty()) {
                return fail("id数组不能为空", -1);
            }
 
            int count = metaService.deletes(ids);
 
            return success(count);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
}