Browse Source

修改场景计算异常处理逻辑

tianboguang 2 năm trước cách đây
mục cha
commit
f27bc53385

+ 5 - 5
src/main/java/com/fdkankan/contro/mq/listener/DingTalkMessageListener.java

@@ -1,6 +1,7 @@
 package com.fdkankan.contro.mq.listener;
 
 import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.contro.constant.DingTalkConst;
 import com.fdkankan.contro.service.IBuildSceneDTService;
 import com.fdkankan.rabbitmq.bean.BuildSceneFailDTMqMessage;
 import com.rabbitmq.client.Channel;
@@ -35,13 +36,12 @@ public class DingTalkMessageListener {
             concurrency = "${maxThread.modeling.modeling-dt}"
     )
     public void buildSceneDTHandler(Channel channel, Message message) throws Exception {
-        Object correlation = message.getMessageProperties().getHeader("spring_returned_message_correlation");
-        String correlationId = (String) correlation;
+        String messageId = message.getMessageProperties().getMessageId();
         String msg = new String(message.getBody(), StandardCharsets.UTF_8);
-        log.info("发送钉钉消息处理,队列名:{},id:{},消息体:{}", queueModelingDt, correlationId, msg);
+        log.info("发送钉钉消息处理,队列名:{},id:{},消息体:{}", queueModelingDt, messageId, msg);
         BuildSceneFailDTMqMessage dtMessage = JSONObject.parseObject(msg, BuildSceneFailDTMqMessage.class);
-//        buildSceneDTService.handFail(dtMessage.getReason(), dtMessage.getServerPath(),
-//            dtMessage.getNum(), dtMessage.getHostName(), DingTalkConst.contentExt);
+        buildSceneDTService.handModelFail(dtMessage.getReason(), dtMessage.getServerPath(),
+                dtMessage.getNum(), dtMessage.getHostName());
         channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
     }
 }

+ 9 - 1
src/main/java/com/fdkankan/contro/mq/service/impl/BuildObjServiceImpl.java

@@ -117,7 +117,7 @@ public class BuildObjServiceImpl implements IBuildSceneService {
         }finally {
             //如果前置处理失败,发送钉钉消息
             if(!success){
-                buildSceneDTService.handFail("生成OBJ场景资源准备异常", message.getPath(), message.getSceneNum(), "计算控制服务器", null);
+                buildSceneDTService.handBaseFail("生成OBJ场景资源准备异常", message.getPath(), message.getSceneNum(), "计算控制服务器");
             }
 
         }
@@ -140,6 +140,14 @@ public class BuildObjServiceImpl implements IBuildSceneService {
 
     @Override
     public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
+
+        if (!message.getBuildSuccess()) {
+            log.error("生成OBJ场景计算失败!");
+            // 发送钉钉消息,计算失败
+            buildSceneDTService.handModelFail("生成OBJ场景计算失败!", message.getPath(), message.getBuildContext().get("sceneNum").toString(), message.getHostName());
+            return;
+        }
+
         String path = message.getPath();
         String projectNum = message.getBuildContext().get("sceneNum").toString();
 

+ 56 - 74
src/main/java/com/fdkankan/contro/mq/service/impl/BuildSceneServiceImpl.java

@@ -23,7 +23,6 @@ import com.fdkankan.contro.vo.SceneEditControlsVO;
 import com.fdkankan.fyun.config.FYunFileConfig;
 import com.fdkankan.fyun.constant.FYunTypeEnum;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
-import com.fdkankan.image.MatrixToImageWriterUtil;
 import com.fdkankan.model.constants.ConstantFileName;
 import com.fdkankan.model.constants.ConstantFilePath;
 import com.fdkankan.model.constants.UploadFilePath;
@@ -148,7 +147,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         }finally {
             //如果前置处理失败,发送钉钉消息
             if(!success){
-                buildSceneDTService.handFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器", null);
+                buildSceneDTService.handBaseFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
             }
 
         }
@@ -190,7 +189,10 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
                 scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
                         .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
                         .eq(ScenePlus::getNum, sceneCode));
-                throw new RuntimeException("建模失败!");
+
+                // 发送钉钉消息,计算失败
+                buildSceneDTService.handModelFail("计算失败", message.getPath(), sceneCode, message.getHostName());
+                return;
             }
 
             Map<String, String> uploadFiles = getUploadFiles(path,cameraType,fdageData);
@@ -284,17 +286,8 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             log.info("场景计算结果处理结束,场景码:{}", sceneCode);
 
         }catch (Exception e){
-            String errorMsg = "场景计算结果处理出错!";
-            String hostName = "计算控制服务";
-            log.error(errorMsg);
             e.printStackTrace();
-            if(!buildSuccess){
-                errorMsg = "场景构建失败!";
-                hostName = message.getHostName();
-            }
-            //发送钉钉
-            String serverPath = message.getPath();
-            buildSceneDTService.handFail(errorMsg, serverPath, sceneCode, hostName, null);
+            buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
         }
     }
 
@@ -433,60 +426,61 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
                                 SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt, boolean arrearCap)  throws Exception{
         String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
 
-        //清除redis缓存
-        redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
-
-        String sceneJsonKey = dataViewPath + "scene.json";
-        boolean exist = fYunFileService.fileExist(sceneJsonKey);
-        //如果云端没有scene.json文件,生成一份
-        String qrLogo = null;
-
-        if(!exist){
-            SceneJsonBean sceneJson = new SceneJsonBean();
-            BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
-            BeanUtil.copyProperties(sceneEditInfo, sceneJson);
-            SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
-            sceneJson.setControls(sceneEditControlsVO);
-            sceneJson.setNum(num);
-            sceneJson.setCreateTime(scenePlus.getCreateTime());
-            sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
-            sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
-            sceneJson.setVideos(JSON.toJSONString(videosJson));
-            if(arrearCap) {
-                sceneJson.setPayStatus(PayStatus.NO_CAPACITY.code());
+        SceneJsonBean sceneJson = new SceneJsonBean();
+        BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
+        BeanUtil.copyProperties(sceneEditInfo, sceneJson);
+        SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
+        sceneJson.setControls(sceneEditControlsVO);
+        sceneJson.setNum(num);
+        sceneJson.setCreateTime(scenePlus.getCreateTime());
+        sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
+        sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
+        sceneJson.setVideos(JSON.toJSONString(videosJson));
+        if(arrearCap) {
+            sceneJson.setPayStatus(PayStatus.NO_CAPACITY.code());
+        }
+        // 获取企业logo
+        CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
+        if(!ObjectUtils.isEmpty(cameraDetail.getCompanyId())){
+            String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
+            Company company = companyService.getById(cameraDetail.getCompanyId());
+            if (StrUtil.isNotEmpty(company.getTopLogo())) {
+                fYunFileService.copyFileInBucket(company.getTopLogo(),userViewPath + "loadingLogo-user.png");
+                sceneJson.setLoadingLogo("user");
+                sceneJson.setLoadingLogoFile("loadingLogo-user.png");
             }
-            // 获取企业logo
-            CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
-            if(!ObjectUtils.isEmpty(cameraDetail.getCompanyId())){
-                String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
-                Company company = companyService.getById(cameraDetail.getCompanyId());
-                if (StrUtil.isNotEmpty(company.getTopLogo())) {
-                    fYunFileService.copyFileInBucket(company.getTopLogo(),userViewPath + "loadingLogo-user.png");
-                    sceneJson.setLoadingLogo("user");
-                    sceneJson.setLoadingLogoFile("loadingLogo-user.png");
-                }
-                if (StrUtil.isNotEmpty(company.getFloorLogo())) {
-                    fYunFileService.copyFileInBucket(company.getFloorLogo(),userViewPath + "floorLogo-user.png");
-                    sceneJson.setFloorLogo("user");
-                    sceneJson.setFloorLogoFile("floorLogo-user.png");
-                }
-                if (!ObjectUtils.isEmpty(company.getQrLogo())) {
-                    if (!new File(ConstantFilePath.AGENT_PATH + company.getQrLogo()).exists()) {
-                        fYunFileService.downloadFile(company.getQrLogo(), ConstantFilePath.AGENT_PATH + company.getQrLogo());
-                    }
-                    qrLogo = ConstantFilePath.AGENT_PATH + company.getQrLogo();
+            if (StrUtil.isNotEmpty(company.getFloorLogo())) {
+                fYunFileService.copyFileInBucket(company.getFloorLogo(),userViewPath + "floorLogo-user.png");
+                sceneJson.setFloorLogo("user");
+                sceneJson.setFloorLogoFile("floorLogo-user.png");
+            }
+            String qrLogo = null;
+            if (!ObjectUtils.isEmpty(company.getQrLogo())) {
+                if (!new File(ConstantFilePath.AGENT_PATH + company.getQrLogo()).exists()) {
+                    fYunFileService.downloadFile(company.getQrLogo(), ConstantFilePath.AGENT_PATH + company.getQrLogo());
                 }
-
+                qrLogo = ConstantFilePath.AGENT_PATH + company.getQrLogo();
             }
-            String sceneJsonStr = JSON.toJSONString(sceneJson);
-            //上传sceneJson文件
-            fYunFileService.uploadFile(sceneJsonStr.getBytes(), sceneJsonKey);
-            //scenejson写入缓存
-            redisUtil.set(String.format(RedisKey.SCENE_JSON, num), sceneJsonStr);
-
+            //生成二维码
+            String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+num+".png";
+            String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+num+"_en.png";
+            QrConfig qrConfig = QrConfig.create();
+            if(!ObjectUtils.isEmpty(qrLogo)){
+                qrConfig.setImg(qrLogo);
+            }
+            QrCodeUtil.generate(scenePlusExt.getWebSite(), qrConfig, FileUtil.file(outPathZh));
+            QrCodeUtil.generate(scenePlusExt.getWebSite() + "&lang=en", qrConfig, FileUtil.file(outPathEn));
+            //上传二维码
+            fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
+            fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
         }
-        // 上传status JSON.
+        String sceneJsonStr = JSON.toJSONString(sceneJson);
+        //上传sceneJson文件
+        fYunFileService.uploadFile(sceneJsonStr.getBytes(), dataViewPath + "scene.json");
+        //scenejson写入缓存
+        redisUtil.set(String.format(RedisKey.SCENE_JSON, num), sceneJsonStr);
 
+        // 上传status JSON.
         JSONObject statusJson = new JSONObject();
         //临时将-2改成1,app还没完全更新
         statusJson.put("status", 1);
@@ -500,18 +494,6 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json",
                 dataViewPath + "status.json");
 
-        //生成二维码
-        String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+num+".png";
-        String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+num+"_en.png";
-        QrConfig qrConfig = QrConfig.create();
-        if(!ObjectUtils.isEmpty(qrLogo)){
-            qrConfig.setImg(qrLogo);
-        }
-        QrCodeUtil.generate(scenePlusExt.getWebSite(), qrConfig, FileUtil.file(outPathZh));
-        QrCodeUtil.generate(scenePlusExt.getWebSite() + "&lang=en", qrConfig, FileUtil.file(outPathEn));
-        //上传二维码
-        fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
-        fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
     }
 
     private void pushMsgToApp(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){

+ 5 - 14
src/main/java/com/fdkankan/contro/mq/service/impl/BuildV3SceneServiceImpl.java

@@ -24,7 +24,6 @@ import com.fdkankan.contro.service.impl.FdkkV4Service;
 import com.fdkankan.fyun.config.FYunFileConfig;
 import com.fdkankan.fyun.constant.FYunTypeEnum;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
-import com.fdkankan.image.MatrixToImageWriterUtil;
 import com.fdkankan.model.constants.ConstantFileName;
 import com.fdkankan.model.constants.ConstantFilePath;
 import com.fdkankan.model.constants.UploadFilePath;
@@ -35,7 +34,6 @@ import com.fdkankan.push.utils.PushMsgUtil;
 import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
 import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
 import com.fdkankan.rabbitmq.util.RabbitMqProducer;
-import com.fdkankan.redis.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -131,7 +129,7 @@ public class BuildV3SceneServiceImpl implements IBuildSceneService {
         }finally {
             //如果前置处理失败,发送钉钉消息
             if(!success){
-                buildSceneDTService.handFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器", null);
+                buildSceneDTService.handBaseFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
             }
 
         }
@@ -173,7 +171,9 @@ public class BuildV3SceneServiceImpl implements IBuildSceneService {
                 sceneProService.update(new LambdaUpdateWrapper<ScenePro>()
                         .set(ScenePro::getStatus, SceneStatus.FAILD.code())
                         .eq(ScenePro::getNum, sceneCode));
-                throw new RuntimeException("建模失败!");
+                // 发送钉钉消息,计算失败
+                buildSceneDTService.handModelFail("计算失败", message.getPath(), sceneCode, message.getHostName());
+                return;
             }
 
             Map<String, String> uploadFiles = getUploadFiles(path,cameraType,fdageData);
@@ -252,17 +252,8 @@ public class BuildV3SceneServiceImpl implements IBuildSceneService {
             }
 
         }catch (Exception e){
-            String errorMsg = "场景计算结果处理出错!";
-            String hostName = "计算控制服务";
-            log.error(errorMsg);
             e.printStackTrace();
-            if(!buildSuccess){
-                errorMsg = "场景构建失败!";
-                hostName = message.getHostName();
-            }
-            //发送钉钉
-            String serverPath = message.getPath();
-            buildSceneDTService.handFail(errorMsg, serverPath, sceneCode, hostName, null);
+            buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
         }
     }
 

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

@@ -10,6 +10,8 @@ package com.fdkankan.contro.service;
  **/
 public interface IBuildSceneDTService {
 
-    void handFail(String reason, String serverPath, String num, String hostName, String contentExt);
+    void handModelFail(String reason, String serverPath, String num, String hostName);
+
+    void handBaseFail(String reason, String serverPath, String num, String hostName);
 
 }

+ 25 - 14
src/main/java/com/fdkankan/contro/service/impl/BuildSceneDTServiceImpl.java

@@ -31,27 +31,38 @@ public class BuildSceneDTServiceImpl implements IBuildSceneDTService {
         "**失败原因**: %s\n\n" +
         "**num**: %s\n\n" +
         "**server-path**: %s\n\n";
-//        "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
 
     public static final String contentExt = "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
 
     @Autowired
     private DingTalkSendUtils dingTalkSendUtils;
-    @Value("${spring.profiles.active}")
-    private String environment;
+
+    @Value("${main.url}")
+    private String mainUrl;
 
     @Override
-    public void handFail(String reason, String serverPath, String num, String hostName, String message) {
-//        CompletableFuture.runAsync(() -> {
-//            try {
-//                String contentFormat = StrUtil.isBlank(message) ? this.DINGTALK_MSG_PATTERN : this.DINGTALK_MSG_PATTERN +  contentExt;
-//                String content = String.format(contentFormat, this.environment, hostName, reason, num, serverPath, num, num);
-//                log.info("发送钉钉消息,content:{}", content);
-//                dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
-//            } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
-//                log.error("发送钉钉消息失败", apiException);
-//            }
-//        });
+    public void handModelFail(String reason, String serverPath, String num, String hostName) {
+        CompletableFuture.runAsync(() -> {
+            try {
+                String content = String.format(this.DINGTALK_MSG_PATTERN +  contentExt, this.mainUrl, hostName, reason, num, serverPath, num, num);
+                log.info("发送钉钉消息,content:{}", content);
+                dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
+            } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
+                log.error("发送钉钉消息失败", apiException);
+            }
+        });
     }
 
+    @Override
+    public void handBaseFail(String reason, String serverPath, String num, String hostName) {
+        CompletableFuture.runAsync(() -> {
+            try {
+                String content = String.format(this.DINGTALK_MSG_PATTERN, this.mainUrl, hostName, reason, num, serverPath);
+                log.info("发送钉钉消息,content:{}", content);
+                dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
+            } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
+                log.error("发送钉钉消息失败", apiException);
+            }
+        });
+    }
 }