CommonServiceImpl.java 45 KB

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