123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- package com.fdkankan.contro.mq.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.io.FileUtil;
- import cn.hutool.core.util.CharsetUtil;
- 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.contro.util.FyunUtil;
- 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;
- @Resource
- private FyunUtil fyunUtil;
- @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 zipPath = (String)message.getExt().get("path");
- String fyunType = (String)message.getExt().get("fyunType");
- String bucket = (String)message.getExt().get("bucket");
- //下载资源到本地
- String destPath = dataSource + "/capture/" + FileUtil.getName(zipPath);
- fyunUtil.yunDownloadSs(fyunType, bucket, zipPath, destPath);
- ZipUtil.unzip(destPath, dataSource + "/capture/", CharsetUtil.CHARSET_GBK);
- List<File> files = FileUtil.loopFiles(dataSource + "/capture/");
- files.stream().forEach(file->{
- if(file.getAbsolutePath().endsWith(".e57")){
- FileUtil.rename(file, "input.e57", 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];
- SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
- //如果相机容量不足,需要把场景的paystatus改为容量不足状态
- scenePlusExt.setOrigSpace(FileUtil.size(new File(path.concat(File.separator).concat("capture"))));
- if (cameraType == 14) {
- //计算成功 激光转台相机 同步 请求
- fdkkLaserService.syncBuildResult4E57(path);
- fdkkLaserService.sendE57ToLaser(scenePlus, scenePlusExt);
- 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;
- }
- }
|