BuildV3SceneServiceImpl.java 31 KB

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