ソースを参照

修改计算结果处理逻辑

tianboguang 2 年 前
コミット
0b2ecc657b

+ 5 - 0
src/main/java/com/fdkankan/contro/service/IFdkkLaserService.java

@@ -1,5 +1,8 @@
 package com.fdkankan.contro.service;
 
+import com.fdkankan.contro.entity.ScenePlus;
+import com.fdkankan.contro.entity.ScenePlusExt;
+
 /**
  * <p>
  * TODO
@@ -12,4 +15,6 @@ public interface IFdkkLaserService {
 
     void updateSceneStatus(String sceneCode,int status);
 
+    void syncBuildResult(ScenePlus scenePlus, ScenePlusExt scenePlusExt);
+
 }

+ 31 - 122
src/main/java/com/fdkankan/contro/service/impl/BuildScenePostServiceImpl.java

@@ -28,6 +28,7 @@ import com.fdkankan.model.utils.CreateHouseJsonUtil;
 import com.fdkankan.model.utils.CreateObjUtil;
 import com.fdkankan.push.config.PushMessageConfig;
 import com.fdkankan.push.utils.PushMsgUtil;
+import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
 import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
@@ -61,6 +62,10 @@ public class BuildScenePostServiceImpl implements IBuildScenePostService {
     private String mainUrl;
     @Value("${scene.pro.new.url}")
     private String sceneProNewUrl;
+
+    @Value("${4dkk.laserService.host}")
+    private String laserHost;
+
     @Autowired
     private ISceneFileBuildService sceneFileBuildService;
     @Autowired
@@ -86,6 +91,9 @@ public class BuildScenePostServiceImpl implements IBuildScenePostService {
     @Autowired
     private IUserIncrementService userIncrementService;
 
+    @Autowired
+    private IFdkkLaserService fdkkLaserService;
+
     @Override
     public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
         Integer cameraType = Integer.parseInt(message.getCameraType());
@@ -99,26 +107,28 @@ public class BuildScenePostServiceImpl implements IBuildScenePostService {
         Boolean buildSuccess = message.getBuildSuccess();
         Integer videoVersion = getVideoVersion(path + File.separator + "capture" +File.separator+"data.fdage");
 
-        Map<String, String> uploadFiles = getUploadFiles(path);
+
 
         Integer pushChannel = message.getPushChannel();
         String pushToken = message.getPushToken();
         String prefix = message.getPrefix();
         try {
-            if(!buildSuccess){//建模失败,修改状态为失败状态
-                log.info("建模失败,修改状态为失败状态");
+            if (!buildSuccess) {
+                log.error("建模失败,修改状态为失败状态");
                 scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
                         .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
                         .eq(ScenePlus::getNum, sceneCode));
 
                 SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
-                if(Objects.nonNull(sceneFileBuild)){
+                if (Objects.nonNull(sceneFileBuild)) {
                     sceneFileBuild.setBuildStatus(BuildStatus.fail.code());
                     sceneFileBuildService.updateById(sceneFileBuild);
                 }
-                return;
+                throw new RuntimeException("建模失败!");
             }
 
+            Map<String, String> uploadFiles = getUploadFiles(path);
+
             //建模成功走以下逻辑
             log.info("cameraType:{}",cameraType);
 
@@ -160,14 +170,12 @@ public class BuildScenePostServiceImpl implements IBuildScenePostService {
             fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, sceneCode) + sceneCode + ".png");
             fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, sceneCode) + sceneCode + "_en.png");
 
-            Map<String, String> newUploadFiles = this.uploadFileMapHandler(sceneCode, cameraType, uploadFiles);
-
             //上传全景图俯视图
-            this.uploadFloorCad(path, sceneCode, newUploadFiles);
+            this.uploadFloorCad(path, sceneCode, uploadFiles);
 
             //上传文件
             log.info("开始上传场景计算结果数据,num:{}", sceneCode);
-            fYunFileService.uploadMulFiles(newUploadFiles);
+            fYunFileService.uploadMulFiles(uploadFiles);
 
             Map<String,String> damFileHeaders = new HashMap<>();
             damFileHeaders.put("Content-Encoding","gzip");
@@ -199,13 +207,22 @@ public class BuildScenePostServiceImpl implements IBuildScenePostService {
             //计算成功,发短信
             this.pushMsgToApp(pushChannel,pushToken, cameraType, scenePlus.getTitle(), scenePlusExt.getWebSite());
 
+            if (cameraType == 14) {
+                //计算成功  激光转台相机 同步 请求
+                fdkkLaserService.syncBuildResult(scenePlus, scenePlusExt);
+            }
             log.info("场景计算结果处理结束,场景码:{}", message.getSceneCode());
 
         }catch (Exception e){
-            log.error("场景计算结果处理出错", e);
+            String errorMsg = "场景计算结果处理出错!";
+            log.error(errorMsg);
+            e.printStackTrace();
+            if(!buildSuccess){
+                errorMsg = "场景构建失败!";
+            }
             //发送钉钉
             String serverPath = message.getPath().substring(0,message.getPath().lastIndexOf("/")+1).concat(prefix);
-//            buildSceneDTService.handFail("场景计算结果处理出错", serverPath, sceneCode, BuildScenePreServiceImpl.hostName, BuildScenePreServiceImpl.contentExt);
+//            buildSceneDTService.handFail(errorMsg, serverPath, sceneCode, BuildScenePreServiceImpl.hostName, BuildScenePreServiceImpl.contentExt);
         }
     }
 
@@ -217,9 +234,9 @@ public class BuildScenePostServiceImpl implements IBuildScenePostService {
 
         String projectNum = scenePlus.getNum();
 
-        String dataPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, projectNum);
-        String imagesPath = String.format(ConstantFilePath.IMAGE_PATH_FORMAT, projectNum);
-        String videoPath = String.format(ConstantFilePath.VIDEO_PATH_FORMAT, projectNum);
+        String dataPath = String.format(UploadFilePath.DATA_VIEW_PATH, projectNum);
+        String imagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, projectNum);
+        String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, projectNum);
         String resultsPath = path + File.separator + "results" + File.separator;
 
         String uploadJsonPath = resultsPath + "upload.json";
@@ -447,36 +464,6 @@ public class BuildScenePostServiceImpl implements IBuildScenePostService {
         }
     }
 
-
-    private Map<String, String> uploadFileMapHandler(String num, int cameraType, Map<String, String> map) {
-        if(CollUtil.isEmpty(map)){
-            return null;
-        }
-
-        String dataPath = String.format("data/data%s/", num);
-        String imagePath = String.format("images/images%s/", num);
-        String videoPath = String.format("video/video%s/", num);
-
-        String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
-        String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
-        String videosViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
-
-        Map<String, String> newMap = new HashMap<>();
-        for (String key : map.keySet()) {
-            String value = map.get(key);
-            if(value.contains(dataPath)){
-                newMap.put(key, value.replace(dataPath, dataViewPath));
-            }
-            if(value.contains(imagePath)){
-                newMap.put(key, value.replace(imagePath, imgViewPath));
-            }
-            if(value.contains(videoPath)){
-                newMap.put(key, value.replace(videoPath, videosViewPath));
-            }
-        }
-        return newMap;
-    }
-
     private JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception {
         //读取videos_hdr_param.json, 保存点位视频的value
         Map<String, Object> videoMap = new HashMap<>();
@@ -712,82 +699,4 @@ public class BuildScenePostServiceImpl implements IBuildScenePostService {
         hourseTypeJsonPath = String.format(UploadFilePath.DATA_EDIT_PATH, num) + "houseType.json";
         fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
     }
-
-    private JSONArray[] createHouseTypeJsonHandler(JSONObject floor){
-
-        JSONArray[] result = new JSONArray[2];
-
-        //处理点
-        Map<Integer, VertexBean> vertexMap = new HashMap<>();
-        Map<String, PointBean> pointMap = new HashMap<>();
-        Map<Integer, String> vpMap = new HashMap<>();
-        JSONArray vertexArr = floor.getJSONArray("vertex-xy");
-        for(int i = 0; i < vertexArr.size(); i++){
-            Object o = vertexArr.get(i);
-
-            VertexBean vertexBean = JSON.parseObject(JSON.toJSONString(o), VertexBean.class);
-            Integer vertexId = vertexBean.getId();
-            vertexMap.put(vertexId, vertexBean);
-
-            String pointId = "Point" + i;
-            pointMap.put(pointId, PointBean.builder().vectorId(pointId).x(vertexBean.getX()).y(vertexBean.getY()).build());
-
-            vpMap.put(vertexId, pointId);
-        }
-
-        //处理墙
-        Map<Integer, SegmentBean> segmentMap = new HashMap<>();
-        Map<String, WallBean> wallMap = new HashMap<>();
-        Map<Integer, String> swMap = new HashMap<>();
-        JSONArray segmentArr = floor.getJSONArray("segment");
-        Map<String, String> startMap = new HashMap<>();
-        Map<String, String> endMap = new HashMap<>();
-        for(int i = 0; i < segmentArr.size(); i++){
-            Object o = segmentArr.get(i);
-
-            SegmentBean segmentBean = JSON.parseObject(JSON.toJSONString(o), SegmentBean.class);
-            String startPointId = vpMap.get(segmentBean.getA());
-            String endPointId = vpMap.get(segmentBean.getB());
-            segmentBean.setStartPointId(startPointId);
-            segmentBean.setEndPointId(endPointId);
-
-            Integer segmentId = segmentBean.getId();
-            segmentMap.put(segmentId, segmentBean);
-
-            String wallId = "Wall" + i;
-            WallBean wallBean = WallBean.builder()
-                .vectorId(wallId)
-                .start(segmentBean.getStartPointId())
-                .end(segmentBean.getEndPointId())
-                .children(new String[]{})
-                .width(0.2d)
-                .build();
-            wallMap.put(wallId, wallBean);
-
-            startMap.put(wallBean.getStart(), wallBean.getVectorId());
-            endMap.put(wallBean.getEnd(), wallBean.getVectorId());
-
-            swMap.put(segmentId, wallId);
-        }
-
-        Collection<PointBean> pointBeans = pointMap.values();
-        for (PointBean pointBean : pointBeans) {
-            Map<String, String> parent = new HashMap<>();
-            String startParent = startMap.get(pointBean.getVectorId());
-            String endParent = endMap.get(pointBean.getVectorId());
-            parent.put(startParent, "start");
-            parent.put(endParent, "end");
-            pointBean.setParent(parent);
-        }
-        JSONArray pointArr = JSON.parseArray(JSON.toJSONString(pointBeans));
-        result[0] = pointArr;
-
-        Collection<WallBean> wallBeans = wallMap.values();
-        JSONArray wallArr = JSON.parseArray(JSON.toJSONString(wallBeans));
-        result[1] = wallArr;
-
-        return result;
-
-    }
-
 }

+ 77 - 0
src/main/java/com/fdkankan/contro/service/impl/IFdkkLaserServiceImpl.java

@@ -1,17 +1,31 @@
 package com.fdkankan.contro.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.constant.HttpCode;
 import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.contro.entity.Camera;
+import com.fdkankan.contro.entity.ScenePlus;
+import com.fdkankan.contro.entity.ScenePlusExt;
+import com.fdkankan.contro.entity.User;
+import com.fdkankan.contro.service.ICameraService;
 import com.fdkankan.contro.service.IFdkkLaserService;
+import com.fdkankan.contro.service.IUserService;
+import com.fdkankan.model.utils.CreateObjUtil;
 import com.fdkankan.web.response.Result;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
+import java.io.File;
+
 @Service
 @Slf4j
 public class IFdkkLaserServiceImpl implements IFdkkLaserService {
@@ -26,6 +40,12 @@ public class IFdkkLaserServiceImpl implements IFdkkLaserService {
     @Value("${4dkk.laserService.host}")
     private String laserHost;
 
+    @Autowired
+    private ICameraService cameraService;
+
+    @Autowired
+    private IUserService userService;
+
     private RestTemplate restTemplate = new RestTemplate();
 
     public void updateSceneStatus(String sceneCode,int status){
@@ -39,4 +59,61 @@ public class IFdkkLaserServiceImpl implements IFdkkLaserService {
         }
     }
 
+    public void syncBuildResult(ScenePlus scenePlus, ScenePlusExt scenePlusExt) {
+        log.info("激光转台相机构建结果 同步 请求 ");
+        try {
+            String title = "";
+            String sceneName = scenePlus.getTitle();
+            if (StringUtils.isNotEmpty(sceneName)) {
+                title = sceneName;
+            }
+            String dataSource = scenePlusExt.getDataSource();
+            String jgPath = dataSource;
+            //创建目录
+            if (dataSource.lastIndexOf("/") != -1) {
+                jgPath = jgPath + "_laserData";
+            } else {
+                jgPath = jgPath.substring(0, jgPath.length() - 1) + "_laserData";
+            }
+
+            FileUtils.createDir(jgPath + "/extras");
+
+            log.info("生成 激光相机目录 " + jgPath);
+            //生成data.json
+            JSONObject jgDataJson = new JSONObject();
+            jgDataJson.put("split_type", "SPLIT_V15");
+            jgDataJson.put("skybox_type", "SKYBOX_V5");
+            jgDataJson.put("extras", null);
+            FileUtils.writeFile(jgPath + File.separator + "data.json", jgDataJson.toString());
+
+            CreateObjUtil.cpfile(dataSource + "/results/laserData/cover", jgPath + "/extras/");
+            CreateObjUtil.cplaserfile(dataSource + "/results/laserData", jgPath + File.separator);
+
+            Camera camera = cameraService.getById(scenePlus.getCameraId());
+            String cameraName = camera.getChildName();
+            //激光相机
+            String url = laserHost + "/indoor/{sceneCode}/service/init?path="
+                    + jgPath + File.separator + "laserData" + "&title=" + title
+                    + "&childName=" + cameraName + "&createTime=" + scenePlus.getCreateTime()
+                    + "&snCode=" + cameraName;
+
+            if (scenePlus.getUserId() != null) {
+                url = url + "&userId=" + scenePlus.getUserId();
+            }
+
+            User user = userService.getById(scenePlus.getUserId());
+
+            if (ObjectUtils.isNotEmpty(user)) {
+                url = url + "&phone=" + user.getUserName();
+            }
+
+            url = url.replace("{sceneCode}", scenePlus.getNum());
+            log.info("激光转台相机 同步 :" + url);
+            JSONObject hotListJson = JSONObject.parseObject(restTemplate.getForObject(url, String.class));
+            log.info("激光转台相机 同步结束 :" + hotListJson);
+        } catch (Exception e) {
+            log.error("激光转台相机同步失败", e);
+        }
+    }
+
 }