BuildV3SceneServiceImpl.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. package com.fdkankan.contro.mq.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.io.file.FileNameUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import cn.hutool.core.util.ZipUtil;
  7. import com.alibaba.fastjson.JSON;
  8. import com.alibaba.fastjson.JSONArray;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  11. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  12. import com.fdkankan.common.constant.ExpiredStatus;
  13. import com.fdkankan.common.constant.PayStatus;
  14. import com.fdkankan.common.constant.SceneStatus;
  15. import com.fdkankan.common.util.FileUtils;
  16. import com.fdkankan.contro.entity.*;
  17. import com.fdkankan.contro.mq.service.IBuildSceneService;
  18. import com.fdkankan.contro.service.*;
  19. import com.fdkankan.contro.service.impl.FdkkV4Service;
  20. import com.fdkankan.fyun.config.FYunFileConfig;
  21. import com.fdkankan.fyun.constant.FYunTypeEnum;
  22. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  23. import com.fdkankan.model.constants.ConstantFileName;
  24. import com.fdkankan.model.constants.ConstantFilePath;
  25. import com.fdkankan.model.constants.UploadFilePath;
  26. import com.fdkankan.model.utils.CreateHouseJsonUtil;
  27. import com.fdkankan.model.utils.CreateObjUtil;
  28. import com.fdkankan.push.config.PushMessageConfig;
  29. import com.fdkankan.push.utils.PushMsgUtil;
  30. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  31. import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
  32. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  33. import lombok.extern.slf4j.Slf4j;
  34. import org.apache.commons.lang3.ObjectUtils;
  35. import org.apache.commons.lang3.StringUtils;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.beans.factory.annotation.Value;
  38. import org.springframework.stereotype.Service;
  39. import java.io.File;
  40. import java.io.IOException;
  41. import java.util.*;
  42. import java.util.Map.Entry;
  43. import java.util.stream.Collectors;
  44. /**
  45. * <p>
  46. * TODO
  47. * </p>
  48. *
  49. * @author dengsixing
  50. * @since 2022/4/20
  51. **/
  52. @Slf4j
  53. @Service
  54. public class BuildV3SceneServiceImpl implements IBuildSceneService {
  55. @Value("${queue.modeling.modeling-call}")
  56. private String queueModelingCall;
  57. @Value("${queue.modeling.v3.modeling-post}")
  58. private String queueV3ModelingPost;
  59. @Value("${model.type:#{null}}")
  60. private String modelSceneKind;
  61. @Autowired
  62. private RabbitMqProducer mqProducer;
  63. @Autowired
  64. private FYunFileServiceInterface fYunFileService;
  65. @Autowired
  66. private ICameraDetailService cameraDetailService;
  67. @Autowired
  68. private FYunFileConfig fYunFileConfig;
  69. @Autowired
  70. private ISceneProService sceneProService;
  71. @Autowired
  72. private IUserIncrementService userIncrementService;
  73. @Autowired
  74. private IFdkkLaserService fdkkLaserService;
  75. @Autowired
  76. private FdkkV4Service fdkkV4Service;
  77. @Autowired
  78. private IIncrementTypeService incrementTypeService;
  79. @Autowired
  80. private IBuildSceneDTService buildSceneDTService;
  81. @Autowired
  82. private ISceneProEditService sceneProEditService;
  83. @Override
  84. public void buildScenePre(BuildSceneCallMessage message) {
  85. boolean success = false;
  86. try {
  87. //根据相机类型,组装资源路径
  88. //下载资源到本地
  89. this.downLoadSource(message, message.getPath());
  90. if (!ObjectUtils.isEmpty(modelSceneKind)) {
  91. // 修改dataFdage文件
  92. JSONObject fdageJson = JSONObject.parseObject(FileUtils.readFile(message.getPath().concat("/capture/data.fdage")));
  93. fdageJson.put("modelType", modelSceneKind);
  94. FileUtils.writeFile(message.getPath().concat("/capture/data.fdage"), fdageJson.toJSONString());
  95. }
  96. message.getBuildContext().put("cameraType",message.getCameraType());
  97. message.setResultReceiverMqName(queueV3ModelingPost);
  98. //发送mq,就进行计算
  99. mqProducer.sendByWorkQueue(queueModelingCall, message);
  100. success = true;
  101. log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
  102. }catch (Exception e){
  103. log.error("场景计算前置处理出错", e);
  104. }finally {
  105. //如果前置处理失败,发送钉钉消息
  106. if(!success){
  107. buildSceneDTService.handBaseFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
  108. }
  109. }
  110. }
  111. @Override
  112. public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
  113. String ossPath = ConstantFilePath.OSS_PREFIX
  114. + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  115. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  116. if (!ossPath.endsWith("/")) {
  117. ossPath = ossPath.concat("/");
  118. }
  119. fYunFileService.downloadFileByCommand(path + File.separator + "capture", ossPath);
  120. }
  121. @Override
  122. public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
  123. Integer cameraType = Integer.parseInt(message.getBuildContext().get("cameraType").toString());
  124. String sceneCode = message.getBuildContext().get("sceneNum").toString();
  125. Long computeTime = message.getComputeTime();
  126. String path = message.getPath();
  127. Boolean buildSuccess = message.getBuildSuccess();
  128. JSONObject fdageData = getFdageData(path + File.separator + "capture" +File.separator+"data.fdage");
  129. Integer videoVersion = fdageData.getInteger("videoVersion");
  130. try {
  131. // 上传计算日志
  132. //如果是重复计算,没有走到计算逻辑,不需要上传日志文件
  133. log.info("开始上传计算日志");
  134. String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneCode);
  135. fYunFileService.uploadFile(path + File.separator + "console.log", buildLogPath + "console.log");
  136. log.info("计算日志上传完成");
  137. if (!buildSuccess) {
  138. log.error("建模失败,修改状态为失败状态");
  139. sceneProService.update(new LambdaUpdateWrapper<ScenePro>()
  140. .set(ScenePro::getStatus, SceneStatus.FAILD.code())
  141. .eq(ScenePro::getNum, sceneCode));
  142. // 发送钉钉消息,计算失败
  143. buildSceneDTService.handModelFail("计算失败", message.getPath(), sceneCode, message.getHostName());
  144. return;
  145. }
  146. Map<String, String> uploadFiles = getUploadFiles(sceneCode,path,cameraType,fdageData);
  147. //建模成功走以下逻辑
  148. log.info("cameraType:{}",cameraType);
  149. //计算场景消耗磁盘空间
  150. long space = this.calUseSpace(uploadFiles);
  151. //读取计算结果文件生成videosJson
  152. JSONObject videosJson = this.getVideosJson(path, videoVersion, sceneCode, cameraType);
  153. //写入数据库
  154. ScenePro scenePro = this.updateDbPlus(sceneCode, space, videosJson.toJSONString(), computeTime,fdageData.containsKey("exportMeshObj") && fdageData.getIntValue("exportMeshObj") == 1);
  155. scenePro.setPayStatus(PayStatus.PAY.code());
  156. //如果相机容量不足,需要把场景的paystatus改为容量不足状态
  157. if (cameraType != 14) {
  158. scenePro.setPayStatus(this.getPayStatus(scenePro.getCameraId(), space));
  159. sceneProService.update(
  160. new LambdaUpdateWrapper<ScenePro>()
  161. .set(ScenePro::getPayStatus, scenePro.getPayStatus())
  162. .eq(ScenePro::getId, scenePro.getId()));
  163. }
  164. //上传文件
  165. log.info("开始上传场景计算结果数据,num:{}", sceneCode);
  166. fYunFileService.uploadMulFiles(uploadFiles);
  167. Map<String,String> damFileHeaders = new HashMap<>();
  168. damFileHeaders.put("Content-Encoding","gzip");
  169. if (!fYunFileService.getFyunType().equals(FYunTypeEnum.LOCAL.code())) {
  170. // dam 文件设置请求头
  171. uploadFiles.entrySet().stream().filter(entry -> FileNameUtil.extName(entry.getKey()).equals("dam"))
  172. .filter(entry -> new File(entry.getKey()).exists())
  173. .forEach(entry -> {
  174. // gzip压缩
  175. FileUtil.writeBytes(ZipUtil.gzip(new File(entry.getKey())), entry.getKey() + ".gzip");
  176. // 重命名
  177. FileUtil.rename(new File(entry.getKey() + ".gzip"), entry.getKey(), true);
  178. fYunFileService.uploadFile(entry.getKey(), entry.getValue(), damFileHeaders);
  179. });
  180. }
  181. //生成houseTypejson并上传
  182. uploadFiles.entrySet().stream().filter(entry-> FileNameUtil.getName(entry.getKey()).equals("floorplan_cad.json"))
  183. .forEach(entry-> uploadHouseTypeJson(sceneCode,entry.getKey()));
  184. //计算成功,通知APP
  185. Integer pushChannel = fdageData.getInteger("pushChannel");
  186. String pushToken = fdageData.getString("pushToken");
  187. this.pushMsgToApp(pushChannel,pushToken, cameraType, scenePro.getSceneName(), scenePro.getWebSite());
  188. SceneProEdit sceneProEdit = sceneProEditService.getByProId(scenePro.getId());
  189. sceneProEdit.setVersion(ObjectUtils.isEmpty(sceneProEdit.getVersion()) ? 0 : sceneProEdit.getVersion() + 1);
  190. sceneProEdit.setImagesVersion(ObjectUtils.isEmpty(sceneProEdit.getImagesVersion()) ? 0 : sceneProEdit.getImagesVersion() + 1);
  191. sceneProEdit.setFloorEditVer(ObjectUtils.isEmpty(sceneProEdit.getFloorEditVer()) ? 0 : sceneProEdit.getFloorEditVer() + 1);
  192. sceneProEdit.setFloorPublishVer(ObjectUtils.isEmpty(sceneProEdit.getFloorPublishVer()) ? 0 : sceneProEdit.getFloorPublishVer() + 1);
  193. if (cameraType == 14) {
  194. //计算成功 激光转台相机 同步 请求
  195. fdkkLaserService.syncBuildResult(scenePro.getNum(), scenePro.getDataSource(),scenePro.getCreateTime());
  196. sceneProEdit.setMapVisi(0);
  197. }
  198. sceneProEditService.updateById(sceneProEdit);
  199. //写scene.json
  200. log.info("生成scene.json上传oss并设置缓存,num:{}", sceneCode);
  201. this.writeSceneJson(videosJson,scenePro,sceneProEdit);
  202. CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/") + "/capture");
  203. log.info("场景计算结果处理结束,场景码:{}", sceneCode);
  204. // 判断是否升级V4
  205. if(fdageData.containsKey("updateV4") && fdageData.getIntValue("updateV4") == 1){
  206. fdkkV4Service.upgradeToV4(sceneCode);
  207. }
  208. }catch (Exception e){
  209. e.printStackTrace();
  210. buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
  211. }
  212. }
  213. private Map<String, String> getUploadFiles(String projectNum,String path,Integer cameraType,JSONObject fdageData) throws Exception {
  214. String dataViewPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, projectNum);
  215. String imagesPath = String.format(ConstantFilePath.IMAGE_PATH_FORMAT, projectNum);
  216. String videoPath = String.format(ConstantFilePath.VIDEO_PATH_FORMAT, projectNum);
  217. String resultsPath = path + File.separator + "results" + File.separator;
  218. String uploadData = FileUtils.readFile(resultsPath + "upload.json");
  219. JSONArray array = JSONObject.parseObject(uploadData).getJSONArray("upload");
  220. JSONObject fileJson = null;
  221. String fileName = "";
  222. Map<String, String> map = new HashMap();
  223. for (int i = 0; i < array.size(); ++i) {
  224. fileJson = array.getJSONObject(i);
  225. fileName = fileJson.getString("file");
  226. String filePath = resultsPath + fileName;
  227. if (!(new File(filePath)).exists()) {
  228. throw new Exception(filePath + "文件不存在");
  229. }
  230. if ("vision2.txt".equals(fileName)) {
  231. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision2.txt", resultsPath + "vision2.modeldata");
  232. map.put(resultsPath + "vision2.modeldata", imagesPath + "vision2.modeldata");
  233. map.put(resultsPath + "vision2.txt", imagesPath + "vision2.txt");
  234. }
  235. if (fileJson.getIntValue("clazz") == 2) {
  236. map.put(filePath, imagesPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
  237. } else if (fileJson.getIntValue("clazz") == 3) {
  238. map.put(filePath, imagesPath + "pan/high/" + fileName.replace("high/", ""));
  239. } else if (fileJson.getIntValue("clazz") == 4) {
  240. map.put(filePath, imagesPath + "pan/low/" + fileName.replace("low/", ""));
  241. } else if (fileJson.getIntValue("clazz") == 5) {
  242. map.put(filePath, imagesPath + fileName);
  243. } else if (fileJson.getIntValue("clazz") == 7) {
  244. map.put(filePath, imagesPath + fileName);
  245. } else if (fileJson.getIntValue("clazz") == 10) {
  246. String mappingOssPath = String.format("scene_edit_data/%s/data/", projectNum) + fileName.replace("updown", "mapping");
  247. map.put(filePath, mappingOssPath);
  248. } else {
  249. if (fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("clazz") == 12) {
  250. map.put(filePath, videoPath + fileName.replace("videos/", ""));
  251. if (fileName.contains(".mp4")) {
  252. map.put(resultsPath + fileName.replace("mp4", "flv"), videoPath + fileName.replace("videos/", "").replace("mp4", "flv"));
  253. }
  254. }
  255. if (fileJson.getIntValue("clazz") == 16) {
  256. map.put(filePath, dataViewPath + fileName);
  257. }
  258. if (fileJson.getIntValue("clazz") == 18) {
  259. map.put(filePath, imagesPath + fileName);
  260. }
  261. }
  262. }
  263. if ((fdageData.containsKey("exportMeshObj") && fdageData.getIntValue("exportMeshObj") == 1)
  264. || (!ObjectUtils.isEmpty(cameraType) && (!cameraType.equals(14)))) {
  265. CreateObjUtil.convertTxtToDam(path + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam");
  266. CreateObjUtil.convertDamToLzma(path + File.separator + "results/");
  267. CreateObjUtil.convertTxtToDam(path + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam");
  268. map.put(path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam.lzma", imagesPath + ConstantFileName.modelUUID + "_50k.dam.lzma");
  269. map.put(path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam", imagesPath + ConstantFileName.modelUUID + "_50k.dam");
  270. }
  271. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision.txt", resultsPath + "vision.modeldata");
  272. map.put(resultsPath + "vision.txt", imagesPath + "vision.txt");
  273. map.put(resultsPath + "vision.modeldata", imagesPath + "vision.modeldata");
  274. log.info("数据转换完成:" + projectNum);
  275. FileUtil.touch("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum);
  276. map.put(resultsPath + "floorplan.json", dataViewPath + "floor.json");
  277. map.put(resultsPath + "floorplan_cad.json", dataViewPath + "floorplan_cad.json");
  278. map.put(path + File.separator + "capture/stitch_params.txt", dataViewPath + "stitch_params.txt");
  279. map.put(path + File.separator + "capture/Up.xml", dataViewPath + "Up.xml");
  280. map.put(path + File.separator + "capture/Up2.xml", dataViewPath + "Up2.xml");
  281. map.put(path + File.separator + "capture/Up.txt", dataViewPath + "Up.txt");
  282. map.put(path + File.separator + "capture/Up2.txt", dataViewPath + "Up2.txt");
  283. return map;
  284. }
  285. private JSONObject getFdageData(String dataFdagePath) {
  286. log.info("dataFdagePath 文件路径 :{}", dataFdagePath);
  287. String data = FileUtils.readFile(dataFdagePath);
  288. //获取data.fdage的内容
  289. JSONObject dataJson = new JSONObject();
  290. if(data!=null){
  291. dataJson = JSONObject.parseObject(data);
  292. }
  293. return dataJson;
  294. }
  295. private void writeSceneJson(JSONObject videosJson, ScenePro scenePro,SceneProEdit sceneProEdit) throws Exception{
  296. String num = scenePro.getNum();
  297. String dataViewPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, num);
  298. //如果云端没有scene.json文件,生成一份
  299. JSONObject sceneJson = JSONObject.parseObject(JSONObject.toJSONString(scenePro));
  300. sceneJson.put("videos",videosJson.toJSONString());
  301. sceneJson.put("version",sceneProEdit.getVersion());
  302. sceneJson.put("imagesVersion",sceneProEdit.getImagesVersion());
  303. sceneJson.put("floorEditVer",sceneProEdit.getFloorEditVer());
  304. sceneJson.put("floorPublishVer",sceneProEdit.getFloorPublishVer());
  305. String sceneJsonStr = JSON.toJSONString(sceneJson);
  306. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "scene.json", sceneJsonStr);
  307. //上传sceneJson文件
  308. fYunFileService.uploadFile(sceneJsonStr.getBytes(), dataViewPath + "scene.json");
  309. // 上传status JSON.
  310. JSONObject statusJson = new JSONObject();
  311. //临时将-2改成1,app还没完全更新
  312. statusJson.put("status", 1);
  313. statusJson.put("webSite", scenePro.getWebSite());
  314. statusJson.put("sceneNum", num);
  315. statusJson.put("thumb", scenePro.getThumb());
  316. statusJson.put("payStatus", scenePro.getPayStatus());
  317. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
  318. fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json",
  319. dataViewPath + "status.json");
  320. }
  321. private void pushMsgToApp(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
  322. log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
  323. if(Objects.isNull(pushChannel) && StrUtil.isBlank(pushToken)){
  324. return;
  325. }
  326. String title = sceneName + "计算完成";
  327. String body = "您上传的" + sceneName + "计算完成,点击查看";
  328. try{
  329. if(FYunTypeEnum.AWS.code().equals(fYunFileService.getFyunType())){
  330. PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
  331. title, body , webSite);
  332. return;
  333. }
  334. PushMessageConfig pushConfig = null;
  335. if(pushChannel == 0){
  336. if(cameraType == 10 || cameraType == 13){
  337. //ios
  338. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY_Z, PushMessageConfig.IOS_SECRET_Z);
  339. pushConfig.sendIOSUnicast(pushToken, "四维看看Minion",title, body, webSite);
  340. }else {
  341. //ios
  342. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY, PushMessageConfig.IOS_SECRET);
  343. pushConfig.sendIOSUnicast(pushToken, "四维看看Pro",title, body, webSite);
  344. }
  345. }else {
  346. if(cameraType == 10 || cameraType == 13){
  347. //ios
  348. //安卓
  349. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY_Z, PushMessageConfig.ANDROID_SECRET_Z);
  350. pushConfig.sendAndroidUnicast2(pushToken, "四维看看Minion",title, body, webSite);
  351. }else {
  352. //安卓
  353. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY, PushMessageConfig.ANDROID_SECRET);
  354. pushConfig.sendAndroidUnicast(pushToken, "四维看看Pro",title, body, webSite);
  355. }
  356. }
  357. log.info("消息推送结束!");
  358. }catch (Exception e){
  359. log.error("推送消息失败:", e);
  360. }
  361. }
  362. private JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception {
  363. //读取videos_hdr_param.json, 保存点位视频的value
  364. Map<String, Object> videoMap = new HashMap<>();
  365. String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
  366. JSONArray videoArray = null;
  367. if(StringUtils.isNotEmpty(videosHdr)){
  368. videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
  369. }
  370. if(videoArray != null){
  371. for(int i = 0, len = videoArray.size(); i < len; i++) {
  372. videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
  373. if(videoArray.getJSONObject(i).containsKey("fov")){
  374. videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
  375. }
  376. }
  377. }
  378. //获取upload中的video视频名称
  379. String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
  380. JSONObject uploadJson = null;
  381. JSONArray array = null;
  382. if(uploadData!=null) {
  383. uploadJson = JSONObject.parseObject(uploadData);
  384. array = uploadJson.getJSONArray("upload");
  385. }
  386. JSONObject fileJson = null;
  387. String fileName = "";
  388. //计算ts文件的大小,并拼接成json格式
  389. JSONArray jsonArray = new JSONArray();
  390. JSONObject videoJson = null;
  391. JSONObject videosJson = new JSONObject();
  392. long videoSize = 0L;
  393. for(int i = 0, len = array.size(); i < len; i++) {
  394. fileJson = array.getJSONObject(i);
  395. fileName = fileJson.getString("file");
  396. if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
  397. videoJson = new JSONObject();
  398. videoJson.put("id", fileName.substring(
  399. 0, fileName.lastIndexOf(".")).replace("videos/", ""));
  400. //如果ts文件存在,就计算ts大小
  401. if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
  402. videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
  403. videoJson.put("tsSize", videoSize);
  404. }
  405. if(videoMap.containsKey(videoJson.get("id"))){
  406. videoJson.put("value", videoMap.get(videoJson.get("id")));
  407. }
  408. if(videoMap.containsKey(videoJson.get("id") + "_fov")){
  409. videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
  410. }else {
  411. videoJson.put("blend_fov", 7);
  412. }
  413. jsonArray.add(videoJson);
  414. }
  415. }
  416. videosJson.put("data", jsonArray);
  417. if(Objects.nonNull(videoVersion) && videoVersion >= 4){
  418. videosJson.put("version", 3);
  419. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(ConstantFilePath.DATA_PATH_FORMAT, projectNum) + "Up.xml");
  420. if(cameraType == 13){
  421. //转台相机
  422. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  423. }
  424. }else {
  425. videosJson.put("version", 1);
  426. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(ConstantFilePath.DATA_PATH_FORMAT, projectNum) + "Up2.xml");
  427. if(cameraType == 13){
  428. //转台相机
  429. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  430. }
  431. }
  432. if(cameraType == 5 || cameraType == 6){
  433. videosJson.put("version", 1);
  434. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(ConstantFilePath.DATA_PATH_FORMAT, projectNum) + "stitch_params.txt");
  435. }
  436. return videosJson;
  437. }
  438. private Long calUseSpace(Map<String, String> uploadFile) {
  439. return uploadFile.keySet().stream().map(File::new).filter(File::exists).mapToLong(File::length).sum();
  440. }
  441. /**
  442. * <p>
  443. 双目场景更新数据库
  444. * </p>
  445. * @author dengsixing
  446. * @date 2022/3/21
  447. * @param num
  448. * @param space
  449. **/
  450. private void updateDb4Sm(String num, long space){
  451. List<ScenePro> ScenePlusList = sceneProService.list(
  452. new LambdaQueryWrapper<ScenePro>().select(ScenePro::getId).eq(ScenePro::getNum, num));
  453. if(CollUtil.isEmpty(ScenePlusList)){
  454. return ;
  455. }
  456. List<Long> sceneIds = ScenePlusList.stream().map(ScenePro::getId).collect(Collectors.toList());
  457. //更新场景创建时间
  458. sceneProService.update(new LambdaUpdateWrapper<ScenePro>().in(ScenePro::getId, sceneIds)
  459. .set(ScenePro::getStatus, SceneStatus.NO_DISPLAY.code())
  460. .set(ScenePro::getSpace,space)
  461. .set(ScenePro::getCreateTime,new Date())
  462. );
  463. }
  464. private ScenePro updateDbPlus(String num, Long space, String videosJson, Long computeTime,boolean isObj){
  465. sceneProService.update(new LambdaUpdateWrapper<ScenePro>()
  466. .eq(ScenePro::getNum, num)
  467. .set(ScenePro::getStatus, SceneStatus.NO_DISPLAY.code())
  468. .set(ScenePro::getUpdateTime, new Date())
  469. .set(ScenePro::getCreateTime, new Date())
  470. .set(ScenePro::getSpace, space)
  471. .set(ScenePro::getComputeTime, computeTime)
  472. .set(ScenePro::getVideos, videosJson)
  473. .set(ScenePro::getIsObj, isObj ? 1 : 0)
  474. .set(ScenePro::getPayStatus, PayStatus.PAY.code()));
  475. return sceneProService.getByNum(num);
  476. }
  477. private int getPayStatus(Long cameraId, Long space) throws Exception{
  478. //更新相机使用用量
  479. CameraDetail cameraDetail = cameraDetailService.updateCameraDetailByCameraIdAndSpace(cameraId, space);
  480. Long totalSpace = cameraDetail.getTotalSpace();
  481. UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
  482. if(!ObjectUtils.isEmpty(userIncrement) && userIncrement.getIsExpired().equals(ExpiredStatus.NOT_EXPIRED.code())){
  483. IncrementType type = incrementTypeService.getById(userIncrement.getIncrementTypeId());
  484. if (ObjectUtils.isEmpty(type) || type.getType().equals("cn")) {
  485. return PayStatus.PAY.code();
  486. } else if (type.getType().equals("eur")) {
  487. totalSpace = type.getCameraCapacity() * 1024 * 1024L;
  488. }
  489. }
  490. return totalSpace.compareTo(cameraDetail.getUsedSpace()) == -1 ? PayStatus.NO_CAPACITY.code() : PayStatus.PAY.code();
  491. }
  492. public void uploadHouseTypeJson(String num, String floorPlanCardFilePath) {
  493. if (!new File(floorPlanCardFilePath).exists()) {
  494. log.error("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  495. return;
  496. }
  497. JSONObject json = CreateHouseJsonUtil.createHouseTypeJsonByCad(floorPlanCardFilePath);
  498. String hourseTypeJsonPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, num) + "houseType.json";
  499. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  500. hourseTypeJsonPath = String.format(UploadFilePath.DATA_EDIT_PATH, num) + "houseType.json";
  501. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  502. }
  503. }