123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- package com.fdkankan.modeling.message;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.common.constant.ConstantFilePath;
- import com.fdkankan.common.util.FileUtils;
- import com.fdkankan.common.util.UploadToOssUtil;
- import com.fdkankan.scene.entity.SceneProEditEntity;
- import com.fdkankan.scene.entity.SceneProEntity;
- import com.fdkankan.scene.entity.VideoSceneProgressEntity;
- import com.fdkankan.scene.service.IRebuildVideoProgressService;
- import com.fdkankan.scene.service.ISceneProEditService;
- import com.fdkankan.scene.service.ISceneProService;
- import com.fdkankan.scene.util.ComputerUtil;
- import com.fdkankan.scene.util.CreateObjUtil;
- import lombok.extern.log4j.Log4j2;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.amqp.rabbit.annotation.RabbitListener;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import java.io.File;
- import java.io.PrintWriter;
- import java.io.StringWriter;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- @Log4j2
- public class ReBuildVideoSceneReceiver {
- @Autowired
- private ISceneProService sceneProService;
- @Autowired
- private ISceneProEditService sceneProEditService;
- @Autowired
- private IRebuildVideoProgressService rebuildVideoProgressService;
- @Autowired
- private UploadToOssUtil uploadToOssUtil;
- @Value("${rabbitmq.queue.video}")
- private String queue;
- @RabbitListener(queues = "${rabbitmq.queue.video}", containerFactory = "rabbitListenerContainerFactory")
- public void processvideo(String content) {
- log.info("接收处理队列当中" + queue + "的消息: " + content);
- rebuildVideo(content);
- }
- private void rebuildVideo(String content){
- String projectNum = null;
- String panId = null;
- String path = null;
- SceneProEntity scene = null;
- try {
- if(content == null||content.trim().equals("")){
- return;
- }
- String[] strs = content.split(":;");
- projectNum = strs[0];
- panId = strs[1];
- VideoSceneProgressEntity videoSceneProgressEntity = rebuildVideoProgressService.findrebuildVideoProgressDetail(projectNum,panId);
- videoSceneProgressEntity.setRebuildStartTime(new Date());
- videoSceneProgressEntity.setRebuildResult(3);
- rebuildVideoProgressService.update(videoSceneProgressEntity);
- log.info("开始计算 : 进度列表:" + videoSceneProgressEntity);
- String splitType = "SPLIT_V13";
- String skyboxType = "SKYBOX_V5";
- Map<String,String> map = new HashMap<>();
- //从云端拉取capture文件
- //目前只支持八目相机
- //休眠1秒,否则可能获取不到场景资源
- Thread.sleep(1000);
- scene = sceneProService.findBySceneNum(projectNum);
- if (scene == null) {
- log.info(projectNum + ":场景不存在");
- return;
- }
- String filePath = videoSceneProgressEntity.getDataSource() + "_rv";
- File targetFile = new File(filePath);
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- String fileId = videoSceneProgressEntity.getDataSource().replace(ConstantFilePath.BUILD_MODEL_PATH, "") ;
- log.info("fileId : " + fileId);
- //下载capture
- CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + fileId + File.separator,
- ConstantFilePath.BUILD_MODEL_PATH + fileId + "_rv" + File.separator + "capture");
- path = ConstantFilePath.BUILD_MODEL_PATH + fileId + "_rv" + File.separator ;
- log.info("path :" + path);
- ComputerUtil.createJson(path, splitType, skyboxType, null, projectNum, path);
- //创建文件 Extras 供算法不用
- log.info("开始生成 Extras 文件");
- ComputerUtil.createExtras(videoSceneProgressEntity,path);
- log.info("开始生成 Extras 文件结束");
- //计算模型并返回需要上传oss的文件集合
- map = ComputerUtil.computerRebuildVideo(projectNum, path);
- log.info("上传内容 ===== + " + map);
- uploadToOssUtil.uploadMulFiles(map);
- log.info("结束计算 =====");
- Map map2 = new HashMap();
- JSONArray uploadarray = null;
- JSONArray hdrArray = null;
- JSONObject fileJson = null;
- String fileName = "";
- //读取videos_hdr_param.json, 保存点位视频的value
- String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
- String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
- String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + projectNum + File.separator + "scene.json");
- JSONObject scenejson = new JSONObject();
- log.info("strsceneInfos =====" + strsceneInfos);
- if(strsceneInfos!=null){
- scenejson = JSONObject.parseObject(strsceneInfos);
- log.info("scenejson =====" + scenejson);
- }
- JSONObject videoJsonNew = new JSONObject();
- JSONArray dataarray = new JSONArray();
- SceneProEntity sceneProEntity = sceneProService.findBySceneNum(projectNum);
- //获取 videos
- if(StringUtils.isNotEmpty(sceneProEntity.getVideos())){
- JSONObject videosjson = JSONObject.parseObject(sceneProEntity.getVideos());
- log.info("videosjson =====" + videosjson);
- if (videosjson.containsKey("data")) {
- JSONArray dataArray = new JSONArray();
- dataArray = (JSONArray) videosjson.get("data");
- JSONObject uploadJson = null;
- if(uploadData!=null) {
- uploadJson = JSONObject.parseObject(uploadData);
- uploadarray = uploadJson.getJSONArray("upload");
- log.info("uploadarray =====" + uploadarray);
- }
- JSONObject hdrObject = new JSONObject();
- for(int i = 0, len = uploadarray.size(); i < len; i++) {
- fileJson = uploadarray.getJSONObject(i);
- fileName = fileJson.getString("file");
- if (fileJson.getIntValue("clazz") == 20 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")) {
- String id =fileName.substring( 0, fileName.lastIndexOf(".")).replace("videos/", "");
- log.info("id :" + id);
- //生成objet
- if(StringUtils.isNotEmpty(videosHdr)){
- hdrArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
- log.info("hdrArray :" + hdrArray);
- }
- if(hdrArray != null){
- for(int z = 0, lenq = hdrArray.size(); z< lenq; z++) {
- JSONObject obj = (JSONObject) hdrArray.get(z);
- String name = (String) obj.get("name");
- if(name.equals(id)){
- String fov = obj.get("fov").toString();
- String name1 = obj.get("name").toString();
- String value = obj.get("value").toString();
- hdrObject.put("blend_fov",String.valueOf(fov));
- hdrObject.put("id",name1);
- hdrObject.put("value",String.valueOf(value));
- log.info("hdrObject :" + hdrObject);
- dataarray.add(hdrObject);
- }
- }
- }
- log.info("dataArray 2 =====" + dataArray);
- for(int x = 0; x < dataArray.size(); x++) {
- JSONObject obj = (JSONObject) dataArray.get(x);
- String id2 = (String) obj.get("id");
- if(!id2.equals(id)){
- dataarray.add(obj);
- log.info("data obj =====" + obj);
- }
- }
- }
- }
- }
- log.info("dataarray =====" + dataarray);
- videoJsonNew.put("data",dataarray);
- videoJsonNew.put("upPath",videosjson.get("upPath"));
- videoJsonNew.put("version",videosjson.get("version"));
- }
- map2.put("videos",videoJsonNew.toJSONString());
- long start = System.currentTimeMillis();
- long computeTime = (System.currentTimeMillis() - start) / 1000;
- sceneProService.updateTime2(projectNum, videoJsonNew.toJSONString(), computeTime);
- Integer imagesVersion = 50;
- if(strsceneInfos!=null){
- scenejson = JSONObject.parseObject(strsceneInfos);
- if(scenejson.containsKey("imagesVersion")){
- log.error("imagesVersion ============" + imagesVersion);
- imagesVersion = (Integer) scenejson.get("imagesVersion");
- imagesVersion = imagesVersion + 50;
- // map2.put("imagesVersion", imagesVersion + 50);
- }
- log.error("imagesVersion2 ============" + imagesVersion);
- map2.put("imagesVersion", imagesVersion);
- log.error("map2 ============" + map2);
- FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + projectNum + File.separator + "scene.json", map2);
- }else{
- log.error("更新 scene.json 文件失败");
- }
- SceneProEditEntity sceneProEditEntity = sceneProEditService.findByProId(sceneProEntity.getId());
- sceneProEditEntity.setImagesVersion(imagesVersion);
- // sceneProEditEntity.setFloorEditVer(sceneProEditEntity.getFloorEditVer() + 1);
- // sceneProEditEntity.setFloorPublishVer(sceneProEditEntity.getFloorPublishVer() + 1);
- sceneProEditService.update(sceneProEditEntity);
- rebuildVideoProgressService.updateProgress(projectNum, panId,1);
- }catch(Exception e){
- log.error("视频失败"+projectNum);
- rebuildVideoProgressService.updateProgress(projectNum, panId,0);
- e.printStackTrace();
- StringWriter trace=new StringWriter();
- e.printStackTrace(new PrintWriter(trace));
- log.error(trace.toString());
- }finally {
- try{
- scene = sceneProService.findBySceneNum(projectNum);
- if(scene != null){
- JSONObject statusJson = new JSONObject();
- //临时将-2改成1,app还没完全更新
- statusJson.put("status", scene.getStatus() == -2? 1 : scene.getStatus());
- statusJson.put("webSite", scene.getWebSite());
- statusJson.put("sceneNum", scene.getNum());
- statusJson.put("thumb", scene.getThumb());
- statusJson.put("payStatus", scene.getPayStatus());
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"status.json", statusJson.toString());
- uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"status.json",
- "data/data"+projectNum+File.separator+"status.json");
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }
- }
|