管道基础大数据平台系统开发-【后端】-Server
1.5
13693261870
2023-01-05 e5f61db766b3eaa28506835e3581cbd2fdc8533d
src/main/java/com/lf/server/controller/show/DataLibController.java
@@ -10,10 +10,8 @@
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.data.DictEntity;
import com.lf.server.entity.data.DownloadEntity;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.data.MetaFileEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.*;
import com.lf.server.mapper.all.BasicMapper;
@@ -21,6 +19,7 @@
import com.lf.server.service.data.DownloadService;
import com.lf.server.service.data.MetaService;
import com.lf.server.service.show.DataLibService;
import com.lf.server.service.sys.DownlogService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -54,6 +53,9 @@
    DataLibService dataLibService;
    @Autowired
    DownlogService downlogService;
    @Autowired
    DownloadService downloadService;
    @Autowired
@@ -62,24 +64,25 @@
    @SysLog()
    @ApiOperation(value = "分页查询元数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "depid", value = "单位ID", dataType = "Integer", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "dirid", value = "目录ID", dataType = "Integer", paramType = "query", example = "10"),
            @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 = "/selectByPageForMeta")
    public ResponseMsg<List<MetaEntity>> selectByPageForMeta(Integer dirid, String name, Integer pageSize, Integer pageIndex) {
    public ResponseMsg<List<MetaEntity>> selectByPageForMeta(Integer depid, Integer dirid, String name, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            int count = metaService.selectCount(dirid, name);
            int count = metaService.selectCount(depid, dirid, name);
            if (count == 0) {
                return success(0, null);
            }
            List<MetaEntity> rs = metaService.selectByPage(dirid, name, pageSize, pageSize * (pageIndex - 1));
            List<MetaEntity> rs = metaService.selectByPage(depid, dirid, name, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
@@ -103,11 +106,11 @@
            }
            MetaEntity meta = metaService.selectById(id);
            if (null == meta || null == meta.getTab() || !meta.getTab().contains(StaticData.POINT)) {
            if (null == meta || null == meta.getBstab() || !meta.getBstab().contains(StaticData.POINT)) {
                return fail("找不到元数据信息", null);
            }
            String entity = meta.getTab().substring(meta.getTab().indexOf(".") + 1).replace("_", "").toLowerCase();
            String entity = meta.getBstab().substring(meta.getBstab().indexOf(".") + 1).replace("_", "").toLowerCase();
            BasicMapper baseMapper = ClassHelper.getBasicMapper(entity);
            if (null == baseMapper) {
                return null;
@@ -131,27 +134,6 @@
    }
    @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 = "reqEntity", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body")
@@ -166,14 +148,14 @@
            if (null == reqEntity.getIds() || reqEntity.getIds().isEmpty()) {
                return fail("请选择要下载的文件");
            }
            if (!downloadService.decryptPwd(reqEntity)) {
            if (!DownloadService.decryptPwd(reqEntity)) {
                return fail("密码解密失败", null);
            }
            if (!StringHelper.checkPwdValid(reqEntity.getPwd())) {
                return fail("密码不符合要求");
            }
            List<MetaFileEntity> list = metaService.selectMetaFiles(reqEntity.getIds());
            List<MetaEntity> list = metaService.selectMetaFiles(reqEntity.getIds());
            if (null == list || list.isEmpty()) {
                return fail("没有找到元数据");
            }
@@ -203,7 +185,7 @@
                pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name());
            }
            String password = downloadService.decryptPwd(pwd);
            String password = DownloadService.decryptPwd(pwd);
            if (null == password) {
                return fail("密码解密失败", null);
            }
@@ -242,7 +224,7 @@
                pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name());
            }
            String password = downloadService.decryptPwd(pwd);
            String password = DownloadService.decryptPwd(pwd);
            if (null == password) {
                WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "密码解密失败", res);
            }
@@ -257,49 +239,12 @@
            }
            UserEntity ue = tokenService.getCurrentUser(req);
            de.setDcount(de.getDcount() + 1);
            de.setDownloadUser(ue.getId());
            int rows = downloadService.update(de);
            downlogService.updateInfos(ue, de, req);
            String filePath = downloadService.getDownloadFilePath(de);
            WebHelper.download(filePath, de.getName(), res);
        } catch (Exception ex) {
            WebHelper.writeInfo(HttpStatus.ERROR, ex.getMessage(), res);
        }
    }
    @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.checkPwdValid(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);
        }
    }
}