Bladeren bron

迁移生成模型到其他机器

houweiyu 5 jaren geleden
bovenliggende
commit
719fb0862e

+ 2 - 2
README.md

@@ -59,7 +59,7 @@
 
 
  
- ##垂直校验/生成模型的目录结构以及用途
+ ##垂直校验/生成模型的目录结构以及用途A
     /data/kanfang/  目录位置
         -- 100001  房源编号
           -- input_img  目录:用户生成的图片位置
@@ -102,7 +102,7 @@
     bash /home/ubuntu/HorizonNet/run.sh /data/kanfang/10023
     
     生成模型:
-    bash /home/ubuntu/bin/Launcher.sh /data/kanfang/t001/pano
+    bash /home/ubuntu/bin/Launcher.sh /mnt/123_data/kanfang/t001/pano
     
 ## rabbit mq
 http://localhost:15672    

+ 3 - 0
fdkanfang-application/src/main/resources/application-dev.properties

@@ -84,3 +84,6 @@ spring.rabbitmq.password=guest
 #queue
 verticle.queue=verticalQueue
 
+
+#垂直校验远程调用脚本路径
+verticle.remote.call.path=bash /home/algorithm/HorizonNet.sh 

+ 13 - 5
fdkanfang-application/src/main/resources/application-sit.properties

@@ -6,7 +6,7 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
 spring.datasource.druid.url=jdbc:mysql://localhost:3306/fdkanfang?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
 spring.datasource.druid.username=root
 #spring.datasource.druid.password=4dkk2019%
-spring.datasource.druid.password=4dkk2020test%
+spring.datasource.druid.password=4dagecui2019$
 
 
 # \u521D\u59CB\u8FDE\u63A5\u6570
@@ -52,20 +52,28 @@ spring.redis.jedis.pool.max-wait=-1ms
 
 # \u6587\u4EF6\u4FDD\u5B58\u8DEF\u5F84\uFF0C\u7B97\u6CD5\u751F\u6210\u6587\u4EF6\u5730\u5740
 #output.file.path=/data/kanfang/
-output.file.path=/root/data/kanfang/
+output.file.path=/mnt/data_sk/kanfang/
 
 #\u7F16\u8F91\u9875\u9762
-server.domain=http://39.108.220.65:8084/fdkanfang/spc.html
+server.domain=http://120.24.64.23:8084/fdkanfang/spc.html
 
 #log
 logging.path=${output.file.path}fdkanfang_log
 logging.config=classpath:logback-spring.xml
 logging.level.com.fdkanfang=debug
 
-
+#rabbit MQ
+spring.rabbitmq.host=127.0.0.1
+#spring.rabbitmq.host=localhost
+spring.rabbitmq.port=5672
+spring.rabbitmq.username=4dage 
+spring.rabbitmq.password=4dagecui2019$
 
 #四维看看的登录域名
 4dkankan.host=https://4dkankan.com/
 
 #queue
-verticle.queue=verticalQueue
+verticle.queue=verticalQueue
+
+#垂直校验远程调用脚本路径
+verticle.remote.call.path=bash /home/algorithm/HorizonNet.sh 

+ 1 - 1
fdkanfang-application/src/main/resources/application.properties

@@ -1,6 +1,6 @@
 server.port=8084
 
-spring.profiles.active=dev
+spring.profiles.active=sit
 
 # \u8BBF\u95EE\u9759\u6001\u8D44\u6E90\u8BBE\u7F6E
 spring.resources.static-locations=classpath:templates/,classpath:static/,classpath:web/

+ 115 - 0
fdkanfang-common/src/main/java/com/fdkanfang/common/util/DataUtils.java

