BuildSceneServiceImpl.java 33 KB

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