BuildSceneServiceImpl.java 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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.HttpResponse;
  9. import cn.hutool.http.HttpUtil;
  10. import com.alibaba.fastjson.JSON;
  11. import com.alibaba.fastjson.JSONArray;
  12. import com.alibaba.fastjson.JSONObject;
  13. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  14. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  15. import com.fdkankan.common.constant.*;
  16. import com.fdkankan.common.exception.BusinessException;
  17. import com.fdkankan.common.util.DateExtUtil;
  18. import com.fdkankan.common.util.DateUtil;
  19. import com.fdkankan.common.util.FileUtils;
  20. import com.fdkankan.contro.bean.SyncLaserResultBean;
  21. import com.fdkankan.contro.constant.UserEditDataType;
  22. import com.fdkankan.contro.entity.*;
  23. import com.fdkankan.contro.mq.service.IBuildSceneService;
  24. import com.fdkankan.contro.service.*;
  25. import com.fdkankan.contro.util.EcsScaling;
  26. import com.fdkankan.contro.util.HttpUtilExt;
  27. import com.fdkankan.fyun.config.FYunFileConfig;
  28. import com.fdkankan.fyun.constant.FYunTypeEnum;
  29. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  30. import com.fdkankan.model.constants.ConstantFileName;
  31. import com.fdkankan.model.constants.ConstantFilePath;
  32. import com.fdkankan.model.constants.UploadFilePath;
  33. import com.fdkankan.model.enums.ModelTypeEnums;
  34. import com.fdkankan.model.utils.CreateHouseJsonUtil;
  35. import com.fdkankan.model.utils.CreateObjUtil;
  36. import com.fdkankan.model.utils.SceneUtil;
  37. import com.fdkankan.push.config.PushMessageConfig;
  38. import com.fdkankan.push.utils.PushMsgUtil;
  39. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  40. import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
  41. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  42. import com.fdkankan.redis.util.RedisUtil;
  43. import com.fdkankan.rubbersheeting.ScalingService;
  44. import lombok.extern.slf4j.Slf4j;
  45. import org.apache.commons.lang3.ObjectUtils;
  46. import org.apache.commons.lang3.StringUtils;
  47. import org.apache.http.HttpHeaders;
  48. import org.springframework.amqp.rabbit.core.RabbitTemplate;
  49. import org.springframework.beans.factory.annotation.Autowired;
  50. import org.springframework.beans.factory.annotation.Value;
  51. import org.springframework.cloud.context.config.annotation.RefreshScope;
  52. import org.springframework.stereotype.Service;
  53. import javax.annotation.Resource;
  54. import java.io.File;
  55. import java.io.IOException;
  56. import java.nio.charset.StandardCharsets;
  57. import java.util.*;
  58. import java.util.Map.Entry;
  59. /**
  60. * <p>
  61. * </p>
  62. *
  63. * @author dengsixing
  64. * @since 2022/4/20
  65. **/
  66. @Slf4j
  67. @Service
  68. @RefreshScope
  69. public class BuildSceneServiceImpl implements IBuildSceneService {
  70. @Value("${queue.modeling.modeling-call}")
  71. private String queueModelingCall;
  72. @Value("${queue.modeling.single.modeling-call}")
  73. private String singleModelingCall;
  74. @Value("${model.type:#{null}}")
  75. private String modelType;
  76. @Value("${model.modelKind:3dtiles}")
  77. private String modelKind;
  78. @Value("#{'${model.3dtiles.sceneSource:}'.split(',')}")
  79. private List<Integer> sdTilesSceneSourceList;
  80. @Value("#{'${elastic.userIds:}'.split(',')}")
  81. private List<Long> elasticUserIds;
  82. @Value("${env:gn}")
  83. private String env;
  84. @Value("#{'${build.scene.post.not-delete-nas-nums:}'.split(',')}")
  85. private List<String> notDeleteNasNumList;
  86. @Value("4dkk.laserService.bucket")
  87. private String laserBucket;
  88. @Autowired
  89. private RabbitMqProducer mqProducer;
  90. @Resource
  91. private FYunFileServiceInterface fYunFileService;
  92. @Autowired
  93. private ICameraDetailService cameraDetailService;
  94. @Autowired
  95. private ISceneEditInfoService sceneEditInfoService;
  96. @Autowired
  97. private ISceneEditControlsService sceneEditControlsService;
  98. @Autowired
  99. private FYunFileConfig fYunFileConfig;
  100. @Autowired
  101. private RedisUtil redisUtil;
  102. @Autowired
  103. private IScenePlusService scenePlusService;
  104. @Autowired
  105. private IScenePlusExtService scenePlusExtService;
  106. @Autowired
  107. private ISceneEditInfoExtService sceneEditInfoExtService;
  108. @Autowired
  109. private IUserIncrementService userIncrementService;
  110. @Autowired
  111. private IFdkkLaserService fdkkLaserService;
  112. // @Autowired
  113. // private IBuildSceneDTService buildSceneDTService;
  114. @Autowired
  115. private IIncrementTypeService incrementTypeService;
  116. @Autowired
  117. private ICompanyService companyService;
  118. @Autowired
  119. private ISceneAsynOperLogService sceneAsynOperLogService;
  120. @Autowired
  121. private ICommonService commonService;
  122. @Autowired
  123. private ISceneBuildProcessLogService sceneBuildProcessLogService;
  124. @Autowired
  125. private ISceneColdStorageService sceneColdStorageService;
  126. @Autowired
  127. private IOrigFileUploadBatchService origFileUploadBatchService;
  128. @Autowired
  129. private IOrigFileUploadService origFileUploadService;
  130. @Autowired
  131. private ILinkPanService linkPanService;
  132. @Autowired
  133. private IJmgaService jmgaService;
  134. @Autowired(required = false)
  135. private ScalingService scalingService;
  136. @Autowired
  137. private RabbitTemplate rabbitTemplate;
  138. @Resource
  139. private EcsScaling ecsScaling;
  140. @Autowired
  141. private IAiService aiService;
  142. @Autowired
  143. private IHaixinService haixinService;
  144. @Autowired
  145. private IRtkService rtkService;
  146. @Override
  147. public void buildScenePre(BuildSceneCallMessage message) throws Exception{
  148. boolean success = false;
  149. String num = message.getSceneNum();
  150. String batchIds = (String) message.getExt().get("batchId");
  151. try {
  152. //重新计算时需要删除文件夹,否知使用缓存
  153. if(new File(message.getPath() + File.separator + "results").exists()){
  154. FileUtils.deleteDirectory(message.getPath() + File.separator + "results");
  155. }
  156. //由于刘强说caches会影响计算结果,所以这里删除caches
  157. if(new File(message.getPath() + File.separator + "caches").exists()){
  158. FileUtils.deleteDirectory(message.getPath() + File.separator + "caches");
  159. }
  160. //删除project.json文件
  161. FileUtil.del(message.getPath().concat(File.separator).concat("project.json"));
  162. //删除点位校准数据
  163. if (Objects.nonNull(message.getExt())
  164. && message.getExt().containsKey("deleteExtras")
  165. && (Boolean) message.getExt().get("deleteExtras")) {
  166. String extras = String.format(UploadFilePath.scene_result_data_path, num).concat("extras");
  167. if(CollUtil.isNotEmpty(fYunFileService.listRemoteFiles(extras))){
  168. fYunFileService.deleteFolder(extras);
  169. }
  170. FileUtil.del(message.getPath() + "/extras");
  171. }
  172. //下载资源到本地
  173. this.downLoadSource(message, message.getPath());
  174. //校验文件是否完整
  175. jmgaService.checkLackFile(message.getPath());
  176. List<String> linkPanTargetList = linkPanService.genLinkPanPre(num);
  177. if(CollUtil.isNotEmpty(linkPanTargetList)){
  178. Map<String, Object> ext = message.getExt();
  179. if(Objects.isNull(ext)){
  180. ext = new HashMap<>();
  181. message.setExt(ext);
  182. }
  183. ext.put("linkPanTargetList", linkPanTargetList);
  184. }
  185. JSONObject fdageJson = JSONObject.parseObject(FileUtils.readFile(message.getPath().concat("/capture/data.fdage")));
  186. boolean rewrite = false;
  187. // 兼容旧的数据,防止OnlyExportMeshObj标志未删除掉
  188. if (fdageJson.containsKey("OnlyExportMeshObj")) {
  189. log.info("data.fdage 包含 OnlyExportMeshObj,进行去除!");
  190. // 写入data.fdage 防止重算
  191. fdageJson.remove("OnlyExportMeshObj");
  192. String ossPath = getOssPath(message.getPath());
  193. fYunFileService.uploadFile(fdageJson.toJSONString().getBytes(), ossPath + "data.fdage");
  194. rewrite = true;
  195. }
  196. if (!ObjectUtils.isEmpty(modelType)) {
  197. // 修改dataFdage文件
  198. fdageJson.put("modelType", modelType);
  199. rewrite = true;
  200. }
  201. if (rewrite) {
  202. FileUtils.writeFile(message.getPath().concat("/capture/data.fdage"), fdageJson.toJSONString());
  203. }
  204. message.getBuildContext().put("cameraType",message.getCameraType());
  205. //查询是否超过比例50%,如果超过,则启动128G服务器弹性伸缩
  206. Float maxRate = fdageJson.getFloat("maxRate");
  207. if(env.equals("gn") && Objects.nonNull(maxRate) && maxRate > 50){
  208. Map<String, Object> ext = message.getExt();
  209. if(Objects.isNull(ext)){
  210. ext = new HashMap<>();
  211. message.setExt(ext);
  212. }
  213. ext.put("128G", 1);
  214. }
  215. jmgaService.sendStatus(num, "排队中");
  216. boolean elastic = false;
  217. if(CollUtil.isNotEmpty(elasticUserIds)){
  218. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  219. if(elasticUserIds.contains(scenePlus.getUserId())){
  220. elastic = true;
  221. }
  222. }
  223. if(elastic){
  224. mqProducer.sendByWorkQueue("modeling-call-C", message);
  225. Thread.sleep(10000L);
  226. //查询队列是否存在堆积(未消费数>0)
  227. Long count = rabbitTemplate.execute(channel -> channel.messageCount("modeling-call-C"));
  228. //开启弹性伸缩
  229. if(Objects.nonNull(count) && count > 0){
  230. ecsScaling.createEcs();
  231. }
  232. }else{
  233. mqProducer.sendByWorkQueue(queueModelingCall, message);
  234. }
  235. if(StrUtil.isNotEmpty(batchIds)){
  236. origFileUploadBatchService.update(new LambdaUpdateWrapper<OrigFileUploadBatch>().set(OrigFileUploadBatch::getStatus, 1).in(OrigFileUploadBatch::getBatchId, batchIds.split(",")));
  237. }
  238. log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
  239. }catch (Exception e){
  240. log.error("场景计算前置处理出错,num"+num, e);
  241. String reason = "";
  242. if(e instanceof BusinessException){
  243. int code = ((BusinessException) e).getCode();
  244. if(code == ErrorCode.FAILURE_CODE_4001.code()){
  245. reason = "文件缺失,请重新上传";
  246. }
  247. }else{
  248. reason = "前置处理异常";
  249. }
  250. if(StrUtil.isNotEmpty(batchIds)){
  251. List<OrigFileUploadBatch> list = origFileUploadBatchService.list(new LambdaQueryWrapper<OrigFileUploadBatch>().in(OrigFileUploadBatch::getBatchId, batchIds));
  252. for (OrigFileUploadBatch origFileUploadBatch : list) {
  253. if(origFileUploadBatch.getCreateTime().before(DateExtUtil.offsetDay(new Date(), -1))){//一天之内重试,超过一天就认为此批次没有可用价值,置为异常状态
  254. origFileUploadBatch.setStatus(-1);
  255. origFileUploadBatch.setUpdateTime(new Date());
  256. origFileUploadBatchService.updateById(origFileUploadBatch);
  257. }
  258. }
  259. }
  260. //修改场景状态为失败,并打包日志
  261. jmgaService.updateSceneFailAndZipLog(num, reason);
  262. //推送海鑫场景状态和进度
  263. Map<String, Object> ext = message.getExt();
  264. if(CollUtil.isNotEmpty(ext)){
  265. Long sceneOrigBdId = (Long) ext.get("sceneOrigBdId");
  266. if(sceneOrigBdId != null){
  267. haixinService.syncRenderStatus(sceneOrigBdId, 4, null, "场景计算前置处理出错");
  268. }
  269. }
  270. this.sendFailToLaser(num);
  271. jmgaService.sendStatus(num, "计算失败");
  272. throw e;
  273. }
  274. }
  275. private String getOssPath(String path) {
  276. String ossPath = ConstantFilePath.OSS_PREFIX
  277. + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "")
  278. .replace(ConstantFilePath.BUILD_MODEL_LASER_PATH, "");
  279. if (!ossPath.endsWith("/")) {
  280. ossPath = ossPath.concat("/");
  281. }
  282. return ossPath;
  283. }
  284. @Override
  285. public void downLoadSource(BuildSceneCallMessage buildSceneMqMessage,String path){
  286. String ossPath = getOssPath(path);
  287. fYunFileService.downloadByCommand(path + File.separator + "capture", ossPath, true);
  288. }
  289. @Override
  290. public void buildScenePost(BuildSceneResultMqMessage message) throws Exception {
  291. String sceneCode = message.getBuildContext().get("sceneNum").toString();
  292. String path = message.getPath();
  293. boolean status = false;
  294. String batchIds = (String) message.getExt().get("batchId");
  295. Object sceneOrigBdIdObj = message.getExt().get("sceneOrigBdId");
  296. Long sceneOrigBdId = null;
  297. if(sceneOrigBdIdObj != null){
  298. sceneOrigBdId = Long.valueOf(sceneOrigBdIdObj.toString());
  299. }
  300. Long count = redisUtil.decr("modeling-count:" + sceneCode, 1);
  301. log.info("场景:{},剩余计算次数:{}", sceneCode, count);
  302. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(sceneCode);
  303. try {
  304. //如果场景被删除,就无需往下运行了
  305. if(Objects.isNull(scenePlus)){
  306. log.info("场景已被删除,场景码:{}", sceneCode);
  307. return;
  308. }
  309. // 上传计算日志
  310. //如果是重复计算,没有走到计算逻辑,不需要上传日志文件
  311. log.info("开始上传计算日志");
  312. String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneCode);
  313. fYunFileService.uploadFile(path + File.separator + "console.log", buildLogPath + "console.log");
  314. log.info("计算日志上传完成");
  315. JSONObject fdageData = getFdageData(path + File.separator + "capture" +File.separator+"data.fdage");
  316. if (!message.getBuildSuccess()) {
  317. log.error("建模失败,修改状态为失败状态");
  318. if(count < 1){
  319. jmgaService.updateSceneFailAndZipLog(sceneCode, "算法报错");
  320. if(sceneOrigBdId != null){
  321. haixinService.syncRenderStatus(sceneOrigBdId, 4, null, "算法失败");
  322. }
  323. this.sendFailToLaser(sceneCode);
  324. String statusJsonKey = String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode) + "status.json";
  325. String fileContent = fYunFileService.getFileContent(statusJsonKey);
  326. JSONObject statusJson = JSON.parseObject(fileContent);
  327. statusJson.put("status", -1);
  328. fYunFileService.uploadFile(statusJson.toJSONString().getBytes(StandardCharsets.UTF_8), statusJsonKey);
  329. jmgaService.sendStatus(sceneCode, "计算失败");
  330. }
  331. // redisUtil.set(String.format(RedisKey.SCENE_BUILD_FINISH_NUM, sceneCode), "-1");
  332. return;
  333. }
  334. Integer cameraType = Integer.parseInt(message.getBuildContext().get("cameraType").toString());
  335. Map<String, String> uploadFiles = getUploadFiles(scenePlus,path,cameraType,fdageData);
  336. scenePlus.setPayStatus(PayStatus.PAY.code());
  337. scenePlus.setUpdateTime(new Date());
  338. scenePlus.setSceneStatus(SceneStatus.NO_DISPLAY.code());
  339. Integer videoVersion = fdageData.getInteger("videoVersion");
  340. //读取计算结果文件生成videosJson
  341. JSONObject videosJson = this.getVideosJson(path, videoVersion, sceneCode, cameraType);
  342. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  343. boolean isObj = fdageData.containsKey("exportMeshObj") && fdageData.getIntValue("exportMeshObj") == 1;
  344. //上传全景图俯视图
  345. this.uploadFloorCad(path, sceneCode, uploadFiles);
  346. Integer hasAi = this.uploadFreespace(sceneCode, path, uploadFiles);
  347. scenePlus.setHasAi(hasAi);
  348. log.info("开始上传场景计算结果数据,num:{}", sceneCode);
  349. //由于3dtiles算法mesh文件发生变化,所以这里需要先清除一下oss的mesh目录,避免存在旧算法obj文件
  350. fYunFileService.deleteFolder(String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode) + "mesh");
  351. fYunFileService.deleteFolder(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ModelKind.THREE_D_TILE.code());
  352. //上传文件
  353. fYunFileService.uploadMulFiles(uploadFiles);
  354. //修改oss上dam的内容编码
  355. // Map<String,String> damFileHeaders = new HashMap<>();
  356. // damFileHeaders.put("Content-Encoding","gzip");
  357. // String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
  358. // fYunFileService.uploadFile(damPath, String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode) + ConstantFileName.modelUUID + "_50k.dam", damFileHeaders);
  359. //拷贝部分文件到编辑目录,用于用户编辑
  360. this.copyToEditDir(sceneCode);
  361. //计算完毕后,同步全景图到缓存目录
  362. // this.cachePanorama(path, sceneCode);
  363. //生成houseTypejson并上传
  364. // boolean existHouseType = this.uploadHouseTypeJson(sceneCode, path);
  365. // scenePlus.setHouseType(existHouseType ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue());
  366. //生成场景关联数据
  367. Integer links = linkPanService.genLinkPanPost(sceneCode);
  368. //生成floorpan.json
  369. commonService.uploadFloorplanJson(sceneCode, path);
  370. //江门需求,算法识别平面图
  371. commonService.uploadFloorplanAi(sceneCode, path);
  372. LinkedHashMap<Integer, Boolean> detFloorplan = message.getDetFloorplan();
  373. boolean hasFloorplanAi = commonService.detFloorPlanAi(sceneCode, path, detFloorplan);
  374. if(hasFloorplanAi){
  375. scenePlus.setHasFloorplanAi(CommonStatus.YES.code().intValue());
  376. }else{
  377. scenePlus.setHasFloorplanAi(CommonStatus.NO.code().intValue());
  378. }
  379. //重置异步操作记录
  380. commonService.removeSceneAsynOperLog(sceneCode);
  381. //清除用户编辑业务数据
  382. Set<String> bizs = new HashSet<>();
  383. bizs.add(UserEditDataType.BOX_MODEL.message());
  384. bizs.add(UserEditDataType.FLOORPLAN.message());
  385. bizs.add(UserEditDataType.FILTERS.message());
  386. commonService.initUserEditData(sceneCode, bizs, null);
  387. //上传计算结果文件
  388. commonService.uploadBuildResultData(sceneCode, path, SceneVersionType.V4.code());
  389. //容量统计
  390. Long space = commonService.getSpace(sceneCode);
  391. //ai识别
  392. aiService.detectScenePano(scenePlus, scenePlusExt, path);
  393. //写入数据库
  394. this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), message.getComputeTime(),isObj,scenePlusExt);
  395. Object[] editInfoArr = commonService.updateEditInfo(scenePlus);
  396. SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
  397. SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
  398. SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
  399. sceneEditInfoExt.setLinks(links);
  400. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  401. //更新场景主表
  402. //如果相机容量不足,需要把场景的paystatus改为容量不足状态
  403. scenePlus.setPayStatus(commonService.getPayStatus(scenePlus.getCameraId(), space));
  404. //统计原始资源大小
  405. scenePlusExt.setOrigSpace(FileUtil.size(new File(path.concat(File.separator).concat("capture"))));
  406. scenePlusExt.setOrientation(fdageData.getString("orientation"));
  407. if (cameraType == 14) {
  408. //计算成功 激光转台相机 同步 请求
  409. fdkkLaserService.syncBuildResult(
  410. SyncLaserResultBean.builder()
  411. .num(sceneCode).dataSource(path)
  412. .sceneStatus(2)
  413. .createTime(scenePlus.getCreateTime())
  414. .shootCount(scenePlusExt.getShootCount())
  415. .payStatus(scenePlus.getPayStatus())
  416. .mixture(scenePlusExt.getMixture())
  417. .version(SceneVersionType.V4.code()).build());
  418. if(message.getRebuild().equals("0")){//场景第一次计算,需要判断是否有地理位置信息,如果有,则需要默认勾选上迷你地图,地面logo设置默认为指南针
  419. Integer mapStatus = rtkService.getMapStatus(scenePlusExt.getDataSource());
  420. if(mapStatus == 1){
  421. sceneEditControls.setShowMap(3);
  422. sceneEditControls.setUpdateTime(null);
  423. sceneEditInfoExt.setFloorLogoType(0);
  424. }
  425. }
  426. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  427. sceneEditControlsService.updateById(sceneEditControls);
  428. } else if (new File(path + "/results/laserData/vision_edit.txt").exists()) {
  429. fdkkLaserService.cloudPointBuild(sceneCode,path);
  430. }
  431. if(cameraType == 6){
  432. scenePlusExt.setModelKind(modelKind);
  433. }
  434. log.info("生成scene.json上传oss并设置缓存,num:{}", sceneCode);
  435. CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
  436. Company company = !ObjectUtils.isEmpty(cameraDetail.getCompanyId()) ? companyService.getById(cameraDetail.getCompanyId()) : null;
  437. //写scene.json
  438. commonService.writeSceneJson(sceneCode, videosJson,sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus,scenePlusExt,company);
  439. //删除计算目录
  440. if(CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)){
  441. CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/"));
  442. }
  443. //更新场景主表
  444. //如果相机容量不足,需要把场景的paystatus改为容量不足状态
  445. if (cameraType != 14) {
  446. scenePlus.setPayStatus(commonService.getPayStatus(scenePlus.getCameraId(), space));
  447. }
  448. this.uploadStatusJson(scenePlus, scenePlusExt);
  449. scenePlusService.updateById(scenePlus);
  450. scenePlusExtService.updateById(scenePlusExt);
  451. //推送场景码以及案件号到案件系统
  452. Map<String, String> params = new HashMap<>();
  453. params.put("num", sceneCode);
  454. params.put("kNo",scenePlus.getKNo());
  455. mqProducer.sendByWorkQueue("queue-aj-add-scene", params);
  456. //推送ai识别平面图mq
  457. this.sendMqForAiPano(sceneCode);
  458. //自动ai识别只在场景初次计算时执行
  459. if(StrUtil.isEmpty(message.getRebuild()) || message.getRebuild().equals("0")){
  460. this.sendMqForAiSeg(sceneCode);
  461. }
  462. log.info("场景计算结果处理结束,场景码:{}", sceneCode);
  463. if(sceneOrigBdId != null){
  464. haixinService.syncRenderStatus(sceneOrigBdId, 3, null, null);
  465. }
  466. jmgaService.sendStatus(sceneCode, "计算成功");
  467. }catch (Exception e){
  468. log.error("场景计算结果处理出错,num"+sceneCode, e);
  469. jmgaService.updateSceneFailAndZipLog(sceneCode, "后置处理异常");
  470. if(sceneOrigBdId != null){
  471. haixinService.syncRenderStatus(sceneOrigBdId, 4, null, "算法失败");
  472. }
  473. this.sendFailToLaser(sceneCode);
  474. jmgaService.sendStatus(sceneCode, "计算失败");
  475. throw e;
  476. } finally {
  477. Map<String, Object> sceneStatusParam = new HashMap<>();
  478. sceneStatusParam.put("num", sceneCode);
  479. sceneStatusParam.put("status", message.getBuildSuccess() ? 1 : -1);
  480. if(StrUtil.isNotEmpty(batchIds)){
  481. origFileUploadBatchService.update(new LambdaUpdateWrapper<OrigFileUploadBatch>().set(OrigFileUploadBatch::getStatus, 3).in(OrigFileUploadBatch::getBatchId, batchIds.split(",")));
  482. }
  483. }
  484. }
  485. private Integer uploadFreespace(String num, String path, Map<String, String> map){
  486. String floor0pngPath = "/results/floorplan/floor_0.png";
  487. String plyPath = path + "/results/laserData/cover/final_freespace.ply";
  488. String pngPath = path + "/results/laserData/cover/final_freespace.png";
  489. String infoJsonPath = path + "/results/laserData/cover/info.json";
  490. Integer hasAi = CommonStatus.NO.code().intValue();
  491. if(FileUtil.exist(floor0pngPath) || FileUtil.exist(plyPath)){
  492. hasAi = CommonStatus.YES.code().intValue();
  493. map.put(plyPath, String.format(UploadFilePath.IMG_VIEW_PATH, num) + "cover/" + FileUtil.getName(plyPath));
  494. }
  495. if(FileUtil.exist(pngPath)){
  496. map.put(pngPath, String.format(UploadFilePath.IMG_VIEW_PATH, num) + "cover/" + FileUtil.getName(pngPath));
  497. }
  498. if(FileUtil.exist(infoJsonPath)){
  499. map.put(infoJsonPath, String.format(UploadFilePath.IMG_VIEW_PATH, num) + "cover/" + FileUtil.getName(infoJsonPath));
  500. }
  501. return hasAi;
  502. }
  503. private void sendMqForBcgn(String num){
  504. Map<String, String> map = new HashMap<>();
  505. map.put("num", num);
  506. mqProducer.sendByWorkQueue("detect-queue", map);
  507. }
  508. private void sendMqForAiPano(String num){
  509. Map<String, String> map = new HashMap<>();
  510. map.put("num", num);
  511. mqProducer.sendByWorkQueue("detect-queue-pano", map);
  512. }
  513. private void sendMqForAiSeg(String num){
  514. Map<String, String> map = new HashMap<>();
  515. map.put("num", num);
  516. mqProducer.sendByWorkQueue("pano-ai-seg", map);
  517. }
  518. private Map<String, String> getUploadFiles(ScenePlus scenePlus,String path,Integer cameraType,JSONObject fdageData) throws Exception {
  519. if (ObjectUtils.isEmpty(scenePlus)) {
  520. throw new Exception("未找到场景信息:" + path);
  521. }
  522. String projectNum = scenePlus.getNum();
  523. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, projectNum);
  524. String imagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, projectNum);
  525. String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, projectNum);
  526. String resultsPath = path + File.separator + "results" + File.separator;
  527. String uploadData = FileUtils.readFile(resultsPath + "upload.json");
  528. JSONArray array = JSONObject.parseObject(uploadData).getJSONArray("upload");
  529. JSONObject fileJson = null;
  530. String fileName = "";
  531. Map<String, String> map = new HashMap();
  532. for (int i = 0; i < array.size(); ++i) {
  533. fileJson = array.getJSONObject(i);
  534. fileName = fileJson.getString("file");
  535. String filePath = resultsPath + fileName;
  536. if (!(new File(filePath)).exists()) {
  537. throw new Exception(filePath + "文件不存在");
  538. }
  539. if ("vision2.txt".equals(fileName)) {
  540. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision2.txt", resultsPath + "vision2.modeldata");
  541. map.put(resultsPath + "vision2.modeldata", imagesPath + "vision2.modeldata");
  542. map.put(resultsPath + "vision2.txt", imagesPath + "vision2.txt");
  543. }
  544. if (fileJson.getIntValue("clazz") == 2) {
  545. map.put(filePath, imagesPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
  546. } else if (fileJson.getIntValue("clazz") == 3) {
  547. map.put(filePath, imagesPath + "pan/high/" + fileName.replace("high/", ""));
  548. } else if (fileJson.getIntValue("clazz") == 4) {
  549. map.put(filePath, imagesPath + "pan/low/" + fileName.replace("low/", ""));
  550. } else if (fileJson.getIntValue("clazz") == 5) {
  551. map.put(filePath, imagesPath + fileName);
  552. } else if (fileJson.getIntValue("clazz") == 7) {
  553. map.put(filePath, imagesPath + fileName);
  554. } else if (fileJson.getIntValue("clazz") == 10) {
  555. String updown = FileUtils.readFile(filePath);
  556. JSONObject updownJson = JSONObject.parseObject(updown);
  557. String mappingOssPath = String.format("scene_edit_data/%s/data/", projectNum) + fileName.replace("updown", "mapping");
  558. map.put(filePath, mappingOssPath);
  559. } else {
  560. if (fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("clazz") == 12) {
  561. map.put(filePath, videoPath + fileName.replace("videos/", ""));
  562. if (fileName.contains(".mp4")) {
  563. map.put(resultsPath + fileName.replace("mp4", "flv"), videoPath + fileName.replace("videos/", "").replace("mp4", "flv"));
  564. }
  565. }
  566. if (fileJson.getIntValue("clazz") == 16) {
  567. map.put(filePath, dataViewPath + fileName);
  568. }
  569. if (fileJson.getIntValue("clazz") == 18) {
  570. map.put(filePath, imagesPath + fileName);
  571. }
  572. }
  573. }
  574. //exportMeshObj这个是字段由app写入的
  575. boolean genModel = true;//是否生成模型 默认生成,深时场景要根据 exportMeshObj判断是否生成
  576. if(!ObjectUtils.isEmpty(cameraType)
  577. && cameraType == 14
  578. && (!fdageData.containsKey("exportMeshObj") || fdageData.getIntValue("exportMeshObj") != 1)){
  579. genModel = false;
  580. }
  581. boolean gen3dTiles = true;//是否生成3dtiles模型 默认生成
  582. if(!ModelKind.THREE_D_TILE.code().equals(modelKind)
  583. || CollUtil.isEmpty(sdTilesSceneSourceList)
  584. || !sdTilesSceneSourceList.contains(scenePlus.getSceneSource())){
  585. gen3dTiles = false;
  586. }
  587. if(cameraType == 6){
  588. gen3dTiles = true;
  589. }
  590. if(cameraType == 6){
  591. gen3dTiles = true;
  592. }
  593. if(genModel){
  594. if (!gen3dTiles) {
  595. String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
  596. CreateObjUtil.convertTxtToDam(path + File.separator + "results" + File.separator + "tex" + File.separator + "modeldata.txt", damPath);
  597. // FileUtil.writeBytes(ZipUtil.gzip(new File(damPath)), damPath);
  598. map.put(damPath, imagesPath + ConstantFileName.modelUUID + "_50k.dam");
  599. }else{
  600. List<String> list = FileUtils.list(new File(path + File.separator + "results" + File.separator + ModelKind.THREE_D_TILE.code()));
  601. if(CollUtil.isEmpty(list)){
  602. log.error("3dtiles目录异常,3dtiles地址:{}", new File(path + File.separator + "results" + File.separator + ModelKind.THREE_D_TILE.code()));
  603. throw new Exception("3dtiles目录异常");
  604. }
  605. list.stream().forEach(str->{
  606. map.put(str, str.replace(path + File.separator + "results" + File.separator, imagesPath));
  607. });
  608. }
  609. }
  610. CreateObjUtil.convertTxtToVisionmodeldata(resultsPath + "vision.txt", resultsPath + "vision.modeldata");
  611. map.put(resultsPath + "vision.txt", imagesPath + "vision.txt");
  612. map.put(resultsPath + "vision.modeldata", imagesPath + "vision.modeldata");
  613. log.info("数据转换完成:" + projectNum);
  614. if(!new File("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum).exists()){
  615. FileUtil.mkdir("/mnt/4Dkankan/scene/data" + File.separator + "data" + projectNum);
  616. }
  617. // map.put(resultsPath + "floorplan.json", dataViewPath + "floor.json");
  618. map.put(resultsPath + "floorplan_cad.json", dataViewPath + "floorplan_cad.json");
  619. map.put(path + File.separator + "capture/stitch_params.txt", dataViewPath + "stitch_params.txt");
  620. map.put(path + File.separator + "capture/Up.xml", dataViewPath + "Up.xml");
  621. map.put(path + File.separator + "capture/Up2.xml", dataViewPath + "Up2.xml");
  622. map.put(path + File.separator + "capture/Up.txt", dataViewPath + "Up.txt");
  623. map.put(path + File.separator + "capture/Up2.txt", dataViewPath + "Up2.txt");
  624. return map;
  625. }
  626. private JSONObject getFdageData(String dataFdagePath) {
  627. log.info("dataFdagePath 文件路径 :{}", dataFdagePath);
  628. String data = FileUtils.readFile(dataFdagePath);
  629. //获取data.fdage的内容
  630. JSONObject dataJson = new JSONObject();
  631. if(data!=null){
  632. dataJson = JSONObject.parseObject(data);
  633. }
  634. return dataJson;
  635. }
  636. private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles){
  637. //户型图上传
  638. String dataViewPath = UploadFilePath.DATA_VIEW_PATH + "floor-cad-%s.%s";
  639. String floorCadPath = path + "/results/floorplan_cad";
  640. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  641. if(CollUtil.isNotEmpty(floorCadList)){
  642. floorCadList.stream().forEach(str->{
  643. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  644. String[] arr = substring.split("floor");
  645. String[] arr2 = arr[1].split("\\.");
  646. uploadFiles.put(str, String.format(dataViewPath, num, arr2[0], arr2[1]));
  647. });
  648. }
  649. }
  650. private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt){
  651. String num = scenePlus.getNum();
  652. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  653. Integer status = 1;
  654. if(scenePlus.getSceneSource() == 4 || scenePlus.getSceneSource() == 5){//如果是激光场景,需要激光系统那边完全处理好之后再发mq通知更新状态
  655. status = 0;
  656. }
  657. // 上传status JSON.
  658. JSONObject statusJson = new JSONObject();
  659. //临时将-2改成1,app还没完全更新
  660. statusJson.put("status", status);
  661. statusJson.put("webSite", scenePlusExt.getWebSite());
  662. statusJson.put("sceneNum", num);
  663. statusJson.put("thumb", scenePlusExt.getThumb());
  664. statusJson.put("payStatus", scenePlus.getPayStatus());
  665. statusJson.put("sceneScheme", scenePlusExt.getSceneScheme());
  666. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
  667. Map<String,String> headers = new HashMap<>();
  668. headers.put(HttpHeaders.CONTENT_TYPE, ContentType.JSON.getValue());
  669. fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", dataViewPath + "status.json", headers);
  670. }
  671. private void createQrCode(String num, ScenePlusExt scenePlusExt, String qrLogo) {
  672. String localLogoPath = null;
  673. if (!ObjectUtils.isEmpty(qrLogo)) {
  674. try {
  675. localLogoPath = ConstantFilePath.AGENT_PATH + qrLogo.substring(qrLogo.lastIndexOf("//") + 1);
  676. HttpUtil.downloadFile(qrLogo, localLogoPath);
  677. } catch (Exception e) {
  678. log.error("公司logo下载失败:{}", qrLogo);
  679. localLogoPath = null;
  680. }
  681. }
  682. //生成二维码
  683. String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +".png";
  684. String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+ num +"_en.png";
  685. QrConfig qrConfig = QrConfig.create();
  686. qrConfig.setWidth(1024);
  687. qrConfig.setHeight(1024);
  688. if(StrUtil.isNotEmpty(localLogoPath)){
  689. qrConfig.setImg(localLogoPath);
  690. }
  691. QrCodeUtil.generate(scenePlusExt.getWebSite(), qrConfig, FileUtil.file(outPathZh));
  692. QrCodeUtil.generate(scenePlusExt.getWebSite() + "&lang=en", qrConfig, FileUtil.file(outPathEn));
  693. //上传二维码
  694. fYunFileService.uploadFile(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + ".png");
  695. fYunFileService.uploadFile(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, num) + num + "_en.png");
  696. if(!ObjectUtils.isEmpty(localLogoPath)){
  697. FileUtils.deleteFile(localLogoPath);
  698. }
  699. }
  700. private void pushMsgToApp(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
  701. log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
  702. if(Objects.isNull(pushChannel) || StrUtil.isBlank(pushToken)){
  703. return;
  704. }
  705. String title = sceneName + "计算完成";
  706. String body = "您上传的" + sceneName + "计算完成,点击查看";
  707. try{
  708. if(FYunTypeEnum.AWS.code().equals(fYunFileService.getFyunType())){
  709. PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
  710. title, body , webSite);
  711. return;
  712. }
  713. PushMessageConfig pushConfig = null;
  714. if(pushChannel == 0){
  715. if(cameraType == 10 || cameraType == 13){
  716. //ios
  717. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY_Z, PushMessageConfig.IOS_SECRET_Z);
  718. pushConfig.sendIOSUnicast(pushToken, "四维看看Minion",title, body, webSite);
  719. }else {
  720. //ios
  721. pushConfig = new PushMessageConfig(PushMessageConfig.IOS_KEY, PushMessageConfig.IOS_SECRET);
  722. pushConfig.sendIOSUnicast(pushToken, "四维看看Pro",title, body, webSite);
  723. }
  724. }else {
  725. if(cameraType == 10 || cameraType == 13){
  726. //ios
  727. //安卓
  728. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY_Z, PushMessageConfig.ANDROID_SECRET_Z);
  729. pushConfig.sendAndroidUnicast2(pushToken, "四维看看Minion",title, body, webSite);
  730. }else {
  731. //安卓
  732. pushConfig = new PushMessageConfig(PushMessageConfig.ANDROID_KEY, PushMessageConfig.ANDROID_SECRET);
  733. pushConfig.sendAndroidUnicast(pushToken, "四维看看Pro",title, body, webSite);
  734. }
  735. }
  736. log.info("消息推送结束!");
  737. }catch (Exception e){
  738. log.error("推送消息失败:", e);
  739. }
  740. }
  741. private void copyToEditDir(String num) throws IOException {
  742. String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  743. String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  744. String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
  745. String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  746. Map<String, String> map = new HashMap<>();
  747. map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
  748. map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
  749. map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
  750. for (Entry<String, String> entry : map.entrySet()) {
  751. fYunFileService.copyFileInBucket(entry.getValue(), entry.getKey());
  752. }
  753. }
  754. private JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception {
  755. //读取videos_hdr_param.json, 保存点位视频的value
  756. Map<String, Object> videoMap = new HashMap<>();
  757. String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
  758. JSONArray videoArray = null;
  759. if(StringUtils.isNotEmpty(videosHdr)){
  760. videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
  761. }
  762. if(videoArray != null){
  763. for(int i = 0, len = videoArray.size(); i < len; i++) {
  764. videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
  765. if(videoArray.getJSONObject(i).containsKey("fov")){
  766. videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
  767. }
  768. }
  769. }
  770. //获取upload中的video视频名称
  771. String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
  772. JSONObject uploadJson = null;
  773. JSONArray array = null;
  774. if(uploadData!=null) {
  775. uploadJson = JSONObject.parseObject(uploadData);
  776. array = uploadJson.getJSONArray("upload");
  777. }
  778. JSONObject fileJson = null;
  779. String fileName = "";
  780. //计算ts文件的大小,并拼接成json格式
  781. JSONArray jsonArray = new JSONArray();
  782. JSONObject videoJson = null;
  783. JSONObject videosJson = new JSONObject();
  784. long videoSize = 0L;
  785. for(int i = 0, len = array.size(); i < len; i++) {
  786. fileJson = array.getJSONObject(i);
  787. fileName = fileJson.getString("file");
  788. if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
  789. videoJson = new JSONObject();
  790. videoJson.put("id", fileName.substring(
  791. 0, fileName.lastIndexOf(".")).replace("videos/", ""));
  792. //如果ts文件存在,就计算ts大小
  793. if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
  794. videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
  795. videoJson.put("tsSize", videoSize);
  796. }
  797. if(videoMap.containsKey(videoJson.get("id"))){
  798. videoJson.put("value", videoMap.get(videoJson.get("id")));
  799. }
  800. if(videoMap.containsKey(videoJson.get("id") + "_fov")){
  801. videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
  802. }else {
  803. videoJson.put("blend_fov", 7);
  804. }
  805. jsonArray.add(videoJson);
  806. }
  807. }
  808. videosJson.put("data", jsonArray);
  809. if(Objects.nonNull(videoVersion) && videoVersion >= 4){
  810. videosJson.put("version", 3);
  811. videosJson.put("upPath", String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up.xml");
  812. if(cameraType == 13 || cameraType == 14){
  813. //转台相机
  814. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  815. }
  816. }else {
  817. videosJson.put("version", 1);
  818. videosJson.put("upPath", String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "Up2.xml");
  819. if(cameraType == 13 || cameraType == 14){
  820. //转台相机
  821. videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
  822. }
  823. }
  824. if(cameraType == 5 || cameraType == 6){
  825. videosJson.put("version", 1);
  826. videosJson.put("upPath", String.format(UploadFilePath.DATA_VIEW_PATH, projectNum) + "stitch_params.txt");
  827. }
  828. return videosJson;
  829. }
  830. private void updateDbPlus(int sceneSource,Long space,String videosJson, Long computeTime,boolean isObj,ScenePlusExt scenePlusExt){
  831. scenePlusExt.setSpace(space);
  832. scenePlusExt.setComputeTime(computeTime.toString());
  833. scenePlusExt.setAlgorithmTime(new Date());
  834. scenePlusExt.setVideos(videosJson);
  835. scenePlusExt.setIsObj(isObj ? 1 : 0);
  836. if(ModelTypeEnums.TILE_CODE.equals(modelType)){
  837. scenePlusExt.setSceneScheme(3);
  838. }
  839. switch (SceneSource.get(sceneSource)){
  840. case BM:
  841. scenePlusExt.setSceneResolution(SceneResolution.two_K.code());
  842. scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
  843. break;
  844. case SM:
  845. scenePlusExt.setSceneResolution(SceneResolution.one_k.code());
  846. scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
  847. break;
  848. case ZT:
  849. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  850. scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
  851. break;
  852. case JG:
  853. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  854. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  855. break;
  856. case SG:
  857. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  858. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  859. break;
  860. }
  861. String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
  862. scenePlusExt.setSceneKind(sceneKind);
  863. // scenePlusExt.setModelKind(modelKind);
  864. //统计点位数量
  865. Map<String, Integer> result = this.getShootCount(scenePlusExt);
  866. Integer shootCount = result.get("shootCount");
  867. Integer mixture = result.get("mixture");
  868. scenePlusExt.setShootCount(shootCount);
  869. scenePlusExt.setMixture(mixture);
  870. scenePlusExtService.updateById(scenePlusExt);
  871. }
  872. private Map<String, Integer> getShootCount(ScenePlusExt scenePlusExt){
  873. Map<String, Integer> result = new HashMap<>();
  874. Integer shootCount = 0;
  875. Integer mixture = Objects.isNull(scenePlusExt.getMixture()) ? 0 : scenePlusExt.getMixture();
  876. String homePath = SceneUtil.getHomePath(scenePlusExt.getDataSource());
  877. JSONObject dataFdageObj = JSON.parseObject(fYunFileService.getFileContent(homePath.concat("data.fdage")));
  878. if(Objects.nonNull(dataFdageObj)){
  879. JSONArray points = dataFdageObj.getJSONArray("points");
  880. if(CollUtil.isNotEmpty(points)){
  881. shootCount = points.size();
  882. }
  883. }
  884. if(Objects.nonNull(shootCount) && shootCount > 0){
  885. if(Objects.nonNull(scenePlusExt.getLocation()) && scenePlusExt.getLocation() == 6){
  886. mixture = CommonStatus.YES.code().intValue();
  887. }
  888. }else{
  889. String slamDataStr = fYunFileService.getFileContent(homePath.concat("slam_data.json"));
  890. JSONObject slamDataObj = JSON.parseObject(slamDataStr);
  891. if(Objects.nonNull(slamDataObj)){
  892. JSONArray viewsInfo = slamDataObj.getJSONArray("views_info");
  893. if(CollUtil.isNotEmpty(viewsInfo)){
  894. shootCount = viewsInfo.stream().mapToInt(info -> {
  895. return ((JSONObject) info).getJSONArray("list_pose").size();
  896. }).sum();
  897. }
  898. }
  899. mixture = CommonStatus.NO.code().intValue();
  900. }
  901. result.put("shootCount", shootCount);
  902. result.put("mixture", mixture);
  903. return result;
  904. }
  905. public static void main(String[] args) {
  906. // JSONObject dataFdageObj = JSON.parseObject(null);
  907. // System.out.println(dataFdageObj);
  908. // String test ="{\"rebuild\":\"0\",\"flexibility\":0,\"isStandardization\":null,\"createTime\":null,\"resultReceiverMqName\":null,\"buildContext\":{\"sceneNum\":\"SG-jm-JT77TjCZwF5\",\"cameraType\":\"14\"},\"computeTime\":446,\"buildSuccess\":true,\"path\":\"/mnt/data/bpvt00006/1328767184540794880/bpvt00006_202412301634030230\",\"hostName\":null,\"ext\":{\"deleteExtras\":true,\"detFloorplan\":{\"0\":true,\"4\":true,\"3\":true,\"1\":true},\"location\":4,\"linkPanTargetList\":[\"/mnt/data/bpvt00006/1328767184540794880/bpvt00006_202412301634030230/linkPan/panorama/0_pano_0\",\"/mnt/data/bpvt00006/1328767184540794880/bpvt00006_202412301634030230/linkPan/panorama/1_pano_0\"]},\"errorType\":null}";
  909. // BuildSceneResultMqMessage message = JSONObject.parseObject(test, BuildSceneResultMqMessage.class);
  910. // Map<String, Object> ext = message.getExt();
  911. // JSONObject detFloorplanObj = (JSONObject)ext.get("detFloorplan");
  912. // for (String s : detFloorplanObj.keySet()) {
  913. // System.out.println(s + ":" + detFloorplanObj.getBoolean(s));
  914. //
  915. // }
  916. // try {
  917. // throw new BusinessException(345, "哈哈哈");
  918. // }catch (Exception e){
  919. // if(e instanceof BusinessException){
  920. // System.out.println(((BusinessException) e).getCode());
  921. // System.out.println(((BusinessException) e).getMessage());
  922. // }
  923. // }
  924. Map<String, Object> params = new HashMap<>();
  925. params.put("count", 5);
  926. params.put("ackmode", "ack_requeue_true");
  927. params.put("encoding", "auto");
  928. String url = "http://119.23.182.50:15672/api/queues/4dkankan/modeling-call-C/get";
  929. // String s = HttpUtil.post(url, params);
  930. // System.out.println(s);
  931. Map<String, String> map = new HashMap<>();
  932. map.put("authorization", "Basic cm9vdDo0ZGtrMjAyM2N1aWt1YW4l");
  933. HttpResponse execute = HttpUtil.createPost(url).addHeaders(map).body(JSON.toJSONString(params)).execute();
  934. String body = execute.body();
  935. System.out.println(body);
  936. }
  937. public boolean uploadHouseTypeJson(String num, String dataSource) {
  938. String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
  939. if (!new File(floorPlanCardFilePath).exists()) {
  940. log.warn("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  941. return false;
  942. }
  943. JSONObject json = CreateHouseJsonUtil.createHouseTypeJsonByCad(floorPlanCardFilePath);
  944. if(Objects.isNull(json)){
  945. return false;
  946. }
  947. String hourseTypeJsonPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "houseType.json";
  948. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  949. hourseTypeJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "houseType.json";
  950. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  951. return true;
  952. }
  953. private void sendFailToLaser(String num){
  954. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  955. if(SceneSource.JG.code() != scenePlus.getSceneSource().intValue() && SceneSource.SG.code() != scenePlus.getSceneSource().intValue()){
  956. return;
  957. }
  958. Map<String, Object> params = new HashMap<>();
  959. params.put("sceneCode", num);
  960. params.put("status", 1);
  961. params.put("createTime", DateUtil.date2String(scenePlus.getCreateTime(), null));
  962. params.put("algorithmTime", DateUtil.date2String(Calendar.getInstance().getTime(), null));
  963. params.put("sceneSource", scenePlus.getSceneSource());
  964. fdkkLaserService.syncFailResult(params);
  965. }
  966. }