浏览代码

重定位

dengsixing 3 天之前
父节点
当前提交
df5b683d98

+ 1 - 1
src/main/java/com/fdkankan/contro/generate/AutoGenerate.java

@@ -17,7 +17,7 @@ public class AutoGenerate {
         String path =System.getProperty("user.dir");
 
         generate(path,"contro", getTables(new String[]{
-                "t_app_camera_fail_log"
+                "t_relocation_init"
         }));
 
 //        generate(path,"goods", getTables(new String[]{

+ 70 - 10
src/main/java/com/fdkankan/contro/mq/listener/BuildSxRelocationListener.java

@@ -1,11 +1,18 @@
 package com.fdkankan.contro.mq.listener;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.exceptions.ExceptionUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.common.constant.CommonOperStatus;
+import com.fdkankan.contro.entity.RelocationBatch;
+import com.fdkankan.contro.entity.RelocationBatchDetail;
 import com.fdkankan.contro.mq.service.impl.BuildSxRelocationServiceImpl;
 import com.fdkankan.contro.service.ICommonService;
+import com.fdkankan.contro.service.IRelocationBatchDetailService;
+import com.fdkankan.contro.service.IRelocationBatchService;
 import com.fdkankan.contro.service.ISceneBuildProcessLogService;
 import com.fdkankan.model.constants.SceneBuildProcessType;
 import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
@@ -20,7 +27,8 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Component
@@ -37,6 +45,65 @@ public class BuildSxRelocationListener {
     private ISceneBuildProcessLogService sceneBuildProcessLogService;
     @Autowired
     private ICommonService commonService;
+    @Autowired
+    private IRelocationBatchService relocationBatchService;
+    @Autowired
+    private IRelocationBatchDetailService relocationBatchDetailService;
+
+
+    /**
+     * 场景计算前置资源准备处理
+     * @param channel
+     * @param message
+     * @throws Exception
+     */
+    @RabbitListener(
+            queuesToDeclare = @Queue("${queue.modeling.sx-relocation-push:sx-relocation-push}"),
+            concurrency = "5"
+    )
+    public void push(Channel channel, Message message) throws Exception {
+        String messageId = message.getMessageProperties().getMessageId();
+        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+        JSONObject jsonObject = JSON.parseObject(msg);
+        log.info("开始接受重定位请求,id:{},消息体:{}", messageId, jsonObject);
+        String sxNum = jsonObject.getString("sxNum");
+        RelocationBatch relocationBatch = new RelocationBatch();
+        relocationBatch.setNum(sxNum);
+        relocationBatchService.save(relocationBatch);
+        JSONArray imgs = jsonObject.getJSONArray("imgs");
+        List<RelocationBatchDetail> detailList = imgs.stream().map(v -> {
+            JSONObject img = (JSONObject) v;
+            RelocationBatchDetail detail = new RelocationBatchDetail();
+            detail.setBatchId(relocationBatch.getId());
+            detail.setNum(sxNum);
+            detail.setPanNum(img.getString("num"));
+            detail.setBucket(img.getString("bucket"));
+            detail.setImgKey(img.getString("key"));
+            detail.setFileName(img.getString("fileName"));
+            return detail;
+        }).collect(Collectors.toList());
+        relocationBatchDetailService.saveBatch(detailList);
+
+
+        List<RelocationBatch> list = relocationBatchService.list(new LambdaQueryWrapper<RelocationBatch>().eq(RelocationBatch::getNum, sxNum).in(RelocationBatch::getStatus, 0, 1).lt(RelocationBatch::getId, relocationBatch.getId()));
+        boolean canBuild = true;
+        if(CollUtil.isNotEmpty(list)){
+            for (RelocationBatch batch : list) {
+                if(batch.getStatus() == 1){//如果已经有进入计算的重定位记录,则这次提交需要进入定时任务等待
+                    canBuild = false;
+                }
+                if(batch.getStatus() == 0){//如果前面有等待的,则丢弃等待的记录,因为最后一次推送是最全的
+                    relocationBatchService.removeById(batch);
+                }
+            }
+        }
+        if(canBuild){
+            relocationBatchService.relocationControlHandler(relocationBatch);
+        }
+
+        log.info("结束接受重定位请求,id:{}", messageId);
+        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+    }
 
     /**
      * 场景计算前置资源准备处理
@@ -51,15 +118,8 @@ public class BuildSxRelocationListener {
     public void buildScenePreHandler(Channel channel, Message message) throws Exception {
         String messageId = message.getMessageProperties().getMessageId();
         String msg = new String(message.getBody(), StandardCharsets.UTF_8);
-        HashMap<String, Object> map = JSON.parseObject(msg, HashMap.class);
-        String num = (String) map.get("num");
-        String path = (String) map.get("path");
-
-        BuildSceneCallMessage buildSceneMessage = new BuildSceneCallMessage();
-        buildSceneMessage.setSceneNum(num);
-        buildSceneMessage.setBizType("relocation");
-        buildSceneMessage.setPath(path);
-        buildSceneMessage.setCameraType("14");
+        BuildSceneCallMessage buildSceneMessage = JSON.parseObject(msg, BuildSceneCallMessage.class);
+        String num = buildSceneMessage.getSceneNum();
 
         log.info("开始准备重定位计算资源,队列名:{},id:{},消息体:{}", queueModelingPre, messageId, msg);
         try {

+ 17 - 1
src/main/java/com/fdkankan/contro/mq/service/impl/BuildIntermitSceneServiceImpl.java

@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fdkankan.common.constant.*;
 import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.contro.entity.RelocationInit;
 import com.fdkankan.contro.entity.ScenePlus;
 import com.fdkankan.contro.entity.ScenePlusExt;
 import com.fdkankan.contro.mq.service.IBuildSceneService;
@@ -23,7 +24,6 @@ import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
 import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
 import com.fdkankan.rabbitmq.util.RabbitMqProducer;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
@@ -78,6 +78,8 @@ public class BuildIntermitSceneServiceImpl implements IBuildSceneService {
     private IntermitSceneService intermitSceneService;
     @Autowired
     private IBuildService buildService;
+    @Autowired
+    private IRelocationInitService relocationInitService;
 
     @Override
     public void buildScenePre(BuildSceneCallMessage message) throws Exception{
@@ -187,6 +189,11 @@ public class BuildIntermitSceneServiceImpl implements IBuildSceneService {
             ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
 
             log.info("开始上传场景计算结果数据,num:{}", sceneCode);
+            //上传结算结果之前需要删除oss上的结果数据
+            String panoramaKey = String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + "panoramas";
+            if(fYunFileService.fileExist(panoramaKey)){
+                fYunFileService.deleteFolder(panoramaKey);
+            }
             //上传文件
             fYunFileService.uploadMulFiles(uploadFiles);
 
@@ -217,6 +224,15 @@ public class BuildIntermitSceneServiceImpl implements IBuildSceneService {
             //推送到全景看看
             intermitSceneService.sendMq(sceneCode, fdageData, CommonSuccessStatus.SUCCESS.code());
 
+            //判断是否有重定位关系,如果有,推送到激光系统去做初始化处理
+            String sxUuid = fdageData.getString("parentScene");
+            ScenePlus sxScenePlus = scenePlusService.getByFileId(sxUuid);
+            RelocationInit relocationInit = new RelocationInit();
+            relocationInit.setNum(sxScenePlus.getNum());
+            relocationInit.setPanNum(sceneCode);
+            relocationInitService.save(relocationInit);
+            relocationInitService.pushInit(relocationInit);
+
             log.info("场景计算结果处理结束,场景码:{}", sceneCode);
 
         }catch (Exception e){

+ 39 - 18
src/main/java/com/fdkankan/contro/mq/service/impl/BuildSxRelocationServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fdkankan.contro.mq.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -32,6 +33,7 @@ import javax.annotation.Resource;
 import java.io.File;
 import java.nio.charset.StandardCharsets;
 import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
@@ -77,10 +79,15 @@ public class BuildSxRelocationServiceImpl implements IBuildSceneService {
     private IntermitSceneService intermitSceneService;
     @Autowired
     private IBuildService buildService;
+    @Autowired
+    private IRelocationBatchDetailService relocationBatchDetailService;
+    @Autowired
+    private IRelocationBatchService relocationBatchService;
 
     @Override
     public void buildScenePre(BuildSceneCallMessage message) throws Exception{
         String num = message.getSceneNum();
+        Long batchId = (Long) message.getExt().get("batchId");
         ScenePlus scenePlusByNum = scenePlusService.getScenePlusByNum(num);
         try {
             //重新计算时需要删除文件夹,否知使用缓存
@@ -92,8 +99,7 @@ public class BuildSxRelocationServiceImpl implements IBuildSceneService {
                 FileUtils.deleteDirectory(message.getPath() + File.separator + "caches");
             }
 
-            String extrasPath = message.getPath() + File.separator + "extras";
-            fYunFileService.downloadFileByCommand(extrasPath, String.format(UploadFilePath.scene_result_data_path, num) + "pose/");
+            this.downLoadSource(message, message.getPath());
 
             message.setResultReceiverMqName(queueModelingPost);
 
@@ -110,30 +116,43 @@ public class BuildSxRelocationServiceImpl implements IBuildSceneService {
         }catch (Exception e){
             scenePlusByNum.setSceneStatus(SceneStatus.FAILD.code());
             scenePlusService.updateById(scenePlusByNum);
+            //修改重定位记录为退出计算
+            relocationBatchService.update(new LambdaUpdateWrapper<RelocationBatch>().eq(RelocationBatch::getId, batchId).set(RelocationBatch::getStatus, 2));
             buildSceneDTService.handBaseFail("深巡场景重定位资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
             throw e;
         }
     }
 
-    private String getOssPath(String path) {
-        String ossPath = ConstantFilePath.OSS_PREFIX
-                + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
-                .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
-        if (!ossPath.endsWith("/")) {
-            ossPath = ossPath.concat("/");
-        }
-        return ossPath;
-    }
-
     @Override
     public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
-        String ossPath = getOssPath(path);
-        fYunFileService.downloadFileByCommand(path + File.separator + "capture", ossPath);
+        String num = buildSceneMqMessage.getSceneNum();
+        Long batchId = (Long)buildSceneMqMessage.getExt().get("batchId");
+        //下载深巡缓存数据
+        String extrasPath = path + File.separator + "extras";
+        fYunFileService.downloadFileByCommand(extrasPath, String.format(UploadFilePath.scene_result_data_path, num) + "pose/");
+        String imagesPath = extrasPath + File.separator + "images";
+        //下载图片
+        String queryPath = imagesPath + File.separator + "query";
+        List<RelocationBatchDetail> detailList = relocationBatchDetailService.listByBatchId(batchId);
+        detailList.stream().forEach(v->{
+            fYunFileService.downloadFile(v.getBucket(), v.getImgKey(), queryPath + File.separator + v.getFileName());
+        });
+        //生成query.json
+        List<String> imgNameList = FileUtil.listFileNames(queryPath);
+        List<JSONObject> filenames = imgNameList.stream().map(v -> {
+            JSONObject a = new JSONObject();
+            a.put("filename", v);
+            return a;
+        }).collect(Collectors.toList());
+        JSONObject query = new JSONObject();
+        query.put("query", filenames);
+        FileUtil.writeUtf8String(query.toJSONString(), extrasPath + File.separator + "query.json");
     }
 
     @Override
     public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
         String sceneCode = message.getBuildContext().get("sceneNum").toString();
+        Long batchId = (Long) message.getExt().get("batchId");
         String path = message.getPath();
         Map<String, Object> downParams = new HashMap<>();
         downParams.put("sceneCode", sceneCode);
@@ -147,7 +166,7 @@ public class BuildSxRelocationServiceImpl implements IBuildSceneService {
             log.info("计算日志上传完成");
 
             if (!message.getBuildSuccess()) {
-                log.error("建模失败,修改状态为失败状态");
+                log.error("重定位计算报错,修改状态为失败状态");
                 scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
                         .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
                         .eq(ScenePlus::getNum, sceneCode));
@@ -190,16 +209,18 @@ public class BuildSxRelocationServiceImpl implements IBuildSceneService {
 
             //发送消息到点云系统处理
             downParams.put("status", CommonSuccessStatus.SUCCESS.code());
-            log.info("场景计算结果处理结束,场景码:{}", sceneCode);
+            log.info("场景重定位计算结果处理结束,场景码:{}", sceneCode);
 
         }catch (Exception e){
-            log.error("场景计算结果处理出错,num"+sceneCode, e);
+            log.error("场景重定位计算结果处理出错,num"+sceneCode, e);
             downParams.put("status", CommonSuccessStatus.FAIL.code());
-            buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
+            buildSceneDTService.handBaseFail("场景重定位计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
             throw e;
         } finally {
             //发送消息到激光系统做处理
             mqProducer.sendByWorkQueue("sx-relocation-done", downParams);
+            //修改重定位记录为退出计算
+            relocationBatchService.update(new LambdaUpdateWrapper<RelocationBatch>().eq(RelocationBatch::getId, batchId).set(RelocationBatch::getStatus, 2));
         }
     }
 

+ 26 - 3
src/main/java/com/fdkankan/contro/schedule/ScheduleJob.java

@@ -1,11 +1,10 @@
 package com.fdkankan.contro.schedule;
 
+import com.fdkankan.contro.service.IRelocationBatchService;
+import com.fdkankan.contro.service.IRelocationInitService;
 import com.fdkankan.contro.service.IScene3dNumService;
-import com.fdkankan.rabbitmq.util.RabbitMqProducer;
-import com.fdkankan.rubbersheeting.ScalingService;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
@@ -15,6 +14,10 @@ public class ScheduleJob {
 
     @Autowired
     private IScene3dNumService scene3dNumService;
+    @Autowired
+    private IRelocationBatchService relocationBatchService;
+    @Autowired
+    private IRelocationInitService relocationInitService;
 
 
     /**
@@ -24,4 +27,24 @@ public class ScheduleJob {
     public void generateSceneNum() {
         scene3dNumService.generateSceneNumHandler();
     }
+
+    /**
+     * 重定位调度
+     */
+    @Scheduled(fixedDelay = 5*60*1000, initialDelay = 1000)
+    public void relocationControl() {
+        log.info("重定位调度开始");
+        relocationBatchService.relocationControl();
+        log.info("重定位调度结束");
+    }
+
+    /**
+     * 重定位调度
+     */
+    @Scheduled(fixedDelay = 5*60*1000, initialDelay = 1000)
+    public void relocationInit() {
+        log.info("重定位初始化调度开始");
+        relocationInitService.relocationInit();
+        log.info("重定位初始化调度结束");
+    }
 }