|
|
@@ -0,0 +1,111 @@
|
|
|
+package com.fdkankan.scene;
|
|
|
+
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.scene.config.FdkkLaserConfig;
|
|
|
+import com.fdkankan.scene.config.RedisKeyExt;
|
|
|
+import com.fdkankan.scene.constant.BuildType;
|
|
|
+import com.fdkankan.scene.entity.SceneFileBuildEntity;
|
|
|
+import com.fdkankan.scene.service.ISceneDownloadLogService;
|
|
|
+import com.fdkankan.scene.service.SceneFileBuildService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.CommandLineRunner;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileWriter;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Xiewj
|
|
|
+ * @date 2023/12/14
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class ApplicationRunner implements CommandLineRunner {
|
|
|
+ @Autowired
|
|
|
+ private SceneFileBuildService sceneFileBuildService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneDownloadLogService sceneDownloadLogService;
|
|
|
+ @Resource
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+ private static String keyFormat = "touch:scene:download:num:%s";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(String... args) throws Exception {
|
|
|
+ initServer();
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ Integer javaPort = config.getInteger("laserPort");
|
|
|
+ fdkkLaserConfig.setLaserPort(javaPort);
|
|
|
+
|
|
|
+
|
|
|
+ redisUtil.del(RedisKey.SCENE_DOWNLOAD_ING);
|
|
|
+ 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) {
|
|
|
+ redisUtil.del(o.toString());
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<SceneFileBuildEntity> offlineBuildList = sceneFileBuildService.findBuildListByStatusAndBuildType(Arrays.asList(1),Arrays.asList(BuildType.BUILD_MESH_OFFLINE));
|
|
|
+ for (SceneFileBuildEntity sceneFileBuildEntity : offlineBuildList) {
|
|
|
+ log.info("处理排队离线包{}",sceneFileBuildEntity);
|
|
|
+ if (!FileUtil.exist(sceneFileBuildEntity.getResultPath())){
|
|
|
+ //路径不存在改为失败
|
|
|
+ sceneFileBuildEntity.setBuildStatus(-1);
|
|
|
+ sceneFileBuildService.updateById(sceneFileBuildEntity);
|
|
|
+ if (sceneFileBuildEntity.getBuildType().equals(BuildType.BUILD_MESH_OFFLINE)){
|
|
|
+ //路径不存在改为失败
|
|
|
+ sceneDownloadLogService.removeBySceneNum(sceneFileBuildEntity.getSceneNum());
|
|
|
+ String key = String.format(RedisKey.PREFIX_DOWNLOAD_PROGRESS_V4, sceneFileBuildEntity.getSceneNum());
|
|
|
+ redisUtil.del(key);
|
|
|
+ redisUtil.lRemove(RedisKey.SCENE_DOWNLOAD_ING, 1, sceneFileBuildEntity.getSceneNum());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //查询排队中的离线包,重新入队列
|
|
|
+ // laser public static final String SCENE_DOWNLOADS_TASK = "scene:downloads:task:";
|
|
|
+ // mesh public static final String SCENE_DOWNLOADS_TASK_V4 = "scene:downloads:task:v4";
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|