BuildSceneServiceImpl.java 40 KB

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