BuildSceneServiceImpl.java 36 KB

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