BuildSceneServiceImpl.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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.ArrayUtil;
  7. import cn.hutool.core.util.ObjUtil;
  8. import cn.hutool.core.util.StrUtil;
  9. import cn.hutool.core.util.ZipUtil;
  10. import cn.hutool.extra.qrcode.QrCodeUtil;
  11. import cn.hutool.extra.qrcode.QrConfig;
  12. import cn.hutool.http.ContentType;
  13. import cn.hutool.http.HttpUtil;
  14. import com.alibaba.fastjson.JSON;
  15. import com.alibaba.fastjson.JSONArray;
  16. import com.alibaba.fastjson.JSONObject;
  17. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  18. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  19. import com.fdkankan.common.constant.*;
  20. import com.fdkankan.common.util.FileUtils;
  21. import com.fdkankan.contro.bean.SyncLaserResultBean;
  22. import com.fdkankan.contro.constant.UserEditDataType;
  23. import com.fdkankan.contro.entity.*;
  24. import com.fdkankan.contro.mq.service.IBuildSceneService;
  25. import com.fdkankan.contro.service.*;
  26. import com.fdkankan.fyun.config.FYunFileConfig;
  27. import com.fdkankan.fyun.constant.FYunTypeEnum;
  28. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  29. import com.fdkankan.model.constants.ConstantFileName;
  30. import com.fdkankan.model.constants.ConstantFilePath;
  31. import com.fdkankan.model.constants.UploadFilePath;
  32. import com.fdkankan.model.enums.ModelTypeEnums;
  33. import com.fdkankan.model.utils.CreateHouseJsonUtil;
  34. import com.fdkankan.model.utils.CreateObjUtil;
  35. import com.fdkankan.model.utils.SceneUtil;
  36. import com.fdkankan.push.config.PushMessageConfig;
  37. import com.fdkankan.push.utils.PushMsgUtil;
  38. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  39. import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
  40. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  41. import com.fdkankan.redis.util.RedisUtil;
  42. import com.fdkankan.rubbersheeting.ScalingService;
  43. import lombok.extern.slf4j.Slf4j;
  44. import org.apache.commons.lang3.ObjectUtils;
  45. import org.apache.commons.lang3.StringUtils;
  46. import org.apache.http.HttpHeaders;
  47. import org.springframework.beans.factory.annotation.Autowired;
  48. import org.springframework.beans.factory.annotation.Value;
  49. import org.springframework.cloud.context.config.annotation.RefreshScope;
  50. import org.springframework.stereotype.Service;
  51. import javax.annotation.Resource;
  52. import java.io.File;
  53. import java.io.IOException;
  54. import java.nio.charset.StandardCharsets;
  55. import java.util.*;
  56. import java.util.Map.Entry;
  57. import java.util.stream.Collectors;
  58. /**
  59. * <p>
  60. * TODO
  61. * </p>
  62. *
  63. * @author dengsixing
  64. * @since 2022/4/20
  65. **/
  66. @Slf4j
  67. @Service
  68. @RefreshScope
  69. public class BuildSceneServiceImpl implements IBuildSceneService {
  70. @Value("${queue.modeling.modeling-call}")
  71. private String queueModelingCall;
  72. @Value("${queue.modeling.single.modeling-call}")
  73. private String singleModelingCall;
  74. @Value("${model.type:#{null}}")
  75. private String modelType;
  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. @Autowired
  121. private ScalingService scalingService;
  122. @Autowired
  123. private RabbitMqProducer rabbitMqProducer;
  124. @Autowired
  125. private ILinkPanService linkPanService;
  126. @Autowired
  127. private IWbService wbService;
  128. @Override
  129. public void buildScenePre(BuildSceneCallMessage message) throws Exception {
  130. String num = message.getSceneNum();
  131. try {
  132. Map<String, Object> sceneStatusParam = new HashMap<>();
  133. sceneStatusParam.put("num", num);
  134. sceneStatusParam.put("status", 0);
  135. commonService.sendUpdateSceneStatusMqToQueues(sceneStatusParam);
  136. //重新计算时需要删除文件夹,否知使用缓存
  137. if(new File(message.getPath() + File.separator + "results").exists()){
  138. FileUtils.deleteDirectory(message.getPath() + File.separator + "results");
  139. }
  140. //由于刘强说caches会影响计算结果,所以这里删除caches
  141. if(new File(message.getPath() + File.separator + "caches").exists()){
  142. FileUtils.deleteDirectory(message.getPath() + File.separator + "caches");
  143. }
  144. //删除点位校准数据
  145. if (Objects.nonNull(message.getExt())
  146. && message.getExt().containsKey("deleteExtras")
  147. && (Boolean) message.getExt().get("deleteExtras")) {
  148. String extras = String.format(UploadFilePath.scene_result_data_path, num).concat("extras");
  149. if(CollUtil.isNotEmpty(fYunFileService.listRemoteFiles(extras))){
  150. fYunFileService.deleteFolder(extras);
  151. }
  152. }
  153. //用户相机重新全量上传,需要解冻结
  154. sceneColdStorageService.unfreeze(num, "用户相机重新全量上传", message.getPath());
  155. //根据相机类型,组装资源路径
  156. //下载资源到本地
  157. this.downLoadSource(message, message.getPath());
  158. List<String> linkPanTargetList = linkPanService.genLinkPanPre(num);
  159. if(CollUtil.isNotEmpty(linkPanTargetList)){
  160. Map<String, Object> ext = message.getExt();
  161. if(Objects.isNull(ext)){
  162. ext = new HashMap<>();
  163. message.setExt(ext);
  164. }
  165. ext.put("linkPanTargetList", linkPanTargetList);
  166. }
  167. JSONObject fdageJson = JSONObject.parseObject(FileUtils.readFile(message.getPath().concat("/capture/data.fdage")));
  168. boolean rewrite = false;
  169. // 兼容旧的数据,防止OnlyExportMeshObj标志未删除掉
  170. if (fdageJson.containsKey("OnlyExportMeshObj")) {
  171. log.info("data.fdage 包含 OnlyExportMeshObj,进行去除!");
  172. // 写入data.fdage 防止重算
  173. fdageJson.remove("OnlyExportMeshObj");
  174. String ossPath = getOssPath(message.getPath());
  175. fYunFileService.uploadFile(fdageJson.toJSONString().getBytes(), ossPath + "data.fdage");
  176. rewrite = true;
  177. }
  178. if (!ObjectUtils.isEmpty(modelType)) {
  179. // 修改dataFdage文件
  180. fdageJson.put("modelType", modelType);
  181. rewrite = true;
  182. }
  183. if (rewrite) {
  184. FileUtils.writeFile(message.getPath().concat("/capture/data.fdage"), fdageJson.toJSONString());
  185. }
  186. message.getBuildContext().put("cameraType",message.getCameraType());
  187. //查询是否超过比例50%,如果超过,则启动128G服务器弹性伸缩
  188. Float maxRate = fdageJson.getFloat("maxRate");
  189. if(env.equals("gn") && Objects.nonNull(maxRate) && maxRate > 50){
  190. Map<String, Object> ext = message.getExt();
  191. if(Objects.isNull(ext)){
  192. ext = new HashMap<>();
  193. message.setExt(ext);
  194. }
  195. ext.put("128G", 1);
  196. }
  197. message.setBizType("standard");
  198. log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
  199. }catch (Exception e){
  200. log.error("场景计算前置处理出错,num"+num, e);
  201. buildSceneDTService.handBaseFail("场景计算资源准备异常!", message.getPath(), message.getSceneNum(), "计算控制服务器");
  202. throw e;
  203. }
  204. }
  205. private String getOssPath(String path) {
  206. String ossPath = ConstantFilePath.OSS_PREFIX
  207. + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  208. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  209. if (!ossPath.endsWith("/")) {
  210. ossPath = ossPath.concat("/");
  211. }
  212. return ossPath;
  213. }
  214. @Override
  215. public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
  216. String ossPath = getOssPath(path);
  217. fYunFileService.downloadFileByCommand(path + File.separator + "capture", ossPath);
  218. }
  219. @Override
  220. public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
  221. String sceneCode = message.getBuildContext().get("sceneNum").toString();
  222. String path = message.getPath();
  223. try {
  224. // 上传计算日志
  225. //如果是重复计算,没有走到计算逻辑,不需要上传日志文件
  226. log.info("开始上传计算日志");
  227. String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneCode);
  228. fYunFileService.uploadFile(path + File.separator + "console.log", buildLogPath + "console.log");
  229. log.info("计算日志上传完成");
  230. if (!message.getBuildSuccess()) {
  231. log.error("建模失败,修改状态为失败状态");
  232. scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
  233. .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
  234. .eq(ScenePlus::getNum, sceneCode));
  235. wbService.sendMq(sceneCode, CommonSuccessStatus.FAIL.code());
  236. // 发送钉钉消息,计算失败
  237. buildSceneDTService.handModelFail("计算失败", message.getPath(), sceneCode, message.getHostName());
  238. return;
  239. }
  240. JSONObject fdageData = commonService.getFdageData(path + File.separator + "capture" +File.separator+"data.fdage");
  241. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
  242. Integer cameraType = Integer.parseInt(message.getBuildContext().get("cameraType").toString());
  243. Map<String, String> uploadFiles = commonService.getUploadFiles(scenePlus,path,cameraType,fdageData);
  244. scenePlus.setPayStatus(PayStatus.PAY.code());
  245. scenePlus.setUpdateTime(new Date());
  246. scenePlus.setSceneStatus(SceneStatus.NO_DISPLAY.code());
  247. Integer videoVersion = fdageData.getInteger("videoVersion");
  248. //读取计算结果文件生成videosJson
  249. JSONObject videosJson = commonService.getVideosJson(path, videoVersion, sceneCode, cameraType);
  250. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  251. boolean isObj = fdageData.containsKey("exportMeshObj") && fdageData.getIntValue("exportMeshObj") == 1;
  252. //上传全景图俯视图
  253. this.uploadFloorCad(path, sceneCode, uploadFiles);
  254. log.info("开始上传场景计算结果数据,num:{}", sceneCode);
  255. //由于3dtiles算法mesh文件发生变化,所以这里需要先清除一下oss的mesh目录,避免存在旧算法obj文件
  256. fYunFileService.deleteFolder(String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode) + "mesh");
  257. fYunFileService.deleteFolder(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ModelKind.THREE_D_TILE.code());
  258. //上传文件
  259. fYunFileService.uploadMulFiles(uploadFiles);
  260. //修改oss上dam的内容编码
  261. Map<String,String> damFileHeaders = new HashMap<>();
  262. damFileHeaders.put("Content-Encoding","gzip");
  263. String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
  264. fYunFileService.uploadFile(damPath, String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ConstantFileName.modelUUID + "_50k.dam", damFileHeaders);
  265. //拷贝部分文件到编辑目录,用于用户编辑
  266. this.copyToEditDir(sceneCode);
  267. //计算完毕后,同步全景图到缓存目录
  268. // this.cachePanorama(path, sceneCode);
  269. //生成houseTypejson并上传
  270. boolean existHouseType = this.uploadHouseTypeJson(sceneCode, path);
  271. scenePlus.setHouseType(existHouseType ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue());
  272. //生成场景关联数据
  273. Integer links = linkPanService.genLinkPanPost(sceneCode);
  274. //生成floorpan.json
  275. commonService.uploadFloorplanJson(sceneCode, path);
  276. //重置异步操作记录
  277. commonService.removeSceneAsynOperLog(sceneCode);
  278. //清除用户编辑业务数据
  279. Set<String> bizs = new HashSet<>();
  280. bizs.add(UserEditDataType.BOX_MODEL.message());
  281. bizs.add(UserEditDataType.FLOORPLAN.message());
  282. bizs.add(UserEditDataType.FILTERS.message());
  283. commonService.initUserEditData(sceneCode, bizs, null);
  284. //上传计算结果文件
  285. commonService.uploadBuildResultData(sceneCode, path, SceneVersionType.V4.code());
  286. //容量统计
  287. Long space = commonService.getSpace(sceneCode);
  288. //写入数据库
  289. this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), message.getComputeTime(),isObj,scenePlusExt);
  290. Object[] editInfoArr = commonService.updateEditInfo(scenePlus);
  291. SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
  292. SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
  293. SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
  294. sceneEditInfoExt.setLinks(links);
  295. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  296. //更新场景主表
  297. //如果相机容量不足,需要把场景的paystatus改为容量不足状态
  298. scenePlus.setPayStatus(commonService.getPayStatus(scenePlus.getCameraId(), space));
  299. //统计原始资源大小
  300. scenePlusExt.setOrigSpace(FileUtil.size(new File(path.concat(File.separator).concat("capture"))));
  301. if (cameraType == 14) {
  302. //计算成功 激光转台相机 同步 请求
  303. fdkkLaserService.syncBuildResult(
  304. SyncLaserResultBean.builder()
  305. .num(sceneCode).dataSource(path)
  306. .sceneStatus(2)
  307. .createTime(scenePlus.getCreateTime())
  308. .shootCount(scenePlusExt.getShootCount())
  309. .payStatus(scenePlus.getPayStatus())
  310. .mixture(scenePlusExt.getMixture())
  311. .version(SceneVersionType.V4.code()).build());
  312. sceneEditControlsService.update(new LambdaUpdateWrapper<SceneEditControls>().set(SceneEditControls::getShowMap,0)
  313. .eq(SceneEditControls::getEditInfoId,sceneEditInfo.getId()));
  314. sceneEditControls.setShowMap(0);
  315. } else if (new File(path + "/results/laserData/vision_edit.txt").exists()) {
  316. fdkkLaserService.cloudPointBuild(sceneCode,path);
  317. }
  318. log.info("生成scene.json上传oss并设置缓存,num:{}", sceneCode);
  319. CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
  320. Company company = !ObjectUtils.isEmpty(cameraDetail.getCompanyId()) ? companyService.getById(cameraDetail.getCompanyId()) : null;
  321. //写scene.json
  322. commonService.writeSceneJson(sceneCode,sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus,scenePlusExt,company);
  323. String qrLogo = !ObjectUtils.isEmpty(company) && !ObjectUtils.isEmpty(company.getQrLogo()) ? company.getQrLogo() : null;
  324. qrLogo = ObjectUtils.isEmpty(qrLogo) && !ObjectUtils.isEmpty(sceneEditInfoExt.getShareLogoImg()) ? fYunFileConfig.getHost().concat(sceneEditInfoExt.getShareLogoImg()) : null;
  325. createQrCode(sceneCode, scenePlusExt, qrLogo);
  326. //计算成功,通知APP
  327. Integer pushChannel = fdageData.getInteger("pushChannel");
  328. String pushToken = fdageData.getString("pushToken");
  329. this.pushMsgToApp(pushChannel,pushToken, cameraType, scenePlus.getTitle(), scenePlusExt.getWebSite());
  330. // //删除计算目录
  331. if(CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)){
  332. CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/"));
  333. }
  334. this.uploadStatusJson(scenePlus, scenePlusExt);
  335. scenePlusService.updateById(scenePlus);
  336. scenePlusExtService.updateById(scenePlusExt);
  337. //国际环境需要发邮件通知
  338. if("eur".equals(env)){
  339. commonService.sendEmail(sceneCode, "V4");
  340. }
  341. wbService.sendMq(sceneCode, CommonSuccessStatus.SUCCESS.code());
  342. log.info("场景计算结果处理结束,场景码:{}", sceneCode);
  343. }catch (Exception e){
  344. log.error("场景计算结果处理出错,num"+sceneCode, e);
  345. buildSceneDTService.handBaseFail("场景计算结果处理出错!", message.getPath(), sceneCode, "计算控制服务器");
  346. throw e;
  347. } finally {
  348. Map<String, Object> sceneStatusParam = new HashMap<>();
  349. sceneStatusParam.put("num", sceneCode);
  350. sceneStatusParam.put("status", message.getBuildSuccess() ? 1 : -1);
  351. commonService.sendUpdateSceneStatusMqToQueues(sceneStatusParam);
  352. }
  353. }
  354. // private void cachePanorama(String dataSource, String num){
  355. // String cachedImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
  356. // //将全景图缓存到缓存目录
  357. // List<String> imagesList = FileUtil.listFileNames(dataSource + "/caches/images");
  358. // //先清除旧的全景图
  359. // cn.hutool.core.io.FileUtil.del(cachedImagesPath);
  360. // String visionPath = dataSource + "/results/vision.txt";
  361. // List<String> panoramaImageList = SceneUtil.getPanoramaImageList(visionPath);
  362. // imagesList.stream().forEach(fileName -> {
  363. // if (panoramaImageList.contains(fileName)) {
  364. // String srcPath = dataSource + "/caches/images/" + fileName;
  365. // String targetPath = cachedImagesPath + fileName;
  366. // log.info("源文件:{}, 目标文件:{}", srcPath, targetPath);
  367. // cn.hutool.core.io.FileUtil.copy(srcPath, targetPath, true);
  368. // }
  369. // });
  370. // }
  371. private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles){
  372. //户型图上传
  373. String dataViewPath = UploadFilePath.DATA_VIEW_PATH + "floor-cad-%s.%s";
  374. String floorCadPath = path + "/results/floorplan_cad";
  375. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  376. if(CollUtil.isNotEmpty(floorCadList)){
  377. floorCadList.stream().forEach(str->{
  378. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  379. String[] arr = substring.split("floor");
  380. String[] arr2 = arr[1].split("\\.");
  381. uploadFiles.put(str, String.format(dataViewPath, num, arr2[0], arr2[1]));
  382. });
  383. }
  384. }
  385. private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt){
  386. String num = scenePlus.getNum();
  387. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  388. Integer status = 1;
  389. if(scenePlus.getSceneSource() == 4 || scenePlus.getSceneSource() == 5){//如果是激光场景,需要激光系统那边完全处理好之后再发mq通知更新状态
  390. status = 0;
  391. }
  392. // 上传status JSON.
  393. JSONObject statusJson = new JSONObject();
  394. //临时将-2改成1,app还没完全更新
  395. statusJson.put("status", status);
  396. statusJson.put("webSite", scenePlusExt.getWebSite());
  397. statusJson.put("sceneNum", num);
  398. statusJson.put("thumb", scenePlusExt.getThumb());
  399. statusJson.put("payStatus", scenePlus.getPayStatus());
  400. statusJson.put("sceneScheme", scenePlusExt.getSceneScheme());
  401. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
  402. Map<String,String> headers = new HashMap<>();
  403. headers.put(HttpHeaders.CONTENT_TYPE, ContentType.JSON.getValue());
  404. fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", dataViewPath + "status.json", headers);
  405. }
  406. private void createQrCode(String num, ScenePlusExt scenePlusExt, String qrLogo) {
  407. String localLogoPath = null;
  408. if (!ObjectUtils.isEmpty(qrLogo)) {
  409. try {
  410. localLogoPath = ConstantFilePath.AGENT_PATH + qrLogo.substring(qrLogo.lastIndexOf("//") + 1);
  411. HttpUtil.downloadFile(qrLogo, localLogoPath);
  412. } catch (Exception e) {
  413. log.error("公司logo下载失败:{}", qrLogo);
  414. localLogoPath = null;
  415. }
  416. }
  417. //生成二维码
  418. String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png";
  419. String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png";
  420. QrConfig qrConfig = QrConfig.create();
  421. qrConfig.setWidth(1024);
  422. qrConfig.setHeight(1024);
  423. if(StrUtil.isNotEmpty(localLogoPath)){
  424. qrConfig.setImg(localLogoPath);
  425. }
  426. QrCodeUtil.generate(scenePlusExt.getWebSite(), qrConfig, FileUtil.file(outPathZh));
  427. QrCodeUtil.generate(scenePlusExt.getWebSite() + "&lang=en", qrConfig, FileUtil.file(outPathEn));
  428. //上传二维码
  429. fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
  430. fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
  431. if(!ObjectUtils.isEmpty(localLogoPath)){
  432. FileUtils.deleteFile(localLogoPath);
  433. }
  434. }
  435. private void pushMsgToApp(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
  436. log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
  437. if(Objects.isNull(pushChannel) || StrUtil.isBlank(pushToken)){
  438. return;
  439. }
  440. String title = sceneName + "计算完成";
  441. String body = "您上传的" + sceneName + "计算完成,点击查看";
  442. try{
  443. if(FYunTypeEnum.AWS.code().equals(fYunFileService.getFyunType())){
  444. PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
  445. title, body , webSite);
  446. return;
  447. }
  448. PushMessageConfig pushConfig = null;
  449. if(pushChannel == 0){
  450. if(cameraType == 10 || cameraType == 13){
  451. //ios
  452. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY_Z, PushMessageConfig.IOS_SECRET_Z);
  453. pushConfig.sendIOSUnicast(pushToken, "四维看看Minion",title, body, webSite);
  454. }else {
  455. //ios
  456. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY, PushMessageConfig.IOS_SECRET);
  457. pushConfig.sendIOSUnicast(pushToken, "四维看看Pro",title, body, webSite);
  458. }
  459. }else {
  460. if(cameraType == 10 || cameraType == 13){
  461. //ios
  462. //安卓
  463. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY_Z, PushMessageConfig.ANDROID_SECRET_Z);
  464. pushConfig.sendAndroidUnicast2(pushToken, "四维看看Minion",title, body, webSite);
  465. }else {
  466. //安卓
  467. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY, PushMessageConfig.ANDROID_SECRET);
  468. pushConfig.sendAndroidUnicast(pushToken, "四维看看Pro",title, body, webSite);
  469. }
  470. }
  471. log.info("消息推送结束!");
  472. }catch (Exception e){
  473. log.error("推送消息失败:", e);
  474. }
  475. }
  476. private void copyToEditDir(String num) throws IOException {
  477. String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  478. String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  479. String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
  480. String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  481. Map<String, String> map = new HashMap<>();
  482. map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
  483. map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
  484. map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
  485. for (Entry<String, String> entry : map.entrySet()) {
  486. fYunFileService.copyFileInBucket(entry.getValue(), entry.getKey());
  487. }
  488. }
  489. private void updateDbPlus(int sceneSource,Long space,String videosJson, Long computeTime,boolean isObj,ScenePlusExt scenePlusExt){
  490. scenePlusExt.setSpace(space);
  491. scenePlusExt.setComputeTime(computeTime.toString());
  492. scenePlusExt.setAlgorithmTime(new Date());
  493. scenePlusExt.setVideos(videosJson);
  494. scenePlusExt.setIsObj(isObj ? 1 : 0);
  495. if(ModelTypeEnums.TILE_CODE.equals(modelType)){
  496. scenePlusExt.setSceneScheme(3);
  497. }
  498. switch (SceneSource.get(sceneSource)){
  499. case BM:
  500. scenePlusExt.setSceneResolution(SceneResolution.two_K.code());
  501. scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
  502. break;
  503. case SM:
  504. scenePlusExt.setSceneResolution(SceneResolution.one_k.code());
  505. scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
  506. break;
  507. case ZT:
  508. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  509. scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
  510. break;
  511. case JG:
  512. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  513. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  514. break;
  515. case SG:
  516. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  517. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  518. break;
  519. }
  520. String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
  521. scenePlusExt.setSceneKind(sceneKind);
  522. // scenePlusExt.setModelKind(modelKind);
  523. //统计点位数量
  524. Map<String, Integer> result = this.getShootCount(scenePlusExt);
  525. Integer shootCount = result.get("shootCount");
  526. Integer mixture = result.get("mixture");
  527. scenePlusExt.setShootCount(shootCount);
  528. scenePlusExt.setMixture(mixture);
  529. scenePlusExtService.updateById(scenePlusExt);
  530. }
  531. private Map<String, Integer> getShootCount(ScenePlusExt scenePlusExt){
  532. Map<String, Integer> result = new HashMap<>();
  533. Integer shootCount = 0;
  534. Integer mixture = Objects.isNull(scenePlusExt.getMixture()) ? 0 : scenePlusExt.getMixture();
  535. String homePath = SceneUtil.getHomePath(scenePlusExt.getDataSource());
  536. JSONObject dataFdageObj = JSON.parseObject(fYunFileService.getFileContent(homePath.concat("data.fdage")));
  537. if(Objects.nonNull(dataFdageObj)){
  538. JSONArray points = dataFdageObj.getJSONArray("points");
  539. if(CollUtil.isNotEmpty(points)){
  540. shootCount = points.size();
  541. }
  542. }
  543. if(Objects.nonNull(shootCount) && shootCount > 0){
  544. if(Objects.nonNull(scenePlusExt.getLocation()) && scenePlusExt.getLocation() == 6){
  545. mixture = CommonStatus.YES.code().intValue();
  546. }
  547. }else{
  548. String slamDataStr = fYunFileService.getFileContent(homePath.concat("slam_data.json"));
  549. JSONObject slamDataObj = JSON.parseObject(slamDataStr);
  550. if(Objects.nonNull(slamDataObj)){
  551. JSONArray viewsInfo = slamDataObj.getJSONArray("views_info");
  552. if(CollUtil.isNotEmpty(viewsInfo)){
  553. shootCount = viewsInfo.stream().mapToInt(info -> {
  554. return ((JSONObject) info).getJSONArray("list_pose").size();
  555. }).sum();
  556. }
  557. }
  558. mixture = CommonStatus.NO.code().intValue();
  559. }
  560. result.put("shootCount", shootCount);
  561. result.put("mixture", mixture);
  562. return result;
  563. }
  564. public static void main(String[] args) {
  565. JSONObject dataFdageObj = JSON.parseObject(null);
  566. System.out.println(dataFdageObj);
  567. }
  568. public boolean uploadHouseTypeJson(String num, String dataSource) {
  569. String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
  570. if (!new File(floorPlanCardFilePath).exists()) {
  571. log.warn("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  572. return false;
  573. }
  574. JSONObject json = CreateHouseJsonUtil.createHouseTypeJsonByCad(floorPlanCardFilePath);
  575. if(Objects.isNull(json)){
  576. return false;
  577. }
  578. String hourseTypeJsonPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "houseType.json";
  579. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  580. hourseTypeJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "houseType.json";
  581. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  582. return true;
  583. }
  584. }