BuildSceneServiceImpl.java 43 KB

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