| | |
| | | import com.baomidou.mybatisplus.core.metadata.OrderItem; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.lf.server.annotation.SysLog; |
| | | import com.lf.server.entity.all.BaseGeoEntity; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.ctrl.DownloadReqEntity; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @ApiImplicitParam(name = "wkt", value = "WKT(著名文本)", dataType = "String", paramType = "query", example = ""), |
| | | //@ApiImplicitParam(name = "srid", value = "空间引用标识符", dataType = "Integer", paramType = "query", example = "4326"), |
| | | @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1"), |
| | | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10") |
| | | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"), |
| | | @ApiImplicitParam(name = "hasGeom", value = "是/否包含空间信息", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectByPage") |
| | | @PostMapping(value = "/selectByPage") |
| | | public ResponseMsg<List<Object>> selectByPage(String name, String depcode, String dirs, String filter, String wkt, Integer pageIndex, Integer pageSize) { |
| | | public ResponseMsg<List<Object>> selectByPage(String name, String depcode, String dirs, String filter, String wkt, Integer pageIndex, Integer pageSize, Integer hasGeom) { |
| | | try { |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(name); |
| | | if (baseMapper == null) { |
| | | if (null == baseMapper) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | |
| | | wrapper.apply(dirs); |
| | | } |
| | | |
| | | boolean hasWkt = null != hasGeom && hasGeom > 0 && baseMapper instanceof GeomBaseMapper; |
| | | if (hasWkt) { |
| | | wrapper.select("ST_AsText(geom) as geom, *"); |
| | | } |
| | | |
| | | Page<Object> page = new Page<>(pageIndex, pageSize); |
| | | page.addOrder(OrderItem.asc("gid")); |
| | | page.addOrder(OrderItem.desc("gid")); |
| | | IPage<Object> paged = baseMapper.selectPage(page, wrapper); |
| | | if (hasWkt && null != paged.getRecords()) { |
| | | copeWkt(paged.getRecords()); |
| | | } |
| | | |
| | | return success(paged.getTotal(), paged.getRecords()); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理WKT |
| | | */ |
| | | private void copeWkt(List<?> list) { |
| | | for (int i = 0, c = list.size(); i < c; i++) { |
| | | Object obj = list.get(i); |
| | | setWktEncrypt(obj); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置WKT加密 |
| | | */ |
| | | private void setWktEncrypt(Object obj) { |
| | | if (obj instanceof BaseGeoEntity) { |
| | | BaseGeoEntity entity = (BaseGeoEntity) obj; |
| | | if (StringHelper.isEmpty(entity.getGeom())) { |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | String wkt = AesHelper.encrypt(entity.getGeom()); |
| | | entity.setGeom(wkt); |
| | | } catch (Exception ex) { |
| | | entity.setGeom(null); |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | wrapper.select("ST_AsText(geom) as geom, *"); |
| | | baseQueryService.addBufferWrapper(baseMapper, wrapper, wkt, buffer); |
| | | wrapper.last("limit " + limit); |
| | | |
| | | List<?> list = baseMapper.selectList(wrapper); |
| | | |
| | | return success(list); |
| | | return success(null == list ? 0 : list.size(), list); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | |
| | | public ResponseMsg<String> selectWktById(String name, Integer gid) { |
| | | try { |
| | | GeomBaseMapper baseMapper = ClassHelper.getGeoBaseMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | if (null == baseMapper) { |
| | | return fail("查询对象不存在或不是空间表", null); |
| | | } |
| | | |
| | | String tab = BaseQueryService.getTabName(baseMapper); |
| | | if (StringHelper.isNull(tab)) { |
| | | return fail("查询对象不存在", null); |
| | | return fail("查询对象的表名不存在", null); |
| | | } |
| | | |
| | | String wkt = baseMapper.selectWktById(tab, gid); |
| | |
| | | } |
| | | |
| | | return success(wkt); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据GID查询") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgagnp"), |
| | | @ApiImplicitParam(name = "gid", value = "GID", dataType = "int", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectByGid") |
| | | public ResponseMsg<Object> selectByGid(String name, int gid) { |
| | | try { |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(name); |
| | | if (null == baseMapper) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | if (baseMapper instanceof GeomBaseMapper) { |
| | | wrapper.select("ST_AsText(geom) as geom, *"); |
| | | } |
| | | wrapper.eq("gid", gid); |
| | | |
| | | Object obj = baseMapper.selectOne(wrapper); |
| | | setWktEncrypt(obj); |
| | | |
| | | return success(null == obj ? 0 : 1, obj); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据实体名查询表名") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgagnp") |
| | | }) |
| | | @GetMapping(value = "/selectTabByEntity") |
| | | public ResponseMsg<Object> selectTabByEntity(String name) { |
| | | try { |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | String tab = BaseQueryService.getTabName(baseMapper); |
| | | |
| | | return success(tab); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | |
| | | if (StringHelper.isEmpty(field) || StringHelper.isSqlInjection(field)) { |
| | | return fail("查询字段不正确", null); |
| | | } |
| | | if (!StringHelper.isEmpty(value)) { |
| | | value = value.trim().replace("'", ""); |
| | | } |
| | | |
| | | value = StringHelper.getLikeStr2(value); |
| | | value = StringHelper.isEmpty(value) ? "%" : StringHelper.getLikeUpperStr(value); |
| | | List<String> rs = baseMapper.selectFieldFuzzy(tab, field, value); |
| | | |
| | | return success(rs); |
| | |
| | | } |
| | | dirs = DataLibService.copeCodes(dirs, "dirid"); |
| | | if (dirs != null) { |
| | | filters += String.format(" and (%s)", dirs); |
| | | filters += String.format(" and %s", dirs); |
| | | } |
| | | |
| | | String field = null == hasGeom || !hasGeom ? "gid" : "geom"; |
| | |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询元数据中溢出的单位ID") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "reqEntity", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/selectMetaOverflowDep") |
| | | public ResponseMsg<Object> selectMetaOverflowDep(@RequestBody DownloadReqEntity dr, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | if (null == dr || null == dr.getIds() || dr.getIds().isEmpty()) { |
| | | return fail("请选择要下载的文件ID"); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (StaticData.ADMIN.equals(ue.getUid())) { |
| | | return success(new ArrayList<String>()); |
| | | } |
| | | |
| | | List<String> list = downloadService.selectMetaOverflowDep(ue, dr); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询DB中溢出的单位ID") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "reqEntity", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/selectDbOverflowDep") |
| | | public ResponseMsg<Object> selectDbOverflowDep(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) { |
| | | public ResponseMsg<Object> selectDbOverflowDep(@RequestBody DownloadReqEntity dr, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | if (null == reqEntity || null == reqEntity.getEntities() || reqEntity.getEntities().isEmpty()) { |
| | | if (null == dr || null == dr.getEntities() || dr.getEntities().isEmpty()) { |
| | | return fail("请选择要下载的实体名"); |
| | | } |
| | | reqEntity.setWkt(AesHelper.decrypt(reqEntity.getWkt())); |
| | | if (StringHelper.isEmpty(reqEntity.getWkt())) { |
| | | return fail("请选择要下载的WKT范围"); |
| | | if (!StringHelper.isEmpty(dr.getWkt())) { |
| | | dr.setWkt(AesHelper.decrypt(dr.getWkt())); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | List<String> list = dataLibService.selectDbOverflowDep(ue, reqEntity.getEntities(), reqEntity.getWkt()); |
| | | if (StaticData.ADMIN.equals(ue.getUid())) { |
| | | return success(new ArrayList<String>()); |
| | | } |
| | | |
| | | List<String> list = dataLibService.selectDbOverflowDep(ue, dr); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "请求DB数据下载") |
| | | @ApiOperation(value = "下载DB数据") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "dre", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body") |
| | | @ApiImplicitParam(name = "dr", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/downloadDbReq") |
| | | public ResponseMsg<Object> downloadDbReq(@RequestBody DownloadReqEntity dre, HttpServletRequest req, HttpServletResponse res) { |
| | | @PostMapping(value = "/downloadDbData") |
| | | public ResponseMsg<Object> downloadDbData(@RequestBody DownloadReqEntity dr, HttpServletRequest req) { |
| | | try { |
| | | if (null == dre || StringHelper.isEmpty(dre.getPwd())) { |
| | | return fail("密码不能为空"); |
| | | } |
| | | if (null == dre.getEntities() || dre.getEntities().isEmpty()) { |
| | | if (null == dr || null == dr.getEntities() || dr.getEntities().isEmpty()) { |
| | | return fail("请选择要下载的实体名"); |
| | | } |
| | | dre.setWkt(AesHelper.decrypt(dre.getWkt())); |
| | | if (StringHelper.isEmpty(dre.getWkt())) { |
| | | return fail("请选择要下载的WKT范围"); |
| | | if (StringHelper.isEmpty(dr.getPwd())) { |
| | | return fail("密码不能为空"); |
| | | } |
| | | if (!DownloadService.decryptPwd(dre)) { |
| | | if (!DownloadService.decryptPwd(dr)) { |
| | | return fail("密码解密失败", null); |
| | | } |
| | | if (StringHelper.isPwdInvalid(dre.getPwd())) { |
| | | if (StringHelper.isPwdInvalid(dr.getPwd())) { |
| | | return fail("密码不符合要求"); |
| | | } |
| | | if (!StringHelper.isEmpty(dr.getWkt())) { |
| | | dr.setWkt(AesHelper.decrypt(dr.getWkt())); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | String depcode = null == dre.getDepcodes() || dre.getDepcodes().isEmpty() ? null : dre.getDepcodes().get(0); |
| | | String guid = dataLibService.createZipFile(ue, dre.getEntities(), depcode, dre.getDirs(), dre.getWkt(), dre.getPwd()); |
| | | |
| | | return success(guid); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "请求实体数据下载") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "dre", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/downloadEntityReq") |
| | | public ResponseMsg<Object> downloadEntityReq(@RequestBody DownloadReqEntity dre, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | if (null == dre || StringHelper.isEmpty(dre.getPwd())) { |
| | | return fail("密码不能为空"); |
| | | } |
| | | if (null == dre.getEntities() || dre.getEntities().isEmpty()) { |
| | | return fail("请选择要下载的实体名"); |
| | | } |
| | | if (!DownloadService.decryptPwd(dre)) { |
| | | return fail("密码解密失败", null); |
| | | } |
| | | if (StringHelper.isPwdInvalid(dre.getPwd())) { |
| | | return fail("密码不符合要求"); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | String depcode = null == dre.getDepcodes() || dre.getDepcodes().isEmpty() ? null : dre.getDepcodes().get(0); |
| | | String guid = dataLibService.zipDbData(ue, dre.getEntities().get(0), depcode, dre.getDirs(), dre.getFilter(), dre.getPwd()); |
| | | String guid = dataLibService.downloadDbReq(ue, dr); |
| | | |
| | | return success(guid); |
| | | } catch (Exception ex) { |