CommonServiceImpl.java 37 KB

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