|
@@ -1,17 +1,27 @@
|
|
package com.fdkankan.modeling.receiver;
|
|
package com.fdkankan.modeling.receiver;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
|
+import cn.hutool.core.io.watch.WatchMonitor;
|
|
|
|
+import cn.hutool.core.io.watch.Watcher;
|
|
|
|
+import cn.hutool.core.lang.Console;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.fdkankan.common.constant.ModelingBuildStatus;
|
|
import com.fdkankan.common.constant.ModelingBuildStatus;
|
|
|
|
+import com.fdkankan.common.util.CmdUtils;
|
|
import com.fdkankan.common.util.FileUtils;
|
|
import com.fdkankan.common.util.FileUtils;
|
|
import com.fdkankan.model.utils.ComputerUtil;
|
|
import com.fdkankan.model.utils.ComputerUtil;
|
|
|
|
+import com.fdkankan.model.utils.CreateObjUtil;
|
|
import com.fdkankan.modeling.bean.BuildSceneResultBean;
|
|
import com.fdkankan.modeling.bean.BuildSceneResultBean;
|
|
|
|
+import com.fdkankan.modeling.constants.CmdConstant;
|
|
import com.fdkankan.modeling.constants.RedisKey;
|
|
import com.fdkankan.modeling.constants.RedisKey;
|
|
import com.fdkankan.modeling.constants.SysConstants;
|
|
import com.fdkankan.modeling.constants.SysConstants;
|
|
import com.fdkankan.modeling.entity.BuildLog;
|
|
import com.fdkankan.modeling.entity.BuildLog;
|
|
import com.fdkankan.modeling.exception.BuildException;
|
|
import com.fdkankan.modeling.exception.BuildException;
|
|
import com.fdkankan.modeling.handler.LaserSceneObjGenerateHandler;
|
|
import com.fdkankan.modeling.handler.LaserSceneObjGenerateHandler;
|
|
|
|
+import com.fdkankan.modeling.service.IAiService;
|
|
import com.fdkankan.modeling.service.IBuildLogService;
|
|
import com.fdkankan.modeling.service.IBuildLogService;
|
|
import com.fdkankan.modeling.service.IBuildService;
|
|
import com.fdkankan.modeling.service.IBuildService;
|
|
import com.fdkankan.modeling.service.IReverseE57Service;
|
|
import com.fdkankan.modeling.service.IReverseE57Service;
|
|
@@ -36,10 +46,9 @@ import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
+import java.nio.file.WatchEvent;
|
|
|
|
+import java.util.*;
|
|
import java.util.concurrent.Future;
|
|
import java.util.concurrent.Future;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeoutException;
|
|
import java.util.concurrent.TimeoutException;
|
|
@@ -86,6 +95,8 @@ public class RabbitMqListener {
|
|
private IBuildService buildService;
|
|
private IBuildService buildService;
|
|
@Autowired
|
|
@Autowired
|
|
private IReverseE57Service reverseE57Service;
|
|
private IReverseE57Service reverseE57Service;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IAiService aiService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 场景计算
|
|
* 场景计算
|
|
@@ -131,6 +142,12 @@ public class RabbitMqListener {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //进入计算之前,判断算法文件锁是否存在,如果存在,则删除
|
|
|
|
+ String lockPath = buildSceneMessage.getPath() + "/.lockdirectory";
|
|
|
|
+ if(FileUtil.exist(lockPath)){
|
|
|
|
+ FileUtil.del(lockPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
BuildLog buildLog = new BuildLog();
|
|
BuildLog buildLog = new BuildLog();
|
|
log.info("场景计算开始,队列名:{},id:{},deliveryTag:{},消息体:{}", queueNameService.getQueueName(), messageId,deliveryTag,msg);
|
|
log.info("场景计算开始,队列名:{},id:{},deliveryTag:{},消息体:{}", queueNameService.getQueueName(), messageId,deliveryTag,msg);
|
|
buildLog.setMessageId(messageId);
|
|
buildLog.setMessageId(messageId);
|
|
@@ -204,6 +221,9 @@ public class RabbitMqListener {
|
|
} else {
|
|
} else {
|
|
status = ModelingBuildStatus.FAILED;
|
|
status = ModelingBuildStatus.FAILED;
|
|
}
|
|
}
|
|
|
|
+ }finally {
|
|
|
|
+ //杀掉算法进程,否则有可能导致上一个超时的算法进程没终止,下一个场景算法进程启动,一台机器有两个算法进程在跑
|
|
|
|
+ CreateObjUtil.killMainLoader();
|
|
}
|
|
}
|
|
buildLog.setStatus(status.code());
|
|
buildLog.setStatus(status.code());
|
|
buildSceneResult.setCameraType(message.getCameraType());
|
|
buildSceneResult.setCameraType(message.getCameraType());
|
|
@@ -286,7 +306,13 @@ public class RabbitMqListener {
|
|
log.error("未检测到计算结果文件:upload.json");
|
|
log.error("未检测到计算结果文件:upload.json");
|
|
return ModelingBuildStatus.FAILED;
|
|
return ModelingBuildStatus.FAILED;
|
|
}
|
|
}
|
|
- log.info("八目上完oss结束修改数据:"+num);
|
|
|
|
|
|
+
|
|
|
|
+ //调用ai识别,但是报错也不影响计算结果
|
|
|
|
+ aiService.detectScenePano(path);
|
|
|
|
+
|
|
|
|
+ //平面图ai识别
|
|
|
|
+ buildSceneResult.setDetFloorplan(this.detFloorplan(path));
|
|
|
|
+
|
|
return ModelingBuildStatus.SUCCESS;
|
|
return ModelingBuildStatus.SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -314,9 +340,85 @@ public class RabbitMqListener {
|
|
log.error("未检测到计算结果文件:upload.json");
|
|
log.error("未检测到计算结果文件:upload.json");
|
|
return ModelingBuildStatus.FAILED;
|
|
return ModelingBuildStatus.FAILED;
|
|
}
|
|
}
|
|
|
|
+
|
|
return ModelingBuildStatus.SUCCESS;
|
|
return ModelingBuildStatus.SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private LinkedHashMap<Integer, Boolean> detFloorplan(String path) throws Exception {
|
|
|
|
+ LinkedHashMap<Integer, Boolean> result = new LinkedHashMap<>();
|
|
|
|
+ String workDir = path + "/detFloorplan/";
|
|
|
|
+ if(FileUtil.exist(workDir)){
|
|
|
|
+ FileUtil.del(workDir);
|
|
|
|
+ }
|
|
|
|
+ String infoJsonPath = path + "/results/floorplan/info.json";
|
|
|
|
+ if(!FileUtil.exist(infoJsonPath)){
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONObject infoObj = JSON.parseObject(FileUtil.readUtf8String(infoJsonPath));
|
|
|
|
+ JSONArray floors = infoObj.getJSONArray("floors");
|
|
|
|
+ if(CollUtil.isEmpty(floors)){
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ for (Object o : floors) {
|
|
|
|
+ JSONObject floor = (JSONObject) o;
|
|
|
|
+ Integer subgroup = floor.getInteger("subgroup");
|
|
|
|
+ String detectPath = workDir + subgroup + "/detect.json";
|
|
|
|
+ String floorKeyPath = path + "/results/floorplan/floor_" + subgroup + ".png";
|
|
|
|
+ String parent = FileUtil.getParent(detectPath, 1);
|
|
|
|
+ FileUtil.mkdir(parent);
|
|
|
|
+ result.put(subgroup, false);
|
|
|
|
+ if(!FileUtil.exist(floorKeyPath)){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ String cmd = CmdConstant.LAYOUT_DETECT;
|
|
|
|
+ cmd = cmd.replace("@in", floorKeyPath);
|
|
|
|
+ cmd = cmd.replace("@out", detectPath);
|
|
|
|
+ CmdUtils.callLine(cmd, 50);
|
|
|
|
+ if (ComputerUtil.checkComputeCompleted(detectPath,5, 500)) {
|
|
|
|
+ result.put(subgroup, true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ File file = FileUtil.file("D:\\test\\111.txt");
|
|
|
|
+//这里只监听文件或目录的修改事件
|
|
|
|
+ WatchMonitor watchMonitor = WatchMonitor.create(file);
|
|
|
|
+ watchMonitor.setWatcher(new Watcher(){
|
|
|
|
+ @Override
|
|
|
|
+ public void onCreate(WatchEvent<?> event, Path currentPath) {
|
|
|
|
+ Object obj = event.context();
|
|
|
|
+ Console.log("创建:{}-> {}", currentPath, obj);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onModify(WatchEvent<?> event, Path currentPath) {
|
|
|
|
+ Object obj = event.context();
|
|
|
|
+ Console.log("修改:{}-> {}", currentPath, obj);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onDelete(WatchEvent<?> event, Path currentPath) {
|
|
|
|
+ Object obj = event.context();
|
|
|
|
+ Console.log("删除:{}-> {}", currentPath, obj);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onOverflow(WatchEvent<?> event, Path currentPath) {
|
|
|
|
+ Object obj = event.context();
|
|
|
|
+ Console.log("Overflow:{}-> {}", currentPath, obj);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ watchMonitor.start();
|
|
|
|
+ for (int i= 0; i< 10; i++ ){
|
|
|
|
+ System.out.println(i);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
private void afterBuild(BuildSceneCallMessage message, BuildSceneResultBean buildSceneResult, BuildLog buildLog){
|
|
private void afterBuild(BuildSceneCallMessage message, BuildSceneResultBean buildSceneResult, BuildLog buildLog){
|
|
ModelingBuildStatus buildStatus = null;
|
|
ModelingBuildStatus buildStatus = null;
|
|
try {
|
|
try {
|
|
@@ -361,32 +463,33 @@ public class RabbitMqListener {
|
|
buildLog.setUpdateTime(new Date());
|
|
buildLog.setUpdateTime(new Date());
|
|
buildLog.setBuildType(0);
|
|
buildLog.setBuildType(0);
|
|
buildLog.setStatus(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);
|
|
buildLogService.save(buildLog);
|
|
-
|
|
|
|
- if(!ObjectUtils.isEmpty(buildLog.getMessageId())){
|
|
|
|
- // 设置消息id幂等性,防止消息重复消费
|
|
|
|
- boolean lock = redisLockUtil.lock(SysConstants.SCENE_MESSAGE_BUILDING + buildLog.getMessageId(), SysConstants.modelTimeOut * 3600);
|
|
|
|
- if (!lock) {
|
|
|
|
- log.error("服务:{},消息重复消费:{}", SysConstants.hostName, buildLog.getMessageId());
|
|
|
|
- throw new BuildException(ModelingBuildStatus.REPEAT);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (building.compareTo(1L) > 0) {
|
|
|
|
- log.error("服务:{},重复构建:{},构建次数:{}", SysConstants.hostName, buildLog.getSceneNum(),building);
|
|
|
|
- throw new BuildException(ModelingBuildStatus.REPEAT);
|
|
|
|
- } else {
|
|
|
|
- redisUtil.expire(key, Integer.toUnsignedLong(SysConstants.modelTimeOut * 3600));
|
|
|
|
- }
|
|
|
|
|
|
+// // 设置缓存锁
|
|
|
|
+// 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);
|
|
|
|
+//
|
|
|
|
+// if(!ObjectUtils.isEmpty(buildLog.getMessageId())){
|
|
|
|
+// // 设置消息id幂等性,防止消息重复消费
|
|
|
|
+// boolean lock = redisLockUtil.lock(SysConstants.SCENE_MESSAGE_BUILDING + buildLog.getMessageId(), SysConstants.modelTimeOut * 3600);
|
|
|
|
+// if (!lock) {
|
|
|
|
+// log.error("服务:{},消息重复消费:{}", SysConstants.hostName, buildLog.getMessageId());
|
|
|
|
+// throw new BuildException(ModelingBuildStatus.REPEAT);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// if (building.compareTo(1L) > 0) {
|
|
|
|
+// log.error("服务:{},重复构建:{},构建次数:{}", SysConstants.hostName, buildLog.getSceneNum(),building);
|
|
|
|
+// throw new BuildException(ModelingBuildStatus.REPEAT);
|
|
|
|
+// } else {
|
|
|
|
+// redisUtil.expire(key, Integer.toUnsignedLong(SysConstants.modelTimeOut * 3600));
|
|
|
|
+// }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -409,6 +512,7 @@ public class RabbitMqListener {
|
|
.build();
|
|
.build();
|
|
buildResult.setBuildContext(message.getBuildContext());
|
|
buildResult.setBuildContext(message.getBuildContext());
|
|
buildResult.setRebuild(message.getRebuild());
|
|
buildResult.setRebuild(message.getRebuild());
|
|
|
|
+ buildResult.setDetFloorplan(buildSceneResult.getDetFloorplan());
|
|
rabbitMqProducer.sendByWorkQueue(buildSceneResult.getResultQueueName(),buildResult);
|
|
rabbitMqProducer.sendByWorkQueue(buildSceneResult.getResultQueueName(),buildResult);
|
|
}
|
|
}
|
|
|
|
|