CommonServiceImpl.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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.core.util.ZipUtil;
  6. import cn.hutool.http.HttpUtil;
  7. import com.alibaba.fastjson.JSON;
  8. import com.alibaba.fastjson.JSONArray;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.fdkankan.common.constant.*;
  11. import com.fdkankan.common.util.FileUtils;
  12. import cn.hutool.core.util.StrUtil;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  15. import com.fdkankan.common.util.FileUtils;
  16. import com.fdkankan.contro.bean.SceneJsonBean;
  17. import com.fdkankan.contro.entity.*;
  18. import com.fdkankan.contro.factory.UserEditData.UserEditDataHandler;
  19. import com.fdkankan.contro.factory.UserEditData.UserEditDataHandlerFactory;
  20. import com.fdkankan.contro.service.ICommonService;
  21. import com.fdkankan.contro.service.*;
  22. import com.fdkankan.contro.vo.SceneEditControlsVO;
  23. import com.fdkankan.contro.vo.ScenePlusVO;
  24. import com.fdkankan.fyun.config.FYunFileConfig;
  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.utils.CreateObjUtil;
  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.laserUrlP:#{null}}")
  59. private String laserUrl;
  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. @Value("${model.modelKind:3dtiles}")
  69. private String modelKind;
  70. @Value("#{'${model.3dtiles.sceneSource:}'.split(',')}")
  71. private List<Integer> sdTilesSceneSourceList;
  72. @Autowired
  73. private ISceneAsynOperLogService sceneAsynOperLogService;
  74. @Resource
  75. private FYunFileServiceInterface fYunFileServiceInterface;
  76. @Autowired
  77. private IScenePlusService scenePlusService;
  78. @Autowired
  79. private IScenePlusExtService scenePlusExtService;
  80. @Autowired
  81. private IMailTemplateService mailTemplateService;
  82. @Autowired
  83. private IUserService userService;
  84. @Autowired
  85. private ISceneProService sceneProService;
  86. @Autowired
  87. private ICameraDetailService cameraDetailService;
  88. @Autowired
  89. private IUserIncrementService userIncrementService;
  90. @Autowired
  91. private IIncrementTypeService incrementTypeService;
  92. @Autowired
  93. private ICameraService cameraService;
  94. @Autowired
  95. private FYunFileConfig fYunFileConfig;
  96. @Autowired
  97. private ISceneEditInfoService sceneEditInfoService;
  98. @Autowired
  99. private ISceneEditControlsService sceneEditControlsService;
  100. @Autowired
  101. private ISceneEditInfoExtService sceneEditInfoExtService;
  102. @Autowired
  103. private RedisUtil redisUtil;
  104. @Autowired
  105. private IMqSendLogService mqSendLogService;
  106. @Autowired
  107. private RabbitMqProducer rabbitMqProducer;
  108. @Autowired
  109. private ISceneInfoSyncMqConfigService sceneInfoSyncMqConfigService;
  110. @Override
  111. public void uploadBuildResultData(String num, String dataSource, String version) {
  112. Map<String, String> uploadMap = new HashMap<>();
  113. String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num);
  114. //删除旧的文件目录
  115. fYunFileServiceInterface.deleteFolder(ossResultPath);
  116. //上传caches/images
  117. String localCachesImagePath = dataSource + "/caches/images/";
  118. String ossCachesImagePath = ossResultPath + "caches/images/";
  119. //先清除旧的全景图
  120. if(FileUtil.exist(localCachesImagePath)){
  121. fYunFileServiceInterface.uploadFileByCommand(localCachesImagePath, ossCachesImagePath);
  122. }
  123. //上传project.json
  124. String localProjectJsonPath = dataSource + "/project.json";
  125. String ossProjectJsonPath = ossResultPath + "project.json";
  126. if(FileUtil.exist(localProjectJsonPath)){
  127. uploadMap.put(localProjectJsonPath, ossProjectJsonPath);
  128. }
  129. //上传data.json
  130. String localDataJsonPath = dataSource + "/data.json";
  131. String ossDataJsonPath = ossResultPath + "data.json";
  132. if(FileUtil.exist(localDataJsonPath)){
  133. uploadMap.put(localDataJsonPath, ossDataJsonPath);
  134. }
  135. //户型图上传
  136. String floorplanCadPath = ossResultPath + "floorplan_cad";
  137. String cadPicPathFormat = floorplanCadPath + "/floor-cad-%s.%s";
  138. String floorCadPath = dataSource + "/results/floorplan_cad";
  139. //清除原有旧的cad图
  140. fYunFileServiceInterface.deleteFolder(floorplanCadPath);
  141. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  142. if(CollUtil.isNotEmpty(floorCadList)){
  143. floorCadList.stream().forEach(str->{
  144. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  145. String[] arr = substring.split("floor");
  146. String[] arr2 = arr[1].split("\\.");
  147. //上传到用户编辑目录
  148. uploadMap.put(str, String.format(cadPicPathFormat, arr2[0], arr2[1]));
  149. });
  150. }
  151. //上传深时场景生成obj需要的文件
  152. String localReconstruction = dataSource + "/caches/reconstruction/";
  153. String ossReconstruction = ossResultPath + "caches/reconstruction/";
  154. if(FileUtil.exist(localReconstruction)){
  155. fYunFileServiceInterface.uploadFileByCommand(localReconstruction, ossReconstruction);
  156. }
  157. String localDepthmap = dataSource + "/caches/depthmap/";
  158. String ossDepthmap = ossResultPath + "caches/depthmap/";
  159. if(FileUtil.exist(localDepthmap)){
  160. fYunFileServiceInterface.uploadFileByCommand(localDepthmap, ossDepthmap);
  161. }
  162. String localDepthmapAsc = dataSource + "/caches/depthmap_csc/";
  163. String ossDepthmapAsc = ossResultPath + "caches/depthmap_csc/";
  164. if(FileUtil.exist(localDepthmapAsc)){
  165. fYunFileServiceInterface.uploadFileByCommand(localDepthmapAsc, ossDepthmapAsc);
  166. }
  167. String localPanoramaJson = dataSource + "/caches/panorama.json";
  168. String ossPanoramaJson = ossResultPath + "caches/panorama.json";
  169. if(FileUtil.exist(localPanoramaJson)){
  170. fYunFileServiceInterface.uploadFile(localPanoramaJson, ossPanoramaJson);
  171. }
  172. // String localLaserPly = dataSource + "/results/laserData/laser.ply";
  173. // String ossLaserPly = ossResultPath + "results/laserData/laser.ply";
  174. // if(FileUtil.exist(localLaserPly)){
  175. // fYunFileServiceInterface.uploadFile(localLaserPly, ossLaserPly);
  176. // }
  177. String localFloorGroupFixJson = dataSource + "/caches/floor_group_fix.json";
  178. String ossFloorGroupFixJson = ossResultPath + "caches/floor_group_fix.json";
  179. if(FileUtil.exist(localFloorGroupFixJson)){
  180. fYunFileServiceInterface.uploadFile(localFloorGroupFixJson, ossFloorGroupFixJson);
  181. }
  182. String localDepthmapVis = dataSource + "/caches/depthmap_vis";
  183. String ossDepthmapVis = ossResultPath + "caches/depthmap_vis";
  184. if(FileUtil.exist(localDepthmapVis)){
  185. fYunFileServiceInterface.uploadFileByCommand(localDepthmapVis, ossDepthmapVis);
  186. }
  187. String localIntensity = dataSource + "/caches/intensity";
  188. String ossIntensity = ossResultPath + "caches/intensity";
  189. if(FileUtil.exist(localIntensity)){
  190. fYunFileServiceInterface.uploadFileByCommand(localIntensity, ossIntensity);
  191. }
  192. //上传点位校准相关文件
  193. String localExtras = dataSource + "/extras";
  194. String ossExtras = ossResultPath + "extras";
  195. if(FileUtil.exist(localExtras)){
  196. fYunFileServiceInterface.uploadFileByCommand(localExtras, ossExtras);
  197. }
  198. //开始上传
  199. fYunFileServiceInterface.uploadMulFiles(uploadMap);
  200. }
  201. @Override
  202. public void uploadFloorplanJson(String num, String dataSource) throws Exception{
  203. String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
  204. if (!new File(floorPlanCardFilePath).exists()) {
  205. log.warn("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  206. return;
  207. }
  208. JSONObject json = FloorPlanUserUtil.createFloorPlanUserJson(floorPlanCardFilePath);
  209. if(Objects.isNull(json)){
  210. log.warn("生成floorplan.json失败,cadPath:{}", floorPlanCardFilePath);
  211. return;
  212. }
  213. String floorplanJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "floorplan.json";
  214. fYunFileServiceInterface.uploadFile(json.toJSONString().getBytes(), floorplanJsonPath);
  215. }
  216. @Override
  217. public void initUserEditData(String num, Set<String> bizs, Map<String, Map<String ,Object>> params) throws Exception {
  218. if(StrUtil.isEmpty(num) || CollUtil.isEmpty(bizs)){
  219. return;
  220. }
  221. for (String biz : bizs) {
  222. UserEditDataHandler handler = UserEditDataHandlerFactory.getHandler(biz);
  223. handler.init(num, CollUtil.isEmpty(params) ? null : params.get(biz));
  224. }
  225. }
  226. @Override
  227. public void sendEmail(String num, String type) {
  228. try {
  229. Long userId = null;
  230. String websize = "";
  231. String title = "";
  232. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  233. if(Objects.isNull(scenePlus)){
  234. ScenePro scenePro = sceneProService.getByNum(num);
  235. if(Objects.isNull(scenePro)){
  236. return;
  237. }
  238. userId = scenePro.getUserId();
  239. websize = scenePro.getWebSite();
  240. title = scenePro.getSceneName();
  241. }else{
  242. userId = scenePlus.getUserId();
  243. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  244. websize = scenePlusExt.getWebSite();
  245. title = scenePlus.getTitle();
  246. }
  247. if(Objects.isNull(userId)){
  248. return;
  249. }
  250. User user = userService.getById(userId);
  251. if(Objects.isNull(user) || StrUtil.isEmpty(user.getUserName())){
  252. return;
  253. }
  254. String toEmail = user.getUserName();
  255. String helpLink = helpLinkEn;
  256. String lang = "en";
  257. if("gn".equals(env)){
  258. lang = "zh";
  259. helpLink = helpLinkZh;
  260. }
  261. websize += "&lang=" + lang;
  262. if(("V4".equals(type) || "V3".equals(type))
  263. && (scenePlus.getSceneSource() == SceneSource.JG.code() || scenePlus.getSceneSource() == SceneSource.SG.code())){
  264. websize = String.format(laserUrl, num, lang);
  265. }
  266. MailTemplate mailTemplate = mailTemplateService.getOne(new LambdaQueryWrapper<MailTemplate>().eq(MailTemplate::getRemark, "计算完成").eq(MailTemplate::getLang, lang));
  267. String content = mailTemplate.getMsg().replaceAll("scene_name", title).replaceAll("scene_link", websize).replaceAll("help_link", helpLink);
  268. SendMailAcceUtils.sendMail(mailTemplate.getSendMail(), mailTemplate.getSendPassword(), mailTemplate.getSendHost(), toEmail, mailTemplate.getSubject(), content, null);
  269. }catch (Exception e){
  270. log.error("发送邮件失败,num:" + num, e);
  271. }
  272. }
  273. public String getOssOrignPath(String path) {
  274. String ossPath = ConstantFilePath.OSS_PREFIX
  275. + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  276. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  277. if (!ossPath.endsWith("/")) {
  278. ossPath = ossPath.concat("/");
  279. }
  280. return ossPath;
  281. }
  282. @Override
  283. public int getPayStatus(Long cameraId, Long space){
  284. //查询权益统计容量的方式
  285. String unit = SpaceType.GB.code();
  286. CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId);
  287. if(StrUtil.isNotEmpty(cameraDetail.getUnit())){
  288. unit = cameraDetail.getUnit();
  289. }
  290. Long limit = this.getSpaceLimit(cameraDetail);
  291. if(SpaceType.SP.code().equals(unit)){//如果按空间方式统计,则space置为1
  292. space = 1L;
  293. }
  294. //更新相机使用用量,非激光相机或者是空间个数计算方式的,需要叠加相机容量
  295. cameraDetailService.updateCameraDetailByCameraIdAndSpace(cameraId, space);
  296. //无限容量或者激光相机,直接返回已支付
  297. if(limit == -1 || ("gn".equals(env) && CollUtil.isNotEmpty(laserCamTypeList) && laserCamTypeList.contains(cameraDetail.getType()))){
  298. return PayStatus.PAY.code();
  299. }
  300. Long usedSpace = cameraService.getUsedSpace(cameraId, unit);
  301. if(usedSpace + space > limit){
  302. return PayStatus.NO_CAPACITY.code();
  303. }
  304. return PayStatus.PAY.code();
  305. }
  306. @Override
  307. public void uploadStatusJson(String num, Integer sceneStatus, String webSite, String thumb, Integer payStatus, String uploadPath) {
  308. String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, num);
  309. JSONObject statusJson = new JSONObject();
  310. statusJson.put("status", sceneStatus);
  311. statusJson.put("webSite", webSite);
  312. statusJson.put("sceneNum", num);
  313. statusJson.put("thumb", thumb);
  314. statusJson.put("payStatus", PayStatus.NOT_PAY.code());
  315. statusJson.put("recStatus", 'A');
  316. FileUtils.writeFile(localDataPath + "status.json", statusJson.toString());
  317. fYunFileServiceInterface.uploadFile(localDataPath + "status.json", uploadPath + "status.json");
  318. }
  319. @Override
  320. public Long getSpaceLimit(CameraDetail cameraDetail){
  321. Long limit = cameraDetail.getTotalSpace();
  322. UserIncrement userIncrement = userIncrementService.getByCameraId(cameraDetail.getCameraId());
  323. if(Objects.nonNull(userIncrement) && userIncrement.getIsExpired() == CommonStatus.NO.code().intValue()){
  324. IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
  325. switch (SpaceType.get(cameraDetail.getUnit())){
  326. case GB:
  327. limit = incrementType.getCameraCapacity();
  328. if(limit != -1){
  329. limit = limit * 1024 * 1024 * 1024;
  330. }
  331. break;
  332. case SP:
  333. limit = incrementType.getCameraSpace();
  334. break;
  335. }
  336. }
  337. return limit;
  338. }
  339. @Override
  340. public Long getSpace(String num){
  341. Long space = fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.DATA_VIEW_PATH, num));
  342. space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.IMG_VIEW_PATH, num));
  343. space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.VIDEOS_VIEW_PATH, num));
  344. space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.VOICE_VIEW_PATH, num));
  345. space += fYunFileServiceInterface.getSpace(fYunFileConfig.getBucket(), String.format(UploadFilePath.scene_result_data_path, num).concat("caches"));
  346. return space;
  347. }
  348. public Object[] updateEditInfo(ScenePlus scenePlus){
  349. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  350. SceneEditControls sceneEditControls = null;
  351. SceneEditInfoExt sceneEditInfoExt = null;
  352. if(sceneEditInfo == null){
  353. sceneEditInfo = new SceneEditInfo();
  354. sceneEditInfo.setScenePlusId(scenePlus.getId());
  355. sceneEditInfo.setDescription(scenePlus.getDescription());
  356. sceneEditInfo.setTitle(scenePlus.getTitle());
  357. sceneEditInfoService.save(sceneEditInfo);
  358. }else{
  359. int version = 0;
  360. int imgVersion = 0;
  361. int linkVersion = 0;
  362. //获取展示页的版本号
  363. String sceneJsonStr = fYunFileServiceInterface.getFileContent(String.format(UploadFilePath.DATA_VIEW_PATH, scenePlus.getNum()) + "scene.json");
  364. if(StrUtil.isNotEmpty(sceneJsonStr)){
  365. JSONObject sceneJson = JSON.parseObject(sceneJsonStr);
  366. version = sceneJson.getIntValue("version");
  367. imgVersion = sceneJson.getIntValue("imgVersion");
  368. linkVersion = sceneJson.getIntValue("linkVersion");
  369. }
  370. if(version < sceneEditInfo.getVersion()){
  371. version = sceneEditInfo.getVersion();
  372. }
  373. if(imgVersion < sceneEditInfo.getImgVersion()){
  374. imgVersion = sceneEditInfo.getImgVersion();
  375. }
  376. if(linkVersion < sceneEditInfo.getLinkVersion()){
  377. linkVersion = sceneEditInfo.getLinkVersion();
  378. }
  379. sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  380. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  381. sceneEditInfo.setVersion(version + 1);
  382. sceneEditInfo.setImgVersion(imgVersion + 1);
  383. sceneEditInfo.setLinkVersion(linkVersion + 1);
  384. sceneEditInfo.setIsUploadObj(CommonStatus.NO.code());
  385. sceneEditInfoService.updateById(sceneEditInfo);
  386. }
  387. if(sceneEditControls == null){
  388. sceneEditControls = new SceneEditControls();
  389. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  390. sceneEditControlsService.save(sceneEditControls);
  391. }
  392. if(sceneEditInfoExt == null){
  393. sceneEditInfoExt = new SceneEditInfoExt();
  394. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  395. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  396. sceneEditInfoExtService.save(sceneEditInfoExt);
  397. }
  398. return new Object[]{sceneEditInfo, sceneEditInfoExt, sceneEditControls};
  399. }
  400. public void writeSceneJson(String num, SceneEditInfo sceneEditInfo, SceneEditInfoExt sceneEditInfoExt,
  401. SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt,Company company){
  402. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  403. String oldSceneJson = fYunFileServiceInterface.getFileContent(dataViewPath + "scene.json");
  404. SceneJsonBean sceneJson = new SceneJsonBean();
  405. BeanUtil.copyProperties(sceneEditInfoExt, sceneJson, "started");
  406. BeanUtil.copyProperties(sceneEditInfo, sceneJson);
  407. SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
  408. sceneJson.setControls(sceneEditControlsVO);
  409. sceneJson.setNum(num);
  410. sceneJson.setCreateTime(scenePlus.getCreateTime());
  411. sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
  412. sceneJson.setVersion(sceneEditInfo.getVersion());
  413. sceneJson.setImgVersion(sceneEditInfo.getImgVersion());
  414. sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
  415. sceneJson.setSceneKind(scenePlusExt.getSceneKind());
  416. sceneJson.setModelKind(scenePlusExt.getModelKind());
  417. sceneJson.setVideos(scenePlusExt.getVideos());
  418. sceneJson.setPayStatus(scenePlus.getPayStatus());
  419. if(StrUtil.isNotEmpty(oldSceneJson)){
  420. SceneJsonBean oldSceneJsonBean = JSON.parseObject(oldSceneJson, SceneJsonBean.class);
  421. List<JSONObject> mosaicList = JSON.parseObject(oldSceneJson, SceneJsonBean.class).getMosaicList();
  422. sceneJson.setMosaicList(mosaicList);
  423. sceneJson.setFloorLogo(oldSceneJsonBean.getFloorLogo());
  424. sceneJson.setFloorLogoFile(oldSceneJsonBean.getFloorLogoFile());
  425. sceneJson.setBoxModels(oldSceneJsonBean.getBoxModels());
  426. sceneJson.setBoxVideos(oldSceneJsonBean.getBoxVideos());
  427. sceneJson.setBoxPhotos(oldSceneJsonBean.getBoxPhotos());
  428. }
  429. if(StrUtil.isNotEmpty(sceneEditInfoExt.getStarted())){
  430. log.info("开始转换started:{}", sceneEditInfoExt.getStarted());
  431. sceneJson.setStarted(JSON.parseObject(sceneEditInfoExt.getStarted()));
  432. log.info("结束转换started:{}", sceneEditInfoExt.getStarted());
  433. }
  434. if(!ObjectUtils.isEmpty(company)){
  435. String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
  436. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  437. String localLogoPath = null;
  438. if (StrUtil.isNotEmpty(company.getTopLogo())) {
  439. localLogoPath = ConstantFilePath.AGENT_PATH + company.getTopLogo().substring(company.getTopLogo().lastIndexOf("//") + 1);
  440. if(company.getTopLogo().startsWith("http")){
  441. HttpUtil.downloadFile(company.getTopLogo(), localLogoPath);
  442. }else{
  443. fYunFileServiceInterface.downloadFile(company.getTopLogo().substring(1), localLogoPath);
  444. }
  445. fYunFileServiceInterface.uploadFile(localLogoPath, userViewPath + "loadingLogo-user.png");
  446. fYunFileServiceInterface.uploadFile(localLogoPath, userEditPath + "loadingLogo-user.png");
  447. sceneJson.setLoadingLogo("user");
  448. sceneJson.setLoadingLogoFile("loadingLogo-user.png");
  449. sceneEditInfo.setLoadingLogo("user");
  450. sceneEditInfo.setLoadingLogoFile("loadingLogo-user.png");
  451. }
  452. if (StrUtil.isNotEmpty(company.getFloorLogo())) {
  453. if(company.getFloorLogo().startsWith("http")){
  454. HttpUtil.downloadFile(company.getFloorLogo(), localLogoPath);
  455. }else{
  456. fYunFileServiceInterface.downloadFile(company.getFloorLogo().substring(1), localLogoPath);
  457. }
  458. localLogoPath = ConstantFilePath.AGENT_PATH + company.getFloorLogo().substring(company.getFloorLogo().lastIndexOf("//") + 1);
  459. fYunFileServiceInterface.uploadFile(localLogoPath, userViewPath + "floorLogo-user.png");
  460. fYunFileServiceInterface.uploadFile(localLogoPath, userEditPath + "floorLogo-user.png");
  461. sceneJson.setFloorLogo("user");
  462. sceneJson.setFloorLogoFile("floorLogo-user.png");
  463. sceneEditInfo.setFloorLogo("user");
  464. sceneEditInfo.setFloorLogoFile("floorLogo-user.png");
  465. }
  466. if(!ObjectUtils.isEmpty(localLogoPath)){
  467. sceneEditInfoService.updateById(sceneEditInfo);
  468. FileUtils.deleteFile(localLogoPath);
  469. }
  470. }
  471. String sceneJsonStr = JSON.toJSONString(sceneJson);
  472. //上传sceneJson文件
  473. fYunFileServiceInterface.uploadFile(sceneJsonStr.getBytes(), dataViewPath + "scene.json");
  474. //scenejson写入缓存
  475. log.info("--------------------sceneJson:{}", sceneJsonStr);
  476. redisUtil.set(String.format(RedisKey.SCENE_JSON, num), sceneJsonStr);
  477. }
  478. @Override
  479. public void saveMqSendLog(String num, BuildSceneCallMessage message) {
  480. MqSendLog mqSendLog = new MqSendLog();
  481. mqSendLog.setNum(num);
  482. mqSendLog.setContent(JSON.toJSONString(message));
  483. mqSendLogService.save(mqSendLog);
  484. }
  485. @Override
  486. public void sendUpdateSceneStatusMqToQueues(Map<String, Object> content) {
  487. List<SceneInfoSyncMqConfig> configs = sceneInfoSyncMqConfigService.listByInfoType("update_scene_status");
  488. if(CollUtil.isEmpty(configs)){
  489. return;
  490. }
  491. for (SceneInfoSyncMqConfig config : configs) {
  492. rabbitMqProducer.sendByWorkQueue(config.getQueueName(), content);
  493. }
  494. }
  495. @Override
  496. public void removeSceneAsynOperLog(String num) {
  497. List<SceneAsynOperLog> list = sceneAsynOperLogService.list(new LambdaQueryWrapper<SceneAsynOperLog>().eq(SceneAsynOperLog::getNum, num));
  498. if(CollUtil.isEmpty(list)){
  499. return;
  500. }
  501. //删除数据库记录
  502. List<Long> deleteIdList = list.parallelStream().map(item -> item.getId()).collect(Collectors.toList());
  503. sceneAsynOperLogService.removeByIds(deleteIdList);
  504. list.parallelStream().forEach(item -> {
  505. if(StrUtil.isNotEmpty(item.getUrl())){
  506. try {
  507. fYunFileServiceInterface.deleteFile(item.getUrl());
  508. } catch (IOException e) {
  509. log.warn("删除oss全景图下载压缩包失败,key:{}", item.getUrl());
  510. }
  511. }
  512. });
  513. }
  514. public JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType){
  515. //读取videos_hdr_param.json, 保存点位视频的value
  516. Map<String, Object> videoMap = new HashMap<>();
  517. String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
  518. JSONArray videoArray = null;
  519. if(StringUtils.isNotEmpty(videosHdr)){
  520. videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
  521. }
  522. if(videoArray != null){
  523. for(int i = 0, len = videoArray.size(); i < len; i++) {
  524. videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
  525. if(videoArray.getJSONObject(i).containsKey("fov")){
  526. videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
  527. }
  528. }
  529. }
  530. //获取upload中的video视频名称
  531. String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
  532. JSONObject uploadJson = null;
  533. JSONArray array = null;
  534. if(uploadData!=null) {
  535. uploadJson = JSONObject.parseObject(uploadData);
  536. array = uploadJson.getJSONArray("upload");
  537. }
  538. JSONObject fileJson = null;
  539. String fileName = "";
  540. //计算ts文件的大小,并拼接成json格式
  541. JSONArray jsonArray = new JSONArray();
  542. JSONObject videoJson = null;
  543. JSONObject videosJson = new JSONObject();
  544. long videoSize = 0L;
  545. for(int i = 0, len = array.size(); i < len; i++) {
  546. fileJson = array.getJSONObject(i);
  547. fileName = fileJson.getString("file");
  548. if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
  549. videoJson = new JSONObject();
  550. videoJson.put("id", fileName.substring(
  551. 0, fileName.lastIndexOf(".")).replace("videos/", ""));
  552. //如果ts文件存在,就计算ts大小
  553. if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
  554. videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
  555. videoJson.put("tsSize", videoSize);
  556. }
  557. if(videoMap.containsKey(videoJson.get("id"))){
  558. videoJson.put("value", videoMap.get(videoJson.get("id")));
  559. }
  560. if(videoMap.containsKey(videoJson.get("id") + "_fov")){
  561. videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
  562. }else {
  563. videoJson.put("blend_fov", 7);
  564. }
  565. jsonArray.add(videoJson);
  566. }
  567. }
  568. videosJson.put("data", jsonArray);
  569. if(Objects.nonNull(videoVersion) && videoVersion >= 4){
  570. videosJson.put("version", 3);
  571. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up.xml");
  572. if(cameraType == 13 || cameraType == 14){
  573. //转台相机
  574. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  575. }
  576. }else {
  577. videosJson.put("version", 1);
  578. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up2.xml");
  579. if(cameraType == 13 || cameraType == 14){
  580. //转台相机
  581. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  582. }
  583. }
  584. if(cameraType == 5 || cameraType == 6){
  585. videosJson.put("version", 1);
  586. videosJson.put("upPath", fYunFileConfig.getHost() + String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "stitch_params.txt");
  587. }
  588. return videosJson;
  589. }
  590. @Override
  591. public JSONObject getFdageData(String dataFdagePath) {
  592. log.info("dataFdagePath 文件路径 :{}", dataFdagePath);
  593. String data = FileUtils.readFile(dataFdagePath);
  594. //获取data.fdage的内容
  595. JSONObject dataJson = new JSONObject();
  596. if(data!=null){
  597. dataJson = JSONObject.parseObject(data);
  598. }
  599. return dataJson;
  600. }
  601. @Override
  602. public Map<String, String> getUploadFiles(ScenePlus scenePlus,String path,Integer cameraType,JSONObject fdageData) throws Exception {
  603. if (ObjectUtils.isEmpty(scenePlus)) {
  604. throw new Exception("未找到场景信息:" + path);
  605. }
  606. String projectNum = scenePlus.getNum();
  607. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, projectNum);
  608. String imagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, projectNum);
  609. String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, projectNum);
  610. String resultsPath = path + File.separator + "results" + File.separator;
  611. String uploadData = FileUtils.readFile(resultsPath + "upload.json");
  612. JSONArray array = JSONObject.parseObject(uploadData).getJSONArray("upload");
  613. JSONObject fileJson = null;
  614. String fileName = "";
  615. Map<String, String> map = new HashMap();
  616. for (int i = 0; i < array.size(); ++i) {
  617. fileJson = array.getJSONObject(i);
  618. fileName = fileJson.getString("file");
  619. String filePath = resultsPath + fileName;
  620. if (!(new File(filePath)).exists()) {
  621. throw new Exception(filePath + "文件不存在");
  622. }
  623. if ("vision2.txt".equals(fileName)) {
  624. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision2.txt", resultsPath + "vision2.modeldata");
  625. map.put(resultsPath + "vision2.modeldata", imagesPath + "vision2.modeldata");
  626. map.put(resultsPath + "vision2.txt", imagesPath + "vision2.txt");
  627. }
  628. if (fileJson.getIntValue("clazz") == 2) {
  629. map.put(filePath, imagesPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
  630. } else if (fileJson.getIntValue("clazz") == 3) {
  631. map.put(filePath, imagesPath + "pan/high/" + fileName.replace("high/", ""));
  632. } else if (fileJson.getIntValue("clazz") == 4) {
  633. map.put(filePath, imagesPath + "pan/low/" + fileName.replace("low/", ""));
  634. } else if (fileJson.getIntValue("clazz") == 5) {
  635. map.put(filePath, imagesPath + fileName);
  636. } else if (fileJson.getIntValue("clazz") == 7) {
  637. map.put(filePath, imagesPath + fileName);
  638. } else if (fileJson.getIntValue("clazz") == 10) {
  639. String updown = FileUtils.readFile(filePath);
  640. JSONObject updownJson = JSONObject.parseObject(updown);
  641. String mappingOssPath = String.format("scene_edit_data/%s/data/", projectNum) + fileName.replace("updown", "mapping");
  642. map.put(filePath, mappingOssPath);
  643. } else {
  644. if (fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("clazz") == 12) {
  645. map.put(filePath, videoPath + fileName.replace("videos/", ""));
  646. if (fileName.contains(".mp4")) {
  647. map.put(resultsPath + fileName.replace("mp4", "flv"), videoPath + fileName.replace("videos/", "").replace("mp4", "flv"));
  648. }
  649. }
  650. if (fileJson.getIntValue("clazz") == 16) {
  651. map.put(filePath, dataViewPath + fileName);
  652. }
  653. if (fileJson.getIntValue("clazz") == 18) {
  654. map.put(filePath, imagesPath + fileName);
  655. }
  656. }
  657. }
  658. //exportMeshObj这个是字段由app写入的
  659. boolean genModel = true;//是否生成模型 默认生成,深时场景要根据 exportMeshObj判断是否生成
  660. if(!ObjectUtils.isEmpty(cameraType)
  661. && cameraType == 14
  662. && (!fdageData.containsKey("exportMeshObj") || fdageData.getIntValue("exportMeshObj") != 1)){
  663. genModel = false;
  664. }
  665. boolean gen3dTiles = true;//是否生成3dtiles模型 默认生成
  666. if(!ModelKind.THREE_D_TILE.code().equals(modelKind)
  667. || CollUtil.isEmpty(sdTilesSceneSourceList)
  668. || !sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){
  669. gen3dTiles = false;
  670. }
  671. if(genModel){
  672. if (!gen3dTiles) {
  673. String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
  674. CreateObjUtil.convertTxtToDam(path + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", damPath);
  675. FileUtil.writeBytes(ZipUtil.gzip(new File(damPath)), damPath);
  676. map.put(damPath, imagesPath + ConstantFileName.modelUUID + "_50k.dam");
  677. }else{
  678. List<String> list = FileUtils.list(new File(path + File.separator + "results" + File.separator + ModelKind.THREE_D_TILE.code()));
  679. if(CollUtil.isEmpty(list)){
  680. log.error("3dtiles目录异常,3dtiles地址:{}", new File(path + File.separator + "results" + File.separator + ModelKind.THREE_D_TILE.code()));
  681. throw new Exception("3dtiles目录异常");
  682. }
  683. list.stream().forEach(str->{
  684. map.put(str, str.replace(path + File.separator + "results" + File.separator, imagesPath));
  685. });
  686. }
  687. }
  688. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision.txt", resultsPath + "vision.modeldata");
  689. map.put(resultsPath + "vision.txt", imagesPath + "vision.txt");
  690. map.put(resultsPath + "vision.modeldata", imagesPath + "vision.modeldata");
  691. log.info("数据转换完成:" + projectNum);
  692. if(!new File("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum).exists()){
  693. FileUtil.mkdir("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum);
  694. }
  695. // map.put(resultsPath + "floorplan.json", dataViewPath + "floor.json");
  696. map.put(resultsPath + "floorplan_cad.json", dataViewPath + "floorplan_cad.json");
  697. map.put(path + File.separator + "capture/stitch_params.txt", dataViewPath + "stitch_params.txt");
  698. map.put(path + File.separator + "capture/Up.xml", dataViewPath + "Up.xml");
  699. map.put(path + File.separator + "capture/Up2.xml", dataViewPath + "Up2.xml");
  700. map.put(path + File.separator + "capture/Up.txt", dataViewPath + "Up.txt");
  701. map.put(path + File.separator + "capture/Up2.txt", dataViewPath + "Up2.txt");
  702. return map;
  703. }
  704. }