BuildSceneServiceImpl.java 31 KB

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