管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-03-27 7f65bcb71ae47abbf563f79ce83c7d580af89b3c
src/main/java/com/lf/server/controller/all/BaseQueryController.java
@@ -6,6 +6,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lf.server.annotation.SysLog;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.all.StaticData;
import com.lf.server.entity.ctrl.DownloadReqEntity;
import com.lf.server.entity.ctrl.IdNameEntity;
import com.lf.server.entity.ctrl.KeyValueEntity;
@@ -19,6 +20,7 @@
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.DictService;
import com.lf.server.service.data.DirService;
import com.lf.server.service.data.DownloadService;
import com.lf.server.service.data.MetaService;
@@ -65,6 +67,9 @@
    @Autowired
    BaseQueryService baseQueryService;
    @Autowired
    DictService dictService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
    @ApiImplicitParams({
@@ -89,7 +94,7 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -127,12 +132,51 @@
            }
            Page<Object> page = new Page<>(pageIndex, pageSize);
            page.addOrder(OrderItem.asc("gid"));
            page.addOrder(OrderItem.desc("gid"));
            IPage<Object> paged = baseMapper.selectPage(page, wrapper);
            return success(paged.getTotal(), paged.getRecords());
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
    @SysLog()
    @ApiOperation(value = "缓冲区查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "映射名称", dataType = "String", paramType = "query", example = "dlgagnp"),
            @ApiImplicitParam(name = "wkt", value = "WKT(著名文本)", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "buffer", value = "缓冲区大小", dataType = "Double", paramType = "query", example = "10"),
            @ApiImplicitParam(name = "limit", value = "限制条数", dataType = "Integer", paramType = "query", example = "20")
    })
    @GetMapping(value = "/selectByBuffer")
    public ResponseMsg<List<?>> selectByBuffer(String name, String wkt, Double buffer, Integer limit) {
        try {
            if (StringHelper.isEmpty(wkt)) {
                return fail("WKT不能为空", null);
            }
            if (null == limit || limit < 1 || limit > StaticData.ONE_HUNDRED) {
                limit = 20;
            }
            if (null == buffer || buffer < 0 || buffer > StaticData.ONE_HUNDRED_THOUSAND) {
                buffer = 10.0;
            }
            GeomBaseMapper baseMapper = ClassHelper.getGeoBaseMapper(name);
            if (baseMapper == null) {
                return fail("查询对象不存在", null);
            }
            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(null == list ? 0 : list.size(), list);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
@@ -163,7 +207,7 @@
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -193,7 +237,54 @@
            return success(wkt);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            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 {
            GeomBaseMapper baseMapper = ClassHelper.getGeoBaseMapper(name);
            if (baseMapper == null) {
                return fail("查询对象不存在", null);
            }
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.select("ST_AsText(geom) as geom, *");
            wrapper.eq("gid", gid);
            Object obj = baseMapper.selectOne(wrapper);
            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);
        }
    }
