BuildSceneServiceImpl.java 46 KB

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