BuildSceneServiceImpl.java 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. package com.fdkankan.contro.mq.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  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 cn.hutool.extra.qrcode.QrCodeUtil;
  9. import cn.hutool.extra.qrcode.QrConfig;
  10. import cn.hutool.http.HttpUtil;
  11. import com.alibaba.fastjson.JSON;
  12. import com.alibaba.fastjson.JSONArray;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  15. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  16. import com.fdkankan.common.constant.*;
  17. import com.fdkankan.common.util.FileUtils;
  18. import com.fdkankan.contro.bean.SceneJsonBean;
  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.vo.SceneEditControlsVO;
  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 com.fdkankan.redis.constant.RedisKey;
  38. import com.fdkankan.redis.util.RedisUtil;
  39. import lombok.extern.slf4j.Slf4j;
  40. import org.apache.commons.lang3.ObjectUtils;
  41. import org.apache.commons.lang3.StringUtils;
  42. import org.springframework.beans.factory.annotation.Autowired;
  43. import org.springframework.beans.factory.annotation.Value;
  44. import org.springframework.stereotype.Service;
  45. import java.io.File;
  46. import java.io.IOException;
  47. import java.util.*;
  48. import java.util.Map.Entry;
  49. import java.util.stream.Collectors;
  50. /**
  51. * <p>
  52. * TODO
  53. * </p>
  54. *
  55. * @author dengsixing
  56. * @since 2022/4/20
  57. **/
  58. @Slf4j
  59. @Service
  60. public class BuildSceneServiceImpl implements IBuildSceneService {
  61. @Value("${queue.modeling.modeling-call}")
  62. private String queueModelingCall;
  63. @Value("${queue.modeling.single.modeling-call}")
  64. private String singleModelingCall;
  65. @Value("${model.type:#{null}}")
  66. private String modelType;
  67. @Autowired
  68. private RabbitMqProducer mqProducer;
  69. @Autowired
  70. private FYunFileServiceInterface fYunFileService;
  71. @Autowired
  72. private ICameraDetailService cameraDetailService;
  73. @Autowired
  74. private ISceneEditInfoService sceneEditInfoService;
  75. @Autowired
  76. private ISceneEditControlsService sceneEditControlsService;
  77. @Autowired
  78. private FYunFileConfig fYunFileConfig;
  79. @Autowired
  80. private RedisUtil redisUtil;
  81. @Autowired
  82. private IScenePlusService scenePlusService;
  83. @Autowired
  84. private IScenePlusExtService scenePlusExtService;
  85. @Autowired
  86. private ISceneEditInfoExtService sceneEditInfoExtService;
  87. @Autowired
  88. private IUserIncrementService userIncrementService;
  89. @Autowired
  90. private IFdkkLaserService fdkkLaserService;
  91. @Autowired
  92. private IBuildSceneDTService buildSceneDTService;
  93. @Autowired
  94. private IIncrementTypeService incrementTypeService;
  95. @Autowired
  96. private ICompanyService companyService;
  97. @Override
  98. public void buildScenePre(BuildSceneCallMessage message) {
  99. boolean success = false;
  100. try {
  101. //根据相机类型,组装资源路径
  102. //下载资源到本地
  103. this.downLoadSource(message, message.getPath());
  104. if (!ObjectUtils.isEmpty(modelType)) {
  105. // 修改dataFdage文件
  106. JSONObject fdageJson = JSONObject.parseObject(FileUtils.readFile(message.getPath().concat("/capture/data.fdage")));
  107. fdageJson.put("modelType", modelType);
  108. FileUtils.writeFile(message.getPath().concat("/capture/data.fdage"), fdageJson.toJSONString());
  109. }
  110. message.getBuildContext().put("cameraType",message.getCameraType());
  111. // 判断企业是否配置了弹性伸缩
  112. if (message.getFlexibility() == 0) {
  113. //发送mq,就进行计算
  114. mqProducer.sendByWorkQueue(queueModelingCall, message);
  115. } else {
  116. //发送mq,就进行计算
  117. mqProducer.sendByWorkQueue(singleModelingCall, message);
  118. }
  119. success = true;
  120. log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
  121. }catch (Exception e){
  122. log.error("场景计算前置处理出错", e);
  123. }finally {
  124. //如果前置处理失败,发送钉钉消息
  125. if(!success){
  126. buildSceneDTService.handBaseFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
  127. }
  128. }
  129. }
  130. @Override
  131. public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
  132. String ossPath = ConstantFilePath.OSS_PREFIX
  133. + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  134. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  135. if (!ossPath.endsWith("/")) {
  136. ossPath = ossPath.concat("/");
  137. }
  138. fYunFileService.downloadFileByCommand(path + File.separator + "capture", ossPath);
  139. }
  140. @Override
  141. public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
  142. String sceneCode = message.getBuildContext().get("sceneNum").toString();
  143. String path = message.getPath();
  144. try {
  145. // 上传计算日志
  146. //如果是重复计算,没有走到计算逻辑,不需要上传日志文件
  147. log.info("开始上传计算日志");
  148. String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneCode);
  149. fYunFileService.uploadFile(path + File.separator + "console.log", buildLogPath + "console.log");
  150. log.info("计算日志上传完成");
  151. if (!message.getBuildSuccess()) {
  152. log.error("建模失败,修改状态为失败状态");
  153. scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
  154. .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
  155. .eq(ScenePlus::getNum, sceneCode));
  156. // 发送钉钉消息,计算失败
  157. buildSceneDTService.handModelFail("计算失败", message.getPath(), sceneCode, message.getHostName());
  158. return;
  159. }
  160. JSONObject fdageData = getFdageData(path + File.separator + "capture" +File.separator+"data.fdage");
  161. Integer cameraType = Integer.parseInt(message.getBuildContext().get("cameraType").toString());
  162. Map<String, String> uploadFiles = getUploadFiles(path,cameraType,fdageData);
  163. //计算场景消耗磁盘空间
  164. long space = this.calUseSpace(uploadFiles);
  165. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
  166. scenePlus.setPayStatus(PayStatus.PAY.code());
  167. //如果相机容量不足,需要把场景的paystatus改为容量不足状态
  168. if (cameraType != 14) {
  169. scenePlus.setPayStatus(this.getPayStatus(scenePlus.getCameraId(), space));
  170. }
  171. scenePlus.setUpdateTime(new Date());
  172. scenePlus.setSceneStatus(SceneStatus.NO_DISPLAY.code());
  173. scenePlusService.updateById(scenePlus);
  174. Integer videoVersion = fdageData.getInteger("videoVersion");
  175. //读取计算结果文件生成videosJson
  176. JSONObject videosJson = this.getVideosJson(path, videoVersion, sceneCode, cameraType);
  177. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  178. boolean isObj = fdageData.containsKey("exportMeshObj") && fdageData.getIntValue("exportMeshObj") == 1;
  179. //写入数据库
  180. this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), message.getComputeTime(),isObj,scenePlusExt);
  181. Object[] editInfoArr = this.updateEditInfo(scenePlus);
  182. SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
  183. SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
  184. SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
  185. //上传全景图俯视图
  186. this.uploadFloorCad(path, sceneCode, uploadFiles);
  187. //上传文件
  188. log.info("开始上传场景计算结果数据,num:{}", sceneCode);
  189. fYunFileService.uploadMulFiles(uploadFiles);
  190. Map<String,String> damFileHeaders = new HashMap<>();
  191. damFileHeaders.put("Content-Encoding","gzip");
  192. if (!fYunFileService.getFyunType().equals(FYunTypeEnum.LOCAL.code())) {
  193. // dam 文件设置请求头
  194. uploadFiles.entrySet().stream().filter(entry -> FileNameUtil.extName(entry.getKey()).equals("dam"))
  195. .filter(entry -> new File(entry.getKey()).exists())
  196. .forEach(entry -> {
  197. // gzip压缩
  198. FileUtil.writeBytes(ZipUtil.gzip(new File(entry.getKey())), entry.getKey() + ".gzip");
  199. // 重命名
  200. FileUtil.rename(new File(entry.getKey() + ".gzip"), entry.getKey(), true);
  201. fYunFileService.uploadFile(entry.getKey(), entry.getValue(), damFileHeaders);
  202. });
  203. }
  204. //拷贝部分文件到编辑目录,用于用户编辑
  205. this.copyToEditDir(sceneCode);
  206. //生成houseTypejson并上传
  207. uploadFiles.entrySet().stream().filter(entry-> FileNameUtil.getName(entry.getKey()).equals("floorplan_cad.json"))
  208. .forEach(entry-> uploadHouseTypeJson(sceneCode,entry.getKey()));
  209. //写scene.json
  210. log.info("生成scene.json上传oss并设置缓存,num:{}", sceneCode);
  211. CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
  212. Company company = !ObjectUtils.isEmpty(cameraDetail.getCompanyId()) ? companyService.getById(cameraDetail.getCompanyId()) : null;
  213. this.writeSceneJson(sceneCode, videosJson,sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus,scenePlusExt,company);
  214. createQrCode(sceneCode, scenePlusExt, ObjectUtils.isEmpty(company) ? null : company.getQrLogo());
  215. //计算成功,通知APP
  216. Integer pushChannel = fdageData.getInteger("pushChannel");
  217. String pushToken = fdageData.getString("pushToken");
  218. this.pushMsgToApp(pushChannel,pushToken, cameraType, scenePlus.getTitle(), scenePlusExt.getWebSite());
  219. if (cameraType == 14) {
  220. // 如果是激光场景,上传全景文件到V3路径,激光系统上线后,可不用上传
  221. String imagePath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode);
  222. String V3ImagePath = String.format(ConstantFilePath.IMAGE_PATH_FORMAT, sceneCode);
  223. uploadFiles.entrySet().stream().filter(entry -> entry.getValue().contains(imagePath)).forEach(entry -> {
  224. fYunFileService.uploadFile(entry.getKey(), entry.getValue().replace(imagePath, V3ImagePath));
  225. });
  226. //计算成功 激光转台相机 同步 请求
  227. fdkkLaserService.syncBuildResult(scenePlus.getNum(), scenePlusExt.getDataSource(),scenePlus.getCreateTime());
  228. }
  229. CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/") + "/capture");
  230. log.info("场景计算结果处理结束,场景码:{}", sceneCode);
  231. }catch (Exception e){
  232. e.printStackTrace();
  233. buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
  234. }
  235. }
  236. private Map<String, String> getUploadFiles(String path,Integer cameraType,JSONObject fdageData) throws Exception {
  237. ScenePlus scenePlus = scenePlusService.getByFileId(path);
  238. if (ObjectUtils.isEmpty(scenePlus)) {
  239. throw new Exception("未找到场景信息:" + path);
  240. }
  241. String projectNum = scenePlus.getNum();
  242. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, projectNum);
  243. String imagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, projectNum);
  244. String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, projectNum);
  245. String resultsPath = path + File.separator + "results" + File.separator;
  246. String uploadJsonPath = resultsPath + "upload.json";
  247. String uploadData = FileUtils.readFile(uploadJsonPath);
  248. log.info("upload.json 文件路径:{}, 内容:{}", uploadJsonPath, uploadData);
  249. JSONArray array = JSONObject.parseObject(uploadData).getJSONArray("upload");
  250. JSONObject fileJson = null;
  251. String fileName = "";
  252. Map<String, String> map = new HashMap();
  253. for (int i = 0; i < array.size(); ++i) {
  254. fileJson = array.getJSONObject(i);
  255. fileName = fileJson.getString("file");
  256. String filePath = resultsPath + fileName;
  257. if (!(new File(filePath)).exists()) {
  258. throw new Exception(filePath + "文件不存在");
  259. }
  260. if ("vision2.txt".equals(fileName)) {
  261. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision2.txt", resultsPath + "vision2.modeldata");
  262. map.put(resultsPath + "vision2.modeldata", imagesPath + "vision2.modeldata");
  263. map.put(resultsPath + "vision2.txt", imagesPath + "vision2.txt");
  264. }
  265. if (fileJson.getIntValue("clazz") == 2) {
  266. map.put(filePath, imagesPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
  267. } else if (fileJson.getIntValue("clazz") == 3) {
  268. map.put(filePath, imagesPath + "pan/high/" + fileName.replace("high/", ""));
  269. } else if (fileJson.getIntValue("clazz") == 4) {
  270. map.put(filePath, imagesPath + "pan/low/" + fileName.replace("low/", ""));
  271. } else if (fileJson.getIntValue("clazz") == 5) {
  272. map.put(filePath, imagesPath + fileName);
  273. } else if (fileJson.getIntValue("clazz") == 7) {
  274. map.put(filePath, imagesPath + fileName);
  275. } else if (fileJson.getIntValue("clazz") == 10) {
  276. String updown = FileUtils.readFile(filePath);
  277. JSONObject updownJson = JSONObject.parseObject(updown);
  278. String mappingOssPath = String.format("scene_edit_data/%s/data/", projectNum) + fileName.replace("updown", "mapping");
  279. map.put(filePath, mappingOssPath);
  280. } else {
  281. if (fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("clazz") == 12) {
  282. map.put(filePath, videoPath + fileName.replace("videos/", ""));
  283. if (fileName.contains(".mp4")) {
  284. map.put(resultsPath + fileName.replace("mp4", "flv"), videoPath + fileName.replace("videos/", "").replace("mp4", "flv"));
  285. }
  286. }
  287. if (fileJson.getIntValue("clazz") == 16) {
  288. map.put(filePath, dataViewPath + fileName);
  289. }
  290. if (fileJson.getIntValue("clazz") == 18) {
  291. map.put(filePath, imagesPath + fileName);
  292. }
  293. }
  294. }
  295. if ((fdageData.containsKey("exportMeshObj") && fdageData.getIntValue("exportMeshObj") == 1)
  296. || (!ObjectUtils.isEmpty(cameraType) && (!cameraType.equals(14)))) {
  297. CreateObjUtil.convertTxtToDam(path + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam");
  298. CreateObjUtil.convertDamToLzma(path + File.separator + "results/");
  299. CreateObjUtil.convertTxtToDam(path + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam");
  300. map.put(path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam.lzma", imagesPath + ConstantFileName.modelUUID + "_50k.dam.lzma");
  301. map.put(path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam", imagesPath + ConstantFileName.modelUUID + "_50k.dam");
  302. }
  303. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision.txt", resultsPath + "vision.modeldata");
  304. map.put(resultsPath + "vision.txt", imagesPath + "vision.txt");
  305. map.put(resultsPath + "vision.modeldata", imagesPath + "vision.modeldata");
  306. log.info("数据转换完成:" + projectNum);
  307. FileUtil.touch("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum);
  308. map.put(resultsPath + "floorplan.json", dataViewPath + "floor.json");
  309. map.put(resultsPath + "floorplan_cad.json", dataViewPath + "floorplan_cad.json");
  310. map.put(path + File.separator + "capture/stitch_params.txt", dataViewPath + "stitch_params.txt");
  311. map.put(path + File.separator + "capture/Up.xml", dataViewPath + "Up.xml");
  312. map.put(path + File.separator + "capture/Up2.xml", dataViewPath + "Up2.xml");
  313. map.put(path + File.separator + "capture/Up.txt", dataViewPath + "Up.txt");
  314. map.put(path + File.separator + "capture/Up2.txt", dataViewPath + "Up2.txt");
  315. return map;
  316. }
  317. private JSONObject getFdageData(String dataFdagePath) {
  318. log.info("dataFdagePath 文件路径 :{}", dataFdagePath);
  319. String data = FileUtils.readFile(dataFdagePath);
  320. //获取data.fdage的内容
  321. JSONObject dataJson = new JSONObject();
  322. if(data!=null){
  323. dataJson = JSONObject.parseObject(data);
  324. }
  325. return dataJson;
  326. }
  327. private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles){
  328. //户型图上传
  329. String userEditPath = UploadFilePath.USER_EDIT_PATH + "floor-cad-%s.%s";
  330. String userViewPath = UploadFilePath.USER_VIEW_PATH + "floor-cad-%s.%s";
  331. String floorCadPath = path + "/results/floorplan_cad";
  332. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  333. if(CollUtil.isNotEmpty(floorCadList)){
  334. floorCadList.stream().forEach(str->{
  335. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  336. String[] arr = substring.split("floor");
  337. String[] arr2 = arr[1].split("\\.");
  338. uploadFiles.put(str, String.format(userEditPath, num, arr2[0], arr2[1]));
  339. uploadFiles.put(str, String.format(userViewPath, num, arr2[0], arr2[1]));
  340. });
  341. }
  342. }
  343. private void writeSceneJson(String num, JSONObject videosJson, SceneEditInfo sceneEditInfo, SceneEditInfoExt sceneEditInfoExt,
  344. SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt,Company company){
  345. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  346. SceneJsonBean sceneJson = new SceneJsonBean();
  347. BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
  348. BeanUtil.copyProperties(sceneEditInfo, sceneJson);
  349. SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
  350. sceneJson.setControls(sceneEditControlsVO);
  351. sceneJson.setNum(num);
  352. sceneJson.setCreateTime(scenePlus.getCreateTime());
  353. sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
  354. sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
  355. sceneJson.setVideos(JSON.toJSONString(videosJson));
  356. sceneJson.setPayStatus(scenePlus.getPayStatus());
  357. if(!ObjectUtils.isEmpty(company)){
  358. String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
  359. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  360. String localLogoPath = null;
  361. if (StrUtil.isNotEmpty(company.getTopLogo())) {
  362. localLogoPath = ConstantFilePath.AGENT_PATH + company.getTopLogo().substring(company.getTopLogo().lastIndexOf("//") + 1);
  363. HttpUtil.downloadFile(company.getTopLogo(), localLogoPath);
  364. fYunFileService.uploadFile(localLogoPath, userViewPath + "loadingLogo-user.png");
  365. fYunFileService.uploadFile(localLogoPath, userEditPath + "loadingLogo-user.png");
  366. sceneJson.setLoadingLogo("user");
  367. sceneJson.setLoadingLogoFile("loadingLogo-user.png");
  368. sceneEditInfo.setLoadingLogo("user");
  369. sceneEditInfo.setLoadingLogoFile("loadingLogo-user.png");
  370. }
  371. if (StrUtil.isNotEmpty(company.getFloorLogo())) {
  372. localLogoPath = ConstantFilePath.AGENT_PATH + company.getFloorLogo().substring(company.getFloorLogo().lastIndexOf("//") + 1);
  373. HttpUtil.downloadFile(company.getFloorLogo(), localLogoPath);
  374. fYunFileService.uploadFile(localLogoPath, userViewPath + "floorLogo-user.png");
  375. fYunFileService.uploadFile(localLogoPath, userEditPath + "floorLogo-user.png");
  376. sceneJson.setFloorLogo("user");
  377. sceneJson.setFloorLogoFile("floorLogo-user.png");
  378. sceneEditInfo.setFloorLogo("user");
  379. sceneEditInfo.setFloorLogoFile("floorLogo-user.png");
  380. }
  381. if(!ObjectUtils.isEmpty(localLogoPath)){
  382. sceneEditInfoService.updateById(sceneEditInfo);
  383. FileUtils.deleteFile(localLogoPath);
  384. }
  385. }
  386. String sceneJsonStr = JSON.toJSONString(sceneJson);
  387. //上传sceneJson文件
  388. fYunFileService.uploadFile(sceneJsonStr.getBytes(), dataViewPath + "scene.json");
  389. //scenejson写入缓存
  390. redisUtil.set(String.format(RedisKey.SCENE_JSON, num), sceneJsonStr);
  391. // 上传status JSON.
  392. JSONObject statusJson = new JSONObject();
  393. //临时将-2改成1,app还没完全更新
  394. statusJson.put("status", 1);
  395. statusJson.put("webSite", scenePlusExt.getWebSite());
  396. statusJson.put("sceneNum", num);
  397. statusJson.put("thumb", scenePlusExt.getThumb());
  398. statusJson.put("payStatus", 1);
  399. statusJson.put("sceneScheme", scenePlusExt.getSceneScheme());
  400. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
  401. fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json",
  402. dataViewPath + "status.json");
  403. }
  404. private void createQrCode(String num, ScenePlusExt scenePlusExt, String qrLogo) {
  405. String localLogoPath = null;
  406. if (!ObjectUtils.isEmpty(qrLogo)) {
  407. try {
  408. localLogoPath = ConstantFilePath.AGENT_PATH + qrLogo.substring(qrLogo.lastIndexOf("//") + 1);
  409. HttpUtil.downloadFile(qrLogo, localLogoPath);
  410. } catch (Exception e) {
  411. log.error("公司logo下载失败:{}", qrLogo);
  412. localLogoPath = null;
  413. }
  414. }
  415. //生成二维码
  416. String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png";
  417. String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png";
  418. QrConfig qrConfig = QrConfig.create();
  419. if(!ObjectUtils.isEmpty(localLogoPath)){
  420. qrConfig.setImg(localLogoPath);
  421. }
  422. QrCodeUtil.generate(scenePlusExt.getWebSite(), qrConfig, FileUtil.file(outPathZh));
  423. QrCodeUtil.generate(scenePlusExt.getWebSite() + "&lang=en", qrConfig, FileUtil.file(outPathEn));
  424. //上传二维码
  425. fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
  426. fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
  427. if(!ObjectUtils.isEmpty(localLogoPath)){
  428. FileUtils.deleteFile(localLogoPath);
  429. }
  430. }
  431. private void pushMsgToApp(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
  432. log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
  433. if(Objects.isNull(pushChannel) && StrUtil.isBlank(pushToken)){
  434. return;
  435. }
  436. String title = sceneName + "计算完成";
  437. String body = "您上传的" + sceneName + "计算完成,点击查看";
  438. try{
  439. if(FYunTypeEnum.AWS.code().equals(fYunFileService.getFyunType())){
  440. PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
  441. title, body , webSite);
  442. return;
  443. }
  444. PushMessageConfig pushConfig = null;
  445. if(pushChannel == 0){
  446. if(cameraType == 10 || cameraType == 13){
  447. //ios
  448. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY_Z, PushMessageConfig.IOS_SECRET_Z);
  449. pushConfig.sendIOSUnicast(pushToken, "四维看看Minion",title, body, webSite);
  450. }else {
  451. //ios
  452. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY, PushMessageConfig.IOS_SECRET);
  453. pushConfig.sendIOSUnicast(pushToken, "四维看看Pro",title, body, webSite);
  454. }
  455. }else {
  456. if(cameraType == 10 || cameraType == 13){
  457. //ios
  458. //安卓
  459. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY_Z, PushMessageConfig.ANDROID_SECRET_Z);
  460. pushConfig.sendAndroidUnicast2(pushToken, "四维看看Minion",title, body, webSite);
  461. }else {
  462. //安卓
  463. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY, PushMessageConfig.ANDROID_SECRET);
  464. pushConfig.sendAndroidUnicast(pushToken, "四维看看Pro",title, body, webSite);
  465. }
  466. }
  467. log.info("消息推送结束!");
  468. }catch (Exception e){
  469. log.error("推送消息失败:", e);
  470. }
  471. }
  472. private void copyToEditDir(String num) throws IOException {
  473. String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  474. String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  475. String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
  476. String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  477. Map<String, String> map = new HashMap<>();
  478. map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
  479. map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
  480. map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
  481. for (Entry<String, String> entry : map.entrySet()) {
  482. fYunFileService.copyFileInBucket(entry.getValue(), entry.getKey());
  483. }
  484. }
  485. private JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception {
  486. //读取videos_hdr_param.json, 保存点位视频的value
  487. Map<String, Object> videoMap = new HashMap<>();
  488. String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
  489. JSONArray videoArray = null;
  490. if(StringUtils.isNotEmpty(videosHdr)){
  491. videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
  492. }
  493. if(videoArray != null){
  494. for(int i = 0, len = videoArray.size(); i < len; i++) {
  495. videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
  496. if(videoArray.getJSONObject(i).containsKey("fov")){
  497. videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
  498. }
  499. }
  500. }
  501. //获取upload中的video视频名称
  502. String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
  503. JSONObject uploadJson = null;
  504. JSONArray array = null;
  505. if(uploadData!=null) {
  506. uploadJson = JSONObject.parseObject(uploadData);
  507. array = uploadJson.getJSONArray("upload");
  508. }
  509. JSONObject fileJson = null;
  510. String fileName = "";
  511. //计算ts文件的大小,并拼接成json格式
  512. JSONArray jsonArray = new JSONArray();
  513. JSONObject videoJson = null;
  514. JSONObject videosJson = new JSONObject();
  515. long videoSize = 0L;
  516. for(int i = 0, len = array.size(); i < len; i++) {
  517. fileJson = array.getJSONObject(i);
  518. fileName = fileJson.getString("file");
  519. if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
  520. videoJson = new JSONObject();
  521. videoJson.put("id", fileName.substring(
  522. 0, fileName.lastIndexOf(".")).replace("videos/", ""));
  523. //如果ts文件存在,就计算ts大小
  524. if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
  525. videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
  526. videoJson.put("tsSize", videoSize);
  527. }
  528. if(videoMap.containsKey(videoJson.get("id"))){
  529. videoJson.put("value", videoMap.get(videoJson.get("id")));
  530. }
  531. if(videoMap.containsKey(videoJson.get("id") + "_fov")){
  532. videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
  533. }else {
  534. videoJson.put("blend_fov", 7);
  535. }
  536. jsonArray.add(videoJson);
  537. }
  538. }
  539. videosJson.put("data", jsonArray);
  540. if(Objects.nonNull(videoVersion) && videoVersion >= 4){
  541. videosJson.put("version", 3);
  542. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up.xml");
  543. if(cameraType == 13){
  544. //转台相机
  545. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  546. }
  547. }else {
  548. videosJson.put("version", 1);
  549. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up2.xml");
  550. if(cameraType == 13){
  551. //转台相机
  552. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  553. }
  554. }
  555. if(cameraType == 5 || cameraType == 6){
  556. videosJson.put("version", 1);
  557. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "stitch_params.txt");
  558. }
  559. return videosJson;
  560. }
  561. private Long calUseSpace(Map<String, String> uploadFile) {
  562. return uploadFile.keySet().stream().map(File::new).filter(File::exists).mapToLong(File::length).sum();
  563. }
  564. private void sealScene(Long scenePlusId){
  565. scenePlusService.update(
  566. new LambdaUpdateWrapper<ScenePlus>()
  567. .set(ScenePlus::getPayStatus, PayStatus.NO_CAPACITY.code())
  568. .eq(ScenePlus::getId, scenePlusId));
  569. }
  570. /**
  571. * <p>
  572. 双目场景更新数据库
  573. * </p>
  574. * @author dengsixing
  575. * @date 2022/3/21
  576. * @param num
  577. * @param space
  578. **/
  579. private void updateDb4Sm(String num, long space){
  580. List<ScenePlus> ScenePlusList = scenePlusService.list(
  581. new LambdaQueryWrapper<ScenePlus>().select(ScenePlus::getId).eq(ScenePlus::getNum, num));
  582. if(CollUtil.isEmpty(ScenePlusList)){
  583. return ;
  584. }
  585. List<Long> sceneIds = ScenePlusList.stream().map(ScenePlus::getId).collect(Collectors.toList());
  586. //更新场景创建时间
  587. scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>().in(ScenePlus::getId, sceneIds)
  588. .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code()));
  589. //更新使用容量
  590. scenePlusExtService.update(new LambdaUpdateWrapper<ScenePlusExt>().in(ScenePlusExt::getPlusId, sceneIds)
  591. .set(ScenePlusExt::getSpace, space)
  592. .set(ScenePlusExt::getAlgorithmTime, Calendar.getInstance().getTime()));
  593. }
  594. private void updateDbPlus(int sceneSource,Long space,String videosJson, Long computeTime,boolean isObj,ScenePlusExt scenePlusExt){
  595. scenePlusExt.setSpace(space);
  596. scenePlusExt.setComputeTime(computeTime.toString());
  597. scenePlusExt.setAlgorithmTime(new Date());
  598. scenePlusExt.setVideos(videosJson);
  599. scenePlusExt.setIsObj(isObj ? 1 : 0);
  600. if(ModelTypeEnums.TILE_CODE.equals(modelType)){
  601. scenePlusExt.setSceneScheme(3);
  602. }
  603. switch (SceneSource.get(sceneSource)){
  604. case BM:
  605. scenePlusExt.setSceneResolution(SceneResolution.two_K.code());
  606. scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
  607. break;
  608. case SM:
  609. scenePlusExt.setSceneResolution(SceneResolution.one_k.code());
  610. scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
  611. break;
  612. case ZT:
  613. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  614. scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
  615. break;
  616. case JG:
  617. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  618. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  619. break;
  620. }
  621. String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
  622. scenePlusExt.setSceneKind(sceneKind);
  623. scenePlusExtService.updateById(scenePlusExt);
  624. }
  625. private int getPayStatus(Long cameraId, Long space){
  626. //更新相机使用用量
  627. CameraDetail cameraDetail = cameraDetailService.updateCameraDetailByCameraIdAndSpace(cameraId, space);
  628. Long totalSpace = cameraDetail.getTotalSpace();
  629. UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
  630. if(!ObjectUtils.isEmpty(userIncrement) && userIncrement.getIsExpired().equals(ExpiredStatus.NOT_EXPIRED.code())){
  631. IncrementType type = incrementTypeService.getById(userIncrement.getIncrementTypeId());
  632. if (ObjectUtils.isEmpty(type) || type.getType().equals("cn")) {
  633. return PayStatus.PAY.code();
  634. } else if (type.getType().equals("eur")) {
  635. totalSpace = type.getCameraCapacity() * 1024 * 1024L;
  636. }
  637. }
  638. return totalSpace.compareTo(cameraDetail.getUsedSpace()) == -1 ? PayStatus.NO_CAPACITY.code() : PayStatus.PAY.code();
  639. }
  640. private Object[] updateEditInfo(ScenePlus scenePlus){
  641. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  642. SceneEditControls sceneEditControls = null;
  643. SceneEditInfoExt sceneEditInfoExt = null;
  644. if(sceneEditInfo == null){
  645. sceneEditInfo = new SceneEditInfo();
  646. sceneEditInfo.setScenePlusId(scenePlus.getId());
  647. sceneEditInfo.setDescription(scenePlus.getDescription());
  648. sceneEditInfo.setTitle(scenePlus.getTitle());
  649. sceneEditInfoService.save(sceneEditInfo);
  650. }else{
  651. sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  652. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  653. sceneEditInfo.setVersion(sceneEditInfo.getVersion() + 1);
  654. sceneEditInfoService.updateById(sceneEditInfo);
  655. }
  656. if(sceneEditControls == null){
  657. sceneEditControls = new SceneEditControls();
  658. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  659. sceneEditControlsService.save(sceneEditControls);
  660. }
  661. if(sceneEditInfoExt == null){
  662. sceneEditInfoExt = new SceneEditInfoExt();
  663. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  664. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  665. sceneEditInfoExtService.save(sceneEditInfoExt);
  666. }
  667. return new Object[]{sceneEditInfo, sceneEditInfoExt, sceneEditControls};
  668. }
  669. public void uploadHouseTypeJson(String num, String floorPlanCardFilePath) {
  670. if (!new File(floorPlanCardFilePath).exists()) {
  671. log.error("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  672. return;
  673. }
  674. JSONObject json = CreateHouseJsonUtil.createHouseTypeJsonByCad(floorPlanCardFilePath);
  675. String hourseTypeJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "houseType.json";
  676. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  677. hourseTypeJsonPath = String.format(UploadFilePath.DATA_EDIT_PATH, num) + "houseType.json";
  678. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  679. }
  680. }