|
@@ -16,7 +16,6 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.gdal.ogr.*;
|
|
import org.gdal.ogr.*;
|
|
|
-import org.gdal.osr.CoordinateTransformation;
|
|
|
|
|
import org.gdal.osr.SpatialReference;
|
|
import org.gdal.osr.SpatialReference;
|
|
|
import org.locationtech.jts.io.ParseException;
|
|
import org.locationtech.jts.io.ParseException;
|
|
|
import org.locationtech.jts.io.WKBReader;
|
|
import org.locationtech.jts.io.WKBReader;
|
|
@@ -59,6 +58,133 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
private FzssFxrwrzMapper fzssFxrwrzMapper;
|
|
private FzssFxrwrzMapper fzssFxrwrzMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解压文件并且根据情况进行拆分或合并的处理
|
|
|
|
|
+ * @param theFileName 上传文件名
|
|
|
|
|
+ * @param theFilePath 文件路径
|
|
|
|
|
+ * @param landRightType 宗地权利类型
|
|
|
|
|
+ * @param landChangeMode 宗地变更模式
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String addLandChange(String theFileName, String theFilePath, String landRightType,String landChangeMode) {
|
|
|
|
|
+ String result = "success";
|
|
|
|
|
+ /**
|
|
|
|
|
+ *
|
|
|
|
|
+ * 1.必须要上产并解压文件,保证一个gdb文件,并且保证文件名与表名称对应
|
|
|
|
|
+ * 2.字段校验权利类型是否正确
|
|
|
|
|
+ * 3.能够获取到相关数据,并且数据都合规。
|
|
|
|
|
+ * 4.无日志,无对比文件,直接入库,返回变化和变更多少条
|
|
|
|
|
+ *
|
|
|
|
|
+ *
|
|
|
|
|
+ *
|
|
|
|
|
+ */
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (StringUtils.isBlank(theFilePath)) {
|
|
|
|
|
+ log.warn("处理文件失败:filePath不能为空");
|
|
|
|
|
+ throw new ServiceException("处理文件失败:filePath不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ Path currentFilePath = Paths.get(theFilePath);
|
|
|
|
|
+ if (!Files.exists(currentFilePath)) {
|
|
|
|
|
+ log.warn("处理文件失败:文件不存在: {}", theFilePath);
|
|
|
|
|
+ throw new ServiceException("处理文件失败:文件不存在:"+theFilePath);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断是否为压缩文件
|
|
|
|
|
+ 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;
|
|
|
|
|
+ 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格式矢量数据,请检查重新上传");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // -----------------第二部分遍历图层进行质量检查 -------------------------------
|
|
|
|
|
+ DataSource ds = ogr.Open(unZipPath + "/" + theFileName, 0); // 0 = 只读
|
|
|
|
|
+ if (ds == null) {
|
|
|
|
|
+ log.warn("无法打开 gdb");
|
|
|
|
|
+ result = "无法打开gdb文件,不能入库";
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String tableName = "zdjbxx";
|
|
|
|
|
+ if(ds.GetLayerCount()!=1){
|
|
|
|
|
+ throw new ServiceException("当前gdb文件,仅仅支持一个图层,并且图层名称应为("+tableName+")");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Layer layer = ds.GetLayer(0);
|
|
|
|
|
+ String name = layer.GetName();
|
|
|
|
|
+ //检查表名对应
|
|
|
|
|
+ if (!name.equalsIgnoreCase(tableName)) {
|
|
|
|
|
+ throw new ServiceException("当前gdb文件,图层名称不对,图层名称应为("+tableName+")");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //检查坐标系
|
|
|
|
|
+ if (checkCoordinateSystem(layer).equals(false)) {
|
|
|
|
|
+ throw new ServiceException(name + ":坐标系不正确,确认是否CGCS2000!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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) {
|
|
|
|
|
+ throw new ServiceException(name + ":字段数据不一致!-" + dbFieldNameList);
|
|
|
|
|
+ }
|
|
|
|
|
+ // -----------------第三部分遍历图层进行数据处理 -------------------------------
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("矢量数据入库异常,uploadId: {}", "", e);
|
|
|
|
|
+ throw new ServiceException("矢量数据入库异常," + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* 解析文件内容,insert 到表中
|
|
* 解析文件内容,insert 到表中
|