dengsixing hai 5 meses
pai
achega
7f05f7e26e

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

@@ -2,14 +2,11 @@ package com.fdkankan.scene.controller;
 
 
 import com.fdkankan.scene.service.ISceneDownloadLogService;
+import com.fdkankan.scene.vo.SceneDownloadParamVO;
 import com.fdkankan.web.response.ResultData;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -51,6 +48,18 @@ public class SceneDownloadLogController {
         return sceneDownloadLogService.downloadUpDateStatus(num);
     }
 
+    @GetMapping("/downloadDetail")
+    public ResultData downloadSceneDetail(@RequestBody SceneDownloadParamVO param){
+        log.info("downOfflineSceneDetail");
+        return ResultData.ok(sceneDownloadLogService.downOfflineSceneDetail(param));
+    }
+
+    @PostMapping()
+    public ResultData downloadScene(@RequestBody SceneDownloadParamVO param){
+        log.info("downloadScene");
+        return ResultData.ok(sceneDownloadLogService.downloadScene(param));
+    }
+
 
 
 

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

@@ -2,9 +2,12 @@ package com.fdkankan.scene.service;
 
 import com.fdkankan.scene.entity.SceneDownloadLog;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.scene.vo.SceneDownloadParamVO;
 import com.fdkankan.web.response.ResultData;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.util.Map;
