|
@@ -1,24 +1,13 @@
|
|
|
package com.fdkankan.contro.mq.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.io.watch.WatchMonitor;
|
|
|
import cn.hutool.core.io.watch.Watcher;
|
|
|
-import cn.hutool.core.thread.ThreadUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.fdkankan.common.constant.*;
|
|
|
-import com.fdkankan.common.util.FileUtils;
|
|
|
-import com.fdkankan.contro.entity.ScenePlus;
|
|
|
-import com.fdkankan.contro.entity.ScenePlusExt;
|
|
|
import com.fdkankan.contro.mq.service.IBuildSceneProgressService;
|
|
|
import com.fdkankan.contro.service.IScenePlusExtService;
|
|
|
import com.fdkankan.contro.service.IScenePlusService;
|
|
|
import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
|
|
|
-import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -27,11 +16,9 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.WatchEvent;
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.*;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@RefreshScope
|
|
|
@Slf4j
|
|
@@ -53,84 +40,83 @@ public class BuildSceneProgressServiceImpl implements IBuildSceneProgressService
|
|
|
|
|
|
@Override
|
|
|
public void monitorProgress(BuildSceneCallMessage buildSceneCallMessage) {
|
|
|
- String num = buildSceneCallMessage.getSceneNum();
|
|
|
- String customUserId = (String)buildSceneCallMessage.getExt().get("customUserId");
|
|
|
- String gps = (String)buildSceneCallMessage.getExt().get("gps");
|
|
|
- String path = buildSceneCallMessage.getPath();
|
|
|
-
|
|
|
- ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
|
|
|
- ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
- String website = scenePlusExt.getWebSite();
|
|
|
- String title = scenePlus.getTitle();
|
|
|
-
|
|
|
- Long factor = 10L;
|
|
|
- Long totalTime = 300L;
|
|
|
- Integer shootCount = scenePlusExt.getShootCount();
|
|
|
- if(Objects.nonNull(shootCount)){
|
|
|
- totalTime += shootCount*7*60;//预估7分钟一个点位
|
|
|
- }
|
|
|
- redisUtil.set(String.format(RedisKey.SCENE_BUILD_EXPECT_TOTAL_TIME_NUM, num), String.valueOf(totalTime));
|
|
|
- Long intervalTime = totalTime/factor;//发送计算进度时间窗口
|
|
|
- log.info("推送进度时间窗口:{}", intervalTime);
|
|
|
-
|
|
|
- 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);
|
|
|
- params.put("status", CommonSuccessStatus.WAITING.code());
|
|
|
- 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();
|
|
|
- }
|
|
|
- String finishStr = redisUtil.get(String.format(RedisKey.SCENE_BUILD_FINISH_NUM, num));
|
|
|
- if(StrUtil.isEmpty(finishStr)){
|
|
|
- finishStr = "0";
|
|
|
- }
|
|
|
- CommonSuccessStatus commonSuccessStatus = CommonSuccessStatus.get(Integer.valueOf(finishStr));
|
|
|
- switch (commonSuccessStatus){
|
|
|
- case SUCCESS:
|
|
|
- //计算结果处理消费者消费完毕后,会发送一次进度为100的消息,这里就不需要再做任务操作,
|
|
|
- finish = true;
|
|
|
- break;
|
|
|
- case FAIL:
|
|
|
- finish = true;
|
|
|
- params.put("progress", mainProgress);
|
|
|
- params.put("status", commonSuccessStatus.code());
|
|
|
- log.info("场景计算失败,发送进度请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
|
|
|
- this.sendNotice(params);
|
|
|
- break;
|
|
|
- case WAITING:
|
|
|
- mainProgress += factor;
|
|
|
- log.info("mainProgress:{}", mainProgress);
|
|
|
- //如果预估的时间比实际的时间要慢,那么这里的进度条会草超过100,所以当超过100时,不需要再发送进度了,只需要等计算结果处理监听中的计算完毕去发送100即可
|
|
|
- if(mainProgress >= 100){
|
|
|
- finish = true;
|
|
|
- }else{
|
|
|
- params.put("progress", mainProgress);
|
|
|
- params.put("status", commonSuccessStatus.code());
|
|
|
- log.info("场景计算进行中,发送进度请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
|
|
|
- this.sendNotice(params);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }while (!finish);
|
|
|
-
|
|
|
- log.info("场景计算完成,删除计算完成redis记录,key:{}", String.format(RedisKey.SCENE_BUILD_FINISH_NUM, num));
|
|
|
- redisUtil.del(String.format(RedisKey.SCENE_BUILD_FINISH_NUM, num));
|
|
|
- log.info("推送计算进度结束,num:{}", num);
|
|
|
- });
|
|
|
+// String num = buildSceneCallMessage.getSceneNum();
|
|
|
+// String customUserId = (String)buildSceneCallMessage.getExt().get("customUserId");
|
|
|
+// String gps = (String)buildSceneCallMessage.getExt().get("gps");
|
|
|
+// String path = buildSceneCallMessage.getPath();
|
|
|
+//
|
|
|
+// ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
|
|
|
+// ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
+// String website = scenePlusExt.getWebSite();
|
|
|
+// String title = scenePlus.getTitle();
|
|
|
+//
|
|
|
+// Long factor = 10L;
|
|
|
+// Long totalTime = 300L;
|
|
|
+// Integer shootCount = scenePlusExt.getShootCount();
|
|
|
+// if(Objects.nonNull(shootCount)){
|
|
|
+// totalTime += shootCount*7*60;//预估7分钟一个点位
|
|
|
+// }
|
|
|
+// redisUtil.set(String.format(RedisKey.SCENE_BUILD_EXPECT_TOTAL_TIME_NUM, num), String.valueOf(totalTime));
|
|
|
+// Long intervalTime = totalTime/factor;//发送计算进度时间窗口
|
|
|
+// log.info("推送进度时间窗口:{}", intervalTime);
|
|
|
+//
|
|
|
+// 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);
|
|
|
+// params.put("status", CommonSuccessStatus.WAITING.code());
|
|
|
+// 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();
|
|
|
+// }
|
|
|
+// String finishStr = redisUtil.get(String.format(RedisKey.SCENE_BUILD_FINISH_NUM, num));
|
|
|
+// if(StrUtil.isEmpty(finishStr)){
|
|
|
+// finishStr = "0";
|
|
|
+// }
|
|
|
+// CommonSuccessStatus commonSuccessStatus = CommonSuccessStatus.get(Integer.valueOf(finishStr));
|
|
|
+// switch (commonSuccessStatus){
|
|
|
+// case SUCCESS:
|
|
|
+// //计算结果处理消费者消费完毕后,会发送一次进度为100的消息,这里就不需要再做任务操作,
|
|
|
+// finish = true;
|
|
|
+// break;
|
|
|
+// case FAIL:
|
|
|
+// finish = true;
|
|
|
+// params.put("progress", mainProgress);
|
|
|
+// params.put("status", commonSuccessStatus.code());
|
|
|
+// log.info("场景计算失败,发送进度请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
|
|
|
+// this.sendNotice(params);
|
|
|
+// break;
|
|
|
+// case WAITING:
|
|
|
+// mainProgress += factor;
|
|
|
+// log.info("mainProgress:{}", mainProgress);
|
|
|
+// //如果预估的时间比实际的时间要慢,那么这里的进度条会草超过100,所以当超过100时,不需要再发送进度了,只需要等计算结果处理监听中的计算完毕去发送100即可
|
|
|
+// if(mainProgress >= 100){
|
|
|
+// finish = true;
|
|
|
+// }else{
|
|
|
+// params.put("progress", mainProgress);
|
|
|
+// params.put("status", commonSuccessStatus.code());
|
|
|
+// log.info("场景计算进行中,发送进度请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
|
|
|
+// this.sendNotice(params);
|
|
|
+// }
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }while (!finish);
|
|
|
+//
|
|
|
+// redisUtil.del(String.format(RedisKey.SCENE_BUILD_FINISH_NUM, num));
|
|
|
+// log.info("推送计算进度结束,num:{}", num);
|
|
|
+// });
|
|
|
|
|
|
}
|
|
|
|