houweiyu 5 år sedan
förälder
incheckning
e4377d1eba

+ 42 - 52
fdkanfang-common/src/main/java/com/fdkanfang/common/util/ComputerUtil.java

@@ -12,7 +12,6 @@ import lombok.extern.slf4j.Slf4j;
 import java.io.File;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.UUID;
 
 /**
  * 生成场景和计算场景
@@ -22,34 +21,30 @@ import java.util.UUID;
 public class ComputerUtil {
 
     /**
-     *
-     * @param unicode 创建文件目录码(目前是用场景吗)
+     * @param unicode    创建文件目录码(目前是用场景吗)
      * @param projectNum 场景码
-     * @param path 算法生成文件路径
+     * @param panoRootPath       算法生成文件路径
      * @return
      * @throws Exception
      */
-    public static Map<String,String> computer(String unicode, String projectNum, String path) throws Exception{
+    public static Map<String, String> computer(String unicode, String projectNum, String panoRootPath) throws Exception {
         // path: /data/kanfang/10002/pano
-        log.info("path: {}", path);
-        Map<String,String> map = new HashMap<String,String>();
+        log.info("建模收到的文件路径为:{}", panoRootPath);
+        Map<String, String> map = new HashMap<String, String>();
 
         // 生成模型oss存放路径
-//        String ossPanoPath = ConstantFilePath.UPLOAD_HOUSE_PATH + projectNum + "/pano/";
         //TODO:这里需要加斜杆,不然黏连在一起了
 //        String ossPanoPath = ConstantFilePath.OSS_IMAGE_PATH  + "/" + projectNum + "/";
-        String ossPanoPath = ConstantFilePath.OSS_IMAGE_PATH  + projectNum + "/";
-//        String ossVerticalPath = ossBasePath+"/pan/high/" + filename;
+        String ossPanoPath = ConstantFilePath.OSS_IMAGE_PATH + projectNum + "/";
 
-        log.info("开始建模:"+projectNum);
+        log.info(">>>>>>>>开始建模:{}<<<<<<<<", projectNum);
         //构建算法isModel去掉,因此改成空字符串
-//        CreateObjUtil.build3dModel(ConstantFilePath.BUILD_MODEL_PATH + unicode, "");
-        CreateObjUtil.build3dModel(path, "");
-        log.info("建模完成转换数据:"+projectNum);
+        CreateObjUtil.build3dModel(panoRootPath, "");
+        log.info("建模完成转换数据:" + projectNum);
 
         boolean vision2 = false;
         //读取upload文件,检验需要上传的文件是否存在
-        String uploadJsonPath = path + File.separator + "results" + File.separator + "upload.json";
+        String uploadJsonPath = panoRootPath + File.separator + "results" + File.separator + "upload.json";
         boolean exist = FileUtil.exist(uploadJsonPath);
         if (!exist) {
             log.error("模型算法生成的upload.json不存在");
@@ -57,88 +52,83 @@ public class ComputerUtil {
         }
         String uploadData = FileUtils.readFile(uploadJsonPath);
         JSONObject uploadJson = null;
-        JSONArray array = null;
-        if(uploadData!=null) {
+        JSONArray uploadFileArray = null;
+        if (uploadData != null) {
             uploadJson = JSONObject.parseObject(uploadData);
-            array = uploadJson.getJSONArray("upload");
+            uploadFileArray = uploadJson.getJSONArray("upload");
         }
-        if(array == null){
+        if (uploadFileArray == null) {
             log.error("模型算法生成的upload.json数据出错");
             throw new BaseRuntimeException(MsgCode.e_COMMON_3100, "模型算法生成的upload.json数据出错");
         }
         JSONObject fileJson = null;
         String fileName = "";
-        for(int i = 0, len = array.size(); i < len; i++){
-            fileJson = array.getJSONObject(i);
+        for (int i = 0, len = uploadFileArray.size(); i < len; i++) {
+            fileJson = uploadFileArray.getJSONObject(i);
             fileName = fileJson.getString("file");
             //文件不存在抛出异常
-            String filePath = path + File.separator + "results" + File.separator + fileName;
-            if(!FileUtil.exist(filePath)){
+            String filePath = panoRootPath + File.separator + "results" + File.separator + fileName;
+            if (!FileUtil.exist(filePath)) {
                 log.error("文件不存在: " + filePath);
                 throw new BaseRuntimeException(MsgCode.e_COMMON_3100, "文件不存在: " + filePath);
             }
 
             //判断是否有vision2.txt
-            if("vision2.txt".equals(fileName)){
+            if ("vision2.txt".equals(fileName)) {
                 vision2 = true;
             }
 
 
-
             //tex文件夹
-            if(fileJson.getIntValue("clazz") == 2 && !fileJson.containsKey("pack-file")){
+            if (fileJson.getIntValue("clazz") == 2 && !fileJson.containsKey("pack-file")) {
 
                 // param1: 文件地址, param2:oss upload 地址
-                map.put(filePath, ossPanoPath + ConstantFileName.modelUUID+"_50k_texture_jpg_high1/"+fileName.replace("tex/", ""));
+                map.put(filePath, ossPanoPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
             }
 
             //high文件夹
-            if(fileJson.getIntValue("clazz") == 3){
-                map.put(filePath, ossPanoPath +"pan/high/"+ fileName.replace("high/", ""));
+            if (fileJson.getIntValue("clazz") == 3) {
+                map.put(filePath, ossPanoPath + "pan/high/" + fileName.replace("high/", ""));
             }
             //low文件夹
-            if(fileJson.getIntValue("clazz") == 4){
-                map.put(filePath, ossPanoPath +"pan/low/"+ fileName.replace("low/", ""));
+            if (fileJson.getIntValue("clazz") == 4) {
+                map.put(filePath, ossPanoPath + "pan/low/" + fileName.replace("low/", ""));
             }
         }
 
-        CreateObjUtil.convertTxtToDam( path + File.separator + "results" + File.separator+"tex"+File.separator+"modeldata.txt", path + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam");
-//        CreateObjUtil.convertDamToLzma(unicode + File.separator + "results");
+        CreateObjUtil.convertTxtToDam(panoRootPath + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", panoRootPath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam");
         // 服务器地址
         // path:/data/kanfang/房源编号/pano
-        CreateObjUtil.convertDamToLzma(path + "/results/" );
-        CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+"tex"+File.separator+"modeldata.txt", path + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
+        CreateObjUtil.convertDamToLzma(panoRootPath + "/results/");
+        CreateObjUtil.convertTxtToDam(panoRootPath + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", panoRootPath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam");
         //8目相机有两个vision.txt因此第二个叫vision2.txt
-        if(vision2){
-            CreateObjUtil.convertTxtToVisionmodeldata(path + File.separator + "results" +File.separator+"vision.txt",path + File.separator + "results" +File.separator+"vision.modeldata");
-            CreateObjUtil.convertTxtToVisionmodeldata(path + File.separator + "results" +File.separator+"vision2.txt",path + File.separator + "results" +File.separator+"vision2.modeldata");
-            map.put(path + File.separator + "results" +File.separator+"vision2.modeldata", "images/images"+projectNum+"/"+"vision2.modeldata");
-        }else {
-
-//            CreateObjUtil.convertTxtToVisionmodeldataCommon(path + File.separator + "results" +File.separator+"vision.txt",path + File.separator + "results" +File.separator+"vision.modeldata");
+        if (vision2) {
+            CreateObjUtil.convertTxtToVisionmodeldata(panoRootPath + File.separator + "results" + File.separator + "vision.txt", panoRootPath + File.separator + "results" + File.separator + "vision.modeldata");
+            CreateObjUtil.convertTxtToVisionmodeldata(panoRootPath + File.separator + "results" + File.separator + "vision2.txt", panoRootPath + File.separator + "results" + File.separator + "vision2.modeldata");
+            map.put(panoRootPath + File.separator + "results" + File.separator + "vision2.modeldata", "images/images" + projectNum + "/" + "vision2.modeldata");
+        } else {
             // 将前端上传的vision.txt转vision.modeldata
-            CreateObjUtil.convertTxtToVisionmodeldata(path + "/extras/vision.txt", path + "/results/vision.modeldata");
+            CreateObjUtil.convertTxtToVisionmodeldata(panoRootPath + "/extras/vision.txt", panoRootPath + "/results/vision.modeldata");
             log.info("vision.modeldata创建完成");
         }
-        log.info("数据转换完成"+projectNum);
+        log.info("场景码[{}]的数据转换完成" + projectNum);
 
-        File file = new File(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma");
-        while(!file.exists())
-        {
+        File file = new File(panoRootPath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam.lzma");
+        while (!file.exists()) {
             Thread.sleep(60000);
         }
 
 
         // 文件上传oss
-        map.put(path + File.separator + "results" +File.separator+"vision.modeldata", ossPanoPath+"vision.modeldata");
-        map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", ossPanoPath + ConstantFileName.modelUUID+"_50k.dam.lzma");
-        map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", ossPanoPath + ConstantFileName.modelUUID+"_50k.dam");
+        map.put(panoRootPath + File.separator + "results" + File.separator + "vision.modeldata", ossPanoPath + "vision.modeldata");
+        map.put(panoRootPath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam.lzma", ossPanoPath + ConstantFileName.modelUUID + "_50k.dam.lzma");
+        map.put(panoRootPath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam", ossPanoPath + ConstantFileName.modelUUID + "_50k.dam");
 
-        log.info("准备上传文件到oss:"+projectNum);
+        log.info("场景[{}]准备上传文件到oss:" + projectNum);
         return map;
     }
 
-    public static void createJson(String path, String splitType, String skyboxType, String dataDescribe) throws Exception{
+    public static void createJson(String path, String splitType, String skyboxType, String dataDescribe) throws Exception {
         JSONObject dataJson = new JSONObject();
         dataJson.put("split_type", splitType);
         dataJson.put("skybox_type", skyboxType);

+ 1 - 0
fdkanfang-common/src/main/java/com/fdkanfang/common/util/CreateObjUtil.java

@@ -33,6 +33,7 @@ public class CreateObjUtil {
             outGobbler.start();
             process.waitFor();
         } catch (Exception e) {
+            log.error("执行垂直校验算法脚本出现错误:{}" , e);
             e.printStackTrace();
         }
     }

+ 8 - 2
fdkanfang-web/src/main/java/com/fdkanfang/web/backend/HouseController.java

@@ -304,10 +304,16 @@ public class HouseController extends BaseController {
     public R detail(Long houseId, Integer floor){
         HouseEntity house = houseService2.findById(houseId);
         List<ImageEntity> images = imageService2.findByHouseIdAndFloor(houseId, floor);
-        house.setImages(images);
-        return new R(MsgCode.SUCCESS_CODE, house);
+        if(null != house){
+            house.setImages(images);
+            return new R(MsgCode.SUCCESS_CODE, house);
+        }else{
+            return new R(MsgCode.ERROR_CODE, "房源不存在");
+        }
     }
 
+
+
     @RequiresRoles(value = {"admin", "edit", "upload"}, logical = Logical.OR)
     @ApiOperation("删除房源(软删除)")
     @GetMapping("removes/{ids}")

+ 14 - 18
fdkanfang-web/src/main/java/com/fdkanfang/web/mq/listener/PanoListener.java

@@ -12,6 +12,7 @@ import org.springframework.amqp.rabbit.annotation.RabbitHandler;
 import org.springframework.amqp.rabbit.annotation.RabbitListener;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.time.Duration;
 import java.time.LocalDateTime;
@@ -36,53 +37,48 @@ public class PanoListener {
      * 结果监听
      */
     @RabbitHandler
+    @Transactional(rollbackFor = Exception.class)
     public void getMessage(HashMap<Object, Object> mqMap)  {
-        log.info("run PanoListener ");
+        log.info("=====================收到生成模型消息,开始生成模型=====================");
 
         LocalDateTime starTime = LocalDateTime.now();
 
         Long houseId = (Long)mqMap.get("id");
         String basePath = (String)mqMap.get("basePath");
-        String splitType = (String)mqMap.get("splitType");
-        String skyboxType = (String)mqMap.get("skyboxType");
-        String dataDescribe = (String)mqMap.get("dataDescribe");
 
         HouseEntity house = houseService2.findById(houseId);
         if (house == null) {
+            log.error("房源不存在,无法生成模型");
             throw new BaseRuntimeException(MsgCode.e_COMMON_3002, MsgCode.msg_COMMON_3002);
         }
-
         String sceneCode = house.getSceneCode();
-
         try {
-
-
             //计算模型并返回需要上传oss的文件集合
             Map<String, String> map = ComputerUtil.computer(sceneCode, sceneCode, basePath);
-
             // 模型上传oss
             AliyunOssUtil.uploadMulFiles(map);
-            log.info("oss upload success");
-
+            log.info("房源[{}]执行生成模型之后上传oss完成" , house.getId());
             // 3:rsaPano 成功
             house.setStatus(4);
-
         } catch (Exception e) {
             // 4:rsaPano失败
+            log.error("房源[{}]执行生成模型脚本出现异常:{}" , house.getId() , e);
             house.setStatus(5);
             e.printStackTrace();
         } finally {
             house.setUpdateTime(new Date());
-
-            houseService2.update(house);
-            log.info("update db success");
+            int update = houseService2.update(house);
+            if(update == 1){
+                log.info("执行完生成模型脚本,房源[{}]更新状态[{}]成功" , house.getId() , house.getStatus());
+            }else{
+                log.info("执行完生成模型脚本,房源[{}]更新状态[{}]失败" , house.getId() , house.getStatus());
+            }
 
         }
         LocalDateTime endTime = LocalDateTime.now();
-
         Duration.between(starTime, endTime);
-        log.info("total time: {} s", Duration.between(starTime, endTime).getSeconds());
-        log.info("end PanoListener houseId:{}", house.getId());
+        log.info("调用生成模型脚本耗时: {} s", Duration.between(starTime, endTime).getSeconds());
+        log.info("=====================房源[{}]生成模型结束=====================", house.getId());
     }
 
     @RabbitHandler

+ 18 - 19
fdkanfang-web/src/main/java/com/fdkanfang/web/mq/listener/VerticalListener.java

@@ -2,17 +2,21 @@ package com.fdkanfang.web.mq.listener;
 
 import cn.hutool.core.io.FileUtil;
 import com.fdkanfang.common.constant.MsgCode;
+import com.fdkanfang.common.enums.ResultCodeEnum;
 import com.fdkanfang.common.exception.BaseRuntimeException;
+import com.fdkanfang.common.exception.CommonBaseException;
 import com.fdkanfang.common.util.AliyunOssUtil;
 import com.fdkanfang.common.util.CreateObjUtil;
 import com.fdkanfang.domain.backend.HouseEntity;
 import com.fdkanfang.service.backend.HouseService2;
 import com.fdkanfang.web.mq.config.RabbitConfig;
 import lombok.extern.log4j.Log4j2;
+import org.hibernate.boot.spi.InFlightMetadataCollector;
 import org.springframework.amqp.rabbit.annotation.RabbitHandler;
 import org.springframework.amqp.rabbit.annotation.RabbitListener;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Date;
 import java.util.HashMap;
@@ -34,14 +38,12 @@ public class VerticalListener {
      * order结果监听
      */
     @RabbitHandler
+    @Transactional(rollbackFor = Exception.class)
     public void getMessage(HashMap<Object, Object> mqMap){
-        log.info("run VerticalListener ");
-
-//        HashMap<String, String>  rsaUploadMap = (HashMap<String, String>)mqMap.get("ossUpload");
+        log.info("===================收到MQ消息,开始执行垂直校验===================== ");
         Long houseId = (Long)mqMap.get("id");
         String basePath = (String)mqMap.get("basePath");
 
-
         HashMap<String, String>  ossImageHigh = (HashMap<String, String>)mqMap.get("ossImageHigh");
         HashMap<String, String>  ossImageLow = (HashMap<String, String>)mqMap.get("ossImageLow");
 
@@ -52,18 +54,16 @@ public class VerticalListener {
 
         long start = System.currentTimeMillis();
 
-        // 保存数据开关
-        boolean flag = false;
         String filePath = basePath+house.getSceneCode();
         try {
             // 后面跟目录路径就可以了
             String cmd  = "bash /home/ubuntu/HorizonNet/run.sh " + filePath ;
-            log.info("cmd : {}", cmd);
+            log.info("算法linux指令为:{}", cmd);
             // 调用算法
             CreateObjUtil.callshell(cmd);
 
             long end = System.currentTimeMillis();
-            log.info("time: {} s", (end-start)/1000);
+            log.info("调用算法部垂直校验脚本执行耗时: {} s", (end-start)/1000);
 
             /**
              * 假如算法少于2秒就结束,证明算法发生了错误;
@@ -74,13 +74,11 @@ public class VerticalListener {
             }
 
             // 模型上传oss
-//            AliyunOssUtil.uploadMulFiles(rsaUploadMap);
             AliyunOssUtil.uploadMulFiles(ossImageHigh);
             AliyunOssUtil.uploadMulFiles(ossImageLow);
             log.info("oss上传完成");
 
             // 保存信息到db
-
             // 读取算法生成的scene.json内容到数据库
             String scenePath = filePath + "/scene.json";
             String sceneJson = FileUtil.readString(scenePath, "utf-8");
@@ -89,24 +87,25 @@ public class VerticalListener {
 
             // 1:成功
             house.setStatus(1);
-
             log.info("t houseId: {}", house.toString());
 
-
         } catch (Exception e) {
-            log.error("error VerticalListener 转换异常");
+            log.error("error VerticalListener 转换异常:{}" , e);
             // 2:失败
             house.setStatus(2);
-
             e.printStackTrace();
         } finally {
-
             house.setUpdateTime(new Date());
-            int n = houseService2.update(house);
-            log.info("update db success");
-        }
+            int update = houseService2.update(house);
+            if(update == 1){
+                log.info("垂直校验后,更新房源[{}]状态[{}]成功" , house.getId() , house.getStatus());
+            }else{
+                log.info("垂直校验后,更新房源[{}]状态[{}]失败" , house.getId() , house.getStatus());
+                throw new CommonBaseException(ResultCodeEnum.D101 , "更新房源状态失败");
+            }
 
-        log.info("end VerticalListener houseId:{}", house.getId());
+        }
+        log.info("===================处理完MQ消息,房源[{}]的垂直校验完成===================== ", house.getId());
     }