chenendian пре 8 часа
родитељ
комит
6ae340f3bd

+ 23 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/cadastre/StorageController.java

@@ -615,4 +615,27 @@ public class StorageController extends BaseController {
     }
 
 
+    /**
+     *
+     * 收储文件上传入库
+     * 0 全量更新;1 增量更新
+     */
+    @PostMapping("/actual/import")
+    public R<String> importActual(String shpFilePath,String addType) {
+        try {
+            Map<String, Object>  res = storageServiceImpl.importActual(shpFilePath,addType);
+            return R.ok("success");
+        } catch (Exception e) {
+            e.printStackTrace();
+            return R.fail(e.getMessage());
+        }
+    }
+
+
+
+
+
+
+
+
 }

+ 1 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/mapper/GjShouchuJihuaMapper.java

@@ -25,6 +25,6 @@ public interface GjShouchuJihuaMapper {
 
     int deleteByTable(@Param("tableName") String tableName, @Param("gid") String gid,@Param("sourceType") String sourceType);
 
-
+    int insertTableActualData(@Param("tableName") String tableName, @Param("data") Map<String, Object> data, @Param("shpDbSRID") Integer shpDbSRID);
 
 }

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

@@ -30,6 +30,20 @@ import java.util.stream.Collectors;
 @Service
 public class StorageServiceImpl {
 
+    /**
+     * gj_shouchu_xiangmu_shiji 表允许入库的字段白名单
+     * (除 gid / geom / create_time / update_time 外的全部业务列,外加 shp 读取时的 the_geom)
+     * shp 字段数量可能多于数据表字段,需通过白名单过滤多余字段
+     */
+    private static final Set<String> SHIJI_ALLOWED_COLUMNS = new HashSet<>(Arrays.asList(
+            "dabh", "scfs", "scjg", "scmj", "scnd", "scsj", "scwh",
+            "shape_area", "shape_leng", "tdzl", "wzfbck", "xzq", "yqsdw",
+            "ytdsyqxz", "ytdyt", "cblx", "htqdsj", "nf", "schtbh", "sczj",
+            "yqsxz", "yzfbck", "sccb", "mj_m", "xmmc", "ghyt", "jzwmj",
+            "jzwjj", "pggs", "tdpgjg", "jzwpgjg", "qyzcpg", "tctgss",
+            "zfjl", "bz", "the_geom"
+    ));
+
     @Autowired
     private GjShijiShouchuMapper gjShijiShouchuMapper;
 
@@ -695,19 +709,20 @@ public class StorageServiceImpl {
         List<Map<String, Object>> shpDataList = shpGeomResult.getData();
         log.info("远程调用geom获取,返回结果:{}", shpDataList);
 
-        //数据字段进行校验
         int count = 1;
         for (Map<String, Object> shpData : shpDataList){
             String sccb = shpData.get("sccb").toString();
-            String scfs = shpData.get("scnf").toString();
+            String scnf = shpData.get("scnf").toString();
+            String scfs = shpData.get("scfs").toString();
             String ghyt = shpData.get("ghyt").toString();
             String mj_m = shpData.get("mj_m").toString();
-            if(StringUtils.isBlank(sccb)|| StringUtils.isBlank(scfs) || StringUtils.isBlank(ghyt) || StringUtils.isBlank(mj_m)){
-                throw new  ServiceException("关键字段不能为空(sccb,scnf,ghyt,mj_m),请检查第"+count+"条数据");
+            if(StringUtils.isBlank(sccb)|| StringUtils.isBlank(scfs) ||StringUtils.isBlank(scnf) || StringUtils.isBlank(ghyt) || StringUtils.isBlank(mj_m)){
+                throw new  ServiceException("关键字段不能为空(sccb,scnf,scfs,ghyt,mj_m),请检查第"+count+"条数据");
             }
             count++;
         }
 
+
         if("0".equals(addType)){
             //这里把当前表清空,重新写入;
             gjShouchuJihuaMapper.deleteByTable("gj_shouchu_xiangmu","",sourceType);
@@ -775,6 +790,95 @@ public class StorageServiceImpl {
 
 
 
+    //导入实际的数据
+    public Map<String, Object> importActual(String shpFilePath,String addType) {
+        Map<String, Object> retMap = new LinkedHashMap<>();
+        if(StringUtils.isBlank(shpFilePath)){
+            throw new  ServiceException("文件不存在请重新上传!");
+        }
+        File file = new File(shpFilePath);
+        if (!file.exists()) {
+            throw new  ServiceException("文件不存在请重新上传!");
+        }
+
+        R<List<Map<String, Object>>> shpGeomResult  = remoteSpatialFilesDbService.readShpFile(shpFilePath, SecurityConstants.INNER);
+        List<Map<String, Object>> shpDataList = shpGeomResult.getData();
+        log.info("远程调用geom获取,返回结果:{}", shpDataList);
+
+        //数据字段进行校验
+        int count = 1;
+        for (Map<String, Object> shpData : shpDataList){
+//            String scfs = shpData.get("scfs").toString();
+//            String scnd = shpData.get("scnd").toString();
+//            String sccb = shpData.get("sccb").toString();
+//            String mj_m = shpData.get("mj_m").toString();
+//            String ghyt = shpData.get("ghyt").toString();
+//            if(StringUtils.isBlank(sccb)|| StringUtils.isBlank(scfs) ||StringUtils.isBlank(scnd) || StringUtils.isBlank(ghyt) || StringUtils.isBlank(mj_m)){
+//                throw new  ServiceException("关键字段不能为空(sccb,scnd,scfs,ghyt,mj_m),请检查第"+count+"条数据");
+//            }
+            count++;
+        }
+        if("0".equals(addType)){
+            //这里把当前表清空,重新写入;
+            gjShouchuJihuaMapper.deleteByTable("gj_shouchu_xiangmu_shiji","","");
+        }
+
+        // 实际收储项目表 gj_shouchu_xiangmu_shiji geom 列的 SRID(建表语句中为 geometry(MULTIPOLYGON, 4326))
+        int shpDbSRID = 4326;
+        // 日期字段(shp 读取出来是 ISO8601 字符串,如 2025-12-24T00:00:00.000+08:00):
+        // 该表对应字段均为 varchar(100),为避免脏数据,统一截取 "T" 之前部分入库
+        Set<String> dateFields = new HashSet<>(Arrays.asList("scsj", "htqdsj"));
+        // 该表除 gid、geom、create_time、update_time 外,其余字段均为 varchar(100),
+        // 无需做 numeric 转换,仅做字符串清洗即可
+
+        for (Map<String, Object> shpData : shpDataList) {
+            Map<String, Object> insertData = new LinkedHashMap<>();
+            for (Map.Entry<String, Object> e : shpData.entrySet()) {
+                String key = e.getKey();
+                // shp 字段数量可能多于数据表字段,通过白名单过滤多余字段
+                if (!SHIJI_ALLOWED_COLUMNS.contains(key)) {
+                    continue;
+                }
+                Object val = e.getValue();
+                if (val == null) {
+                    continue;
+                }
+                if (val instanceof String) {
+                    String s = ((String) val).trim();
+                    if (s.isEmpty()) {
+                        continue;
+                    }
+                    if (dateFields.contains(key)) {
+                        int t = s.indexOf('T');
+                        if (t > 0) {
+                            s = s.substring(0, t);
+                        }
+                        insertData.put(key, s);
+                        continue;
+                    }
+                    insertData.put(key, s);
+                } else {
+                    insertData.put(key, val);
+                }
+            }
+            if (MapUtils.isEmpty(insertData)) {
+                continue;
+            }
+            gjShouchuJihuaMapper.insertTableActualData(
+                    "gj_shouchu_xiangmu_shiji", insertData, shpDbSRID);
+        }
+
+        retMap.put("status", "success");
+        retMap.put("path", shpFilePath);
+        return retMap;
+    }
+
+
+
+
+
+
+
 
 
 

+ 27 - 0
siwei-modules/siwei-apply/src/main/resources/mapper/GjShouchuJihuaMapper.xml

@@ -188,6 +188,33 @@
         </trim>
     </insert>
 
+    <insert id="insertTableActualData" parameterType="map">
+        INSERT INTO vector.${tableName} (
+            <foreach collection="data" index="k" item="v" separator=",">
+                <choose>
+                    <when test="k == 'the_geom'">geom</when>
+                    <otherwise>"${k}"</otherwise>
+                </choose>
+            </foreach>
+        ) VALUES (
+            <foreach collection="data" index="k" item="v" separator=",">
+                <choose>
+                    <when test="k == 'the_geom'">
+                        public.st_transform(public.st_geomfromewkt(#{v}), #{shpDbSRID})
+                    </when>
+                    <otherwise>#{v}::varchar</otherwise>
+                </choose>
+            </foreach>
+        )
+    </insert>
+
+
+
+
+
+
+
+
     <!-- 根据gid删除记录 -->
     <delete id="deleteByTable" parameterType="String">
         DELETE FROM vector.${tableName}