13693261870
6 天以前 73e913fb24bf163ab9c5332ab960b1eb56a6402b
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
package com.terra.system.controller.data.upload;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.terra.system.annotation.SysLog;
import com.terra.common.entity.all.ResponseMsg;
import com.terra.common.entity.all.StaticData;
import com.terra.system.entity.ctrl.TabEntity;
import com.terra.system.entity.data.*;
import com.terra.system.entity.sys.DepEntity;
import com.terra.system.entity.sys.UserEntity;
import com.terra.system.helper.ClassHelper;
import com.terra.system.helper.StringHelper;
import com.terra.system.mapper.all.BasicMapper;
import com.terra.system.service.all.BaseQueryService;
import com.terra.system.service.data.*;
import com.terra.system.service.sys.DepService;
import com.terra.system.service.sys.TokenService;
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 org.springframework.web.bind.annotation.GetMapping;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
 
/**
 * 查询控制器
 * @author WWW
 */
public class QueryController extends CheckController {
    @Resource
    protected DepService depService;
 
    @Resource
    protected DirService dirService;
 
    @Resource
    protected VerService verService;
 
    @Resource
    protected MetaService metaService;
 
    @Resource
    protected TokenService tokenService;
 
    @Resource
    protected UploadService uploadService;
 
    @Resource
    protected BaseQueryService baseQueryService;
 
    @Resource
    DictService dictService;
 
