CommonServiceImpl.java 39 KB

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