BuildSceneServiceImpl.java 28 KB

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