Sfoglia il codice sorgente

增加计算进度通知

dsx 2 anni fa
parent
commit
6f742ca781

+ 1 - 1
src/main/java/com/fdkankan/contro/controller/SceneFileController.java

@@ -108,7 +108,7 @@ public class SceneFileController{
      * @throws Exception
      */
     @PostMapping("sendCallAlgorithm")
-    public ResultData sendCallAlgorithm(@RequestBody Map<String,String> params) throws Exception {
+    public ResultData sendCallAlgorithm(@RequestBody Map<String,Object> params) throws Exception {
         return sceneFileBuildService.sendCallAlgorithm(params);
     }
 

+ 109 - 90
src/main/java/com/fdkankan/contro/mq/service/impl/BuildSceneProgressServiceImpl.java

@@ -45,6 +45,8 @@ public class BuildSceneProgressServiceImpl implements IBuildSceneProgressService
     public String buildProgressUrl;
     @Autowired
     private RedisUtil redisUtil;
+    @Value("${main.url}")
+    private String mainUrl;
 
     @Autowired
     private IScenePlusService scenePlusService;
@@ -63,102 +65,119 @@ public class BuildSceneProgressServiceImpl implements IBuildSceneProgressService
         String website = scenePlusExt.getWebSite();
         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);
-                        log.info("算法完成发送请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
+                        log.info("场景计算进行中,发送进度请求,url:{}, param:{}", buildProgressUrl, JSON.toJSONString(params));
                         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) {

+ 2 - 0
src/main/java/com/fdkankan/contro/mq/service/impl/BuildSceneServiceImpl.java

@@ -268,6 +268,8 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
 
             CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/") + "/capture");
 
+            redisUtil.set(String.format(RedisKey.SCENE_BUILD_FINISH_NUM, sceneCode), "1");
+
             Map<String, Object> ext = message.getExt();
             Map<String, Object> params = new HashMap<>();
             params.put("website", scenePlusExt.getWebSite());

+ 1 - 1
src/main/java/com/fdkankan/contro/service/ISceneFileBuildService.java

@@ -32,5 +32,5 @@ public interface ISceneFileBuildService extends IService<SceneFileBuild> {
 
     ResultData uploadFile(MultipartFile file, String params) throws Exception;
 
-    ResultData sendCallAlgorithm(@RequestBody Map<String,String> params) throws Exception;
+    ResultData sendCallAlgorithm(@RequestBody Map<String,Object> params) throws Exception;
 }

+ 19 - 6
src/main/java/com/fdkankan/contro/service/impl/SceneFileBuildServiceImpl.java

@@ -39,6 +39,7 @@ import com.fdkankan.web.response.ResultData;
 import com.fdkankan.web.util.RSAEncrypt;
 import lombok.extern.slf4j.Slf4j;
 import net.lingala.zip4j.core.ZipFile;
+import net.lingala.zip4j.exception.ZipException;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -859,21 +860,26 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
     }
 
     @Override
-    public ResultData sendCallAlgorithm(@RequestBody Map<String,String> params) throws Exception {
+    public ResultData sendCallAlgorithm(@RequestBody Map<String,Object> params) throws Exception {
         log.info("sendCallAlgorithm 参数为:{}", JSONObject.toJSONString(params));
-        String filePath = params.get("filepath");
-        if(StrUtil.isBlank(filePath)){
+        List<String> filePaths = (List<String>) params.get("filepath");
+        if(CollUtil.isEmpty(filePaths)){
             throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
         }
         String uuid = UUID.randomUUID().toString();
         String parentPath = sendCallAlgorithmPath.concat(uuid);
-        String localFilePath = parentPath.concat(File.separator).concat(uuid).concat(".zip");
         if(FileUtil.exist(parentPath)){
             FileUtil.del(parentPath);
         }
-        FileUtil.mkParentDirs(localFilePath);
+
+        String localFilePath = parentPath.concat(File.separator).concat(uuid).concat(".zip");
         try {
-            HttpUtil.downloadFile(filePath, localFilePath);
+            for (String filePath : filePaths) {
+                String extName = FileUtil.extName(filePath);
+                String subFilePath = parentPath.concat(File.separator).concat(uuid).concat(".").concat(extName);
+                FileUtil.mkParentDirs(localFilePath);
+                HttpUtil.downloadFile(filePath, subFilePath);
+            }
         }catch (Exception e){
             throw new BusinessException(ErrorCode.FAILURE_CODE_5063);
         }
@@ -972,6 +978,13 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
         return ResultData.ok();
     }
 
+    public static void main(String[] args) throws ZipException {
+//        ZipUtil.unzip("D:\\test\\KJ-07UBv9PY4TU.zip","D:\\test");
+        ZipFile zipFile = new ZipFile(new File("D:\\test\\KJ-07UBv9PY4TU.zip"));
+        zipFile.setPassword("");
+        zipFile.extractAll("D:\\test");
+    }
+
     private String getFileIdByFolderName(String folderName) {
         // 检测是否有生成
         String fileId = redisUtil.get(String.format(RedisConstants.FOLDER_FILEID_BUILD, folderName));