Pārlūkot izejas kodu

添加三维家V4场景逻辑

tianboguang 2 gadi atpakaļ
vecāks
revīzija
bc9e35beff

+ 63 - 8
src/main/java/com/fdkankan/scene/controller/Scene3dFamilyController.java

@@ -1,19 +1,16 @@
 package com.fdkankan.scene.controller;
 
 import cn.hutool.core.util.StrUtil;
-import com.dtflys.forest.annotation.Get;
 import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.scene.entity.Scene3dfamily;
+import com.fdkankan.scene.entity.ScenePlus;
+import com.fdkankan.scene.entity.ScenePlusExt;
 import com.fdkankan.scene.entity.ScenePro;
-import com.fdkankan.scene.service.IScene3dfamilyService;
-import com.fdkankan.scene.service.ISceneProService;
-import com.fdkankan.scene.service.IUserService;
+import com.fdkankan.scene.service.*;
 import com.fdkankan.web.controller.BaseController;
 import com.fdkankan.web.response.Result;
 import com.fdkankan.web.user.SSOUser;
-import java.util.Arrays;
-import java.util.Date;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,9 +19,11 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Arrays;
+import java.util.Date;
+
 
 /**
  * 三维家
@@ -39,6 +38,13 @@ public class Scene3dFamilyController extends BaseController {
     private IScene3dfamilyService scene3dFamilyService;
     @Autowired
     private ISceneProService sceneProService;
+
+    @Autowired
+    private IScenePlusService scenePlusService;
+
+    @Autowired
+    private IScenePlusExtService scenePlusExtService;
+
     @Autowired
     private IUserService userService;
 
@@ -75,7 +81,7 @@ public class Scene3dFamilyController extends BaseController {
         if(scene3dFamilyEntity != null){
             throw new BusinessException(ErrorCode.FAILURE_CODE_5031);
         }
-        scene3dFamilyService.updateSceneNumByNum(sceneProEntity);
+        scene3dFamilyService.updateSceneNumByNum(sceneProEntity.getNum());
 
         //信息入库
         scene3dFamilyEntity = new Scene3dfamily();
@@ -91,6 +97,55 @@ public class Scene3dFamilyController extends BaseController {
         return Result.success();
     }
 
+    /**
+     *
+     * 三维家 拉取场景数据,压缩zip包
+     */
+    @GetMapping(value = "/scenecpzipV4")
+    public Result scenecpzipV4(String sceneNum) throws Exception{
+        String token = getToken();
+        if(StringUtils.isEmpty(token)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3004);
+        }
+        SSOUser ssoUser = this.getSsoUserV3();
+        if(ssoUser == null || ssoUser.getId() == null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3004);
+        }
+
+        if(StrUtil.isEmpty(sceneNum)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
+        }
+
+        ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
+        if(ObjectUtils.isEmpty(scenePlus)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+        }
+        ScenePlusExt plusExt = scenePlusExtService.getByScenePlusId(scenePlus.getId());
+        String dataSource = plusExt.getDataSource();
+        String thumb = plusExt.getThumb();
+
+
+        //验证是否在打包
+        Scene3dfamily scene3dFamilyEntity = scene3dFamilyService.findSceneNumByNum(sceneNum,0);
+        if(scene3dFamilyEntity != null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5031);
+        }
+        scene3dFamilyService.updateSceneNumByNum(sceneNum);
+
+        //信息入库
+        scene3dFamilyEntity = new Scene3dfamily();
+        scene3dFamilyEntity.setSceneNum(sceneNum);
+        scene3dFamilyEntity.setStatus(0);
+        scene3dFamilyEntity.setZipStartTime(new Date());
+        scene3dFamilyEntity.setCreateUesr(ssoUser.getId());
+        scene3dFamilyEntity.setUpdateUesr(ssoUser.getId());
+        scene3dFamilyService.save(scene3dFamilyEntity);
+
+        scene3dFamilyService.createZip(sceneNum,dataSource,thumb, ssoUser.getId());
+
+        return Result.success();
+    }
+
 
     /**
      *

+ 2 - 1
src/main/java/com/fdkankan/scene/service/IScene3dfamilyService.java

@@ -17,6 +17,7 @@ public interface IScene3dfamilyService extends IService<Scene3dfamily> {
 
     JSONObject findSceneNumByNum2(ScenePro sceneProEntity);
 
-    void updateSceneNumByNum (ScenePro sceneProEntity);
+    void updateSceneNumByNum (String sceneNum);
 
+    Result createZip(String sceneNum, String dataSource, String thumb, Long userId) throws Exception;
 }

+ 155 - 6
src/main/java/com/fdkankan/scene/service/impl/Scene3dfamilyServiceImpl.java

@@ -14,6 +14,7 @@ import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.model.constants.ConstantFilePath;
+import com.fdkankan.model.constants.UploadFilePath;
 import com.fdkankan.model.utils.CreateObjUtil;
 import com.fdkankan.scene.bean.EulerAngles;
 import com.fdkankan.scene.bean.ResponseScene;
@@ -25,15 +26,16 @@ import com.fdkankan.scene.service.IScene3dfamilyService;
 import com.fdkankan.scene.service.ISceneProService;
 import com.fdkankan.web.response.Result;
 import com.fdkankan.web.response.ResultData;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
 import java.io.File;
 import java.io.FileWriter;
 import java.util.Date;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
 
 /**
  * Created by Hb_zzZ on 2019/6/28.
@@ -207,9 +209,9 @@ public class Scene3dfamilyServiceImpl extends ServiceImpl<IScene3dfamilyMapper,
     }
 
     @Override
-    public void updateSceneNumByNum (ScenePro sceneProEntity){
+    public void updateSceneNumByNum (String sceneNum){
         this.update(new LambdaUpdateWrapper<Scene3dfamily>().set(Scene3dfamily::getRecStatus,
-            RecStatus.DISABLE.code()).eq(Scene3dfamily::getSceneNum, sceneProEntity.getNum()));
+            RecStatus.DISABLE.code()).eq(Scene3dfamily::getSceneNum, sceneNum));
     }
 
     private void downloadVisionData(ScenePro sceneProEntity) throws Exception {
@@ -233,6 +235,22 @@ public class Scene3dfamilyServiceImpl extends ServiceImpl<IScene3dfamilyMapper,
         fYunFileService.uploadFile(dataBuffer.toString() + "vision.json", dataBuf.toString() + "vision.json");
     }
 
+    private void downloadVisionData(String sceneNum) throws Exception {
+        String dataBuf = String.format(UploadFilePath.IMG_VIEW_PATH,sceneNum);
+
+        String dataBuffer = String.format(ConstantFilePath.SCENE_IMAGES_PATH_V4,sceneNum);
+
+        fYunFileService.downloadFile(dataBuf.toString() + "vision.modeldata", dataBuffer.toString() + "vision.modeldata");
+
+        File file = new File(dataBuffer.toString() + "vision.modeldata");
+        if(!file.exists()) {
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
+        }
+        CreateObjUtil.convertVisionmodeldataToTxt(dataBuffer.toString() + "vision.modeldata", dataBuffer.toString() + "vision.json");
+
+        fYunFileService.uploadFile(dataBuffer.toString() + "vision.json", dataBuf.toString() + "vision.json");
+    }
+
     /**
      *
      * @param src   vision.json 路径
@@ -277,4 +295,135 @@ public class Scene3dfamilyServiceImpl extends ServiceImpl<IScene3dfamilyMapper,
         }
 
     }
+
+    @Override
+    public Result createZip(String sceneNum, String dataSource, String thumb, Long userId) throws Exception {
+        Scene3dfamily scene3dFamilyEntity = this.findSceneNumByNum(sceneNum,0);
+        String path = dataSource + "_3df" + File.separator + sceneNum;
+        try {
+            if(scene3dFamilyEntity == null){
+                throw new BusinessException(ErrorCode.FAILURE_CODE_5032);
+            }
+
+            log.info("三维家 信息保存 路径 : " + path);
+            //创建文件夹
+            FileUtils.createDir(path);
+
+            //生成vision.json
+            this.downloadVisionData(sceneNum);
+
+            String dataBuffer = String.format(ConstantFilePath.SCENE_IMAGES_PATH_V4,sceneNum);
+
+            String dataBuf = "data" + File.separator + "data" + sceneNum + File.separator;
+
+            this.visionTxtToPano(dataBuffer + "vision.json",path+ File.separator +"scene"+ File.separator+ dataBuf );
+
+            //拉取data
+            fYunFileService.downloadFileByCommand(path + File.separator + "scene" + File.separator + "data" + File.separator + "data" + sceneNum,
+                    String.format(UploadFilePath.DATA_VIEW_PATH,sceneNum));
+
+            // 下载用户的户型图数据
+            if (fYunFileService.fileExist(String.format(UploadFilePath.USER_VIEW_PATH, sceneNum) + "houst_floor.json")) {
+                fYunFileService.downloadFile(String.format(UploadFilePath.USER_VIEW_PATH, sceneNum) + "houst_floor.json",
+                        path + File.separator + "scene" + File.separator + "data" + File.separator + "data" + sceneNum
+                );
+            }
+
+            if (fYunFileService.fileExist(String.format(UploadFilePath.USER_VIEW_PATH, sceneNum) + "floorplan_cad.json")) {
+                fYunFileService.downloadFile(String.format(UploadFilePath.USER_VIEW_PATH, sceneNum) + "floorplan_cad.json",
+                        path + File.separator + "scene" + File.separator + "data" + File.separator + "data" + sceneNum
+                );
+            }
+
+            //转换house.json
+            Integer bo = JsonToHouseUtil.ToHouseJson(path + File.separator + "scene" + File.separator + dataBuf);
+
+            if (bo != 0) {
+                switch (bo) {
+                    case -1:
+                        throw new BusinessException(ErrorCode.FAILURE_CODE_5029.code(), "点位数据为空");
+                    case -2:
+                        throw new BusinessException(ErrorCode.FAILURE_CODE_5029.code(), "点位数据重复");
+                    case -3:
+                        throw new BusinessException(ErrorCode.FAILURE_CODE_5029.code(), "转换异常");
+                    case -4:
+                        throw new BusinessException(ErrorCode.FAILURE_CODE_5029.code(), "源文件不存在");
+                }
+            }
+
+            //下载 scene.json 改名为 getinfo.json
+            fYunFileService.downloadFile(String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum) + "scene.json",
+                    path + File.separator + "scene"  + File.separator + "data" +  File.separator  + "data"
+                            + sceneNum + File.separator + "getinfo.json");
+
+            //下载场景封面图
+            String ossImagePath =  String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
+            String ImagePath = path + File.separator + "scene"  + File.separator + "images" + File.separator + "images" + sceneNum;
+            FileUtils.downLoadFromUrl(thumb,"cover.jpg", ImagePath);
+
+            //拉取images
+            fYunFileService.downloadFile(ossImagePath + "floorLogoImg.png", ImagePath + "/floorLogoImg.png");
+            fYunFileService.downloadFile(ossImagePath + "floorplan.png", ImagePath + "/floorplan.png");
+            fYunFileService.downloadFile(ossImagePath + "logo-main.png", ImagePath + "/logo-main.png");
+            fYunFileService.downloadFile(ossImagePath + "logo-main-en.png", ImagePath + "/logo-main-en.png");
+            fYunFileService.downloadFile(ossImagePath + "smallPic.jpg", ImagePath + "/smallPic.jpg");
+            fYunFileService.downloadFile(ossImagePath + "thumbBigImg.jpg", ImagePath + "/thumbBigImg.jpg");
+            fYunFileService.downloadFile(ossImagePath + "thumbSmallImg.jpg", ImagePath + "/thumbSmallImg.jpg");
+            fYunFileService.downloadFileByCommand(ImagePath + "/pan", ossImagePath + "pan");
+
+            // 异步执行
+            CompletableFuture.runAsync(()->{
+                //压缩zip
+                try {
+                    log.info("开始异步执行打包逻辑……");
+                    //获取六面体图
+                    fYunFileService.downloadFileByCommand(ImagePath + "/tiles", ossImagePath + "tiles");
+
+                    //拉取video
+                    fYunFileService.downloadFileByCommand(path + File.separator + "scene"  + File.separator + "video" + File.separator + "video" + sceneNum,
+                            String.format(UploadFilePath.VIDEOS_VIEW_PATH, sceneNum));
+
+                    //拉取voice
+                    fYunFileService.downloadFileByCommand(path + File.separator + "scene"  + File.separator + "voice" + File.separator + "voice" + sceneNum,
+                            String.format(UploadFilePath.VOICE_VIEW_PATH, sceneNum));
+
+                    ZipUtil.zip(path, path + ".zip");
+
+                    log.info("三维家 zip完成 : " + path);
+
+                    //上传oss
+                    // 上传到阿里云sso
+                    fYunFileService.uploadFileByCommand(path + ".zip", DIR_NAME + sceneNum + ".zip");
+                    log.info("upload success");
+
+                    String url = fyunHost + DIR_NAME + sceneNum + ".zip";
+
+                    log.info("upload url: {}" + url);
+
+                    scene3dFamilyEntity.setZipLink(url);
+                    scene3dFamilyEntity.setStatus(1);
+                    scene3dFamilyEntity.setZipEndTime(new Date());
+                    scene3dFamilyEntity.setUpdateTime(new Date());
+                    this.updateById(scene3dFamilyEntity);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    scene3dFamilyEntity.setStatus(2);
+                    scene3dFamilyEntity.setZipEndTime(new Date());
+                    scene3dFamilyEntity.setUpdateTime(new Date());
+                    this.updateById(scene3dFamilyEntity);
+                }finally {
+                    FileUtils.deleteDirectory(path);
+                    FileUtils.deleteFile(path + ".zip");
+                }
+            });
+        }catch (Exception e){
+            scene3dFamilyEntity.setStatus(2);
+            scene3dFamilyEntity.setZipEndTime(new Date());
+            scene3dFamilyEntity.setUpdateTime(new Date());
+            this.updateById(scene3dFamilyEntity);
+            e.printStackTrace();
+            throw e;
+        }
+        return Result.success();
+    }
 }