BuildSceneServiceImpl.java 41 KB

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