BuildSceneServiceImpl.java 42 KB

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