|
@@ -45,6 +45,8 @@ public class BuildSceneProgressServiceImpl implements IBuildSceneProgressService
|
|
public String buildProgressUrl;
|
|
public String buildProgressUrl;
|
|
@Autowired
|
|
@Autowired
|
|
private RedisUtil redisUtil;
|
|
private RedisUtil redisUtil;
|
|
|
|
+ @Value("${main.url}")
|
|
|
|
+ private String mainUrl;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private IScenePlusService scenePlusService;
|
|
private IScenePlusService scenePlusService;
|
|
@@ -63,102 +65,119 @@ public class BuildSceneProgressServiceImpl implements IBuildSceneProgressService
|
|
String website = scenePlusExt.getWebSite();
|
|
String website = scenePlusExt.getWebSite();
|
|
String title = scenePlus.getTitle();
|
|
String title = scenePlus.getTitle();
|
|
|
|
|
|
- String projectJsonPath = path.concat(File.separator).concat("project.json");
|
|
|
|
- File file = FileUtil.file(projectJsonPath);
|
|
|
|
- WatchMonitor watchMonitor = WatchMonitor.create(file);
|
|
|
|
- watchMonitor.setWatcher(new Watcher() {
|
|
|
|
-
|
|
|
|
- boolean complete = false;
|
|
|
|
- int mainProgress = 0;
|
|
|
|
- Long totalTime = null;//buildProgressTime
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void onCreate(WatchEvent<?> event, Path currentPath) {
|
|
|
|
-// log.info("project.json文件创建完毕");
|
|
|
|
-// String projectJsonStr = FileUtil.readUtf8String(file);
|
|
|
|
-// JSONObject projectJson = JSON.parseObject(projectJsonStr);
|
|
|
|
-// JSONObject state = projectJson.getJSONObject("state");
|
|
|
|
-// Long expectTime = state.getLong("expect_time");
|
|
|
|
-// totalTime += expectTime;
|
|
|
|
-// redisUtil.set(String.format(RedisKey.SCENE_BUILD_EXPECT_TOTAL_TIME_NUM, num), String.valueOf(totalTime), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
|
-// Map<String, Object> params = new HashMap<>();
|
|
|
|
-// params.put("website", website);
|
|
|
|
-// params.put("title", title);
|
|
|
|
-// params.put("customUserId",customUserId);
|
|
|
|
-// params.put("gps", gps);
|
|
|
|
-// params.put("totalTime", totalTime);
|
|
|
|
-// params.put("progress", mainProgress);
|
|
|
|
-// HttpUtil.post(buildProgressUrl, JSON.toJSONString(params), 2000);
|
|
|
|
-
|
|
|
|
|
|
+ Long factor = 10L;
|
|
|
|
+ Long totalTime = 300L;
|
|
|
|
+ Integer shootCount = scenePlusExt.getShootCount();
|
|
|
|
+ if(Objects.nonNull(shootCount)){
|
|
|
|
+ totalTime += shootCount*7*60;//预估7分钟一个点位
|
|
|
|
+ }
|
|
|
|
+ Long intervalTime = totalTime/factor;//发送计算进度时间窗口
|
|
|
|
+
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ params.put("website", mainUrl.concat(website));
|
|
|
|
+ params.put("title", title);
|
|
|
|
+ params.put("customUserId", customUserId);
|
|
|
|
+ params.put("gps", gps);
|
|
|
|
+ params.put("totalTime", totalTime);
|
|
|
|
+ params.put("progress", 0);
|
|
|
|
+ log.info("场景计算开始,发送进度请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
|
|
|
|
+ HttpUtil.post(buildProgressUrl, JSON.toJSONString(params), 2000);
|
|
|
|
+
|
|
|
|
+ ExecutorService executorService = ThreadUtil.newSingleExecutor();
|
|
|
|
+ executorService.submit(()->{
|
|
|
|
+ boolean finish = false;
|
|
|
|
+ int mainProgress = 0;
|
|
|
|
+ do {
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(intervalTime*1000);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void onModify(WatchEvent<?> event, Path currentPath) {
|
|
|
|
- log.info("发生了变化,小飞棍来惹。。。。。");
|
|
|
|
- String projectJsonStr = FileUtil.readUtf8String(file);
|
|
|
|
- JSONObject projectJson = JSON.parseObject(projectJsonStr);
|
|
|
|
- JSONObject state = projectJson.getJSONObject("state");
|
|
|
|
- complete = state.getBoolean("done");
|
|
|
|
- log.info("计算完成状态:{}", complete);
|
|
|
|
- if (Objects.isNull(totalTime)) {
|
|
|
|
- try {
|
|
|
|
- log.info("计算总时间开始。。。。");
|
|
|
|
- totalTime = state.getLong("expect_time") + buildProgressTime;
|
|
|
|
- redisUtil.set(String.format(RedisKey.SCENE_BUILD_EXPECT_TOTAL_TIME_NUM, num), String.valueOf(totalTime), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
|
- log.info("计算总时间结束。。。。");
|
|
|
|
- }catch (Exception e){
|
|
|
|
- log.info("这里报错了,你麻痹。。。。。");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (complete) {
|
|
|
|
- log.info("1111111111111111");
|
|
|
|
- mainProgress = 90;
|
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
|
- params.put("website", website);
|
|
|
|
- params.put("title", title);
|
|
|
|
- params.put("customUserId", customUserId);
|
|
|
|
- params.put("gps", gps);
|
|
|
|
- params.put("totalTime", totalTime);
|
|
|
|
|
|
+ String finishStr = redisUtil.get(String.format(RedisKey.SCENE_BUILD_FINISH_NUM, num));
|
|
|
|
+ //计算结果处理消费者消费完毕后,会发送一次进度为100的消息,这里就不需要再做任务操作,
|
|
|
|
+ if(StrUtil.isNotEmpty(finishStr)){
|
|
|
|
+ finish = true;
|
|
|
|
+ }else{
|
|
|
|
+ mainProgress += factor;
|
|
|
|
+ //如果预估的时间比实际的时间要慢,那么这里的进度条会草超过100,所以当超过100时,不需要再发送进度了,只需要等计算结果处理监听中的计算完毕去发送100即可
|
|
|
|
+ if(mainProgress >= 100){
|
|
|
|
+ finish = true;
|
|
|
|
+ }else{
|
|
params.put("progress", mainProgress);
|
|
params.put("progress", mainProgress);
|
|
- log.info("算法完成发送请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
|
|
|
|
|
|
+ log.info("场景计算进行中,发送进度请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
|
|
HttpUtil.post(buildProgressUrl, JSON.toJSONString(params), 2000);
|
|
HttpUtil.post(buildProgressUrl, JSON.toJSONString(params), 2000);
|
|
- watchMonitor.interrupt();
|
|
|
|
- } else {
|
|
|
|
- log.info("222222222222222");
|
|
|
|
- int progress = 0;
|
|
|
|
- try {
|
|
|
|
- progress = new BigDecimal(state.getDouble("progress")).multiply(new BigDecimal(100)).intValue();
|
|
|
|
- }catch (Exception e){
|
|
|
|
- log.error("报错", e);
|
|
|
|
- }
|
|
|
|
- log.info("当前进度为,progress:{}",progress);
|
|
|
|
- if (progress - mainProgress >= 10) {
|
|
|
|
- mainProgress = progress;
|
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
|
- params.put("website", website);
|
|
|
|
- params.put("title", title);
|
|
|
|
- params.put("customUserId", customUserId);
|
|
|
|
- params.put("gps", gps);
|
|
|
|
- params.put("totalTime", totalTime);
|
|
|
|
- params.put("progress", progress);
|
|
|
|
- log.info("算法进行中发送请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
|
|
|
|
- HttpUtil.post(buildProgressUrl, JSON.toJSONString(params), 2000);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }while (!finish);
|
|
|
|
+ });
|
|
|
|
|
|
- @Override
|
|
|
|
- public void onDelete(WatchEvent<?> event, Path currentPath) {
|
|
|
|
- watchMonitor.interrupt();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void onOverflow(WatchEvent<?> event, Path currentPath) {
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- watchMonitor.start();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+// String projectJsonPath = path.concat(File.separator).concat("project.json");
|
|
|
|
+// File file = FileUtil.file(projectJsonPath);
|
|
|
|
+// WatchMonitor watchMonitor = WatchMonitor.create(file);
|
|
|
|
+// watchMonitor.setWatcher(new Watcher() {
|
|
|
|
+//
|
|
|
|
+// boolean complete = false;
|
|
|
|
+// int mainProgress = 0;
|
|
|
|
+// Long totalTime = null;//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// @Override
|
|
|
|
+// public void onCreate(WatchEvent<?> event, Path currentPath) {
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @Override
|
|
|
|
+// public void onModify(WatchEvent<?> event, Path currentPath) {
|
|
|
|
+// log.info("算法进度更新了.....");
|
|
|
|
+// String projectJsonStr = FileUtil.readUtf8String(file);
|
|
|
|
+// JSONObject projectJson = JSON.parseObject(projectJsonStr);
|
|
|
|
+// JSONObject state = projectJson.getJSONObject("state");
|
|
|
|
+// complete = state.getBoolean("done");
|
|
|
|
+// log.info("计算完成状态:{}", complete);
|
|
|
|
+// if (Objects.isNull(totalTime)) {
|
|
|
|
+// totalTime = state.getLong("expect_time") + buildProgressTime;
|
|
|
|
+// redisUtil.set(String.format(RedisKey.SCENE_BUILD_EXPECT_TOTAL_TIME_NUM, num), String.valueOf(totalTime), RedisKey.CAMERA_EXPIRE_7_TIME);
|
|
|
|
+// }
|
|
|
|
+// if (complete) {
|
|
|
|
+// mainProgress = 90;
|
|
|
|
+// Map<String, Object> params = new HashMap<>();
|
|
|
|
+// params.put("website", mainUrl.concat(website));
|
|
|
|
+// params.put("title", title);
|
|
|
|
+// params.put("customUserId", customUserId);
|
|
|
|
+// params.put("gps", gps);
|
|
|
|
+// params.put("totalTime", totalTime);
|
|
|
|
+// params.put("progress", mainProgress);
|
|
|
|
+// log.info("算法完成发送请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
|
|
|
|
+// HttpUtil.post(buildProgressUrl, JSON.toJSONString(params), 2000);
|
|
|
|
+// watchMonitor.interrupt();
|
|
|
|
+// } else {
|
|
|
|
+// int progress = 0;
|
|
|
|
+// progress = new BigDecimal(state.getDouble("progress")).multiply(new BigDecimal(100)).intValue();
|
|
|
|
+// log.info("当前进度为,progress:{}",progress);
|
|
|
|
+// if (progress - mainProgress >= 10) {
|
|
|
|
+// mainProgress = progress;
|
|
|
|
+// Map<String, Object> params = new HashMap<>();
|
|
|
|
+// params.put("website", mainUrl.concat(website));
|
|
|
|
+// params.put("title", title);
|
|
|
|
+// params.put("customUserId", customUserId);
|
|
|
|
+// params.put("gps", gps);
|
|
|
|
+// params.put("totalTime", totalTime);
|
|
|
|
+// params.put("progress", (progress/10)*10);
|
|
|
|
+// log.info("算法进行中发送请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
|
|
|
|
+// HttpUtil.post(buildProgressUrl, JSON.toJSONString(params), 2000);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @Override
|
|
|
|
+// public void onDelete(WatchEvent<?> event, Path currentPath) {
|
|
|
|
+// watchMonitor.interrupt();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @Override
|
|
|
|
+// public void onOverflow(WatchEvent<?> event, Path currentPath) {
|
|
|
|
+// }
|
|
|
|
+// });
|
|
|
|
+// watchMonitor.start();
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|