1
0
chenendian преди 3 седмици
родител
ревизия
b44de807c4

+ 39 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/cadastre/ConvergeController.java

@@ -10,6 +10,7 @@ import com.siwei.common.core.web.controller.BaseController;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.Map;
 
 /**
@@ -75,6 +76,44 @@ public class ConvergeController extends BaseController {
     }
 
 
+    /**
+     * 下载汇交文件
+     * zip 文件
+     *
+     */
+    @PostMapping("/downConvergeFile")
+    public void downConvergeFile(HttpServletResponse response, String  ywh)  {
+        try {
+            convergeService.downConvergeFile(response, ywh);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+
+    /**
+     * 新增汇交文件
+     * 汇交提交
+     */
+    @PostMapping("/addConverge")
+    public R<String> addConverge(@RequestBody ConvergeUpdateVo addDataVo) {
+        try {
+            String batch =  addDataVo.getBatchName();
+            String type  = addDataVo.getType();
+            //convergeService.batchDelete333(batch,type);
+            return R.ok("提交成功");
+        } catch (Exception e) {
+            return R.fail(e.getMessage());
+        }
+    }
+
+
+
+
+
+
+
 
 
 

+ 6 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/ConvergeService.java

@@ -4,6 +4,7 @@ import com.siwei.apply.domain.Converge;
 import com.siwei.apply.domain.vo.ConvergeFilterVo;
 import com.siwei.apply.domain.vo.ConvergeUpdateVo;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 import java.util.Map;
 
@@ -30,4 +31,9 @@ public interface ConvergeService {
      * 批量删除汇交记录
      */
     void batchDelete(List<String> ids);
+
+    void downConvergeFile(HttpServletResponse response, String ywh);
+
+
+
 }

+ 58 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/ConvergeServiceImpl.java

@@ -5,11 +5,17 @@ import com.siwei.apply.domain.vo.ConvergeFilterVo;
 import com.siwei.apply.domain.vo.ConvergeUpdateVo;
 import com.siwei.apply.mapper.ConvergeMapper;
 import com.siwei.apply.service.ConvergeService;
+import com.siwei.apply.utils.ServiceFileUtil;
+import com.siwei.common.core.utils.uuid.IdUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -54,4 +60,56 @@ public class ConvergeServiceImpl implements ConvergeService {
     public void batchDelete(List<String> ids) {
         convergeMapper.batchDelete(ids);
     }
+
+
+    @Override
+    public void downConvergeFile(HttpServletResponse response, String ywh) {
+        try {
+            // 1. 创建临时目录
+            String tempDir = System.getProperty("java.io.tmpdir") + File.separator + IdUtils.fastSimpleUUID();
+            File dir = new File(tempDir);
+            if (!dir.exists()) dir.mkdirs();
+            String shpName = "test"+IdUtils.fastSimpleUUID();
+            File zipFile = new File(tempDir + File.separator + shpName + ".zip");
+
+            File file1 =  new File(tempDir + File.separator + shpName + ".shp");
+            File file2 =   new File(tempDir + File.separator + shpName + ".shx");
+            if(!file1.exists()){
+                file1.createNewFile();
+            }
+            if(!file2.exists()){
+                file2.createNewFile();
+            }
+
+            List<File> filesToZip = Arrays.asList(
+                    file1,
+                    file2
+            );
+            ServiceFileUtil.zipFiles(filesToZip, zipFile);
+
+            // 4. 设置响应头并下载
+            response.setContentType("application/zip");
+            response.setCharacterEncoding("utf-8");
+            String fileName = shpName + ".zip";
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+
+            try (FileInputStream fis = new FileInputStream(zipFile)) {
+                byte[] buffer = new byte[4096];
+                int len;
+                while ((len = fis.read(buffer)) > 0) {
+                    response.getOutputStream().write(buffer, 0, len);
+                }
+            }
+            response.getOutputStream().flush();
+        } catch (Exception e) {
+            log.error("导出SHP文件失败", e);
+            throw new RuntimeException("导出SHP文件失败: " + e.getMessage());
+        }
+
+    }
+
+
+
+
+
 }

+ 31 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/ServiceFileUtil.java

@@ -9,10 +9,14 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.file.*;
 import java.util.*;
 import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -208,6 +212,33 @@ public class ServiceFileUtil {
     }
 
 
+    /**
+     * 将多个文件压缩成ZIP
+     *
+     * @param files       要压缩的文件列表
+     * @param zipFile     目标ZIP文件
+     * @throws IOException
+     */
+    public static void zipFiles(List<File> files, File zipFile) throws IOException {
+        try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile))) {
+            byte[] buffer = new byte[4096];
+            for (File file : files) {
+                if (!file.exists()) continue;
+                try (FileInputStream fis = new FileInputStream(file)) {
+                    zos.putNextEntry(new ZipEntry(file.getName()));
+                    int len;
+                    while ((len = fis.read(buffer)) > 0) {
+                        zos.write(buffer, 0, len);
+                    }
+                    zos.closeEntry();
+                }
+            }
+        }
+    }
+
+
+
+
     public static void test() throws Exception {
         Path dirPath = Paths.get("C:\\Users\\Administrator\\Desktop\\01\\一码管地相关\\数据库.docx");
         String extension = FilenameUtils.getExtension(dirPath.toString());