BuildSceneServiceImpl.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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. this.uploadFreespace(sceneCode, path, uploadFiles);
  236. log.info("开始上传场景计算结果数据,num:{}", sceneCode);
  237. //由于3dtiles算法mesh文件发生变化,所以这里需要先清除一下oss的mesh目录,避免存在旧算法obj文件
  238. fYunFileService.deleteFolder(String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode) + "mesh");
  239. fYunFileService.deleteFolder(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ModelKind.THREE_D_TILE.code());
  240. //上传文件
  241. fYunFileService.uploadMulFiles(uploadFiles);
  242. //修改oss上dam的内容编码
  243. Map<String,String> damFileHeaders = new HashMap<>();
  244. damFileHeaders.put("Content-Encoding","gzip");
  245. String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
  246. fYunFileService.uploadFile(damPath, String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ConstantFileName.modelUUID + "_50k.dam", damFileHeaders);
  247. //拷贝部分文件到编辑目录,用于用户编辑
  248. this.copyToEditDir(sceneCode);
  249. //计算完毕后,同步全景图到缓存目录
  250. // this.cachePanorama(path, sceneCode);
  251. //生成houseTypejson并上传
  252. boolean existHouseType = this.uploadHouseTypeJson(sceneCode, path);
  253. scenePlus.setHouseType(existHouseType ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue());
  254. //生成floorpan.json
  255. commonService.uploadFloorplanJson(sceneCode, path);
  256. //重置异步操作记录
  257. commonService.removeSceneAsynOperLog(sceneCode);
  258. //清除用户编辑业务数据
  259. Set<String> bizs = new HashSet<>();
  260. bizs.add(UserEditDataType.BOX_MODEL.message());
  261. bizs.add(UserEditDataType.FLOORPLAN.message());
  262. bizs.add(UserEditDataType.FILTERS.message());
  263. commonService.initUserEditData(sceneCode, bizs, null);
  264. //上传计算结果文件
  265. commonService.uploadBuildResultData(sceneCode, path, SceneVersionType.V4.code());
  266. //容量统计
  267. Long space = commonService.getSpace(sceneCode);
  268. //写入数据库
  269. this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), message.getComputeTime(),isObj,scenePlusExt);
  270. Object[] editInfoArr = commonService.updateEditInfo(scenePlus);
  271. SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
  272. SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
  273. SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
  274. //更新场景主表
  275. //如果相机容量不足,需要把场景的paystatus改为容量不足状态
  276. scenePlus.setPayStatus(commonService.getPayStatus(scenePlus.getCameraId(), space));
  277. //统计原始资源大小
  278. scenePlusExt.setOrigSpace(FileUtil.size(new File(path.concat(File.separator).concat("capture"))));
  279. if (cameraType == 14) {
  280. //计算成功 激光转台相机 同步 请求
  281. fdkkLaserService.syncBuildResult(
  282. SyncLaserResultBean.builder()
  283. .num(sceneCode).dataSource(path)
  284. .sceneStatus(2)
  285. .createTime(scenePlus.getCreateTime())
  286. .shootCount(scenePlusExt.getShootCount())
  287. .payStatus(scenePlus.getPayStatus())
  288. .mixture(scenePlusExt.getMixture())
  289. .version(SceneVersionType.V4.code()).build());
  290. sceneEditControlsService.update(new LambdaUpdateWrapper<SceneEditControls>().set(SceneEditControls::getShowMap,0)
  291. .eq(SceneEditControls::getEditInfoId,sceneEditInfo.getId()));
  292. sceneEditControls.setShowMap(0);
  293. } else if (new File(path + "/results/laserData/vision_edit.txt").exists()) {
  294. fdkkLaserService.cloudPointBuild(sceneCode,path);
  295. }
  296. log.info("生成scene.json上传oss并设置缓存,num:{}", sceneCode);
  297. CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
  298. Company company = !ObjectUtils.isEmpty(cameraDetail.getCompanyId()) ? companyService.getById(cameraDetail.getCompanyId()) : null;
  299. //写scene.json
  300. commonService.writeSceneJson(sceneCode,sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus,scenePlusExt,company);
  301. String qrLogo = !ObjectUtils.isEmpty(company) && !ObjectUtils.isEmpty(company.getQrLogo()) ? company.getQrLogo() : null;
  302. qrLogo = ObjectUtils.isEmpty(qrLogo) && !ObjectUtils.isEmpty(sceneEditInfoExt.getShareLogoImg()) ? fYunFileConfig.getHost().concat(sceneEditInfoExt.getShareLogoImg()) : null;
  303. createQrCode(sceneCode, scenePlusExt, qrLogo);
  304. //计算成功,通知APP
  305. Integer pushChannel = fdageData.getInteger("pushChannel");
  306. String pushToken = fdageData.getString("pushToken");
  307. this.pushMsgToApp(pushChannel,pushToken, cameraType, scenePlus.getTitle(), scenePlusExt.getWebSite());
  308. // //删除计算目录
  309. if(CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)){
  310. CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/"));
  311. }
  312. this.uploadStatusJson(scenePlus, scenePlusExt);
  313. scenePlusService.updateById(scenePlus);
  314. scenePlusExtService.updateById(scenePlusExt);
  315. //国际环境需要发邮件通知
  316. if("eur".equals(env) &&
  317. !scenePlus.getSceneSource().equals(SceneSource.JG.code()) &&
  318. !scenePlus.getSceneSource().equals(SceneSource.SG.code())){
  319. commonService.sendEmail(sceneCode, "standar");
  320. }
  321. wbService.sendMq(sceneCode, CommonSuccessStatus.SUCCESS.code());
  322. //拜城公安需求
  323. this.sendMqForBcgn(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. void uploadFreespace(String num, String path, Map<String, String> map){
  337. String plyPath = path + "/results/laserData/cover/final_freespace.ply";
  338. String pngPath = path + "/results/laserData/cover/final_freespace.png";
  339. String infoJsonPath = path + "/results/laserData/cover/info.json";
  340. if(FileUtil.exist(plyPath)){
  341. map.put(plyPath, String.format(UploadFilePath.IMG_VIEW_PATH, num) + "cover/" + FileUtil.getName(plyPath));
  342. }
  343. if(FileUtil.exist(pngPath)){
  344. map.put(pngPath, String.format(UploadFilePath.IMG_VIEW_PATH, num) + "cover/" + FileUtil.getName(pngPath));
  345. }
  346. if(FileUtil.exist(infoJsonPath)){
  347. map.put(infoJsonPath, String.format(UploadFilePath.IMG_VIEW_PATH, num) + "cover/" + FileUtil.getName(infoJsonPath));
  348. }
  349. }
  350. private void sendMqForBcgn(String num){
  351. Map<String, String> map = new HashMap<>();
  352. map.put("num", num);
  353. mqProducer.sendByWorkQueue("detect-queue", map);
  354. }
  355. private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles){
  356. //户型图上传
  357. String dataViewPath = UploadFilePath.DATA_VIEW_PATH + "floor-cad-%s.%s";
  358. String floorCadPath = path + "/results/floorplan_cad";
  359. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  360. if(CollUtil.isNotEmpty(floorCadList)){
  361. floorCadList.stream().forEach(str->{
  362. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  363. String[] arr = substring.split("floor");
  364. String[] arr2 = arr[1].split("\\.");
  365. uploadFiles.put(str, String.format(dataViewPath, num, arr2[0], arr2[1]));
  366. });
  367. }
  368. }
  369. private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt){
  370. String num = scenePlus.getNum();
  371. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  372. Integer status = 1;
  373. if(scenePlus.getSceneSource() == 4 || scenePlus.getSceneSource() == 5){//如果是激光场景,需要激光系统那边完全处理好之后再发mq通知更新状态
  374. status = 0;
  375. }
  376. // 上传status JSON.
  377. JSONObject statusJson = new JSONObject();
  378. //临时将-2改成1,app还没完全更新
  379. statusJson.put("status", status);
  380. statusJson.put("webSite", scenePlusExt.getWebSite());
  381. statusJson.put("sceneNum", num);
  382. statusJson.put("thumb", scenePlusExt.getThumb());
  383. statusJson.put("payStatus", scenePlus.getPayStatus());
  384. statusJson.put("sceneScheme", scenePlusExt.getSceneScheme());
  385. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
  386. Map<String,String> headers = new HashMap<>();
  387. headers.put(HttpHeaders.CONTENT_TYPE, ContentType.JSON.getValue());
  388. fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", dataViewPath + "status.json", headers);
  389. }
  390. private void createQrCode(String num, ScenePlusExt scenePlusExt, String qrLogo) {
  391. String localLogoPath = null;
  392. if (!ObjectUtils.isEmpty(qrLogo)) {
  393. try {
  394. localLogoPath = ConstantFilePath.AGENT_PATH + qrLogo.substring(qrLogo.lastIndexOf("//") + 1);
  395. HttpUtil.downloadFile(qrLogo, localLogoPath);
  396. } catch (Exception e) {
  397. log.error("公司logo下载失败:{}", qrLogo);
  398. localLogoPath = null;
  399. }
  400. }
  401. //生成二维码
  402. String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png";
  403. String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png";
  404. QrConfig qrConfig = QrConfig.create();
  405. qrConfig.setWidth(1024);
  406. qrConfig.setHeight(1024);
  407. if(StrUtil.isNotEmpty(localLogoPath)){
  408. qrConfig.setImg(localLogoPath);
  409. }
  410. QrCodeUtil.generate(scenePlusExt.getWebSite(), qrConfig, FileUtil.file(outPathZh));
  411. QrCodeUtil.generate(scenePlusExt.getWebSite() + "&lang=en", qrConfig, FileUtil.file(outPathEn));
  412. //上传二维码
  413. fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
  414. fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
  415. if(!ObjectUtils.isEmpty(localLogoPath)){
  416. FileUtils.deleteFile(localLogoPath);
  417. }
  418. }
  419. private void pushMsgToApp(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
  420. log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
  421. if(Objects.isNull(pushChannel) || StrUtil.isBlank(pushToken)){
  422. return;
  423. }
  424. String title = sceneName + "计算完成";
  425. String body = "您上传的" + sceneName + "计算完成,点击查看";
  426. try{
  427. if(FYunTypeEnum.AWS.code().equals(fYunFileService.getFyunType())){
  428. PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
  429. title, body , webSite);
  430. return;
  431. }
  432. PushMessageConfig pushConfig = null;
  433. if(pushChannel == 0){
  434. if(cameraType == 10 || cameraType == 13){
  435. //ios
  436. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY_Z, PushMessageConfig.IOS_SECRET_Z);
  437. pushConfig.sendIOSUnicast(pushToken, "四维看看Minion",title, body, webSite);
  438. }else {
  439. //ios
  440. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY, PushMessageConfig.IOS_SECRET);
  441. pushConfig.sendIOSUnicast(pushToken, "四维看看Pro",title, body, webSite);
  442. }
  443. }else {
  444. if(cameraType == 10 || cameraType == 13){
  445. //ios
  446. //安卓
  447. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY_Z, PushMessageConfig.ANDROID_SECRET_Z);
  448. pushConfig.sendAndroidUnicast2(pushToken, "四维看看Minion",title, body, webSite);
  449. }else {
  450. //安卓
  451. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY, PushMessageConfig.ANDROID_SECRET);
  452. pushConfig.sendAndroidUnicast(pushToken, "四维看看Pro",title, body, webSite);
  453. }
  454. }
  455. log.info("消息推送结束!");
  456. }catch (Exception e){
  457. log.error("推送消息失败:", e);
  458. }
  459. }
  460. private void copyToEditDir(String num) throws IOException {
  461. String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  462. String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  463. String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
  464. String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  465. Map<String, String> map = new HashMap<>();
  466. map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
  467. map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
  468. map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
  469. for (Entry<String, String> entry : map.entrySet()) {
  470. fYunFileService.copyFileInBucket(entry.getValue(), entry.getKey());
  471. }
  472. }
  473. private void updateDbPlus(int sceneSource,Long space,String videosJson, Long computeTime,boolean isObj,ScenePlusExt scenePlusExt){
  474. scenePlusExt.setSpace(space);
  475. scenePlusExt.setComputeTime(computeTime.toString());
  476. scenePlusExt.setAlgorithmTime(new Date());
  477. scenePlusExt.setVideos(videosJson);
  478. scenePlusExt.setIsObj(isObj ? 1 : 0);
  479. if(ModelTypeEnums.TILE_CODE.equals(modelType)){
  480. scenePlusExt.setSceneScheme(3);
  481. }
  482. switch (SceneSource.get(sceneSource)){
  483. case BM:
  484. scenePlusExt.setSceneResolution(SceneResolution.two_K.code());
  485. scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
  486. break;
  487. case SM:
  488. scenePlusExt.setSceneResolution(SceneResolution.one_k.code());
  489. scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
  490. break;
  491. case ZT:
  492. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  493. scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
  494. break;
  495. case JG:
  496. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  497. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  498. break;
  499. case SG:
  500. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  501. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  502. break;
  503. }
  504. String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
  505. scenePlusExt.setSceneKind(sceneKind);
  506. // scenePlusExt.setModelKind(modelKind);
  507. //统计点位数量
  508. Map<String, Integer> result = this.getShootCount(scenePlusExt);
  509. Integer shootCount = result.get("shootCount");
  510. Integer mixture = result.get("mixture");
  511. scenePlusExt.setShootCount(shootCount);
  512. scenePlusExt.setMixture(mixture);
  513. scenePlusExtService.updateById(scenePlusExt);
  514. }
  515. private Map<String, Integer> getShootCount(ScenePlusExt scenePlusExt){
  516. Map<String, Integer> result = new HashMap<>();
  517. Integer shootCount = 0;
  518. Integer mixture = Objects.isNull(scenePlusExt.getMixture()) ? 0 : scenePlusExt.getMixture();
  519. String homePath = SceneUtil.getHomePath(scenePlusExt.getDataSource());
  520. JSONObject dataFdageObj = JSON.parseObject(fYunFileService.getFileContent(homePath.concat("data.fdage")));
  521. if(Objects.nonNull(dataFdageObj)){
  522. JSONArray points = dataFdageObj.getJSONArray("points");
  523. if(CollUtil.isNotEmpty(points)){
  524. shootCount = points.size();
  525. }
  526. }
  527. if(Objects.nonNull(shootCount) && shootCount > 0){
  528. if(Objects.nonNull(scenePlusExt.getLocation()) && scenePlusExt.getLocation() == 6){
  529. mixture = CommonStatus.YES.code().intValue();
  530. }
  531. }else{
  532. String slamDataStr = fYunFileService.getFileContent(homePath.concat("slam_data.json"));
  533. JSONObject slamDataObj = JSON.parseObject(slamDataStr);
  534. if(Objects.nonNull(slamDataObj)){
  535. JSONArray viewsInfo = slamDataObj.getJSONArray("views_info");
  536. if(CollUtil.isNotEmpty(viewsInfo)){
  537. shootCount = viewsInfo.stream().mapToInt(info -> {
  538. return ((JSONObject) info).getJSONArray("list_pose").size();
  539. }).sum();
  540. }
  541. }
  542. mixture = CommonStatus.NO.code().intValue();
  543. }
  544. result.put("shootCount", shootCount);
  545. result.put("mixture", mixture);
  546. return result;
  547. }
  548. public static void main(String[] args) {
  549. JSONObject dataFdageObj = JSON.parseObject(null);
  550. System.out.println(dataFdageObj);
  551. }
  552. public boolean uploadHouseTypeJson(String num, String dataSource) {
  553. String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
  554. if (!new File(floorPlanCardFilePath).exists()) {
  555. log.warn("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  556. return false;
  557. }
  558. JSONObject json = CreateHouseJsonUtil.createHouseTypeJsonByCad(floorPlanCardFilePath);
  559. if(Objects.isNull(json)){
  560. return false;
  561. }
  562. String hourseTypeJsonPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "houseType.json";
  563. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  564. hourseTypeJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "houseType.json";
  565. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  566. return true;
  567. }
  568. }