|
|
@@ -1,1569 +1,1569 @@
|
|
|
-package com.siwei.apply.service.cadastre.impl;
|
|
|
-
|
|
|
-import com.siwei.apply.domain.CadastreFile;
|
|
|
-import com.siwei.apply.domain.LayerAndDbData;
|
|
|
-import com.siwei.apply.domain.MdbAndDbData;
|
|
|
-import com.siwei.apply.domain.vo.*;
|
|
|
-import com.siwei.apply.mapper.CadastreFileMapper;
|
|
|
-import com.siwei.apply.mapper.FzssFxrwrzMapper;
|
|
|
-import com.siwei.apply.service.cadastre.CadastreManageService;
|
|
|
-
|
|
|
-import com.siwei.apply.utils.FileExtractUtil;
|
|
|
-import com.siwei.apply.utils.MdbUtil;
|
|
|
-import com.siwei.common.core.exception.ServiceException;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.collections4.MapUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.gdal.ogr.*;
|
|
|
-import org.gdal.osr.CoordinateTransformation;
|
|
|
-import org.gdal.osr.SpatialReference;
|
|
|
-import org.locationtech.jts.io.ParseException;
|
|
|
-import org.locationtech.jts.io.WKBReader;
|
|
|
-import org.locationtech.jts.io.WKTWriter;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Propagation;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.nio.file.Files;
|
|
|
-import java.nio.file.Path;
|
|
|
-import java.nio.file.Paths;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- * 地籍管理系统主业务逻辑
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
- static {
|
|
|
- ogr.RegisterAll();
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CadastreFileMapper cadastreFileMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private FzssFxrwrzHandleService fzssFxrwrzHandleService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private FzssFxrwrzMapper fzssFxrwrzMapper;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 解析文件内容,insert 到表中
|
|
|
- * <p>
|
|
|
- * <p>
|
|
|
- * 1.进行解析数据成为list<map></map>
|
|
|
- * 2.进行调用方法动态插入到当前表中
|
|
|
- * 3.需要修改upload 的表更新状态
|
|
|
- * 4.考虑增量入库还是全量入库。()
|
|
|
- * 5.校验逻辑复杂()
|
|
|
- *
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- @Override
|
|
|
- public String addBatchGdbData(String uploadId) {
|
|
|
- String result = "success";
|
|
|
- try {
|
|
|
- CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
- //这里判断是否校验通过
|
|
|
- if (!cadastreFile.getStatus().equalsIgnoreCase("3")) {
|
|
|
- log.info("校验未通过,不能入库");
|
|
|
- result = "校验未通过,不能入库";
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", result, "info");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- String gdbPath = cadastreFile.getUnzipPath();
|
|
|
- DataSource ds = ogr.Open(gdbPath + "/" + cadastreFile.getName(), 0); // 0 = 只读
|
|
|
- if (ds == null) {
|
|
|
- log.warn("无法打开 gdb");
|
|
|
- result = "无法打开gdb文件,不能入库";
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", result, "info");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "正在执行入库操作。。。", "info");
|
|
|
- //这里进行遍历每个图层
|
|
|
- for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
- Layer layer = ds.GetLayer(i);
|
|
|
- String layerName = layer.GetName();
|
|
|
-
|
|
|
- boolean haveGeom = false;
|
|
|
- //获取字段信息
|
|
|
- List<String> dbFieldNameList = cadastreFileMapper.selectTableCollum(layerName.toLowerCase(Locale.ROOT));
|
|
|
- if (dbFieldNameList.contains("geom")) {
|
|
|
- haveGeom = true;
|
|
|
- }
|
|
|
-
|
|
|
- List<Map<String, String>> dbFieldNameAndTypeList = cadastreFileMapper.selectTableCollumAndType(layerName.toLowerCase(Locale.ROOT));
|
|
|
- Map<String, String> dbFieldNameAndTypeMap = dbFieldNameAndTypeList.stream().collect(Collectors.toMap(
|
|
|
- s -> s.get("column_name"),
|
|
|
- s -> s.get("data_type"),
|
|
|
- (existing, replacement) -> existing // 如果有重复键,保留第一个值
|
|
|
- ));
|
|
|
- List<Map<String, Object>> theValueList = getValueList(layer, dbFieldNameAndTypeMap, haveGeom);
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "正在执行-" + layerName + "-入库", "info");
|
|
|
- //这里直接数据入库,区分增量或者全量
|
|
|
- Boolean addRes;
|
|
|
- if ("2".equalsIgnoreCase(cadastreFile.getReadStatus())) {
|
|
|
- //增量更新
|
|
|
- addRes = incrementDataStorage(layerName, theValueList);
|
|
|
- if (addRes.equals(true)) {
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "增量更新-" + layerName + "-成功", "info");
|
|
|
- }
|
|
|
- } else {
|
|
|
- addRes = fullDataStorage(layerName, theValueList);
|
|
|
- if (addRes.equals(true)) {
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "增量更新-" + layerName + "-成功", "info");
|
|
|
- }
|
|
|
- }
|
|
|
- log.error("当前图层{},入库结果 {}", layerName, addRes);
|
|
|
- }
|
|
|
- //成功则更新状态
|
|
|
- CadastreFile updateCadastreFile = new CadastreFile();
|
|
|
- updateCadastreFile.setId(cadastreFile.getId());
|
|
|
- updateCadastreFile.setStatus("1");//入库成功
|
|
|
- updateCadastreFile.setReadMessage("入库成功");//入库成功
|
|
|
- cadastreFileMapper.update(updateCadastreFile);
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前批次-" + cadastreFile.getId() + "-入库成功", "info");
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("矢量数据入库异常,uploadId: {}", uploadId, e);
|
|
|
- //更新状态
|
|
|
- CadastreFile updateCadastreFile = new CadastreFile();
|
|
|
- updateCadastreFile.setId(uploadId);
|
|
|
- updateCadastreFile.setStatus("2");//入库失败
|
|
|
- updateCadastreFile.setReadMessage("入库失败");//入库失败
|
|
|
- cadastreFileMapper.update(updateCadastreFile);
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前批次-" + uploadId + "-入库失败", "info");
|
|
|
- throw new ServiceException("矢量数据入库异常," + e.getMessage());
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- @Override
|
|
|
- public String addBatchMdbData(String uploadId) {
|
|
|
- String result = "success";
|
|
|
- try {
|
|
|
- CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
- //这里判断是否校验通过
|
|
|
- if (!cadastreFile.getStatus().equalsIgnoreCase("3")) {
|
|
|
- log.info("校验未通过,不能入库");
|
|
|
- result = "校验未通过,不能入库";
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", result, "info");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- String gdbPath = cadastreFile.getUnzipPath();
|
|
|
- List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + cadastreFile.getName(), "", "");
|
|
|
-
|
|
|
- if (allMdbTableList == null) {
|
|
|
- log.warn("无法打开 mdb");
|
|
|
- result = "无法打开mdb文件,不能入库";
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", result, "info");
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "正在执行入库操作。。。", "info");
|
|
|
- for (Map<String, Object> tableMap : allMdbTableList) {
|
|
|
- String talbleName = String.valueOf(tableMap.get("name"));
|
|
|
- //List<Map<String, Object>> theValueList = getValueList(layer, dbFieldNameAndTypeMap, haveGeom);
|
|
|
- Map<String, Object> allMdbTableFieldMap = MdbUtil.MdbTableContent(gdbPath + "/" + cadastreFile.getName(), talbleName, "", "", 1, 1000);
|
|
|
- List<Map<String, Object>> theValueList = (List<Map<String, Object>>) allMdbTableFieldMap.get("rows");
|
|
|
-
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "正在执行-" + talbleName + "-入库", "info");
|
|
|
- //这里直接数据入库,区分增量或者全量
|
|
|
- Boolean addRes;
|
|
|
- if ("2".equalsIgnoreCase(cadastreFile.getReadStatus())) {
|
|
|
- //增量更新
|
|
|
- addRes = incrementDataStorage(talbleName, theValueList);
|
|
|
- if (addRes.equals(true)) {
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "增量更新-" + talbleName + "-成功", "info");
|
|
|
- }
|
|
|
- } else {
|
|
|
- addRes = fullDataStorage(talbleName, theValueList);
|
|
|
- if (addRes.equals(true)) {
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "全量更新-" + talbleName + "-成功", "info");
|
|
|
- }
|
|
|
- }
|
|
|
- log.error("当前属性名{},入库结果 {}", talbleName, addRes);
|
|
|
- }
|
|
|
- //成功则更新状态
|
|
|
- CadastreFile updateCadastreFile = new CadastreFile();
|
|
|
- updateCadastreFile.setId(cadastreFile.getId());
|
|
|
- updateCadastreFile.setStatus("1");//入库成功
|
|
|
- updateCadastreFile.setReadMessage("入库成功");//入库成功
|
|
|
- cadastreFileMapper.update(updateCadastreFile);
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前批次-" + cadastreFile.getId() + "-入库成功", "info");
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("mdb表格数据入库异常,uploadId: {}", uploadId, e);
|
|
|
- //更新状态
|
|
|
- CadastreFile updateCadastreFile = new CadastreFile();
|
|
|
- updateCadastreFile.setId(uploadId);
|
|
|
- updateCadastreFile.setStatus("2");//入库失败
|
|
|
- updateCadastreFile.setReadMessage("入库失败");//入库失败
|
|
|
- cadastreFileMapper.update(updateCadastreFile);
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前批次-" + uploadId + "-入库失败", "info");
|
|
|
- throw new ServiceException("表格数据入库异常," + e.getMessage());
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取比较数据
|
|
|
- *
|
|
|
- * @param uploadId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public CompareResultVo getCompareData(String uploadId) {
|
|
|
- CompareResultVo compareResultVo = new CompareResultVo();
|
|
|
- compareResultVo.setUploadId(uploadId);
|
|
|
- compareResultVo.setResultStatus(true);
|
|
|
- try {
|
|
|
- List<CompareGemoVo> gemos = new ArrayList<>();
|
|
|
- CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
- String gdbPath = cadastreFile.getUnzipPath();
|
|
|
- DataSource ds = ogr.Open(gdbPath + "/" + cadastreFile.getName(), 0); // 0 = 只读
|
|
|
- if (ds == null) {
|
|
|
- log.warn("无法打开 gdb");
|
|
|
- return compareResultVo;
|
|
|
- }
|
|
|
- //这里进行遍历每个图层
|
|
|
- for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
- Layer layer = ds.GetLayer(i);
|
|
|
- String layerName = layer.GetName();
|
|
|
-
|
|
|
- CompareGemoVo compareGemoVo = new CompareGemoVo();
|
|
|
- compareGemoVo.setLayerName(layerName);
|
|
|
- List<String> layerGeom = getLayerGeom(layer);
|
|
|
- compareGemoVo.setGeomData(layerGeom);
|
|
|
- List<String> dbGeom = getDbGeom(layerName);
|
|
|
- compareGemoVo.setOldGeomData(dbGeom);
|
|
|
- //加入当前图层对比对象
|
|
|
- gemos.add(compareGemoVo);
|
|
|
- }
|
|
|
- compareResultVo.setGemos(gemos);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("获取对比矢量数据信息异常,uploadId: {}", uploadId, e);
|
|
|
- throw new ServiceException("获取对比矢量数据信息异常," + e.getMessage());
|
|
|
- }
|
|
|
- return compareResultVo;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 文件upload入库
|
|
|
- *
|
|
|
- * @param theFileName
|
|
|
- * @param theFilePath
|
|
|
- * @param fileType
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public CadastreFile saveUploadFile(String theFileName, String theFilePath, String fileType, String updateType) {
|
|
|
- try {
|
|
|
- if (theFilePath == null || theFilePath.trim().isEmpty()) {
|
|
|
- log.warn("处理文件失败:filePath不能为空");
|
|
|
- return null;
|
|
|
- }
|
|
|
- Path currentFilePath = Paths.get(theFilePath);
|
|
|
- if (!Files.exists(currentFilePath)) {
|
|
|
- log.warn("处理文件失败:文件不存在: {}", theFilePath);
|
|
|
- return null;
|
|
|
- }
|
|
|
- Long fileSize = Files.size(currentFilePath);
|
|
|
-
|
|
|
- // 判断是否为压缩文件
|
|
|
- if (FileExtractUtil.isCompressedFile(theFilePath)) {
|
|
|
- // 解压文件到同名文件夹并获取目录结构
|
|
|
- String extractRes = FileExtractUtil.extractToSameNameFolder(theFilePath);
|
|
|
- if (StringUtils.isBlank(extractRes)) {
|
|
|
- log.warn("解压文件失败:文件不存在: {}", theFilePath);
|
|
|
- throw new ServiceException("解压文件失败:文件不存在,");
|
|
|
- }
|
|
|
-
|
|
|
- //解压成功文件保存
|
|
|
- if (StringUtils.isNotBlank(extractRes)) {
|
|
|
- String unZipPath = extractRes;
|
|
|
- if ("1".equals(fileType)) { //gdb格式
|
|
|
- String innerExtractFileName = FileExtractUtil.getInnerFolderByDirName(unZipPath);
|
|
|
- // 如果解压后的文件夹名称不为空,则使用解压后的文件夹名称作为文件名
|
|
|
- if (StringUtils.isNotBlank(innerExtractFileName)) {
|
|
|
- theFileName = innerExtractFileName;
|
|
|
- } else {
|
|
|
- String suffix = ".gdb"; //需要后缀为.gdb才能被jar包识别为矢量数据进行读取
|
|
|
- //这里解压文件名称作为文件名
|
|
|
- String fileName = currentFilePath.getFileName().toString();
|
|
|
- theFileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
|
|
- theFileName += suffix;
|
|
|
-
|
|
|
- //如果当前压缩文件为gdb文件,则解压后的文件夹名称需要修改为.gdb结尾
|
|
|
- FileExtractUtil.modifyDirName(unZipPath, unZipPath + suffix);
|
|
|
- unZipPath += suffix;
|
|
|
- unZipPath = unZipPath.replace(theFileName, "");
|
|
|
- if (StringUtils.isNotBlank(unZipPath) && (unZipPath.endsWith("/") || unZipPath.endsWith("\\"))) {
|
|
|
- unZipPath = unZipPath.substring(0, unZipPath.length() - 1);
|
|
|
- }
|
|
|
- }
|
|
|
- if (StringUtils.isNotBlank(theFileName) && !theFileName.toLowerCase(Locale.ROOT).endsWith(".gdb")) {
|
|
|
- throw new ServiceException("文件不是gdb格式矢量数据,请检查重新上传");
|
|
|
- }
|
|
|
- } else if ("2".equals(fileType)) {//如果是mdb文件
|
|
|
- String innerExtractFileName = FileExtractUtil.getInnerFileByDirName(unZipPath);
|
|
|
- if (StringUtils.isBlank(innerExtractFileName)) {
|
|
|
- throw new ServiceException("可能入库失败或没有历史版本,无法回退");
|
|
|
- }
|
|
|
- theFileName = innerExtractFileName;
|
|
|
- if (StringUtils.isNotBlank(theFileName) && !theFileName.toLowerCase(Locale.ROOT).endsWith(".mdb")) {
|
|
|
- throw new ServiceException("文件不是mdb格式表格数据,请检查重新上传");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- CadastreFile cadastreFile = new CadastreFile();
|
|
|
- cadastreFile.generateId();//生成id
|
|
|
- cadastreFile.setName(theFileName);
|
|
|
- cadastreFile.setFilePath(theFilePath);
|
|
|
- cadastreFile.setUnzipPath(unZipPath);
|
|
|
- cadastreFile.setFileType("1");//矢量/表格
|
|
|
- if (StringUtils.isNotBlank(fileType)) {
|
|
|
- cadastreFile.setFileType(fileType);
|
|
|
- }
|
|
|
-
|
|
|
- //0 为全量更新,1为增量更新
|
|
|
- if (StringUtils.isNotBlank(updateType)) {
|
|
|
- cadastreFile.setReadStatus(updateType);
|
|
|
- }
|
|
|
- cadastreFile.setFileSize(fileSize);
|
|
|
- cadastreFile.setStatus("0");
|
|
|
- cadastreFile.setUploadUser("admin");
|
|
|
- cadastreFile.setUploadTime(new Date());
|
|
|
- cadastreFile.setReadMessage("入库中。。。");
|
|
|
- cadastreFile.setUpdateTime(new Date());
|
|
|
- cadastreFileMapper.add(cadastreFile);
|
|
|
- return cadastreFile;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("处理文件并保存附件信息异常,filePath: {}", theFilePath, e);
|
|
|
- throw new ServiceException("处理文件并保存附件信息异常," + e.getMessage());
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * //1.文件进行解压
|
|
|
- * //1.先获取相关信息,进行入库
|
|
|
- * //2.日志记录写入
|
|
|
- * //3.读取文件进行录入
|
|
|
- * //4.质量进行检查
|
|
|
- * //日志记录
|
|
|
- * //fzssFxrwrzHandleService.insertFxrwrz();
|
|
|
- *
|
|
|
- * @param theFileName
|
|
|
- * @param theFilePath
|
|
|
- * @param fileType
|
|
|
- * @param updateType
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public CheckInfoResultVo checkFileData(String theFileName, String theFilePath, String fileType, String updateType) {
|
|
|
- CheckInfoResultVo checkInfoResult = new CheckInfoResultVo();
|
|
|
- checkInfoResult.setResultStatus(true);
|
|
|
- List<CheckInfoVo> checkInfoSuccessList = new ArrayList<>();
|
|
|
- List<CheckInfoVo> checkInfoFailList = new ArrayList<>();
|
|
|
-
|
|
|
- CadastreFile uploadFile = this.saveUploadFile(theFileName, theFilePath, fileType, updateType);
|
|
|
-
|
|
|
- if (Objects.nonNull(uploadFile)) {
|
|
|
- //入库成功
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadFile.getId(), "地籍库管理", "上传文件成功", "info");
|
|
|
- checkInfoResult.setUploadId(uploadFile.getId());
|
|
|
- String gdbPath = uploadFile.getUnzipPath();
|
|
|
- theFileName = uploadFile.getName();//这里需要使用解压处理后的文件名称进行读取
|
|
|
- //获取库中表名
|
|
|
- List<String> allTableList = cadastreFileMapper.selectAllTable();
|
|
|
-
|
|
|
- //这里区分文件类型,矢量还是表格的读取方式不一样
|
|
|
- if (uploadFile.getFileType().equals("1")) { //矢量数据读取方式
|
|
|
- DataSource ds = ogr.Open(gdbPath + "/" + theFileName, 0); // 0 = 只读
|
|
|
- if (ds == null) {
|
|
|
- log.warn("无法打开 gdb");
|
|
|
- return checkInfoResult;
|
|
|
- }
|
|
|
- log.info("图层数量: {}", ds.GetLayerCount());
|
|
|
- //这里进行遍历每个图层
|
|
|
- for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
- Layer layer = ds.GetLayer(i);
|
|
|
- //todo 测试代码
|
|
|
- //这里做质量检查
|
|
|
- CheckInfoVo checkRes = checkLayerInfo(layer, allTableList, uploadFile.getId());
|
|
|
- if (checkRes.getCheckStatus().equals(false)) { //检查出错
|
|
|
- checkInfoFailList.add(checkRes);
|
|
|
- checkInfoResult.setResultStatus(false);
|
|
|
- } else if (checkRes.getCheckStatus().equals(true)) {
|
|
|
- //成功则更新文件上传状态
|
|
|
- CadastreFile cadastreFile = new CadastreFile();
|
|
|
- cadastreFile.setId(uploadFile.getId());
|
|
|
- cadastreFile.setStatus("3");//校验通过
|
|
|
- cadastreFileMapper.update(cadastreFile);
|
|
|
- checkInfoSuccessList.add(checkRes);
|
|
|
- }
|
|
|
- }
|
|
|
- ds.delete();
|
|
|
- } else if (uploadFile.getFileType().equals("2")) {//处理表格类型
|
|
|
- try {
|
|
|
- List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + theFileName, "", "");
|
|
|
- if (CollectionUtils.isNotEmpty(allTableList)) {
|
|
|
- for (Map<String, Object> tableMap : allMdbTableList) {
|
|
|
- String talbleName = String.valueOf(tableMap.get("name"));
|
|
|
- Map<String, Object> allMdbTableFieldMap = MdbUtil.MdbTableContent(gdbPath + "/" + theFileName, talbleName, "", "", 1, 1000);
|
|
|
- //这里做质量检查
|
|
|
- CheckInfoVo checkRes = checkMdbInfo(talbleName, allTableList, allMdbTableFieldMap, uploadFile.getId());
|
|
|
- if (checkRes.getCheckStatus().equals(false)) { //检查出错
|
|
|
- checkInfoFailList.add(checkRes);
|
|
|
- checkInfoResult.setResultStatus(false);
|
|
|
- } else if (checkRes.getCheckStatus().equals(true)) {
|
|
|
- //成功则更新文件上传状态
|
|
|
- CadastreFile cadastreFile = new CadastreFile();
|
|
|
- cadastreFile.setId(uploadFile.getId());
|
|
|
- cadastreFile.setStatus("3");//校验通过
|
|
|
- cadastreFileMapper.update(cadastreFile);
|
|
|
- checkInfoSuccessList.add(checkRes);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("表格数据校验异常,uploadId: {}", uploadFile.getId(), e);
|
|
|
- throw new ServiceException("表格数据校验异常,uploadId:" + uploadFile.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- checkInfoResult.setCheckFailList(checkInfoFailList);
|
|
|
- checkInfoResult.setCheckSuccessList(checkInfoSuccessList);
|
|
|
- }
|
|
|
- return checkInfoResult;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 对每个图层进行数据格式校验
|
|
|
- *
|
|
|
- * @param layer
|
|
|
- * @param allTableList
|
|
|
- * @return
|
|
|
- */
|
|
|
- private CheckInfoVo checkLayerInfo(Layer layer, List<String> allTableList, String uploadId) {
|
|
|
- //总返回对象
|
|
|
- CheckInfoVo checkInfoVo = new CheckInfoVo();
|
|
|
- checkInfoVo.setCheckStatus(true);//初始化检查通过
|
|
|
-
|
|
|
- List<String> checkInfoList = new ArrayList<>();
|
|
|
- String name = layer.GetName();
|
|
|
- checkInfoVo.setUploadFileTableName(name);
|
|
|
-
|
|
|
- //检查表名对应
|
|
|
- if (!allTableList.contains(name.toLowerCase(Locale.ROOT))) {
|
|
|
- checkInfoList.add(name + ":图层名称不在地籍库范围内!");
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", name + ":图层名称不在地籍库范围内!", "info");
|
|
|
- checkInfoVo.setCheckStatus(false);
|
|
|
- }
|
|
|
-
|
|
|
- //检查坐标系
|
|
|
- if (checkCoordinateSystem(layer).equals(false)) {
|
|
|
- checkInfoList.add(name + ":坐标系不正确,确认是否CGCS2000!");
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", name + ":坐标系不正确,确认是否CGCS2000!", "info");
|
|
|
- checkInfoVo.setCheckStatus(false);
|
|
|
- }
|
|
|
-
|
|
|
- boolean haveGeom = false;
|
|
|
- //获取字段信息
|
|
|
- List<String> dbFieldNameList = cadastreFileMapper.selectTableCollum(name.toLowerCase(Locale.ROOT));
|
|
|
- if (dbFieldNameList.contains("geom")) {
|
|
|
- haveGeom = true;
|
|
|
- }
|
|
|
- //这里移除校验字段(非属mdb中的字段)
|
|
|
- dbFieldNameList.remove("valid_flag");
|
|
|
-
|
|
|
- List<String> layerFieldNameList = this.getFieldName(layer, haveGeom);
|
|
|
- // 判断是否包含相同的元素(不考虑顺序)
|
|
|
- boolean areCollectionsEqual = CollectionUtils.containsAll(layerFieldNameList,dbFieldNameList);
|
|
|
- if (!areCollectionsEqual) {
|
|
|
- checkInfoList.add(name + ":字段数据不一致!-" + dbFieldNameList);
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", name + ":字段数据不一致!-" + dbFieldNameList, "info");
|
|
|
- checkInfoVo.setCheckStatus(false);
|
|
|
- }
|
|
|
-
|
|
|
- //检查字段数据是否为空
|
|
|
- //todo 这里根据表名获取相关校验字段信息
|
|
|
- List<String> checkFieldList = new ArrayList<>();
|
|
|
- //checkFieldList.add("111");
|
|
|
- //checkFieldList.add("bz");
|
|
|
- //仅获取图层属性
|
|
|
- List<Map<String, Object>> theValueList = getValueList(layer, new LinkedHashMap<>(), false);
|
|
|
- for (Map<String, Object> theMap : theValueList) {
|
|
|
- for (String fieldName : checkFieldList) {
|
|
|
- if (Objects.isNull(theMap.get(fieldName))) {
|
|
|
- checkInfoList.add(name + "--" + fieldName + "字段不能为空!");
|
|
|
- checkInfoVo.setCheckStatus(false);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- checkInfoVo.setCheckInfoList(checkInfoList);
|
|
|
- //todo 这里需要放入到缓存中,并且可以下载为txt内容
|
|
|
- if (checkInfoVo.getCheckStatus().equals(true)) {
|
|
|
- checkInfoList.add("当前矢量数据:" + name + "---" + "数据格式为gdb");
|
|
|
- checkInfoList.add("当前矢量数据:" + name + "---" + "坐标系是CGCS2000");
|
|
|
- checkInfoList.add("当前矢量数据:" + name + "---" + "检查校验通过!");
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前矢量数据:" + name + "---" + "数据格式为gdb", "info");
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前矢量数据:" + name + "---" + "坐标系是CGCS2000", "info");
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前矢量数据:" + name + "---" + "检查校验通过!", "info");
|
|
|
- }
|
|
|
- return checkInfoVo;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 对表格属性数据进行数据格式校验
|
|
|
- *
|
|
|
- * @param mdbTableName
|
|
|
- * @param allTableList
|
|
|
- * @return
|
|
|
- */
|
|
|
- private CheckInfoVo checkMdbInfo(String mdbTableName, List<String> allTableList, Map<String, Object> mdbTableFieldMap, String uploadId) {
|
|
|
- //总返回对象
|
|
|
- CheckInfoVo checkInfoVo = new CheckInfoVo();
|
|
|
- checkInfoVo.setCheckStatus(true);//初始化检查通过
|
|
|
- List<String> checkInfoList = new ArrayList<>();
|
|
|
- checkInfoVo.setUploadFileTableName(mdbTableName);
|
|
|
-
|
|
|
- //字段名称
|
|
|
- List<String> mdbTableFieldNameList = (List<String>) mdbTableFieldMap.get("column");
|
|
|
- List<String> lowerCaseMdbTableFieldNameList = mdbTableFieldNameList.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
-
|
|
|
- //所有条数
|
|
|
- List<Map<String, String>> dataList = (List<Map<String, String>>) mdbTableFieldMap.get("rows");
|
|
|
-
|
|
|
- //检查表名对应
|
|
|
- if (!allTableList.contains(mdbTableName.toLowerCase(Locale.ROOT))) {
|
|
|
- checkInfoList.add(mdbTableName + ":图层名称不在地籍库范围内!");
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", mdbTableName + ":图层名称不在地籍库范围内!", "info");
|
|
|
- checkInfoVo.setCheckStatus(false);
|
|
|
- }
|
|
|
-
|
|
|
- //获取当前表数据库字段信息
|
|
|
- List<String> dbFieldNameList = cadastreFileMapper.selectTableCollum(mdbTableName.toLowerCase(Locale.ROOT));
|
|
|
- //这里移除校验字段(非属mdb中的字段)
|
|
|
- dbFieldNameList.remove("valid_flag");
|
|
|
- // 判断是否包含相同的元素(不考虑顺序)
|
|
|
- boolean areCollectionsEqual = CollectionUtils.containsAll(lowerCaseMdbTableFieldNameList,dbFieldNameList);
|
|
|
- if (!areCollectionsEqual) {
|
|
|
- checkInfoList.add(mdbTableName + ":字段数据不一致!-" + dbFieldNameList);
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", mdbTableName + ":字段数据不一致!-" + dbFieldNameList, "info");
|
|
|
- checkInfoVo.setCheckStatus(false);
|
|
|
- }
|
|
|
-
|
|
|
- //检查字段数据是否为空
|
|
|
- //todo 这里根据表名获取相关校验字段信息
|
|
|
- List<String> checkFieldList = new ArrayList<>();
|
|
|
- //checkFieldList.add("111");
|
|
|
- //checkFieldList.add("bz");
|
|
|
-
|
|
|
- for (Map<String, String> theMap : dataList) {
|
|
|
- for (String fieldName : checkFieldList) {
|
|
|
- if (Objects.isNull(theMap.get(fieldName))) {
|
|
|
- checkInfoList.add(mdbTableName + "--" + fieldName + "字段不能为空!");
|
|
|
- checkInfoVo.setCheckStatus(false);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- checkInfoVo.setCheckInfoList(checkInfoList);
|
|
|
- if (checkInfoVo.getCheckStatus().equals(true)) {
|
|
|
- checkInfoList.add("当前表格数据:" + mdbTableName + "---" + "数据格式为mdb");
|
|
|
- checkInfoList.add("当前表格数据:" + mdbTableName + "---" + "检查校验通过!");
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前表格数据:" + mdbTableName + "---" + "数据格式为mdb", "info");
|
|
|
- fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前表格数据:" + mdbTableName + "---" + "检查校验通过!", "info");
|
|
|
- }
|
|
|
- return checkInfoVo;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取当前图层的所有属性字段名
|
|
|
- *
|
|
|
- * @param layer
|
|
|
- * @return
|
|
|
- */
|
|
|
- private List<String> getFieldName(Layer layer, Boolean haveGeom) {
|
|
|
- List<String> nameList = new ArrayList();
|
|
|
- FeatureDefn defn = layer.GetLayerDefn();
|
|
|
- System.out.println("字段数: " + defn.GetFieldCount());
|
|
|
- for (int i = 0; i < defn.GetFieldCount(); i++) {
|
|
|
- FieldDefn field = defn.GetFieldDefn(i);
|
|
|
- nameList.add(field.GetName().toLowerCase(Locale.ROOT));
|
|
|
- }
|
|
|
- if (haveGeom.equals(true)) {
|
|
|
- nameList.add("geom");
|
|
|
- }
|
|
|
- return nameList;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private static final String[] DATE_PATTERNS = {
|
|
|
- "yyyy-MM-dd HH:mm:ssX",
|
|
|
- "yyyy-MM-dd HH:mm:ss",
|
|
|
- "yyyy/MM/dd HH:mm:ssX",
|
|
|
- "yyyy/MM/dd HH:mm:ss",
|
|
|
- "yyyy-MM-dd",
|
|
|
- "yyyy/MM/dd"
|
|
|
- };
|
|
|
-
|
|
|
- private Object convertFieldValue(Feature feature, int fieldIndex, String fieldName, String fieldType) {
|
|
|
- if (feature.IsFieldNull(fieldIndex)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- String strValue = feature.GetFieldAsString(fieldIndex);
|
|
|
- if (StringUtils.isBlank(strValue)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- try {
|
|
|
- if (StringUtils.containsIgnoreCase(fieldType, "character") || StringUtils.containsIgnoreCase(fieldType, "text")) {
|
|
|
- return strValue;
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "integer") || StringUtils.containsIgnoreCase(fieldType, "smallint") || StringUtils.containsIgnoreCase(fieldType, "int2") || StringUtils.containsIgnoreCase(fieldType, "int4")) {
|
|
|
- return feature.GetFieldAsInteger(fieldIndex);
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "bigint") || StringUtils.containsIgnoreCase(fieldType, "int8")) {
|
|
|
- return feature.GetFieldAsInteger64(fieldIndex);
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "timestamp")) {
|
|
|
- return parseDate(strValue, fieldName);
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "date")) {
|
|
|
- return parseDate(strValue, fieldName);
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "numeric") || StringUtils.containsIgnoreCase(fieldType, "double") || StringUtils.containsIgnoreCase(fieldType, "real")) {
|
|
|
- return feature.GetFieldAsDouble(fieldIndex);
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "bytea") || StringUtils.containsIgnoreCase(fieldType, "blob") || StringUtils.containsIgnoreCase(fieldType, "binary")) {
|
|
|
- return null;
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "boolean")) {
|
|
|
- return feature.GetFieldAsInteger(fieldIndex) != 0;
|
|
|
- } else {
|
|
|
- return strValue;
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("字段{}类型转换异常,值:{},类型:{},置空处理", fieldName, strValue, fieldType, e);
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private java.sql.Date parseDate(String dateStr, String fieldName) {
|
|
|
- if (StringUtils.isBlank(dateStr)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- String cleaned = dateStr.trim();
|
|
|
- for (String pattern : DATE_PATTERNS) {
|
|
|
- try {
|
|
|
- java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(pattern);
|
|
|
- sdf.setLenient(false);
|
|
|
- java.util.Date parsed = sdf.parse(cleaned);
|
|
|
- return new java.sql.Date(parsed.getTime());
|
|
|
- } catch (Exception ignored) {
|
|
|
- }
|
|
|
- }
|
|
|
- try {
|
|
|
- String normalized = cleaned.replace("/", "-");
|
|
|
- if (normalized.contains(" ") || normalized.contains("T")) {
|
|
|
- normalized = normalized.substring(0, Math.min(normalized.indexOf(' ') > 0 ? normalized.indexOf(' ') : Integer.MAX_VALUE, normalized.indexOf('T') > 0 ? normalized.indexOf('T') : Integer.MAX_VALUE));
|
|
|
- }
|
|
|
- if (normalized.length() > 10) {
|
|
|
- normalized = normalized.substring(0, 10);
|
|
|
- }
|
|
|
- return java.sql.Date.valueOf(normalized);
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("日期字段{}解析失败,值:{},置空处理", fieldName, dateStr);
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取当前图层的所有字段名称和值
|
|
|
- *
|
|
|
- * @param layer
|
|
|
- * @return
|
|
|
- */
|
|
|
- private List<Map<String, Object>> getValueList(Layer layer, Map<String, String> fieldNameAndTypeMap, Boolean haveGeom) {
|
|
|
- List<Map<String, Object>> list = new ArrayList<>();
|
|
|
- Integer sourceSRID = 4326;
|
|
|
-
|
|
|
- // ========== 1. 获取源数据坐标系 EPSG:4527 ==========
|
|
|
- try {
|
|
|
- SpatialReference srcSR = layer.GetSpatialRef();
|
|
|
- if (srcSR != null) {
|
|
|
- srcSR.AutoIdentifyEPSG();
|
|
|
- String code = srcSR.GetAuthorityCode(null);
|
|
|
- if (code != null) {
|
|
|
- sourceSRID = Integer.parseInt(code);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("获取图层坐标系SRID失败,使用默认4326", e);
|
|
|
- }
|
|
|
-
|
|
|
- layer.ResetReading();
|
|
|
- Feature feature;
|
|
|
- while ((feature = layer.GetNextFeature()) != null) {
|
|
|
- Map<String, Object> map = new LinkedHashMap<>();
|
|
|
- for (int i = 0; i < feature.GetFieldCount(); i++) {
|
|
|
- String fieldName = feature.GetFieldDefnRef(i).GetName();
|
|
|
- if (fieldNameAndTypeMap.containsKey(fieldName.toLowerCase())) {
|
|
|
- String fieldType = fieldNameAndTypeMap.get(fieldName.toLowerCase());
|
|
|
-
|
|
|
-
|
|
|
-/* if ("dclxtzm".equalsIgnoreCase(fieldName)) {
|
|
|
- map.put(fieldName, "99");
|
|
|
- }
|
|
|
- else if ("fwjg".equalsIgnoreCase(fieldName)) {
|
|
|
- map.put(fieldName, null);
|
|
|
- }
|
|
|
- else if ("jzwgd".equalsIgnoreCase(fieldName)) {
|
|
|
- map.put(fieldName, 1);
|
|
|
- }
|
|
|
- else if ("ycjzmj".equalsIgnoreCase(fieldName)) {
|
|
|
- map.put(fieldName, 1);
|
|
|
- }
|
|
|
- else if ("zts".equalsIgnoreCase(fieldName)) {
|
|
|
- map.put(fieldName, 1);
|
|
|
- }
|
|
|
- else if ("zydmj".equalsIgnoreCase(fieldName)) {
|
|
|
- map.put(fieldName, null);
|
|
|
- }*/
|
|
|
-
|
|
|
- if ("ydyhfl".equalsIgnoreCase(fieldName)) {
|
|
|
- map.put(fieldName, null);
|
|
|
- }
|
|
|
- else if (StringUtils.containsIgnoreCase(fieldType, "character")) {
|
|
|
- map.put(fieldName, feature.GetFieldAsString(i));
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "integer") || StringUtils.containsIgnoreCase(fieldType, "smallint") || StringUtils.containsIgnoreCase(fieldType, "int2") || StringUtils.containsIgnoreCase(fieldType, "int4")) {
|
|
|
- map.put(fieldName, feature.GetFieldAsInteger(i));
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "bigint") || StringUtils.containsIgnoreCase(fieldType, "int8")) {
|
|
|
- map.put(fieldName, feature.GetFieldAsInteger64(i));
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "date")) {
|
|
|
- String dateStr = feature.GetFieldAsString(i);
|
|
|
- if (StringUtils.isNotBlank(dateStr)) {
|
|
|
- try {
|
|
|
- String normalized = dateStr.trim().replace("/", "-");
|
|
|
- if (normalized.length() > 10) {
|
|
|
- normalized = normalized.substring(0, 10);
|
|
|
- }
|
|
|
- map.put(fieldName, java.sql.Date.valueOf(normalized));
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("日期字段{}解析失败,值:{},置空处理", fieldName, dateStr);
|
|
|
- map.put(fieldName, null);
|
|
|
- }
|
|
|
- } else {
|
|
|
- map.put(fieldName, null);
|
|
|
- }
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "numeric") || StringUtils.containsIgnoreCase(fieldType, "double") || StringUtils.containsIgnoreCase(fieldType, "real")) {
|
|
|
- if (feature.IsFieldNull(i)) {
|
|
|
- map.put(fieldName, null);
|
|
|
- } else {
|
|
|
- map.put(fieldName, feature.GetFieldAsDouble(i));
|
|
|
- }
|
|
|
- } else if (StringUtils.containsIgnoreCase(fieldType, "bytea") || StringUtils.containsIgnoreCase(fieldType, "blob") || StringUtils.containsIgnoreCase(fieldType, "binary")) {
|
|
|
- map.put(fieldName, new byte[0]);
|
|
|
- }
|
|
|
- else {
|
|
|
- map.put(fieldName, feature.GetFieldAsString(i));
|
|
|
- }
|
|
|
- } else {
|
|
|
- //这里兼容图层可能存在多出的字段不处理
|
|
|
- //map.put(fieldName, feature.GetFieldAsString(i));
|
|
|
- log.warn("当前图层-{},多出字段-{}",layer.GetName(),fieldName);
|
|
|
- }
|
|
|
- }
|
|
|
- if (haveGeom.equals(true)) {
|
|
|
- String ewkt = null;
|
|
|
- Geometry geom = feature.GetGeometryRef();
|
|
|
- if (geom != null) {
|
|
|
- String wkt = geom.ExportToWkt();
|
|
|
- ewkt = "SRID=" + sourceSRID + ";" + wkt;
|
|
|
- ewkt = this.transforGeomTo4326(ewkt);
|
|
|
- }
|
|
|
- map.put("geom", ewkt);
|
|
|
- }
|
|
|
- list.add(map);
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 校验当前图层坐标系是否为:CGCS2000
|
|
|
- *
|
|
|
- * @param layer
|
|
|
- * @return
|
|
|
- */
|
|
|
- private Boolean checkCoordinateSystem(Layer layer) {
|
|
|
- boolean isCGCS2000 = false;
|
|
|
- SpatialReference sr = layer.GetSpatialRef();
|
|
|
- if (sr != null) {
|
|
|
- String wkt = sr.ExportToWkt();
|
|
|
- log.info("当前图层{},wkt为:{}", layer.GetName(), wkt);
|
|
|
- // 判断 WKT 是否包含 "CGCS2000"
|
|
|
- if (wkt.contains("CGCS2000")) {
|
|
|
- isCGCS2000 = true;
|
|
|
- }
|
|
|
- }
|
|
|
- return isCGCS2000;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 校验当前图层是否存在矢量数据
|
|
|
- *
|
|
|
- * @param layer
|
|
|
- * @return
|
|
|
- */
|
|
|
- private Boolean checkHaveGeom(Layer layer) {
|
|
|
- boolean haveGeom = false;
|
|
|
- // 循环处理每个要素
|
|
|
- for (int i = 0; i < layer.GetFeatureCount(0); i++) {
|
|
|
- Feature feature = layer.GetFeature(i);
|
|
|
- if (feature == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- Geometry geometry = feature.GetGeometryRef(); // 获取几何对象
|
|
|
- if (geometry != null) {
|
|
|
- // 将几何对象转换为 WKT 格式
|
|
|
- String wkt = geometry.ExportToWkt();
|
|
|
- if (StringUtils.isNotBlank(wkt)) {
|
|
|
- haveGeom = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return haveGeom;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取对比的矢量图层
|
|
|
- *
|
|
|
- * @param layer
|
|
|
- * @return
|
|
|
- */
|
|
|
- private List<String> getLayerGeom(Layer layer) {
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
- SpatialReference srcSrs = layer.GetSpatialRef();
|
|
|
- Integer srid = null;
|
|
|
- if (srcSrs != null) {
|
|
|
- String authCode = srcSrs.GetAuthorityCode(null);
|
|
|
- if (authCode != null) {
|
|
|
- srid = Integer.parseInt(authCode);
|
|
|
- }
|
|
|
- }
|
|
|
- if (srid == null) {
|
|
|
- srid = 4527;
|
|
|
- }
|
|
|
-
|
|
|
- layer.ResetReading();
|
|
|
- Feature feature;
|
|
|
- while ((feature = layer.GetNextFeature()) != null) {
|
|
|
- Geometry geom = feature.GetGeometryRef();
|
|
|
- if (geom == null) {
|
|
|
- list.add("");
|
|
|
- continue;
|
|
|
- }
|
|
|
- String wkt = geom.ExportToWkt();
|
|
|
- String ewkt = "SRID=" + srid + ";" + wkt;
|
|
|
- ewkt = this.transforGeomTo4326(ewkt);
|
|
|
- list.add(ewkt);
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取对比的矢量图层
|
|
|
- *
|
|
|
- * @param layer
|
|
|
- * @return
|
|
|
- */
|
|
|
- private List<String> getLayerGeom_del(Layer layer) {
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
- // 循环处理每个要素
|
|
|
- for (int i = 0; i < layer.GetFeatureCount(0); i++) {
|
|
|
- Feature feature = layer.GetFeature(i);
|
|
|
- if (feature == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- Geometry geometry = feature.GetGeometryRef(); // 获取几何对象
|
|
|
- if (geometry != null) {
|
|
|
- // 将几何对象转换为 WKT 格式
|
|
|
- String wkt = geometry.ExportToWkt();
|
|
|
- list.add(wkt);
|
|
|
- }
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param tableName
|
|
|
- * @return
|
|
|
- */
|
|
|
- private List<String> getDbGeom(String tableName) {
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
- String geomsStr = cadastreFileMapper.selectGeoms(tableName);
|
|
|
- if (StringUtils.isNotBlank(geomsStr)) {
|
|
|
- list = Arrays.asList(geomsStr.split("\\|"));
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 这里需要开启事务
|
|
|
- * 数据全量入库
|
|
|
- *
|
|
|
- * @param tableName
|
|
|
- * @param theValueList
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
- public Boolean fullDataStorage(String tableName, List<Map<String, Object>> theValueList) {
|
|
|
- boolean addRes = false;
|
|
|
- Integer shpDbSRID = 4326;
|
|
|
- if (!CollectionUtils.isEmpty(theValueList)) {
|
|
|
- //先删除数据
|
|
|
- cadastreFileMapper.deleteByValidFlag("1", tableName);
|
|
|
- //先把当前版本都修改为历史版本
|
|
|
- cadastreFileMapper.updateValidFlag("1", "0", tableName);
|
|
|
- for (Map<String, Object> map : theValueList) {
|
|
|
-// Collection<Object> values = map.values();
|
|
|
-// Collection<String> keys = map.keySet();
|
|
|
- map.put("valid_flag", 0);//有效数据标识
|
|
|
- cadastreFileMapper.insertTableData(tableName, map, shpDbSRID);
|
|
|
- }
|
|
|
- }
|
|
|
- return addRes;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断两个Map中的数据是否完全一致(排除geom字段的比较方式,或根据业务需求处理)
|
|
|
- */
|
|
|
- private boolean isSameData(Map<String, Object> map1, Map<String, Object> map2) {
|
|
|
- if (map1 == map2) return true;
|
|
|
- if (map1 == null || map2 == null) return false;
|
|
|
-
|
|
|
- // 比较两个map的交集字段(排除valid_flag)
|
|
|
- Set<String> keys1 = new HashSet<>(map1.keySet());
|
|
|
- Set<String> keys2 = new HashSet<>(map2.keySet());
|
|
|
- keys1.retainAll(keys2); // 取交集
|
|
|
- if (keys1.isEmpty()) return false;
|
|
|
-
|
|
|
- for (String field : keys1) {
|
|
|
- if ("valid_flag".equalsIgnoreCase(field)) {
|
|
|
- continue; // 忽略版本标识
|
|
|
- }
|
|
|
- Object val1 = map1.get(field);
|
|
|
- Object val2 = map2.get(field);
|
|
|
-
|
|
|
- if (val1 == null && val2 == null) continue;
|
|
|
- if (val1 == null || val2 == null) return false;
|
|
|
-
|
|
|
- // 特殊处理geom字段:以字符串比较,去掉空白
|
|
|
- if ("geom".equalsIgnoreCase(field)) {
|
|
|
- String s1 = String.valueOf(val1).trim();
|
|
|
- String s2 = String.valueOf(val2).trim();
|
|
|
- if (!s1.equals(s2)) {
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 数值类型比较
|
|
|
- if (val1 instanceof Number && val2 instanceof Number) {
|
|
|
- if (Double.compare(((Number) val1).doubleValue(), ((Number) val2).doubleValue()) != 0) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 尝试将字符串数字与数字类型做比较(例如数据库返回Integer/String混合)
|
|
|
- if (val1 instanceof Number && val2 instanceof String) {
|
|
|
- try {
|
|
|
- double d2 = Double.parseDouble(((String) val2).trim());
|
|
|
- if (Double.compare(((Number) val1).doubleValue(), d2) != 0) return false;
|
|
|
- else continue;
|
|
|
- } catch (Exception ignored) {
|
|
|
- // fallthrough to string compare
|
|
|
- }
|
|
|
- }
|
|
|
- if (val2 instanceof Number && val1 instanceof String) {
|
|
|
- try {
|
|
|
- double d1 = Double.parseDouble(((String) val1).trim());
|
|
|
- if (Double.compare(((Number) val2).doubleValue(), d1) != 0) return false;
|
|
|
- else continue;
|
|
|
- } catch (Exception ignored) {
|
|
|
- // fallthrough to string compare
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 默认字符串比较(去除首尾空白)
|
|
|
- if (!String.valueOf(val1).trim().equals(String.valueOf(val2).trim())) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 这里需要开启事务
|
|
|
- * 数据增量入库
|
|
|
- *
|
|
|
- * @param tableName
|
|
|
- * @param theValueList
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
- public Boolean incrementDataStorage(String tableName, List<Map<String, Object>> theValueList) {
|
|
|
- /**
|
|
|
- * 1。查询出当前表所有数据。
|
|
|
- * 2.修改当前数据的valid_flag为1,表示历史版本
|
|
|
- * 3.把当前数据和数据库数据进行对比,获取新增数据和修改数据。
|
|
|
- * 4.新增数据直接插入,修改数据根据主键进行更新。
|
|
|
- * 任务标识码相同,并且geom数据有相交则认为数据相同。
|
|
|
- */
|
|
|
- boolean addRes = false;
|
|
|
- Integer shpDbSRID = 4326;
|
|
|
- if (!CollectionUtils.isEmpty(theValueList)) {
|
|
|
- //先删除数据
|
|
|
- cadastreFileMapper.deleteByValidFlag("1", tableName);
|
|
|
- //查询出当前表所有数据。
|
|
|
- List<Map<String, Object>> dbDataList = cadastreFileMapper.selectTableData("0", tableName);
|
|
|
- //筛选出需要更新的数据
|
|
|
- List<Map<String, Object>> dbExistsList = new ArrayList<>();
|
|
|
- for (Map<String, Object> map : theValueList) {
|
|
|
- Map<String, Object> dbExistsMap = cadastreFileMapper.selectExistsSameData("0", map, tableName);
|
|
|
- if (MapUtils.isNotEmpty(dbExistsMap)) {
|
|
|
- dbExistsList.add(dbExistsMap);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 在dbDataList 中找出 dbExistsMap中各个字段完全一致的数据 并从dbDataList移除
|
|
|
- if (CollectionUtils.isNotEmpty(dbExistsList)) {
|
|
|
- for (Map<String, Object> dbExistsMap : dbExistsList) {
|
|
|
- dbDataList.removeIf(dbData -> isSameData(dbData, dbExistsMap));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //这里合并两个list 最终写入数据表
|
|
|
- if (CollectionUtils.isNotEmpty(dbDataList)) {
|
|
|
- theValueList.addAll(dbDataList);
|
|
|
- }
|
|
|
-
|
|
|
- //先把当前版本都修改为历史版本
|
|
|
- cadastreFileMapper.updateValidFlag("1", "0", tableName);
|
|
|
- for (Map<String, Object> map : theValueList) {
|
|
|
- map.put("valid_flag", 0);//有效数据标识
|
|
|
- cadastreFileMapper.insertTableData(tableName, map, shpDbSRID);
|
|
|
- }
|
|
|
- }
|
|
|
- return addRes;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取列表
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Map<String, Object> list(CadastreFileFilterVo cadastreFileFilterVo) {
|
|
|
- List<CadastreFile> list = cadastreFileMapper.getListByFilter(cadastreFileFilterVo);
|
|
|
- int count = cadastreFileMapper.getCountByFilter(cadastreFileFilterVo);
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("rows", list);
|
|
|
- map.put("total", count);
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量删除
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void batchDelete(List<String> ids) {
|
|
|
- if (ids == null || ids.isEmpty()) {
|
|
|
- throw new IllegalArgumentException("IDs list cannot be null or empty");
|
|
|
- }
|
|
|
- cadastreFileMapper.batchDelete(ids);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void testRun() {
|
|
|
- //这里批量增修改表结构增加校验字段:
|
|
|
- String[] arr = new String[]{
|
|
|
- "tdgy_jh",
|
|
|
- "tdjyq",
|
|
|
- "TB_TDGY_SJ",
|
|
|
- "t_cgzj_cwtc_m",
|
|
|
- "t_cgzj_cwtc_m_bak1",
|
|
|
- "t_cgzj_cwtc_m_copy1",
|
|
|
- "public_dict",
|
|
|
- "spatial_ref_sys"
|
|
|
- };
|
|
|
-
|
|
|
- //获取库中表名
|
|
|
- //List<String> allTableList = cadastreFileMapper.selectAllTable();
|
|
|
- List<String> allTableList = cadastreFileMapper.selectAllTableNoView();
|
|
|
- allTableList.removeAll(Arrays.asList(arr));
|
|
|
-
|
|
|
- // 对每个表名执行添加校验字段的操作
|
|
|
- for (String tableName : allTableList) {
|
|
|
- System.out.println("正在处理表: " + tableName);
|
|
|
- cadastreFileMapper.addValidFlagColumn(tableName);
|
|
|
- System.out.println("正在处理表: " + tableName + " 完成");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
- @Override
|
|
|
- public String backToOldData(String uploadId) {
|
|
|
- try {
|
|
|
- CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
- if (!"1".equals(cadastreFile.getStatus())) {
|
|
|
- throw new ServiceException("可能未入库成功,无法回退");
|
|
|
- }
|
|
|
-
|
|
|
- List<String> fileTableNameList = new ArrayList<>();
|
|
|
- if ("1".equals(cadastreFile.getFileType())) {//矢量数据
|
|
|
- fileTableNameList = getLayerNameList(uploadId);
|
|
|
- } else if ("2".equals(cadastreFile.getFileType())) { //表格数据
|
|
|
- fileTableNameList = getMdbTableNameList(uploadId);
|
|
|
- }
|
|
|
-
|
|
|
- for (String layerName : fileTableNameList) {
|
|
|
- //校验是否都有历史版本
|
|
|
- Integer count = cadastreFileMapper.countByValidFlag("1", layerName.toLowerCase(Locale.ROOT));
|
|
|
- if (count == 0) {
|
|
|
- throw new ServiceException("表" + layerName + "没有历史版本,无法回退");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for (String layerName : fileTableNameList) {
|
|
|
-
|
|
|
- cadastreFileMapper.deleteByValidFlag("0", layerName.toLowerCase(Locale.ROOT));
|
|
|
- cadastreFileMapper.updateValidFlag("0", "1", layerName.toLowerCase(Locale.ROOT));
|
|
|
- log.info("正在回退表:{}。。。", layerName);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("数据回退异常,uploadId: {}", uploadId, e);
|
|
|
- throw new ServiceException("数据回退异常," + e.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
-// //成功则更新状态
|
|
|
-// CadastreFile updateCadastreFile = new CadastreFile();
|
|
|
-// updateCadastreFile.setId(uploadId);
|
|
|
-// updateCadastreFile.setStatus("4");//已经回退
|
|
|
-// updateCadastreFile.setReadMessage("已经回退");//校验通过
|
|
|
-// cadastreFileMapper.update(updateCadastreFile);
|
|
|
- return "当前批次数据已回退到上一个版本!:" + uploadId;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取图层名称列表
|
|
|
- *
|
|
|
- * @param uploadId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<String> getLayerNameList(String uploadId) {
|
|
|
- List<String> nameList = new ArrayList<>();
|
|
|
- CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
- String gdbPath = cadastreFile.getUnzipPath();
|
|
|
- DataSource ds = ogr.Open(gdbPath + "/" + cadastreFile.getName(), 0); // 0 = 只读
|
|
|
- if (ds == null) {
|
|
|
- throw new ServiceException("无法打开 gdb");
|
|
|
- }
|
|
|
- //这里进行遍历每个图层
|
|
|
- for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
- Layer layer = ds.GetLayer(i);
|
|
|
- String layerName = layer.GetName();
|
|
|
- nameList.add(layerName);
|
|
|
- }
|
|
|
- return nameList;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 获取mdb文件中表名称
|
|
|
- *
|
|
|
- * @param uploadId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<String> getMdbTableNameList(String uploadId) throws Exception {
|
|
|
- List<String> nameList = new ArrayList<>();
|
|
|
- CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
- String gdbPath = cadastreFile.getUnzipPath();
|
|
|
- List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + cadastreFile.getName(), "", "");
|
|
|
- for (Map<String, Object> tableMap : allMdbTableList) {
|
|
|
- String talbleName = String.valueOf(tableMap.get("name"));
|
|
|
- nameList.add(talbleName);
|
|
|
- }
|
|
|
- return nameList;
|
|
|
- }
|
|
|
-
|
|
|
- //1.获取图层中所有数据
|
|
|
- //2.获取库中所有数据
|
|
|
- //3.进行对比返回
|
|
|
- @Override
|
|
|
- public List<LayerAndDbData> getLayerData(String uploadId) {
|
|
|
- List<LayerAndDbData> resList = new ArrayList<>();
|
|
|
- try {
|
|
|
- CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
- //这里判断是否校验通过
|
|
|
- if (!cadastreFile.getStatus().equalsIgnoreCase("3")) {
|
|
|
- log.info("校验未通过,不能入库");
|
|
|
- throw new ServiceException("校验未通过,不能入库");
|
|
|
- }
|
|
|
- String gdbPath = cadastreFile.getUnzipPath();
|
|
|
- DataSource ds = ogr.Open(gdbPath + "/" + cadastreFile.getName(), 0); // 0 = 只读
|
|
|
- if (ds == null) {
|
|
|
- log.warn("无法打开 gdb");
|
|
|
- throw new ServiceException("无法打开 gdb");
|
|
|
- }
|
|
|
- //这里进行遍历每个图层
|
|
|
- for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
- Layer layer = ds.GetLayer(i);
|
|
|
- String layerName = layer.GetName();
|
|
|
- LayerAndDbData layerAndDbData = new LayerAndDbData();
|
|
|
- layerAndDbData.setCurrentTableName(layerName);
|
|
|
-
|
|
|
- boolean haveGeom = false;//这里不需要geom信息
|
|
|
- List<Map<String, String>> dbFieldNameAndTypeList = cadastreFileMapper.selectTableCollumAndType(layerName.toLowerCase(Locale.ROOT));
|
|
|
- Map<String, String> dbFieldNameAndTypeMap = dbFieldNameAndTypeList.stream().collect(Collectors.toMap(
|
|
|
- s -> s.get("column_name"),
|
|
|
- s -> s.get("data_type"),
|
|
|
- (existing, replacement) -> existing // 如果有重复键,保留第一个值
|
|
|
- ));
|
|
|
- List<Map<String, Object>> theValueList = getValueList(layer, dbFieldNameAndTypeMap, haveGeom);
|
|
|
- List<Map<String, Object>> dbDataList = cadastreFileMapper.selectTableData("0", layerName);
|
|
|
-
|
|
|
- layerAndDbData.setAddTotalNum(theValueList.size());
|
|
|
- layerAndDbData.setInsertNum(theValueList.size());
|
|
|
- layerAndDbData.setMarkHistoryNum(dbDataList.size());
|
|
|
- layerAndDbData.setInsertDataList(theValueList);
|
|
|
- layerAndDbData.setMarkHistoryDataList(dbDataList);
|
|
|
- resList.add(layerAndDbData);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("矢量数据入库异常,uploadId: {}", uploadId, e);
|
|
|
- throw new ServiceException("矢量数据入库异常," + e.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- return resList;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取表格数据进行对比
|
|
|
- *
|
|
|
- * @param uploadId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<LayerAndDbData> getMdbPropertyData(String uploadId) {
|
|
|
- List<LayerAndDbData> resList = new ArrayList<>();
|
|
|
- try {
|
|
|
- CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
- //这里判断是否校验通过
|
|
|
- if (!cadastreFile.getStatus().equalsIgnoreCase("3")) {
|
|
|
- log.info("校验未通过,不能入库");
|
|
|
- throw new ServiceException("校验未通过,不能入库");
|
|
|
- }
|
|
|
- String gdbPath = cadastreFile.getUnzipPath();
|
|
|
- List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + cadastreFile.getName(), "", "");
|
|
|
-
|
|
|
- for (Map<String, Object> tableMap : allMdbTableList) {
|
|
|
- String talbleName = String.valueOf(tableMap.get("name"));
|
|
|
- LayerAndDbData layerAndDbData = new LayerAndDbData();
|
|
|
- layerAndDbData.setCurrentTableName(talbleName);
|
|
|
-
|
|
|
- Map<String, Object> allMdbTableFieldMap = MdbUtil.MdbTableContent(gdbPath + "/" + cadastreFile.getName(), talbleName, "", "", 1, 1000);
|
|
|
- List<Map<String, Object>> theValueList = (List<Map<String, Object>>) allMdbTableFieldMap.get("rows");
|
|
|
- List<Map<String, Object>> dbDataList = cadastreFileMapper.selectTableData("0", talbleName);
|
|
|
-
|
|
|
- layerAndDbData.setAddTotalNum(theValueList.size());
|
|
|
- layerAndDbData.setInsertNum(theValueList.size());
|
|
|
- layerAndDbData.setMarkHistoryNum(dbDataList.size());
|
|
|
- layerAndDbData.setInsertDataList(theValueList);
|
|
|
- layerAndDbData.setMarkHistoryDataList(dbDataList);
|
|
|
- resList.add(layerAndDbData);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("矢量数据入库异常,uploadId: {}", uploadId, e);
|
|
|
- throw new ServiceException("矢量数据入库异常," + e.getMessage());
|
|
|
- }
|
|
|
- return resList;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<MdbAndDbData> getMdbCompareData(String uploadId) {
|
|
|
- List<MdbAndDbData> resList = new ArrayList<>();
|
|
|
- try {
|
|
|
- CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
- //这里判断是否校验通过
|
|
|
- if (!cadastreFile.getStatus().equalsIgnoreCase("3")) {
|
|
|
- log.info("校验未通过,不能入库");
|
|
|
- throw new ServiceException("校验未通过,不能入库");
|
|
|
- }
|
|
|
- String gdbPath = cadastreFile.getUnzipPath();
|
|
|
- List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + cadastreFile.getName(), "", "");
|
|
|
-
|
|
|
- for (Map<String, Object> tableMap : allMdbTableList) {
|
|
|
- String talbleName = String.valueOf(tableMap.get("name"));
|
|
|
- MdbAndDbData mdbAndDbData = new MdbAndDbData();
|
|
|
- mdbAndDbData.setCurrentTableName(talbleName);
|
|
|
- List<Map<String, String>> dbFieldNameAndTypeList = cadastreFileMapper.selectTableCollumAndType(talbleName.toLowerCase(Locale.ROOT));
|
|
|
- Map<String, String> dbFieldNameAndTypeMap = dbFieldNameAndTypeList.stream().collect(Collectors.toMap(
|
|
|
- s -> s.get("column_name"),
|
|
|
- s -> s.get("data_type"),
|
|
|
- (existing, replacement) -> existing // 如果有重复键,保留第一个值
|
|
|
- ));
|
|
|
-
|
|
|
- Map<String, Object> allMdbTableFieldMap = MdbUtil.MdbTableContent(gdbPath + "/" + cadastreFile.getName(), talbleName, "", "", 1, 1000);
|
|
|
- List<Map<String, Object>> theValueList = (List<Map<String, Object>>) allMdbTableFieldMap.get("rows");
|
|
|
- List<Map<String, Object>> dbDataList = cadastreFileMapper.selectTableData("0", talbleName);
|
|
|
-
|
|
|
- //这里进行遍历dbDataList,判断是否存在bsm字段,且bsm字段是否存在于theValueList中
|
|
|
- Set<String> mdbBsmSet = theValueList.stream()
|
|
|
- .map(v -> v.get("bsm".toUpperCase(Locale.ROOT)))
|
|
|
- .filter(bsm -> bsm != null)
|
|
|
- .map(String::valueOf)
|
|
|
- .collect(Collectors.toSet());
|
|
|
-
|
|
|
- dbDataList.stream()
|
|
|
- .filter(dbData -> {
|
|
|
- Object bsmObj = dbData.get("bsm");
|
|
|
- return bsmObj != null && mdbBsmSet.contains(String.valueOf(bsmObj));
|
|
|
- })
|
|
|
- .forEach(dbData -> dbData.put("valid_flag", 100));
|
|
|
-
|
|
|
- mdbAndDbData.setMdbFileDataList(theValueList);
|
|
|
- mdbAndDbData.setDbDataList(dbDataList);
|
|
|
- resList.add(mdbAndDbData);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("获取mdb对比数据异常,uploadId: {}", uploadId, e);
|
|
|
- throw new ServiceException("获取mdb对比数据异常," + e.getMessage());
|
|
|
- }
|
|
|
- return resList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Map<String,Object>> selectTableRow(String tableName,String geomFlag,String bsm,String ywh) {
|
|
|
- String validFlag = "0";
|
|
|
- if(Arrays.asList("tf_500", "tf_1000", "tf_2000","zd_shp").contains(tableName)){
|
|
|
- validFlag = "";
|
|
|
- }
|
|
|
- if(StringUtils.isNotEmpty(bsm)){
|
|
|
- bsm = bsm.trim();
|
|
|
- }
|
|
|
- if(StringUtils.isNotEmpty(ywh)){
|
|
|
- ywh = ywh.trim();
|
|
|
- }
|
|
|
- if (ywh.matches(".*=\\d+")) {
|
|
|
- ywh = ywh.replaceAll("=(\\d+)", "='$1'");
|
|
|
- }
|
|
|
- List<Map<String,Object>> res = cadastreFileMapper.selectTableDataByCondition(validFlag,tableName,bsm,ywh);
|
|
|
- if(CollectionUtils.isNotEmpty(res)){ //去掉geom字段和valid_flag字段
|
|
|
- List<Map<String, String>> dbFieldNameAndTypeList = cadastreFileMapper.selectTableCollumAndType(tableName.toLowerCase(Locale.ROOT));
|
|
|
- List<Object> filterCollumList = dbFieldNameAndTypeList.stream().filter(s->s.get("data_type").equals("bytea")).map(s->s.get("column_name")).collect(Collectors.toList());
|
|
|
- filterCollumList.add("valid_flag");
|
|
|
- //res.forEach(m -> m.keySet().removeIf(k -> "valid_flag".equalsIgnoreCase(k)));
|
|
|
- res.forEach(m -> m.keySet().removeIf(filterCollumList::contains));
|
|
|
- if("0".equals(geomFlag)){
|
|
|
- res.forEach(m -> m.keySet().removeIf("geom"::equalsIgnoreCase));
|
|
|
- }
|
|
|
- res.forEach(s -> {
|
|
|
- if(s.get("geom") != null){
|
|
|
- WKBReader reader = new WKBReader();
|
|
|
- org.locationtech.jts.geom.Geometry geom = null;
|
|
|
- try {
|
|
|
- geom = reader.read(WKBReader.hexToBytes(s.get("geom").toString()));
|
|
|
- } catch (ParseException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- //geom.setSRID(4490);
|
|
|
- WKTWriter writer = new WKTWriter();
|
|
|
- String ewkt = "SRID=" + "4326" + ";" + writer.write(geom);
|
|
|
- s.put("geom", ewkt);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<String> getTableFields(String tableName) {
|
|
|
- List<String> res = cadastreFileMapper.selectTableCollum(tableName);
|
|
|
- res.remove("valid_flag");
|
|
|
- res.remove("geom");
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<String> getDistinctValueByField(String tableName,String fieldName) {
|
|
|
- List<String> res = new ArrayList<>();
|
|
|
- String validFlag =null;
|
|
|
- List<String> collumList = cadastreFileMapper.selectTableCollum(tableName);
|
|
|
- if(!collumList.contains(fieldName)){
|
|
|
- return res;
|
|
|
- }
|
|
|
- if(collumList.contains("valid_flag")){
|
|
|
- validFlag = "0";
|
|
|
- }
|
|
|
- res = cadastreFileMapper.selectDistinctValueByField(tableName,fieldName,validFlag);
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public String tableRowUpdate(String tableName, List<Map<String,Object>> list) {
|
|
|
- for (Map<String, Object> row : list) {
|
|
|
- row.replaceAll((k, v) -> {
|
|
|
- if (v instanceof String) {
|
|
|
- String sv = (String) v;
|
|
|
- try {
|
|
|
- return new java.math.BigDecimal(sv);
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- return v;
|
|
|
- }
|
|
|
- }
|
|
|
- return v;
|
|
|
- });
|
|
|
- }
|
|
|
- int res = cadastreFileMapper.batchUpdateByBsm(tableName,list);
|
|
|
- return res+"";
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String batchDeleteByBsm(String tableName, List<Map<String,Object>> list) {
|
|
|
- int res = cadastreFileMapper.batchDeleteByBsm(tableName,list);
|
|
|
- return res+"";
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> getDataByName(String tableName) {
|
|
|
- Map<String, Object> map = cadastreFileMapper.selectTableDataByBsm(tableName, "");
|
|
|
- List<Map<String, Object>> list = new ArrayList<>();
|
|
|
- list.add(map);
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> selectTableRowExcel(String tableName, String geomFlag, List<Object> bsmList, List<String> ywhList) {
|
|
|
- List<Map<String, Object>> res = cadastreFileMapper.selectTableRowExcel(tableName, geomFlag, bsmList, ywhList);
|
|
|
- if(CollectionUtils.isNotEmpty(res)) { //去掉geom字段和valid_flag字段
|
|
|
- res.forEach(m -> m.keySet().removeIf(k -> "valid_flag".equalsIgnoreCase(k)));
|
|
|
- if ("0".equals(geomFlag)) {
|
|
|
- res.forEach(m -> m.keySet().removeIf(k -> "geom".equalsIgnoreCase(k)));
|
|
|
- }
|
|
|
- }
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public Boolean checkQueryWhere(String tableName, String queryWhere) {
|
|
|
- try {
|
|
|
- if (queryWhere.matches(".*=\\d+")) {
|
|
|
- queryWhere = queryWhere.replaceAll("=(\\d+)", "='$1'");
|
|
|
- }
|
|
|
- String res = cadastreFileMapper.checkQueryWhere(tableName, queryWhere);
|
|
|
- log.info("SQL语法检查结果,res: {}", res);
|
|
|
- return true;
|
|
|
- } catch (Exception e) {
|
|
|
- throw new ServiceException("SQL语法检查异常:");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * 生成一个mdb文件
|
|
|
- *
|
|
|
- * @param tableName
|
|
|
- * @param filePath
|
|
|
- * @param fileName
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void testBuildMdbFile(String tableName, String filePath, String fileName) {
|
|
|
- try {
|
|
|
- // 1. 获取表字段及类型信息
|
|
|
- List<Map<String, String>> columns = cadastreFileMapper.selectTableCollumAndType(tableName);
|
|
|
- if (columns == null || columns.isEmpty()) {
|
|
|
- log.warn("无法获取表字段信息: {}", tableName);
|
|
|
- throw new ServiceException("无法获取表字段信息: "+tableName);
|
|
|
- }
|
|
|
-
|
|
|
- if(columns.stream().anyMatch(s->s.get("column_name").equals("geom"))){
|
|
|
- log.warn("当前为矢量数据,无法生成mdb: {}", tableName);
|
|
|
- throw new ServiceException("当前为矢量数据,无法生成mdb");
|
|
|
- }
|
|
|
-
|
|
|
- // 2. 获取表数据 (获取 valid_flag 为 0 的当前版本数据)
|
|
|
- List<Map<String, Object>> dataList = cadastreFileMapper.selectTableData("", tableName);
|
|
|
-
|
|
|
- // 3. 构造完整的文件路径
|
|
|
- String mdbPath = filePath;
|
|
|
- if (!mdbPath.endsWith(File.separator)) {
|
|
|
- mdbPath += File.separator;
|
|
|
- }
|
|
|
- mdbPath += fileName;
|
|
|
- if (!mdbPath.toLowerCase().endsWith(".mdb")) {
|
|
|
- mdbPath += ".mdb";
|
|
|
- }
|
|
|
-
|
|
|
- // 4. 调用工具类生成 MDB 文件并写入数据
|
|
|
- MdbUtil.writeMdbByTable(mdbPath, tableName, columns, dataList);
|
|
|
-
|
|
|
- log.info("MDB 文件生成成功: {}", mdbPath);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("生成 MDB 文件失败: {}", tableName, e);
|
|
|
- throw new ServiceException("生成 MDB 文件失败: " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 4527坐标系转换为4326坐标系
|
|
|
- * @param ewkt
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String transforGeomTo4326(String ewkt) {
|
|
|
- if(StringUtils.isBlank(ewkt)){
|
|
|
- return "";
|
|
|
- }
|
|
|
- return cadastreFileMapper.transformTo4326(ewkt);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+//package com.siwei.apply.service.cadastre.impl;
|
|
|
+//
|
|
|
+//import com.siwei.apply.domain.CadastreFile;
|
|
|
+//import com.siwei.apply.domain.LayerAndDbData;
|
|
|
+//import com.siwei.apply.domain.MdbAndDbData;
|
|
|
+//import com.siwei.apply.domain.vo.*;
|
|
|
+//import com.siwei.apply.mapper.CadastreFileMapper;
|
|
|
+//import com.siwei.apply.mapper.FzssFxrwrzMapper;
|
|
|
+//import com.siwei.apply.service.cadastre.CadastreManageService;
|
|
|
+//
|
|
|
+//import com.siwei.apply.utils.FileExtractUtil;
|
|
|
+//import com.siwei.apply.utils.MdbUtil;
|
|
|
+//import com.siwei.common.core.exception.ServiceException;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.apache.commons.collections4.CollectionUtils;
|
|
|
+//import org.apache.commons.collections4.MapUtils;
|
|
|
+//import org.apache.commons.lang3.StringUtils;
|
|
|
+//import org.gdal.ogr.*;
|
|
|
+//import org.gdal.osr.CoordinateTransformation;
|
|
|
+//import org.gdal.osr.SpatialReference;
|
|
|
+//import org.locationtech.jts.io.ParseException;
|
|
|
+//import org.locationtech.jts.io.WKBReader;
|
|
|
+//import org.locationtech.jts.io.WKTWriter;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.stereotype.Service;
|
|
|
+//import org.springframework.transaction.annotation.Propagation;
|
|
|
+//import org.springframework.transaction.annotation.Transactional;
|
|
|
+//
|
|
|
+//import java.io.File;
|
|
|
+//import java.nio.file.Files;
|
|
|
+//import java.nio.file.Path;
|
|
|
+//import java.nio.file.Paths;
|
|
|
+//import java.util.*;
|
|
|
+//import java.util.stream.Collectors;
|
|
|
+//
|
|
|
+//
|
|
|
+///**
|
|
|
+// * 地籍管理系统主业务逻辑
|
|
|
+// */
|
|
|
+//@Slf4j
|
|
|
+//@Service
|
|
|
+//public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
+// static {
|
|
|
+// ogr.RegisterAll();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private CadastreFileMapper cadastreFileMapper;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private FzssFxrwrzHandleService fzssFxrwrzHandleService;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private FzssFxrwrzMapper fzssFxrwrzMapper;
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// *
|
|
|
+// * 解析文件内容,insert 到表中
|
|
|
+// * <p>
|
|
|
+// * <p>
|
|
|
+// * 1.进行解析数据成为list<map></map>
|
|
|
+// * 2.进行调用方法动态插入到当前表中
|
|
|
+// * 3.需要修改upload 的表更新状态
|
|
|
+// * 4.考虑增量入库还是全量入库。()
|
|
|
+// * 5.校验逻辑复杂()
|
|
|
+// *
|
|
|
+// */
|
|
|
+// @Transactional(rollbackFor = Exception.class)
|
|
|
+// @Override
|
|
|
+// public String addBatchGdbData(String uploadId) {
|
|
|
+// String result = "success";
|
|
|
+// try {
|
|
|
+// CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
+// //这里判断是否校验通过
|
|
|
+// if (!cadastreFile.getStatus().equalsIgnoreCase("3")) {
|
|
|
+// log.info("校验未通过,不能入库");
|
|
|
+// result = "校验未通过,不能入库";
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", result, "info");
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// String gdbPath = cadastreFile.getUnzipPath();
|
|
|
+// DataSource ds = ogr.Open(gdbPath + "/" + cadastreFile.getName(), 0); // 0 = 只读
|
|
|
+// if (ds == null) {
|
|
|
+// log.warn("无法打开 gdb");
|
|
|
+// result = "无法打开gdb文件,不能入库";
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", result, "info");
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "正在执行入库操作。。。", "info");
|
|
|
+// //这里进行遍历每个图层
|
|
|
+// for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
+// Layer layer = ds.GetLayer(i);
|
|
|
+// String layerName = layer.GetName();
|
|
|
+//
|
|
|
+// boolean haveGeom = false;
|
|
|
+// //获取字段信息
|
|
|
+// List<String> dbFieldNameList = cadastreFileMapper.selectTableCollum(layerName.toLowerCase(Locale.ROOT));
|
|
|
+// if (dbFieldNameList.contains("geom")) {
|
|
|
+// haveGeom = true;
|
|
|
+// }
|
|
|
+//
|
|
|
+// List<Map<String, String>> dbFieldNameAndTypeList = cadastreFileMapper.selectTableCollumAndType(layerName.toLowerCase(Locale.ROOT));
|
|
|
+// Map<String, String> dbFieldNameAndTypeMap = dbFieldNameAndTypeList.stream().collect(Collectors.toMap(
|
|
|
+// s -> s.get("column_name"),
|
|
|
+// s -> s.get("data_type"),
|
|
|
+// (existing, replacement) -> existing // 如果有重复键,保留第一个值
|
|
|
+// ));
|
|
|
+// List<Map<String, Object>> theValueList = getValueList(layer, dbFieldNameAndTypeMap, haveGeom);
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "正在执行-" + layerName + "-入库", "info");
|
|
|
+// //这里直接数据入库,区分增量或者全量
|
|
|
+// Boolean addRes;
|
|
|
+// if ("2".equalsIgnoreCase(cadastreFile.getReadStatus())) {
|
|
|
+// //增量更新
|
|
|
+// addRes = incrementDataStorage(layerName, theValueList);
|
|
|
+// if (addRes.equals(true)) {
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "增量更新-" + layerName + "-成功", "info");
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// addRes = fullDataStorage(layerName, theValueList);
|
|
|
+// if (addRes.equals(true)) {
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "增量更新-" + layerName + "-成功", "info");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// log.error("当前图层{},入库结果 {}", layerName, addRes);
|
|
|
+// }
|
|
|
+// //成功则更新状态
|
|
|
+// CadastreFile updateCadastreFile = new CadastreFile();
|
|
|
+// updateCadastreFile.setId(cadastreFile.getId());
|
|
|
+// updateCadastreFile.setStatus("1");//入库成功
|
|
|
+// updateCadastreFile.setReadMessage("入库成功");//入库成功
|
|
|
+// cadastreFileMapper.update(updateCadastreFile);
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前批次-" + cadastreFile.getId() + "-入库成功", "info");
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("矢量数据入库异常,uploadId: {}", uploadId, e);
|
|
|
+// //更新状态
|
|
|
+// CadastreFile updateCadastreFile = new CadastreFile();
|
|
|
+// updateCadastreFile.setId(uploadId);
|
|
|
+// updateCadastreFile.setStatus("2");//入库失败
|
|
|
+// updateCadastreFile.setReadMessage("入库失败");//入库失败
|
|
|
+// cadastreFileMapper.update(updateCadastreFile);
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前批次-" + uploadId + "-入库失败", "info");
|
|
|
+// throw new ServiceException("矢量数据入库异常," + e.getMessage());
|
|
|
+// }
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @Transactional(rollbackFor = Exception.class)
|
|
|
+// @Override
|
|
|
+// public String addBatchMdbData(String uploadId) {
|
|
|
+// String result = "success";
|
|
|
+// try {
|
|
|
+// CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
+// //这里判断是否校验通过
|
|
|
+// if (!cadastreFile.getStatus().equalsIgnoreCase("3")) {
|
|
|
+// log.info("校验未通过,不能入库");
|
|
|
+// result = "校验未通过,不能入库";
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", result, "info");
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// String gdbPath = cadastreFile.getUnzipPath();
|
|
|
+// List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + cadastreFile.getName(), "", "");
|
|
|
+//
|
|
|
+// if (allMdbTableList == null) {
|
|
|
+// log.warn("无法打开 mdb");
|
|
|
+// result = "无法打开mdb文件,不能入库";
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", result, "info");
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "正在执行入库操作。。。", "info");
|
|
|
+// for (Map<String, Object> tableMap : allMdbTableList) {
|
|
|
+// String talbleName = String.valueOf(tableMap.get("name"));
|
|
|
+// //List<Map<String, Object>> theValueList = getValueList(layer, dbFieldNameAndTypeMap, haveGeom);
|
|
|
+// Map<String, Object> allMdbTableFieldMap = MdbUtil.MdbTableContent(gdbPath + "/" + cadastreFile.getName(), talbleName, "", "", 1, 1000);
|
|
|
+// List<Map<String, Object>> theValueList = (List<Map<String, Object>>) allMdbTableFieldMap.get("rows");
|
|
|
+//
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "正在执行-" + talbleName + "-入库", "info");
|
|
|
+// //这里直接数据入库,区分增量或者全量
|
|
|
+// Boolean addRes;
|
|
|
+// if ("2".equalsIgnoreCase(cadastreFile.getReadStatus())) {
|
|
|
+// //增量更新
|
|
|
+// addRes = incrementDataStorage(talbleName, theValueList);
|
|
|
+// if (addRes.equals(true)) {
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "增量更新-" + talbleName + "-成功", "info");
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// addRes = fullDataStorage(talbleName, theValueList);
|
|
|
+// if (addRes.equals(true)) {
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "全量更新-" + talbleName + "-成功", "info");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// log.error("当前属性名{},入库结果 {}", talbleName, addRes);
|
|
|
+// }
|
|
|
+// //成功则更新状态
|
|
|
+// CadastreFile updateCadastreFile = new CadastreFile();
|
|
|
+// updateCadastreFile.setId(cadastreFile.getId());
|
|
|
+// updateCadastreFile.setStatus("1");//入库成功
|
|
|
+// updateCadastreFile.setReadMessage("入库成功");//入库成功
|
|
|
+// cadastreFileMapper.update(updateCadastreFile);
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前批次-" + cadastreFile.getId() + "-入库成功", "info");
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("mdb表格数据入库异常,uploadId: {}", uploadId, e);
|
|
|
+// //更新状态
|
|
|
+// CadastreFile updateCadastreFile = new CadastreFile();
|
|
|
+// updateCadastreFile.setId(uploadId);
|
|
|
+// updateCadastreFile.setStatus("2");//入库失败
|
|
|
+// updateCadastreFile.setReadMessage("入库失败");//入库失败
|
|
|
+// cadastreFileMapper.update(updateCadastreFile);
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前批次-" + uploadId + "-入库失败", "info");
|
|
|
+// throw new ServiceException("表格数据入库异常," + e.getMessage());
|
|
|
+// }
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 获取比较数据
|
|
|
+// *
|
|
|
+// * @param uploadId
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public CompareResultVo getCompareData(String uploadId) {
|
|
|
+// CompareResultVo compareResultVo = new CompareResultVo();
|
|
|
+// compareResultVo.setUploadId(uploadId);
|
|
|
+// compareResultVo.setResultStatus(true);
|
|
|
+// try {
|
|
|
+// List<CompareGemoVo> gemos = new ArrayList<>();
|
|
|
+// CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
+// String gdbPath = cadastreFile.getUnzipPath();
|
|
|
+// DataSource ds = ogr.Open(gdbPath + "/" + cadastreFile.getName(), 0); // 0 = 只读
|
|
|
+// if (ds == null) {
|
|
|
+// log.warn("无法打开 gdb");
|
|
|
+// return compareResultVo;
|
|
|
+// }
|
|
|
+// //这里进行遍历每个图层
|
|
|
+// for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
+// Layer layer = ds.GetLayer(i);
|
|
|
+// String layerName = layer.GetName();
|
|
|
+//
|
|
|
+// CompareGemoVo compareGemoVo = new CompareGemoVo();
|
|
|
+// compareGemoVo.setLayerName(layerName);
|
|
|
+// List<String> layerGeom = getLayerGeom(layer);
|
|
|
+// compareGemoVo.setGeomData(layerGeom);
|
|
|
+// List<String> dbGeom = getDbGeom(layerName);
|
|
|
+// compareGemoVo.setOldGeomData(dbGeom);
|
|
|
+// //加入当前图层对比对象
|
|
|
+// gemos.add(compareGemoVo);
|
|
|
+// }
|
|
|
+// compareResultVo.setGemos(gemos);
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("获取对比矢量数据信息异常,uploadId: {}", uploadId, e);
|
|
|
+// throw new ServiceException("获取对比矢量数据信息异常," + e.getMessage());
|
|
|
+// }
|
|
|
+// return compareResultVo;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 文件upload入库
|
|
|
+// *
|
|
|
+// * @param theFileName
|
|
|
+// * @param theFilePath
|
|
|
+// * @param fileType
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public CadastreFile saveUploadFile(String theFileName, String theFilePath, String fileType, String updateType) {
|
|
|
+// try {
|
|
|
+// if (theFilePath == null || theFilePath.trim().isEmpty()) {
|
|
|
+// log.warn("处理文件失败:filePath不能为空");
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// Path currentFilePath = Paths.get(theFilePath);
|
|
|
+// if (!Files.exists(currentFilePath)) {
|
|
|
+// log.warn("处理文件失败:文件不存在: {}", theFilePath);
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// Long fileSize = Files.size(currentFilePath);
|
|
|
+//
|
|
|
+// // 判断是否为压缩文件
|
|
|
+// if (FileExtractUtil.isCompressedFile(theFilePath)) {
|
|
|
+// // 解压文件到同名文件夹并获取目录结构
|
|
|
+// String extractRes = FileExtractUtil.extractToSameNameFolder(theFilePath);
|
|
|
+// if (StringUtils.isBlank(extractRes)) {
|
|
|
+// log.warn("解压文件失败:文件不存在: {}", theFilePath);
|
|
|
+// throw new ServiceException("解压文件失败:文件不存在,");
|
|
|
+// }
|
|
|
+//
|
|
|
+// //解压成功文件保存
|
|
|
+// if (StringUtils.isNotBlank(extractRes)) {
|
|
|
+// String unZipPath = extractRes;
|
|
|
+// if ("1".equals(fileType)) { //gdb格式
|
|
|
+// String innerExtractFileName = FileExtractUtil.getInnerFolderByDirName(unZipPath);
|
|
|
+// // 如果解压后的文件夹名称不为空,则使用解压后的文件夹名称作为文件名
|
|
|
+// if (StringUtils.isNotBlank(innerExtractFileName)) {
|
|
|
+// theFileName = innerExtractFileName;
|
|
|
+// } else {
|
|
|
+// String suffix = ".gdb"; //需要后缀为.gdb才能被jar包识别为矢量数据进行读取
|
|
|
+// //这里解压文件名称作为文件名
|
|
|
+// String fileName = currentFilePath.getFileName().toString();
|
|
|
+// theFileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
|
|
+// theFileName += suffix;
|
|
|
+//
|
|
|
+// //如果当前压缩文件为gdb文件,则解压后的文件夹名称需要修改为.gdb结尾
|
|
|
+// FileExtractUtil.modifyDirName(unZipPath, unZipPath + suffix);
|
|
|
+// unZipPath += suffix;
|
|
|
+// unZipPath = unZipPath.replace(theFileName, "");
|
|
|
+// if (StringUtils.isNotBlank(unZipPath) && (unZipPath.endsWith("/") || unZipPath.endsWith("\\"))) {
|
|
|
+// unZipPath = unZipPath.substring(0, unZipPath.length() - 1);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (StringUtils.isNotBlank(theFileName) && !theFileName.toLowerCase(Locale.ROOT).endsWith(".gdb")) {
|
|
|
+// throw new ServiceException("文件不是gdb格式矢量数据,请检查重新上传");
|
|
|
+// }
|
|
|
+// } else if ("2".equals(fileType)) {//如果是mdb文件
|
|
|
+// String innerExtractFileName = FileExtractUtil.getInnerFileByDirName(unZipPath);
|
|
|
+// if (StringUtils.isBlank(innerExtractFileName)) {
|
|
|
+// throw new ServiceException("可能入库失败或没有历史版本,无法回退");
|
|
|
+// }
|
|
|
+// theFileName = innerExtractFileName;
|
|
|
+// if (StringUtils.isNotBlank(theFileName) && !theFileName.toLowerCase(Locale.ROOT).endsWith(".mdb")) {
|
|
|
+// throw new ServiceException("文件不是mdb格式表格数据,请检查重新上传");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// CadastreFile cadastreFile = new CadastreFile();
|
|
|
+// cadastreFile.generateId();//生成id
|
|
|
+// cadastreFile.setName(theFileName);
|
|
|
+// cadastreFile.setFilePath(theFilePath);
|
|
|
+// cadastreFile.setUnzipPath(unZipPath);
|
|
|
+// cadastreFile.setFileType("1");//矢量/表格
|
|
|
+// if (StringUtils.isNotBlank(fileType)) {
|
|
|
+// cadastreFile.setFileType(fileType);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //0 为全量更新,1为增量更新
|
|
|
+// if (StringUtils.isNotBlank(updateType)) {
|
|
|
+// cadastreFile.setReadStatus(updateType);
|
|
|
+// }
|
|
|
+// cadastreFile.setFileSize(fileSize);
|
|
|
+// cadastreFile.setStatus("0");
|
|
|
+// cadastreFile.setUploadUser("admin");
|
|
|
+// cadastreFile.setUploadTime(new Date());
|
|
|
+// cadastreFile.setReadMessage("入库中。。。");
|
|
|
+// cadastreFile.setUpdateTime(new Date());
|
|
|
+// cadastreFileMapper.add(cadastreFile);
|
|
|
+// return cadastreFile;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("处理文件并保存附件信息异常,filePath: {}", theFilePath, e);
|
|
|
+// throw new ServiceException("处理文件并保存附件信息异常," + e.getMessage());
|
|
|
+// }
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * //1.文件进行解压
|
|
|
+// * //1.先获取相关信息,进行入库
|
|
|
+// * //2.日志记录写入
|
|
|
+// * //3.读取文件进行录入
|
|
|
+// * //4.质量进行检查
|
|
|
+// * //日志记录
|
|
|
+// * //fzssFxrwrzHandleService.insertFxrwrz();
|
|
|
+// *
|
|
|
+// * @param theFileName
|
|
|
+// * @param theFilePath
|
|
|
+// * @param fileType
|
|
|
+// * @param updateType
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public CheckInfoResultVo checkFileData(String theFileName, String theFilePath, String fileType, String updateType) {
|
|
|
+// CheckInfoResultVo checkInfoResult = new CheckInfoResultVo();
|
|
|
+// checkInfoResult.setResultStatus(true);
|
|
|
+// List<CheckInfoVo> checkInfoSuccessList = new ArrayList<>();
|
|
|
+// List<CheckInfoVo> checkInfoFailList = new ArrayList<>();
|
|
|
+//
|
|
|
+// CadastreFile uploadFile = this.saveUploadFile(theFileName, theFilePath, fileType, updateType);
|
|
|
+//
|
|
|
+// if (Objects.nonNull(uploadFile)) {
|
|
|
+// //入库成功
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadFile.getId(), "地籍库管理", "上传文件成功", "info");
|
|
|
+// checkInfoResult.setUploadId(uploadFile.getId());
|
|
|
+// String gdbPath = uploadFile.getUnzipPath();
|
|
|
+// theFileName = uploadFile.getName();//这里需要使用解压处理后的文件名称进行读取
|
|
|
+// //获取库中表名
|
|
|
+// List<String> allTableList = cadastreFileMapper.selectAllTable();
|
|
|
+//
|
|
|
+// //这里区分文件类型,矢量还是表格的读取方式不一样
|
|
|
+// if (uploadFile.getFileType().equals("1")) { //矢量数据读取方式
|
|
|
+// DataSource ds = ogr.Open(gdbPath + "/" + theFileName, 0); // 0 = 只读
|
|
|
+// if (ds == null) {
|
|
|
+// log.warn("无法打开 gdb");
|
|
|
+// return checkInfoResult;
|
|
|
+// }
|
|
|
+// log.info("图层数量: {}", ds.GetLayerCount());
|
|
|
+// //这里进行遍历每个图层
|
|
|
+// for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
+// Layer layer = ds.GetLayer(i);
|
|
|
+// //todo 测试代码
|
|
|
+// //这里做质量检查
|
|
|
+// CheckInfoVo checkRes = checkLayerInfo(layer, allTableList, uploadFile.getId());
|
|
|
+// if (checkRes.getCheckStatus().equals(false)) { //检查出错
|
|
|
+// checkInfoFailList.add(checkRes);
|
|
|
+// checkInfoResult.setResultStatus(false);
|
|
|
+// } else if (checkRes.getCheckStatus().equals(true)) {
|
|
|
+// //成功则更新文件上传状态
|
|
|
+// CadastreFile cadastreFile = new CadastreFile();
|
|
|
+// cadastreFile.setId(uploadFile.getId());
|
|
|
+// cadastreFile.setStatus("3");//校验通过
|
|
|
+// cadastreFileMapper.update(cadastreFile);
|
|
|
+// checkInfoSuccessList.add(checkRes);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// ds.delete();
|
|
|
+// } else if (uploadFile.getFileType().equals("2")) {//处理表格类型
|
|
|
+// try {
|
|
|
+// List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + theFileName, "", "");
|
|
|
+// if (CollectionUtils.isNotEmpty(allTableList)) {
|
|
|
+// for (Map<String, Object> tableMap : allMdbTableList) {
|
|
|
+// String talbleName = String.valueOf(tableMap.get("name"));
|
|
|
+// Map<String, Object> allMdbTableFieldMap = MdbUtil.MdbTableContent(gdbPath + "/" + theFileName, talbleName, "", "", 1, 1000);
|
|
|
+// //这里做质量检查
|
|
|
+// CheckInfoVo checkRes = checkMdbInfo(talbleName, allTableList, allMdbTableFieldMap, uploadFile.getId());
|
|
|
+// if (checkRes.getCheckStatus().equals(false)) { //检查出错
|
|
|
+// checkInfoFailList.add(checkRes);
|
|
|
+// checkInfoResult.setResultStatus(false);
|
|
|
+// } else if (checkRes.getCheckStatus().equals(true)) {
|
|
|
+// //成功则更新文件上传状态
|
|
|
+// CadastreFile cadastreFile = new CadastreFile();
|
|
|
+// cadastreFile.setId(uploadFile.getId());
|
|
|
+// cadastreFile.setStatus("3");//校验通过
|
|
|
+// cadastreFileMapper.update(cadastreFile);
|
|
|
+// checkInfoSuccessList.add(checkRes);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("表格数据校验异常,uploadId: {}", uploadFile.getId(), e);
|
|
|
+// throw new ServiceException("表格数据校验异常,uploadId:" + uploadFile.getId());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// checkInfoResult.setCheckFailList(checkInfoFailList);
|
|
|
+// checkInfoResult.setCheckSuccessList(checkInfoSuccessList);
|
|
|
+// }
|
|
|
+// return checkInfoResult;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 对每个图层进行数据格式校验
|
|
|
+// *
|
|
|
+// * @param layer
|
|
|
+// * @param allTableList
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private CheckInfoVo checkLayerInfo(Layer layer, List<String> allTableList, String uploadId) {
|
|
|
+// //总返回对象
|
|
|
+// CheckInfoVo checkInfoVo = new CheckInfoVo();
|
|
|
+// checkInfoVo.setCheckStatus(true);//初始化检查通过
|
|
|
+//
|
|
|
+// List<String> checkInfoList = new ArrayList<>();
|
|
|
+// String name = layer.GetName();
|
|
|
+// checkInfoVo.setUploadFileTableName(name);
|
|
|
+//
|
|
|
+// //检查表名对应
|
|
|
+// if (!allTableList.contains(name.toLowerCase(Locale.ROOT))) {
|
|
|
+// checkInfoList.add(name + ":图层名称不在地籍库范围内!");
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", name + ":图层名称不在地籍库范围内!", "info");
|
|
|
+// checkInfoVo.setCheckStatus(false);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //检查坐标系
|
|
|
+// if (checkCoordinateSystem(layer).equals(false)) {
|
|
|
+// checkInfoList.add(name + ":坐标系不正确,确认是否CGCS2000!");
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", name + ":坐标系不正确,确认是否CGCS2000!", "info");
|
|
|
+// checkInfoVo.setCheckStatus(false);
|
|
|
+// }
|
|
|
+//
|
|
|
+// boolean haveGeom = false;
|
|
|
+// //获取字段信息
|
|
|
+// List<String> dbFieldNameList = cadastreFileMapper.selectTableCollum(name.toLowerCase(Locale.ROOT));
|
|
|
+// if (dbFieldNameList.contains("geom")) {
|
|
|
+// haveGeom = true;
|
|
|
+// }
|
|
|
+// //这里移除校验字段(非属mdb中的字段)
|
|
|
+// dbFieldNameList.remove("valid_flag");
|
|
|
+//
|
|
|
+// List<String> layerFieldNameList = this.getFieldName(layer, haveGeom);
|
|
|
+// // 判断是否包含相同的元素(不考虑顺序)
|
|
|
+// boolean areCollectionsEqual = CollectionUtils.containsAll(layerFieldNameList,dbFieldNameList);
|
|
|
+// if (!areCollectionsEqual) {
|
|
|
+// checkInfoList.add(name + ":字段数据不一致!-" + dbFieldNameList);
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", name + ":字段数据不一致!-" + dbFieldNameList, "info");
|
|
|
+// checkInfoVo.setCheckStatus(false);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //检查字段数据是否为空
|
|
|
+// //todo 这里根据表名获取相关校验字段信息
|
|
|
+// List<String> checkFieldList = new ArrayList<>();
|
|
|
+// //checkFieldList.add("111");
|
|
|
+// //checkFieldList.add("bz");
|
|
|
+// //仅获取图层属性
|
|
|
+// List<Map<String, Object>> theValueList = getValueList(layer, new LinkedHashMap<>(), false);
|
|
|
+// for (Map<String, Object> theMap : theValueList) {
|
|
|
+// for (String fieldName : checkFieldList) {
|
|
|
+// if (Objects.isNull(theMap.get(fieldName))) {
|
|
|
+// checkInfoList.add(name + "--" + fieldName + "字段不能为空!");
|
|
|
+// checkInfoVo.setCheckStatus(false);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// checkInfoVo.setCheckInfoList(checkInfoList);
|
|
|
+// //todo 这里需要放入到缓存中,并且可以下载为txt内容
|
|
|
+// if (checkInfoVo.getCheckStatus().equals(true)) {
|
|
|
+// checkInfoList.add("当前矢量数据:" + name + "---" + "数据格式为gdb");
|
|
|
+// checkInfoList.add("当前矢量数据:" + name + "---" + "坐标系是CGCS2000");
|
|
|
+// checkInfoList.add("当前矢量数据:" + name + "---" + "检查校验通过!");
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前矢量数据:" + name + "---" + "数据格式为gdb", "info");
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前矢量数据:" + name + "---" + "坐标系是CGCS2000", "info");
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前矢量数据:" + name + "---" + "检查校验通过!", "info");
|
|
|
+// }
|
|
|
+// return checkInfoVo;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// *
|
|
|
+// * 对表格属性数据进行数据格式校验
|
|
|
+// *
|
|
|
+// * @param mdbTableName
|
|
|
+// * @param allTableList
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private CheckInfoVo checkMdbInfo(String mdbTableName, List<String> allTableList, Map<String, Object> mdbTableFieldMap, String uploadId) {
|
|
|
+// //总返回对象
|
|
|
+// CheckInfoVo checkInfoVo = new CheckInfoVo();
|
|
|
+// checkInfoVo.setCheckStatus(true);//初始化检查通过
|
|
|
+// List<String> checkInfoList = new ArrayList<>();
|
|
|
+// checkInfoVo.setUploadFileTableName(mdbTableName);
|
|
|
+//
|
|
|
+// //字段名称
|
|
|
+// List<String> mdbTableFieldNameList = (List<String>) mdbTableFieldMap.get("column");
|
|
|
+// List<String> lowerCaseMdbTableFieldNameList = mdbTableFieldNameList.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
+//
|
|
|
+// //所有条数
|
|
|
+// List<Map<String, String>> dataList = (List<Map<String, String>>) mdbTableFieldMap.get("rows");
|
|
|
+//
|
|
|
+// //检查表名对应
|
|
|
+// if (!allTableList.contains(mdbTableName.toLowerCase(Locale.ROOT))) {
|
|
|
+// checkInfoList.add(mdbTableName + ":图层名称不在地籍库范围内!");
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", mdbTableName + ":图层名称不在地籍库范围内!", "info");
|
|
|
+// checkInfoVo.setCheckStatus(false);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //获取当前表数据库字段信息
|
|
|
+// List<String> dbFieldNameList = cadastreFileMapper.selectTableCollum(mdbTableName.toLowerCase(Locale.ROOT));
|
|
|
+// //这里移除校验字段(非属mdb中的字段)
|
|
|
+// dbFieldNameList.remove("valid_flag");
|
|
|
+// // 判断是否包含相同的元素(不考虑顺序)
|
|
|
+// boolean areCollectionsEqual = CollectionUtils.containsAll(lowerCaseMdbTableFieldNameList,dbFieldNameList);
|
|
|
+// if (!areCollectionsEqual) {
|
|
|
+// checkInfoList.add(mdbTableName + ":字段数据不一致!-" + dbFieldNameList);
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", mdbTableName + ":字段数据不一致!-" + dbFieldNameList, "info");
|
|
|
+// checkInfoVo.setCheckStatus(false);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //检查字段数据是否为空
|
|
|
+// //todo 这里根据表名获取相关校验字段信息
|
|
|
+// List<String> checkFieldList = new ArrayList<>();
|
|
|
+// //checkFieldList.add("111");
|
|
|
+// //checkFieldList.add("bz");
|
|
|
+//
|
|
|
+// for (Map<String, String> theMap : dataList) {
|
|
|
+// for (String fieldName : checkFieldList) {
|
|
|
+// if (Objects.isNull(theMap.get(fieldName))) {
|
|
|
+// checkInfoList.add(mdbTableName + "--" + fieldName + "字段不能为空!");
|
|
|
+// checkInfoVo.setCheckStatus(false);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// checkInfoVo.setCheckInfoList(checkInfoList);
|
|
|
+// if (checkInfoVo.getCheckStatus().equals(true)) {
|
|
|
+// checkInfoList.add("当前表格数据:" + mdbTableName + "---" + "数据格式为mdb");
|
|
|
+// checkInfoList.add("当前表格数据:" + mdbTableName + "---" + "检查校验通过!");
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前表格数据:" + mdbTableName + "---" + "数据格式为mdb", "info");
|
|
|
+// fzssFxrwrzHandleService.insertFxrwrz(uploadId, "地籍库管理", "当前表格数据:" + mdbTableName + "---" + "检查校验通过!", "info");
|
|
|
+// }
|
|
|
+// return checkInfoVo;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 获取当前图层的所有属性字段名
|
|
|
+// *
|
|
|
+// * @param layer
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private List<String> getFieldName(Layer layer, Boolean haveGeom) {
|
|
|
+// List<String> nameList = new ArrayList();
|
|
|
+// FeatureDefn defn = layer.GetLayerDefn();
|
|
|
+// System.out.println("字段数: " + defn.GetFieldCount());
|
|
|
+// for (int i = 0; i < defn.GetFieldCount(); i++) {
|
|
|
+// FieldDefn field = defn.GetFieldDefn(i);
|
|
|
+// nameList.add(field.GetName().toLowerCase(Locale.ROOT));
|
|
|
+// }
|
|
|
+// if (haveGeom.equals(true)) {
|
|
|
+// nameList.add("geom");
|
|
|
+// }
|
|
|
+// return nameList;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// private static final String[] DATE_PATTERNS = {
|
|
|
+// "yyyy-MM-dd HH:mm:ssX",
|
|
|
+// "yyyy-MM-dd HH:mm:ss",
|
|
|
+// "yyyy/MM/dd HH:mm:ssX",
|
|
|
+// "yyyy/MM/dd HH:mm:ss",
|
|
|
+// "yyyy-MM-dd",
|
|
|
+// "yyyy/MM/dd"
|
|
|
+// };
|
|
|
+//
|
|
|
+// private Object convertFieldValue(Feature feature, int fieldIndex, String fieldName, String fieldType) {
|
|
|
+// if (feature.IsFieldNull(fieldIndex)) {
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// String strValue = feature.GetFieldAsString(fieldIndex);
|
|
|
+// if (StringUtils.isBlank(strValue)) {
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// if (StringUtils.containsIgnoreCase(fieldType, "character") || StringUtils.containsIgnoreCase(fieldType, "text")) {
|
|
|
+// return strValue;
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "integer") || StringUtils.containsIgnoreCase(fieldType, "smallint") || StringUtils.containsIgnoreCase(fieldType, "int2") || StringUtils.containsIgnoreCase(fieldType, "int4")) {
|
|
|
+// return feature.GetFieldAsInteger(fieldIndex);
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "bigint") || StringUtils.containsIgnoreCase(fieldType, "int8")) {
|
|
|
+// return feature.GetFieldAsInteger64(fieldIndex);
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "timestamp")) {
|
|
|
+// return parseDate(strValue, fieldName);
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "date")) {
|
|
|
+// return parseDate(strValue, fieldName);
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "numeric") || StringUtils.containsIgnoreCase(fieldType, "double") || StringUtils.containsIgnoreCase(fieldType, "real")) {
|
|
|
+// return feature.GetFieldAsDouble(fieldIndex);
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "bytea") || StringUtils.containsIgnoreCase(fieldType, "blob") || StringUtils.containsIgnoreCase(fieldType, "binary")) {
|
|
|
+// return null;
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "boolean")) {
|
|
|
+// return feature.GetFieldAsInteger(fieldIndex) != 0;
|
|
|
+// } else {
|
|
|
+// return strValue;
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.warn("字段{}类型转换异常,值:{},类型:{},置空处理", fieldName, strValue, fieldType, e);
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// private java.sql.Date parseDate(String dateStr, String fieldName) {
|
|
|
+// if (StringUtils.isBlank(dateStr)) {
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// String cleaned = dateStr.trim();
|
|
|
+// for (String pattern : DATE_PATTERNS) {
|
|
|
+// try {
|
|
|
+// java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(pattern);
|
|
|
+// sdf.setLenient(false);
|
|
|
+// java.util.Date parsed = sdf.parse(cleaned);
|
|
|
+// return new java.sql.Date(parsed.getTime());
|
|
|
+// } catch (Exception ignored) {
|
|
|
+// }
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// String normalized = cleaned.replace("/", "-");
|
|
|
+// if (normalized.contains(" ") || normalized.contains("T")) {
|
|
|
+// normalized = normalized.substring(0, Math.min(normalized.indexOf(' ') > 0 ? normalized.indexOf(' ') : Integer.MAX_VALUE, normalized.indexOf('T') > 0 ? normalized.indexOf('T') : Integer.MAX_VALUE));
|
|
|
+// }
|
|
|
+// if (normalized.length() > 10) {
|
|
|
+// normalized = normalized.substring(0, 10);
|
|
|
+// }
|
|
|
+// return java.sql.Date.valueOf(normalized);
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.warn("日期字段{}解析失败,值:{},置空处理", fieldName, dateStr);
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 获取当前图层的所有字段名称和值
|
|
|
+// *
|
|
|
+// * @param layer
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private List<Map<String, Object>> getValueList(Layer layer, Map<String, String> fieldNameAndTypeMap, Boolean haveGeom) {
|
|
|
+// List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+// Integer sourceSRID = 4326;
|
|
|
+//
|
|
|
+// // ========== 1. 获取源数据坐标系 EPSG:4527 ==========
|
|
|
+// try {
|
|
|
+// SpatialReference srcSR = layer.GetSpatialRef();
|
|
|
+// if (srcSR != null) {
|
|
|
+// srcSR.AutoIdentifyEPSG();
|
|
|
+// String code = srcSR.GetAuthorityCode(null);
|
|
|
+// if (code != null) {
|
|
|
+// sourceSRID = Integer.parseInt(code);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.warn("获取图层坐标系SRID失败,使用默认4326", e);
|
|
|
+// }
|
|
|
+//
|
|
|
+// layer.ResetReading();
|
|
|
+// Feature feature;
|
|
|
+// while ((feature = layer.GetNextFeature()) != null) {
|
|
|
+// Map<String, Object> map = new LinkedHashMap<>();
|
|
|
+// for (int i = 0; i < feature.GetFieldCount(); i++) {
|
|
|
+// String fieldName = feature.GetFieldDefnRef(i).GetName();
|
|
|
+// if (fieldNameAndTypeMap.containsKey(fieldName.toLowerCase())) {
|
|
|
+// String fieldType = fieldNameAndTypeMap.get(fieldName.toLowerCase());
|
|
|
+//
|
|
|
+//
|
|
|
+///* if ("dclxtzm".equalsIgnoreCase(fieldName)) {
|
|
|
+// map.put(fieldName, "99");
|
|
|
+// }
|
|
|
+// else if ("fwjg".equalsIgnoreCase(fieldName)) {
|
|
|
+// map.put(fieldName, null);
|
|
|
+// }
|
|
|
+// else if ("jzwgd".equalsIgnoreCase(fieldName)) {
|
|
|
+// map.put(fieldName, 1);
|
|
|
+// }
|
|
|
+// else if ("ycjzmj".equalsIgnoreCase(fieldName)) {
|
|
|
+// map.put(fieldName, 1);
|
|
|
+// }
|
|
|
+// else if ("zts".equalsIgnoreCase(fieldName)) {
|
|
|
+// map.put(fieldName, 1);
|
|
|
+// }
|
|
|
+// else if ("zydmj".equalsIgnoreCase(fieldName)) {
|
|
|
+// map.put(fieldName, null);
|
|
|
+// }*/
|
|
|
+//
|
|
|
+// if ("ydyhfl".equalsIgnoreCase(fieldName)) {
|
|
|
+// map.put(fieldName, null);
|
|
|
+// }
|
|
|
+// else if (StringUtils.containsIgnoreCase(fieldType, "character")) {
|
|
|
+// map.put(fieldName, feature.GetFieldAsString(i));
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "integer") || StringUtils.containsIgnoreCase(fieldType, "smallint") || StringUtils.containsIgnoreCase(fieldType, "int2") || StringUtils.containsIgnoreCase(fieldType, "int4")) {
|
|
|
+// map.put(fieldName, feature.GetFieldAsInteger(i));
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "bigint") || StringUtils.containsIgnoreCase(fieldType, "int8")) {
|
|
|
+// map.put(fieldName, feature.GetFieldAsInteger64(i));
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "date")) {
|
|
|
+// String dateStr = feature.GetFieldAsString(i);
|
|
|
+// if (StringUtils.isNotBlank(dateStr)) {
|
|
|
+// try {
|
|
|
+// String normalized = dateStr.trim().replace("/", "-");
|
|
|
+// if (normalized.length() > 10) {
|
|
|
+// normalized = normalized.substring(0, 10);
|
|
|
+// }
|
|
|
+// map.put(fieldName, java.sql.Date.valueOf(normalized));
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.warn("日期字段{}解析失败,值:{},置空处理", fieldName, dateStr);
|
|
|
+// map.put(fieldName, null);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// map.put(fieldName, null);
|
|
|
+// }
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "numeric") || StringUtils.containsIgnoreCase(fieldType, "double") || StringUtils.containsIgnoreCase(fieldType, "real")) {
|
|
|
+// if (feature.IsFieldNull(i)) {
|
|
|
+// map.put(fieldName, null);
|
|
|
+// } else {
|
|
|
+// map.put(fieldName, feature.GetFieldAsDouble(i));
|
|
|
+// }
|
|
|
+// } else if (StringUtils.containsIgnoreCase(fieldType, "bytea") || StringUtils.containsIgnoreCase(fieldType, "blob") || StringUtils.containsIgnoreCase(fieldType, "binary")) {
|
|
|
+// map.put(fieldName, new byte[0]);
|
|
|
+// }
|
|
|
+// else {
|
|
|
+// map.put(fieldName, feature.GetFieldAsString(i));
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// //这里兼容图层可能存在多出的字段不处理
|
|
|
+// //map.put(fieldName, feature.GetFieldAsString(i));
|
|
|
+// log.warn("当前图层-{},多出字段-{}",layer.GetName(),fieldName);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (haveGeom.equals(true)) {
|
|
|
+// String ewkt = null;
|
|
|
+// Geometry geom = feature.GetGeometryRef();
|
|
|
+// if (geom != null) {
|
|
|
+// String wkt = geom.ExportToWkt();
|
|
|
+// ewkt = "SRID=" + sourceSRID + ";" + wkt;
|
|
|
+// ewkt = this.transforGeomTo4326(ewkt);
|
|
|
+// }
|
|
|
+// map.put("geom", ewkt);
|
|
|
+// }
|
|
|
+// list.add(map);
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 校验当前图层坐标系是否为:CGCS2000
|
|
|
+// *
|
|
|
+// * @param layer
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private Boolean checkCoordinateSystem(Layer layer) {
|
|
|
+// boolean isCGCS2000 = false;
|
|
|
+// SpatialReference sr = layer.GetSpatialRef();
|
|
|
+// if (sr != null) {
|
|
|
+// String wkt = sr.ExportToWkt();
|
|
|
+// log.info("当前图层{},wkt为:{}", layer.GetName(), wkt);
|
|
|
+// // 判断 WKT 是否包含 "CGCS2000"
|
|
|
+// if (wkt.contains("CGCS2000")) {
|
|
|
+// isCGCS2000 = true;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return isCGCS2000;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 校验当前图层是否存在矢量数据
|
|
|
+// *
|
|
|
+// * @param layer
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private Boolean checkHaveGeom(Layer layer) {
|
|
|
+// boolean haveGeom = false;
|
|
|
+// // 循环处理每个要素
|
|
|
+// for (int i = 0; i < layer.GetFeatureCount(0); i++) {
|
|
|
+// Feature feature = layer.GetFeature(i);
|
|
|
+// if (feature == null) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// Geometry geometry = feature.GetGeometryRef(); // 获取几何对象
|
|
|
+// if (geometry != null) {
|
|
|
+// // 将几何对象转换为 WKT 格式
|
|
|
+// String wkt = geometry.ExportToWkt();
|
|
|
+// if (StringUtils.isNotBlank(wkt)) {
|
|
|
+// haveGeom = true;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return haveGeom;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 获取对比的矢量图层
|
|
|
+// *
|
|
|
+// * @param layer
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private List<String> getLayerGeom(Layer layer) {
|
|
|
+// List<String> list = new ArrayList<>();
|
|
|
+// SpatialReference srcSrs = layer.GetSpatialRef();
|
|
|
+// Integer srid = null;
|
|
|
+// if (srcSrs != null) {
|
|
|
+// String authCode = srcSrs.GetAuthorityCode(null);
|
|
|
+// if (authCode != null) {
|
|
|
+// srid = Integer.parseInt(authCode);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (srid == null) {
|
|
|
+// srid = 4527;
|
|
|
+// }
|
|
|
+//
|
|
|
+// layer.ResetReading();
|
|
|
+// Feature feature;
|
|
|
+// while ((feature = layer.GetNextFeature()) != null) {
|
|
|
+// Geometry geom = feature.GetGeometryRef();
|
|
|
+// if (geom == null) {
|
|
|
+// list.add("");
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// String wkt = geom.ExportToWkt();
|
|
|
+// String ewkt = "SRID=" + srid + ";" + wkt;
|
|
|
+// ewkt = this.transforGeomTo4326(ewkt);
|
|
|
+// list.add(ewkt);
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 获取对比的矢量图层
|
|
|
+// *
|
|
|
+// * @param layer
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private List<String> getLayerGeom_del(Layer layer) {
|
|
|
+// List<String> list = new ArrayList<>();
|
|
|
+// // 循环处理每个要素
|
|
|
+// for (int i = 0; i < layer.GetFeatureCount(0); i++) {
|
|
|
+// Feature feature = layer.GetFeature(i);
|
|
|
+// if (feature == null) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// Geometry geometry = feature.GetGeometryRef(); // 获取几何对象
|
|
|
+// if (geometry != null) {
|
|
|
+// // 将几何对象转换为 WKT 格式
|
|
|
+// String wkt = geometry.ExportToWkt();
|
|
|
+// list.add(wkt);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// *
|
|
|
+// * @param tableName
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private List<String> getDbGeom(String tableName) {
|
|
|
+// List<String> list = new ArrayList<>();
|
|
|
+// String geomsStr = cadastreFileMapper.selectGeoms(tableName);
|
|
|
+// if (StringUtils.isNotBlank(geomsStr)) {
|
|
|
+// list = Arrays.asList(geomsStr.split("\\|"));
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 这里需要开启事务
|
|
|
+// * 数据全量入库
|
|
|
+// *
|
|
|
+// * @param tableName
|
|
|
+// * @param theValueList
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+// public Boolean fullDataStorage(String tableName, List<Map<String, Object>> theValueList) {
|
|
|
+// boolean addRes = false;
|
|
|
+// Integer shpDbSRID = 4326;
|
|
|
+// if (!CollectionUtils.isEmpty(theValueList)) {
|
|
|
+// //先删除数据
|
|
|
+// cadastreFileMapper.deleteByValidFlag("1", tableName);
|
|
|
+// //先把当前版本都修改为历史版本
|
|
|
+// cadastreFileMapper.updateValidFlag("1", "0", tableName);
|
|
|
+// for (Map<String, Object> map : theValueList) {
|
|
|
+//// Collection<Object> values = map.values();
|
|
|
+//// Collection<String> keys = map.keySet();
|
|
|
+// map.put("valid_flag", 0);//有效数据标识
|
|
|
+// cadastreFileMapper.insertTableData(tableName, map, shpDbSRID);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return addRes;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 判断两个Map中的数据是否完全一致(排除geom字段的比较方式,或根据业务需求处理)
|
|
|
+// */
|
|
|
+// private boolean isSameData(Map<String, Object> map1, Map<String, Object> map2) {
|
|
|
+// if (map1 == map2) return true;
|
|
|
+// if (map1 == null || map2 == null) return false;
|
|
|
+//
|
|
|
+// // 比较两个map的交集字段(排除valid_flag)
|
|
|
+// Set<String> keys1 = new HashSet<>(map1.keySet());
|
|
|
+// Set<String> keys2 = new HashSet<>(map2.keySet());
|
|
|
+// keys1.retainAll(keys2); // 取交集
|
|
|
+// if (keys1.isEmpty()) return false;
|
|
|
+//
|
|
|
+// for (String field : keys1) {
|
|
|
+// if ("valid_flag".equalsIgnoreCase(field)) {
|
|
|
+// continue; // 忽略版本标识
|
|
|
+// }
|
|
|
+// Object val1 = map1.get(field);
|
|
|
+// Object val2 = map2.get(field);
|
|
|
+//
|
|
|
+// if (val1 == null && val2 == null) continue;
|
|
|
+// if (val1 == null || val2 == null) return false;
|
|
|
+//
|
|
|
+// // 特殊处理geom字段:以字符串比较,去掉空白
|
|
|
+// if ("geom".equalsIgnoreCase(field)) {
|
|
|
+// String s1 = String.valueOf(val1).trim();
|
|
|
+// String s2 = String.valueOf(val2).trim();
|
|
|
+// if (!s1.equals(s2)) {
|
|
|
+// return false;
|
|
|
+// } else {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 数值类型比较
|
|
|
+// if (val1 instanceof Number && val2 instanceof Number) {
|
|
|
+// if (Double.compare(((Number) val1).doubleValue(), ((Number) val2).doubleValue()) != 0) {
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 尝试将字符串数字与数字类型做比较(例如数据库返回Integer/String混合)
|
|
|
+// if (val1 instanceof Number && val2 instanceof String) {
|
|
|
+// try {
|
|
|
+// double d2 = Double.parseDouble(((String) val2).trim());
|
|
|
+// if (Double.compare(((Number) val1).doubleValue(), d2) != 0) return false;
|
|
|
+// else continue;
|
|
|
+// } catch (Exception ignored) {
|
|
|
+// // fallthrough to string compare
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (val2 instanceof Number && val1 instanceof String) {
|
|
|
+// try {
|
|
|
+// double d1 = Double.parseDouble(((String) val1).trim());
|
|
|
+// if (Double.compare(((Number) val2).doubleValue(), d1) != 0) return false;
|
|
|
+// else continue;
|
|
|
+// } catch (Exception ignored) {
|
|
|
+// // fallthrough to string compare
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 默认字符串比较(去除首尾空白)
|
|
|
+// if (!String.valueOf(val1).trim().equals(String.valueOf(val2).trim())) {
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// return true;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 这里需要开启事务
|
|
|
+// * 数据增量入库
|
|
|
+// *
|
|
|
+// * @param tableName
|
|
|
+// * @param theValueList
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+// public Boolean incrementDataStorage(String tableName, List<Map<String, Object>> theValueList) {
|
|
|
+// /**
|
|
|
+// * 1。查询出当前表所有数据。
|
|
|
+// * 2.修改当前数据的valid_flag为1,表示历史版本
|
|
|
+// * 3.把当前数据和数据库数据进行对比,获取新增数据和修改数据。
|
|
|
+// * 4.新增数据直接插入,修改数据根据主键进行更新。
|
|
|
+// * 任务标识码相同,并且geom数据有相交则认为数据相同。
|
|
|
+// */
|
|
|
+// boolean addRes = false;
|
|
|
+// Integer shpDbSRID = 4326;
|
|
|
+// if (!CollectionUtils.isEmpty(theValueList)) {
|
|
|
+// //先删除数据
|
|
|
+// cadastreFileMapper.deleteByValidFlag("1", tableName);
|
|
|
+// //查询出当前表所有数据。
|
|
|
+// List<Map<String, Object>> dbDataList = cadastreFileMapper.selectTableData("0", tableName);
|
|
|
+// //筛选出需要更新的数据
|
|
|
+// List<Map<String, Object>> dbExistsList = new ArrayList<>();
|
|
|
+// for (Map<String, Object> map : theValueList) {
|
|
|
+// Map<String, Object> dbExistsMap = cadastreFileMapper.selectExistsSameData("0", map, tableName);
|
|
|
+// if (MapUtils.isNotEmpty(dbExistsMap)) {
|
|
|
+// dbExistsList.add(dbExistsMap);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 在dbDataList 中找出 dbExistsMap中各个字段完全一致的数据 并从dbDataList移除
|
|
|
+// if (CollectionUtils.isNotEmpty(dbExistsList)) {
|
|
|
+// for (Map<String, Object> dbExistsMap : dbExistsList) {
|
|
|
+// dbDataList.removeIf(dbData -> isSameData(dbData, dbExistsMap));
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// //这里合并两个list 最终写入数据表
|
|
|
+// if (CollectionUtils.isNotEmpty(dbDataList)) {
|
|
|
+// theValueList.addAll(dbDataList);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //先把当前版本都修改为历史版本
|
|
|
+// cadastreFileMapper.updateValidFlag("1", "0", tableName);
|
|
|
+// for (Map<String, Object> map : theValueList) {
|
|
|
+// map.put("valid_flag", 0);//有效数据标识
|
|
|
+// cadastreFileMapper.insertTableData(tableName, map, shpDbSRID);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return addRes;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 获取列表
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public Map<String, Object> list(CadastreFileFilterVo cadastreFileFilterVo) {
|
|
|
+// List<CadastreFile> list = cadastreFileMapper.getListByFilter(cadastreFileFilterVo);
|
|
|
+// int count = cadastreFileMapper.getCountByFilter(cadastreFileFilterVo);
|
|
|
+// Map<String, Object> map = new HashMap<>();
|
|
|
+// map.put("rows", list);
|
|
|
+// map.put("total", count);
|
|
|
+// return map;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 批量删除
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// @Transactional(rollbackFor = Exception.class)
|
|
|
+// public void batchDelete(List<String> ids) {
|
|
|
+// if (ids == null || ids.isEmpty()) {
|
|
|
+// throw new IllegalArgumentException("IDs list cannot be null or empty");
|
|
|
+// }
|
|
|
+// cadastreFileMapper.batchDelete(ids);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// @Transactional(rollbackFor = Exception.class)
|
|
|
+// public void testRun() {
|
|
|
+// //这里批量增修改表结构增加校验字段:
|
|
|
+// String[] arr = new String[]{
|
|
|
+// "tdgy_jh",
|
|
|
+// "tdjyq",
|
|
|
+// "TB_TDGY_SJ",
|
|
|
+// "t_cgzj_cwtc_m",
|
|
|
+// "t_cgzj_cwtc_m_bak1",
|
|
|
+// "t_cgzj_cwtc_m_copy1",
|
|
|
+// "public_dict",
|
|
|
+// "spatial_ref_sys"
|
|
|
+// };
|
|
|
+//
|
|
|
+// //获取库中表名
|
|
|
+// //List<String> allTableList = cadastreFileMapper.selectAllTable();
|
|
|
+// List<String> allTableList = cadastreFileMapper.selectAllTableNoView();
|
|
|
+// allTableList.removeAll(Arrays.asList(arr));
|
|
|
+//
|
|
|
+// // 对每个表名执行添加校验字段的操作
|
|
|
+// for (String tableName : allTableList) {
|
|
|
+// System.out.println("正在处理表: " + tableName);
|
|
|
+// cadastreFileMapper.addValidFlagColumn(tableName);
|
|
|
+// System.out.println("正在处理表: " + tableName + " 完成");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+// @Override
|
|
|
+// public String backToOldData(String uploadId) {
|
|
|
+// try {
|
|
|
+// CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
+// if (!"1".equals(cadastreFile.getStatus())) {
|
|
|
+// throw new ServiceException("可能未入库成功,无法回退");
|
|
|
+// }
|
|
|
+//
|
|
|
+// List<String> fileTableNameList = new ArrayList<>();
|
|
|
+// if ("1".equals(cadastreFile.getFileType())) {//矢量数据
|
|
|
+// fileTableNameList = getLayerNameList(uploadId);
|
|
|
+// } else if ("2".equals(cadastreFile.getFileType())) { //表格数据
|
|
|
+// fileTableNameList = getMdbTableNameList(uploadId);
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (String layerName : fileTableNameList) {
|
|
|
+// //校验是否都有历史版本
|
|
|
+// Integer count = cadastreFileMapper.countByValidFlag("1", layerName.toLowerCase(Locale.ROOT));
|
|
|
+// if (count == 0) {
|
|
|
+// throw new ServiceException("表" + layerName + "没有历史版本,无法回退");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (String layerName : fileTableNameList) {
|
|
|
+//
|
|
|
+// cadastreFileMapper.deleteByValidFlag("0", layerName.toLowerCase(Locale.ROOT));
|
|
|
+// cadastreFileMapper.updateValidFlag("0", "1", layerName.toLowerCase(Locale.ROOT));
|
|
|
+// log.info("正在回退表:{}。。。", layerName);
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("数据回退异常,uploadId: {}", uploadId, e);
|
|
|
+// throw new ServiceException("数据回退异常," + e.getMessage());
|
|
|
+// }
|
|
|
+//
|
|
|
+//// //成功则更新状态
|
|
|
+//// CadastreFile updateCadastreFile = new CadastreFile();
|
|
|
+//// updateCadastreFile.setId(uploadId);
|
|
|
+//// updateCadastreFile.setStatus("4");//已经回退
|
|
|
+//// updateCadastreFile.setReadMessage("已经回退");//校验通过
|
|
|
+//// cadastreFileMapper.update(updateCadastreFile);
|
|
|
+// return "当前批次数据已回退到上一个版本!:" + uploadId;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 获取图层名称列表
|
|
|
+// *
|
|
|
+// * @param uploadId
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public List<String> getLayerNameList(String uploadId) {
|
|
|
+// List<String> nameList = new ArrayList<>();
|
|
|
+// CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
+// String gdbPath = cadastreFile.getUnzipPath();
|
|
|
+// DataSource ds = ogr.Open(gdbPath + "/" + cadastreFile.getName(), 0); // 0 = 只读
|
|
|
+// if (ds == null) {
|
|
|
+// throw new ServiceException("无法打开 gdb");
|
|
|
+// }
|
|
|
+// //这里进行遍历每个图层
|
|
|
+// for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
+// Layer layer = ds.GetLayer(i);
|
|
|
+// String layerName = layer.GetName();
|
|
|
+// nameList.add(layerName);
|
|
|
+// }
|
|
|
+// return nameList;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// *
|
|
|
+// * 获取mdb文件中表名称
|
|
|
+// *
|
|
|
+// * @param uploadId
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public List<String> getMdbTableNameList(String uploadId) throws Exception {
|
|
|
+// List<String> nameList = new ArrayList<>();
|
|
|
+// CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
+// String gdbPath = cadastreFile.getUnzipPath();
|
|
|
+// List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + cadastreFile.getName(), "", "");
|
|
|
+// for (Map<String, Object> tableMap : allMdbTableList) {
|
|
|
+// String talbleName = String.valueOf(tableMap.get("name"));
|
|
|
+// nameList.add(talbleName);
|
|
|
+// }
|
|
|
+// return nameList;
|
|
|
+// }
|
|
|
+//
|
|
|
+// //1.获取图层中所有数据
|
|
|
+// //2.获取库中所有数据
|
|
|
+// //3.进行对比返回
|
|
|
+// @Override
|
|
|
+// public List<LayerAndDbData> getLayerData(String uploadId) {
|
|
|
+// List<LayerAndDbData> resList = new ArrayList<>();
|
|
|
+// try {
|
|
|
+// CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
+// //这里判断是否校验通过
|
|
|
+// if (!cadastreFile.getStatus().equalsIgnoreCase("3")) {
|
|
|
+// log.info("校验未通过,不能入库");
|
|
|
+// throw new ServiceException("校验未通过,不能入库");
|
|
|
+// }
|
|
|
+// String gdbPath = cadastreFile.getUnzipPath();
|
|
|
+// DataSource ds = ogr.Open(gdbPath + "/" + cadastreFile.getName(), 0); // 0 = 只读
|
|
|
+// if (ds == null) {
|
|
|
+// log.warn("无法打开 gdb");
|
|
|
+// throw new ServiceException("无法打开 gdb");
|
|
|
+// }
|
|
|
+// //这里进行遍历每个图层
|
|
|
+// for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
+// Layer layer = ds.GetLayer(i);
|
|
|
+// String layerName = layer.GetName();
|
|
|
+// LayerAndDbData layerAndDbData = new LayerAndDbData();
|
|
|
+// layerAndDbData.setCurrentTableName(layerName);
|
|
|
+//
|
|
|
+// boolean haveGeom = false;//这里不需要geom信息
|
|
|
+// List<Map<String, String>> dbFieldNameAndTypeList = cadastreFileMapper.selectTableCollumAndType(layerName.toLowerCase(Locale.ROOT));
|
|
|
+// Map<String, String> dbFieldNameAndTypeMap = dbFieldNameAndTypeList.stream().collect(Collectors.toMap(
|
|
|
+// s -> s.get("column_name"),
|
|
|
+// s -> s.get("data_type"),
|
|
|
+// (existing, replacement) -> existing // 如果有重复键,保留第一个值
|
|
|
+// ));
|
|
|
+// List<Map<String, Object>> theValueList = getValueList(layer, dbFieldNameAndTypeMap, haveGeom);
|
|
|
+// List<Map<String, Object>> dbDataList = cadastreFileMapper.selectTableData("0", layerName);
|
|
|
+//
|
|
|
+// layerAndDbData.setAddTotalNum(theValueList.size());
|
|
|
+// layerAndDbData.setInsertNum(theValueList.size());
|
|
|
+// layerAndDbData.setMarkHistoryNum(dbDataList.size());
|
|
|
+// layerAndDbData.setInsertDataList(theValueList);
|
|
|
+// layerAndDbData.setMarkHistoryDataList(dbDataList);
|
|
|
+// resList.add(layerAndDbData);
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("矢量数据入库异常,uploadId: {}", uploadId, e);
|
|
|
+// throw new ServiceException("矢量数据入库异常," + e.getMessage());
|
|
|
+// }
|
|
|
+//
|
|
|
+// return resList;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 获取表格数据进行对比
|
|
|
+// *
|
|
|
+// * @param uploadId
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public List<LayerAndDbData> getMdbPropertyData(String uploadId) {
|
|
|
+// List<LayerAndDbData> resList = new ArrayList<>();
|
|
|
+// try {
|
|
|
+// CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
+// //这里判断是否校验通过
|
|
|
+// if (!cadastreFile.getStatus().equalsIgnoreCase("3")) {
|
|
|
+// log.info("校验未通过,不能入库");
|
|
|
+// throw new ServiceException("校验未通过,不能入库");
|
|
|
+// }
|
|
|
+// String gdbPath = cadastreFile.getUnzipPath();
|
|
|
+// List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + cadastreFile.getName(), "", "");
|
|
|
+//
|
|
|
+// for (Map<String, Object> tableMap : allMdbTableList) {
|
|
|
+// String talbleName = String.valueOf(tableMap.get("name"));
|
|
|
+// LayerAndDbData layerAndDbData = new LayerAndDbData();
|
|
|
+// layerAndDbData.setCurrentTableName(talbleName);
|
|
|
+//
|
|
|
+// Map<String, Object> allMdbTableFieldMap = MdbUtil.MdbTableContent(gdbPath + "/" + cadastreFile.getName(), talbleName, "", "", 1, 1000);
|
|
|
+// List<Map<String, Object>> theValueList = (List<Map<String, Object>>) allMdbTableFieldMap.get("rows");
|
|
|
+// List<Map<String, Object>> dbDataList = cadastreFileMapper.selectTableData("0", talbleName);
|
|
|
+//
|
|
|
+// layerAndDbData.setAddTotalNum(theValueList.size());
|
|
|
+// layerAndDbData.setInsertNum(theValueList.size());
|
|
|
+// layerAndDbData.setMarkHistoryNum(dbDataList.size());
|
|
|
+// layerAndDbData.setInsertDataList(theValueList);
|
|
|
+// layerAndDbData.setMarkHistoryDataList(dbDataList);
|
|
|
+// resList.add(layerAndDbData);
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("矢量数据入库异常,uploadId: {}", uploadId, e);
|
|
|
+// throw new ServiceException("矢量数据入库异常," + e.getMessage());
|
|
|
+// }
|
|
|
+// return resList;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<MdbAndDbData> getMdbCompareData(String uploadId) {
|
|
|
+// List<MdbAndDbData> resList = new ArrayList<>();
|
|
|
+// try {
|
|
|
+// CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
+// //这里判断是否校验通过
|
|
|
+// if (!cadastreFile.getStatus().equalsIgnoreCase("3")) {
|
|
|
+// log.info("校验未通过,不能入库");
|
|
|
+// throw new ServiceException("校验未通过,不能入库");
|
|
|
+// }
|
|
|
+// String gdbPath = cadastreFile.getUnzipPath();
|
|
|
+// List<Map<String, Object>> allMdbTableList = MdbUtil.MdbTables(gdbPath + "/" + cadastreFile.getName(), "", "");
|
|
|
+//
|
|
|
+// for (Map<String, Object> tableMap : allMdbTableList) {
|
|
|
+// String talbleName = String.valueOf(tableMap.get("name"));
|
|
|
+// MdbAndDbData mdbAndDbData = new MdbAndDbData();
|
|
|
+// mdbAndDbData.setCurrentTableName(talbleName);
|
|
|
+// List<Map<String, String>> dbFieldNameAndTypeList = cadastreFileMapper.selectTableCollumAndType(talbleName.toLowerCase(Locale.ROOT));
|
|
|
+// Map<String, String> dbFieldNameAndTypeMap = dbFieldNameAndTypeList.stream().collect(Collectors.toMap(
|
|
|
+// s -> s.get("column_name"),
|
|
|
+// s -> s.get("data_type"),
|
|
|
+// (existing, replacement) -> existing // 如果有重复键,保留第一个值
|
|
|
+// ));
|
|
|
+//
|
|
|
+// Map<String, Object> allMdbTableFieldMap = MdbUtil.MdbTableContent(gdbPath + "/" + cadastreFile.getName(), talbleName, "", "", 1, 1000);
|
|
|
+// List<Map<String, Object>> theValueList = (List<Map<String, Object>>) allMdbTableFieldMap.get("rows");
|
|
|
+// List<Map<String, Object>> dbDataList = cadastreFileMapper.selectTableData("0", talbleName);
|
|
|
+//
|
|
|
+// //这里进行遍历dbDataList,判断是否存在bsm字段,且bsm字段是否存在于theValueList中
|
|
|
+// Set<String> mdbBsmSet = theValueList.stream()
|
|
|
+// .map(v -> v.get("bsm".toUpperCase(Locale.ROOT)))
|
|
|
+// .filter(bsm -> bsm != null)
|
|
|
+// .map(String::valueOf)
|
|
|
+// .collect(Collectors.toSet());
|
|
|
+//
|
|
|
+// dbDataList.stream()
|
|
|
+// .filter(dbData -> {
|
|
|
+// Object bsmObj = dbData.get("bsm");
|
|
|
+// return bsmObj != null && mdbBsmSet.contains(String.valueOf(bsmObj));
|
|
|
+// })
|
|
|
+// .forEach(dbData -> dbData.put("valid_flag", 100));
|
|
|
+//
|
|
|
+// mdbAndDbData.setMdbFileDataList(theValueList);
|
|
|
+// mdbAndDbData.setDbDataList(dbDataList);
|
|
|
+// resList.add(mdbAndDbData);
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("获取mdb对比数据异常,uploadId: {}", uploadId, e);
|
|
|
+// throw new ServiceException("获取mdb对比数据异常," + e.getMessage());
|
|
|
+// }
|
|
|
+// return resList;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<Map<String,Object>> selectTableRow(String tableName,String geomFlag,String bsm,String ywh) {
|
|
|
+// String validFlag = "0";
|
|
|
+// if(Arrays.asList("tf_500", "tf_1000", "tf_2000","zd_shp").contains(tableName)){
|
|
|
+// validFlag = "";
|
|
|
+// }
|
|
|
+// if(StringUtils.isNotEmpty(bsm)){
|
|
|
+// bsm = bsm.trim();
|
|
|
+// }
|
|
|
+// if(StringUtils.isNotEmpty(ywh)){
|
|
|
+// ywh = ywh.trim();
|
|
|
+// }
|
|
|
+// if (ywh.matches(".*=\\d+")) {
|
|
|
+// ywh = ywh.replaceAll("=(\\d+)", "='$1'");
|
|
|
+// }
|
|
|
+// List<Map<String,Object>> res = cadastreFileMapper.selectTableDataByCondition(validFlag,tableName,bsm,ywh);
|
|
|
+// if(CollectionUtils.isNotEmpty(res)){ //去掉geom字段和valid_flag字段
|
|
|
+// List<Map<String, String>> dbFieldNameAndTypeList = cadastreFileMapper.selectTableCollumAndType(tableName.toLowerCase(Locale.ROOT));
|
|
|
+// List<Object> filterCollumList = dbFieldNameAndTypeList.stream().filter(s->s.get("data_type").equals("bytea")).map(s->s.get("column_name")).collect(Collectors.toList());
|
|
|
+// filterCollumList.add("valid_flag");
|
|
|
+// //res.forEach(m -> m.keySet().removeIf(k -> "valid_flag".equalsIgnoreCase(k)));
|
|
|
+// res.forEach(m -> m.keySet().removeIf(filterCollumList::contains));
|
|
|
+// if("0".equals(geomFlag)){
|
|
|
+// res.forEach(m -> m.keySet().removeIf("geom"::equalsIgnoreCase));
|
|
|
+// }
|
|
|
+// res.forEach(s -> {
|
|
|
+// if(s.get("geom") != null){
|
|
|
+// WKBReader reader = new WKBReader();
|
|
|
+// org.locationtech.jts.geom.Geometry geom = null;
|
|
|
+// try {
|
|
|
+// geom = reader.read(WKBReader.hexToBytes(s.get("geom").toString()));
|
|
|
+// } catch (ParseException e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// }
|
|
|
+// //geom.setSRID(4490);
|
|
|
+// WKTWriter writer = new WKTWriter();
|
|
|
+// String ewkt = "SRID=" + "4326" + ";" + writer.write(geom);
|
|
|
+// s.put("geom", ewkt);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
+// return res;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<String> getTableFields(String tableName) {
|
|
|
+// List<String> res = cadastreFileMapper.selectTableCollum(tableName);
|
|
|
+// res.remove("valid_flag");
|
|
|
+// res.remove("geom");
|
|
|
+// return res;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<String> getDistinctValueByField(String tableName,String fieldName) {
|
|
|
+// List<String> res = new ArrayList<>();
|
|
|
+// String validFlag =null;
|
|
|
+// List<String> collumList = cadastreFileMapper.selectTableCollum(tableName);
|
|
|
+// if(!collumList.contains(fieldName)){
|
|
|
+// return res;
|
|
|
+// }
|
|
|
+// if(collumList.contains("valid_flag")){
|
|
|
+// validFlag = "0";
|
|
|
+// }
|
|
|
+// res = cadastreFileMapper.selectDistinctValueByField(tableName,fieldName,validFlag);
|
|
|
+// return res;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public String tableRowUpdate(String tableName, List<Map<String,Object>> list) {
|
|
|
+// for (Map<String, Object> row : list) {
|
|
|
+// row.replaceAll((k, v) -> {
|
|
|
+// if (v instanceof String) {
|
|
|
+// String sv = (String) v;
|
|
|
+// try {
|
|
|
+// return new java.math.BigDecimal(sv);
|
|
|
+// } catch (NumberFormatException e) {
|
|
|
+// return v;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return v;
|
|
|
+// });
|
|
|
+// }
|
|
|
+// int res = cadastreFileMapper.batchUpdateByBsm(tableName,list);
|
|
|
+// return res+"";
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public String batchDeleteByBsm(String tableName, List<Map<String,Object>> list) {
|
|
|
+// int res = cadastreFileMapper.batchDeleteByBsm(tableName,list);
|
|
|
+// return res+"";
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<Map<String, Object>> getDataByName(String tableName) {
|
|
|
+// Map<String, Object> map = cadastreFileMapper.selectTableDataByBsm(tableName, "");
|
|
|
+// List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+// list.add(map);
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<Map<String, Object>> selectTableRowExcel(String tableName, String geomFlag, List<Object> bsmList, List<String> ywhList) {
|
|
|
+// List<Map<String, Object>> res = cadastreFileMapper.selectTableRowExcel(tableName, geomFlag, bsmList, ywhList);
|
|
|
+// if(CollectionUtils.isNotEmpty(res)) { //去掉geom字段和valid_flag字段
|
|
|
+// res.forEach(m -> m.keySet().removeIf(k -> "valid_flag".equalsIgnoreCase(k)));
|
|
|
+// if ("0".equals(geomFlag)) {
|
|
|
+// res.forEach(m -> m.keySet().removeIf(k -> "geom".equalsIgnoreCase(k)));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return res;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Boolean checkQueryWhere(String tableName, String queryWhere) {
|
|
|
+// try {
|
|
|
+// if (queryWhere.matches(".*=\\d+")) {
|
|
|
+// queryWhere = queryWhere.replaceAll("=(\\d+)", "='$1'");
|
|
|
+// }
|
|
|
+// String res = cadastreFileMapper.checkQueryWhere(tableName, queryWhere);
|
|
|
+// log.info("SQL语法检查结果,res: {}", res);
|
|
|
+// return true;
|
|
|
+// } catch (Exception e) {
|
|
|
+// throw new ServiceException("SQL语法检查异常:");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// *
|
|
|
+// * 生成一个mdb文件
|
|
|
+// *
|
|
|
+// * @param tableName
|
|
|
+// * @param filePath
|
|
|
+// * @param fileName
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public void testBuildMdbFile(String tableName, String filePath, String fileName) {
|
|
|
+// try {
|
|
|
+// // 1. 获取表字段及类型信息
|
|
|
+// List<Map<String, String>> columns = cadastreFileMapper.selectTableCollumAndType(tableName);
|
|
|
+// if (columns == null || columns.isEmpty()) {
|
|
|
+// log.warn("无法获取表字段信息: {}", tableName);
|
|
|
+// throw new ServiceException("无法获取表字段信息: "+tableName);
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(columns.stream().anyMatch(s->s.get("column_name").equals("geom"))){
|
|
|
+// log.warn("当前为矢量数据,无法生成mdb: {}", tableName);
|
|
|
+// throw new ServiceException("当前为矢量数据,无法生成mdb");
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 2. 获取表数据 (获取 valid_flag 为 0 的当前版本数据)
|
|
|
+// List<Map<String, Object>> dataList = cadastreFileMapper.selectTableData("", tableName);
|
|
|
+//
|
|
|
+// // 3. 构造完整的文件路径
|
|
|
+// String mdbPath = filePath;
|
|
|
+// if (!mdbPath.endsWith(File.separator)) {
|
|
|
+// mdbPath += File.separator;
|
|
|
+// }
|
|
|
+// mdbPath += fileName;
|
|
|
+// if (!mdbPath.toLowerCase().endsWith(".mdb")) {
|
|
|
+// mdbPath += ".mdb";
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 4. 调用工具类生成 MDB 文件并写入数据
|
|
|
+// MdbUtil.writeMdbByTable(mdbPath, tableName, columns, dataList);
|
|
|
+//
|
|
|
+// log.info("MDB 文件生成成功: {}", mdbPath);
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("生成 MDB 文件失败: {}", tableName, e);
|
|
|
+// throw new ServiceException("生成 MDB 文件失败: " + e.getMessage());
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 4527坐标系转换为4326坐标系
|
|
|
+// * @param ewkt
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// private String transforGeomTo4326(String ewkt) {
|
|
|
+// if(StringUtils.isBlank(ewkt)){
|
|
|
+// return "";
|
|
|
+// }
|
|
|
+// return cadastreFileMapper.transformTo4326(ewkt);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//}
|