CommonServiceImpl.java 49 KB

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