浏览代码

批次数据号调整

chenendian 3 周之前
父节点
当前提交
7ab4728215

+ 2 - 0
siwei-common/siwei-common-core/src/main/java/com/siwei/common/core/utils/DateUtils.java

@@ -24,6 +24,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
 
     public static String YYYY_MM_DD = "yyyy-MM-dd";
 
+    public static String YYYYMMDDHH = "yyyyMMddHH";
+
     public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
 
     public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

+ 33 - 23
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/ConvergeServiceImpl.java

@@ -12,6 +12,7 @@ import com.siwei.apply.service.cadastre.impl.FzssFxrwrzHandleService;
 import com.siwei.apply.utils.MdbUtil;
 import com.siwei.apply.utils.ServiceFileUtil;
 import com.siwei.common.core.exception.ServiceException;
+import com.siwei.common.core.utils.DateUtils;
 import com.siwei.common.core.utils.uuid.IdUtils;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.MultiPolygon;
@@ -109,32 +110,26 @@ public class ConvergeServiceImpl implements ConvergeService {
     @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();
+            String id = ywh;
+            Converge converge = convergeMapper.get(id);
+            if(Objects.isNull(converge)){
+                throw new ServiceException("获取不到当前任务:"+id);
             }
-            if(!file2.exists()){
-                file2.createNewFile();
+            String path = converge.getFilePath();
+            Path dirPath = Paths.get(path);
+            if(!Files.exists(dirPath)){
+                throw new ServiceException("找不到汇交文件生成目录:"+id);
+            }
+            File zipFile = new File(dirPath + ".zip");
+            if(!zipFile.exists()){
+                ServiceFileUtil.zipByDir(dirPath.toFile(),null, zipFile);
             }
-
-            List<File> filesToZip = Arrays.asList(
-                    file1,
-                    file2
-            );
-            ServiceFileUtil.zipFiles(filesToZip, zipFile);
 
             // 4. 设置响应头并下载
+            String downName = converge.getName()+IdUtils.fastSimpleUUID();
             response.setContentType("application/zip");
             response.setCharacterEncoding("utf-8");
-            String fileName = shpName + ".zip";
+            String fileName = downName + ".zip";
             response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
 
             try (FileInputStream fis = new FileInputStream(zipFile)) {
@@ -152,6 +147,7 @@ public class ConvergeServiceImpl implements ConvergeService {
     }
 
 
+
     @Transactional
     @Override
     public void operationConverge(String batch,String type) {
@@ -160,9 +156,9 @@ public class ConvergeServiceImpl implements ConvergeService {
             throw new ServiceException("汇交入参,类型错误"+type);
         }
         if (StringUtils.isBlank(batch)) {
-            batch = "123";
+            batch = DateUtils.dateTimeNow(DateUtils.YYYYMMDDHH);
+            //batch = "123";
         }
-
         Converge converge = new Converge();
         converge.generateId();
         String convergeId = converge.getId();
@@ -179,6 +175,7 @@ public class ConvergeServiceImpl implements ConvergeService {
         fzssFxrwrzHandleService.insertFxrwrz(convergeId, "地籍库管理", "汇交任务创建", "info");
         fzssFxrwrzHandleService.insertFxrwrz(convergeId, "地籍库管理", "汇交数据执行开始。。。", "info");
 
+        long startTime = System.currentTimeMillis();
         //todo  1.做一个vo类型的javabean 2.查询所有的表数据,进行判断去除空表数据。3.区分是否矢量。4.把当前文件处理成其它。
         List<ConvergeRes> convergeTableList = new ArrayList<>();
         Arrays.stream(ConvergeTableEnum.values()).forEach(e -> {
@@ -200,6 +197,8 @@ public class ConvergeServiceImpl implements ConvergeService {
             }
         });
 
+        fzssFxrwrzHandleService.insertFxrwrz(convergeId, "地籍库管理", "数据已完成提取。。。。", "info");
+
         String basePath =  convergedir + converge.getName()+"/"+"012345赣江新区"+"/";
         List<ConvergeRes> subConvergeTableList = new ArrayList<>();//衍生出的数据
 
@@ -238,12 +237,24 @@ public class ConvergeServiceImpl implements ConvergeService {
             if(!subConvergeTableList.isEmpty()){
                 convergeTableList.addAll(subConvergeTableList);
             }
+
+            fzssFxrwrzHandleService.insertFxrwrz(convergeId, "地籍库管理", "数据已完成目录构建。。。。", "info");
             //这里进行数据汇交
             try {
                 operationFileStrategy(convergeTableList);
             } catch (Exception e) {
                 throw new ServiceException("汇交失败,数据错误"+e);
             }
+
+            //更新状态
+            ConvergeUpdateVo updateVo = new ConvergeUpdateVo();
+            updateVo.setId(convergeId);
+            updateVo.setFilePath(convergedir + converge.getName());
+            updateVo.setFileCostTime(String.valueOf((System.currentTimeMillis()-startTime)/1000));
+            updateVo.setStatus("1");
+            updateVo.setReadMessage("创建成功");
+            convergeMapper.update(updateVo);
+            fzssFxrwrzHandleService.insertFxrwrz(convergeId, "地籍库管理", "汇交数据文件创建成功。", "info");
         }
     }
 
@@ -467,5 +478,4 @@ public class ConvergeServiceImpl implements ConvergeService {
 
 
 
-
 }

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

@@ -237,6 +237,77 @@ public class ServiceFileUtil {
     }
 
 
+    /**
+     * 通过目录进行压缩
+     * @param dirFile
+     * @param entryName
+     * @param zipFile
+     * @throws IOException
+     */
+    public static void zipByDir(File dirFile, String entryName, File zipFile) throws IOException {
+
+        if (dirFile == null || !dirFile.exists()) {
+            throw new RuntimeException("源文件或目录不存在");
+        }
+
+        // 如果 entryName 为空,就用目录名
+        if (entryName == null || entryName.trim().isEmpty()) {
+            entryName = dirFile.getName();
+        }
+
+        // 创建 zip 输出流(只创建一次!!)
+        try (ZipOutputStream zos = new ZipOutputStream(
+                new FileOutputStream(zipFile),
+                java.nio.charset.StandardCharsets.UTF_8)) {
+
+            // 调用递归方法
+            zipInternal(dirFile, entryName, zos);
+        }
+    }
+
+
+    /**
+     * 核心压缩文件逻辑
+     * @param file
+     * @param entryName
+     * @param zos
+     * @throws IOException
+     */
+    private static void zipInternal(File file, String entryName, ZipOutputStream zos) throws IOException {
+        // 👉 目录
+        if (file.isDirectory()) {
+            File[] files = file.listFiles();
+
+            // 空目录
+            if (files == null || files.length == 0) {
+                zos.putNextEntry(new ZipEntry(entryName + "/"));
+                zos.closeEntry();
+            } else {
+                for (File child : files) {
+                    zipInternal(child, entryName + "/" + child.getName(), zos);
+                }
+            }
+        } else {
+            // 👉 文件
+            try (FileInputStream fis = new FileInputStream(file)) {
+
+                zos.putNextEntry(new ZipEntry(entryName));
+
+                byte[] buffer = new byte[4096];
+                int len;
+                while ((len = fis.read(buffer)) != -1) {
+                    zos.write(buffer, 0, len);
+                }
+
+                zos.closeEntry();
+            }
+        }
+    }
+
+
+
+
+
 
 
     public static void test() throws Exception {

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

@@ -92,7 +92,6 @@
             <if test="type != null">type = #{type},</if>
             <if test="readMessage != null">read_message = #{readMessage},</if>
             <if test="fileCostTime != null">file_cost_time = #{fileCostTime},</if>
-            operation_time = now()
         </set>
         WHERE id = #{id}
     </update>