CommonServiceImpl.java 40 KB

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