CommonServiceImpl.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. package com.fdkankan.contro.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.http.HttpUtil;
  6. import com.alibaba.fastjson.JSON;
  7. import com.alibaba.fastjson.JSONArray;
  8. import com.alibaba.fastjson.JSONObject;
  9. import com.fdkankan.common.util.FileUtils;
  10. import cn.hutool.core.util.StrUtil;
  11. import com.alibaba.fastjson.JSONObject;
  12. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  13. import com.fdkankan.common.constant.CommonStatus;
  14. import com.fdkankan.common.constant.PayStatus;
  15. import com.fdkankan.common.constant.SceneStatus;
  16. import com.fdkankan.common.constant.SpaceType;
  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.factory.UserEditData.UserEditDataHandler;
  21. import com.fdkankan.contro.factory.UserEditData.UserEditDataHandlerFactory;
  22. import com.fdkankan.contro.service.ICommonService;
  23. import com.fdkankan.contro.service.*;
  24. import com.fdkankan.contro.vo.SceneEditControlsVO;
  25. import com.fdkankan.contro.vo.ScenePlusVO;
  26. import com.fdkankan.fyun.config.FYunFileConfig;
  27. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  28. import com.fdkankan.model.constants.ConstantFilePath;
  29. import com.fdkankan.model.constants.UploadFilePath;
  30. import com.fdkankan.model.utils.FloorPlanUserUtil;
  31. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  32. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  33. import com.fdkankan.redis.constant.RedisKey;
  34. import com.fdkankan.redis.util.RedisUtil;
  35. import com.fdkankan.sms.SendMailAcceUtils;
  36. import lombok.extern.slf4j.Slf4j;
  37. import org.apache.commons.lang3.ObjectUtils;
  38. import org.apache.commons.lang3.StringUtils;
  39. import org.springframework.beans.factory.annotation.Autowired;
  40. import org.springframework.beans.factory.annotation.Value;
  41. import org.springframework.cloud.context.config.annotation.RefreshScope;
  42. import org.springframework.stereotype.Service;
  43. import javax.annotation.Resource;
  44. import java.io.File;
  45. import java.io.IOException;
  46. import java.util.HashMap;
  47. import java.util.List;
  48. import java.util.Map;
  49. import java.util.Objects;
  50. import java.util.Set;
  51. import java.util.Objects;
  52. import java.util.*;
  53. import java.util.stream.Collectors;
  54. @Slf4j
  55. @Service
  56. @RefreshScope
  57. public class CommonServiceImpl implements ICommonService {
  58. @Value("${main.url}")
  59. private String mainUrl;
  60. @Value("${env:gn}")
  61. private String env;
  62. @Value("${helpLink.zh-cn:https://docs.4dkankan.com/#/product/4dkk/zh-cn/README}")
  63. private String helpLinkZh;
  64. @Value("${helpLink.en-us:https://docs.4dkankan.com/#/product/4dkk/en-us/README}")
  65. private String helpLinkEn;
  66. @Value("#{'${camType.laser:}'.split(',')}")
  67. private List<Integer> laserCamTypeList;
  68. @Autowired
  69. private ISceneAsynOperLogService sceneAsynOperLogService;
  70. @Resource
  71. private FYunFileServiceInterface fYunFileServiceInterface;
  72. @Autowired
  73. private IScenePlusService scenePlusService;
  74. @Autowired
  75. private IScenePlusExtService scenePlusExtService;
  76. @Autowired
  77. private IMailTemplateService mailTemplateService;
  78. @Autowired
  79. private IUserService userService;
  80. @Autowired
  81. private ISceneProService sceneProService;
  82. @Autowired
  83. private ICameraDetailService cameraDetailService;
  84. @Autowired
  85. private IUserIncrementService userIncrementService;
  86. @Autowired
  87. private IIncrementTypeService incrementTypeService;
  88. @Autowired
  89. private ICameraService cameraService;
  90. @Autowired
  91. private FYunFileConfig fYunFileConfig;
  92. @Autowired
  93. private ISceneEditInfoService sceneEditInfoService;
  94. @Autowired
  95. private ISceneEditControlsService sceneEditControlsService;
  96. @Autowired
  97. private ISceneEditInfoExtService sceneEditInfoExtService;
  98. @Autowired
  99. private RedisUtil redisUtil;
  100. @Autowired
  101. private IMqSendLogService mqSendLogService;
  102. @Autowired
  103. private RabbitMqProducer rabbitMqProducer;
  104. @Autowired
  105. private ISceneInfoSyncMqConfigService sceneInfoSyncMqConfigService;
  106. @Override
  107. public void uploadBuildResultData(String num, String dataSource, String version) {
  108. Map<String, String> uploadMap = new HashMap<>();
  109. String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num);
  110. //删除旧的文件目录
  111. fYunFileServiceInterface.deleteFolder(ossResultPath);
  112. //上传caches/images
  113. String localCachesImagePath = dataSource + "/caches/images/";
  114. String ossCachesImagePath = ossResultPath + "caches/images/";
  115. //先清除旧的全景图
  116. if(FileUtil.exist(localCachesImagePath)){
  117. fYunFileServiceInterface.uploadFileByCommand(localCachesImagePath, ossCachesImagePath);
  118. }
  119. //上传project.json
  120. String localProjectJsonPath = dataSource + "/project.json";
  121. String ossProjectJsonPath = ossResultPath + "project.json";
  122. if(FileUtil.exist(localProjectJsonPath)){
  123. uploadMap.put(localProjectJsonPath, ossProjectJsonPath);
  124. }
  125. //上传data.json
  126. String localDataJsonPath = dataSource + "/data.json";
  127. String ossDataJsonPath = ossResultPath + "data.json";
  128. if(FileUtil.exist(localDataJsonPath)){
  129. uploadMap.put(localDataJsonPath, ossDataJsonPath);
  130. }
  131. //户型图上传
  132. String floorplanCadPath = ossResultPath + "floorplan_cad";
  133. String cadPicPathFormat = floorplanCadPath + "/floor-cad-%s.%s";
  134. String floorCadPath = dataSource + "/results/floorplan_cad";
  135. //清除原有旧的cad图
  136. fYunFileServiceInterface.deleteFolder(floorplanCadPath);
  137. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  138. if(CollUtil.isNotEmpty(floorCadList)){
  139. floorCadList.stream().forEach(str->{
  140. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  141. String[] arr = substring.split("floor");
  142. String[] arr2 = arr[1].split("\\.");
  143. //上传到用户编辑目录
  144. uploadMap.put(str, String.format(cadPicPathFormat, arr2[0], arr2[1]));
  145. });
  146. }
  147. //上传深时场景生成obj需要的文件
  148. String localReconstruction = dataSource + "/caches/reconstruction/";
  149. String ossReconstruction = ossResultPath + "caches/reconstruction/";
  150. if(FileUtil.exist(localReconstruction)){
  151. fYunFileServiceInterface.uploadFileByCommand(localReconstruction, ossReconstruction);
  152. }
  153. String localDepthmap = dataSource + "/caches/depthmap/";
  154. String ossDepthmap = ossResultPath + "caches/depthmap/";
  155. if(FileUtil.exist(localDepthmap)){
  156. fYunFileServiceInterface.uploadFileByCommand(localDepthmap, ossDepthmap);
  157. }
  158. String localDepthmapAsc = dataSource + "/caches/depthmap_csc/";
  159. String ossDepthmapAsc = ossResultPath + "caches/depthmap_csc/";
  160. if(FileUtil.exist(localDepthmapAsc)){
  161. fYunFileServiceInterface.uploadFileByCommand(localDepthmapAsc, ossDepthmapAsc);
  162. }
  163. String localPanoramaJson = dataSource + "/caches/panorama.json";
  164. String ossPanoramaJson = ossResultPath + "caches/panorama.json";
  165. if(FileUtil.exist(localPanoramaJson)){
  166. fYunFileServiceInterface.uploadFile(localPanoramaJson, ossPanoramaJson);
  167. }
  168. // String localLaserPly = dataSource + "/results/laserData/laser.ply";
  169. // String ossLaserPly = ossResultPath + "results/laserData/laser.ply";
  170. // if(FileUtil.exist(localLaserPly)){
  171. // fYunFileServiceInterface.uploadFile(localLaserPly, ossLaserPly);
  172. // }
  173. String localFloorGroupFixJson = dataSource + "/caches/floor_group_fix.json";
  174. String ossFloorGroupFixJson = ossResultPath + "caches/floor_group_fix.json";
  175. if(FileUtil.exist(localFloorGroupFixJson)){
  176. fYunFileServiceInterface.uploadFile(localFloorGroupFixJson, ossFloorGroupFixJson);
  177. }
  178. String localDepthmapVis = dataSource + "/caches/depthmap_vis";
  179. String ossDepthmapVis = ossResultPath + "caches/depthmap_vis";
  180. if(FileUtil.exist(localDepthmapVis)){
  181. fYunFileServiceInterface.uploadFileByCommand(localDepthmapVis, ossDepthmapVis);
  182. }
  183. String localIntensity = dataSource + "/caches/intensity";
  184. String ossIntensity = ossResultPath + "caches/intensity";
  185. if(FileUtil.exist(localIntensity)){
  186. fYunFileServiceInterface.uploadFileByCommand(localIntensity, ossIntensity);
  187. }
  188. //上传点位校准相关文件
  189. String localExtras = dataSource + "/extras";
  190. String ossExtras = ossResultPath + "extras";
  191. if(FileUtil.exist(localExtras)){
  192. fYunFileServiceInterface.uploadFileByCommand(localExtras, ossExtras);
  193. }
  194. //开始上传
  195. fYunFileServiceInterface.uploadMulFiles(uploadMap);
  196. }
  197. @Override
  198. public void uploadFloorplanJson(String num, String dataSource) throws Exception{
  199. String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
  200. if (!new File(floorPlanCardFilePath).exists()) {
  201. log.warn("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  202. return;
  203. }
  204. JSONObject json = FloorPlanUserUtil.createFloorPlanUserJson(floorPlanCardFilePath);
  205. if(Objects.isNull(json)){
  206. log.warn("生成floorplan.json失败,cadPath:{}", floorPlanCardFilePath);
  207. return;
  208. }
  209. String floorplanJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "floorplan.json";
  210. fYunFileServiceInterface.uploadFile(json.toJSONString().getBytes(), floorplanJsonPath);
  211. }
  212. @Override
  213. public void initUserEditData(String num, Set<String> bizs, Map<String, Map<String ,Object>> params) throws Exception {
  214. if(StrUtil.isEmpty(num) || CollUtil.isEmpty(bizs)){
  215. return;
  216. }
  217. for (String biz : bizs) {
  218. UserEditDataHandler handler = UserEditDataHandlerFactory.getHandler(biz);
  219. handler.init(num, CollUtil.isEmpty(params) ? null : params.get(biz));
  220. }
  221. }
  222. @Override
  223. public void sendEmail(String num) {
  224. try {
  225. Long userId = null;
  226. String websize = "";
  227. String title = "";
  228. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  229. if(Objects.isNull(scenePlus)){
  230. ScenePro scenePro = sceneProService.getByNum(num);
  231. if(Objects.isNull(scenePro)){
  232. return;
  233. }
  234. userId = scenePro.getUserId();
  235. websize = scenePro.getWebSite();
  236. title = scenePro.getSceneName();
  237. }else{
  238. userId = scenePlus.getUserId();
  239. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  240. websize = scenePlusExt.getWebSite();
  241. title = scenePlus.getTitle();
  242. }
  243. if(Objects.isNull(userId)){
  244. return;
  245. }
  246. User user = userService.getById(userId);
  247. if(Objects.isNull(user) || StrUtil.isEmpty(user.getUserName())){
  248. return;
  249. }
  250. String toEmail = user.getUserName();
  251. String helpLink = helpLinkEn;
  252. String lang = "en";
  253. if("gn".equals(env)){
  254. lang = "zh";
  255. helpLink = helpLinkZh;
  256. }
  257. websize += "&lang=" + lang;
  258. MailTemplate mailTemplate = mailTemplateService.getOne(new LambdaQueryWrapper<MailTemplate>().eq(MailTemplate::getRemark, "计算完成").eq(MailTemplate::getLang, lang));
  259. String content = mailTemplate.getMsg().replaceAll("scene_name", title).replaceAll("scene_link", websize).replaceAll("help_link", helpLink);
  260. SendMailAcceUtils.sendMail(mailTemplate.getSendMail(), mailTemplate.getSendPassword(), mailTemplate.getSendHost(), toEmail, mailTemplate.getSubject(), content, null);
  261. }catch (Exception e){
  262. log.error("发送邮件失败,num:" + num, e);
  263. }
  264. }
  265. public String getOssOrignPath(String path) {
  266. String ossPath = ConstantFilePath.OSS_PREFIX
  267. + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  268. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  269. if (!ossPath.endsWith("/")) {
  270. ossPath = ossPath.concat("/");
  271. }
  272. return ossPath;
  273. }
  274. @Override
  275. public int getPayStatus(Long cameraId, Long space){
  276. //查询权益统计容量的方式
  277. String unit = SpaceType.GB.code();
  278. CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId);
  279. if(StrUtil.isNotEmpty(cameraDetail.getUnit())){
  280. unit = cameraDetail.getUnit();
  281. }
  282. Long limit = this.getSpaceLimit(cameraDetail);
  283. if(SpaceType.SP.code().equals(unit)){//如果按空间方式统计,则space置为1
  284. space = 1L;
  285. }
  286. //更新相机使用用量,非激光相机或者是空间个数计算方式的,需要叠加相机容量
  287. cameraDetailService.updateCameraDetailByCameraIdAndSpace(cameraId, space);
  288. //无限容量或者激光相机,直接返回已支付
  289. if(limit == -1 || ("gn".equals(env) && CollUtil.isNotEmpty(laserCamTypeList) && laserCamTypeList.contains(cameraDetail.getType()))){
  290. return PayStatus.PAY.code();
  291. }
  292. Long usedSpace = cameraService.getUsedSpace(cameraId, unit);
  293. if(usedSpace + space > limit){
  294. return PayStatus.NO_CAPACITY.code();
  295. }
  296. return PayStatus.PAY.code();
  297. }
  298. @Override
  299. public void uploadStatusJson(String num, Integer sceneStatus, String webSite, String thumb, Integer payStatus, String uploadPath) {
  300. String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, num);
  301. JSONObject statusJson = new JSONObject();
  302. statusJson.put("status", sceneStatus);
  303. statusJson.put("webSite", webSite);
  304. statusJson.put("sceneNum", num);
  305. statusJson.put("thumb", thumb);
  306. statusJson.put("payStatus", PayStatus.NOT_PAY.code());
  307. statusJson.put("recStatus", 'A');
  308. FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
  309. fYunFileServiceInterface.uploadFile(localDataPath + "status.json", uploadPath + "status.json");
  310. }
  311. @Override
  312. public Long getSpaceLimit(CameraDetail cameraDetail){
  313. Long limit = cameraDetail.getTotalSpace();
  314. UserIncrement userIncrement = userIncrementService.getByCameraId(cameraDetail.getCameraId());
  315. if(Objects.nonNull(userIncrement) && userIncrement.getIsExpired() == CommonStatus.NO.code().intValue()){
  316. IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
  317. switch (SpaceType.get(cameraDetail.getUnit())){
  318. case GB:
  319. limit = incrementType.getCameraCapacity();
  320. if(limit != -1){
  321. limit = limit * 1024 * 1024 * 1024;
  322. }
  323. break;
  324. case SP:
  325. limit = incrementType.getCameraSpace();
  326. break;
  327. }
  328. }
  329. return limit;
  330. }
  331. @Override
  332. public Long getSpace(String num){
  333. Long space = fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.DATA_VIEW_PATH, num));
  334. space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.IMG_VIEW_PATH, num));
  335. space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.VIDEOS_VIEW_PATH, num));
  336. space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.VOICE_VIEW_PATH, num));
  337. space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.scene_result_data_path, num).concat("caches"));
  338. return space;
  339. }
  340. public Object[] updateEditInfo(ScenePlus scenePlus){
  341. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  342. SceneEditControls sceneEditControls = null;
  343. SceneEditInfoExt sceneEditInfoExt = null;
  344. if(sceneEditInfo == null){
  345. sceneEditInfo = new SceneEditInfo();
  346. sceneEditInfo.setScenePlusId(scenePlus.getId());
  347. sceneEditInfo.setDescription(scenePlus.getDescription());
  348. sceneEditInfo.setTitle(scenePlus.getTitle());
  349. sceneEditInfoService.save(sceneEditInfo);
  350. }else{
  351. int version = 0;
  352. int imgVersion = 0;
  353. int linkVersion = 0;
  354. //获取展示页的版本号
  355. String sceneJsonStr = fYunFileServiceInterface.getFileContent(String.format(UploadFilePath.DATA_VIEW_PATH, scenePlus.getNum()) + "scene.json");
  356. if(StrUtil.isNotEmpty(sceneJsonStr)){
  357. JSONObject sceneJson = JSON.parseObject(sceneJsonStr);
  358. version = sceneJson.getIntValue("version");
  359. imgVersion = sceneJson.getIntValue("imgVersion");
  360. linkVersion = sceneJson.getIntValue("linkVersion");
  361. }
  362. if(version < sceneEditInfo.getVersion()){
  363. version = sceneEditInfo.getVersion();
  364. }
  365. if(imgVersion < sceneEditInfo.getImgVersion()){
  366. imgVersion = sceneEditInfo.getImgVersion();
  367. }
  368. if(linkVersion < sceneEditInfo.getLinkVersion()){
  369. linkVersion = sceneEditInfo.getLinkVersion();
  370. }
  371. sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  372. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  373. sceneEditInfo.setVersion(version + 1);
  374. sceneEditInfo.setImgVersion(imgVersion + 1);
  375. sceneEditInfo.setLinkVersion(linkVersion + 1);
  376. sceneEditInfo.setIsUploadObj(CommonStatus.NO.code());
  377. sceneEditInfoService.updateById(sceneEditInfo);
  378. }
  379. if(sceneEditControls == null){
  380. sceneEditControls = new SceneEditControls();
  381. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  382. sceneEditControlsService.save(sceneEditControls);
  383. }
  384. if(sceneEditInfoExt == null){
  385. sceneEditInfoExt = new SceneEditInfoExt();
  386. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  387. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  388. sceneEditInfoExtService.save(sceneEditInfoExt);
  389. }
  390. return new Object[]{sceneEditInfo, sceneEditInfoExt, sceneEditControls};
  391. }
  392. public void writeSceneJson(String num, SceneEditInfo sceneEditInfo, SceneEditInfoExt sceneEditInfoExt,
  393. SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt,Company company){
  394. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  395. String oldSceneJson = fYunFileServiceInterface.getFileContent(dataViewPath + "scene.json");
  396. SceneJsonBean sceneJson = new SceneJsonBean();
  397. BeanUtil.copyProperties(sceneEditInfoExt, sceneJson, "started");
  398. BeanUtil.copyProperties(sceneEditInfo, sceneJson);
  399. SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
  400. sceneJson.setControls(sceneEditControlsVO);
  401. sceneJson.setNum(num);
  402. sceneJson.setCreateTime(scenePlus.getCreateTime());
  403. sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
  404. sceneJson.setVersion(sceneEditInfo.getVersion());
  405. sceneJson.setImgVersion(sceneEditInfo.getImgVersion());
  406. sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
  407. sceneJson.setSceneKind(scenePlusExt.getSceneKind());
  408. sceneJson.setModelKind(scenePlusExt.getModelKind());
  409. sceneJson.setVideos(scenePlusExt.getVideos());
  410. sceneJson.setPayStatus(scenePlus.getPayStatus());
  411. if(StrUtil.isNotEmpty(oldSceneJson)){
  412. SceneJsonBean oldSceneJsonBean = JSON.parseObject(oldSceneJson, SceneJsonBean.class);
  413. List<JSONObject> mosaicList = JSON.parseObject(oldSceneJson, SceneJsonBean.class).getMosaicList();
  414. sceneJson.setMosaicList(mosaicList);
  415. sceneJson.setFloorLogo(oldSceneJsonBean.getFloorLogo());
  416. sceneJson.setFloorLogoFile(oldSceneJsonBean.getFloorLogoFile());
  417. sceneJson.setBoxModels(oldSceneJsonBean.getBoxModels());
  418. sceneJson.setBoxVideos(oldSceneJsonBean.getBoxVideos());
  419. sceneJson.setBoxPhotos(oldSceneJsonBean.getBoxPhotos());
  420. }
  421. if(StrUtil.isNotEmpty(sceneEditInfoExt.getStarted())){
  422. sceneJson.setStarted(JSON.parseObject(sceneEditInfoExt.getStarted()));
  423. }
  424. if(!ObjectUtils.isEmpty(company)){
  425. String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
  426. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  427. String localLogoPath = null;
  428. if (StrUtil.isNotEmpty(company.getTopLogo())) {
  429. localLogoPath = ConstantFilePath.AGENT_PATH + company.getTopLogo().substring(company.getTopLogo().lastIndexOf("//") + 1);
  430. HttpUtil.downloadFile(company.getTopLogo(), localLogoPath);
  431. fYunFileServiceInterface.uploadFile(localLogoPath, userViewPath + "loadingLogo-user.png");
  432. fYunFileServiceInterface.uploadFile(localLogoPath, userEditPath + "loadingLogo-user.png");
  433. sceneJson.setLoadingLogo("user");
  434. sceneJson.setLoadingLogoFile("loadingLogo-user.png");
  435. sceneEditInfo.setLoadingLogo("user");
  436. sceneEditInfo.setLoadingLogoFile("loadingLogo-user.png");
  437. }
  438. if (StrUtil.isNotEmpty(company.getFloorLogo())) {
  439. localLogoPath = ConstantFilePath.AGENT_PATH + company.getFloorLogo().substring(company.getFloorLogo().lastIndexOf("//") + 1);
  440. HttpUtil.downloadFile(company.getFloorLogo(), localLogoPath);
  441. fYunFileServiceInterface.uploadFile(localLogoPath, userViewPath + "floorLogo-user.png");
  442. fYunFileServiceInterface.uploadFile(localLogoPath, userEditPath + "floorLogo-user.png");
  443. sceneJson.setFloorLogo("user");
  444. sceneJson.setFloorLogoFile("floorLogo-user.png");
  445. sceneEditInfo.setFloorLogo("user");
  446. sceneEditInfo.setFloorLogoFile("floorLogo-user.png");
  447. }
  448. if(!ObjectUtils.isEmpty(localLogoPath)){
  449. sceneEditInfoService.updateById(sceneEditInfo);
  450. FileUtils.deleteFile(localLogoPath);
  451. }
  452. }
  453. String sceneJsonStr = JSON.toJSONString(sceneJson);
  454. //上传sceneJson文件
  455. fYunFileServiceInterface.uploadFile(sceneJsonStr.getBytes(), dataViewPath + "scene.json");
  456. //scenejson写入缓存
  457. redisUtil.set(String.format(RedisKey.SCENE_JSON, num), sceneJsonStr);
  458. }
  459. @Override
  460. public void saveMqSendLog(String num, BuildSceneCallMessage message) {
  461. MqSendLog mqSendLog = new MqSendLog();
  462. mqSendLog.setNum(num);
  463. mqSendLog.setContent(JSON.toJSONString(message));
  464. mqSendLogService.save(mqSendLog);
  465. }
  466. @Override
  467. public void sendUpdateSceneStatusMqToQueues(Map<String, Object> content) {
  468. List<SceneInfoSyncMqConfig> configs = sceneInfoSyncMqConfigService.listByInfoType("update_scene_status");
  469. if(CollUtil.isEmpty(configs)){
  470. return;
  471. }
  472. for (SceneInfoSyncMqConfig config : configs) {
  473. rabbitMqProducer.sendByWorkQueue(config.getQueueName(), content);
  474. }
  475. }
  476. @Override
  477. public void removeSceneAsynOperLog(String num) {
  478. List<SceneAsynOperLog> list = sceneAsynOperLogService.list(new LambdaQueryWrapper<SceneAsynOperLog>().eq(SceneAsynOperLog::getNum, num));
  479. if(CollUtil.isEmpty(list)){
  480. return;
  481. }
  482. //删除数据库记录
  483. List<Long> deleteIdList = list.parallelStream().map(item -> item.getId()).collect(Collectors.toList());
  484. sceneAsynOperLogService.removeByIds(deleteIdList);
  485. list.parallelStream().forEach(item -> {
  486. if(StrUtil.isNotEmpty(item.getUrl())){
  487. try {
  488. fYunFileServiceInterface.deleteFile(item.getUrl());
  489. } catch (IOException e) {
  490. log.warn("删除oss全景图下载压缩包失败,key:{}", item.getUrl());
  491. }
  492. }
  493. });
  494. }
  495. public JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType){
  496. //读取videos_hdr_param.json, 保存点位视频的value
  497. Map<String, Object> videoMap = new HashMap<>();
  498. String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
  499. JSONArray videoArray = null;
  500. if(StringUtils.isNotEmpty(videosHdr)){
  501. videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
  502. }
  503. if(videoArray != null){
  504. for(int i = 0, len = videoArray.size(); i < len; i++) {
  505. videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
  506. if(videoArray.getJSONObject(i).containsKey("fov")){
  507. videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
  508. }
  509. }
  510. }
  511. //获取upload中的video视频名称
  512. String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
  513. JSONObject uploadJson = null;
  514. JSONArray array = null;
  515. if(uploadData!=null) {
  516. uploadJson = JSONObject.parseObject(uploadData);
  517. array = uploadJson.getJSONArray("upload");
  518. }
  519. JSONObject fileJson = null;
  520. String fileName = "";
  521. //计算ts文件的大小,并拼接成json格式
  522. JSONArray jsonArray = new JSONArray();
  523. JSONObject videoJson = null;
  524. JSONObject videosJson = new JSONObject();
  525. long videoSize = 0L;
  526. for(int i = 0, len = array.size(); i < len; i++) {
  527. fileJson = array.getJSONObject(i);
  528. fileName = fileJson.getString("file");
  529. if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
  530. videoJson = new JSONObject();
  531. videoJson.put("id", fileName.substring(
  532. 0, fileName.lastIndexOf(".")).replace("videos/", ""));
  533. //如果ts文件存在,就计算ts大小
  534. if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
  535. videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
  536. videoJson.put("tsSize", videoSize);
  537. }
  538. if(videoMap.containsKey(videoJson.get("id"))){
  539. videoJson.put("value", videoMap.get(videoJson.get("id")));
  540. }
  541. if(videoMap.containsKey(videoJson.get("id") + "_fov")){
  542. videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
  543. }else {
  544. videoJson.put("blend_fov", 7);
  545. }
  546. jsonArray.add(videoJson);
  547. }
  548. }
  549. videosJson.put("data", jsonArray);
  550. if(Objects.nonNull(videoVersion) && videoVersion >= 4){
  551. videosJson.put("version", 3);
  552. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up.xml");
  553. if(cameraType == 13 || cameraType == 14){
  554. //转台相机
  555. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  556. }
  557. }else {
  558. videosJson.put("version", 1);
  559. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up2.xml");
  560. if(cameraType == 13 || cameraType == 14){
  561. //转台相机
  562. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  563. }
  564. }
  565. if(cameraType == 5 || cameraType == 6){
  566. videosJson.put("version", 1);
  567. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "stitch_params.txt");
  568. }
  569. return videosJson;
  570. }
  571. }