소스 검색

重算接口 cameraType判断方式变更

dengsixing 8 달 전
부모
커밋
6c6139c3f8

+ 11 - 0
src/main/java/com/fdkankan/contro/controller/SceneFileController.java

@@ -69,6 +69,17 @@ public class SceneFileController{
         return sceneFileBuildService.turntableUploadSuccess(params);
     }
 
+    /**
+     *
+     *
+     * @param params
+     * @return
+     */
+    @PostMapping("reverseE57")
+    public ResultData reverseE57(@RequestBody JSONObject params) throws Exception {
+        return sceneFileBuildService.reverseE57(params);
+    }
+
     @GetMapping("rebuildScene")
     public ResultData rebuildScene(@RequestParam(value = "num") String num,@RequestParam(value = "force",defaultValue = "false") Boolean force ,@RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras) throws IOException {
         return sceneFileBuildService.rebuildScene(num,force,deleteExtras);

+ 68 - 6
src/main/java/com/fdkankan/contro/mq/listener/BuildReverseE57Listener.java

@@ -1,7 +1,15 @@
 package com.fdkankan.contro.mq.listener;
 
-import com.fdkankan.contro.mq.service.impl.BuildIntermitSceneServiceImpl;
-import com.fdkankan.contro.mq.service.impl.BuildReverseE57ServiceImpl;
+import cn.hutool.core.exceptions.ExceptionUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.common.constant.CommonOperStatus;
+import com.fdkankan.contro.mq.service.impl.BuildReverseE57SceneServiceImpl;
+import com.fdkankan.contro.service.ICommonService;
+import com.fdkankan.contro.service.ISceneBuildProcessLogService;
+import com.fdkankan.model.constants.SceneBuildProcessType;
+import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
+import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
 import com.rabbitmq.client.Channel;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.core.Message;
@@ -10,18 +18,28 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
+import org.springframework.util.ObjectUtils;
+
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
 
 @Slf4j
 @Component
-public class BuildReverseE57Listener extends AbstrackBuildSceneListener {
+public class BuildReverseE57Listener {
 
     @Value("${queue.modeling.reverseE57.modeling-pre:reverseE57-modeling-pre}")
     private String queueModelingPre;
+
     @Value("${queue.modeling.reverseE57.modeling-post:reverseE57-modeling-post}")
     private String queueModelingPost;
 
     @Autowired
-    private BuildReverseE57ServiceImpl buildSceneService;
+    private ISceneBuildProcessLogService sceneBuildProcessLogService;
+    @Autowired
+    private ICommonService commonService;
+    @Autowired
+    private BuildReverseE57SceneServiceImpl buildSceneService;
+
 
     /**
      * 场景计算前置资源准备处理
@@ -34,7 +52,36 @@ public class BuildReverseE57Listener extends AbstrackBuildSceneListener {
             concurrency = "${maxThread.modeling.modeling-pre}"
     )
     public void buildScenePreHandler(Channel channel, Message message) throws Exception {
-        preHandle(channel,queueModelingPre,message,buildSceneService);
+        String messageId = message.getMessageProperties().getMessageId();
+        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+        HashMap<String, Object> map = JSON.parseObject(msg, HashMap.class);
+        String num = (String) map.get("num");
+        map.put("bizType", "reverseE57");
+
+        log.info("开始准备上传e57计算资源,队列名:{},id:{},消息体:{}", queueModelingPre, messageId, msg);
+        BuildSceneCallMessage buildSceneMessage = new BuildSceneCallMessage();
+        buildSceneMessage.setSceneNum(num);
+        buildSceneMessage.setExt(map);
+        buildSceneMessage.setBuildType("V3");
+        try {
+            if(ObjectUtils.isEmpty(buildSceneMessage.getBuildContext())){
+                buildSceneMessage.setBuildContext(new HashMap<>());
+            }
+            if(!ObjectUtils.isEmpty(buildSceneMessage.getSceneNum())){
+                buildSceneMessage.getBuildContext().put("sceneNum",buildSceneMessage.getSceneNum());
+            }
+            //记录日志
+            sceneBuildProcessLogService.clearSceneBuildProcessLog(num, SceneBuildProcessType.PRE.code(), queueModelingPre);
+            sceneBuildProcessLogService.saveSceneBuildProcessLog(num, SceneBuildProcessType.PRE.code(), queueModelingPre, CommonOperStatus.WAITING.code(), null);
+            buildSceneService.buildScenePre(buildSceneMessage);
+            commonService.saveMqSendLog(num, buildSceneMessage);
+            sceneBuildProcessLogService.saveSceneBuildProcessLog(num, SceneBuildProcessType.PRE.code(), queueModelingPre, CommonOperStatus.SUCCESS.code(), null);
+        }catch (Exception e){
+            log.error("上传e57计算前置处理出错,num=" + num, e);
+            sceneBuildProcessLogService.saveSceneBuildProcessLog(num, SceneBuildProcessType.PRE.code(), queueModelingPre, CommonOperStatus.FAILD.code(), ExceptionUtil.stacktraceToString(e, 3000));
+        }
+        log.info("准备上传e57计算资源完成,队列名:{},id:{},消息体:{}", queueModelingPre, messageId, msg);
+        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
     }
 
     /**
@@ -48,7 +95,22 @@ public class BuildReverseE57Listener extends AbstrackBuildSceneListener {
             concurrency = "${maxThread.modeling.modeling-post}"
     )
     public void buildScenePostHandler(Channel channel, Message message) throws Exception {
-        postHandle(channel,queueModelingPost,message,buildSceneService);
+        String messageId = message.getMessageProperties().getMessageId();
+        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+        log.info("场景计算完成,开始处理e57计算结果,队列名:{},id:{},消息体:{}", queueModelingPost, messageId, msg);
+        BuildSceneResultMqMessage buildSceneMessage = JSONObject.parseObject(msg, BuildSceneResultMqMessage.class);
+        String num = buildSceneMessage.getBuildContext().get("sceneNum").toString();
+        try {
+            sceneBuildProcessLogService.clearSceneBuildProcessLog(num, SceneBuildProcessType.POST.code(), queueModelingPost);
+            sceneBuildProcessLogService.saveSceneBuildProcessLog(num, SceneBuildProcessType.POST.code(), queueModelingPost, CommonOperStatus.WAITING.code(), null);
+            buildSceneService.buildScenePost(buildSceneMessage);
+            sceneBuildProcessLogService.saveSceneBuildProcessLog(num, SceneBuildProcessType.POST.code(), queueModelingPost, CommonOperStatus.SUCCESS.code(), null);
+        }catch (Exception e){
+            log.error("场景计算结果处理出错,num=" + num, e);
+            sceneBuildProcessLogService.saveSceneBuildProcessLog(num, SceneBuildProcessType.POST.code(), queueModelingPost, CommonOperStatus.FAILD.code(), ExceptionUtil.stacktraceToString(e, 3000));
+        }
+        log.info("场景计算结果处理完成,队列名:{},id:{},消息体:{}", queueModelingPost, messageId, msg);
+        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
 
     }
 }

+ 319 - 0
src/main/java/com/fdkankan/contro/mq/service/impl/BuildReverseE57SceneServiceImpl.java

@@ -0,0 +1,319 @@
+package com.fdkankan.contro.mq.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ZipUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.fdkankan.common.constant.*;
+import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.contro.constant.UserEditDataType;
+import com.fdkankan.contro.entity.*;
+import com.fdkankan.contro.mq.service.IBuildSceneService;
+import com.fdkankan.contro.service.*;
+import com.fdkankan.contro.service.impl.CommonServiceImpl;
+import com.fdkankan.fyun.config.FYunFileConfig;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import com.fdkankan.model.constants.ConstantFileName;
+import com.fdkankan.model.constants.ConstantFilePath;
+import com.fdkankan.model.constants.UploadFilePath;
+import com.fdkankan.model.utils.CreateObjUtil;
+import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
+import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
+import com.fdkankan.rabbitmq.util.RabbitMqProducer;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/4/20
+ **/
+@Slf4j
+@Service
+@RefreshScope
+public class BuildReverseE57SceneServiceImpl implements IBuildSceneService {
+    public static final String logUrlFormat = "**algorithm-log**: [%sbuild_log/%s/e57/console.log](%sbuild_log/%s/e57/console.log)";
+
+    @Value("${queue.modeling.reverseE57.modeling-post:reverseE57-modeling-post}")
+    private String queueModelingPost;
+    @Value("#{'${build.scene.post.not-delete-nas-nums:}'.split(',')}")
+    private List<String> notDeleteNasNumList;
+    @Value("${queue.application.laser.e57-modeling-done:e57-modeling-done}")
+    private String queueE57ModelingDone;
+    @Autowired
+    private RabbitMqProducer mqProducer;
+    @Resource
+    private FYunFileServiceInterface fYunFileService;
+    @Autowired
+    private FYunFileConfig fYunFileConfig;
+    @Autowired
+    private IScenePlusService scenePlusService;
+    @Autowired
+    private IScenePlusExtService scenePlusExtService;
+    @Autowired
+    private IBuildSceneDTService buildSceneDTService;
+    @Autowired
+    private ICommonService commonService;
+    @Autowired
+    private IFdkkLaserService fdkkLaserService;
+    @Autowired
+    private ISceneEditControlsService sceneEditControlsService;
+
+    @Override
+    public void buildScenePre(BuildSceneCallMessage message) throws Exception{
+        String num = message.getSceneNum();
+        try {
+            ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
+            ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
+            String dataSource = scenePlusExt.getDataSource();
+            message.setPath(dataSource);
+
+            String e57Path = (String)message.getExt().get("path");
+
+            //下载资源到本地
+            FileUtil.copyContent(new File(e57Path), new File(dataSource + "capture"), true);
+
+            //发送mq,就进行计算
+//            message.setPath(path);
+            message.setResultReceiverMqName(queueModelingPost);
+            message.setBizType("reverseE57");
+
+            log.info("上传e57计算资源准备结束,场景码:{}", message.getSceneNum());
+
+        }catch (Exception e){
+            log.error("上传e57计算前置处理出错,num"+num, e);
+            buildSceneDTService.handBaseFail("上传e57计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
+            throw e;
+        }
+    }
+
+    private String getOssPath(String path) {
+        String ossPath = ConstantFilePath.OSS_PREFIX
+                + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
+                .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
+        if (!ossPath.endsWith("/")) {
+            ossPath = ossPath.concat("/");
+        }
+        return ossPath;
+    }
+
+    @Override
+    public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
+        String ossPath = getOssPath(buildSceneMqMessage.getPath());
+        fYunFileService.downloadFileByCommand(path + "/capture", ossPath);
+    }
+
+    @Override
+    public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
+        String sceneCode = message.getBuildContext().get("sceneNum").toString();
+        String path = message.getPath();
+        try {
+            // 上传计算日志
+            //如果是重复计算,没有走到计算逻辑,不需要上传日志文件
+            log.info("开始上传计算日志");
+            String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneCode);
+            fYunFileService.uploadFile(path + File.separator + "console.log", buildLogPath + "console.log");
+            log.info("计算日志上传完成");
+
+            if (!message.getBuildSuccess()) {
+                log.error("建模失败,修改状态为失败状态");
+                scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
+                        .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
+                        .eq(ScenePlus::getNum, sceneCode));
+
+                return;
+            }
+
+            ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
+
+            Integer cameraType = Integer.parseInt(message.getBuildContext().get("cameraType").toString());
+            Map<String, String> uploadFiles = this.getUploadFiles(scenePlus,path);
+
+            scenePlus.setPayStatus(PayStatus.PAY.code());
+            scenePlus.setUpdateTime(new Date());
+            scenePlus.setSceneStatus(SceneStatus.NO_DISPLAY.code());
+
+            ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
+
+            log.info("开始上传场景计算结果数据,num:{}", sceneCode);
+            //上传文件
+            fYunFileService.uploadMulFiles(uploadFiles);
+
+
+            //生成floorpan.json
+            commonService.uploadFloorplanJson(sceneCode, path);
+
+            //清除用户编辑业务数据
+            Set<String> bizs = new HashSet<>();
+            bizs.add(UserEditDataType.BOX_MODEL.message());
+            bizs.add(UserEditDataType.FLOORPLAN.message());
+            bizs.add(UserEditDataType.FILTERS.message());
+            commonService.initUserEditData(sceneCode, bizs, null);
+
+            //上传计算结果文件
+            commonService.uploadBuildResultData(sceneCode, path, SceneVersionType.V4.code());
+
+            Object[] editInfoArr = commonService.updateEditInfo(scenePlus);
+            SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
+            SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
+            SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
+
+            //如果相机容量不足,需要把场景的paystatus改为容量不足状态
+            scenePlusExt.setOrigSpace(FileUtil.size(new File(path.concat(File.separator).concat("capture"))));
+
+            if (cameraType == 14) {
+                //计算成功  激光转台相机 同步 请求
+                fdkkLaserService.syncBuildResult(scenePlus.getNum(), path, scenePlus.getCreateTime(), Calendar.getInstance().getTime(), scenePlusExt.getShootCount(), scenePlus.getPayStatus());
+                sceneEditControlsService.update(new LambdaUpdateWrapper<SceneEditControls>().set(SceneEditControls::getShowMap,0)
+                        .eq(SceneEditControls::getEditInfoId,sceneEditInfo.getId()));
+                sceneEditControls.setShowMap(0);
+            } else if (new File(path + "/results/laserData/vision_edit.txt").exists()) {
+                fdkkLaserService.cloudPointBuild(sceneCode,path);
+            }
+
+
+//            //删除计算目录
+            if(CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)){
+                CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/"));
+            }
+
+
+            this.uploadStatusJson(scenePlus, scenePlusExt);
+
+            scenePlusService.updateById(scenePlus);
+            scenePlusExtService.updateById(scenePlusExt);
+
+
+            log.info("场景计算结果处理结束,场景码:{}", sceneCode);
+
+        }catch (Exception e){
+            log.error("场景计算结果处理出错,num"+sceneCode, e);
+            buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
+            throw e;
+        }
+    }
+
+    private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt){
+        String num = scenePlus.getNum();
+        String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
+
+        Integer status = 0;
+
+        // 上传status JSON.
+        JSONObject statusJson = new JSONObject();
+        //临时将-2改成1,app还没完全更新
+        statusJson.put("status", status);
+        statusJson.put("webSite", scenePlusExt.getWebSite());
+        statusJson.put("sceneNum", num);
+        statusJson.put("thumb", scenePlusExt.getThumb());
+        statusJson.put("payStatus", scenePlus.getPayStatus());
+        statusJson.put("sceneScheme", scenePlusExt.getSceneScheme());
+        FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
+
+        fYunFileService.uploadFile(statusJson.toJSONString().getBytes(StandardCharsets.UTF_8), dataViewPath + "status.json");
+    }
+
+    private Map<String, String> getUploadFiles(ScenePlus scenePlus,String path) throws Exception {
+        if (ObjectUtils.isEmpty(scenePlus)) {
+            throw new Exception("未找到场景信息:" + path);
+        }
+
+        String projectNum = scenePlus.getNum();
+
+        String dataViewPath = 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 uploadData = FileUtils.readFile(resultsPath + "upload.json");
+        JSONArray array = JSONObject.parseObject(uploadData).getJSONArray("upload");
+
+        JSONObject fileJson = null;
+        String fileName = "";
+
+        Map<String, String> map = new HashMap();
+
+        for (int i = 0; i < array.size(); ++i) {
+            fileJson = array.getJSONObject(i);
+            fileName = fileJson.getString("file");
+            String filePath = resultsPath + fileName;
+
+            if (!(new File(filePath)).exists()) {
+                throw new Exception(filePath + "文件不存在");
+            }
+
+            if ("vision2.txt".equals(fileName)) {
+                CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision2.txt", resultsPath + "vision2.modeldata");
+                map.put(resultsPath + "vision2.modeldata", imagesPath + "vision2.modeldata");
+                map.put(resultsPath + "vision2.txt", imagesPath + "vision2.txt");
+            }
+
+            if (fileJson.getIntValue("clazz") == 2) {
+                map.put(filePath, imagesPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
+            } else if (fileJson.getIntValue("clazz") == 3) {
+                map.put(filePath, imagesPath + "pan/high/" + fileName.replace("high/", ""));
+            } else if (fileJson.getIntValue("clazz") == 4) {
+                map.put(filePath, imagesPath + "pan/low/" + fileName.replace("low/", ""));
+            } else if (fileJson.getIntValue("clazz") == 5) {
+                map.put(filePath, imagesPath + fileName);
+            } else if (fileJson.getIntValue("clazz") == 7) {
+                map.put(filePath, imagesPath + fileName);
+            } else if (fileJson.getIntValue("clazz") == 10) {
+                String updown = FileUtils.readFile(filePath);
+                JSONObject updownJson = JSONObject.parseObject(updown);
+                String mappingOssPath = String.format("scene_edit_data/%s/data/", projectNum) + fileName.replace("updown", "mapping");
+                map.put(filePath, mappingOssPath);
+            } else {
+                if (fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("clazz") == 12) {
+                    map.put(filePath, videoPath + fileName.replace("videos/", ""));
+                    if (fileName.contains(".mp4")) {
+                        map.put(resultsPath + fileName.replace("mp4", "flv"), videoPath + fileName.replace("videos/", "").replace("mp4", "flv"));
+                    }
+                }
+
+                if (fileJson.getIntValue("clazz") == 16) {
+                    map.put(filePath, dataViewPath + fileName);
+                }
+
+                if (fileJson.getIntValue("clazz") == 18) {
+                    map.put(filePath, imagesPath + fileName);
+                }
+            }
+        }
+
+        CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision.txt", resultsPath + "vision.modeldata");
+        map.put(resultsPath + "vision.txt", imagesPath + "vision.txt");
+        map.put(resultsPath + "vision.modeldata", imagesPath + "vision.modeldata");
+
+        log.info("数据转换完成:" + projectNum);
+        if(!new File("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum).exists()){
+            FileUtil.mkdir("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum);
+        }
+//        map.put(resultsPath + "floorplan.json", dataViewPath + "floor.json");
+        map.put(resultsPath + "floorplan_cad.json", dataViewPath + "floorplan_cad.json");
+        map.put(path + File.separator + "capture/stitch_params.txt", dataViewPath + "stitch_params.txt");
+        map.put(path + File.separator + "capture/Up.xml", dataViewPath + "Up.xml");
+        map.put(path + File.separator + "capture/Up2.xml", dataViewPath + "Up2.xml");
+        map.put(path + File.separator + "capture/Up.txt", dataViewPath + "Up.txt");
+        map.put(path + File.separator + "capture/Up2.txt", dataViewPath + "Up2.txt");
+        return map;
+
+    }
+
+}

+ 0 - 436
src/main/java/com/fdkankan/contro/mq/service/impl/BuildReverseE57ServiceImpl.java

@@ -1,436 +0,0 @@
-package com.fdkankan.contro.mq.service.impl;
-
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.io.FileUtil;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.fdkankan.common.constant.*;
-import com.fdkankan.common.util.FileUtils;
-import com.fdkankan.contro.entity.ScenePlus;
-import com.fdkankan.contro.entity.ScenePlusExt;
-import com.fdkankan.contro.mq.service.IBuildSceneService;
-import com.fdkankan.contro.service.*;
-import com.fdkankan.fyun.config.FYunFileConfig;
-import com.fdkankan.fyun.face.FYunFileServiceInterface;
-import com.fdkankan.model.constants.ConstantFilePath;
-import com.fdkankan.model.constants.UploadFilePath;
-import com.fdkankan.model.enums.ModelTypeEnums;
-import com.fdkankan.model.utils.CreateObjUtil;
-import com.fdkankan.model.utils.SceneUtil;
-import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
-import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
-import com.fdkankan.rabbitmq.util.RabbitMqProducer;
-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.cloud.context.config.annotation.RefreshScope;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.io.File;
-import java.nio.charset.StandardCharsets;
-import java.util.*;
-
-
-/**
- * <p>
- * TODO
- * </p>
- *
- * @author dengsixing
- * @since 2022/4/20
- **/
-@Slf4j
-@Service
-@RefreshScope
-public class BuildReverseE57ServiceImpl implements IBuildSceneService {
-
-    @Value("${queue.modeling.modeling-call}")
-    private String queueModelingCall;
-    @Value("${queue.modeling.intermit.modeling-post}")
-    private String queueModelingPost;
-    @Value("${model.type:#{null}}")
-    private String modelType;
-    @Value("${env:gn}")
-    private String env;
-    @Value("#{'${build.scene.post.not-delete-nas-nums:}'.split(',')}")
-    private List<String> notDeleteNasNumList;
-    @Autowired
-    private RabbitMqProducer mqProducer;
-    @Resource
-    private FYunFileServiceInterface fYunFileService;
-    @Autowired
-    private FYunFileConfig fYunFileConfig;
-    @Autowired
-    private IScenePlusService scenePlusService;
-    @Autowired
-    private IScenePlusExtService scenePlusExtService;
-    @Autowired
-    private IBuildSceneDTService buildSceneDTService;
-    @Autowired
-    private ICommonService commonService;
-    @Autowired
-    private ISceneColdStorageService sceneColdStorageService;
-    @Autowired
-    private IntermitSceneService intermitSceneService;
-
-    @Override
-    public void buildScenePre(BuildSceneCallMessage message) throws Exception{
-        String num = message.getSceneNum();
-        try {
-            //重新计算时需要删除文件夹,否知使用缓存
-            if(new File(message.getPath() + File.separator + "results").exists()){
-                FileUtils.deleteDirectory(message.getPath() + File.separator + "results");
-            }
-            //由于刘强说caches会影响计算结果,所以这里删除caches
-            if(new File(message.getPath() + File.separator + "caches").exists()){
-                FileUtils.deleteDirectory(message.getPath() + File.separator + "caches");
-            }
-
-            //删除点位校准数据
-            if (Objects.nonNull(message.getExt())
-                    && message.getExt().containsKey("deleteExtras")
-                    && (Boolean) message.getExt().get("deleteExtras")) {
-                String extras = String.format(UploadFilePath.scene_result_data_path, num).concat("extras");
-                if(CollUtil.isNotEmpty(fYunFileService.listRemoteFiles(extras))){
-                    fYunFileService.deleteFolder(extras);
-                }
-            }
-
-            //用户相机重新全量上传,需要解冻结
-            sceneColdStorageService.unfreeze(num, "用户相机重新全量上传", message.getPath());
-
-            //根据相机类型,组装资源路径
-            //下载资源到本地
-            this.downLoadSource(message, message.getPath());
-
-            message.getBuildContext().put("cameraType",message.getCameraType());
-
-            //发送mq,就进行计算
-            message.setResultReceiverMqName(queueModelingPost);
-
-            log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
-
-        }catch (Exception e){
-            log.error("场景计算前置处理出错,num"+num, e);
-            buildSceneDTService.handBaseFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
-            throw e;
-        }
-    }
-
-    private String getOssPath(String path) {
-        String ossPath = ConstantFilePath.OSS_PREFIX
-                + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
-                .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
-        if (!ossPath.endsWith("/")) {
-            ossPath = ossPath.concat("/");
-        }
-        return ossPath;
-    }
-
-    @Override
-    public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
-        String ossPath = getOssPath(path);
-        fYunFileService.downloadFileByCommand(path + File.separator + "capture", ossPath);
-    }
-
-    @Override
-    public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
-        String sceneCode = message.getBuildContext().get("sceneNum").toString();
-        String path = message.getPath();
-        try {
-            // 上传计算日志
-            //如果是重复计算,没有走到计算逻辑,不需要上传日志文件
-            log.info("开始上传计算日志");
-            String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneCode);
-            fYunFileService.uploadFile(path + File.separator + "console.log", buildLogPath + "console.log");
-            log.info("计算日志上传完成");
-
-            if (!message.getBuildSuccess()) {
-                log.error("建模失败,修改状态为失败状态");
-                scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
-                        .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
-                        .eq(ScenePlus::getNum, sceneCode));
-
-                // 发送钉钉消息,计算失败
-                buildSceneDTService.handModelFail("计算失败", message.getPath(), sceneCode, message.getHostName());
-                return;
-            }
-            JSONObject fdageData = getFdageData(path + File.separator + "capture" +File.separator+"data.fdage");
-
-            ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
-
-            Integer cameraType = Integer.parseInt(message.getBuildContext().get("cameraType").toString());
-            Map<String, String> uploadFiles = getUploadFiles(scenePlus,path);
-
-            scenePlus.setPayStatus(PayStatus.PAY.code());
-            scenePlus.setUpdateTime(new Date());
-            scenePlus.setSceneStatus(SceneStatus.NO_DISPLAY.code());
-
-            Integer videoVersion = fdageData.getInteger("videoVersion");
-            //读取计算结果文件生成videosJson
-            JSONObject videosJson = this.getVideosJson(path, videoVersion, sceneCode, cameraType);
-
-            ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
-
-            log.info("开始上传场景计算结果数据,num:{}", sceneCode);
-            //上传文件
-            fYunFileService.uploadMulFiles(uploadFiles);
-
-            //容量统计
-            Long space = commonService.getSpace(sceneCode);
-
-            //写入数据库
-            this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), message.getComputeTime(),false,scenePlusExt);
-
-            Object[] editInfoArr = commonService.updateEditInfo(scenePlus);
-
-            //统计原始资源大小
-            scenePlusExt.setOrigSpace(FileUtil.size(new File(path.concat(File.separator).concat("capture"))));
-
-            //删除计算目录
-            if(CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)){
-                CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/"));
-            }
-
-            //如果相机容量不足,需要把场景的paystatus改为容量不足状态
-            scenePlus.setPayStatus(commonService.getPayStatus(scenePlus.getCameraId(), space));
-
-            this.uploadStatusJson(scenePlus, scenePlusExt);
-
-            scenePlusService.updateById(scenePlus);
-            scenePlusExtService.updateById(scenePlusExt);
-
-            //推送到全景看看
-            intermitSceneService.sendMq(sceneCode, fdageData, CommonSuccessStatus.SUCCESS.code());
-
-            log.info("场景计算结果处理结束,场景码:{}", sceneCode);
-
-        }catch (Exception e){
-            log.error("场景计算结果处理出错,num"+sceneCode, e);
-            buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
-            throw e;
-        }
-    }
-
-    private Map<String, String> getUploadFiles(ScenePlus scenePlus,String path) throws Exception {
-        String projectNum = scenePlus.getNum();
-        String dataViewPath = 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 uploadData = FileUtils.readFile(resultsPath + "upload.json");
-        JSONArray array = JSONObject.parseObject(uploadData).getJSONArray("upload");
-
-        JSONObject fileJson = null;
-        String fileName = "";
-
-        Map<String, String> map = new HashMap();
-
-        for (int i = 0; i < array.size(); ++i) {
-            fileJson = array.getJSONObject(i);
-            fileName = fileJson.getString("file");
-            String filePath = resultsPath + fileName;
-
-            if (!(new File(filePath)).exists()) {
-                throw new Exception(filePath + "文件不存在");
-            }
-
-            if(fileJson.getIntValue("clazz") == 1 || fileJson.getIntValue("clazz") == 22){
-                map.put(filePath, imagesPath + fileName);
-            }
-        }
-        return map;
-    }
-
-    private JSONObject getFdageData(String dataFdagePath) {
-        log.info("dataFdagePath 文件路径 :{}", dataFdagePath);
-        String data = FileUtils.readFile(dataFdagePath);
-        //获取data.fdage的内容
-        JSONObject dataJson = new JSONObject();
-        if(data!=null){
-            dataJson = JSONObject.parseObject(data);
-        }
-        return dataJson;
-    }
-
-    private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt){
-        String num = scenePlus.getNum();
-        String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
-
-        Integer status = 1;
-        // 上传status JSON.
-        JSONObject statusJson = new JSONObject();
-        //临时将-2改成1,app还没完全更新
-        statusJson.put("status", status);
-        statusJson.put("webSite", scenePlusExt.getWebSite());
-        statusJson.put("sceneNum", num);
-        statusJson.put("thumb", scenePlusExt.getThumb());
-        statusJson.put("payStatus", scenePlus.getPayStatus());
-        statusJson.put("sceneScheme", scenePlusExt.getSceneScheme());
-        FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
-
-        fYunFileService.uploadFile(statusJson.toJSONString().getBytes(StandardCharsets.UTF_8), dataViewPath + "status.json");
-    }
-
-    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);
-            videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up.xml");
-            if(cameraType == 13){
-                //转台相机
-                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
-            }
-        }else {
-            videosJson.put("version", 1);
-            videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up2.xml");
-            if(cameraType == 13){
-                //转台相机
-                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
-            }
-        }
-
-        if(cameraType == 5 || cameraType == 6){
-            videosJson.put("version", 1);
-            videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "stitch_params.txt");
-        }
-
-        return videosJson;
-    }
-    private void updateDbPlus(int sceneSource,Long space,String videosJson, Long computeTime,boolean isObj,ScenePlusExt scenePlusExt){
-
-        scenePlusExt.setSpace(space);
-        scenePlusExt.setComputeTime(computeTime.toString());
-        scenePlusExt.setAlgorithmTime(new Date());
-        scenePlusExt.setVideos(videosJson);
-        scenePlusExt.setIsObj(isObj ? 1 : 0);
-
-        if(ModelTypeEnums.TILE_CODE.equals(modelType)){
-            scenePlusExt.setSceneScheme(3);
-        }
-
-        switch (SceneSource.get(sceneSource)){
-            case BM:
-                scenePlusExt.setSceneResolution(SceneResolution.two_K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
-                break;
-            case SM:
-                scenePlusExt.setSceneResolution(SceneResolution.one_k.code());
-                scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
-                break;
-            case ZT:
-                scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
-                break;
-            case JG:
-                scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
-                break;
-            case SG:
-                scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
-                break;
-        }
-
-        String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
-        scenePlusExt.setSceneKind(sceneKind);
-//        scenePlusExt.setModelKind(modelKind);
-
-        //统计点位数量
-        scenePlusExt.setShootCount(this.getShootCount(scenePlusExt));
-
-        scenePlusExtService.updateById(scenePlusExt);
-    }
-
-    private Integer getShootCount(ScenePlusExt scenePlusExt){
-        Integer shootCount = null;
-        String homePath = SceneUtil.getHomePath(scenePlusExt.getDataSource());
-        JSONObject dataFdageObj = JSON.parseObject(fYunFileService.getFileContent(homePath.concat("data.fdage")));
-        if(Objects.nonNull(dataFdageObj)){
-            JSONArray points = dataFdageObj.getJSONArray("points");
-            if(CollUtil.isNotEmpty(points)){
-                shootCount = points.size();
-            }
-        }
-        if(Objects.nonNull(shootCount) && shootCount > 0){
-            return shootCount;
-        }
-
-        String slamDataStr = fYunFileService.getFileContent(homePath.concat("slam_data.json"));
-        JSONObject slamDataObj = JSON.parseObject(slamDataStr);
-        if(Objects.nonNull(slamDataObj)){
-            JSONArray viewsInfo = slamDataObj.getJSONArray("views_info");
-            if(CollUtil.isNotEmpty(viewsInfo)){
-                shootCount = viewsInfo.stream().mapToInt(info -> {
-                    return  ((JSONObject) info).getJSONArray("list_pose").size();
-                }).sum();
-            }
-        }
-
-        return shootCount;
-    }
-
-
-}