+
 /**
  * <p>
  *  服务类
@@ -23,4 +26,8 @@ public interface ISceneDownloadLogService extends IService<SceneDownloadLog> {
 
     ResultData downOfflineSceneCheck(String num, String lang);
 
+    Map<String, Object> downOfflineSceneDetail(SceneDownloadParamVO param);
+
+    ResultData downloadScene(SceneDownloadParamVO param);
+
 }

+ 20 - 20
src/main/java/com/fdkankan/scene/service/impl/SceneDownLoadServiceImpl.java

@@ -55,26 +55,26 @@ public class SceneDownLoadServiceImpl implements ISceneDownLoadService {
 
     }
 
-    @Override
-    public void processV3() throws Exception {
-
-        //统计本节点正在下载任务数量
-        int downloadIngCnt = CurrentDownloadNumUtil.cntDownloadingLocal("v3");
-        //如果正在下载的场景大于最大线程数,不往下执行
-        if(downloadIngCnt >= downloadThreadMax){
-            return;
-        }
-
-        for(int i = 0; i < downloadThreadMax - downloadIngCnt; i++){
-            DownLoadTaskBean downLoadTaskBean = this.getTaskSceneNum("v3");
-            //获取任务队列中队头场景码,如果是空,标识没有场景要下载,则退出程序
-            if(Objects.isNull(downLoadTaskBean)){
-                continue;
-            }
-            handlerService.downloadV3(downLoadTaskBean);
-        }
-
-    }
+//    @Override
+//    public void processV3() throws Exception {
+//
+//        //统计本节点正在下载任务数量
+//        int downloadIngCnt = CurrentDownloadNumUtil.cntDownloadingLocal("v3");
+//        //如果正在下载的场景大于最大线程数,不往下执行
+//        if(downloadIngCnt >= downloadThreadMax){
+//            return;
+//        }
+//
+//        for(int i = 0; i < downloadThreadMax - downloadIngCnt; i++){
+//            DownLoadTaskBean downLoadTaskBean = this.getTaskSceneNum("v3");
+//            //获取任务队列中队头场景码,如果是空,标识没有场景要下载,则退出程序
+//            if(Objects.isNull(downLoadTaskBean)){
+//                continue;
+//            }
+//            handlerService.downloadV3(downLoadTaskBean);
+//        }
+//
+//    }
 
     private DownLoadTaskBean getTaskSceneNum(String version) throws Exception{
         //redis待下载任务出队

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

@@ -266,13 +266,13 @@ public class SceneDownloadHandlerServiceImpl {
 //            ZipUtil.zip(String.format(this.sourceLocal, num, ""), zipPath, Charset.forName("GBK"), true);
 
             //上传压缩包
-            String uploadPath = String.format(this.zipOssFormat, num);
-            ossUtil.uploadFile(bucket, uploadPath, zipPath, false);
+//            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, "v4");
+//            String url = "/" + uploadPath + "?t=" + Calendar.getInstance().getTimeInMillis();
+            this.updateProgress(null, num, SceneDownloadProgressStatus.DOWNLOAD_SUCCESS.code(), resultPath, "v4");
 
         }catch (Exception e){
             //更新进度为下载失败

+ 108 - 4
src/main/java/com/fdkankan/scene/service/impl/SceneDownloadLogServiceImpl.java

@@ -6,10 +6,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.fdkankan.common.constant.ErrorCode;
-import com.fdkankan.common.constant.SceneDownloadProgressStatus;
-import com.fdkankan.common.constant.SceneVersionType;
-import com.fdkankan.common.constant.UploadStatus;
+import com.fdkankan.common.constant.*;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.JwtUtil;
 import com.fdkankan.model.constants.UploadFilePath;
@@ -23,6 +20,8 @@ import com.fdkankan.scene.mapper.ISceneDownloadLogMapper;
 import com.fdkankan.scene.oss.OssUtil;
 import com.fdkankan.scene.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.scene.vo.DownloadVO;
+import com.fdkankan.scene.vo.SceneDownloadParamVO;
 import com.fdkankan.web.bean.DownLoadProgressBean;
 import com.fdkankan.web.response.ResultData;
 import lombok.extern.slf4j.Slf4j;
@@ -210,4 +209,109 @@ public class SceneDownloadLogServiceImpl extends ServiceImpl<ISceneDownloadLogMa
         }
         return ResultData.ok(result);
     }
+
+    @Override
+    public Map<String, Object> downOfflineSceneDetail(SceneDownloadParamVO param) {
+
+        String num = param.getSceneCode();
+//        String lang = param.getLang();
+        Map<String, Object> result = new HashMap<>();
+        SceneDownloadLog sceneDownloadLog = this.getOne(
+                new LambdaQueryWrapper<SceneDownloadLog>()
+                .eq(SceneDownloadLog::getSceneNum, num)
+//                .eq(SceneDownloadLog::getLang, lang)
+                .last("limit 1"));
+        if(Objects.isNull(sceneDownloadLog)){//如果没有记录,则没有生成过
+            result.put("status", -1);
+            return result;
+        }
+
+        Integer status = sceneDownloadLog.getStatus();
+        //成功或者失败,直接返回
+        if(status == DownloadStatus.SUCCESS.code() || status == DownloadStatus.FAILD.code()){
+            result.put("status", status);
+            result.put("path", sceneDownloadLog.getDownloadUrl());
+            return result;
+        }
+        //下载中,从redis中获取下载进度,并根据状态更新数据库
+        String key=String.format(RedisKey.PREFIX_DOWNLOAD_PROGRESS_V4,num);
+        if (!redisUtil.hasKey(key)){
+            result.put("status", DownloadStatus.DOWNLOADING.code());
+            result.put("percent", 0);
+            return result;
+        }
+        DownLoadProgressBean downLoadProgressBean = new DownLoadProgressBean();
+        String processStr = redisUtil.get(key);
+        downLoadProgressBean = JSONObject.parseObject(processStr, DownLoadProgressBean.class);
+        if (downLoadProgressBean.getStatus()== 1002){//下载成功,更新数据库表
+            //写库
+            sceneDownloadLog.setStatus(DownloadStatus.SUCCESS.code());
+            sceneDownloadLog.setDownloadUrl(downLoadProgressBean.getUrl());
+            this.updateById(sceneDownloadLog);
+//            final Scene scene = sceneService.getBySceneCode(num);
+//            downLoadProgressBean.setUrl(this.publicUrl+":"+fdkkLaserConfig.getLaserPort()+ "/" + scene.getMapping() +downLoadProgressBean.getUrl());
+            result.put("status", DownloadStatus.SUCCESS.code());
+            result.put("percent", 100);
+            return result;
+        }
+        if(downLoadProgressBean.getStatus()== 1003){//下载失败,更新数据库表
+            //写库
+            sceneDownloadLog.setStatus(DownloadStatus.FAILD.code());
+            this.updateById(sceneDownloadLog);
+            result.put("status", DownloadStatus.SUCCESS.code());
+            result.put("percent", downLoadProgressBean.getPercent());
+            return result;
+        }
+        //下载中
+        result.put("status", DownloadStatus.DOWNLOADING.code());
+        result.put("percent", downLoadProgressBean.getPercent());
+        return result;
+    }
+
+    @Override
+    public ResultData downloadScene(SceneDownloadParamVO param) {
+
+        String num = param.getSceneCode();
+        String lang = param.getLang();
+        String resultPath = param.getDir();
+        ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
+        if(Objects.isNull(scenePlus)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+        }
+        ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
+        String bucket = scenePlusExt.getYunFileBucket();
+
+        Scene scene = sceneService.getBySceneCode(num);
+
+        String mapping = scene.getMapping();
+
+        Map<String, Object> result = new HashMap<>();
+        String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", num);
+        String sceneJson = ossUtil.getFileContent(bucket, sceneJsonPath);
+        SceneJsonBean sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
+        int version = sceneJsonBean.getVersion();
+//        redisUtil.set(String.format(keyFormat, num), "1");
+
+
+        //清除之前的下载记录
+        this.remove(new LambdaQueryWrapper<SceneDownloadLog>().eq(SceneDownloadLog::getSceneNum, num));
+
+        //写入新的记录
+        SceneDownloadLog sceneDownloadLog = new SceneDownloadLog();
+        sceneDownloadLog.setSceneNum(num);
+        sceneDownloadLog.setSceneVersion(version);
+        sceneDownloadLog.setSysVersion("v4");
+        sceneDownloadLog.setLang(param.getLang());
+        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));
+
+        return ResultData.ok(result);
+    }
 }

+ 9 - 1
src/main/java/com/fdkankan/scene/vo/SceneDownloadParamVO.java

@@ -18,6 +18,14 @@ public class SceneDownloadParamVO {
      * 场景码
      */
     @NotBlank(message = "场景码不能为空")
-    private String sceneNum;
+    private String sceneCode;
+
+    /**
+     * 语言
+     */
+    private String lang;
+
+    private String dir;
+
 
 }