|
@@ -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);
|
|
|
+ }
|
|
|
}
|