BuildSceneServiceImpl.java 39 KB

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