@@ -0,0 +1,115 @@
+package com.fdkanfang.common.util;
+
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author abnerhou
+ * @date 2020/4/23 17:35
+ * @desciption
+ */
+@Component
+public class DataUtils {
+
+    public static BigDecimal getBigDecimalObj(Object data) {
+
+        if (null == data) {
+            return null;
+        } else if (data instanceof String) {
+            String dataStr = (String) data;
+            if (!StringUtils.isEmpty(dataStr.trim())) {
+                return new BigDecimal(dataStr.trim());
+            }
+        } else if (data instanceof Long) {
+            Long dataLong = (Long) data;
+            return BigDecimal.valueOf(dataLong);
+        } else if (data instanceof Integer) {
+            Integer dataInt = (Integer) data;
+            return BigDecimal.valueOf(dataInt);
+
+        } else if (data instanceof Double) {
+            Double dataDouble = (Double) data;
+            return BigDecimal.valueOf(dataDouble);
+        }
+
+        return null;
+
+    }
+
+    public static Integer getInteger(Object object) {
+        if (null == object) {
+            return new Integer(0);
+        }
+        if (object instanceof String) {
+            String ojStr = (String) object;
+            if (StringUtils.isEmpty(ojStr)) {
+                //TODO:在斟酌这里的处理方式
+                return new Integer(0);
+            } else {
+                return new Integer(Integer.parseInt(ojStr.trim()));
+            }
+        } else if (object instanceof Integer) {
+            return (Integer) object;
+        } else if (object instanceof Long) {
+            return (Integer) object;
+        } else if (object instanceof Double) {
+            return (Integer) object;
+        } else {
+            return new Integer(0);
+        }
+    }
+
+    public static Long getLongReturnNullIfNotExit(Object num){
+        if(null == num){
+            return null;
+        }else if(num instanceof String){
+            if(!StringUtils.isEmpty((String) num)){
+                String numStr = (String) num;
+                return Long.parseLong(numStr.trim());
+            }
+        }else if(num instanceof Integer){
+            return (Long) num;
+        }else if(num instanceof  Long){
+            return (Long) num;
+        }
+        return null;
+    }
+
+    public static Integer getIntegerWithDefault(Object object, boolean withDefault) {
+        if (null == object) {
+
+            return withDefault ? new Integer(0) : null;
+        }
+        if (object instanceof String) {
+            String ojStr = (String) object;
+            if (StringUtils.isEmpty(ojStr)) {
+
+                return withDefault ? new Integer(0) : null;
+            } else {
+                return new Integer(Integer.parseInt(ojStr.trim()));
+            }
+        } else if (object instanceof Integer) {
+            return (Integer) object;
+        } else if (object instanceof Long) {
+            return (Integer) object;
+        } else if (object instanceof Double) {
+            return (Integer) object;
+        } else {
+            return withDefault ? new Integer(0) : null;
+        }
+    }
+
+    public static Map<String, Object> assembleResult(long totalNum, long totalPageNum, long currPageNum, Object list) {
+        Map<String, Object> resultMap = new HashMap<>();
+        resultMap.put("totalNum", totalNum);
+        resultMap.put("totalPageNum", totalPageNum);
+        resultMap.put("curPage", currPageNum);
+        resultMap.put("list", list);
+        return resultMap;
+    }
+
+}

+ 55 - 47
fdkanfang-web/src/main/java/com/fdkanfang/web/backend/HouseController.java

@@ -19,13 +19,11 @@ import com.fdkanfang.domain.response.UserResponse;
 import com.fdkanfang.service.backend.*;
 import com.fdkanfang.web.backend.utils.UserUtils;
 import com.fdkanfang.web.mq.config.RabbitConfig;
-import com.fdkanfang.web.shiro.JWTUtil;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.*;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.authz.annotation.Logical;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.apache.shiro.authz.annotation.RequiresRoles;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.BeanUtils;
@@ -35,13 +33,14 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
-import tk.mybatis.mapper.entity.Condition;
 
 import javax.validation.Valid;
 import java.io.File;
 import java.io.IOException;
-import java.time.LocalDateTime;
-import java.util.*;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 
 
