dengsixing 2 months ago
parent
commit
fe178e5afd

+ 5 - 1
src/main/java/com/fdkankan/scene/SceneApplication.java

@@ -9,7 +9,7 @@ import com.fdkankan.common.constant.CommonSuccessStatus;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.scene.config.FdkkLaserConfig;
-import com.fdkankan.scene.entity.SceneDownloadLog;
+import com.fdkankan.scene.config.RedisKeyExt;import com.fdkankan.scene.entity.SceneDownloadLog;
 import com.fdkankan.scene.service.ISceneDownloadLogService;
 import lombok.extern.slf4j.Slf4j;
 import org.mybatis.spring.annotation.MapperScan;
@@ -65,11 +65,15 @@ public class SceneApplication {
         for (Object o : PREFIX_DOWNLOAD_PROGRESS_V4_SET) {
             redisUtil.del(o.toString());
         }
+        redisUtil.del(RedisKey.SCENE_DOWNLOADS_TASK_V4);
+        redisUtil.del(RedisKeyExt.BUILD_SCENE_OFFLINE_MESH);
 
         final ISceneDownloadLogService sceneDownloadLogService = SpringUtil.getBean(ISceneDownloadLogService.class);
         sceneDownloadLogService.remove(new LambdaQueryWrapper<SceneDownloadLog>().eq(SceneDownloadLog::getStatus, CommonSuccessStatus.WAITING.code()));
 
 
+
+
 //        String nameSpace = SocketIoConstant.SCENE_HANDLER_SPACE.replace("/", "");
 //        Collection<String> keys = cache.keys(nameSpace + "*");
 //        for (String key : keys) {

+ 7 - 0
src/main/java/com/fdkankan/scene/config/RedisKeyExt.java

@@ -0,0 +1,7 @@
+package com.fdkankan.scene.config;
+
+public class RedisKeyExt {
+
+    public static final String BUILD_SCENE_OFFLINE_MESH = "BUILD:SCENE:OFFLINE:MESH";
+
+}

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

@@ -30,4 +30,6 @@ public interface ISceneDownloadLogService extends IService<SceneDownloadLog> {
 
     ResultData downloadScene(SceneDownloadParamVO param);
 
+    void setBuildSceneOffline();
+
 }

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

@@ -160,38 +160,7 @@ public class SceneDownloadHandlerServiceImpl {
                 //删除正在下载任务
                 redisUtil.lRemove(RedisKey.SCENE_DOWNLOAD_ING, 1, num);
             }
-        }
-    }
-
-    @Async("sceneDownLoadExecutror")
-    public void downloadV3(DownLoadTaskBean downLoadTaskBean){
-        //场景码
-        String num = null;
-
-        try {
-            num = downLoadTaskBean.getSceneNum();
-
-            log.info("v3场景下载开始 - num[{}] - threadName[{}]", num, Thread.currentThread().getName());
-
-            long startTime = Calendar.getInstance().getTimeInMillis();
-
-            //执行场景下载逻辑
-//            this.downloadHandlerV3(downLoadTaskBean);
-
-            //耗时
-            long consumeTime = Calendar.getInstance().getTimeInMillis() - startTime;
-
-            log.info("v3场景下载结束 - num[{}] - threadName[{}] - consumeTime[{}]", num, Thread.currentThread().getName(), consumeTime);
-
-        }catch (Exception e){
-            log.error(ExceptionUtil.stacktraceToString(e));
-        }finally {
-            if(StrUtil.isNotEmpty(num)){
-                //本地正在下载任务出队
-                CurrentDownloadNumUtil.removeSceneNum(num, "v3");
-                //删除正在下载任务
-                redisUtil.lRemove(RedisKey.SCENE_V3_DOWNLOAD_ING, 1, num);
-            }
+            sceneDownloadLogService.setBuildSceneOffline();
         }
     }
 
@@ -313,84 +282,6 @@ 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, ""));
-//        }
-//    }
-
     private JSONObject getInfo(String num){
         String url = String.format(v3GetInfoUrl, num);
         String getInfoResult = HttpUtil.get(url);

+ 32 - 0
src/main/java/com/fdkankan/scene/service/impl/SceneDownloadLogServiceImpl.java

@@ -12,8 +12,10 @@ import com.fdkankan.common.util.JwtUtil;
 import com.fdkankan.model.constants.UploadFilePath;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.scene.bean.CurrentDownloadNumUtil;
 import com.fdkankan.scene.bean.SceneJsonBean;
 import com.fdkankan.scene.config.FdkkLaserConfig;
+import com.fdkankan.scene.config.RedisKeyExt;
 import com.fdkankan.scene.config.ServiceConfig;
 import com.fdkankan.scene.entity.*;
 import com.fdkankan.scene.mapper.ISceneDownloadLogMapper;
@@ -143,8 +145,12 @@ public class SceneDownloadLogServiceImpl extends ServiceImpl<ISceneDownloadLogMa
             params.put("lang", lang);
             params.put("resultPath", resultPath);
             redisUtil.lRightPush(RedisKey.SCENE_DOWNLOADS_TASK_V4, JSONObject.toJSONString(params));
+
+            redisUtil.set(RedisKeyExt.BUILD_SCENE_OFFLINE_MESH, "1");
         }
 
+        this.setBuildSceneOffline();
+
         return ResultData.ok(result);
     }
 
@@ -346,4 +352,30 @@ public class SceneDownloadLogServiceImpl extends ServiceImpl<ISceneDownloadLogMa
 
         return ResultData.ok(result);
     }
+
+    @Override
+    public synchronized void setBuildSceneOffline() {
+
+        //查询队列中是否有排队
+        long taskCount = redisUtil.lGetSize(RedisKey.SCENE_DOWNLOADS_TASK_V4);
+        log.info("mesh离线包下载排队个数:{}", taskCount);
+
+        //查询是否有正在下载
+        int downloadCount = CurrentDownloadNumUtil.cntDownloadingLocal("v4");
+        log.info("mesh离线包下载中个数:{}", downloadCount);
+
+        if(taskCount > 0 || downloadCount > 0){
+            redisUtil.set(RedisKeyExt.BUILD_SCENE_OFFLINE_MESH, "1");
+        }else{
+            redisUtil.del(RedisKeyExt.BUILD_SCENE_OFFLINE_MESH);
+        }
+
+
+
+
+
+
+
+
+    }
 }