|
@@ -6,6 +6,7 @@ import cn.hutool.core.io.watch.Watcher;
|
|
|
import cn.hutool.core.lang.Console;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.common.constant.CommonOperStatus;
|
|
|
import com.fdkankan.common.constant.ModelingBuildStatus;
|
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
import com.fdkankan.model.utils.ComputerUtil;
|
|
@@ -15,13 +16,18 @@ import com.fdkankan.modeling.entity.BuildLog;
|
|
|
import com.fdkankan.modeling.exception.BuildException;
|
|
|
import com.fdkankan.modeling.handler.LaserSceneObjGenerateHandler;
|
|
|
import com.fdkankan.modeling.service.IBuildLogService;
|
|
|
+import com.fdkankan.modeling.service.IBuildService;
|
|
|
+import com.fdkankan.modeling.service.ISceneBuildProcessLogService;
|
|
|
import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
|
|
|
+import com.fdkankan.rabbitmq.bean.BuildSceneProcessLogMessage;
|
|
|
import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
|
|
|
import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
|
import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
import com.rabbitmq.client.Channel;
|
|
|
+import com.fdkankan.model.constants.SceneBuildProcessType;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.time.StopWatch;
|
|
|
import org.springframework.amqp.core.Message;
|
|
|
import org.springframework.amqp.rabbit.annotation.Queue;
|
|
@@ -59,6 +65,8 @@ public class RabbitMqListener {
|
|
|
private String queueModelingCall;
|
|
|
@Value("${queue.modeling.modeling-post}")
|
|
|
private String queueModelingPost;
|
|
|
+ @Value("${queue.modeling.modeling-process-log}")
|
|
|
+ private String queueModelingProcessLog;
|
|
|
|
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
@@ -74,6 +82,11 @@ public class RabbitMqListener {
|
|
|
|
|
|
@Autowired
|
|
|
private LaserSceneObjGenerateHandler laserSceneObjGenerateHandler;
|
|
|
+ @Autowired
|
|
|
+ private ISceneBuildProcessLogService sceneBuildProcessLogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBuildService buildService;
|
|
|
|
|
|
/**
|
|
|
* 场景计算
|
|
@@ -128,6 +141,12 @@ public class RabbitMqListener {
|
|
|
//开始计时
|
|
|
StopWatch watch = new StopWatch();
|
|
|
watch.start();
|
|
|
+
|
|
|
+ String num = message.getSceneNum();
|
|
|
+
|
|
|
+ //发送记录计算状态为计算中
|
|
|
+ this.sendCallBuildProcessLog(message, ModelingBuildStatus.CALCULATING);
|
|
|
+
|
|
|
final BuildSceneResultBean buildSceneResult = new BuildSceneResultBean();
|
|
|
String resultQueueName = StrUtil.isNotBlank(message.getResultReceiverMqName()) ?
|
|
|
message.getResultReceiverMqName() : queueModelingPost;
|
|
@@ -147,6 +166,7 @@ public class RabbitMqListener {
|
|
|
}
|
|
|
});
|
|
|
status = future.get(SysConstants.modelTimeOut, TimeUnit.HOURS);
|
|
|
+
|
|
|
//结束计时
|
|
|
watch.stop();
|
|
|
buildLog.setDuration(watch.getTime(TimeUnit.SECONDS));
|
|
@@ -213,6 +233,14 @@ public class RabbitMqListener {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+
|
|
|
+ // 检测计算结果文件是否有生成
|
|
|
+ String resultsPath = path + File.separator + "results" + File.separator;
|
|
|
+ if (!new File(resultsPath + "upload.json").exists()) {
|
|
|
+ log.error("未检测到计算结果文件:upload.json");
|
|
|
+ return ModelingBuildStatus.FAILED;
|
|
|
+ }
|
|
|
+
|
|
|
return ModelingBuildStatus.SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -222,7 +250,7 @@ public class RabbitMqListener {
|
|
|
*/
|
|
|
this.deleteCachesAndResult(path,message);
|
|
|
|
|
|
- Map<String, String> dataMap = ComputerUtil.getTypeString(cameraType, algorithm, resolution,dataJson);
|
|
|
+ Map<String, String> dataMap = buildService.getTypeString(cameraType, algorithm, resolution,dataJson);
|
|
|
|
|
|
String splitType = dataMap.get("splitType");
|
|
|
String skyboxType = dataMap.get("skyboxType");
|
|
@@ -231,8 +259,13 @@ public class RabbitMqListener {
|
|
|
//计算模型并返回需要上传oss的文件集合
|
|
|
ComputerUtil.computer(num, path, buildType);
|
|
|
|
|
|
+ // 检测计算结果文件是否有生成
|
|
|
+ String resultsPath = path + File.separator + "results" + File.separator;
|
|
|
+ if (!new File(resultsPath + "upload.json").exists()) {
|
|
|
+ log.error("未检测到计算结果文件:upload.json");
|
|
|
+ return ModelingBuildStatus.FAILED;
|
|
|
+ }
|
|
|
log.info("八目上完oss结束修改数据:"+num);
|
|
|
-
|
|
|
return ModelingBuildStatus.SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -291,9 +324,20 @@ public class RabbitMqListener {
|
|
|
//发送计算结果mq
|
|
|
buildSceneResult.setDuration(buildLog.getDuration());
|
|
|
this.sendCallResult(message, buildSceneResult);
|
|
|
+ this.sendCallBuildProcessLog(message, buildStatus);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送计算流程状态日志mq
|
|
|
+ * @param message
|
|
|
+ * @param buildStatus
|
|
|
+ */
|
|
|
+ private void sendCallBuildProcessLog(BuildSceneCallMessage message, ModelingBuildStatus buildStatus){
|
|
|
+ rabbitMqProducer.sendByWorkQueue(queueModelingProcessLog,
|
|
|
+ BuildSceneProcessLogMessage.builder().num(message.getSceneNum()).buildStatus(buildStatus.code()).build());
|
|
|
+ }
|
|
|
+
|
|
|
private void preBuild(Map<String,Object> buildContext,BuildSceneCallMessage message, BuildLog buildLog) throws BuildException {
|
|
|
|
|
|
// 初始化日志参数
|
|
@@ -304,8 +348,14 @@ public class RabbitMqListener {
|
|
|
buildLog.setCreateTime(new Date());
|
|
|
buildLog.setUpdateTime(new Date());
|
|
|
buildLog.setBuildType(0);
|
|
|
+ buildLog.setStatus(0);
|
|
|
// 设置缓存锁
|
|
|
String key = SysConstants.SCENE_BUILDING + buildLog.getSceneNum();
|
|
|
+ // 如果是强制重新计算,则删除key。
|
|
|
+ if (StringUtils.equals(message.getRebuild(), "1")) {
|
|
|
+ redisUtil.del(key);
|
|
|
+ }
|
|
|
+
|
|
|
// 获取缓存锁,防止重复消费
|
|
|
Long building = redisUtil.incr(key, 1);
|
|
|
buildLogService.save(buildLog);
|
|
@@ -353,15 +403,7 @@ public class RabbitMqListener {
|
|
|
//判断是否计算过资源,若计算过删除缓存, 如果caches中存在_images文件或者目录,就删除掉,否则就删除除了images以外的所有文件和目录
|
|
|
File caches = new File(path + File.separator + "caches");
|
|
|
if (caches.exists()) {
|
|
|
- for (File deleteFile : caches.listFiles()) {
|
|
|
- if (!deleteFile.getAbsolutePath().contains("images")) {
|
|
|
- if (deleteFile.isDirectory()) {
|
|
|
- FileUtils.delAllFile(deleteFile.getAbsolutePath());
|
|
|
- } else {
|
|
|
- FileUtils.deleteFile(deleteFile.getAbsolutePath());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ FileUtils.deleteDirectory(path + File.separator + "caches");
|
|
|
}
|
|
|
//删除上一次计算出来的result目录
|
|
|
if (new File(path + File.separator + "results").exists()) {
|