BuildLiguangServiceImpl.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. package com.fdkankan.contro.mq.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import cn.hutool.core.util.ZipUtil;
  6. import cn.hutool.extra.qrcode.QrCodeUtil;
  7. import cn.hutool.extra.qrcode.QrConfig;
  8. import cn.hutool.http.ContentType;
  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.update.LambdaUpdateWrapper;
  14. import com.fdkankan.common.constant.*;
  15. import com.fdkankan.common.util.FileUtils;
  16. import com.fdkankan.contro.bean.SyncLaserResultBean;
  17. import com.fdkankan.contro.constant.UserEditDataType;
  18. import com.fdkankan.contro.entity.*;
  19. import com.fdkankan.contro.mq.service.IBuildSceneService;
  20. import com.fdkankan.contro.service.*;
  21. import com.fdkankan.fyun.config.FYunFileConfig;
  22. import com.fdkankan.fyun.constant.FYunTypeEnum;
  23. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  24. import com.fdkankan.model.constants.ConstantFileName;
  25. import com.fdkankan.model.constants.ConstantFilePath;
  26. import com.fdkankan.model.constants.UploadFilePath;
  27. import com.fdkankan.model.enums.ModelTypeEnums;
  28. import com.fdkankan.model.utils.CreateHouseJsonUtil;
  29. import com.fdkankan.model.utils.CreateObjUtil;
  30. import com.fdkankan.model.utils.SceneUtil;
  31. import com.fdkankan.push.config.PushMessageConfig;
  32. import com.fdkankan.push.utils.PushMsgUtil;
  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.util.RedisUtil;
  37. import lombok.extern.slf4j.Slf4j;
  38. import org.apache.commons.lang3.ObjectUtils;
  39. import org.apache.http.HttpHeaders;
  40. import org.springframework.beans.factory.annotation.Autowired;
  41. import org.springframework.beans.factory.annotation.Value;
  42. import org.springframework.cloud.context.config.annotation.RefreshScope;
  43. import org.springframework.stereotype.Service;
  44. import javax.annotation.Resource;
  45. import java.io.File;
  46. import java.io.IOException;
  47. import java.util.*;
  48. import java.util.Map.Entry;
  49. /**
  50. * <p>
  51. * TODO
  52. * </p>
  53. *
  54. * @author dengsixing
  55. * @since 2022/4/20
  56. **/
  57. @Slf4j
  58. @Service
  59. @RefreshScope
  60. public class BuildLiguangServiceImpl implements IBuildSceneService {
  61. @Value("${queue.modeling.modeling-call}")
  62. private String queueModelingCall;
  63. @Value("${queue.modeling.single.modeling-call}")
  64. private String singleModelingCall;
  65. @Value("${model.type:#{null}}")
  66. private String modelType;
  67. @Value("${env:gn}")
  68. private String env;
  69. @Value("#{'${build.scene.post.not-delete-nas-nums:}'.split(',')}")
  70. private List<String> notDeleteNasNumList;
  71. @Value("4dkk.laserService.bucket")
  72. private String laserBucket;
  73. @Autowired
  74. private RabbitMqProducer mqProducer;
  75. @Resource
  76. private FYunFileServiceInterface fYunFileService;
  77. @Autowired
  78. private ICameraDetailService cameraDetailService;
  79. @Autowired
  80. private ISceneEditInfoService sceneEditInfoService;
  81. @Autowired
  82. private ISceneEditControlsService sceneEditControlsService;
  83. @Autowired
  84. private FYunFileConfig fYunFileConfig;
  85. @Autowired
  86. private RedisUtil redisUtil;
  87. @Autowired
  88. private IScenePlusService scenePlusService;
  89. @Autowired
  90. private IScenePlusExtService scenePlusExtService;
  91. @Autowired
  92. private ISceneEditInfoExtService sceneEditInfoExtService;
  93. @Autowired
  94. private IUserIncrementService userIncrementService;
  95. @Autowired
  96. private IFdkkLaserService fdkkLaserService;
  97. @Autowired
  98. private IBuildSceneDTService buildSceneDTService;
  99. @Autowired
  100. private IIncrementTypeService incrementTypeService;
  101. @Autowired
  102. private ICompanyService companyService;
  103. @Autowired
  104. private ISceneAsynOperLogService sceneAsynOperLogService;
  105. @Autowired
  106. private ICommonService commonService;
  107. @Autowired
  108. private ISceneBuildProcessLogService sceneBuildProcessLogService;
  109. @Autowired
  110. private ISceneColdStorageService sceneColdStorageService;
  111. @Override
  112. public void buildScenePre(BuildSceneCallMessage message) throws Exception{
  113. String num = message.getSceneNum();
  114. try {
  115. //重新计算时需要删除文件夹,否知使用缓存
  116. if(new File(message.getPath() + File.separator + "results").exists()){
  117. FileUtils.deleteDirectory(message.getPath() + File.separator + "results");
  118. }
  119. //由于刘强说caches会影响计算结果,所以这里删除caches
  120. if(new File(message.getPath() + File.separator + "caches").exists()){
  121. FileUtils.deleteDirectory(message.getPath() + File.separator + "caches");
  122. }
  123. //删除点位校准数据
  124. if (Objects.nonNull(message.getExt())
  125. && message.getExt().containsKey("deleteExtras")
  126. && (Boolean) message.getExt().get("deleteExtras")) {
  127. String extras = String.format(UploadFilePath.scene_result_data_path, num).concat("extras");
  128. if(CollUtil.isNotEmpty(fYunFileService.listRemoteFiles(extras))){
  129. fYunFileService.deleteFolder(extras);
  130. }
  131. }
  132. //根据相机类型,组装资源路径
  133. //下载资源到本地
  134. this.downLoadSource(message, message.getPath());
  135. message.getBuildContext().put("cameraType",message.getCameraType());
  136. message.setBizType("standard");
  137. log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
  138. }catch (Exception e){
  139. log.error("场景计算前置处理出错,num"+num, e);
  140. buildSceneDTService.handBaseFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
  141. throw e;
  142. }
  143. }
  144. private String getOssPath(String path) {
  145. String ossPath = ConstantFilePath.OSS_PREFIX
  146. + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  147. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  148. if (!ossPath.endsWith("/")) {
  149. ossPath = ossPath.concat("/");
  150. }
  151. return ossPath;
  152. }
  153. @Override
  154. public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
  155. String ossPath = (String) buildSceneMqMessage.getExt().get("ossPath");
  156. fYunFileService.downloadFileByCommand(path + File.separator + "capture", ossPath);
  157. }
  158. @Override
  159. public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
  160. String sceneCode = message.getBuildContext().get("sceneNum").toString();
  161. String path = message.getPath();
  162. try {
  163. // 上传计算日志
  164. //如果是重复计算,没有走到计算逻辑,不需要上传日志文件
  165. log.info("开始上传计算日志");
  166. String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneCode);
  167. fYunFileService.uploadFile(path + File.separator + "console.log", buildLogPath + "console.log");
  168. log.info("计算日志上传完成");
  169. if (!message.getBuildSuccess()) {
  170. log.error("建模失败,修改状态为失败状态");
  171. scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
  172. .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
  173. .eq(ScenePlus::getNum, sceneCode));
  174. // 发送钉钉消息,计算失败
  175. buildSceneDTService.handModelFail("计算失败", message.getPath(), sceneCode, message.getHostName());
  176. return;
  177. }
  178. JSONObject fdageData = commonService.getFdageData(path + File.separator + "capture" +File.separator+"data.fdage");
  179. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
  180. Integer cameraType = Integer.parseInt(message.getBuildContext().get("cameraType").toString());
  181. Map<String, String> uploadFiles = commonService.getUploadFiles(scenePlus,path,cameraType,fdageData);
  182. scenePlus.setPayStatus(PayStatus.PAY.code());
  183. scenePlus.setUpdateTime(new Date());
  184. scenePlus.setSceneStatus(SceneStatus.NO_DISPLAY.code());
  185. Integer videoVersion = fdageData.getInteger("videoVersion");
  186. //读取计算结果文件生成videosJson
  187. JSONObject videosJson = commonService.getVideosJson(path, videoVersion, sceneCode, cameraType);
  188. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  189. boolean isObj = fdageData.containsKey("exportMeshObj") && fdageData.getIntValue("exportMeshObj") == 1;
  190. //上传全景图俯视图
  191. this.uploadFloorCad(path, sceneCode, uploadFiles);
  192. log.info("开始上传场景计算结果数据,num:{}", sceneCode);
  193. //由于3dtiles算法mesh文件发生变化,所以这里需要先清除一下oss的mesh目录,避免存在旧算法obj文件
  194. fYunFileService.deleteFolder(String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode) + "mesh");
  195. fYunFileService.deleteFolder(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ModelKind.THREE_D_TILE.code());
  196. //上传文件
  197. fYunFileService.uploadMulFiles(uploadFiles);
  198. //修改oss上dam的内容编码
  199. Map<String,String> damFileHeaders = new HashMap<>();
  200. damFileHeaders.put("Content-Encoding","gzip");
  201. String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
  202. fYunFileService.uploadFile(damPath, String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ConstantFileName.modelUUID + "_50k.dam", damFileHeaders);
  203. //拷贝部分文件到编辑目录,用于用户编辑
  204. this.copyToEditDir(sceneCode);
  205. //计算完毕后,同步全景图到缓存目录
  206. // this.cachePanorama(path, sceneCode);
  207. //生成houseTypejson并上传
  208. boolean existHouseType = this.uploadHouseTypeJson(sceneCode, path);
  209. scenePlus.setHouseType(existHouseType ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue());
  210. //生成floorpan.json
  211. commonService.uploadFloorplanJson(sceneCode, path);
  212. //重置异步操作记录
  213. commonService.removeSceneAsynOperLog(sceneCode);
  214. //清除用户编辑业务数据
  215. Set<String> bizs = new HashSet<>();
  216. bizs.add(UserEditDataType.BOX_MODEL.message());
  217. bizs.add(UserEditDataType.FLOORPLAN.message());
  218. bizs.add(UserEditDataType.FILTERS.message());
  219. commonService.initUserEditData(sceneCode, bizs, null);
  220. //上传计算结果文件
  221. commonService.uploadBuildResultData(sceneCode, path, SceneVersionType.V4.code());
  222. //容量统计
  223. Long space = commonService.getSpace(sceneCode);
  224. //写入数据库
  225. this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), message.getComputeTime(),isObj,scenePlusExt);
  226. Object[] editInfoArr = commonService.updateEditInfo(scenePlus);
  227. SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
  228. SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
  229. SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
  230. //更新场景主表
  231. //如果相机容量不足,需要把场景的paystatus改为容量不足状态
  232. scenePlus.setPayStatus(commonService.getPayStatus(scenePlus.getCameraId(), space, null));
  233. //统计原始资源大小
  234. scenePlusExt.setOrigSpace(FileUtil.size(new File(path.concat(File.separator).concat("capture"))));
  235. if (new File(path + "/results/laserData/vision_edit.txt").exists()) {
  236. fdkkLaserService.cloudPointBuild(sceneCode,path);
  237. }
  238. log.info("生成scene.json上传oss并设置缓存,num:{}", sceneCode);
  239. CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
  240. Company company = !ObjectUtils.isEmpty(cameraDetail.getCompanyId()) ? companyService.getById(cameraDetail.getCompanyId()) : null;
  241. //写scene.json
  242. commonService.writeSceneJson(sceneCode,sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus,scenePlusExt,company);
  243. String qrLogo = !ObjectUtils.isEmpty(company) && !ObjectUtils.isEmpty(company.getQrLogo()) ? company.getQrLogo() : null;
  244. qrLogo = ObjectUtils.isEmpty(qrLogo) && !ObjectUtils.isEmpty(sceneEditInfoExt.getShareLogoImg()) ? fYunFileConfig.getHost().concat(sceneEditInfoExt.getShareLogoImg()) : null;
  245. createQrCode(sceneCode, scenePlusExt, qrLogo);
  246. // //删除计算目录
  247. if(CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)){
  248. CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/"));
  249. }
  250. this.uploadStatusJson(scenePlus, scenePlusExt);
  251. scenePlusService.updateById(scenePlus);
  252. scenePlusExtService.updateById(scenePlusExt);
  253. log.info("场景计算结果处理结束,场景码:{}", sceneCode);
  254. }catch (Exception e){
  255. log.error("场景计算结果处理出错,num"+sceneCode, e);
  256. buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
  257. throw e;
  258. }
  259. }
  260. // private void cachePanorama(String dataSource, String num){
  261. // String cachedImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
  262. // //将全景图缓存到缓存目录
  263. // List<String> imagesList = FileUtil.listFileNames(dataSource + "/caches/images");
  264. // //先清除旧的全景图
  265. // cn.hutool.core.io.FileUtil.del(cachedImagesPath);
  266. // String visionPath = dataSource + "/results/vision.txt";
  267. // List<String> panoramaImageList = SceneUtil.getPanoramaImageList(visionPath);
  268. // imagesList.stream().forEach(fileName -> {
  269. // if (panoramaImageList.contains(fileName)) {
  270. // String srcPath = dataSource + "/caches/images/" + fileName;
  271. // String targetPath = cachedImagesPath + fileName;
  272. // log.info("源文件:{}, 目标文件:{}", srcPath, targetPath);
  273. // cn.hutool.core.io.FileUtil.copy(srcPath, targetPath, true);
  274. // }
  275. // });
  276. // }
  277. private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles){
  278. //户型图上传
  279. String dataViewPath = UploadFilePath.DATA_VIEW_PATH + "floor-cad-%s.%s";
  280. String floorCadPath = path + "/results/floorplan_cad";
  281. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  282. if(CollUtil.isNotEmpty(floorCadList)){
  283. floorCadList.stream().forEach(str->{
  284. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  285. String[] arr = substring.split("floor");
  286. String[] arr2 = arr[1].split("\\.");
  287. uploadFiles.put(str, String.format(dataViewPath, num, arr2[0], arr2[1]));
  288. });
  289. }
  290. }
  291. private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt){
  292. String num = scenePlus.getNum();
  293. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  294. Integer status = 1;
  295. if(scenePlus.getSceneSource() == 4 || scenePlus.getSceneSource() == 5){//如果是激光场景,需要激光系统那边完全处理好之后再发mq通知更新状态
  296. status = 0;
  297. }
  298. // 上传status JSON.
  299. JSONObject statusJson = new JSONObject();
  300. //临时将-2改成1,app还没完全更新
  301. statusJson.put("status", status);
  302. statusJson.put("webSite", scenePlusExt.getWebSite());
  303. statusJson.put("sceneNum", num);
  304. statusJson.put("thumb", scenePlusExt.getThumb());
  305. statusJson.put("payStatus", scenePlus.getPayStatus());
  306. statusJson.put("sceneScheme", scenePlusExt.getSceneScheme());
  307. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
  308. Map<String,String> headers = new HashMap<>();
  309. headers.put(HttpHeaders.CONTENT_TYPE, ContentType.JSON.getValue());
  310. fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", dataViewPath + "status.json", headers);
  311. }
  312. private void createQrCode(String num, ScenePlusExt scenePlusExt, String qrLogo) {
  313. String localLogoPath = null;
  314. if (!ObjectUtils.isEmpty(qrLogo)) {
  315. try {
  316. localLogoPath = ConstantFilePath.AGENT_PATH + qrLogo.substring(qrLogo.lastIndexOf("//") + 1);
  317. HttpUtil.downloadFile(qrLogo, localLogoPath);
  318. } catch (Exception e) {
  319. log.error("公司logo下载失败:{}", qrLogo);
  320. localLogoPath = null;
  321. }
  322. }
  323. //生成二维码
  324. String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png";
  325. String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png";
  326. QrConfig qrConfig = QrConfig.create();
  327. qrConfig.setWidth(1024);
  328. qrConfig.setHeight(1024);
  329. if(StrUtil.isNotEmpty(localLogoPath)){
  330. qrConfig.setImg(localLogoPath);
  331. }
  332. QrCodeUtil.generate(scenePlusExt.getWebSite(), qrConfig, FileUtil.file(outPathZh));
  333. QrCodeUtil.generate(scenePlusExt.getWebSite() + "&lang=en", qrConfig, FileUtil.file(outPathEn));
  334. //上传二维码
  335. fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
  336. fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
  337. if(!ObjectUtils.isEmpty(localLogoPath)){
  338. FileUtils.deleteFile(localLogoPath);
  339. }
  340. }
  341. private void pushMsgToApp(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
  342. log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
  343. if(Objects.isNull(pushChannel) || StrUtil.isBlank(pushToken)){
  344. return;
  345. }
  346. String title = sceneName + "计算完成";
  347. String body = "您上传的" + sceneName + "计算完成,点击查看";
  348. try{
  349. if(FYunTypeEnum.AWS.code().equals(fYunFileService.getFyunType())){
  350. PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
  351. title, body , webSite);
  352. return;
  353. }
  354. PushMessageConfig pushConfig = null;
  355. if(pushChannel == 0){
  356. if(cameraType == 10 || cameraType == 13){
  357. //ios
  358. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY_Z, PushMessageConfig.IOS_SECRET_Z);
  359. pushConfig.sendIOSUnicast(pushToken, "四维看看Minion",title, body, webSite);
  360. }else {
  361. //ios
  362. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY, PushMessageConfig.IOS_SECRET);
  363. pushConfig.sendIOSUnicast(pushToken, "四维看看Pro",title, body, webSite);
  364. }
  365. }else {
  366. if(cameraType == 10 || cameraType == 13){
  367. //ios
  368. //安卓
  369. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY_Z, PushMessageConfig.ANDROID_SECRET_Z);
  370. pushConfig.sendAndroidUnicast2(pushToken, "四维看看Minion",title, body, webSite);
  371. }else {
  372. //安卓
  373. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY, PushMessageConfig.ANDROID_SECRET);
  374. pushConfig.sendAndroidUnicast(pushToken, "四维看看Pro",title, body, webSite);
  375. }
  376. }
  377. log.info("消息推送结束!");
  378. }catch (Exception e){
  379. log.error("推送消息失败:", e);
  380. }
  381. }
  382. private void copyToEditDir(String num) throws IOException {
  383. String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  384. String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  385. String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
  386. String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  387. Map<String, String> map = new HashMap<>();
  388. map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
  389. map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
  390. map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
  391. for (Entry<String, String> entry : map.entrySet()) {
  392. fYunFileService.copyFileInBucket(entry.getValue(), entry.getKey());
  393. }
  394. }
  395. private void updateDbPlus(int sceneSource,Long space,String videosJson, Long computeTime,boolean isObj,ScenePlusExt scenePlusExt){
  396. scenePlusExt.setSpace(space);
  397. scenePlusExt.setComputeTime(computeTime);
  398. scenePlusExt.setAlgorithmTime(new Date());
  399. scenePlusExt.setVideos(videosJson);
  400. scenePlusExt.setIsObj(isObj ? 1 : 0);
  401. if(ModelTypeEnums.TILE_CODE.equals(modelType)){
  402. scenePlusExt.setSceneScheme(3);
  403. }
  404. switch (SceneSource.get(sceneSource)){
  405. case BM:
  406. scenePlusExt.setSceneResolution(SceneResolution.two_K.code());
  407. scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
  408. break;
  409. case SM:
  410. scenePlusExt.setSceneResolution(SceneResolution.one_k.code());
  411. scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
  412. break;
  413. case ZT:
  414. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  415. scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
  416. break;
  417. case JG:
  418. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  419. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  420. break;
  421. case SG:
  422. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  423. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  424. break;
  425. }
  426. String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
  427. scenePlusExt.setSceneKind(sceneKind);
  428. // scenePlusExt.setModelKind(modelKind);
  429. //统计点位数量
  430. Map<String, Integer> result = this.getShootCount(scenePlusExt);
  431. Integer shootCount = result.get("shootCount");
  432. Integer mixture = result.get("mixture");
  433. scenePlusExt.setShootCount(shootCount);
  434. scenePlusExt.setMixture(mixture);
  435. scenePlusExtService.updateById(scenePlusExt);
  436. }
  437. private Map<String, Integer> getShootCount(ScenePlusExt scenePlusExt){
  438. Map<String, Integer> result = new HashMap<>();
  439. Integer shootCount = 0;
  440. Integer mixture = Objects.isNull(scenePlusExt.getMixture()) ? 0 : scenePlusExt.getMixture();
  441. String homePath = SceneUtil.getHomePath(scenePlusExt.getDataSource());
  442. JSONObject dataFdageObj = JSON.parseObject(fYunFileService.getFileContent(homePath.concat("data.fdage")));
  443. if(Objects.nonNull(dataFdageObj)){
  444. JSONArray points = dataFdageObj.getJSONArray("points");
  445. if(CollUtil.isNotEmpty(points)){
  446. shootCount = points.size();
  447. }
  448. }
  449. if(Objects.nonNull(shootCount) && shootCount > 0){
  450. if(Objects.nonNull(scenePlusExt.getLocation()) && scenePlusExt.getLocation() == 6){
  451. mixture = CommonStatus.YES.code().intValue();
  452. }
  453. }else{
  454. String slamDataStr = fYunFileService.getFileContent(homePath.concat("slam_data.json"));
  455. JSONObject slamDataObj = JSON.parseObject(slamDataStr);
  456. if(Objects.nonNull(slamDataObj)){
  457. JSONArray viewsInfo = slamDataObj.getJSONArray("views_info");
  458. if(CollUtil.isNotEmpty(viewsInfo)){
  459. shootCount = viewsInfo.stream().mapToInt(info -> {
  460. return ((JSONObject) info).getJSONArray("list_pose").size();
  461. }).sum();
  462. }
  463. }
  464. mixture = CommonStatus.NO.code().intValue();
  465. }
  466. result.put("shootCount", shootCount);
  467. result.put("mixture", mixture);
  468. return result;
  469. }
  470. public static void main(String[] args) {
  471. JSONObject dataFdageObj = JSON.parseObject(null);
  472. System.out.println(dataFdageObj);
  473. }
  474. public boolean uploadHouseTypeJson(String num, String dataSource) {
  475. String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
  476. if (!new File(floorPlanCardFilePath).exists()) {
  477. log.warn("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  478. return false;
  479. }
  480. JSONObject json = CreateHouseJsonUtil.createHouseTypeJsonByCad(floorPlanCardFilePath);
  481. if(Objects.isNull(json)){
  482. return false;
  483. }
  484. String hourseTypeJsonPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "houseType.json";
  485. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  486. hourseTypeJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "houseType.json";
  487. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  488. return true;
  489. }
  490. }