CommonServiceImpl.java 47 KB

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