BuildSceneServiceImpl.java 34 KB

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