BuildSceneServiceImpl.java 39 KB

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