lyhzzz hace 2 semanas
padre
commit
b1d53c486e

+ 5 - 1
pom.xml

@@ -69,7 +69,11 @@
       <artifactId>4dkankan-utils-rabbitmq</artifactId>
       <version>3.0.0-SNAPSHOT</version>
     </dependency>
-
+    <dependency>
+      <groupId>com.fdkankan</groupId>
+      <artifactId>4dkankan-utils-contro</artifactId>
+      <version>3.0.0-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>org.projectlombok</groupId>
       <artifactId>lombok</artifactId>

+ 2 - 0
src/main/java/com/fdkankan/manage/common/ResultCode.java

@@ -129,6 +129,8 @@ public enum ResultCode  {
     CASE_NOT_EXIST2(60046, "案件或K号不存在"),
     SCENE_BUILDING(60047, "场景计算中"),
     SCENE_BUILDING_ERROR(60048, "场景码池为空"),
+    UPLOAD_SCENE_ERROR3(60049, "scene.json文件数据异常"),
+    UPLOAD_SCENE_ERROR4(60050, "版本不匹配"),
 
     ;
 

+ 15 - 94
src/main/java/com/fdkankan/manage/common/ZipFileReaderUtil.java

@@ -1,5 +1,7 @@
 package com.fdkankan.manage.common;
 
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.io.IoUtil;
 import net.lingala.zip4j.*;
 import net.lingala.zip4j.exception.ZipException;
 import net.lingala.zip4j.model.FileHeader;
@@ -11,106 +13,25 @@ public class ZipFileReaderUtil {
 
     public static final String zipPassword = "a3ad34136de359536af553f9e7f3cefd";
 
-    public static String getFileStringFromZip(String zipPath, String targetFile) throws Exception{
-        return new String(getFileBytesFromZip(zipPath,targetFile,zipPassword));
-    }
-    public static String getFileStringFromZip(String zipPath, String targetFile, String password) throws Exception{
-        return new String(getFileBytesFromZip(zipPath,targetFile,password));
-    }
-
-    /**
-     * 从加密ZIP获取文件内容为字节数组
-     */
-    public static byte[] getFileBytesFromZip(String zipPath, String targetFile, String password)
-            throws IOException {
-
-        try (ZipFile zipFile = new ZipFile(zipPath);
-             InputStream is = getFileStreamFromZip(zipFile, targetFile, password)) {
-
-            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-            int nRead;
-            byte[] data = new byte[1024];
-            while ((nRead = is.read(data, 0, data.length)) != -1) {
-                buffer.write(data, 0, nRead);
+    public static String readUtf8(String zipPath, String fileName) throws Exception {
+        ZipFile zipFile = new ZipFile(zipPath);
+        zipFile.setPassword(zipPassword.toCharArray());
+        // 读取所有条目(文件头)
+        for (FileHeader header : (List<FileHeader>)zipFile.getFileHeaders()) {
+            // 文件名(不含目录)
+            String filePath = header.getFileName();
+            String headerFileName = FileUtil.getName(filePath);
+            if (filePath.contains("backup") || !fileName.equals(headerFileName)) {
+                continue;
             }
-            return buffer.toByteArray();
-        }
-    }
-
-    /**
-     * 获取文件输入流
-     */
-    private static InputStream getFileStreamFromZip(ZipFile zipFile, String targetFile, String password)
-            throws IOException {
-
-        if (zipFile.isEncrypted() && password != null) {
-            zipFile.setPassword(password.toCharArray());
-        }
-
-        FileHeader fileHeader = findFileHeader(zipFile, targetFile);
-        if (fileHeader == null) {
-            throw new IOException("File not found: " + targetFile);
-        }
-
-        return zipFile.getInputStream(fileHeader);
-    }
-
-    /**
-     * 查找文件头(支持路径匹配)
-     */
-    private static FileHeader findFileHeader(ZipFile zipFile, String targetFile) throws IOException {
-        // 首先尝试精确匹配
-        FileHeader header = zipFile.getFileHeader(targetFile);
-        if (header != null) {
-            return header;
-        }
-
-        // 遍历所有文件进行模糊匹配
-        List<FileHeader> headers = zipFile.getFileHeaders();
-        for (FileHeader fileHeader : headers) {
-            String fileName = getFileNameFromPath(fileHeader.getFileName());
-            if (fileName.equals(targetFile)) {
-                return fileHeader;
+            try (InputStream is = zipFile.getInputStream(header)) {
+                return IoUtil.readUtf8(is);
             }
         }
-
         return null;
     }
-
-    /**
-     * 从路径中提取文件名
-     */
-    private static String getFileNameFromPath(String path) {
-        if (path == null || path.isEmpty()) {
-            return path;
-        }
-        int lastSeparator = path.lastIndexOf('/');
-        if (lastSeparator == -1) {
-            lastSeparator = path.lastIndexOf('\\');
-        }
-        return lastSeparator == -1 ? path : path.substring(lastSeparator + 1);
-    }
-
-    /**
-     * 列出ZIP中的所有文件
-     */
-    public static void listZipContents(String zipPath, String password) throws IOException {
-        try (ZipFile zipFile = new ZipFile(zipPath)) {
-            if (zipFile.isEncrypted() && password != null) {
-                zipFile.setPassword(password.toCharArray());
-            }
-
-            List<FileHeader> fileHeaders = zipFile.getFileHeaders();
-            System.out.println("ZIP contents:");
-            for (FileHeader header : fileHeaders) {
-                System.out.println(" - " + header.getFileName() +
-                        " (Encrypted: " + header.isEncrypted() + ")");
-            }
-        }
-    }
-
     public static void main(String[] args) throws Exception{
-        String content = getFileStringFromZip("D:\\panoxv20001.osc_202506161105346420.zip", "data.fdage");
+        String content = readUtf8("D:\\panoxv20001.osc_202506161105346420.zip", "data.fdage");
         System.out.println(content);
     }
 

+ 9 - 3
src/main/java/com/fdkankan/manage/controller/SceneController.java

@@ -213,16 +213,22 @@ public class SceneController {
     @PostMapping("/uploadSceneCheck")
     public ResultData uploadSceneCheck(@RequestBody UploadSceneOrigParamVo paramVo){
         if(StringUtils.isBlank(paramVo.getFilePath()) || !paramVo.getFilePath().contains(".zip") || StringUtils.isBlank(paramVo.getSourceType())){
-            throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
+            throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        if("orig".equals(paramVo.getSourceType())){
+            return ResultData.ok(fdkkService.uploadSceneCheck(paramVo));
         }
-        return ResultData.ok(fdkkService.uploadSceneCheck(paramVo));
+        if("offline".equals(paramVo.getSourceType())){
+            return ResultData.ok(fdkkService.checkUploadSceneOffline(paramVo.getFilePath()));
+        }
+        throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
     }
 
 
     @PostMapping("/uploadScene")
     public ResultData uploadSceneOrig(@RequestBody UploadSceneOrigParamVo paramVo){
         if(StringUtils.isBlank(paramVo.getFilePath()) || !paramVo.getFilePath().contains(".zip") || StringUtils.isBlank(paramVo.getSourceType())){
-            throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
+            throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
         }
         fdkkService.uploadSceneOrig(paramVo);
         return ResultData.ok();

+ 53 - 2
src/main/java/com/fdkankan/manage/httpClient/service/FdkkService.java

@@ -1,6 +1,9 @@
 package com.fdkankan.manage.httpClient.service;
 
 import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.manage.common.OssPath;
@@ -62,7 +65,7 @@ public class FdkkService {
             JyUser loginUser = jyUserService.getBySysId(StpUtil.getLoginId());
             paramVo.setFilePath(paramVo.getFilePath().replace(manageConfig.getQueryPath(),""));
 
-            String content = ZipFileReaderUtil.getFileStringFromZip(manageConfig.getQueryPath() + "4dkankan/"+paramVo.getFilePath(), "data.fdage");
+            String content = ZipFileReaderUtil.readUtf8(manageConfig.getQueryPath() + "4dkankan/"+paramVo.getFilePath(), "data.fdage");
             JSONObject jsonObject = JSONObject.parseObject(content);
             String uuidtime = jsonObject.getString("uuidtime");
             List<ScenePlusExt> exts = scenePlusExtService.getLikeDataSource(uuidtime);
@@ -77,7 +80,7 @@ public class FdkkService {
                         return new UploadSceneCheckVo(ResultCode.UPLOAD_SCENE_ERROR.code(),jyUser.getRyNo());
                     }
                     if(jyUser != null){
-                        return new UploadSceneCheckVo(ResultCode.UPLOAD_SCENE_ERROR2.code(),"");
+                        return new UploadSceneCheckVo(ResultCode.UPLOAD_SCENE_ERROR2.code(),ResultCode.UPLOAD_SCENE_ERROR2.message());
                     }
                 }
             }
@@ -87,4 +90,52 @@ public class FdkkService {
         }
         throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
     }
+
+    public UploadSceneCheckVo checkUploadSceneOffline(String zipPath)  {
+        try {
+            String sceneJsonStr = ZipFileReaderUtil.readUtf8(manageConfig.getQueryPath() + "4dkankan/"+zipPath, "scene.json");
+
+            if(StrUtil.isEmpty(sceneJsonStr) || !JSONUtil.isJson(sceneJsonStr)){
+                throw new BusinessException(ResultCode.UPLOAD_SCENE_ERROR3);
+            }
+            JSONObject jsonObject = JSON.parseObject(sceneJsonStr);
+            //校验版本
+            String offlineVersion = jsonObject.getString("offlineVersion");
+            String platformVersion = "2.2.0";//从数据中获取
+            if (offlineVersion == null || platformVersion == null) {
+                throw new BusinessException(ResultCode.UPLOAD_SCENE_ERROR4);
+            }
+
+            String[] offParts = offlineVersion.split("\\.");
+            String[] pfParts = platformVersion.split("\\.");
+
+            // 至少需要两位版本号
+            if (offParts.length < 2 || pfParts.length < 2) {
+                throw new BusinessException(ResultCode.UPLOAD_SCENE_ERROR4);
+            }
+
+            // 比较前两位
+            if (!offParts[0].equals(pfParts[0]) || !offParts[1].equals(pfParts[1])) {
+                throw new BusinessException(ResultCode.UPLOAD_SCENE_ERROR4);
+            }
+
+            // 前两位一致,检查第三位
+            if (!offParts[2].equals(pfParts[2])) {
+                throw new BusinessException(ResultCode.UPLOAD_SCENE_ERROR4);
+            }
+
+            String num = jsonObject.getString("num");
+            ScenePlus scenePlus = scenePlusService.getByNum(num);
+            if(scenePlus != null){
+                throw new BusinessException(ResultCode.UPLOAD_SCENE_ERROR2);
+            }
+            return new UploadSceneCheckVo(0,"");
+        }catch (BusinessException e){
+            throw e;
+        }catch (Exception e){
+            log.info("upload-scene-error:{}",e);
+        }
+        throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
+
+    }
 }

+ 1 - 0
src/main/java/com/fdkankan/manage/vo/request/UploadSceneCheckVo.java

@@ -1,5 +1,6 @@
 package com.fdkankan.manage.vo.request;
 
+import com.fdkankan.manage.common.ResultCode;
 import lombok.AllArgsConstructor;
 import lombok.Data;