    @SysLog()
    @Operation(summary = "根据父ID分页查询并返回记录数")
    @Parameters({
            @Parameter(name = "metaid", description = "父ID", in = ParameterIn.QUERY, example = "0"),
            @Parameter(name = "name", description = "名称", in = ParameterIn.QUERY, example = ""),
            @Parameter(name = "pageSize", description = "每页条数", in = ParameterIn.QUERY, example = "10"),
            @Parameter(name = "pageIndex", description = "分页数(从1开始)", in = ParameterIn.QUERY, example = "1")
    })
    @GetMapping(value = "/selectPageAndCountByPid")
    public ResponseMsg<List<MetaEntity>> selectPageAndCountByPid(Integer metaid, String name, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            if (null == metaid || metaid < 1) {
                return fail("父ID不能为空且大于1", null);
            }
 
            int count = metaService.selectCountByPid(metaid, name);
            if (count == 0) {
                return success(0, null);
            }
 
            List<MetaEntity> rs = metaService.selectPageByPid(metaid, name, pageSize, pageSize * (pageIndex - 1));
 
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "查询所有单位")
    @GetMapping(value = "/selectDepAll")
    public ResponseMsg<List<DepEntity>> selectDepAll() {
        try {
            List<DepEntity> list = depService.selectDepAll();
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "查询所有目录")
    @GetMapping(value = "/selectDirAll")
    public ResponseMsg<List<DirEntity>> selectDirAll() {
        try {
            List<DirEntity> list = dirService.selectDirAll();
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "根据目录ID查询版本列表")
    @Parameters({
            @Parameter(name = "dirid", description = "目录ID", in = ParameterIn.QUERY)
    })
    @GetMapping(value = "/selectVerByDirid")
    public ResponseMsg<List<VerEntity>> selectVerByDirid(Integer dirid) {
        try {
            if (null == dirid || dirid < 0) {
                dirid = 0;
            }
 
            List<VerEntity> list = verService.selectByDirid(dirid);
            if (null == list || list.isEmpty()) {
                list = verService.selectByDirid(0);
            }
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "查询坐标系")
    @Parameters({
            @Parameter(name = "zoning", description = "带号", in = ParameterIn.QUERY, example = "6度有带号")
    })
    @GetMapping(value = "/selectCoords")
    public ResponseMsg<Object> selectCoords(String zoning) {
        try {
            List<CoordEntity> list = uploadService.selectCoords(zoning);
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "查询项目名称")
    @GetMapping(value = "/selectProject")
    public ResponseMsg<Object> selectProject() {
        try {
            List<DirEntity> list = uploadService.selectProject();
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "查询所有表")
    @Parameters({
            @Parameter(name = "name", description = "名称", in = ParameterIn.QUERY, example = "点"),
            @Parameter(name = "hasGeom", description = "含有Geom字段", in = ParameterIn.QUERY, example = "false")
    })
    @GetMapping(value = "/selectTabs")
    public ResponseMsg<List<TabEntity>> selectTabs(String name, Boolean hasGeom) {
        try {
            List<TabEntity> list = dictService.selectDictTab(name, null == hasGeom || !hasGeom ? "gid" : "geom");
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "查询字段信息")
    @Parameters({
            @Parameter(name = "ns", description = "名称空间", in = ParameterIn.QUERY, example = "bd"),
            @Parameter(name = "tab", description = "表名", in = ParameterIn.QUERY, example = "dlg25wAanp")
    })
    @GetMapping(value = "/selectFields")
    public ResponseMsg<List<DictEntity>> selectFields(String ns, String tab) {
        try {
            if (StringHelper.isEmpty(ns) || StringHelper.isEmpty(tab)) {
                return fail("名称空间和表名不能为空", null);
            }
 
            List<DictEntity> list = baseQueryService.selectFields(ns, tab);
 
            return success(list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "查询表中数据")
    @Parameters({
            @Parameter(name = "id", description = "元数据ID", in = ParameterIn.QUERY, example = "115"),
            @Parameter(name = "pageIndex", description = "分页数(从1开始)", in = ParameterIn.QUERY, example = "1"),
            @Parameter(name = "pageSize", description = "每页条数", in = ParameterIn.QUERY, example = "10")
    })
    @GetMapping(value = "/selectDbData")
    public ResponseMsg<Object> selectDbData(Integer id, Integer pageIndex, Integer pageSize) {
        // noinspection AlibabaRemoveCommentedCode
        try {
            if (null == id || id < 0) {
                return fail("元数据ID不能为空或小于0", null);
            }
 
            MetaEntity meta = metaService.selectById(id);
            if (null == meta || null == meta.getTab() || !meta.getTab().contains(StaticData.POINT)) {
                return fail("找不到元数据信息", null);
            }
 
            String entity = meta.getTab().substring(meta.getTab().indexOf(".") + 1).replace("_", "").toLowerCase();
            BasicMapper baseMapper = ClassHelper.getBasicMapper(entity);
            if (null == baseMapper) {
                return null;
            }
 
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("parentid", meta.getEventid());
 
            Page<Object> page = new Page<>(pageIndex, pageSize);
            page.addOrder(OrderItem.desc("gid"));
            IPage<Object> paged = baseMapper.selectPage(page, wrapper);
 
            return success(paged.getTotal(), paged.getRecords());
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "分页查询上传数据并返回记录数")
    @Parameters({
            @Parameter(name = "name", description = "名称", in = ParameterIn.QUERY, example = ""),
            @Parameter(name = "pageSize", description = "每页条数", in = ParameterIn.QUERY, example = "10"),
            @Parameter(name = "pageIndex", description = "分页数(从1开始)", in = ParameterIn.QUERY, example = "1")
    })
    @GetMapping(value = "/selectByPageForUpload")
    public ResponseMsg<Object> selectByPageForUpload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
 
            UserEntity ue = tokenService.getCurrentUser(req);
 
            int count = metaService.selectCountForUpload(name, ue.getId(), null);
            if (count == 0) {
                return success(0, null);
            }
 
            List<MetaEntity> list = metaService.selectByPageForUpload(name, ue.getId(), null, pageSize, pageSize * (pageIndex - 1));
 
            return success(count, list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @Operation(summary = "根据元数据ID查询")
    @Parameters({
            @Parameter(name = "id", description = "ID", in = ParameterIn.QUERY, example = "1")
    })
    @GetMapping(value = "/selectMetaById")
    public ResponseMsg<MetaEntity> selectMetaById(int id) {
        try {
            MetaEntity entity = metaService.selectById(id);
 
            return success(entity);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
}