BuildSceneServiceImpl.java 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. package com.fdkankan.contro.mq.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.io.file.FileNameUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import cn.hutool.core.util.ZipUtil;
  8. import cn.hutool.extra.qrcode.QrCodeUtil;
  9. import cn.hutool.extra.qrcode.QrConfig;
  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.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  16. import com.fdkankan.common.constant.*;
  17. import com.fdkankan.common.util.FileUtils;
  18. import com.fdkankan.contro.bean.SceneJsonBean;
  19. import com.fdkankan.contro.constant.UserEditDataType;
  20. import com.fdkankan.contro.entity.*;
  21. import com.fdkankan.contro.mq.service.IBuildSceneService;
  22. import com.fdkankan.contro.service.*;
  23. import com.fdkankan.contro.vo.SceneEditControlsVO;
  24. import com.fdkankan.fyun.config.FYunFileConfig;
  25. import com.fdkankan.fyun.constant.FYunTypeEnum;
  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.enums.ModelTypeEnums;
  31. import com.fdkankan.model.utils.CreateHouseJsonUtil;
  32. import com.fdkankan.model.utils.CreateObjUtil;
  33. import com.fdkankan.push.config.PushMessageConfig;
  34. import com.fdkankan.push.utils.PushMsgUtil;
  35. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  36. import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
  37. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  38. import com.fdkankan.redis.constant.RedisKey;
  39. import com.fdkankan.redis.util.RedisUtil;
  40. import lombok.extern.slf4j.Slf4j;
  41. import org.apache.commons.lang3.ObjectUtils;
  42. import org.apache.commons.lang3.StringUtils;
  43. import org.springframework.beans.factory.annotation.Autowired;
  44. import org.springframework.beans.factory.annotation.Value;
  45. import org.springframework.cloud.context.config.annotation.RefreshScope;
  46. import org.springframework.stereotype.Service;
  47. import java.io.File;
  48. import java.io.IOException;
  49. import java.util.*;
  50. import java.util.Map.Entry;
  51. import java.util.stream.Collectors;
  52. /**
  53. * <p>
  54. * </p>
  55. *
  56. * @author dengsixing
  57. * @since 2022/4/20
  58. **/
  59. @Slf4j
  60. @Service
  61. @RefreshScope
  62. public class BuildSceneServiceImpl implements IBuildSceneService {
  63. @Value("${queue.modeling.modeling-call}")
  64. private String queueModelingCall;
  65. @Value("${queue.modeling.single.modeling-call}")
  66. private String singleModelingCall;
  67. @Value("${queue.modeling.modeling-progress-notice}")
  68. private String modelingProgressNotice;
  69. @Value("${model.type:#{null}}")
  70. private String modelType;
  71. @Value("${build.progress.url}")
  72. public String buildProgressUrl;
  73. @Value("${model.modelKind:3dtiles}")
  74. private String modelKind;
  75. @Value("#{'${model.3dtiles.sceneSource:}'.split(',')}")
  76. private List<Integer> sdTilesSceneSourceList;
  77. @Value("${env:gn}")
  78. private String env;
  79. @Value("#{'${build.scene.post.not-delete-nas-nums:}'.split(',')}")
  80. private List<String> notDeleteNasNumList;
  81. @Autowired
  82. private RabbitMqProducer mqProducer;
  83. @Autowired
  84. private FYunFileServiceInterface fYunFileService;
  85. @Autowired
  86. private ICameraDetailService cameraDetailService;
  87. @Autowired
  88. private ISceneEditInfoService sceneEditInfoService;
  89. @Autowired
  90. private ISceneEditControlsService sceneEditControlsService;
  91. @Autowired
  92. private FYunFileConfig fYunFileConfig;
  93. @Autowired
  94. private RedisUtil redisUtil;
  95. @Autowired
  96. private IScenePlusService scenePlusService;
  97. @Autowired
  98. private IScenePlusExtService scenePlusExtService;
  99. @Autowired
  100. private ISceneEditInfoExtService sceneEditInfoExtService;
  101. @Autowired
  102. private IUserIncrementService userIncrementService;
  103. @Autowired
  104. private IFdkkLaserService fdkkLaserService;
  105. // @Autowired
  106. // private IBuildSceneDTService buildSceneDTService;
  107. @Autowired
  108. private IIncrementTypeService incrementTypeService;
  109. @Autowired
  110. private ICompanyService companyService;
  111. @Autowired
  112. private ISceneAsynOperLogService sceneAsynOperLogService;
  113. @Autowired
  114. private ICommonService commonService;
  115. @Autowired
  116. private ISceneBuildProcessLogService sceneBuildProcessLogService;
  117. @Autowired
  118. private ISceneColdStorageService sceneColdStorageService;
  119. @Autowired
  120. private IOrigFileUploadBatchService
  121. @Override
  122. public void buildScenePre(BuildSceneCallMessage message) throws Exception{
  123. boolean success = false;
  124. String num = message.getSceneNum();
  125. String batchId = (String) message.getExt().get("batchId");
  126. try {
  127. if(StrUtil.isNotEmpty(batchId)){
  128. }
  129. //开始计算前发送mq消息,监听project.json文件的变化以更新进度条
  130. mqProducer.sendByWorkQueue(modelingProgressNotice, message);
  131. //重新计算时需要删除文件夹,否知使用缓存
  132. if(new File(message.getPath() + File.separator + "results").exists()){
  133. FileUtils.deleteDirectory(message.getPath() + File.separator + "results");
  134. }
  135. //由于刘强说caches会影响计算结果,所以这里删除caches
  136. if(new File(message.getPath() + File.separator + "caches").exists()){
  137. FileUtils.deleteDirectory(message.getPath() + File.separator + "caches");
  138. }
  139. //删除project.json文件
  140. FileUtil.del(message.getPath().concat(File.separator).concat("project.json"));
  141. //删除点位校准数据
  142. if (Objects.nonNull(message.getExt())
  143. && message.getExt().containsKey("deleteExtras")
  144. && (Boolean) message.getExt().get("deleteExtras")) {
  145. String extras = String.format(UploadFilePath.scene_result_data_path, num).concat("extras");
  146. if(CollUtil.isNotEmpty(fYunFileService.listRemoteFiles(extras))){
  147. fYunFileService.deleteFolder(extras);
  148. }
  149. }
  150. // //用户相机重新全量上传,需要解冻结
  151. // sceneColdStorageService.unfreeze(num, "用户相机重新全量上传", message.getPath());
  152. //根据相机类型,组装资源路径
  153. //下载资源到本地
  154. this.downLoadSource(message, message.getPath());
  155. JSONObject fdageJson = JSONObject.parseObject(FileUtils.readFile(message.getPath().concat("/capture/data.fdage")));
  156. boolean rewrite = false;
  157. // 兼容旧的数据,防止OnlyExportMeshObj标志未删除掉
  158. if (fdageJson.containsKey("OnlyExportMeshObj")) {
  159. log.info("data.fdage 包含 OnlyExportMeshObj,进行去除!");
  160. // 写入data.fdage 防止重算
  161. fdageJson.remove("OnlyExportMeshObj");
  162. String ossPath = getOssPath(message.getPath());
  163. fYunFileService.uploadFile(fdageJson.toJSONString().getBytes(), ossPath + "data.fdage");
  164. rewrite = true;
  165. }
  166. if (!ObjectUtils.isEmpty(modelType)) {
  167. // 修改dataFdage文件
  168. fdageJson.put("modelType", modelType);
  169. rewrite = true;
  170. }
  171. if (rewrite) {
  172. FileUtils.writeFile(message.getPath().concat("/capture/data.fdage"), fdageJson.toJSONString());
  173. }
  174. message.getBuildContext().put("cameraType",message.getCameraType());
  175. // 判断企业是否配置了弹性伸缩
  176. if (message.getFlexibility() == 0) {
  177. //发送mq,就进行计算
  178. mqProducer.sendByWorkQueue(queueModelingCall, message);
  179. } else {
  180. //发送mq,就进行计算
  181. mqProducer.sendByWorkQueue(singleModelingCall, message);
  182. }
  183. success = true;
  184. log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
  185. }catch (Exception e){
  186. log.error("场景计算前置处理出错,num"+num, e);
  187. // buildSceneDTService.handBaseFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
  188. throw e;
  189. }
  190. }
  191. private String getOssPath(String path) {
  192. String ossPath = ConstantFilePath.OSS_PREFIX
  193. + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  194. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  195. if (!ossPath.endsWith("/")) {
  196. ossPath = ossPath.concat("/");
  197. }
  198. return ossPath;
  199. }
  200. @Override
  201. public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
  202. String ossPath = getOssPath(path);
  203. fYunFileService.downloadFileByCommand(path + File.separator + "capture", ossPath);
  204. }
  205. @Override
  206. public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
  207. String sceneCode = message.getBuildContext().get("sceneNum").toString();
  208. String path = message.getPath();
  209. try {
  210. // 上传计算日志
  211. //如果是重复计算,没有走到计算逻辑,不需要上传日志文件
  212. log.info("开始上传计算日志");
  213. String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneCode);
  214. fYunFileService.uploadFile(path + File.separator + "console.log", buildLogPath + "console.log");
  215. log.info("计算日志上传完成");
  216. if (!message.getBuildSuccess()) {
  217. log.error("建模失败,修改状态为失败状态");
  218. scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
  219. .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
  220. .eq(ScenePlus::getNum, sceneCode));
  221. redisUtil.set(String.format(RedisKey.SCENE_BUILD_FINISH_NUM, sceneCode), "-1");
  222. return;
  223. }
  224. JSONObject fdageData = getFdageData(path + File.separator + "capture" +File.separator+"data.fdage");
  225. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
  226. Integer cameraType = Integer.parseInt(message.getBuildContext().get("cameraType").toString());
  227. Map<String, String> uploadFiles = getUploadFiles(scenePlus,path,cameraType,fdageData);
  228. scenePlus.setPayStatus(PayStatus.PAY.code());
  229. scenePlus.setUpdateTime(new Date());
  230. scenePlus.setSceneStatus(SceneStatus.NO_DISPLAY.code());
  231. Integer videoVersion = fdageData.getInteger("videoVersion");
  232. //读取计算结果文件生成videosJson
  233. JSONObject videosJson = this.getVideosJson(path, videoVersion, sceneCode, cameraType);
  234. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  235. boolean isObj = fdageData.containsKey("exportMeshObj") && fdageData.getIntValue("exportMeshObj") == 1;
  236. //上传全景图俯视图
  237. this.uploadFloorCad(path, sceneCode, uploadFiles);
  238. log.info("开始上传场景计算结果数据,num:{}", sceneCode);
  239. //由于3dtiles算法mesh文件发生变化,所以这里需要先清除一下oss的mesh目录,避免存在旧算法obj文件
  240. fYunFileService.deleteFolder(String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode) + "mesh");
  241. //上传文件
  242. fYunFileService.uploadMulFiles(uploadFiles);
  243. //修改oss上dam的内容编码
  244. // Map<String,String> damFileHeaders = new HashMap<>();
  245. // damFileHeaders.put("Content-Encoding","gzip");
  246. // String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
  247. // fYunFileService.uploadFile(damPath, String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ConstantFileName.modelUUID + "_50k.dam", damFileHeaders);
  248. //拷贝部分文件到编辑目录,用于用户编辑
  249. this.copyToEditDir(sceneCode);
  250. //计算完毕后,同步全景图到缓存目录
  251. // this.cachePanorama(path, sceneCode);
  252. //生成houseTypejson并上传
  253. boolean existHouseType = this.uploadHouseTypeJson(sceneCode, path);
  254. scenePlus.setHouseType(existHouseType ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue());
  255. //生成floorpan.json
  256. commonService.uploadFloorplanJson(sceneCode, path);
  257. //重置异步操作记录
  258. this.removeSceneAsynOperLog(sceneCode);
  259. //清除用户编辑业务数据
  260. Set<String> bizs = new HashSet<>();
  261. bizs.add(UserEditDataType.BOX_MODEL.message());
  262. bizs.add(UserEditDataType.FLOORPLAN.message());
  263. commonService.initUserEditData(sceneCode, bizs, null);
  264. //上传计算结果文件
  265. commonService.uploadBuildResultData(sceneCode, path, SceneVersionType.V4.code());
  266. //容量统计
  267. Long space = commonService.getSpace(sceneCode);
  268. //写入数据库
  269. this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), message.getComputeTime(),isObj,scenePlusExt);
  270. Object[] editInfoArr = this.updateEditInfo(scenePlus);
  271. SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
  272. SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
  273. SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
  274. if (cameraType == 14) {
  275. //计算成功 激光转台相机 同步 请求
  276. fdkkLaserService.syncBuildResult(scenePlus.getNum(), path, scenePlus.getCreateTime(), Calendar.getInstance().getTime());
  277. sceneEditControlsService.update(new LambdaUpdateWrapper<SceneEditControls>().set(SceneEditControls::getShowMap,0)
  278. .eq(SceneEditControls::getEditInfoId,sceneEditInfo.getId()));
  279. sceneEditControls.setShowMap(0);
  280. } else if (new File(path + "/results/laserData/vision_edit.txt").exists()) {
  281. fdkkLaserService.cloudPointBuild(sceneCode,path);
  282. }
  283. log.info("生成scene.json上传oss并设置缓存,num:{}", sceneCode);
  284. CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
  285. Company company = !ObjectUtils.isEmpty(cameraDetail.getCompanyId()) ? companyService.getById(cameraDetail.getCompanyId()) : null;
  286. //写scene.json
  287. this.writeSceneJson(sceneCode, videosJson,sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus,scenePlusExt,company);
  288. String qrLogo = !ObjectUtils.isEmpty(company) && !ObjectUtils.isEmpty(company.getQrLogo()) ? company.getQrLogo() : null;
  289. qrLogo = ObjectUtils.isEmpty(qrLogo) && !ObjectUtils.isEmpty(sceneEditInfoExt.getShareLogoImg()) ? fYunFileConfig.getHost().concat(sceneEditInfoExt.getShareLogoImg()) : null;
  290. createQrCode(sceneCode, scenePlusExt, qrLogo);
  291. //计算成功,通知APP
  292. Integer pushChannel = fdageData.getInteger("pushChannel");
  293. String pushToken = fdageData.getString("pushToken");
  294. this.pushMsgToApp(pushChannel,pushToken, cameraType, scenePlus.getTitle(), scenePlusExt.getWebSite());
  295. //删除计算目录
  296. // if(CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)){
  297. // CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/"));
  298. // }
  299. //更新场景主表
  300. //如果相机容量不足,需要把场景的paystatus改为容量不足状态
  301. if (cameraType != 14) {
  302. scenePlus.setPayStatus(commonService.getPayStatus(scenePlus.getCameraId(), space));
  303. }
  304. this.uploadStatusJson(scenePlus, scenePlusExt);
  305. scenePlusService.updateById(scenePlus);
  306. //国际环境需要发邮件通知
  307. if("eur".equals(env)){
  308. commonService.sendEmail(sceneCode);
  309. }
  310. redisUtil.set(String.format(RedisKey.SCENE_BUILD_FINISH_NUM, sceneCode), "1");
  311. Map<String, Object> ext = message.getExt();
  312. Map<String, Object> params = new HashMap<>();
  313. params.put("website", scenePlusExt.getWebSite());
  314. params.put("title", scenePlus.getTitle());
  315. params.put("customUserId", ext.get("customUserId"));
  316. params.put("gps", ext.get("gps"));
  317. params.put("totalTime", Integer.valueOf(redisUtil.get(String.format(RedisKey.SCENE_BUILD_EXPECT_TOTAL_TIME_NUM, sceneCode))));
  318. params.put("progress", 100);
  319. params.put("status", CommonSuccessStatus.SUCCESS.code());
  320. HttpUtil.post(buildProgressUrl, JSON.toJSONString(params), 2000);
  321. log.info("场景计算结果处理结束,场景码:{}", sceneCode);
  322. }catch (Exception e){
  323. log.error("场景计算结果处理出错,num"+sceneCode, e);
  324. // buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
  325. throw e;
  326. }
  327. }
  328. private void removeSceneAsynOperLog(String num){
  329. List<SceneAsynOperLog> list = sceneAsynOperLogService.list(new LambdaQueryWrapper<SceneAsynOperLog>().eq(SceneAsynOperLog::getNum, num));
  330. if(CollUtil.isEmpty(list)){
  331. return;
  332. }
  333. //删除数据库记录
  334. List<Long> deleteIdList = list.parallelStream().map(item -> item.getId()).collect(Collectors.toList());
  335. sceneAsynOperLogService.removeByIds(deleteIdList);
  336. list.parallelStream().forEach(item -> {
  337. if(StrUtil.isNotEmpty(item.getUrl())){
  338. try {
  339. fYunFileService.deleteFile(item.getUrl());
  340. } catch (IOException e) {
  341. log.warn("删除oss全景图下载压缩包失败,key:{}", item.getUrl());
  342. }
  343. }
  344. });
  345. }
  346. // private void cachePanorama(String dataSource, String num){
  347. // String cachedImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
  348. // //将全景图缓存到缓存目录
  349. // List<String> imagesList = FileUtil.listFileNames(dataSource + "/caches/images");
  350. // //先清除旧的全景图
  351. // cn.hutool.core.io.FileUtil.del(cachedImagesPath);
  352. // String visionPath = dataSource + "/results/vision.txt";
  353. // List<String> panoramaImageList = SceneUtil.getPanoramaImageList(visionPath);
  354. // imagesList.stream().forEach(fileName -> {
  355. // if (panoramaImageList.contains(fileName)) {
  356. // String srcPath = dataSource + "/caches/images/" + fileName;
  357. // String targetPath = cachedImagesPath + fileName;
  358. // log.info("源文件:{}, 目标文件:{}", srcPath, targetPath);
  359. // cn.hutool.core.io.FileUtil.copy(srcPath, targetPath, true);
  360. // }
  361. // });
  362. // }
  363. private Map<String, String> getUploadFiles(ScenePlus scenePlus,String path,Integer cameraType,JSONObject fdageData) throws Exception {
  364. if (ObjectUtils.isEmpty(scenePlus)) {
  365. throw new Exception("未找到场景信息:" + path);
  366. }
  367. String projectNum = scenePlus.getNum();
  368. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, projectNum);
  369. String imagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, projectNum);
  370. String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, projectNum);
  371. String resultsPath = path + File.separator + "results" + File.separator;
  372. String uploadData = FileUtils.readFile(resultsPath + "upload.json");
  373. JSONArray array = JSONObject.parseObject(uploadData).getJSONArray("upload");
  374. JSONObject fileJson = null;
  375. String fileName = "";
  376. Map<String, String> map = new HashMap();
  377. for (int i = 0; i < array.size(); ++i) {
  378. fileJson = array.getJSONObject(i);
  379. fileName = fileJson.getString("file");
  380. String filePath = resultsPath + fileName;
  381. if (!(new File(filePath)).exists()) {
  382. throw new Exception(filePath + "文件不存在");
  383. }
  384. if ("vision2.txt".equals(fileName)) {
  385. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision2.txt", resultsPath + "vision2.modeldata");
  386. map.put(resultsPath + "vision2.modeldata", imagesPath + "vision2.modeldata");
  387. map.put(resultsPath + "vision2.txt", imagesPath + "vision2.txt");
  388. }
  389. if (fileJson.getIntValue("clazz") == 2) {
  390. map.put(filePath, imagesPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
  391. } else if (fileJson.getIntValue("clazz") == 3) {
  392. map.put(filePath, imagesPath + "pan/high/" + fileName.replace("high/", ""));
  393. } else if (fileJson.getIntValue("clazz") == 4) {
  394. map.put(filePath, imagesPath + "pan/low/" + fileName.replace("low/", ""));
  395. } else if (fileJson.getIntValue("clazz") == 5) {
  396. map.put(filePath, imagesPath + fileName);
  397. } else if (fileJson.getIntValue("clazz") == 7) {
  398. map.put(filePath, imagesPath + fileName);
  399. } else if (fileJson.getIntValue("clazz") == 10) {
  400. String updown = FileUtils.readFile(filePath);
  401. JSONObject updownJson = JSONObject.parseObject(updown);
  402. String mappingOssPath = String.format("scene_edit_data/%s/data/", projectNum) + fileName.replace("updown", "mapping");
  403. map.put(filePath, mappingOssPath);
  404. } else {
  405. if (fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("clazz") == 12) {
  406. map.put(filePath, videoPath + fileName.replace("videos/", ""));
  407. if (fileName.contains(".mp4")) {
  408. map.put(resultsPath + fileName.replace("mp4", "flv"), videoPath + fileName.replace("videos/", "").replace("mp4", "flv"));
  409. }
  410. }
  411. if (fileJson.getIntValue("clazz") == 16) {
  412. map.put(filePath, dataViewPath + fileName);
  413. }
  414. if (fileJson.getIntValue("clazz") == 18) {
  415. map.put(filePath, imagesPath + fileName);
  416. }
  417. }
  418. }
  419. //exportMeshObj这个是字段由app写入的
  420. boolean genModel = true;//是否生成模型 默认生成,深时场景要根据 exportMeshObj判断是否生成
  421. if(!ObjectUtils.isEmpty(cameraType)
  422. && cameraType == 14
  423. && (!fdageData.containsKey("exportMeshObj") || fdageData.getIntValue("exportMeshObj") != 1)){
  424. genModel = false;
  425. }
  426. boolean gen3dTiles = true;//是否生成3dtiles模型 默认生成
  427. if(!ModelKind.THREE_D_TILE.code().equals(modelKind)
  428. || CollUtil.isEmpty(sdTilesSceneSourceList)
  429. || !sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){
  430. gen3dTiles = false;
  431. }
  432. if(genModel){
  433. if (!gen3dTiles) {
  434. String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
  435. CreateObjUtil.convertTxtToDam(path + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", damPath);
  436. // FileUtil.writeBytes(ZipUtil.gzip(new File(damPath)), damPath);
  437. map.put(damPath, imagesPath + ConstantFileName.modelUUID + "_50k.dam");
  438. }else{
  439. List<String> list = FileUtils.list(new File(path + File.separator + "results" + File.separator + ModelKind.THREE_D_TILE.code()));
  440. if(CollUtil.isEmpty(list)){
  441. log.error("3dtiles目录异常,3dtiles地址:{}", new File(path + File.separator + "results" + File.separator + ModelKind.THREE_D_TILE.code()));
  442. throw new Exception("3dtiles目录异常");
  443. }
  444. list.stream().forEach(str->{
  445. map.put(str, str.replace(path + File.separator + "results" + File.separator, imagesPath));
  446. });
  447. }
  448. }
  449. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision.txt", resultsPath + "vision.modeldata");
  450. map.put(resultsPath + "vision.txt", imagesPath + "vision.txt");
  451. map.put(resultsPath + "vision.modeldata", imagesPath + "vision.modeldata");
  452. log.info("数据转换完成:" + projectNum);
  453. if(!new File("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum).exists()){
  454. FileUtil.mkdir("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum);
  455. }
  456. // map.put(resultsPath + "floorplan.json", dataViewPath + "floor.json");
  457. map.put(resultsPath + "floorplan_cad.json", dataViewPath + "floorplan_cad.json");
  458. map.put(path + File.separator + "capture/stitch_params.txt", dataViewPath + "stitch_params.txt");
  459. map.put(path + File.separator + "capture/Up.xml", dataViewPath + "Up.xml");
  460. map.put(path + File.separator + "capture/Up2.xml", dataViewPath + "Up2.xml");
  461. map.put(path + File.separator + "capture/Up.txt", dataViewPath + "Up.txt");
  462. map.put(path + File.separator + "capture/Up2.txt", dataViewPath + "Up2.txt");
  463. return map;
  464. }
  465. private JSONObject getFdageData(String dataFdagePath) {
  466. log.info("dataFdagePath 文件路径 :{}", dataFdagePath);
  467. String data = FileUtils.readFile(dataFdagePath);
  468. //获取data.fdage的内容
  469. JSONObject dataJson = new JSONObject();
  470. if(data!=null){
  471. dataJson = JSONObject.parseObject(data);
  472. }
  473. return dataJson;
  474. }
  475. private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles){
  476. //户型图上传
  477. String dataViewPath = UploadFilePath.DATA_VIEW_PATH + "floor-cad-%s.%s";
  478. String floorCadPath = path + "/results/floorplan_cad";
  479. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  480. if(CollUtil.isNotEmpty(floorCadList)){
  481. floorCadList.stream().forEach(str->{
  482. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  483. String[] arr = substring.split("floor");
  484. String[] arr2 = arr[1].split("\\.");
  485. uploadFiles.put(str, String.format(dataViewPath, num, arr2[0], arr2[1]));
  486. });
  487. }
  488. }
  489. private void writeSceneJson(String num, JSONObject videosJson, SceneEditInfo sceneEditInfo, SceneEditInfoExt sceneEditInfoExt,
  490. SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt,Company company){
  491. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  492. String oldSceneJson = fYunFileService.getFileContent(dataViewPath + "scene.json");
  493. SceneJsonBean sceneJson = new SceneJsonBean();
  494. BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
  495. BeanUtil.copyProperties(sceneEditInfo, sceneJson);
  496. SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
  497. sceneJson.setControls(sceneEditControlsVO);
  498. sceneJson.setNum(num);
  499. sceneJson.setCreateTime(scenePlus.getCreateTime());
  500. sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
  501. sceneJson.setVersion(sceneEditInfo.getVersion());
  502. sceneJson.setImgVersion(sceneEditInfo.getImgVersion());
  503. sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
  504. sceneJson.setSceneKind(scenePlusExt.getSceneKind());
  505. sceneJson.setModelKind(scenePlusExt.getModelKind());
  506. sceneJson.setVideos(JSON.toJSONString(videosJson));
  507. sceneJson.setPayStatus(scenePlus.getPayStatus());
  508. if(StrUtil.isNotEmpty(oldSceneJson)){
  509. SceneJsonBean oldSceneJsonBean = JSON.parseObject(oldSceneJson, SceneJsonBean.class);
  510. List<JSONObject> mosaicList = JSON.parseObject(oldSceneJson, SceneJsonBean.class).getMosaicList();
  511. sceneJson.setMosaicList(mosaicList);
  512. sceneJson.setFloorLogo(oldSceneJsonBean.getFloorLogo());
  513. sceneJson.setFloorLogoFile(oldSceneJsonBean.getFloorLogoFile());
  514. sceneJson.setBoxModels(oldSceneJsonBean.getBoxModels());
  515. sceneJson.setBoxVideos(oldSceneJsonBean.getBoxVideos());
  516. sceneJson.setBoxPhotos(oldSceneJsonBean.getBoxPhotos());
  517. }
  518. if(!ObjectUtils.isEmpty(company)){
  519. String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
  520. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  521. String localLogoPath = null;
  522. if (StrUtil.isNotEmpty(company.getTopLogo())) {
  523. localLogoPath = ConstantFilePath.AGENT_PATH + company.getTopLogo().substring(company.getTopLogo().lastIndexOf("//") + 1);
  524. HttpUtil.downloadFile(company.getTopLogo(), localLogoPath);
  525. fYunFileService.uploadFile(localLogoPath, userViewPath + "loadingLogo-user.png");
  526. fYunFileService.uploadFile(localLogoPath, userEditPath + "loadingLogo-user.png");
  527. sceneJson.setLoadingLogo("user");
  528. sceneJson.setLoadingLogoFile("loadingLogo-user.png");
  529. sceneEditInfo.setLoadingLogo("user");
  530. sceneEditInfo.setLoadingLogoFile("loadingLogo-user.png");
  531. }
  532. if (StrUtil.isNotEmpty(company.getFloorLogo())) {
  533. localLogoPath = ConstantFilePath.AGENT_PATH + company.getFloorLogo().substring(company.getFloorLogo().lastIndexOf("//") + 1);
  534. HttpUtil.downloadFile(company.getFloorLogo(), localLogoPath);
  535. fYunFileService.uploadFile(localLogoPath, userViewPath + "floorLogo-user.png");
  536. fYunFileService.uploadFile(localLogoPath, userEditPath + "floorLogo-user.png");
  537. sceneJson.setFloorLogo("user");
  538. sceneJson.setFloorLogoFile("floorLogo-user.png");
  539. sceneEditInfo.setFloorLogo("user");
  540. sceneEditInfo.setFloorLogoFile("floorLogo-user.png");
  541. }
  542. if(!ObjectUtils.isEmpty(localLogoPath)){
  543. sceneEditInfoService.updateById(sceneEditInfo);
  544. FileUtils.deleteFile(localLogoPath);
  545. }
  546. }
  547. String sceneJsonStr = JSON.toJSONString(sceneJson);
  548. //上传sceneJson文件
  549. fYunFileService.uploadFile(sceneJsonStr.getBytes(), dataViewPath + "scene.json");
  550. //scenejson写入缓存
  551. redisUtil.set(String.format(RedisKey.SCENE_JSON, num), sceneJsonStr);
  552. }
  553. private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt){
  554. String num = scenePlus.getNum();
  555. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  556. Integer status = 1;
  557. if(scenePlus.getSceneSource() == 4 || scenePlus.getSceneSource() == 5){//如果是激光场景,需要激光系统那边完全处理好之后再发mq通知更新状态
  558. status = 0;
  559. }
  560. // 上传status JSON.
  561. JSONObject statusJson = new JSONObject();
  562. //临时将-2改成1,app还没完全更新
  563. statusJson.put("status", status);
  564. statusJson.put("webSite", scenePlusExt.getWebSite());
  565. statusJson.put("sceneNum", num);
  566. statusJson.put("thumb", scenePlusExt.getThumb());
  567. statusJson.put("payStatus", scenePlus.getPayStatus());
  568. statusJson.put("sceneScheme", scenePlusExt.getSceneScheme());
  569. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
  570. fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json",
  571. dataViewPath + "status.json");
  572. }
  573. private void createQrCode(String num, ScenePlusExt scenePlusExt, String qrLogo) {
  574. String localLogoPath = null;
  575. if (!ObjectUtils.isEmpty(qrLogo)) {
  576. try {
  577. localLogoPath = ConstantFilePath.AGENT_PATH + qrLogo.substring(qrLogo.lastIndexOf("//") + 1);
  578. HttpUtil.downloadFile(qrLogo, localLogoPath);
  579. } catch (Exception e) {
  580. log.error("公司logo下载失败:{}", qrLogo);
  581. localLogoPath = null;
  582. }
  583. }
  584. //生成二维码
  585. String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png";
  586. String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png";
  587. QrConfig qrConfig = QrConfig.create();
  588. qrConfig.setWidth(1024);
  589. qrConfig.setHeight(1024);
  590. if(StrUtil.isNotEmpty(localLogoPath)){
  591. qrConfig.setImg(localLogoPath);
  592. }
  593. QrCodeUtil.generate(scenePlusExt.getWebSite(), qrConfig, FileUtil.file(outPathZh));
  594. QrCodeUtil.generate(scenePlusExt.getWebSite() + "&lang=en", qrConfig, FileUtil.file(outPathEn));
  595. //上传二维码
  596. fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
  597. fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
  598. if(!ObjectUtils.isEmpty(localLogoPath)){
  599. FileUtils.deleteFile(localLogoPath);
  600. }
  601. }
  602. private void pushMsgToApp(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
  603. log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
  604. if(Objects.isNull(pushChannel) || StrUtil.isBlank(pushToken)){
  605. return;
  606. }
  607. String title = sceneName + "计算完成";
  608. String body = "您上传的" + sceneName + "计算完成,点击查看";
  609. try{
  610. if(FYunTypeEnum.AWS.code().equals(fYunFileService.getFyunType())){
  611. PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
  612. title, body , webSite);
  613. return;
  614. }
  615. PushMessageConfig pushConfig = null;
  616. if(pushChannel == 0){
  617. if(cameraType == 10 || cameraType == 13){
  618. //ios
  619. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY_Z, PushMessageConfig.IOS_SECRET_Z);
  620. pushConfig.sendIOSUnicast(pushToken, "四维看看Minion",title, body, webSite);
  621. }else {
  622. //ios
  623. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY, PushMessageConfig.IOS_SECRET);
  624. pushConfig.sendIOSUnicast(pushToken, "四维看看Pro",title, body, webSite);
  625. }
  626. }else {
  627. if(cameraType == 10 || cameraType == 13){
  628. //ios
  629. //安卓
  630. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY_Z, PushMessageConfig.ANDROID_SECRET_Z);
  631. pushConfig.sendAndroidUnicast2(pushToken, "四维看看Minion",title, body, webSite);
  632. }else {
  633. //安卓
  634. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY, PushMessageConfig.ANDROID_SECRET);
  635. pushConfig.sendAndroidUnicast(pushToken, "四维看看Pro",title, body, webSite);
  636. }
  637. }
  638. log.info("消息推送结束!");
  639. }catch (Exception e){
  640. log.error("推送消息失败:", e);
  641. }
  642. }
  643. private void copyToEditDir(String num) throws IOException {
  644. String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  645. String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  646. String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
  647. String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  648. Map<String, String> map = new HashMap<>();
  649. map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
  650. map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
  651. map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
  652. for (Entry<String, String> entry : map.entrySet()) {
  653. fYunFileService.copyFileInBucket(entry.getValue(), entry.getKey());
  654. }
  655. }
  656. private JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception {
  657. //读取videos_hdr_param.json, 保存点位视频的value
  658. Map<String, Object> videoMap = new HashMap<>();
  659. String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
  660. JSONArray videoArray = null;
  661. if(StringUtils.isNotEmpty(videosHdr)){
  662. videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
  663. }
  664. if(videoArray != null){
  665. for(int i = 0, len = videoArray.size(); i < len; i++) {
  666. videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
  667. if(videoArray.getJSONObject(i).containsKey("fov")){
  668. videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
  669. }
  670. }
  671. }
  672. //获取upload中的video视频名称
  673. String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
  674. JSONObject uploadJson = null;
  675. JSONArray array = null;
  676. if(uploadData!=null) {
  677. uploadJson = JSONObject.parseObject(uploadData);
  678. array = uploadJson.getJSONArray("upload");
  679. }
  680. JSONObject fileJson = null;
  681. String fileName = "";
  682. //计算ts文件的大小,并拼接成json格式
  683. JSONArray jsonArray = new JSONArray();
  684. JSONObject videoJson = null;
  685. JSONObject videosJson = new JSONObject();
  686. long videoSize = 0L;
  687. for(int i = 0, len = array.size(); i < len; i++) {
  688. fileJson = array.getJSONObject(i);
  689. fileName = fileJson.getString("file");
  690. if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
  691. videoJson = new JSONObject();
  692. videoJson.put("id", fileName.substring(
  693. 0, fileName.lastIndexOf(".")).replace("videos/", ""));
  694. //如果ts文件存在,就计算ts大小
  695. if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
  696. videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
  697. videoJson.put("tsSize", videoSize);
  698. }
  699. if(videoMap.containsKey(videoJson.get("id"))){
  700. videoJson.put("value", videoMap.get(videoJson.get("id")));
  701. }
  702. if(videoMap.containsKey(videoJson.get("id") + "_fov")){
  703. videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
  704. }else {
  705. videoJson.put("blend_fov", 7);
  706. }
  707. jsonArray.add(videoJson);
  708. }
  709. }
  710. videosJson.put("data", jsonArray);
  711. if(Objects.nonNull(videoVersion) && videoVersion >= 4){
  712. videosJson.put("version", 3);
  713. videosJson.put("upPath", String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up.xml");
  714. if(cameraType == 13){
  715. //转台相机
  716. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  717. }
  718. }else {
  719. videosJson.put("version", 1);
  720. videosJson.put("upPath", String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up2.xml");
  721. if(cameraType == 13){
  722. //转台相机
  723. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  724. }
  725. }
  726. if(cameraType == 5 || cameraType == 6){
  727. videosJson.put("version", 1);
  728. videosJson.put("upPath", String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "stitch_params.txt");
  729. }
  730. return videosJson;
  731. }
  732. private Long calUseSpace(Map<String, String> uploadFile) {
  733. return uploadFile.keySet().stream().map(File::new).filter(File::exists).mapToLong(File::length).sum();
  734. }
  735. private void updateDbPlus(int sceneSource,Long space,String videosJson, Long computeTime,boolean isObj,ScenePlusExt scenePlusExt){
  736. scenePlusExt.setSpace(space);
  737. scenePlusExt.setComputeTime(computeTime.toString());
  738. scenePlusExt.setAlgorithmTime(new Date());
  739. scenePlusExt.setVideos(videosJson);
  740. scenePlusExt.setIsObj(isObj ? 1 : 0);
  741. if(ModelTypeEnums.TILE_CODE.equals(modelType)){
  742. scenePlusExt.setSceneScheme(3);
  743. }
  744. switch (SceneSource.get(sceneSource)){
  745. case BM:
  746. scenePlusExt.setSceneResolution(SceneResolution.two_K.code());
  747. scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
  748. break;
  749. case SM:
  750. scenePlusExt.setSceneResolution(SceneResolution.one_k.code());
  751. scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
  752. break;
  753. case ZT:
  754. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  755. scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
  756. break;
  757. case JG:
  758. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  759. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  760. break;
  761. case SG:
  762. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  763. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  764. break;
  765. }
  766. String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
  767. scenePlusExt.setSceneKind(sceneKind);
  768. // scenePlusExt.setModelKind(modelKind);
  769. String dataFdage = FileUtil.readUtf8String(scenePlusExt.getDataSource().concat("/capture/").concat("data.fdage"));
  770. JSONObject jsonObject = JSON.parseObject(dataFdage);
  771. int points = jsonObject.getJSONArray("points").size();
  772. scenePlusExt.setShootCount(points);
  773. scenePlusExtService.updateById(scenePlusExt);
  774. }
  775. private Object[] updateEditInfo(ScenePlus scenePlus){
  776. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  777. SceneEditControls sceneEditControls = null;
  778. SceneEditInfoExt sceneEditInfoExt = null;
  779. if(sceneEditInfo == null){
  780. sceneEditInfo = new SceneEditInfo();
  781. sceneEditInfo.setScenePlusId(scenePlus.getId());
  782. sceneEditInfo.setDescription(scenePlus.getDescription());
  783. sceneEditInfo.setTitle(scenePlus.getTitle());
  784. sceneEditInfoService.save(sceneEditInfo);
  785. }else{
  786. int version = 0;
  787. int imgVersion = 0;
  788. int linkVersion = 0;
  789. //获取展示页的版本号
  790. String sceneJsonStr = fYunFileService.getFileContent(String.format(UploadFilePath.DATA_VIEW_PATH, scenePlus.getNum()) + "scene.json");
  791. if(StrUtil.isNotEmpty(sceneJsonStr)){
  792. JSONObject sceneJson = JSON.parseObject(sceneJsonStr);
  793. version = sceneJson.getIntValue("version");
  794. imgVersion = sceneJson.getIntValue("imgVersion");
  795. linkVersion = sceneJson.getIntValue("linkVersion");
  796. }
  797. if(version < sceneEditInfo.getVersion()){
  798. version = sceneEditInfo.getVersion();
  799. }
  800. if(imgVersion < sceneEditInfo.getImgVersion()){
  801. imgVersion = sceneEditInfo.getImgVersion();
  802. }
  803. if(linkVersion < sceneEditInfo.getLinkVersion()){
  804. linkVersion = sceneEditInfo.getLinkVersion();
  805. }
  806. sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  807. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  808. sceneEditInfo.setVersion(version + 1);
  809. sceneEditInfo.setImgVersion(imgVersion + 1);
  810. sceneEditInfo.setLinkVersion(linkVersion + 1);
  811. sceneEditInfo.setIsUploadObj(CommonStatus.NO.code());
  812. sceneEditInfoService.updateById(sceneEditInfo);
  813. }
  814. if(sceneEditControls == null){
  815. sceneEditControls = new SceneEditControls();
  816. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  817. sceneEditControlsService.save(sceneEditControls);
  818. }
  819. if(sceneEditInfoExt == null){
  820. sceneEditInfoExt = new SceneEditInfoExt();
  821. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  822. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  823. sceneEditInfoExtService.save(sceneEditInfoExt);
  824. }
  825. return new Object[]{sceneEditInfo, sceneEditInfoExt, sceneEditControls};
  826. }
  827. public boolean uploadHouseTypeJson(String num, String dataSource) {
  828. String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
  829. if (!new File(floorPlanCardFilePath).exists()) {
  830. log.warn("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  831. return false;
  832. }
  833. JSONObject json = CreateHouseJsonUtil.createHouseTypeJsonByCad(floorPlanCardFilePath);
  834. if(Objects.isNull(json)){
  835. return false;
  836. }
  837. String hourseTypeJsonPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "houseType.json";
  838. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  839. hourseTypeJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "houseType.json";
  840. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  841. return true;
  842. }
  843. }