BuildSceneServiceImpl.java 52 KB

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