| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.metadata.OrderItem; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.lf.server.aspect.SysLog; |
| | | import com.lf.server.annotation.SysLog; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.ctrl.DownloadReqEntity; |
| | | import com.lf.server.entity.ctrl.IdNameEntity; |
| | | import com.lf.server.entity.ctrl.TabEntity; |
| | | import com.lf.server.entity.data.DictEntity; |
| | | import com.lf.server.entity.data.DomainEntity; |
| | | import com.lf.server.entity.data.DownloadEntity; |
| | | import com.lf.server.entity.sys.AttachEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.AesHelper; |
| | | import com.lf.server.helper.ClassHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.mapper.all.BasicMapper; |
| | | import com.lf.server.mapper.all.GeomBaseMapper; |
| | | import com.lf.server.service.all.BaseQueryService; |
| | | import com.lf.server.service.data.DownloadService; |
| | | import com.lf.server.service.show.DataLibService; |
| | | import com.lf.server.service.sys.AttachService; |
| | | import com.lf.server.service.sys.TokenService; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | */ |
| | | public class BaseQueryController extends BaseController { |
| | | @Autowired |
| | | AttachService attachService; |
| | | |
| | | @Autowired |
| | | TokenService tokenService; |
| | | |
| | | @Autowired |
| | | DataLibService dataLibService; |
| | | |
| | | @Autowired |
| | | DownloadService downloadService; |
| | | |
| | | @Autowired |
| | | BaseQueryService baseQueryService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询记录数") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgAgnp"), |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgagnp"), |
| | | @ApiImplicitParam(name = "filter", value = "过滤条件", dataType = "String", paramType = "query", example = "gid >= 50 and name like '县' and objectid < 5000.0"), |
| | | @ApiImplicitParam(name = "wkt", value = "WKT(著名文本)", dataType = "String", paramType = "query", example = "gAPpDbZ53XfoQfvT8dj/uhBWX5os8kBJQ1LrNvH3VX7byFQdUJMPiEr8Fkj0q2i1pw+L8KFrvR0MLXq2xaO21nlQQXmEPofJxpDQZwEWUIFZsToXo1kLRD3t6WQezxWB8YTzXHM20Ba73x/ZuuezVhOFOq1U8HKf1dXQdv7gBzEB6fWMmFDc3FuH8GDDHv3LfT86Gio9VgMO6ohlrUdf3ZKtTHeLSuzGF4t0RZuX97YBNo25IIzpeTfRTXBxfdxA"), |
| | | @ApiImplicitParam(name = "srid", value = "空间引用标识符", dataType = "Integer", paramType = "query", example = "4326") |
| | | @ApiImplicitParam(name = "wkt", value = "WKT(著名文本)", dataType = "String", paramType = "query", example = "gAPpDbZ53XfoQfvT8dj/uhBWX5os8kBJQ1LrNvH3VX7byFQdUJMPiEr8Fkj0q2i1pw+L8KFrvR0MLXq2xaO21nlQQXmEPofJxpDQZwEWUIFZsToXo1kLRD3t6WQezxWB8YTzXHM20Ba73x/ZuuezVhOFOq1U8HKf1dXQdv7gBzEB6fWMmFDc3FuH8GDDHv3LfT86Gio9VgMO6ohlrUdf3ZKtTHeLSuzGF4t0RZuX97YBNo25IIzpeTfRTXBxfdxA") |
| | | }) |
| | | @GetMapping({"/selectCount"}) |
| | | public ResponseMsg<Long> selectCount(String name, String filter, String wkt, Integer srid) { |
| | | @GetMapping(value = "/selectCount") |
| | | @PostMapping(value = "/selectCount") |
| | | public ResponseMsg<Long> selectCount(String name, String filter, String wkt) { |
| | | try { |
| | | BasicMapper baseMapper = baseQueryService.getBasicMapper(name); |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | baseQueryService.addFilterWrapper(wrapper, filter); |
| | | baseQueryService.addGeomWrapper(baseMapper, wrapper, wkt, srid); |
| | | baseQueryService.addGeomWrapper(baseMapper, wrapper, wkt); |
| | | |
| | | long count = baseMapper.selectCount(wrapper); |
| | | |
| | |
| | | @SysLog() |
| | | @ApiOperation(value = "分页查询") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgAgnp"), |
| | | @ApiImplicitParam(name = "filter", value = "过滤条件", dataType = "String", paramType = "query", example = ""), |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgagnp"), |
| | | @ApiImplicitParam(name = "filter", value = "过滤条件", dataType = "String", paramType = "query", example = "gid >= 50 and name like '县' and objectid < 5000.0"), |
| | | @ApiImplicitParam(name = "wkt", value = "WKT(著名文本)", dataType = "String", paramType = "query", example = ""), |
| | | @ApiImplicitParam(name = "srid", value = "空间引用标识符", dataType = "Integer", paramType = "query", example = "4326"), |
| | | //@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") |
| | | }) |
| | | @GetMapping(value = "/selectByPage") |
| | | public ResponseMsg<List<Object>> selectByPage(String name, String filter, String wkt, Integer srid, Integer pageIndex, Integer pageSize) { |
| | | @PostMapping(value = "/selectByPage") |
| | | public ResponseMsg<List<Object>> selectByPage(String name, String filter, String wkt, Integer pageIndex, Integer pageSize) { |
| | | try { |
| | | BasicMapper baseMapper = baseQueryService.getBasicMapper(name); |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | baseQueryService.addFilterWrapper(wrapper, filter); |
| | | baseQueryService.addGeomWrapper(baseMapper, wrapper, wkt, srid); |
| | | baseQueryService.addGeomWrapper(baseMapper, wrapper, wkt); |
| | | |
| | | Page<Object> page = new Page<>(pageIndex, pageSize); |
| | | page.addOrder(OrderItem.asc("gid")); |
| | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据ID查询WKT") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgAgnp"), |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgagnp"), |
| | | @ApiImplicitParam(name = "gid", value = "GID", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | @GetMapping(value = "/selectWktById") |
| | | public ResponseMsg<String> selectWktById(String name, Integer gid) { |
| | | try { |
| | | GeomBaseMapper baseMapper = baseQueryService.getGeoBaseMapper(name); |
| | | GeomBaseMapper baseMapper = ClassHelper.getGeoBaseMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | String tab = baseQueryService.getTabName(baseMapper); |
| | | String tab = BaseQueryService.getTabName(baseMapper); |
| | | if (StringHelper.isNull(tab)) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | |
| | | @SysLog() |
| | | @ApiOperation(value = "模糊搜索字段") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgAgnp"), |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgagnp"), |
| | | @ApiImplicitParam(name = "field", value = "字段", dataType = "String", paramType = "query", example = "name"), |
| | | @ApiImplicitParam(name = "value", value = "值", dataType = "String", paramType = "query", example = "'县'") |
| | | }) |
| | | @GetMapping(value = "/selectFieldFuzzy") |
| | | public ResponseMsg<List<String>> selectFieldFuzzy(String name, String field, String value) { |
| | | try { |
| | | BasicMapper baseMapper = baseQueryService.getBasicMapper(name); |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | String tab = baseQueryService.getTabName(baseMapper); |
| | | String tab = BaseQueryService.getTabName(baseMapper); |
| | | if (StringHelper.isNull(tab)) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | if (StringHelper.isEmpty(field) || StringHelper.isSqlInjection(field)) { |
| | | return fail("查询字段不正确", null); |
| | | } |
| | | if (!StringHelper.isEmpty(value)) { |
| | | value = value.trim().replace("'", ""); |
| | | } |
| | | |
| | | value = value == null ? StringHelper.getLikeStr("") : StringHelper.getLikeStr(value.replace("'", "")); |
| | | value = StringHelper.getLikeStr2(value); |
| | | List<String> rs = baseMapper.selectFieldFuzzy(tab, field, value); |
| | | |
| | | return success(rs); |
| | |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询所有表") |
| | | @GetMapping(value = "/selectTabs") |
| | | public ResponseMsg<List<TabEntity>> selectTabs() { |
| | | try { |
| | | List<TabEntity> list = baseQueryService.selectTabs(); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据表名分页查询表") |
| | | @GetMapping(value = "/selectTabsByPage") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "tab", value = "表名", dataType = "String", paramType = "query", example = "dlg_"), |
| | | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"), |
| | | @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | public ResponseMsg<List<TabEntity>> selectTabsByPage(String tab, Integer pageSize, Integer pageIndex) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("每页页数或分页数小于1", null); |
| | | } |
| | | |
| | | int count = baseQueryService.selectTabsForCount(tab); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | |
| | | List<TabEntity> rs = baseQueryService.selectTabsByPage(tab, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(count, rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询字段信息") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlg25wAanp") |
| | | }) |
| | | @GetMapping(value = "/selectFields") |
| | | public ResponseMsg<List<DictEntity>> selectFields(String name) { |
| | | try { |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | String tabName = BaseQueryService.getTabName(baseMapper); |
| | | if (tabName == null) { |
| | | return null; |
| | | } |
| | | |
| | | String[] strs = tabName.split("\\."); |
| | | List<DictEntity> list = baseQueryService.selectFields(strs[0], strs[1]); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询字段信息") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "ns", value = "名称空间", dataType = "String", paramType = "query", example = "bd"), |
| | | @ApiImplicitParam(name = "tab", value = "表名", dataType = "String", paramType = "query", example = "dlg25wAanp") |
| | | }) |
| | | @GetMapping(value = "/selectTabFields") |
| | | public ResponseMsg<List<DictEntity>> selectTabFields(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.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询值域信息") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlg25wAanp") |
| | | }) |
| | | @GetMapping(value = "/selectDomains") |
| | | public ResponseMsg<List<DomainEntity>> selectDomains(String name) { |
| | | try { |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(name); |
| | | if (baseMapper == null) { |
| | | return fail("查询对象不存在", null); |
| | | } |
| | | |
| | | String tabName = BaseQueryService.getTabName(baseMapper); |
| | | if (tabName == null) { |
| | | return null; |
| | | } |
| | | |
| | | String[] strs = tabName.split("\\."); |
| | | List<DomainEntity> list = baseQueryService.selectDomains(strs[0], strs[1]); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询文件") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "tabName", value = "表名", dataType = "String", paramType = "query", example = "lf.sys_style"), |
| | | @ApiImplicitParam(name = "eventid", value = "主键", dataType = "String", paramType = "query", example = "fa25979a5ef8b43ba82a0be35b3fb0d4") |
| | | }) |
| | | @GetMapping(value = "/selectFiles") |
| | | public ResponseMsg<List<AttachEntity>> selectFiles(String tabName, String eventid) { |
| | | try { |
| | | if (StringHelper.isEmpty(tabName) || StringHelper.isEmpty(eventid)) { |
| | | return fail("参数不能为空", null); |
| | | } |
| | | |
| | | List<AttachEntity> list = attachService.selectByTab(tabName, eventid); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "删除文件") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", example = "1,2") |
| | | }) |
| | | @GetMapping(value = "/deletes") |
| | | public ResponseMsg<Integer> deleteFiles(@RequestParam List<Integer> ids) { |
| | | try { |
| | | if (ids == null || ids.isEmpty()) { |
| | | return fail("id数组不能为空", -1); |
| | | } |
| | | |
| | | int rows = attachService.deletes(ids); |
| | | |
| | | return success(rows); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), 0); |
| | | } |
| | | } |
| | | |
| | | @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) { |
| | | try { |
| | | if (null == reqEntity || null == reqEntity.getEntities() || reqEntity.getEntities().isEmpty()) { |
| | | return fail("请选择要下载的实体名"); |
| | | } |
| | | reqEntity.setWkt(AesHelper.decrypt(reqEntity.getWkt())); |
| | | if (StringHelper.isEmpty(reqEntity.getWkt())) { |
| | | return fail("请选择要下载的WKT范围"); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | List<Integer> list = dataLibService.selectDbOverflowDep(ue, reqEntity.getEntities(), reqEntity.getWkt()); |
| | | |
| | | return success(list); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "请求DB数据下载") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "reqEntity", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body") |
| | | }) |
| | | @ResponseBody |
| | | @PostMapping(value = "/downloadDbReq") |
| | | public ResponseMsg<Object> downloadDbReq(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | if (null == reqEntity || StringHelper.isEmpty(reqEntity.getPwd())) { |
| | | return fail("密码不能为空"); |
| | | } |
| | | if (null == reqEntity.getEntities() || reqEntity.getEntities().isEmpty()) { |
| | | return fail("请选择要下载的实体名"); |
| | | } |
| | | reqEntity.setWkt(AesHelper.decrypt(reqEntity.getWkt())); |
| | | if (StringHelper.isEmpty(reqEntity.getWkt())) { |
| | | return fail("请选择要下载的WKT范围"); |
| | | } |
| | | if (!DownloadService.decryptPwd(reqEntity)) { |
| | | return fail("密码解密失败", null); |
| | | } |
| | | if (StringHelper.isPwdInvalid(reqEntity.getPwd())) { |
| | | return fail("密码不符合要求"); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | String guid = dataLibService.createZipFile(ue, reqEntity.getEntities(), reqEntity.getWkt(), reqEntity.getPwd()); |
| | | |
| | | return success(guid); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "分页查询下载文件") |
| | | @ApiImplicitParams({ |
| | | @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 = "/selectPageCountForDownload") |
| | | public ResponseMsg<List<DownloadEntity>> selectPageCountForDownload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) { |
| | | try { |
| | | if (pageSize < 1 || pageIndex < 1) { |
| | | return fail("每页页数或分页数小于1", null); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("用户未登录", null); |
| | | } |
| | | |
| | | int count = downloadService.selectCountForUser(ue.getCreateUser(), 4, name); |
| | | if (count == 0) { |
| | | return success(0, null); |
| | | } |
| | | List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getCreateUser(), 3, name, pageSize, pageSize * (pageIndex - 1)); |
| | | |
| | | return success(count, rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | } |