dengsixing 1 년 전
부모
커밋
e3090edd18

+ 24 - 1
src/main/java/com/fdkankan/jp/xspace/listener/RabbitMqListener.java

@@ -1,11 +1,16 @@
 package com.fdkankan.jp.xspace.listener;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.thread.ThreadUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.fdkankan.common.constant.CommonSuccessStatus;
 import com.fdkankan.dingtalk.DingTalkSendUtils;
+import com.fdkankan.fyun.config.FYunFileConfig;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.jp.xspace.common.constant.NasPathConstant;
+import com.fdkankan.jp.xspace.common.constant.OSSPathConstant;
 import com.fdkankan.jp.xspace.common.exception.PackException;
 import com.fdkankan.jp.xspace.common.rabbitmq.RabbitmqConstant;
 import com.fdkankan.jp.xspace.common.rabbitmq.dto.SceneXspaceMqDTO;
@@ -63,6 +68,10 @@ public class RabbitMqListener {
     private IUnityService unityService;
     @Autowired
     private ISceneXspaceService sceneXspaceService;
+    @Resource
+    private FYunFileServiceInterface fYunFileService;
+    @Resource
+    private FYunFileConfig fYunFileConfig;
 
 
     /**
@@ -79,6 +88,7 @@ public class RabbitMqListener {
         String msg = new String(message.getBody(), StandardCharsets.UTF_8);
         log.info("开始消费消息,id:{},content:{}", messageId, msg);
         SceneXspace bean = JSON.parseObject(msg, SceneXspace.class);
+        String workPath = NasPathConstant.UNITY_WORK_PATH + bean.getNum() + "/" + bean.getSerial() + "/";
         String errorReason = null;
 
         Future submit = executorService.submit(()-> unityService.packXspace(bean));
@@ -108,14 +118,27 @@ public class RabbitMqListener {
         try {
             if(bean.getStatus() == CommonSuccessStatus.FAIL.code()){
                 User user = userService.getById(bean.getUserId());
-                String workPath = NasPathConstant.UNITY_WORK_PATH + bean.getNum() + "/" + bean.getSerial() + "/";
+                String errorLogPath = workPath + "error.log";
+                String errorLogKey = String.format(OSSPathConstant.XSPACE_SCENE_FORMAT, bean.getNum(), bean.getSerial()) + "log/error.log";
+                String logUrl = fYunFileConfig.getHost() + errorLogKey;
+                String extContent = null;
+                if(FileUtil.exist(errorLogPath)){
+                    fYunFileService.uploadFile(errorLogPath, errorLogKey);
+                    extContent = "**error-log**: " + logUrl + "\n\n";
+                }
                 String content = String.format(DINGTALK_MSG_PATTERN, profile, errorReason, bean.getNum(), user.getUserName(), workPath);
+                if(StrUtil.isNotEmpty(extContent)){
+                    content = content + extContent;
+                }
                 dingTalkSendUtils.sendActioncardMsgToDingRobot(content, "场景同步失败");
             }
         }catch (Exception e){
             log.error("发送钉钉失败", e);
         }
 
+        //删除本地资源
+        FileUtil.del(workPath);
+
         log.info("结束消费消息,id:{}", messageId);
         channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
     }

+ 3 - 6
src/main/java/com/fdkankan/jp/xspace/service/impl/UnityServiceImpl.java

@@ -53,9 +53,6 @@ public class UnityServiceImpl implements IUnityService {
 
         //文件处理/上传
         this.dealFileAndUpload(bean, workPath);
-
-        //删除本地资源
-        FileUtil.del(workPath);
     }
 
 
@@ -83,16 +80,16 @@ public class UnityServiceImpl implements IUnityService {
             throw new PackException("unity执行报错");
         }
 
-        String resultFilePath = workPath + "result.txt";
+        String resultFilePath = workPath + "result.json";
         boolean completed = this.checkComputeCompleted(resultFilePath, 3, 300);
         if(!completed){
-            throw new PackException("unity异常,没有生成result.txt");
+            throw new PackException("unity异常,没有生成result.json");
         }
         String resultStr = FileUtil.readUtf8String(resultFilePath);
         JSONObject resultObj = JSON.parseObject(resultStr);
         boolean success = resultObj.getBooleanValue("success");
         if(!success){
-            throw new PackException(resultObj.getString("reason"));
+            throw new PackException(resultObj.getString("message"));
         }
     }