liutao hai 2 semanas
pai
achega
1ab91fc5f1

+ 5 - 0
YHYZT/server/src/main/java/com/zjugis/yzt/beans/entity/StGddk.java

@@ -10,6 +10,11 @@ import com.vividsolutions.jts.geom.Geometry;
 public class StGddk {
     @TableId
     private Integer objectid;
+
+    /**
+     * 属地镇街
+     */
+    private String sdzj;
     /** 供地索引 */
     private String dkBh;
     /** 地块名称 */

+ 3 - 0
YHYZT/server/src/main/java/com/zjugis/yzt/controller/StGddkController.java

@@ -145,4 +145,7 @@ public class StGddkController {
         }
         return vo;
     }
+
+
+
 }

+ 2 - 0
YHYZT/server/src/main/java/com/zjugis/yzt/service/StGddkService.java

@@ -2,6 +2,7 @@ package com.zjugis.yzt.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zjugis.yzt.beans.entity.StGddk;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * @program: yh_yzt
@@ -10,4 +11,5 @@ import com.zjugis.yzt.beans.entity.StGddk;
  * @create: 2024-03-21
  **/
 public interface StGddkService extends IService<StGddk> {
+    boolean uploadGdData(MultipartFile file);
 } 

+ 101 - 1
YHYZT/server/src/main/java/com/zjugis/yzt/service/impl/StGddkServiceImpl.java

@@ -1,10 +1,23 @@
 package com.zjugis.yzt.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zjugis.yzt.beans.entity.StNzydk;
 import com.zjugis.yzt.dao.StGddkMapper;
 import com.zjugis.yzt.beans.entity.StGddk;
 import com.zjugis.yzt.service.StGddkService;
+import com.zjugis.yzt.utils.ExcelUtils;
+import com.zjugis.yzt.utils.geocomm.ParseResult;
+import com.zjugis.yzt.utils.geocomm.TxtReader;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
 
 /**
  * @program: yh_yzt
@@ -14,4 +27,91 @@ import org.springframework.stereotype.Service;
  **/
 @Service
 public class StGddkServiceImpl extends ServiceImpl<StGddkMapper, StGddk> implements StGddkService {
-} 
+    @Override
+    public boolean uploadGdData(MultipartFile zipFile) {
+        if (zipFile.isEmpty()) {
+            log.error("上传文件为空");
+            return false;
+        }
+
+        File tempDir = null;
+        try {
+            // 创建临时目录
+            tempDir = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
+            if (!tempDir.exists()) {
+                tempDir.mkdirs();
+            }
+
+            // 解压ZIP文件
+            Map<String, File> txtFiles = new HashMap<>();
+            File xlsxFile = null;
+
+            try (ZipInputStream zis = new ZipInputStream(zipFile.getInputStream())) {
+                ZipEntry entry;
+                while ((entry = zis.getNextEntry()) != null) {
+                    File newFile = new File(tempDir, entry.getName());
+                    if (entry.isDirectory()) {
+                        newFile.mkdirs();
+                    } else {
+                        // 确保父目录存在
+                        new File(newFile.getParent()).mkdirs();
+                        try (FileOutputStream fos = new FileOutputStream(newFile)) {
+                            byte[] buffer = new byte[1024];
+                            int len;
+                            while ((len = zis.read(buffer)) > 0) {
+                                fos.write(buffer, 0, len);
+                            }
+                        }
+
+                        if (newFile.getName().toLowerCase().endsWith(".xlsx")) {
+                            xlsxFile = newFile;
+                        } else if (newFile.getName().toLowerCase().endsWith(".txt")) {
+                            String fileNameWithoutExt = newFile.getName().substring(0, newFile.getName().lastIndexOf('.'));
+                            txtFiles.put(fileNameWithoutExt, newFile);
+                        }
+                    }
+                }
+            }
+
+            if (xlsxFile == null) {
+                log.error("ZIP包中未找到XLSX文件");
+                return false;
+            }
+
+            // --- Start: 使用 ExcelUtils.importExcel 解析 XLSX 文件 ---
+            Map<String, Map<String, Object>> batchInfoMap = new HashMap<>();
+            List<Map<String, Object>> projectInfoList = new ArrayList<>();
+
+
+            int batchSheetIndex = 0;
+
+            List<Map<String, Object>> batchDataList = ExcelUtils.importExcel(
+                    new FileInputStream(xlsxFile), xlsxFile.getName(), 0, 1, batchSheetIndex
+            );
+            if (!batchDataList.isEmpty()) {
+                Map<String, Object> batchData = batchDataList.get(0);
+                String pcbh = batchData.containsKey("批次索引") ? String.valueOf(batchData.get("批次索引")) : null;
+                if (pcbh != null && !pcbh.isEmpty()) {
+                    batchInfoMap.put(pcbh, batchData);
+                }
+            } else {
+                log.warn("未能从 '农转用批次信息' sheet 读取到数据。");
+            }
+
+            // --- End: 使用 ExcelUtils.importExcel 解析 XLSX 文件 ---
+
+
+            return true;
+
+        } catch (IOException e) {
+            log.error("文件上传或处理失败", e);
+            return false;
+        } finally {
+            // 清理临时文件
+            if (tempDir != null && tempDir.exists()) {
+//                deleteDirectory(tempDir);
+            }
+        }
+    }
+
+}

+ 0 - 10
YHYZT/server/src/main/java/com/zjugis/yzt/service/impl/StNzydkUploadServiceImpl.java

@@ -5,12 +5,10 @@ import com.zjugis.yzt.beans.entity.StNzydk;
 import com.zjugis.yzt.dao.StNzydkMapper;
 import com.zjugis.yzt.service.StNzydkService;
 import com.zjugis.yzt.service.StNzydkUploadService;
-import com.zjugis.yzt.utils.geocomm.GisUtils;
 import com.zjugis.yzt.utils.geocomm.TxtReader;
 import com.zjugis.yzt.utils.geocomm.ParseResult;
 import com.zjugis.yzt.utils.ExcelUtils;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.ss.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
@@ -193,14 +191,6 @@ public class StNzydkUploadServiceImpl extends ServiceImpl<StNzydkMapper, StNzydk
         }
     }
 
-    private Map<String, Integer> getHeaderMap(Row headerRow) {
-        Map<String, Integer> headerMap = new HashMap<>();
-        for (Cell cell : headerRow) {
-            headerMap.put(cell.getStringCellValue(), cell.getColumnIndex());
-        }
-        return headerMap;
-    }
-
     private BigDecimal parseBigDecimal(String value) {
         if (value == null || value.isEmpty()) {
             return null;