BuildSceneServiceImpl.java 30 KB

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