Forráskód Böngészése

不动产数据获取字段优化(入库更新2)

chenendian 2 napja
szülő
commit
c074796654

+ 18 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/cadastre/CadastreManageController.java

@@ -48,6 +48,24 @@ public class CadastreManageController extends BaseController {
     private IZymlService zymlService;
 
 
+    /**
+     * 宗地变化情况表
+     * @param theFileName
+     * @param theFilePath
+     * @param landRightType
+     * @param landChangeMode
+     * @return
+     */
+    @PostMapping("/addLandChangeData")
+    public R<String> landChange(String theFileName, String theFilePath, String landRightType, String landChangeMode) {
+        try {
+            String res = cadastreManageService.addLandChange(theFileName, theFilePath, landRightType, landChangeMode);
+            return R.ok("success");
+        } catch (Exception e) {
+            e.printStackTrace();
+            return R.fail(e.getMessage());
+        }
+    }
 
 
 

+ 2 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/cadastre/CadastreManageService.java

@@ -14,6 +14,8 @@ import java.util.Map;
 
 public interface CadastreManageService {
 
+    String addLandChange(String theFileName, String theFilePath, String landRightType,String landChangeMode);
+
     CompareResultVo getCompareData(String uploadId) ;
 
     CadastreFile saveUploadFile(String theFileName, String theFilePath, String fileType,String updateType);

+ 127 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/cadastre/impl/CadastreManageServiceImpl.java

@@ -16,7 +16,6 @@ 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;
@@ -59,6 +58,133 @@ public class CadastreManageServiceImpl implements CadastreManageService {
     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 到表中

+ 61 - 4
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/cadastre/impl/StorageServiceImpl.java

@@ -20,6 +20,10 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.ArrayUtils;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.io.WKTReader;
+import org.locationtech.jts.io.WKTWriter;
+import org.locationtech.jts.operation.union.UnaryUnionOp;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -719,12 +723,19 @@ public class StorageServiceImpl {
                     vo.setProjectName("");
                     vo.setCompanyName("暂无");
                     vo.setSupplyMethod(item.getGdType());
-                    vo.setSupplyType("2");
-                    vo.setDateType("2");
+                    vo.setSupplyType("3");
+                    vo.setDateType("3");
                     List<Map<String, String>> geomDetailsList= nodeLandService.selectTGeomDbDetailsByNodeId(item.getId());
                     if(CollectionUtils.isNotEmpty(geomDetailsList)){
-                        String geoms = geomDetailsList.stream().map(s->s.get("geom")).collect(Collectors.joining(","));
-                        vo.setGeom(geoms);
+                        //这里合并geom
+                        List<String> geomWkts = geomDetailsList.stream().map(s -> s.get("geom"))
+                                .filter(StringUtils::isNotBlank)
+                                .collect(Collectors.toList());
+                        if(geomWkts.size() == 1){
+                            vo.setGeom(geomWkts.get(0));
+                        }else {
+                            vo.setGeom(unionGeoms(geomWkts));
+                        }
                     }
                     vo.setYear(DateUtils.parseDate(item.getHbcrhtDate()));
                     vo.setArea(String.format("%.2f", item.getGdArea() == null ? BigDecimal.ZERO : item.getGdArea()));
@@ -1191,6 +1202,52 @@ public class StorageServiceImpl {
         return name;
     }
 
+    /**
+     * 模拟 st_union方法实现
+     * @param geomWkts
+     * @return
+     */
+    private String unionGeoms(List<String> geomWkts) {
+        if (CollectionUtils.isEmpty(geomWkts)) {
+            return null;
+        }
+        WKTReader reader = new WKTReader();
+        WKTWriter writer = new WKTWriter();
+        Integer srid = null;
+        List<Geometry> geoms = new ArrayList<>();
+        for (String wkt : geomWkts) {
+            if (StringUtils.isBlank(wkt)) {
+                continue;
+            }
+            String clean = wkt.trim();
+            // 处理 "SRID=xxxx;" 前缀(PostGIS ST_AsEWKT 的输出格式)
+            if (clean.startsWith("SRID=")) {
+                int semi = clean.indexOf(';');
+                if (semi > 0) {
+                    srid = Integer.parseInt(clean.substring(5, semi));
+                    clean = clean.substring(semi + 1);
+                }
+            }
+            try {
+                Geometry g = reader.read(clean);
+                if (!g.isEmpty()) {
+                    geoms.add(g);
+                }
+            } catch (Exception e) {
+                // 单条解析失败跳过,不要整体崩掉(可记日志)
+                log.error("解析几何失败: {}", clean, e);
+            }
+        }
+        if (geoms.isEmpty()) {
+            return null;
+        }
+        // 只有一条直接返回,避免无意义的 union 计算
+        Geometry result = geoms.size() == 1 ? geoms.get(0) : UnaryUnionOp.union(geoms);   // 等价 ST_Union
+        String wkt = writer.write(result);
+        return srid != null ? "SRID=" + srid + ";" + wkt : wkt;
+    }
+
+
 
 
 

+ 1 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/third/impl/TakeDataServiceImpl.java

@@ -388,7 +388,7 @@ public class TakeDataServiceImpl implements TakeDataService {
 //                gyjsydjfwscdjUpdateVo.setGzdgzsj(djDate);//告知单时间
 //            }
             gyjsydjfwscdjUpdateVo.setGzdgzsj(body.getGzdgzsj());//告知单时间
-            gyjsydjfwscdjUpdateVo.setKfdw(body.getKfdw());
+            gyjsydjfwscdjUpdateVo.setKfdw(body.getKfdw());// 这里开发单位用权利人
             gyjsydjfwscdjUpdateVo.setBdcqk(body.getBdcqk()); //不动产情况
             gyjsydjfwscdjUpdateVo.setJzmj(body.getJzmj()); //建筑面积
             gyjsydjfwscdjUpdateVo.setJzmjDw(body.getJzmjDw());//建筑面积单位

+ 1 - 1
siwei-modules/siwei-apply/src/main/resources/mapper/FwmxMapper.xml

@@ -56,7 +56,7 @@
         SELECT
         MIN ( ywh ) AS ywh,
         MIN ( gzdgzsj ) AS gzdgzsj,
-        MIN ( kfdw ) AS kfdw,
+        MIN ( qlrmc ) AS kfdw,
         MIN ( bdcqk ) AS bdcqk,
         MIN ( mjdw ) AS mjdw,
         SUM ( jzmj :: NUMERIC ) AS jzmj,