BuildSceneServiceImpl.java 51 KB

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