BuildV3SceneServiceImpl.java 31 KB

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