Explorar el Código

更新编码判断spatial

chenendian hace 1 día
padre
commit
f18d174ed6

+ 5 - 1
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/cadastre/SupplyController.java

@@ -581,7 +581,7 @@ public class SupplyController extends BaseController {
         }
     }
 
-    @GetMapping("/supply/list")
+    @GetMapping("/schedule/list")
     public  R<?> supplyList(
             @RequestParam(value = "pageNum", required = false) Integer pageNum,
             @RequestParam(value = "pageSize", required = false) Integer pageSize) {
@@ -596,4 +596,8 @@ public class SupplyController extends BaseController {
     }
 
 
+
+
+
+
 }

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

@@ -834,9 +834,9 @@ public class StorageServiceImpl {
         int count = 1;
         for (Map<String, Object> shpData : shpDataList){
 //            String scfs = shpData.get("scfs").toString();
-            String scnd = shpData.get("scnd").toString();
+            String scnd =   Objects.nonNull(shpData.get("scnd"))?shpData.get("scnd").toString():"";
 //            String sccb = shpData.get("sccb").toString();
-            String mj_m = shpData.get("mj_m").toString();
+            String mj_m =  Objects.nonNull(shpData.get("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+"条数据");

+ 26 - 1
siwei-modules/siwei-spatial/src/main/java/com/siwei/spatial/service/file/impl/SpatialFilesDbServiceImpl.java

@@ -49,6 +49,7 @@ import java.io.Serializable;
 import java.math.BigDecimal;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.util.*;
 
 @Service
@@ -275,7 +276,7 @@ public class SpatialFilesDbServiceImpl implements ISpatialFilesDbService {
         String tableId = null;
         try {
             shapefileDataStore = new ShapefileDataStore(shpFile.toURI().toURL());
-            shapefileDataStore.setCharset(Charset.forName(readShpBM(shpFile.getAbsolutePath())));
+            shapefileDataStore.setCharset(Charset.forName(detectEncoding(shpFile.getAbsolutePath())));
             // 这个typeNamae不传递,默认是文件名称
             FeatureSource featuresource = shapefileDataStore.getFeatureSource(shapefileDataStore.getTypeNames()[0]);
 
@@ -348,6 +349,30 @@ public class SpatialFilesDbServiceImpl implements ISpatialFilesDbService {
         return retFeatureList;
     }
 
+
+
+
+    private String detectEncoding(String shpPath) {
+        // 1. 优先读 .cpg 文件
+        String cpgPath = shpPath.substring(0, shpPath.length() - 4) + ".cpg";
+        File cpgFile = new File(cpgPath);
+        if (cpgFile.exists()) {
+            try {
+                String encoding = new String(Files.readAllBytes(cpgFile.toPath()), "ASCII").trim();
+                System.out.println("从 .cpg 文件读取编码: " + encoding);
+                return encoding;  // 返回 "gb18030"
+            } catch (IOException e) {
+                // 忽略,走下面的兜底
+            }
+        }
+        // 2. 没有 .cpg,再读 DBF 的 LDID 兜底
+        return readShpBM(shpPath);
+    }
+
+
+
+
+
     private String readShpBM(String shpPath) {
         String dbfPath = shpPath.substring(0, shpPath.length() - 4) + ".dbf";
         try (FileInputStream fis = new FileInputStream(dbfPath)) {