package com.fdkankan.contro.mq.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.fdkankan.common.util.FileUtils; import com.fdkankan.contro.entity.ScenePlus; import com.fdkankan.contro.entity.ScenePro; import com.fdkankan.contro.entity.SceneProEdit; import com.fdkankan.contro.mq.service.IBuildSceneService; import com.fdkankan.contro.service.*; import com.fdkankan.contro.service.impl.FdkkV4Service; 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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import java.io.File; /** *

* TODO *

* * @author dengsixing * @since 2022/3/1 **/ @Slf4j @Service public class BuildObjServiceImpl implements IBuildSceneService { @Value("${queue.modeling.modeling-call}") private String queueModelingCall; @Value("${queue.modeling.obj.modeling-post}") private String queueObjModelingPost; @Value("${queue.modeling.obj.modeling-pre}") private String queueObjModelingPre; @Autowired private RabbitMqProducer mqProducer; @Autowired private FYunFileServiceInterface fYunFileService; @Autowired private ISceneProService sceneProService; @Autowired private IFdkkLaserService fdkkLaserService; @Autowired private FdkkV4Service fdkkV4Service; @Autowired private IBuildSceneDTService buildSceneDTService; @Autowired private ISceneProEditService sceneProEditService; @Autowired private IScenePlusService scenePlusService; @Autowired private ISceneBuildProcessLogService sceneBuildProcessLogService; @Override public void buildScenePre(BuildSceneCallMessage message) { boolean success = false; try { //记录日志 sceneBuildProcessLogService.clearSceneBuildProcessLog(message.getSceneNum(), scenebuildt); String path = message.getPath(); //根据相机类型,组装资源路径 String laserObjFilePath = path + "_laser_obj"; log.info("开始准备生成OBJ场景资源,路径:{}", laserObjFilePath); FileUtils.delAllFile(laserObjFilePath); //获取解压后的资源的data.fdage中的数据 File folderPath = new File(path); fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "") + "/data.fdage", path + "/capture/data.fdage"); JSONObject jsonObject = FileUtils.readJson(folderPath.getAbsolutePath() + File.separator + "capture" + File.separator + "data.fdage"); if(ObjectUtils.isEmpty(jsonObject)){ log.error("data.fdage文件不存在"); return ; } if (!jsonObject.containsKey("exportMeshObj") || jsonObject.getIntValue("exportMeshObj") != 1) { // 写入data.fdage 防止重算 jsonObject.put("exportMeshObj", 1); FileUtils.writeFile(folderPath.getAbsolutePath() + File.separator + "capture" + File.separator + "data.fdage", jsonObject.toJSONString()); fYunFileService.uploadFile(folderPath.getAbsolutePath() + File.separator + "capture" + File.separator + "data.fdage", ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "") + "/data.fdage"); } // 重新构造datafdage文件,添加生成obt文件选项 jsonObject.put("OnlyExportMeshObj",true); FileUtils.writeFile(laserObjFilePath + File.separator + "capture" + File.separator + "data.fdage", jsonObject.toJSONString()); message.getBuildContext().put("previousPath",path); message.setCameraType("14"); message.setResolution(jsonObject.getString("resolution")); message.setPath(laserObjFilePath); message.setResultReceiverMqName(queueObjModelingPost); //下载资源到本地 this.downLoadSource(message, laserObjFilePath); //发送mq,就进行计算 mqProducer.sendByWorkQueue(queueModelingCall, message); success = true; log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum()); }catch (Exception e){ log.error("场景计算前置处理出错", e); }finally { //如果前置处理失败,发送钉钉消息 if(!success){ buildSceneDTService.handBaseFail("生成OBJ场景资源准备异常", message.getPath(), message.getSceneNum(), "计算控制服务器"); } } } @Override public void downLoadSource(BuildSceneCallMessage message,String path) throws Exception{ String prevoisPath = message.getBuildContext().get("previousPath").toString(); FileUtils.copyFile(prevoisPath + "/caches/reconstruction/final.bin", path + "/caches/reconstruction/final.bin", true); FileUtils.copyFile(prevoisPath + "/caches/reconstruction/chunk.json", path + "/caches/reconstruction/chunk.json", true); FileUtils.copyDirectiory(prevoisPath + "/caches/images", path + "/caches/images"); FileUtils.copyDirectiory(prevoisPath + "/caches/depthmap_csc", path + "/caches/depthmap_csc"); FileUtils.copyDirectiory(prevoisPath + "/caches/depthmap_vis", path + "/caches/depthmap_vis"); FileUtils.copyDirectiory(prevoisPath + "/caches/depthmap", path + "/caches/depthmap"); FileUtils.copyFile(prevoisPath + "/caches/panorama.json", path + "/caches/panorama.json", true); FileUtils.copyFile(prevoisPath + "/results/laserData/laser.ply", path + "/results/laserData/laser.ply", true); } @Override public void buildScenePost(BuildSceneResultMqMessage message) throws Exception { if (!message.getBuildSuccess()) { log.error("生成OBJ场景计算失败!"); // 发送钉钉消息,计算失败 buildSceneDTService.handModelFail("生成OBJ场景计算失败!", message.getPath(), message.getBuildContext().get("sceneNum").toString(), message.getHostName()); return; } String path = message.getPath(); String projectNum = message.getBuildContext().get("sceneNum").toString(); String laserObjFilePath = path; CreateObjUtil.convertTxtToDam(laserObjFilePath + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam"); CreateObjUtil.convertDamToLzma(laserObjFilePath + File.separator + "results/"); CreateObjUtil.convertTxtToDam(laserObjFilePath + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam"); File file = new File(laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam.lzma"); while (!file.exists()) { Thread.sleep(60000); } fYunFileService.uploadFile(laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam.lzma", String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + ConstantFileName.modelUUID + "_50k.dam.lzma"); fYunFileService.uploadFile(laserObjFilePath + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam", String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + ConstantFileName.modelUUID + "_50k.dam"); String texPath = laserObjFilePath + File.separator + "results" + File.separator + "tex"; File texFile = new File(texPath); if(texFile.exists()){ for (File textureFile : texFile.listFiles()) { if(textureFile.getName().endsWith(".jpg")){ fYunFileService.uploadFile(textureFile.getAbsolutePath(), String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/"+textureFile.getName()); } } } fYunFileService.uploadFile(laserObjFilePath + File.separator + "results" + File.separator + "tex/texture1.jpg", String.format(UploadFilePath.IMG_VIEW_PATH, projectNum) + "/" + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/texture1.jpg"); // 拷贝结果 log.info("开始拷贝obj文件"); FileUtils.copyFolderAllFiles(laserObjFilePath + "/results/mesh", laserObjFilePath + "/laserData/mesh/", true); File meshFolder = new File(laserObjFilePath + "/results/mesh"); for (File meshFile : meshFolder.listFiles()) { fYunFileService.uploadFile(meshFile.getAbsolutePath(), String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "mesh/" + meshFile.getName()); } fdkkLaserService.pushBuildStatusToLaserSystem(projectNum, laserObjFilePath + "/laserData/mesh"); ScenePro scenePro = sceneProService.getByNum(projectNum); if(!ObjectUtils.isEmpty(scenePro)){ LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() .set(ScenePro::getStatus, -2).eq(ScenePro::getNum, projectNum); sceneProService.update(updateWrapper); sceneProEditService.update(new LambdaUpdateWrapper().set(SceneProEdit::getMapVisi,0) .eq(SceneProEdit::getProId,scenePro.getId())); } ScenePlus scenePlus = scenePlusService.getScenePlusByNum(projectNum); if(!ObjectUtils.isEmpty(scenePlus)){ LambdaUpdateWrapper plusUpdateWrapper = new LambdaUpdateWrapper() .set(ScenePlus::getSceneStatus, -2).eq(ScenePlus::getNum, projectNum); scenePlusService.update(plusUpdateWrapper); } // 如果未升级V4,则升级V4 fdkkV4Service.upgradeToV4(projectNum); } }