@@ -219,16 +310,13 @@
            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);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -244,7 +332,7 @@
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -260,20 +348,24 @@
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询所有表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = "点"),
            @ApiImplicitParam(name = "hasGeom", value = "含有Geom字段", dataType = "Boolean", paramType = "query", example = "false")
    })
    @GetMapping(value = "/selectTabs")
    public ResponseMsg<List<TabEntity>> selectTabs() {
    public ResponseMsg<List<TabEntity>> selectTabs(String name, Boolean hasGeom) {
        try {
            List<TabEntity> list = baseQueryService.selectTabs();
            List<TabEntity> list = dictService.selectDictTab(name, null == hasGeom || !hasGeom ? "gid" : "geom");
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -284,10 +376,11 @@
            @ApiImplicitParam(name = "depcode", value = "单位编码", dataType = "String", paramType = "query", example = "00"),
            @ApiImplicitParam(name = "dirs", value = "目录编码", dataType = "String", paramType = "query", example = "00,01"),
            @ApiImplicitParam(name = "tab", value = "表名", dataType = "String", paramType = "query", example = "dlg_"),
            @ApiImplicitParam(name = "hasGeom", value = "含有Geom字段", dataType = "Boolean", paramType = "query", example = "false"),
            @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 depcode, String dirs, String tab, Integer pageSize, Integer pageIndex) {
    public ResponseMsg<Object> selectTabsByPage(String depcode, String dirs, String tab, Boolean hasGeom, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
@@ -305,16 +398,17 @@
                filters += String.format(" and (%s)", dirs);
            }
            int count = baseQueryService.selectTabsForCount(tab);
            String field = null == hasGeom || !hasGeom ? "gid" : "geom";
            int count = baseQueryService.selectTabsForCount(tab, field);
            if (count == 0) {
                return success(0, null);
            }
            List<TabEntity> rs = baseQueryService.selectTabsByPage(tab, filters, pageSize, pageSize * (pageIndex - 1));
            List<TabEntity> rs = baseQueryService.selectTabsByPage(tab, field, filters, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -341,7 +435,7 @@
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -362,7 +456,7 @@
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -389,7 +483,7 @@
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -410,7 +504,7 @@
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -430,7 +524,7 @@
            return success(rows);
        } catch (Exception ex) {
            return fail(ex.getMessage(), 0);
            return fail(ex, 0);
        }
    }
@@ -441,22 +535,21 @@
    })
    @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());
            List<String> list = dataLibService.selectDbOverflowDep(ue, dr);
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -476,43 +569,76 @@
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
    @SysLog()
    @ApiOperation(value = "请求DB数据下载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dre", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body")
            @ApiImplicitParam(name = "dr", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/downloadDbData")
    public ResponseMsg<Object> downloadDbData(@RequestBody DownloadReqEntity dr, HttpServletRequest req) {
        try {
            if (null == dr || null == dr.getEntities() || dr.getEntities().isEmpty()) {
                return fail("请选择要下载的实体名");
            }
            if (StringHelper.isEmpty(dr.getPwd())) {
                return fail("密码不能为空");
            }
            if (!DownloadService.decryptPwd(dr)) {
                return fail("密码解密失败", null);
            }
            if (StringHelper.isPwdInvalid(dr.getPwd())) {
                return fail("密码不符合要求");
            }
            if (!StringHelper.isEmpty(dr.getWkt())) {
                dr.setWkt(AesHelper.decrypt(dr.getWkt()));
            }
            UserEntity ue = tokenService.getCurrentUser(req);
            String guid = dataLibService.downloadDbReq(ue, dr);
            return success(guid);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
    @SysLog()
    @ApiOperation(value = "请求DB数据下载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dr", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/downloadDbReq")
    public ResponseMsg<Object> downloadDbReq(@RequestBody DownloadReqEntity dre, HttpServletRequest req, HttpServletResponse res) {
    public ResponseMsg<Object> downloadDbReq(@RequestBody DownloadReqEntity dr, HttpServletRequest req, HttpServletResponse res) {
        try {
            if (null == dre || StringHelper.isEmpty(dre.getPwd())) {
            if (null == dr || StringHelper.isEmpty(dr.getPwd())) {
                return fail("密码不能为空");
            }
            if (null == dre.getEntities() || dre.getEntities().isEmpty()) {
            if (null == dr.getEntities() || dr.getEntities().isEmpty()) {
                return fail("请选择要下载的实体名");
            }
            dre.setWkt(AesHelper.decrypt(dre.getWkt()));
            if (StringHelper.isEmpty(dre.getWkt())) {
            dr.setWkt(AesHelper.decrypt(dr.getWkt()));
            if (StringHelper.isEmpty(dr.getWkt())) {
                return fail("请选择要下载的WKT范围");
            }
            if (!DownloadService.decryptPwd(dre)) {
            if (!DownloadService.decryptPwd(dr)) {
                return fail("密码解密失败", null);
            }
            if (StringHelper.isPwdInvalid(dre.getPwd())) {
            if (StringHelper.isPwdInvalid(dr.getPwd())) {
                return fail("密码不符合要求");
            }
            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());
            String guid = dataLibService.downloadDbReq4Wkt(ue, dr);
            return success(guid);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -523,29 +649,38 @@
    })
    @ResponseBody
    @PostMapping(value = "/downloadEntityReq")
    public ResponseMsg<Object> downloadEntityReq(@RequestBody DownloadReqEntity dre, HttpServletRequest req, HttpServletResponse res) {
    public ResponseMsg<Object> downloadEntityReq(@RequestBody DownloadReqEntity dr, HttpServletRequest req, HttpServletResponse res) {
        try {
            if (null == dre || StringHelper.isEmpty(dre.getPwd())) {
            if (null == dr || StringHelper.isEmpty(dr.getPwd())) {
                return fail("密码不能为空");
            }
            if (null == dre.getEntities() || dre.getEntities().isEmpty()) {
            if (null == dr.getEntities() || dr.getEntities().isEmpty()) {
                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("密码不符合要求");
            }
            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.downloadDbReq4Prop(ue, dr);
            return success(guid);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
    @SysLog()
    @ApiOperation(value = "查看文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "guid", value = "附件Guid", dataType = "String", paramType = "body")
    })
    @GetMapping(value = "/downloadForView")
    public void downloadForView(String guid, HttpServletResponse res) {
        metaService.downloadForView(guid, true, res);
    }
    @SysLog()
@@ -575,33 +710,23 @@
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询基础地理类别")
    @GetMapping(value = "/selectBaseType")
    public ResponseMsg<Object> selectBaseType() {
    @ApiOperation(value = "查询目录类别")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = "D")
    })
    @GetMapping(value = "/selectDirTypes")
    public ResponseMsg<Object> selectDirTypes(String name) {
        try {
            List<KeyValueEntity> list = baseQueryService.selectBaseType();
            List<KeyValueEntity> list = baseQueryService.selectDirTypes(name);
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询业务类别")
    @GetMapping(value = "/selectBusinessType")
    public ResponseMsg<Object> selectBusinessType() {
        try {
            List<KeyValueEntity> list = baseQueryService.selectBusinessType();
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -617,7 +742,23 @@
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
    @SysLog()
    @ApiOperation(value = "根据元数据ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "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);
        }
    }
}