BuildV3SceneServiceImpl.java 29 KB

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