dengsixing 7 ヶ月 前
コミット
45fcc53c71

+ 2 - 0
src/main/java/com/fdkankan/scene/bean/DownLoadTaskBean.java

@@ -31,4 +31,6 @@ public class DownLoadTaskBean implements Serializable {
 
     private String lang;
 
+    private String resultPath;
+
 }

+ 2 - 2
src/main/java/com/fdkankan/scene/controller/SceneDownloadLogController.java

@@ -31,9 +31,9 @@ public class SceneDownloadLogController {
     private ISceneDownloadLogService sceneDownloadLogService;
 
     @GetMapping("/downOfflineScene")
-    public ResultData downOfflineScene(@RequestParam("sceneCode")String num, @RequestParam(name = "lang", defaultValue = "zh")String lang){
+    public ResultData downOfflineScene(@RequestParam("sceneCode")String num, @RequestParam(name = "lang", defaultValue = "zh")String lang, String resultPath){
         log.info("downOfflineScene");
-        return sceneDownloadLogService.downOfflineScene(num, lang);
+        return sceneDownloadLogService.downOfflineScene(num, lang, resultPath);
     }
     @GetMapping("/downOfflineSceneCheck")
     public ResultData downOfflineSceneCheck(@RequestParam("sceneCode")String num, @RequestParam(name = "lang", defaultValue = "zh")String lang){

+ 4 - 4
src/main/java/com/fdkankan/scene/schedule/ScheduleJob.java

@@ -46,10 +46,10 @@ public class ScheduleJob {
         sceneDownLoadService.process();
     }
 
-    @Scheduled(cron = "0/5 * * * * ? ")
-    public void job4SceneV3Download() throws Exception {
-        sceneDownLoadService.processV3();
-    }
+//    @Scheduled(cron = "0/5 * * * * ? ")
+//    public void job4SceneV3Download() throws Exception {
+//        sceneDownLoadService.processV3();
+//    }
 
     @Scheduled(cron = "0/2 * * * * ? ")
     public void transferTourVideo() throws Exception {

+ 1 - 1
src/main/java/com/fdkankan/scene/service/ISceneDownLoadService.java

@@ -12,6 +12,6 @@ public interface ISceneDownLoadService {
 
     void process() throws Exception;
 
-    void processV3() throws Exception;
+//    void processV3() throws Exception;
 
 }

+ 1 - 1
src/main/java/com/fdkankan/scene/service/ISceneDownloadLogService.java

@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
  */
 public interface ISceneDownloadLogService extends IService<SceneDownloadLog> {
 
-    ResultData downOfflineScene(String num, String lang);
+    ResultData downOfflineScene(String num, String lang, String resultPath);
 
     ResultData downloadProcess(String num);
 

+ 110 - 113
src/main/java/com/fdkankan/scene/service/impl/SceneDownloadHandlerServiceImpl.java

@@ -92,8 +92,8 @@ public class SceneDownloadHandlerServiceImpl {
     private String v3localPath;
     @Value("${path.zip-local}")
     private String zipLocalFormat;
-    @Value("${path.source-local}")
-    private String sourceLocal;
+//    @Value("${path.source-local}")
+//    private String sourceLocal;
     @Value("${path.zip-oss}")
     private String zipOssFormat;
     @Value("${path.zip-root}")
@@ -176,7 +176,7 @@ public class SceneDownloadHandlerServiceImpl {
             long startTime = Calendar.getInstance().getTimeInMillis();
 
             //执行场景下载逻辑
-            this.downloadHandlerV3(downLoadTaskBean);
+//            this.downloadHandlerV3(downLoadTaskBean);
 
             //耗时
             long consumeTime = Calendar.getInstance().getTimeInMillis() - startTime;
@@ -197,6 +197,12 @@ public class SceneDownloadHandlerServiceImpl {
 
     public void downloadHandler(DownLoadTaskBean downLoadTaskBean) throws Exception{
 
+        String resultPath = downLoadTaskBean.getResultPath();
+        if(!resultPath.endsWith(File.separator)){
+            resultPath = resultPath.concat(File.separator);
+        }
+        String sourceLocalPath = resultPath + "%s" + File.separator + "%s";
+
         String num = downLoadTaskBean.getNum();
         //zip包路径
         String zipPath = null;
@@ -204,7 +210,7 @@ public class SceneDownloadHandlerServiceImpl {
             TimeInterval timer = DateUtil.timer();
 
             //删除资源目录
-            FileUtil.del(String.format(this.sourceLocal, num, ""));
+            FileUtil.del(String.format(sourceLocalPath, num, ""));
 
             ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
             if(Objects.isNull(scenePlus))
@@ -243,21 +249,21 @@ public class SceneDownloadHandlerServiceImpl {
             }
 
             //固定文件写入
-            this.zipLocalFiles(v4localFilePaths, v4localPath, num, count, total, "v4");
+            this.zipLocalFiles(v4localFilePaths, num, count, total, "v4", sourceLocalPath);
             log.info("打包固定文件耗时, num:{}, time:{}", num, timer.intervalRestart());
 
             //oss文件写入
-            this.zipOssFiles(bucket, ossFilePaths, num, count, total, resolution, imagesVersion, cacheKeys, "v4");
+            this.zipOssFiles(bucket, ossFilePaths, num, count, total, resolution, imagesVersion, cacheKeys, "v4", sourceLocalPath);
             log.info("打包oss文件耗时, num:{}, time:{}", num, timer.intervalRestart());
 
             //重新写入scene.json(去掉密码访问设置)
-            this.zipSceneJson(num, sceneViewInfo);
+            this.zipSceneJson(num, sceneViewInfo,sourceLocalPath);
 
             //写入启动命令
-            this.zipBat(num, "v4", downLoadTaskBean.getLang());
+            this.zipBat(num, "v4", downLoadTaskBean.getLang(), sourceLocalPath);
 
             //打压缩包
-            ZipUtil.zip(String.format(this.sourceLocal, num, ""), zipPath, Charset.forName("GBK"), true);
+//            ZipUtil.zip(String.format(this.sourceLocal, num, ""), zipPath, Charset.forName("GBK"), true);
 
             //上传压缩包
             String uploadPath = String.format(this.zipOssFormat, num);
@@ -272,10 +278,11 @@ public class SceneDownloadHandlerServiceImpl {
             //更新进度为下载失败
             this.updateProgress( null, num, SceneDownloadProgressStatus.DOWNLOAD_FAILED.code(), null, "v4");
             throw e;
-        }finally {
-            FileUtil.del(zipPath);
-            FileUtil.del(String.format(this.sourceLocal, num, ""));
         }
+//        finally {
+//            FileUtil.del(zipPath);
+//            FileUtil.del(String.format(this.sourceLocal, num, ""));
+//        }
     }
 
     private SceneViewInfo getSceneJson(String num, String bucket){
@@ -306,83 +313,83 @@ public class SceneDownloadHandlerServiceImpl {
         return sceneInfoVO;
     }
 
-    public void downloadHandlerV3(DownLoadTaskBean downLoadTaskBean) throws Exception{
-
-        String num = downLoadTaskBean.getSceneNum();
-        //zip包路径
-        String zipPath = null;
-
-        try {
-            TimeInterval timer = DateUtil.timer();
-
-            //删除资源目录
-            FileUtil.del(String.format(this.sourceLocal, num, ""));
-
-            ScenePro scenePro = sceneProService.getByNum(num);
-            if(Objects.isNull(scenePro))
-                throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
-
-            Set<String> cacheKeys = new ConcurrentHashSet<>();
-
-            Map<String, List<String>> allFiles = this.getAllFilesV3(num, v3localPath, bucket);
-            List<String> ossFilePaths = allFiles.get("ossFilePaths");
-            List<String> v3localFilePaths = allFiles.get("localFilePaths");
-
-            //key总个数
-            int total = ossFilePaths.size() + v3localFilePaths.size();
-            AtomicInteger count = new AtomicInteger(0);
-            //定义压缩包
-            zipPath = String.format(this.zipLocalFormat, num);
-            File zipFile = new File(zipPath);
-            if(!zipFile.getParentFile().exists()){
-                zipFile.getParentFile().mkdirs();
-            }
-
-            int imagesVersion =0;
-            String resolution = "2k";
-            JSONObject getInfoJson = this.getInfo(num);
-            imagesVersion = getInfoJson.getInt("imagesVersion");
-            // 转台、激光显示4k图片
-            if(getInfoJson.getInt("sceneSource") == 3 || getInfoJson.getInt("sceneSource") == 4){
-                resolution = "4k";
-            }
-
-            //固定文件写入
-            timer.intervalRestart();
-            this.zipLocalFiles(v3localFilePaths, v3localPath, num, count, total, "v3");
-            log.info("打包固定文件耗时, num:{}, time:{}", num, timer.intervalRestart());
-
-            //oss文件写入
-            this.zipOssFiles(null, ossFilePaths, num, count, total, resolution, imagesVersion, cacheKeys, "v3");
-            log.info("打包oss文件耗时, num:{}, time:{}", num, timer.intervalRestart());
-
-            //重新写入scene.json(去掉密码访问设置)
-            this.zipGetInfoJson(num, getInfoJson);
-
-            //写入启动命令
-            this.zipBat(num, "v3", downLoadTaskBean.getLang());
-
-            //打压缩包
-            ZipUtil.zip(String.format(this.sourceLocal, num, ""), zipPath);
-
-            //上传压缩包
-            String uploadPath = String.format(this.zipOssFormat, num);
-            ossUtil.uploadFile(bucket, uploadPath, zipPath, false);
-            ServiceConfig serviceConfig = SpringUtil.getBean(ServiceConfig.class);
-
-            //更新进度100
-            String url = "/" + uploadPath + "?t=" + Calendar.getInstance().getTimeInMillis();
-            this.updateProgress(null, num, SceneDownloadProgressStatus.DOWNLOAD_SUCCESS.code(), url, "v3");
-
-        }catch (Exception e){
-            //更新进度为下载失败
-            this.updateProgress( null, num, SceneDownloadProgressStatus.DOWNLOAD_FAILED.code(), null, "v3");
-            throw e;
-        }finally {
-            FileUtil.del(zipPath);
-            FileUtil.del(String.format(this.sourceLocal, num, ""));
-        }
-    }
+//    public void downloadHandlerV3(DownLoadTaskBean downLoadTaskBean) throws Exception{
+//
+//        String num = downLoadTaskBean.getSceneNum();
+//        //zip包路径
+//        String zipPath = null;
+//
+//        try {
+//            TimeInterval timer = DateUtil.timer();
+//
+//            //删除资源目录
+//            FileUtil.del(String.format(this.sourceLocal, num, ""));
+//
+//            ScenePro scenePro = sceneProService.getByNum(num);
+//            if(Objects.isNull(scenePro))
+//                throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+//
+//            Set<String> cacheKeys = new ConcurrentHashSet<>();
+//
+//            Map<String, List<String>> allFiles = this.getAllFilesV3(num, v3localPath, bucket);
+//            List<String> ossFilePaths = allFiles.get("ossFilePaths");
+//            List<String> v3localFilePaths = allFiles.get("localFilePaths");
+//
+//            //key总个数
+//            int total = ossFilePaths.size() + v3localFilePaths.size();
+//            AtomicInteger count = new AtomicInteger(0);
+//            //定义压缩包
+//            zipPath = String.format(this.zipLocalFormat, num);
+//            File zipFile = new File(zipPath);
+//            if(!zipFile.getParentFile().exists()){
+//                zipFile.getParentFile().mkdirs();
+//            }
+//
+//            int imagesVersion =0;
+//            String resolution = "2k";
+//            JSONObject getInfoJson = this.getInfo(num);
+//            imagesVersion = getInfoJson.getInt("imagesVersion");
+//            // 转台、激光显示4k图片
+//            if(getInfoJson.getInt("sceneSource") == 3 || getInfoJson.getInt("sceneSource") == 4){
+//                resolution = "4k";
+//            }
+//
+//            //固定文件写入
+//            timer.intervalRestart();
+//            this.zipLocalFiles(v3localFilePaths, v3localPath, num, count, total, "v3");
+//            log.info("打包固定文件耗时, num:{}, time:{}", num, timer.intervalRestart());
+//
+//            //oss文件写入
+//            this.zipOssFiles(null, ossFilePaths, num, count, total, resolution, imagesVersion, cacheKeys, "v3");
+//            log.info("打包oss文件耗时, num:{}, time:{}", num, timer.intervalRestart());
+//
+//            //重新写入scene.json(去掉密码访问设置)
+//            this.zipGetInfoJson(num, getInfoJson);
+//
+//            //写入启动命令
+//            this.zipBat(num, "v3", downLoadTaskBean.getLang());
+//
+//            //打压缩包
+//            ZipUtil.zip(String.format(this.sourceLocal, num, ""), zipPath);
+//
+//            //上传压缩包
+//            String uploadPath = String.format(this.zipOssFormat, num);
+//            ossUtil.uploadFile(bucket, uploadPath, zipPath, false);
+//            ServiceConfig serviceConfig = SpringUtil.getBean(ServiceConfig.class);
+//
+//            //更新进度100
+//            String url = "/" + uploadPath + "?t=" + Calendar.getInstance().getTimeInMillis();
+//            this.updateProgress(null, num, SceneDownloadProgressStatus.DOWNLOAD_SUCCESS.code(), url, "v3");
+//
+//        }catch (Exception e){
+//            //更新进度为下载失败
+//            this.updateProgress( null, num, SceneDownloadProgressStatus.DOWNLOAD_FAILED.code(), null, "v3");
+//            throw e;
+//        }finally {
+//            FileUtil.del(zipPath);
+//            FileUtil.del(String.format(this.sourceLocal, num, ""));
+//        }
+//    }
 
     private JSONObject getInfo(String num){
         String url = String.format(v3GetInfoUrl, num);
@@ -404,7 +411,7 @@ public class SceneDownloadHandlerServiceImpl {
     }
 
     private void zipOssFiles(String bucket, List<String> ossFilePaths, String num, AtomicInteger count,
-        int total, String resolution, int imagesVersion, Set<String> cacheKeys, String version) throws Exception{
+        int total, String resolution, int imagesVersion, Set<String> cacheKeys, String version, String sourceLocal) throws Exception{
         if(CollUtil.isEmpty(ossFilePaths)){
             return;
         }
@@ -420,7 +427,7 @@ public class SceneDownloadHandlerServiceImpl {
                 @Override
                 public Boolean call() throws Exception {
                     zipOssFilesHandler(bucket, num, count, total, resolution,
-                        imagesVersion, cacheKeys,filePath, finalImageNumPath, version);
+                        imagesVersion, cacheKeys,filePath, finalImageNumPath, version, sourceLocal);
                     return true;
                 }
             };
@@ -444,7 +451,7 @@ public class SceneDownloadHandlerServiceImpl {
     private void zipOssFilesHandler(String bucket, String num,
         AtomicInteger count, int total, String resolution,
         int imagesVersion, Set<String> cacheKeys,
-        String filePath, String imageNumPath, String version) throws Exception{
+        String filePath, String imageNumPath, String version, String sourceLocal) throws Exception{
 
         if(filePath.endsWith("/")){
             //更新进度
@@ -461,7 +468,7 @@ public class SceneDownloadHandlerServiceImpl {
         if(!"notNeadCut".equals(resolution)){
             if((filePath.contains(imageNumPath + "panorama/") && filePath.contains("tiles/" + resolution))
                 || filePath.contains(imageNumPath + "tiles/" + resolution + "/")) {
-                this.processImage(num, filePath, resolution, imagesVersion, cacheKeys);
+                this.processImage(num, filePath, resolution, imagesVersion, cacheKeys, sourceLocal);
                 //更新进度
                 this.updateProgress(new BigDecimal(count.incrementAndGet()).divide(new BigDecimal(total), 6, BigDecimal.ROUND_HALF_UP),
                     num, SceneDownloadProgressStatus.DOWNLOADING.code(), null, version);
@@ -470,18 +477,17 @@ public class SceneDownloadHandlerServiceImpl {
         }
 
         //其他文件打包
-        this.ProcessFiles(bucket, num, filePath, this.wwwroot, cacheKeys);
+        this.ProcessFiles(bucket, num, filePath, this.wwwroot, cacheKeys, sourceLocal);
 
         //更新进度
         this.updateProgress(new BigDecimal(count.incrementAndGet()).divide(new BigDecimal(total), 6, BigDecimal.ROUND_HALF_UP),
             num, SceneDownloadProgressStatus.DOWNLOADING.code(), null, version);
     }
 
-    private void zipLocalFiles(List<String> localFilePaths, String v3localPath, String num, AtomicInteger count, int total, String version) throws Exception{
-        String sourcePath = String.format(this.sourceLocal, num, "");
+    private void zipLocalFiles(List<String> localFilePaths, String num, AtomicInteger count, int total, String version, String sourcePath) throws Exception{
         String localPath = "v4".equals(version) ? this.v4localPath : this.v3localPath;
         for (String localFilePath : localFilePaths) {
-            try (FileInputStream in = new FileInputStream(new File(localFilePath));){
+            try (FileInputStream in = new FileInputStream(localFilePath)){
 //                this.zipInputStream(out, localFilePath.replace(v3localPath, ""), in);
                 FileUtil.copy(localFilePath, localFilePath.replace(localPath, sourcePath), true);
             }catch (Exception e){
@@ -494,16 +500,16 @@ public class SceneDownloadHandlerServiceImpl {
         }
         //写入code.txt
 //        this.zipBytes(out, "code.txt", num.getBytes());
-        FileUtil.writeUtf8String(num, String.format(sourceLocal, num, "code.txt"));
+        FileUtil.writeUtf8String(num, String.format(sourcePath, num, "code.txt"));
     }
 
-    private void zipBat(String num, String version, String lang) throws Exception{
+    private void zipBat(String num, String version, String lang, String sourceLocal) throws Exception{
         String batContent = String.format(this.exeContent, num, lang);
         if("v3".equals(version)){
             batContent = String.format(this.exeContentV3, num, lang);
         }
 //        this.zipBytes(out, exeName, batContent.getBytes());
-        FileUtil.writeUtf8String(batContent, String.format(this.sourceLocal, num, exeName));
+        FileUtil.writeUtf8String(batContent, String.format(sourceLocal, num, exeName));
 
         //更新进度为90%
         this.updateProgress(new BigDecimal("0.9").divide(new BigDecimal("0.8"), 6, BigDecimal.ROUND_HALF_UP), num,
@@ -568,24 +574,15 @@ public class SceneDownloadHandlerServiceImpl {
         return map;
     }
 
-    private void zipSceneJson(String num, SceneViewInfo sceneViewInfo) throws Exception{
+    private void zipSceneJson(String num, SceneViewInfo sceneViewInfo, String sourceLocal) throws Exception{
         //访问密码置0
         SceneEditControlsVO controls = sceneViewInfo.getControls();
         controls.setShowLock(CommonStatus.NO.code().intValue());
         String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
-        FileUtil.writeUtf8String(JSON.toJSONString(sceneViewInfo, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero), String.format(this.sourceLocal, num, this.wwwroot + sceneJsonPath));
-    }
-
-    private void zipGetInfoJson(String num, JSONObject getInfo) throws Exception{
-
-        //访问密码置0
-        String getInfoKey = String.format("data/data%s/", num) + "getInfo.json";
-
-        String getInfoStr = getInfo.toString().replace(this.publicUrl , "");
-        FileUtil.writeUtf8String(getInfoStr, String.format(this.sourceLocal, num, this.wwwroot + getInfoKey));
+        FileUtil.writeUtf8String(JSON.toJSONString(sceneViewInfo, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero), String.format(sourceLocal, num, this.wwwroot + sceneJsonPath));
     }
 
-    private void processImage(String sceneNum, String key, String resolution, int imagesVersion, Set<String> imgKeys) throws Exception{
+    private void processImage(String sceneNum, String key, String resolution, int imagesVersion, Set<String> imgKeys, String sourceLocal) throws Exception{
 
         if(key.contains("x-oss-process") || key.endsWith("/")){
             return;
@@ -650,7 +647,7 @@ public class SceneDownloadHandlerServiceImpl {
         HttpUtil.downloadFile(url, path);
     }
 
-    public void ProcessFiles(String bucket, String num, String key, String prefix, Set<String> cacheKeys) throws Exception{
+    public void ProcessFiles(String bucket, String num, String key, String prefix, Set<String> cacheKeys, String sourceLocal) throws Exception{
         if(cacheKeys.contains(key)){
             return;
         }

+ 3 - 1
src/main/java/com/fdkankan/scene/service/impl/SceneDownloadLogServiceImpl.java

@@ -76,7 +76,7 @@ public class SceneDownloadLogServiceImpl extends ServiceImpl<ISceneDownloadLogMa
 
 
     @Override
-    public ResultData downOfflineScene(String num, String lang) {
+    public ResultData downOfflineScene(String num, String lang, String resultPath) {
 
         ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
         if(Objects.isNull(scenePlus)){
@@ -134,12 +134,14 @@ public class SceneDownloadLogServiceImpl extends ServiceImpl<ISceneDownloadLogMa
             sceneDownloadLog.setSceneVersion(version);
             sceneDownloadLog.setSysVersion("v4");
             sceneDownloadLog.setLang(lang);
+            sceneDownloadLog.setDownloadUrl(resultPath);
             this.save(sceneDownloadLog);
 
             Map<String,String> params = new HashMap<>(2);
             params.put("type","local");
             params.put("num",num);
             params.put("lang", lang);
+            params.put("resultPath", resultPath);
             redisUtil.lRightPush(RedisKey.SCENE_DOWNLOADS_TASK_V4, JSONObject.toJSONString(params));
         }