|
|
@@ -1,21 +1,30 @@
|
|
|
package com.fdkankan.scene;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fdkankan.common.constant.CommonStatus;
|
|
|
import com.fdkankan.common.constant.CommonSuccessStatus;
|
|
|
import com.fdkankan.common.constant.DownloadStatus;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.scene.bean.DownLoadTaskBean;
|
|
|
import com.fdkankan.scene.config.FdkkLaserConfig;
|
|
|
import com.fdkankan.scene.config.RedisKeyExt;
|
|
|
import com.fdkankan.scene.constant.BuildType;
|
|
|
+import com.fdkankan.scene.entity.SceneDownloadLog;
|
|
|
import com.fdkankan.scene.entity.SceneFileBuildEntity;
|
|
|
+import com.fdkankan.scene.entity.ScenePlus;
|
|
|
import com.fdkankan.scene.service.ISceneDownloadLogService;
|
|
|
+import com.fdkankan.scene.service.IScenePlusService;
|
|
|
import com.fdkankan.scene.service.SceneFileBuildService;
|
|
|
+import com.fdkankan.scene.vo.SceneDownloadParamVO;
|
|
|
+import com.google.api.client.json.Json;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
@@ -25,9 +34,11 @@ import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author Xiewj
|
|
|
@@ -45,6 +56,8 @@ public class ApplicationRunner implements CommandLineRunner {
|
|
|
|
|
|
private static String keyFormat = "touch:scene:download:num:%s";
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
@Override
|
|
|
public void run(String... args) throws Exception {
|
|
|
initServer();
|
|
|
@@ -52,14 +65,7 @@ public class ApplicationRunner implements CommandLineRunner {
|
|
|
private void initServer() throws IOException {
|
|
|
|
|
|
FdkkLaserConfig fdkkLaserConfig = SpringUtil.getBean(FdkkLaserConfig.class);
|
|
|
- String stateConfigOne = fdkkLaserConfig.getBinPath() + File.separator + ".v4state";
|
|
|
- if (FileUtil.exist(stateConfigOne)) {
|
|
|
- log.info("state文件存在");
|
|
|
- FileWriter writer = new FileWriter(FileUtil.file(stateConfigOne));
|
|
|
- writer.write("1");
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
+
|
|
|
String setting = fdkkLaserConfig.getSettingJson();
|
|
|
String data = FileUtil.readString(setting, "UTF-8");
|
|
|
JSONObject config = JSONObject.parseObject(data);
|
|
|
@@ -67,13 +73,53 @@ public class ApplicationRunner implements CommandLineRunner {
|
|
|
fdkkLaserConfig.setLaserPort(javaPort);
|
|
|
|
|
|
//项目重启,正在下载中的场景要改为失败状态,并删除redis缓存
|
|
|
- List<String> downloadIngNums = redisUtil.lGet(RedisKey.SCENE_DOWNLOAD_ING, 0, -1);
|
|
|
- if(CollUtil.isNotEmpty(downloadIngNums)){
|
|
|
- for (String downloadIngNum : downloadIngNums) {
|
|
|
- sceneDownloadLogService.updateStatusSceneNum(downloadIngNum, DownloadStatus.FAILD.code());
|
|
|
+// List<String> downloadIngNums = redisUtil.lGet(RedisKey.SCENE_DOWNLOAD_ING, 0, -1);
|
|
|
+// if(CollUtil.isNotEmpty(downloadIngNums)){
|
|
|
+// for (String downloadIngNum : downloadIngNums) {
|
|
|
+// sceneDownloadLogService.updateStatusSceneNum(downloadIngNum, DownloadStatus.FAILD.code());
|
|
|
+// }
|
|
|
+// redisUtil.del(RedisKey.SCENE_DOWNLOAD_ING);
|
|
|
+// }
|
|
|
+
|
|
|
+// //兜底,ing队列没有,表记录有下载中的,但是排队队列中没有,就改为失败(应对的特殊情况:下载逻辑走到finally删除了ing队列还没来得及去改状态时,程序推出了)
|
|
|
+// List<String> taskStrs = redisUtil.lGet(RedisKey.SCENE_DOWNLOADS_TASK_V4, 0, -1);
|
|
|
+// List<SceneDownloadLog> list = sceneDownloadLogService.list(new LambdaQueryWrapper<SceneDownloadLog>().eq(SceneDownloadLog::getStatus, DownloadStatus.DOWNLOADING.code()));
|
|
|
+// if(CollUtil.isNotEmpty(list)){
|
|
|
+// f1: for (SceneDownloadLog sceneDownloadLog : list) {
|
|
|
+// if(CollUtil.isEmpty(taskStrs)){
|
|
|
+// sceneDownloadLog.setStatus(DownloadStatus.FAILD.code());
|
|
|
+// sceneDownloadLog.setUpdateTime(null);
|
|
|
+// sceneDownloadLogService.updateById(sceneDownloadLog);
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// for (String taskStr : taskStrs) {
|
|
|
+// if(taskStr.contains(sceneDownloadLog.getSceneNum())){
|
|
|
+// sceneDownloadLog.setStatus(DownloadStatus.FAILD.code());
|
|
|
+// sceneDownloadLog.setUpdateTime(null);
|
|
|
+// sceneDownloadLogService.updateById(sceneDownloadLog);
|
|
|
+// continue f1;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ //删除正在下载队列
|
|
|
+ redisUtil.del(RedisKey.SCENE_DOWNLOAD_ING);
|
|
|
+ //检测如若状态为0的直接改为失败
|
|
|
+ redisUtil.del(RedisKey.SCENE_DOWNLOADS_TASK_V4);
|
|
|
+ List<SceneDownloadLog> list = sceneDownloadLogService.list(new LambdaQueryWrapper<SceneDownloadLog>().eq(SceneDownloadLog::getStatus, DownloadStatus.DOWNLOADING.code()));
|
|
|
+ if(CollUtil.isNotEmpty(list)){
|
|
|
+ for (SceneDownloadLog sceneDownloadLog : list) {
|
|
|
+ sceneDownloadLog.setStatus(DownloadStatus.FAILD.code());
|
|
|
+ sceneDownloadLog.setUpdateTime(null);
|
|
|
+ String key = String.format(RedisKey.PREFIX_DOWNLOAD_PROGRESS_V4, sceneDownloadLog.getSceneNum());
|
|
|
+ redisUtil.del(key);//清楚进度条缓存
|
|
|
}
|
|
|
- redisUtil.del(RedisKey.SCENE_DOWNLOAD_ING);
|
|
|
+ sceneDownloadLogService.updateBatchById(list);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
Set keyFormatSet = redisUtil.keys(String.format(keyFormat, "*"));
|
|
|
Set PREFIX_DOWNLOAD_PROGRESS_V4_SET = redisUtil.keys(String.format(RedisKey.PREFIX_DOWNLOAD_PROGRESS_V4, "*"));
|
|
|
for (Object o : keyFormatSet) {
|
|
|
@@ -87,6 +133,7 @@ public class ApplicationRunner implements CommandLineRunner {
|
|
|
|
|
|
|
|
|
|
|
|
+ //状态,0-未建模,1-等待建模(队列中),2-建模中,3-建模暂停,4-建模成功,-1-建模失败
|
|
|
List<SceneFileBuildEntity> offlineBuildList = sceneFileBuildService.findBuildListByStatusAndBuildType(Arrays.asList(1),Arrays.asList(BuildType.BUILD_MESH_OFFLINE));
|
|
|
for (SceneFileBuildEntity sceneFileBuildEntity : offlineBuildList) {
|
|
|
log.info("处理排队离线包{}",sceneFileBuildEntity);
|
|
|
@@ -94,19 +141,19 @@ public class ApplicationRunner implements CommandLineRunner {
|
|
|
//路径不存在改为失败
|
|
|
sceneFileBuildEntity.setBuildStatus(-1);
|
|
|
sceneFileBuildService.updateById(sceneFileBuildEntity);
|
|
|
- if (sceneFileBuildEntity.getBuildType().equals(BuildType.BUILD_MESH_OFFLINE)){
|
|
|
- //路径不存在改为失败
|
|
|
-// sceneDownloadLogService.updateStatusSceneNum(sceneFileBuildEntity.getSceneNum(), DownloadStatus.FAILD.code());
|
|
|
- String key = String.format(RedisKey.PREFIX_DOWNLOAD_PROGRESS_V4, sceneFileBuildEntity.getSceneNum());
|
|
|
- redisUtil.del(key);
|
|
|
- redisUtil.lRemove(RedisKey.SCENE_DOWNLOAD_ING, 1, sceneFileBuildEntity.getSceneNum());
|
|
|
- }
|
|
|
+ continue;
|
|
|
}
|
|
|
switch (sceneFileBuildEntity.getBuildType()){
|
|
|
case BuildType.BUILD_MESH_OFFLINE:
|
|
|
if (FileUtil.exist(sceneFileBuildEntity.getResultPath())){
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(sceneFileBuildEntity.getExt());
|
|
|
- redisUtil.lRightPush(RedisKey.SCENE_DOWNLOADS_TASK_V4, jsonObject.toJSONString());
|
|
|
+ SceneDownloadParamVO sceneDownloadParamVO = JSON.parseObject(sceneFileBuildEntity.getExt(), SceneDownloadParamVO.class);
|
|
|
+ //{"sceneCode":"1993286825330085888","lang":"zh","fusion":false,"dir":"C:\\Users\\Administrator\\Downloads\\offline\\oooobbbbjjjj\\202512011650091000","type":"local",
|
|
|
+ // "num":"1993286825330085888","resultPath":"C:\\Users\\Administrator\\Downloads\\offline\\oooobbbbjjjj\\202512011650091000"}
|
|
|
+// redisUtil.lRightPush(RedisKey.SCENE_DOWNLOADS_TASK_V4, jsonObject.toJSONString());
|
|
|
+ ScenePlus scenePlusByNum = scenePlusService.getScenePlusByNum(sceneDownloadParamVO.getSceneCode());
|
|
|
+ if (scenePlusByNum!=null){
|
|
|
+ sceneDownloadLogService.downloadScene(sceneDownloadParamVO);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
@@ -115,7 +162,14 @@ public class ApplicationRunner implements CommandLineRunner {
|
|
|
//查询排队中的离线包,重新入队列
|
|
|
// laser public static final String SCENE_DOWNLOADS_TASK = "scene:downloads:task:";
|
|
|
// mesh public static final String SCENE_DOWNLOADS_TASK_V4 = "scene:downloads:task:v4";
|
|
|
-
|
|
|
+ String stateConfigOne = fdkkLaserConfig.getBinPath() + File.separator + ".v4state";
|
|
|
+ if (FileUtil.exist(stateConfigOne)) {
|
|
|
+ log.info("state文件存在");
|
|
|
+ FileWriter writer = new FileWriter(FileUtil.file(stateConfigOne));
|
|
|
+ writer.write("1");
|
|
|
+ writer.flush();
|
|
|
+ writer.close();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|