BuildSceneServiceImpl.java 53 KB

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