dengsixing il y a 3 ans
Parent
commit
202d227a19

+ 5 - 0
4dkankan-center-scene/pom.xml

@@ -76,6 +76,11 @@
             <version>1.5.19</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.google.firebase</groupId>
+            <artifactId>firebase-admin</artifactId>
+            <version>6.8.1</version>
+        </dependency>
 
     </dependencies>
 

+ 0 - 15
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/IBuildSceneDTService.java

@@ -1,15 +0,0 @@
-package com.fdkankan.scene.service;
-
-/**
- * <p>
- * TODO
- * </p>
- *
- * @author dengsixing
- * @since 2022/3/1
- **/
-public interface IBuildSceneDTService {
-
-    void handFail(String reason, String serverPath, String num, String hostName, String contentExt);
-
-}

+ 0 - 17
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/IBuildScenePostService.java

@@ -1,17 +0,0 @@
-package com.fdkankan.scene.service;
-
-import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
-
-/**
- * <p>
- * TODO
- * </p>
- *
- * @author dengsixing
- * @since 2022/3/1
- **/
-public interface IBuildScenePostService {
-
-    void buildScenePost(BuildSceneResultMqMessage message);
-
-}

+ 0 - 27
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/IBuildScenePreService.java

@@ -1,27 +0,0 @@
-package com.fdkankan.scene.service;
-
-import com.alibaba.fastjson.JSONObject;
-import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
-import java.util.Map;
-
-/**
- * <p>
- * TODO
- * </p>
- *
- * @author dengsixing
- * @since 2022/3/1
- **/
-public interface IBuildScenePreService {
-
-    void buildScenePre(BuildSceneCallMessage message);
-
-    Map<String, String> getTypeString(String cameraType, String algorithm, String resolution, JSONObject dataJson);
-
-    String getPath(BuildSceneCallMessage buildSceneMqMessage) throws Exception;
-
-    void downLoadSource(BuildSceneCallMessage buildSceneMqMessage, String path) throws Exception;
-
-    void uploadLogFile(String num, String dataSource);
-
-}

+ 0 - 56
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/BuildSceneDTServiceImpl.java

@@ -1,56 +0,0 @@
-package com.fdkankan.scene.service.impl;
-
-import cn.hutool.core.util.StrUtil;
-import com.fdkankan.dingtalk.DingTalkSendUtils;
-import com.fdkankan.scene.service.IBuildSceneDTService;
-import com.taobao.api.ApiException;
-import java.io.UnsupportedEncodingException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-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;
-
-/**
- * <p>
- * TODO
- * </p>
- *
- * @author dengsixing
- * @since 2022/4/20
- **/
-@Slf4j
-@Service
-public class BuildSceneDTServiceImpl implements IBuildSceneDTService {
-
-    public static final String DINGTALK_MSG_PATTERN = "**环境**: %s\n\n" +
-        "**服务器名称**: %s\n\n" +
-        "**失败原因**: %s\n\n" +
-        "**num**: %s\n\n" +
-        "**server-path**: %s\n\n";
-//        "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
-
-    public static final String contentExt = "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
-
-    @Autowired
-    private DingTalkSendUtils dingTalkSendUtils;
-    @Value("${spring.profiles.active}")
-    private String environment;
-
-    @Override
-    public void handFail(String reason, String serverPath, String num, String hostName, String contentExt) {
-        CompletableFuture.runAsync(() -> {
-            try {
-                String contentFormat = StrUtil.isBlank(contentExt) ? this.DINGTALK_MSG_PATTERN : this.DINGTALK_MSG_PATTERN +  contentExt;
-                String content = String.format(contentFormat, this.environment, hostName, reason, num, serverPath, num, num);
-                log.info("发送钉钉消息,content:{}", content);
-                dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
-            } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
-                log.error("发送钉钉消息失败", apiException);
-            }
-        });
-    }
-
-}

+ 0 - 904
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/BuildScenePostServiceImpl.java

