CommonServiceImpl.java 47 KB

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