+ 3 - 0
src/main/java/com/fdkankan/contro/service/ISceneFileBuildService.java

@@ -1,5 +1,6 @@
 package com.fdkankan.contro.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.contro.entity.SceneFileBuild;
 import com.fdkankan.contro.vo.ResponseSceneFile;
@@ -31,4 +32,6 @@ public interface ISceneFileBuildService extends IService<SceneFileBuild> {
     ResultData copyDataAndBuild(String sourceBucet,String dataSource,String sceneVer) throws Exception;
 
     ResultData uploadFile(MultipartFile file, String params) throws Exception;
+
+    ResultData reverseE57(JSONObject params) throws Exception;
 }

+ 59 - 0
src/main/java/com/fdkankan/contro/service/impl/SceneFileBuildServiceImpl.java

@@ -851,6 +851,65 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
         return ResultData.ok();
     }
 
+    @Override
+    public ResultData reverseE57(JSONObject params) throws Exception {
+
+        String title = params.getString("title");
+        Long userId = params.getLong("userId");
+
+        SSOUser user = userService.getSSOUserByUserId(userId);
+
+        String num = "e57" + scene3dNumService.generateSceneNum(null);
+
+        String uuid = UUID.randomUUID().toString();
+
+        //云目录
+        StringBuilder prefixBuffer = new StringBuilder(ConstantFilePath.BUILD_MODEL_PATH).append("reverseE57").append(uuid);
+
+        String buildType = "V3";
+
+        ScenePlus scenePlus = new ScenePlus();
+        scenePlus.setTitle(title);
+        scenePlus.setUserId(userId);
+        scenePlus.setPayStatus(PayStatus.PAY.code());
+        scenePlus.setNum(num);
+        scenePlus.setSceneSource(57);
+        scenePlusService.save(scenePlus);
+
+        ScenePlusExt scenePlusExt = new ScenePlusExt();
+        scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
+        scenePlusExt.setSceneKind(SceneKind.FACE.code());
+        scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
+        scenePlusExt.setBuildType(buildType);
+        scenePlusExt.setLocation(4);
+        scenePlusExt.setModelKind(ModelKind.THREE_D_TILE.code());
+        scenePlusExt.setSceneScheme(SceneScheme.LM.code());
+        scenePlusExt.setPlusId(scenePlus.getId());
+        scenePlusExt.setDataSource(prefixBuffer.toString());
+        scenePlusExtService.save(scenePlusExt);
+
+
+        SceneEditInfo sceneEditInfo = new SceneEditInfo();
+        sceneEditInfo.setTitle(title);
+        sceneEditInfo.setScenePlusId(scenePlus.getId());
+        sceneEditInfoService.save(sceneEditInfo);
+
+        SceneEditInfoExt sceneEditInfoExt = new SceneEditInfoExt();
+        sceneEditInfoExt.setScenePlusId(scenePlus.getId());
+        sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
+        sceneEditInfoExtService.save(sceneEditInfoExt);
+
+        SceneEditControls sceneEditControls = new SceneEditControls();
+        sceneEditControls.setEditInfoId(sceneEditInfo.getId());
+        sceneEditControlsService.save(sceneEditControls);
+
+        fdkkLaserService.saveScene(scenePlus,new JSONObject(),new Camera(),user.getUserName(),false, scenePlus.getPayStatus());
+
+        rabbitMqProducer.sendByWorkQueue("reverseE57-modeling-pre", params);
+
+        return ResultData.ok();
+    }
+
     public ScenePlusVO createScenePlus(String projectNum, Long cameraId, String phoneId, String sceneKey,
                                      Long cameraType, int camType, String dataSource, String pic, Long userId, String userName,
                                      String algorithm, Integer location, Integer sceneShootCount, String sceneName,