@@ -1,904 +0,0 @@
-package com.fdkankan.scene.service.impl;
-
-import static com.fdkankan.push.PushMessageConfig.ANDROID_KEY;
-import static com.fdkankan.push.PushMessageConfig.ANDROID_KEY_Z;
-import static com.fdkankan.push.PushMessageConfig.ANDROID_SECRET;
-import static com.fdkankan.push.PushMessageConfig.ANDROID_SECRET_Z;
-import static com.fdkankan.push.PushMessageConfig.IOS_KEY;
-import static com.fdkankan.push.PushMessageConfig.IOS_KEY_Z;
-import static com.fdkankan.push.PushMessageConfig.IOS_SECRET;
-import static com.fdkankan.push.PushMessageConfig.IOS_SECRET_Z;
-
-import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.util.StrUtil;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.fdkankan.common.constant.BuildStatus;
-import com.fdkankan.common.constant.ConstantFilePath;
-import com.fdkankan.common.constant.ConstantUrl;
-import com.fdkankan.common.constant.ExpiredStatus;
-import com.fdkankan.common.constant.PayStatus;
-import com.fdkankan.common.constant.SceneFrom;
-import com.fdkankan.common.constant.SceneResolution;
-import com.fdkankan.common.constant.SceneSource;
-import com.fdkankan.common.constant.SceneStatus;
-import com.fdkankan.common.constant.ServerCode;
-import com.fdkankan.common.constant.UploadFilePath;
-import com.fdkankan.common.response.ResultData;
-import com.fdkankan.common.util.FileUtil;
-import com.fdkankan.common.util.FileUtils;
-import com.fdkankan.common.util.MatrixToImageWriterUtil;
-import com.fdkankan.common.util.SceneUtil;
-import com.fdkankan.fyun.constant.StorageType;
-import com.fdkankan.fyun.oss.UploadToOssUtil;
-import com.fdkankan.platform.api.dto.CameraDetail;
-import com.fdkankan.platform.api.dto.UserIncrement;
-import com.fdkankan.platform.api.feign.PlatformGoodsClient;
-import com.fdkankan.platform.api.feign.PlatformUserClient;
-import com.fdkankan.push.PushMessageConfig;
-import com.fdkankan.push.PushMsgUtil;
-import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
-import com.fdkankan.redis.constant.RedisKey;
-import com.fdkankan.redis.util.RedisUtil;
-import com.fdkankan.scene.bean.PointBean;
-import com.fdkankan.scene.bean.SceneJsonBean;
-import com.fdkankan.scene.bean.SegmentBean;
-import com.fdkankan.scene.bean.VertexBean;
-import com.fdkankan.scene.bean.WallBean;
-import com.fdkankan.scene.entity.SceneEditControls;
-import com.fdkankan.scene.entity.SceneEditInfo;
-import com.fdkankan.scene.entity.SceneEditInfoExt;
-import com.fdkankan.scene.entity.SceneFileBuild;
-import com.fdkankan.scene.entity.ScenePlus;
-import com.fdkankan.scene.entity.ScenePlusExt;
-import com.fdkankan.scene.entity.ScenePro;
-import com.fdkankan.scene.entity.SceneProExt;
-import com.fdkankan.scene.service.IBuildSceneDTService;
-import com.fdkankan.scene.service.IBuildScenePostService;
-import com.fdkankan.scene.service.ISceneEditControlsService;
-import com.fdkankan.scene.service.ISceneEditInfoExtService;
-import com.fdkankan.scene.service.ISceneEditInfoService;
-import com.fdkankan.scene.service.ISceneFileBuildService;
-import com.fdkankan.scene.service.IScenePlusExtService;
-import com.fdkankan.scene.service.IScenePlusService;
-import com.fdkankan.scene.service.ISceneProExtService;
-import com.fdkankan.scene.service.ISceneProService;
-import com.fdkankan.scene.service.ISceneService;
-import com.fdkankan.scene.vo.SceneEditControlsVO;
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.stream.Collectors;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-/**
- * <p>
- * TODO
- * </p>
- *
- * @author dengsixing
- * @since 2022/4/20
- **/
-@Slf4j
-@Service
-public class BuildScenePostServiceImpl implements IBuildScenePostService {
-
-    @Value("${main.url}")
-    private String mainUrl;
-    @Value("${scene.pro.url}")
-    private String sceneProUrl;
-    @Value("${scene.pro.new.url}")
-    private String sceneProNewUrl;
-    @Value("${upload.type}")
-    private String ossType;
-    @Value("${oss.prefix.ali}")
-    private String prefixAli;
-    @Value("${oss.bucket:4dkankan}")
-    private String bucket;
-
-    @Autowired
-    ISceneService sceneService;
-    @Autowired
-    ISceneFileBuildService sceneFileBuildService;
-    @Autowired
-    ISceneProService sceneProService;
-    @Autowired
-    ISceneProExtService sceneProExtService;
-    @Autowired
-    PlatformGoodsClient platformGoodsClient;
-    @Autowired
-    PlatformUserClient platformUserClient;
-    @Autowired
-    ISceneEditInfoService sceneEditInfoService;
-    @Autowired
-    ISceneEditControlsService sceneEditControlsService;
-    @Autowired
-    UploadToOssUtil uploadToOssUtil;
-//    @Autowired
-//    IBuildScenePreService buildScenePreService;
-    @Autowired
-    RedisUtil redisUtil;
-    @Autowired
-    IScenePlusService scenePlusService;
-    @Autowired
-    IScenePlusExtService scenePlusExtService;
-    @Autowired
-    IBuildSceneDTService buildSceneDTService;
-    @Autowired
-    ISceneEditInfoExtService sceneEditInfoExtService;
-
-    @Override
-    public void buildScenePost(BuildSceneResultMqMessage message) {
-        Integer cameraType = Integer.parseInt(message.getCameraType());
-        String sceneCode = message.getSceneCode();
-        String fileId = message.getFileId();
-        Integer payStatus = message.getPayStatus();
-        Long computeTime = message.getComputeTime();
-        Boolean buildSuccess = message.getBuildSuccess();
-        Integer videoVersion = message.getVideoVersion();
-
-        Map<String, String> uploadFiles = message.getUploadFiles();
-        String path = message.getPath();
-        Integer pushChannel = message.getPushChannel();
-        String pushToken = message.getPushToken();
-        String prefix = message.getPrefix();
-        try {
-            if(!buildSuccess){//建模失败,修改状态为失败状态
-                log.info("建模失败,修改状态为失败状态");
-                // TODO: 2022/3/21 plus版本稳定后删除------------------------start
-                sceneService.updateStatus(sceneCode, SceneStatus.FAILD.code());
-                sceneProService.updateStatus(sceneCode, SceneStatus.FAILD.code());
-                // TODO: 2022/3/21 plus版本稳定后删除------------------------send
-
-                scenePlusService.update(
-                    new LambdaUpdateWrapper<ScenePlus>()
-                        .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
-                        .eq(ScenePlus::getNum, sceneCode));
-
-                SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
-                if(Objects.nonNull(sceneFileBuild)){
-                    sceneFileBuild.setBuildStatus(BuildStatus.fail.code());
-                    sceneFileBuildService.updateById(sceneFileBuild);
-                }
-                return;
-            }
-
-            //建模成功走以下逻辑
-            log.info("cameraType:{}",cameraType);
-
-            //计算场景消耗磁盘空间
-            long space = this.calUseSpace(uploadFiles);
-
-            if(cameraType < 3){
-                // TODO: 2022/3/21 plus版本稳定后删除------------------------start
-                sceneService.updateTime(sceneCode, space, payStatus);
-                // TODO: 2022/3/21 plus版本稳定后删除------------------------send
-
-                this.updateDb4Sm(sceneCode, space);
-
-                uploadToOssUtil.uploadMulFiles(uploadFiles);
-                return;
-            }
-
-            //读取计算结果文件生成videosJson
-            JSONObject videosJson = this.getVideosJson(path, videoVersion, sceneCode, cameraType);
-
-            //写入数据库
-            // TODO: 2022/3/21 plus版本稳定后删除------------------------start
-            ScenePro scenePro = this.updateDbPro(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
-            SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
-            // TODO: 2022/3/21 plus版本稳定后删除------------------------send
-            ScenePlus scenePlus = this.updateDbPlus(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
-            ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
-
-            //变更容量,arrearCap为true时,代表容量不足
-            boolean arrearCap = this.updateSpace(scenePlus.getCameraId(), space, scenePlus.getId(), scenePro.getId());
-
-            //如果相机容量不足,需要把场景的paystatus改为容量不足状态
-            this.sealScene(arrearCap, scenePlus.getId(), scenePro.getId());
-
-            Object[] editInfoArr = this.updateEditInfo(scenePro, scenePlus);
-            SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
-            SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
-            SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
-
-            String sceneUrl = mainUrl + "/" + sceneProNewUrl;
-            String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneCode+".png";
-            String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneCode+"_en.png";
-            //生成新的分享的二维码-中文版本
-            MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneCode, outPathZh, false,null);
-            //生成新的分享的二维码-英文版本
-            MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneCode + "&lang=en", outPathEn, false, null);
-            //上传二维码
-            uploadToOssUtil.upload(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, sceneCode) + sceneCode + ".png");
-            uploadToOssUtil.upload(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, sceneCode) + sceneCode + "_en.png");
-
-            Map<String, String> newUploadFiles = this.uploadFileMapHandler(sceneCode, cameraType, uploadFiles);
-
-            // TODO: 2022/5/26 下载全景图采用打包本地文件的方式,这里应该是不需要上传到oss了,暂时保留代码并注释掉------start
-            //上传计算结果中的caches/images和caches/videos
-//            this.uploadCaches(sceneCode, uploadFiles, path);
-            // TODO: 2022/5/26 下载全景图采用打包本地文件的方式,这里应该是不需要上传到oss了,暂时保留代码并注释掉------end
-
-            //上传全景图俯视图
-            this.uploadFloorCad(path, sceneCode, newUploadFiles);
-
-            //上传文件
-            uploadToOssUtil.uploadMulFiles(newUploadFiles);
-            // TODO: 2022/3/11 同时上传一份到旧版本的目录,用于过渡期使用,待重构版本稳定后删除
-            uploadToOssUtil.uploadMulFiles(uploadFiles);
-
-            //拷贝部分文件到编辑目录,用于用户编辑
-            this.copyToEditDir(sceneCode);
-
-            //生成houseTypejson并上传
-            this.uploadHouseTypeJson(sceneCode);
-
-//            //上传日志文件
-//            buildScenePreService.uploadLogFile(sceneCode, sceneProExt.getDataSource());
-
-            //写scene.json
-            this.writeSceneJson(sceneCode, videosJson,
-                sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus, scenePlusExt, arrearCap);
-
-            //计算成功,发短信
-            this.sendSms(pushChannel,pushToken, cameraType, scenePro.getSceneName(), scenePro.getWebSite());
-
-            log.info("场景计算结果处理结束,场景码:{}", message.getSceneCode());
-
-        }catch (Exception e){
-            log.error("场景计算结果处理出错", e);
-            //发送钉钉
-            String serverPath = message.getPath().substring(0,message.getPath().lastIndexOf("/")+1).concat(prefix);
-//            buildSceneDTService.handFail("场景计算结果处理出错", serverPath, sceneCode, BuildScenePreServiceImpl.hostName, BuildScenePreServiceImpl.contentExt);
-        }
-    }
-
-    private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles){
-
-        //户型图上传
-        String  userEditPath = UploadFilePath.USER_EDIT_PATH + "floor-cad-%s.%s";
-        String  userViewPath = UploadFilePath.USER_VIEW_PATH + "floor-cad-%s.%s";
-        String floorCadPath = path + "/results/floorplan_cad";
-        List<String> floorCadList = FileUtil.getFileList(floorCadPath);
-        if(CollUtil.isNotEmpty(floorCadList)){
-            floorCadList.stream().forEach(str->{
-                String substring = str.substring(str.lastIndexOf(File.separator) + 1);
-                String[] arr = substring.split("floor");
-                String[] arr2 = arr[1].split("\\.");
-                uploadFiles.put(str, String.format(userEditPath, num, arr2[0], arr2[1]));
-                uploadFiles.put(str, String.format(userViewPath, num, arr2[0], arr2[1]));
-            });
-        }
-
-    }
-
-    private void writeSceneJson(String num, JSONObject videosJson, SceneEditInfo sceneEditInfo,SceneEditInfoExt sceneEditInfoExt,
-        SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt, boolean arrearCap)  throws Exception{
-        String sceneJsonKey = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
-        boolean exist = uploadToOssUtil.existKey(sceneJsonKey);
-        //如果云端没有scene.json文件,生成一份
-        if(!exist){
-            SceneJsonBean sceneJson = new SceneJsonBean();
-            BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
-            BeanUtil.copyProperties(sceneEditInfo, sceneJson);
-            SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
-            sceneJson.setControls(sceneEditControlsVO);
-            sceneJson.setNum(num);
-            sceneJson.setCreateTime(scenePlus.getCreateTime());
-            sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
-            sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
-            sceneJson.setVideos(JSON.toJSONString(videosJson));
-            if(arrearCap) {
-                sceneJson.setPayStatus(PayStatus.NO_CAPACITY.code());
-            }
-
-            String sceneJsonStr = JSON.toJSONString(sceneJson);
-            //上传sceneJson文件
-            uploadToOssUtil.upload(sceneJsonStr.getBytes(), sceneJsonKey);
-            //scenejson写入缓存
-            redisUtil.set(String.format(RedisKey.SCENE_JSON, num), sceneJsonStr);
-        }
-
-        // TODO: 2022/4/21 plus版本稳定后删除------------------------------------------start
-        String localSceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, num);
-        String localSceneJson = FileUtils.readFile(localSceneJsonPath);
-        if(StrUtil.isNotEmpty(localSceneJson)){
-            JSONObject sceneJsonObject = JSON.parseObject(localSceneJson);
-            sceneJsonObject.put("videos", JSON.toJSONString(videosJson));
-            if(arrearCap) {
-                sceneJsonObject.put("payStatus", PayStatus.NO_CAPACITY.code());
-            }
-            FileUtils.writeFile(localSceneJsonPath, sceneJsonObject.toJSONString());
-        }
-        // TODO: 2022/4/21 plus版本稳定后删除------------------------------------------end
-
-    }
-
-    private void sendSms(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
-        log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
-        if(Objects.isNull(pushChannel) && StrUtil.isBlank(pushToken))
-            return;
-
-        try{
-            if(StorageType.AWS.code().equals(ossType)){
-                PushMsgUtil
-                    .googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
-                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-                return;
-            }
-
-            PushMessageConfig demo = null;
-            if(pushChannel == 0){
-                if(cameraType == 10 || cameraType == 13){
-                    //ios
-                    log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY_Z, IOS_SECRET_Z);
-                    demo = new PushMessageConfig(IOS_KEY_Z, IOS_SECRET_Z);
-                    demo.sendIOSUnicast(pushToken,  "四维看看Minion",
-                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-                }else {
-                    //ios
-                    log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY, IOS_SECRET);
-                    demo = new PushMessageConfig(IOS_KEY, IOS_SECRET);
-                    demo.sendIOSUnicast(pushToken, "四维看看Pro",
-                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-                }
-            }else {
-                if(cameraType == 10 || cameraType == 13){
-                    //ios
-                    //安卓
-                    log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY_Z, ANDROID_SECRET_Z);
-                    demo = new PushMessageConfig(ANDROID_KEY_Z, ANDROID_SECRET_Z);
-                    demo.sendAndroidUnicast2(pushToken, "四维看看Minion",
-                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-                }else {
-                    //安卓
-                    log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY, ANDROID_SECRET);
-                    demo = new PushMessageConfig(ANDROID_KEY, ANDROID_SECRET);
-                    demo.sendAndroidUnicast(pushToken, "四维看看Pro",
-                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-                }
-            }
-            log.info("消息推送结束!");
-        }catch (Exception e){
-            log.error("推送消息失败:", e);
-        }
-    }
-
-    private void copyToEditDir(String num) throws IOException {
-
-        String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
-        String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
-
-        String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
-        String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
-
-        Map<String, String> map = new HashMap<>();
-        map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
-        map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
-        map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
-
-        for (Entry<String, String> entry : map.entrySet()) {
-            uploadToOssUtil.copyFiles(entry.getValue(), entry.getKey());
-        }
-    }
-
-
-    private void uploadCaches(String num, Map<String,String> map, String path){
-
-        String sceneNumPath = String.format("scene/%s", num);
-
-        List<String> ossImagesList = uploadToOssUtil.listKeys(String.format(UploadFilePath.IMG_CACHES_PATH, num));
-        if(CollUtil.isNotEmpty(ossImagesList)){
-            ossImagesList.parallelStream().forEach(key->{
-                try {
-                    uploadToOssUtil.delete(key);
-                } catch (IOException e) {
-                    log.error("删除全景图缓存失败,num:{},key:{}", num, key);
-                }
-            });
-        }
-        String visionPath = path + "/results/vision.txt";
-        List<String> panoramaImageList = SceneUtil.getPanoramaImageList(visionPath);
-
-        List<String> imagesList = FileUtil.getFileList(path + "/caches/images");
-        log.info("caches/images_path:{}", path + "/caches/images");
-        if(CollUtil.isNotEmpty(imagesList)){
-            log.info("上传的caches/images文件列表:{}", imagesList.toString());
-            imagesList.stream().forEach(str -> {
-                String filePath = str.substring(str.lastIndexOf(File.separator) + 1);
-                if(panoramaImageList.contains(filePath)){
-                    map.put(str, str.replace(path, sceneNumPath));
-                }
-            });
-        }
-
-        List<String> ossVideosList = uploadToOssUtil.listKeys(String.format(UploadFilePath.VIDEOS_CACHES_PATH, num));
-        if(CollUtil.isNotEmpty(ossVideosList)){
-            ossVideosList.parallelStream().forEach(key->{
-                try {
-                    uploadToOssUtil.delete(key);
-                } catch (IOException e) {
-                    log.error("删除球幕视频缓存失败,num:{},key:{}", num, key);
-                }
-            });
-        }
-        List<String> videosList = FileUtil.getFileList(path + "/caches/videos");
-        if(CollUtil.isNotEmpty(videosList)){
-            log.info("上传的caches/videos文件列表:{}", videosList.toString());
-            videosList.stream().forEach(str -> map.put(str, str.replace(path, sceneNumPath)));
-        }
-    }
-
-    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<>();
-        String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
-        JSONArray videoArray = null;
-        if(StringUtils.isNotEmpty(videosHdr)){
-            videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
-        }
-        if(videoArray != null){
-            for(int i = 0, len = videoArray.size(); i < len; i++) {
-                videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
-                if(videoArray.getJSONObject(i).containsKey("fov")){
-                    videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
-                }
-            }
-        }
-
-        //获取upload中的video视频名称
-        String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
-        JSONObject uploadJson = null;
-        JSONArray array = null;
-        if(uploadData!=null) {
-            uploadJson = JSONObject.parseObject(uploadData);
-            array = uploadJson.getJSONArray("upload");
-        }
-        JSONObject fileJson = null;
-        String fileName = "";
-
-        //计算ts文件的大小,并拼接成json格式
-        JSONArray jsonArray = new JSONArray();
-        JSONObject videoJson = null;
-        JSONObject videosJson = new JSONObject();
-        long videoSize = 0L;
-        for(int i = 0, len = array.size(); i < len; i++) {
-            fileJson = array.getJSONObject(i);
-            fileName = fileJson.getString("file");
-            if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
-                videoJson = new JSONObject();
-                videoJson.put("id", fileName.substring(
-                    0, fileName.lastIndexOf(".")).replace("videos/", ""));
-
-                //如果ts文件存在,就计算ts大小
-                if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
-                    videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
-                    videoJson.put("tsSize", videoSize);
-                }
-                if(videoMap.containsKey(videoJson.get("id"))){
-                    videoJson.put("value", videoMap.get(videoJson.get("id")));
-                }
-                if(videoMap.containsKey(videoJson.get("id") + "_fov")){
-                    videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
-                }else {
-                    videoJson.put("blend_fov", 7);
-                }
-                jsonArray.add(videoJson);
-            }
-        }
-
-        videosJson.put("data", jsonArray);
-        if(Objects.nonNull(videoVersion) && videoVersion >= 4){
-            videosJson.put("version", 3);
-            if(StorageType.OSS.code().equals(ossType)){
-                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up.xml");
-            }
-            if(StorageType.AWS.code().equals(ossType)){
-                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up.xml");
-            }
-            if(cameraType == 13){
-                //转台相机
-                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
-            }
-        }else {
-            videosJson.put("version", 1);
-            if("oss".equals(ossType)){
-                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up2.xml");
-            }
-            if("aws".equals(ossType)){
-                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up2.xml");
-            }
-
-            if(cameraType == 13){
-                //转台相机
-                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
-            }
-        }
-
-        if(cameraType == 5 || cameraType == 6){
-            videosJson.put("version", 1);
-            if("oss".equals(ossType)){
-                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/stitch_params.txt");
-            }
-            if("aws".equals(ossType)){
-                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/stitch_params.txt");
-            }
-        }
-
-        return videosJson;
-    }
-
-    private Long calUseSpace(Map<String, String> uploadFile) {
-        File spaceFile = null;
-        long space = 0L;
-        for (String key : uploadFile.keySet()) {
-            spaceFile = new File(key);
-            if(spaceFile.exists()){
-                space += spaceFile.length();
-            }
-        }
-        return space;
-    }
-
-    private void sealScene(boolean arrearCap, Long scenePlusId, Long sceneProId){
-        if(!arrearCap){
-            return;
-        }
-        scenePlusService.update(
-            new LambdaUpdateWrapper<ScenePlus>()
-                .set(ScenePlus::getPayStatus, PayStatus.NO_CAPACITY.code())
-                .eq(ScenePlus::getId, scenePlusId));
-
-
-        // TODO: 2022/3/22 plus版本稳定后删除---------------------------start
-        sceneProService.update(
-            new LambdaUpdateWrapper<ScenePro>()
-                .set(ScenePro::getPayStatus, PayStatus.NO_CAPACITY.code())
-                .eq(ScenePro::getId, sceneProId));
-        // TODO: 2022/3/22 plus版本稳定后删除---------------------------end
-    }
-
-    /**
-     * <p>
-     双目场景更新数据库
-     * </p>
-     * @author dengsixing
-     * @date 2022/3/21
-     * @param num
-     * @param space
-     **/
-    private void updateDb4Sm(String num, long space){
-        List<ScenePlus> ScenePlusList = scenePlusService.list(
-            new LambdaQueryWrapper<ScenePlus>()
-                .select(ScenePlus::getId)
-                .eq(ScenePlus::getNum, num));
-
-        if(CollUtil.isNotEmpty(ScenePlusList))
-            return ;
-        List<Long> sceneIds = ScenePlusList.stream().map(scene -> {
-            return scene.getId();
-        }).collect(Collectors.toList());
-
-        //更新场景创建时间
-        scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
-            .in(ScenePlus::getId, sceneIds)
-            .set(ScenePlus::getCreateTime, Calendar.getInstance().getTime())
-            .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code()));
-
-        //更新使用容量
-        scenePlusExtService.update(
-            new LambdaUpdateWrapper<ScenePlusExt>()
-                .in(ScenePlusExt::getPlusId, sceneIds)
-                .set(ScenePlusExt::getSpace, space));
-    }
-
-    private ScenePro updateDbPro(String sceneCode, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
-        ScenePro scenePro = sceneProService.findBySceneNum(sceneCode);
-
-        sceneProService.updateTime(sceneCode, space, payStatus, videosJson, computeTime);
-        SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
-        if(sceneFileBuild != null){
-            sceneFileBuild.setBuildStatus(BuildStatus.success.code());
-            sceneFileBuildService.updateById(sceneFileBuild);
-        }
-
-        if(Objects.nonNull(scenePro)){
-            SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
-            SceneSource sceneSource = SceneSource.get(sceneProExt.getSceneSource());
-            switch (sceneSource){
-                case BM:
-                    sceneProExt.setSceneResolution(SceneResolution.TILES_2K.code());
-                    sceneProExt.setSceneFrom(SceneFrom.PRO.code());
-                    break;
-                case SM:
-                    sceneProExt.setSceneResolution(SceneResolution.TILES_1K.code());
-                    sceneProExt.setSceneFrom(SceneFrom.LITE.code());
-                    break;
-                case ZT:
-                    sceneProExt.setSceneResolution(SceneResolution.TILES_4K.code());
-                    sceneProExt.setSceneFrom(SceneFrom.MINION.code());
-                    break;
-                case JG:
-                    sceneProExt.setSceneResolution(SceneResolution.TILES_4K.code());
-                    sceneProExt.setSceneFrom(SceneFrom.LASER.code());
-                    break;
-            }
-            sceneProExtService.updateById(sceneProExt);
-
-        }
-
-        return scenePro;
-    }
-
-    private ScenePlus updateDbPlus(String num, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
-        ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
-        ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
-        List<ScenePlus> list = scenePlusService.list(
-            new LambdaQueryWrapper<ScenePlus>()
-                .select(ScenePlus::getId)
-                .eq(ScenePlus::getNum, num));
-        if(scenePlus == null || CollUtil.isEmpty(list))
-            return null;
-
-        //修改场景状态 空间 支付状态 计算时间
-        List<Long> scenePlusIds = list.stream().map(plus -> {
-            return plus.getId();
-        }).collect(Collectors.toList());
-
-        scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
-            .in(ScenePlus::getId, scenePlusIds)
-            .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code())
-            .set(ScenePlus::getCreateTime, Calendar.getInstance().getTime())
-            .set(ScenePlus::getPayStatus, payStatus));
-
-        scenePlusExtService.update(new LambdaUpdateWrapper<ScenePlusExt>()
-            .in(ScenePlusExt::getPlusId, scenePlusIds)
-            .set(ScenePlusExt::getSpace, space)
-            .set(ScenePlusExt::getComputeTime, computeTime)
-            .set(ScenePlusExt::getVideos, videosJson));
-
-        SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
-        if(sceneFileBuild != null){
-            sceneFileBuild.setBuildStatus(BuildStatus.success.code());
-            sceneFileBuildService.updateById(sceneFileBuild);
-        }
-
-        SceneSource sceneSource = SceneSource.get(scenePlus.getSceneSource());
-        switch (sceneSource){
-            case BM:
-                scenePlusExt.setSceneResolution(SceneResolution.TILES_2K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
-                break;
-            case SM:
-                scenePlusExt.setSceneResolution(SceneResolution.TILES_1K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
-                break;
-            case ZT:
-                scenePlusExt.setSceneResolution(SceneResolution.TILES_4K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
-                break;
-            case JG:
-                scenePlusExt.setSceneResolution(SceneResolution.TILES_4K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
-                break;
-        }
-        scenePlusExtService.updateById(scenePlusExt);
-
-
-        return scenePlus;
-    }
-
-    private boolean updateSpace(Long cameraId, Long space, Long scenePlusId, Long sceneProId) throws Exception{
-        //更新相机使用用量
-        ResultData<CameraDetail> resultData = platformGoodsClient.updateCameraDetailByCameraIdAndSpace(cameraId, space);
-        if(resultData.getCode() != ServerCode.SUCCESS.code()){
-            log.error("调用platform服务updateCameraDetailByCameraIdAndSpace失败,参数{},{}" ,cameraId, space);
-            throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
-        }
-        CameraDetail cameraDetail = JSONObject.parseObject(JSONObject.toJSONString(resultData.getData()), CameraDetail.class);
-
-        ResultData<UserIncrement> resultData1 = platformUserClient.getUserIncrementByCameraId(cameraId);
-        if(resultData1.getCode() != ServerCode.SUCCESS.code()){
-            log.error("调用platform服务getUserIncrementByCameraId失败,参数{}" ,cameraId);
-            throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
-        }
-        if( resultData1.getData() == null || resultData1.getData().getIsExpired() == ExpiredStatus.Expired.code()) {
-            // 新上传的场景,如果总容量小于使用容量,则该大场景保留在临时存储空间30天
-            if (cameraDetail.getTotalSpace().compareTo(cameraDetail.getUsedSpace()) == -1){
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private Object[] updateEditInfo(ScenePro scenePro, ScenePlus scenePlus){
-        SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
-        SceneEditControls sceneEditControls = null;
-        SceneEditInfoExt sceneEditInfoExt = null;
-        if(sceneEditInfo == null){
-            sceneEditInfo = new SceneEditInfo();
-            sceneEditInfo.setScenePlusId(scenePlus.getId());
-            sceneEditInfo.setSceneProId(scenePro.getId());
-            sceneEditInfo.setDescription(scenePlus.getDescription());
-            sceneEditInfo.setTitle(scenePlus.getTitle());
-            sceneEditInfoService.save(sceneEditInfo);
-
-        }else{
-            sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
-            sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
-            sceneEditInfo.setVersion(sceneEditInfo.getVersion() + 1);
-            sceneEditInfoService.updateById(sceneEditInfo);
-        }
-        if(sceneEditControls == null){
-            sceneEditControls = new SceneEditControls();
-            sceneEditControls.setEditInfoId(sceneEditInfo.getId());
-            sceneEditControlsService.save(sceneEditControls);
-        }
-        if(sceneEditInfoExt == null){
-            sceneEditInfoExt = new SceneEditInfoExt();
-            sceneEditInfoExt.setScenePlusId(scenePlus.getId());
-            sceneEditInfoExt.setSceneProId(scenePro.getId());
-            sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
-            sceneEditInfoExtService.save(sceneEditInfoExt);
-        }
-        return new Object[]{sceneEditInfo, sceneEditInfoExt, sceneEditControls};
-    }
-
-    public void uploadHouseTypeJson(String num) throws IOException {
-
-        JSONObject result = new JSONObject();
-        result.put("name", "houseType.json");
-        result.put("version", "2.1");
-
-        String floorplanCadPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "floorplan_cad.json";
-        String floorcadStr = uploadToOssUtil.getObjectContent(this.bucket, floorplanCadPath);
-
-        JSONObject floorcadObj = JSON.parseObject(floorcadStr);
-        JSONArray floors = floorcadObj.getJSONArray("floors");
-
-        JSONArray targetFloors = new JSONArray();
-        result.put("floors", targetFloors);
-        for(int i = 0; i < floors.size(); i++){
-            JSONObject floor = (JSONObject)floors.get(i);
-            JSONArray[] pointsAndWalls = this.createHouseTypeJsonHandler(floor);
-            JSONArray points = pointsAndWalls[0];
-            JSONArray walls = pointsAndWalls[1];
-            JSONObject targetFloor = new JSONObject();
-            targetFloor.put("points", points);
-            targetFloor.put("walls", walls);
-            targetFloors.add(targetFloor);
-        }
-
-        String hourseTypeJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "houseType.json";
-        uploadToOssUtil.upload(result.toJSONString().getBytes(), hourseTypeJsonPath);
-
-        cn.hutool.core.io.FileUtil.writeString(result.toJSONString(), "F:\\test\\hourseType.json", StandardCharsets.UTF_8);
-    }
-
-    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;
-
-    }
-
-    public static void main(String[] args) {
-//        BuildScenePostServiceImpl.createHouseTypeJson();
-    }
-
-}

+ 0 - 520
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/BuildScenePreServiceImpl.java

@@ -1,520 +0,0 @@
-package com.fdkankan.scene.service.impl;
-
-import com.alibaba.fastjson.JSONObject;
-import com.fdkankan.common.constant.ConstantFilePath;
-import com.fdkankan.common.constant.UploadFilePath;
-import com.fdkankan.common.util.CreateObjUtil;
-import com.fdkankan.common.util.FileUtil;
-import com.fdkankan.common.util.FileUtils;
-import com.fdkankan.common.util.SceneUtil;
-import com.fdkankan.dingtalk.DingTalkSendUtils;
-import com.fdkankan.fyun.oss.UploadToOssUtil;
-import com.fdkankan.platform.api.feign.PlatformGoodsClient;
-import com.fdkankan.platform.api.feign.PlatformUserClient;
-import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
-import com.fdkankan.rabbitmq.util.RabbitMqProducer;
-import com.fdkankan.redis.constant.RedisKey;
-import com.fdkankan.redis.util.RedisUtil;
-import com.fdkankan.scene.service.IBuildSceneDTService;
-import com.fdkankan.scene.service.IBuildScenePreService;
-import com.fdkankan.scene.service.IScenePlusService;
-import java.io.File;
-import java.time.Duration;
-import java.time.temporal.ChronoUnit;
-import java.util.Date;
-import java.util.Map;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-/**
- * <p>
- * TODO
- * </p>
- *
- * @author dengsixing
- * @since 2022/3/1
- **/
-@Slf4j
-@Service
-public class BuildScenePreServiceImpl implements IBuildScenePreService {
-
-    @Value("${oss.prefix.ali}")
-    private String prefixAli;
-    @Value("${model.timeOut:48}")
-    private int modelTimeOut;
-    @Value("${upload.type}")
-    private String ossType;
-    @Value("${environment:dev}")
-    private String environment;
-    @Value("${queue.modeling.modeling-call}")
-    private String queueModelingCall;
-
-    @Autowired
-    UploadToOssUtil uploadToOssUtil;
-    @Autowired
-    private DingTalkSendUtils dingTalkSendUtils;
-    @Autowired
-    private IScenePlusService scenePlusService;
-    @Autowired
-    private PlatformUserClient platformUserClient;
-    @Autowired
-    private PlatformGoodsClient platformGoodsClient;
-    @Autowired
-    RedisUtil redisUtil;
-    @Autowired
-    private RabbitMqProducer mqProducer;
-    @Autowired
-    private IBuildSceneDTService buildSceneDTService;
-
-    public static String hostName;
-
-    public static final String DINGTALK_MSG_PATTERN = "**环境**: %s\n\n" +
-        "**服务器名称**: %s\n\n" +
-        "**失败原因**: %s\n\n" +
-        "**num**: %s\n\n" +
-        "**server-path**: %s\n\n";
-//        "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
-
-    public static final String contentExt = "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
-
-    @Value("${hostName.filePath:/opt/hosts/hosts.txt}")
-    public void setHostName(String filePath){
-        try {
-            this.hostName = FileUtils.readFile(filePath);
-            log.error("从文件({})中获取服务器名称:{}", filePath,hostName);
-        } catch (Exception e) {
-            log.error("从文件中获取服务器名称失败,文件路径{}", filePath);
-            e.printStackTrace();
-        }
-    }
-
-
-    @Override
-    public void buildScenePre(BuildSceneCallMessage message) {
-        boolean success = false;
-        try {
-            String key = String.format(RedisKey.SCENE_BUILDING, message.getSceneNum());
-            Long building = redisUtil.incr(key, 1);
-            if (building.compareTo(1L) != 0) {
-                log.info("场景正在构建中,退出构建,参数:{}", JSONObject.toJSONString(message));
-                return;
-            } else {
-                redisUtil.expire(key, Duration.of(modelTimeOut, ChronoUnit.HOURS));
-            }
-
-            //根据相机类型,组装资源路径
-            String path = SceneUtil.getPath(message.getPath(), message.getCameraName(),
-                message.getFileId(), Integer.parseInt(message.getCameraType()), message.getUnicode());
-
-            //下载资源到本地
-            this.downLoadSource(message, path);
-
-            //发送mq,就进行计算
-            mqProducer.sendByWorkQueue(queueModelingCall, message);
-
-            success = true;
-
-            log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
-
-        }catch (Exception e){
-            log.error("场景计算前置处理出错", e);
-        }finally {
-            //如果前置处理失败,发送钉钉消息
-            if(!success){
-                String serverPath = message.getPath().substring(0,message.getPath().lastIndexOf("/")+1).concat(message.getPrefix());
-//            buildSceneDTService.handFail("场景计算前置处理出错", serverPath, message.getSceneNum(), BuildScenePreServiceImpl.hostName, null);
-            }
-
-        }
-    }
-
-    @Override
-    public Map<String, String> getTypeString(String cameraType, String algorithm, String resolution,
-        JSONObject dataJson) {
-        return null;
-    }
-
-    @Override
-    public String getPath(BuildSceneCallMessage buildSceneMqMessage) throws Exception{
-        String path = buildSceneMqMessage.getPath();
-        String cameraName = buildSceneMqMessage.getCameraName();
-        String fileId = buildSceneMqMessage.getFileId();
-        int cameraType = Integer.parseInt(buildSceneMqMessage.getCameraType());
-        String unicode = buildSceneMqMessage.getUnicode();
-        if(cameraType < 3){
-            return path;
-        }
-        String localPath = cameraName.replace("4DKKPRO_", "")
-            .replace("-fdage", "").toLowerCase() +
-            File.separator + fileId + File.separator + unicode;
-
-        if(cameraType == 5 || cameraType == 6){
-            path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
-        }else if(cameraType == 14) {
-            path = ConstantFilePath.BUILD_MODEL_LASER_PATH + localPath;
-        } else{
-            path = ConstantFilePath.BUILD_MODEL_PATH + localPath;
-        }
-        return path;
-    }
-
-    @Override
-    public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path) throws Exception{
-        String cameraName = buildSceneMqMessage.getCameraName();
-        String fileId = buildSceneMqMessage.getFileId();
-        String unicode = buildSceneMqMessage.getUnicode();
-        int cameraType = Integer.parseInt(buildSceneMqMessage.getCameraType());
-        String prefix = buildSceneMqMessage.getPrefix();
-        String imgsName = buildSceneMqMessage.getImgsName();
-        if(cameraType < 3){
-            for(int i = 0;i<5;++i){
-                try{
-                    FileUtils.downLoadFromUrl(prefix+imgsName+"?m="+new Date().getTime(), imgsName,
-                        path + File.separator + "capture");
-                    FileUtils.decompress(path + File.separator + "capture" +File.separator+imgsName,
-                        path + File.separator + "capture") ;
-                    break;
-                }catch(Exception e){
-                    log.error(String.format("第%d次下载并解压资源失败", i+1),  e);
-                    if(i<4)
-                    {
-                        FileUtils.deleteFile(path + File.separator + "capture" +File.separator+imgsName);
-                        FileUtils.delFolder(path + File.separator + "capture" +File.separator+"images");
-                    }
-                    Thread.sleep(10000);
-                }
-            }
-            FileUtils.deleteFile(path + File.separator + "capture" +File.separator+"zip.Zip");
-        }else{
-            String ossPath = ConstantFilePath.OSS_PREFIX + cameraName.replace("4DKKPRO_", "")
-                .replace("-fdage", "").toLowerCase() + File.separator + fileId + File.separator
-                + unicode + File.separator;
-            if(cameraType == 5 || cameraType == 6){
-                path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
-                //下载zip包
-                FileUtils.downLoadFromUrl(prefix + "/" + imgsName + "?m=" + System.currentTimeMillis(), imgsName, path + File.separator + "capture");
-                //解压
-                FileUtils.decompress(path + File.separator + "capture" + File.separator + imgsName,
-                    path + File.separator + "capture") ;
-                //删除压缩包
-                FileUtil.delFile(path + File.separator + "capture" + File.separator + imgsName);
-            }else if(cameraType == 14) {
-                CreateObjUtil.ossUtilCp(ossPath,path + File.separator + "capture");
-            } else{
-                CreateObjUtil.ossUtilCp(ossPath,path + File.separator + "capture");
-            }
-        }
-    }
-
-//    @Override
-//    public 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));
-//            }
-//        }
-////        map.entrySet().parallelStream().forEach(entry -> {
-////            String key = entry.getKey();
-////            String value = entry.getValue();
-////            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;
-//    }
-
-//    @Override
-//    public void uploadCaches(String num, Map<String,String> map, String path){
-//
-//        String sceneNumPAth = String.format("scene/%s", num);
-//
-//        List<String> imagesList = FileUtil.getFileList(path + "/caches/images");
-//        log.info("caches/images_path:{}", path + "/caches/images");
-//        if(CollUtil.isNotEmpty(imagesList)){
-//            log.info("上传的caches/images文件列表:{}", imagesList.toString());
-//            imagesList.stream().forEach(str -> {
-//                if(str.endsWith(".jpg")){
-//                    map.put(str, str.replace(path, sceneNumPAth));
-//                }
-//            });
-//        }
-//
-//        List<String> videosList = FileUtil.getFileList(path + "/caches/videos");
-//        if(CollUtil.isNotEmpty(videosList)){
-//            log.info("上传的caches/videos文件列表:{}", videosList.toString());
-//            videosList.stream().forEach(str -> map.put(str, str.replace(path, sceneNumPAth)));
-//        }
-//    }
-
-//    @Override
-//    public void copyToEditDir(String num) throws IOException {
-//
-//        String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
-//        String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
-//
-//        String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
-//        String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
-//
-//        Map<String, String> map = new HashMap<>();
-//        map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
-//        map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
-//        map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
-//
-//        for (Entry<String, String> entry : map.entrySet()) {
-//            uploadToOssUtil.copyFiles(entry.getValue(), entry.getKey());
-//        }
-//    }
-
-//    @Override
-//    public void sendSms(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
-//        log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
-//        if(Objects.isNull(pushChannel) && StrUtil.isBlank(pushToken))
-//            return;
-//
-//        try{
-//            if(StorageType.AWS.code().equals(ossType)){
-//                PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
-//                    sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-//                return;
-//            }
-//
-//            PushMessageConfig demo = null;
-//            if(pushChannel == 0){
-//                if(cameraType == 10 || cameraType == 13){
-//                    //ios
-//                    log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY_Z, IOS_SECRET_Z);
-//                    demo = new PushMessageConfig(IOS_KEY_Z, IOS_SECRET_Z);
-//                    demo.sendIOSUnicast(pushToken,  "四维看看Minion",
-//                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-//                }else {
-//                    //ios
-//                    log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY, IOS_SECRET);
-//                    demo = new PushMessageConfig(IOS_KEY, IOS_SECRET);
-//                    demo.sendIOSUnicast(pushToken, "四维看看Pro",
-//                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-//                }
-//            }else {
-//                if(cameraType == 10 || cameraType == 13){
-//                    //ios
-//                    //安卓
-//                    log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY_Z, ANDROID_SECRET_Z);
-//                    demo = new PushMessageConfig(ANDROID_KEY_Z, ANDROID_SECRET_Z);
-//                    demo.sendAndroidUnicast2(pushToken, "四维看看Minion",
-//                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-//                }else {
-//                    //安卓
-//                    log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY, ANDROID_SECRET);
-//                    demo = new PushMessageConfig(ANDROID_KEY, ANDROID_SECRET);
-//                    demo.sendAndroidUnicast(pushToken, "四维看看Pro",
-//                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-//                }
-//            }
-//            log.info("消息推送结束!");
-//        }catch (Exception e){
-//            log.error("推送消息失败:", e);
-//        }
-//    }
-
-//    @Override
-//    public void handFail(String reason, String serverPath, String num, String hostName, String contentExt) {
-//        CompletableFuture.runAsync(() -> {
-//            try {
-//                String contentFormat = StrUtil.isBlank(contentExt) ? this.DINGTALK_MSG_PATTERN : this.DINGTALK_MSG_PATTERN +  contentExt;
-//                String content = String.format(contentFormat, this.environment, hostName, reason, num, serverPath, num, num);
-//                log.error("发送钉钉消息,content:{}", content);
-//                dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
-//            } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
-//                log.error("发送钉钉消息失败", apiException);
-//            }
-//        });
-//    }
-
-//    @Override
-//    public Long calUseSpace(Map<String, String> uploadFile) {
-//        File spaceFile = null;
-//        long space = 0L;
-//        for (String key : uploadFile.keySet()) {
-//            spaceFile = new File(key);
-//            if(spaceFile.exists()){
-//                space += spaceFile.length();
-//            }
-//        }
-//        return space;
-//    }
-
-    @Override
-    public void uploadLogFile(String num, String dataSource) {
-        String dataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
-        String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, num);
-
-        //todo 待删除old_path
-        uploadToOssUtil.upload(
-            ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json",
-            "data/data" + num + File.separator + "status.json");
-
-        uploadToOssUtil.upload(
-            ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json",
-            dataPath + "status.json");
-
-        uploadToOssUtil.upload(dataSource + File.separator + "console.log",
-            buildLogPath + "console.log");
-
-    }
-
-//    @Override
-//    public JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception {
-//        //读取videos_hdr_param.json, 保存点位视频的value
-//        Map<String, Object> videoMap = new HashMap<>();
-//        String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
-//        JSONArray videoArray = null;
-//        if(StringUtils.isNotEmpty(videosHdr)){
-//            videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
-//        }
-//        if(videoArray != null){
-//            for(int i = 0, len = videoArray.size(); i < len; i++) {
-//                videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
-//                if(videoArray.getJSONObject(i).containsKey("fov")){
-//                    videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
-//                }
-//            }
-//        }
-//
-//        //获取upload中的video视频名称
-//        String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
-//        JSONObject uploadJson = null;
-//        JSONArray array = null;
-//        if(uploadData!=null) {
-//            uploadJson = JSONObject.parseObject(uploadData);
-//            array = uploadJson.getJSONArray("upload");
-//        }
-//        JSONObject fileJson = null;
-//        String fileName = "";
-//
-//        //计算ts文件的大小,并拼接成json格式
-//        JSONArray jsonArray = new JSONArray();
-//        JSONObject videoJson = null;
-//        JSONObject videosJson = new JSONObject();
-//        long videoSize = 0L;
-//        for(int i = 0, len = array.size(); i < len; i++) {
-//            fileJson = array.getJSONObject(i);
-//            fileName = fileJson.getString("file");
-//            if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
-//                videoJson = new JSONObject();
-//                videoJson.put("id", fileName.substring(
-//                    0, fileName.lastIndexOf(".")).replace("videos/", ""));
-//
-//                //如果ts文件存在,就计算ts大小
-//                if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
-//                    videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
-//                    videoJson.put("tsSize", videoSize);
-//                }
-//                if(videoMap.containsKey(videoJson.get("id"))){
-//                    videoJson.put("value", videoMap.get(videoJson.get("id")));
-//                }
-//                if(videoMap.containsKey(videoJson.get("id") + "_fov")){
-//                    videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
-//                }else {
-//                    videoJson.put("blend_fov", 7);
-//                }
-//                jsonArray.add(videoJson);
-//            }
-//        }
-//
-//        videosJson.put("data", jsonArray);
-//        if(Objects.nonNull(videoVersion) && videoVersion >= 4){
-//            videosJson.put("version", 3);
-//            if(StorageType.OSS.code().equals(ossType)){
-//                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up.xml");
-//            }
-//            if(StorageType.AWS.code().equals(ossType)){
-//                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up.xml");
-//            }
-//            if(cameraType == 13){
-//                //转台相机
-//                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
-//            }
-//        }else {
-//            videosJson.put("version", 1);
-//            if("oss".equals(ossType)){
-//                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up2.xml");
-//            }
-//            if("aws".equals(ossType)){
-//                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up2.xml");
-//            }
-//
-//            if(cameraType == 13){
-//                //转台相机
-//                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
-//            }
-//        }
-//
-//        if(cameraType == 5 || cameraType == 6){
-//            videosJson.put("version", 1);
-//            if("oss".equals(ossType)){
-//                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/stitch_params.txt");
-//            }
-//            if("aws".equals(ossType)){
-//                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/stitch_params.txt");
-//            }
-//        }
-//
-//        return videosJson;
-//    }
-
-//    @Override
-//    public String writeSceneJson(String num, JSONObject videosJson, SceneEditInfo sceneEditInfo,
-//        SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt, boolean arrearCap)  throws Exception{
-//        String sceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, num);
-//        String strsceneInfos = FileUtils.readFile(sceneJsonPath);
-//        SceneJsonBean sceneJson = null;
-//        if(strsceneInfos!=null){
-//            sceneJson = JSON.parseObject(strsceneInfos, SceneJsonBean.class);
-//        }else{
-//            sceneJson = BeanUtil.copyProperties(sceneEditInfo, SceneJsonBean.class);
-//            SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
-//            sceneJson.setControls(sceneEditControlsVO);
-//            sceneJson.setNum(num);
-//            sceneJson.setCreateTime(scenePlus.getCreateTime());
-//            sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
-//            sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
-//            sceneJson.setVideos(videosJson);
-//        }
-//        sceneJson.setVideos(videosJson);
-//
-//        if(arrearCap) {
-//            sceneJson.setPayStatus(PayStatus.NO_CAPACITY.code());
-//        }
-//
-//        String sceneJsonStr = JSON.toJSONString(sceneJson);
-//        FileUtils.writeFile(sceneJsonPath, sceneJsonStr);
-//        return sceneJsonStr;
-//    }
-}