@@ -62,6 +61,9 @@ public class HouseController extends BaseController {
     @Value("${server.domain}")
     private String domain;
 
+    @Value("${4dkankan.host}")
+    private String KankanHost;
+
     @Autowired
     private HouseService2 houseService2;
 
@@ -626,8 +628,7 @@ public class HouseController extends BaseController {
         try {
 
             FileUtils.createDir(sourcePath);
-/*
-          /***
+          /**
                  * 以下字段为给算法部传递的参数(data.json),用于生成模型和
                  * 照片,提供前端使用,完整的参数如下:
                  * {
@@ -677,28 +678,19 @@ public class HouseController extends BaseController {
                 log.error("vision不能为空");
                 return new R(50002, "vision不能为空");
             }
-
             // json写入服务器
             FileUtils.fileWriter(floorPlan, sourcePath + "floorplan.json");
             FileUtils.fileWriter(vision, sourcePath + "vision.txt");
-
-
-
             log.info("floorplan.json生成完成");
             log.info("vision.txt生成完成");
-
             // 复制垂直校验图片到指定目录
             String verticalImagePath = OUTPATH + sceneCode+"/output_img";
             String panoImagePath = sourcePath + "images/";
-
             // srcPath: /data/kanfang/10002/output_img
             log.info("srcPath: {}", verticalImagePath);
-
             // target: /data/kanfang/10002/pano/extras/images/
             log.info("target: {}", panoImagePath);
-
             FileUtil.copyFilesFromDir(new File(verticalImagePath), new File(panoImagePath), true);
-
             flagQ = true;
 
         } catch (Exception e) {
@@ -708,52 +700,69 @@ public class HouseController extends BaseController {
         }
 
         if (flagQ) {
-            HashMap<Object, Object> mqMap = new HashMap<>();
-            mqMap.put("id", house.getId());
-            mqMap.put("basePath", savePath);
+          /*  mqMap.put("id", house.getId());
+            mqMap.put("basePath", savePath);*/
 
             // 上传floorplan.json到oss, 并命名为floor.json
             HashMap<String, String> uploadJson = new HashMap<>();
-
             // osspath : images/images+sceneCode/floor.json
             uploadJson.put(sourcePath + "floorplan.json", ConstantFilePath.OSS_FLOOR_PATH+sceneCode+"/floor.json");
             AliyunOssUtil.uploadMulFiles(uploadJson);
-
             // savePath:/data/kanfang/房源编号/
             // basePath: /data/kanfang/10002/pano
             log.info("basePath: {}", savePath);
             log.info("houseId: {}", house.getId());
 
-            //发消息到mq
-            rabbitTemplate.convertAndSend(RabbitConfig.PANO_EXCHANGE, RabbitConfig.PANO_QUEUE_ROUTING, mqMap);
-
-            // 修改房源状态, 3:模型计算中
-            house.setStatus(3);
-            house.setUpdateTime(new Date());
-            houseService2.update(house);
-
-
             // 每点击生成模型一次,就修改SceneProEditEntity的部分值
             SceneProEntity sceneProEntity = sceneProService.findBySceneNum(house.getSceneCode());
             if (sceneProEntity == null) {
                 log.error("sceneProEntity对象不存在:{}", house.getSceneCode());
                 return new R(MsgCode.ERROR_CODE, "sceneProEntity对象不存在");
             }
+
+            // 修改房源状态, 3:模型计算中
+            house.setStatus(3);
+            house.setUpdateTime(new Date());
+            int updateHouse = houseService2.update(house);
+            if(updateHouse != 1){
+                throw new CommonBaseException(ResultCodeEnum.D101 , "更新房源状态失败");
+            }
+
             SceneProEditEntity proEditEntity = sceneProEditService.findByProId(sceneProEntity.getId());
             proEditEntity.setVersion(proEditEntity.getVersion() + 1);
             proEditEntity.setFloorEditVer(proEditEntity.getFloorEditVer() + 1);
             proEditEntity.setFloorPublishVer(proEditEntity.getFloorPublishVer() + 1);
             proEditEntity.setUpdateTime(new Date());
 
-            sceneProEditService.update(proEditEntity);
+            int updateSceneProEdit = sceneProEditService.update(proEditEntity);
+            if(updateSceneProEdit != 1){
+                throw new CommonBaseException(ResultCodeEnum.D101 , "更新sceneProEdit状态失败");
+            }
             log.info("更新SceneProEditEntity数据完成");
 
+            //发消息到mq
+            Map<String, Object> mqMap = formatMqReq(house , sceneProEntity , savePath);
+            rabbitTemplate.convertAndSend(RabbitConfig.PANO_EXCHANGE, RabbitConfig.PANO_QUEUE_ROUTING, mqMap);
             log.info("入队成功");
+
         }
 
         return new R(MsgCode.SUCCESS_CODE, house);
     }
 
+    private Map<String, Object> formatMqReq(HouseEntity house , SceneProEntity sceneProEntity , String path){
+        Map<String ,Object> result = new HashMap<>();
+        if(null == house){
+            return result;
+        }
+        result.put("sceneName" , house.getDistrictName());
+        result.put("sceneNum" , house.getSceneCode());
+        result.put("sceneScheme" , sceneProEntity.getSceneScheme());
+        result.put("userId" , house.getUserId());
+        result.put("dataSource" , path);
+        return  result;
+    }
+
     private String checkImageResolutionRate(HouseEntity houseEntity){
         if(null == houseEntity || null == houseEntity.getId()){
             return null;
@@ -784,24 +793,23 @@ public class HouseController extends BaseController {
 
 
     /***
-     * 获取唯一场景码
+     * 从四维看看获取唯一场景码
      */
     private String getSceneCode(){
-        String randowString = null;
-        Condition condition = new Condition(HouseEntity.class);
-
-        List<HouseEntity> all = null;
-
-        boolean flag = true;
-        while (flag) {
-            randowString = RandomUtils.randowString(9);
-            condition.and().andEqualTo("sceneCode", randowString);
-            all = houseService2.findAll(condition);
-            log.info(all.size());
-            flag = all.size() > 0;
-        }
-        log.info("code: {}", randowString);
-        return "d_" + randowString;
+        String url = KankanHost + "api/scene/finSkSceneNum";
+        String kankanResult = HttpClientUtil.doPost(url);
+        //解析返回结果
+        JSONObject res = JSONObject.parseObject(kankanResult);
+        log.info("四维看看返回登录数据:{}" , null != res ? res.toJSONString() : "返回结果为null");
+        Integer code = DataUtils.getInteger(res.get("code"));
+        if(null == code || code.compareTo(0) != 0){
+            throw new CommonBaseException(ResultCodeEnum.D101 , "从四维看看获取场景码失败");
+        }
+        String sceneCode = res.getString("msg");
+        if(StringUtils.isBlank(sceneCode)){
+            throw new CommonBaseException(ResultCodeEnum.D101 , "四维看看返回的场景码为空");
+        }
+        return sceneCode;
     }
 
 

+ 34 - 0
fdkanfang-web/src/main/java/com/fdkanfang/web/mq/config/RabbitConfig.java

@@ -35,6 +35,15 @@ public class RabbitConfig {
     public static final String PANO_QUEUE_ROUTING = "panoQueueRouting";
 
 
+    /** 生成模型队列*/
+    public static final String PANO_CALLBACK_QUEUE = "panoCallbackQueue";
+
+    /** 生成模型交换机*/
+    public static final String PANO_CALLBACK_EXCHANGE = "panoCallbackExchange";
+
+    /** 生成模型交换机路由*/
+    public static final String PANO_CALLBACK_QUEUE_ROUTING = "panoCallbackQueueRouting";
+
 
     /**
      * 创建队列
@@ -87,4 +96,29 @@ public class RabbitConfig {
         return BindingBuilder.bind(panoQueue).to(panoExchange).with(PANO_QUEUE_ROUTING).noargs();
     }
 
+
+    /**
+     * 创建生成模回调型队列
+     */
+    @Bean
+    public Queue panoCallbackQueue() {
+        return new Queue(PANO_CALLBACK_QUEUE);
+    }
+
+    /**
+     * 创建生成模型回调交换机
+     */
+    @Bean
+    public Exchange panoCallbackExchange(){
+        return new DirectExchange(PANO_CALLBACK_EXCHANGE, true, false);
+    }
+
+
+    /**
+     * 生成模型回调队列绑定交换机
+     */
+    @Bean
+    public Binding panoCallbackQueueExchange(Queue panoCallbackQueue, Exchange panoCallbackExchange){
+        return BindingBuilder.bind(panoCallbackQueue).to(panoCallbackExchange).with(PANO_CALLBACK_QUEUE_ROUTING).noargs();
+    }
 }

+ 49 - 60
fdkanfang-web/src/main/java/com/fdkanfang/web/mq/listener/PanoListener.java

@@ -1,33 +1,28 @@
 package com.fdkanfang.web.mq.listener;
 
-import com.fdkanfang.common.constant.MsgCode;
-import com.fdkanfang.common.exception.BaseRuntimeException;
-import com.fdkanfang.common.util.AliyunOssUtil;
-import com.fdkanfang.common.util.ComputerUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkanfang.common.util.DataUtils;
 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.apache.commons.lang3.StringUtils;
 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 org.springframework.util.CollectionUtils;
 
-import java.time.Duration;
-import java.time.LocalDateTime;
-import java.util.Date;
-import java.util.HashMap;
 import java.util.Map;
 
 /**
  * Created by owen on 2020/3/16 0016 18:17
  *
- * 生成模型消息监听
+ * 生成模回调型消息监听
  */
 @Log4j2
 @Component
-@RabbitListener(queues = RabbitConfig.PANO_QUEUE) // 指定监听队列
+@RabbitListener(queues = RabbitConfig.PANO_CALLBACK_QUEUE) // 指定监听队列
 public class PanoListener {
 
     @Autowired
@@ -38,57 +33,51 @@ public class PanoListener {
      */
     @RabbitHandler
 //    @Transactional(rollbackFor = Exception.class)
-    public void getMessage(HashMap<Object, Object> mqMap)  {
-        log.info("=====================收到生成模型消息,开始生成模型=====================");
-
-        LocalDateTime starTime = LocalDateTime.now();
-
-        Long houseId = (Long)mqMap.get("id");
-        String basePath = (String)mqMap.get("basePath");
-        log.info("生成模型基础文件目录为:{}" , basePath);
-        HouseEntity house = houseService2.findById(houseId);
-        if (house == null) {
-            log.error("房源不存在,无法生成模型");
-            throw new BaseRuntimeException(MsgCode.e_COMMON_3002, MsgCode.msg_COMMON_3002);
+    public void getMessage(String content)  {
+        log.info("=====================收到生成模型回调消息,回调开始=====================");
+        log.info("接收到的消息为:{}" , content);
+        if(StringUtils.isBlank(content)){
+            log.warn("MQ返回消息为空,无法更新房源状态");
+            return;
         }
-        String sceneCode = house.getSceneCode();
-        try {
-            //计算模型并返回需要上传oss的文件集合
-            Map<String, String> map = ComputerUtil.computer(sceneCode, sceneCode, basePath);
-            // 模型上传oss
-            AliyunOssUtil.uploadMulFiles(map);
-            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());
-            int update = houseService2.update(house);
-            if(update == 1){
-                log.info("执行完生成模型脚本,房源[{}]更新状态[{}]成功" , house.getId() , house.getStatus());
-            }else{
-                log.info("执行完生成模型脚本,房源[{}]更新状态[{}]失败" , house.getId() , house.getStatus());
-            }
-
+        Map<String ,Object> mqMap = JSONObject.parseObject(content , Map.class);
+        if(CollectionUtils.isEmpty(mqMap)){
+            log.error("MQ返回消息解析失败");
+            return;
         }
-        LocalDateTime endTime = LocalDateTime.now();
-        Duration.between(starTime, endTime);
-        log.info("调用生成模型脚本耗时: {} s", Duration.between(starTime, endTime).getSeconds());
-        log.info("=====================房源[{}]生成模型结束=====================", house.getId());
-    }
-
-    @RabbitHandler
-    public void getMessage(String msg)  {
-        log.info("run testPanoListener ");
-
-
-        log.info("end testPanoListener msg: {}", msg);
+        if(!mqMap.containsKey("result")){
+            log.error("看看MQ没有返回建模结果");
+            return;
+        }
+        String sceneNum = (String) mqMap.get("sceneNum");
+        if(StringUtils.isBlank(sceneNum)){
+            log.warn("看看房返回结算结果的场景码为空");
+            return;
+        }
+        HouseEntity houseEntity = houseService2.findBySceneCode(sceneNum);
+        if(null == houseEntity){
+            log.error("场景码[{}]对应的房源信息不存在,不更新模型生成结果" , sceneNum);
+            return;
+        }
+        Integer result = DataUtils.getInteger(mqMap.get("result"));
+        if(null == result){
+            log.error("解析看看返回的计算结果失败");
+            return;
+        }
+        if(result.compareTo(1) == 0){
+            log.info("看看返回建模计算成功");
+            houseEntity.setStatus(4);
+        }else{
+            log.info("看看返回建模计算非成功:{}" , result);
+            houseEntity.setStatus(5);
+        }
+        int update = houseService2.update(houseEntity);
+        if(update == 1){
+            log.info("执行完生成模型脚本后,房源[{}]更新状态[{}]成功" , houseEntity.getId() , houseEntity.getStatus());
+        }else{
+            log.info("执行完生成模型脚本后,房源[{}]更新状态[{}]失败" , houseEntity.getId() , houseEntity.getStatus());
+        }
+        log.info("=====================房源[{}]生成模型回调结束=====================", houseEntity.getId());
     }
 
-
-
 }

+ 5 - 1
fdkanfang-web/src/main/java/com/fdkanfang/web/mq/listener/VerticalListener.java

@@ -14,6 +14,7 @@ import org.springframework.amqp.rabbit.annotation.RabbitHandler;
 import org.springframework.amqp.rabbit.annotation.RabbitListener;
 import org.springframework.amqp.support.postprocessor.MessagePostProcessorUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.util.Date;
@@ -34,6 +35,8 @@ public class VerticalListener {
     @Autowired
     private HouseService2 houseService2;
 
+    @Value("${verticle.remote.call.path}")
+    private String verticleCallPath;
     /**
      * order结果监听
      */
@@ -57,7 +60,8 @@ public class VerticalListener {
         String filePath = basePath+house.getSceneCode();
         try {
             // 后面跟目录路径就可以了
-            String cmd  = "bash /home/ubuntu/HorizonNet/run.sh " + filePath ;
+//            String cmd  = "bash /home/ubuntu/HorizonNet/run.sh " + filePath ;
+            String cmd  = verticleCallPath + " " + filePath ;
             log.info("算法linux指令为:{}", cmd);
             // 调用算法
             CreateObjUtil.callshell(cmd);