ScenePlusServiceImpl.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. package com.fdkankan.openApi.service.www.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.io.FileUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import cn.hutool.core.util.ZipUtil;
  7. import com.alibaba.fastjson.JSON;
  8. import com.alibaba.fastjson.JSONArray;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.baomidou.dynamic.datasource.annotation.DS;
  11. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  12. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  14. import com.fdkankan.common.constant.*;
  15. import com.fdkankan.common.exception.BusinessException;
  16. import com.fdkankan.common.util.DateUtil;
  17. import com.fdkankan.fyun.config.FYunFileConfig;
  18. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  19. import com.fdkankan.model.constants.ConstantFilePath;
  20. import com.fdkankan.model.constants.UploadFilePath;
  21. import com.fdkankan.model.utils.ComputerUtil;
  22. import com.fdkankan.model.utils.CreateObjUtil;
  23. import com.fdkankan.openApi.bean.www.SceneJsonBean;
  24. import com.fdkankan.openApi.common.PageInfo;
  25. import com.fdkankan.openApi.entity.laser.SceneEntity;
  26. import com.fdkankan.openApi.entity.www.*;
  27. import com.fdkankan.openApi.mapper.www.IScenePlusMapper;
  28. import com.fdkankan.openApi.service.laser.SceneService;
  29. import com.fdkankan.openApi.service.www.*;
  30. import com.fdkankan.openApi.vo.www.CreateFicTitiousSceneParamVO;
  31. import com.fdkankan.openApi.vo.www.PageScenesParamVo;
  32. import com.fdkankan.openApi.vo.www.SceneEditControlsVO;
  33. import com.fdkankan.openApi.vo.www.SceneVO;
  34. import com.fdkankan.redis.constant.RedisKey;
  35. import com.fdkankan.redis.util.RedisUtil;
  36. import com.fdkankan.web.response.ResultData;
  37. import org.springframework.beans.factory.annotation.Autowired;
  38. import org.springframework.beans.factory.annotation.Value;
  39. import org.springframework.stereotype.Service;
  40. import org.springframework.util.ObjectUtils;
  41. import java.io.File;
  42. import java.util.*;
  43. import java.util.stream.Collectors;
  44. /**
  45. * <p>
  46. * 场景主表 服务实现类
  47. * </p>
  48. *
  49. * @author
  50. * @since 2023-02-15
  51. */
  52. @DS("www")
  53. @Service
  54. public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlus> implements IScenePlusService {
  55. @Value("${main.url}")
  56. private String mainUrl;
  57. @Value("${scene.pro.new.url}")
  58. private String sceneUrl;
  59. @Value("#{'${camType.laser:}'.split(',')}")
  60. private List<Integer> laserCamTypeList;
  61. @Autowired
  62. private FYunFileServiceInterface fYunFileService;
  63. @Autowired
  64. private ISceneEditInfoService sceneEditInfoService;
  65. @Autowired
  66. private IScenePlusExtService scenePlusExtService;
  67. @Autowired
  68. private ISceneEditInfoExtService sceneEditInfoExtService;
  69. @Autowired
  70. private ISceneEditControlsService sceneEditControlsService;
  71. @Autowired
  72. private RedisUtil redisUtil;
  73. @Autowired
  74. private ICameraService cameraService;
  75. @Autowired
  76. private ICameraDetailService cameraDetailService;
  77. @Autowired
  78. private FYunFileConfig fYunFileConfig;
  79. @Autowired
  80. private SceneService sceneService;
  81. @Autowired
  82. private ISceneCooperationService sceneCooperationService;
  83. @Override
  84. public ScenePlus getByNumAndUserId(long userId, String num) {
  85. return this.getOne(new LambdaQueryWrapper<ScenePlus>().eq(ScenePlus::getNum, num).eq(ScenePlus::getUserId, userId));
  86. }
  87. @Override
  88. public ScenePlus getByNum(String num) {
  89. return this.getOne(new LambdaQueryWrapper<ScenePlus>().eq(ScenePlus::getNum, num));
  90. }
  91. @Override
  92. public ResultData createVirtualScene(CreateFicTitiousSceneParamVO param) throws Exception {
  93. this.checkParams4createVirtualScene(param);
  94. this.buildScene4CreateVirtualScene(param);
  95. String website = this.updateScene4CreateVirtualScene(param);
  96. return ResultData.ok(website);
  97. }
  98. @Override
  99. public ResultData createVirtualSceneV2(CreateFicTitiousSceneParamVO param) throws Exception {
  100. this.checkParams4createVirtualScene(param);
  101. this.buildScene4CreateVirtualScene(param);
  102. this.cutPanorama4CreateVirtualScene(param);
  103. String website = this.updateScene4CreateVirtualScene(param);
  104. return ResultData.ok(website);
  105. }
  106. private void cutPanorama4CreateVirtualScene(CreateFicTitiousSceneParamVO param) throws Exception {
  107. if(!param.getSceneKind().equals(SceneKind.TILES.code())){
  108. return;
  109. }
  110. String num = param.getNum();
  111. //检测原始图片是否存在
  112. String ossImagePath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  113. String ossCaptruePath = ossImagePath.concat("capture/");
  114. List<String> captrueList = fYunFileService.listRemoteFiles(ossCaptruePath);
  115. if(CollUtil.isEmpty(captrueList)){
  116. throw new BusinessException(ErrorCode.FAILURE_CODE_3018.code(), "全景图不能为空");
  117. }
  118. String target = String.format(ConstantFilePath.SCENE_IMAGES_PATH_V4, num);
  119. String targetImagesPath = target + "extras/images/";
  120. FileUtil.del(targetImagesPath);
  121. String ossVisionTxtPath = ossImagePath + "vision.txt";
  122. fYunFileService.downloadFile(ossVisionTxtPath, target + "extras" + File.separator + "vision.txt");
  123. //下载全景图
  124. fYunFileService.downloadFileByCommand(targetImagesPath, ossCaptruePath);
  125. JSONObject dataJson = new JSONObject();
  126. dataJson.put("split_type", "SPLIT_V8");
  127. JSONObject jsonObject = new JSONObject();
  128. jsonObject.put("has_vision_txt",true);
  129. jsonObject.put("has_source_images",true);
  130. dataJson.put("extras", jsonObject);
  131. //V5表示不需要生成high,low文件
  132. String skyboxType = "SKYBOX_V6";
  133. SceneResolution sceneResolution = SceneResolution.get(param.getSceneResolution());
  134. switch (sceneResolution){
  135. case one_k:
  136. skyboxType = "SKYBOX_V9";
  137. break;
  138. case two_K:
  139. skyboxType = "SKYBOX_V7";
  140. break;
  141. case four_K:
  142. skyboxType = "SKYBOX_V6";
  143. }
  144. dataJson.put("skybox_type", skyboxType);
  145. FileUtil.writeUtf8String(dataJson.toJSONString(), target + File.separator+"data.json");
  146. //调用算法切图
  147. CreateObjUtil.build3dModel(target , "1");
  148. String uploadJsonPath= target + File.separator + "results" +File.separator+"upload.json";
  149. Thread.sleep(2000);
  150. boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, 5, 200);
  151. if(!exist){
  152. throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
  153. }
  154. String uploadData = FileUtil.readUtf8String(uploadJsonPath);
  155. JSONObject uploadJson = null;
  156. JSONArray array = null;
  157. if(uploadData!=null) {
  158. uploadJson = JSONObject.parseObject(uploadData);
  159. array = uploadJson.getJSONArray("upload");
  160. }
  161. if(array == null){
  162. throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
  163. }
  164. Map<String, String> map = new HashMap<>();
  165. JSONObject fileJson = null;
  166. String fileName = "";
  167. for(int i = 0, len = array.size(); i < len; i++) {
  168. fileJson = array.getJSONObject(i);
  169. fileName = fileJson.getString("file");
  170. //文件不存在抛出异常
  171. if (!new File(target + File.separator + "results" + File.separator + fileName)
  172. .exists()) {
  173. throw new Exception(
  174. target + File.separator + "results" + File.separator + fileName + "文件不存在");
  175. }
  176. //high文件夹
  177. if (fileJson.getIntValue("clazz") == 3) {
  178. map.put(target + File.separator + "results" + File.separator + fileName,
  179. ossImagePath + "pan/high/" + fileName.replace("high/", ""));
  180. continue;
  181. }
  182. //low文件夹
  183. if (fileJson.getIntValue("clazz") == 4) {
  184. map.put(target + File.separator + "results" + File.separator + fileName,
  185. ossImagePath + "pan/low/" + fileName.replace("low/", ""));
  186. continue;
  187. }
  188. //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
  189. if (fileJson.getIntValue("clazz") == 5) {
  190. map.put(target + File.separator + "results" + File.separator + fileName,
  191. ossImagePath + fileName);
  192. continue;
  193. }
  194. //tiles文件夹,亚马逊瓦片图
  195. if (fileJson.getIntValue("clazz") == 7) {
  196. map.put(target + File.separator + "results" + File.separator + fileName,
  197. ossImagePath + fileName);
  198. continue;
  199. }
  200. }
  201. if(map.size()>0) {
  202. fYunFileService.uploadMulFiles(map);
  203. }
  204. }
  205. private void checkParams4createVirtualScene(CreateFicTitiousSceneParamVO param){
  206. SceneFrom sceneFrom = SceneFrom.get(param.getSceneFrom());
  207. if(Objects.isNull(sceneFrom)){
  208. throw new BusinessException(ErrorCode.PARAM_ERROR.code(), "sceneFrom错误");
  209. }
  210. Integer sceneSource = null;
  211. switch (sceneFrom){
  212. case SXZ:
  213. sceneSource = SceneSource.YJHZ.code();
  214. break;
  215. }
  216. if(Objects.isNull(sceneSource)){
  217. throw new BusinessException(ErrorCode.PARAM_ERROR.code(), "sceneFrom错误");
  218. }
  219. param.setSceneSource(sceneSource);
  220. }
  221. private void buildScene4CreateVirtualScene(CreateFicTitiousSceneParamVO param) throws Exception {
  222. String num = param.getNum();
  223. String objName = param.getObjName();
  224. String mtlName = param.getMtlName();
  225. String localImagePath = String.format(ConstantFilePath.SCENE_IMAGES_PATH_V4, num);
  226. String ossImagePath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  227. String ossObjPath = ossImagePath + objName;
  228. if(!fYunFileService.fileExist(ossObjPath)){
  229. throw new BusinessException(ErrorCode.FAILURE_CODE_4001, objName);
  230. }
  231. String ossMtlPath = ossImagePath + mtlName;
  232. if(!fYunFileService.fileExist(ossMtlPath)){
  233. throw new BusinessException(ErrorCode.FAILURE_CODE_4001, mtlName);
  234. }
  235. String ossTexturePath = ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1/";
  236. // if(CollUtil.isEmpty(fYunFileService.listRemoteFiles(ossTexturePath))){
  237. // throw new BusinessException(ErrorCode.FAILURE_CODE_4001, "贴图");
  238. // }
  239. String ossVisionTxtPath = ossImagePath + "vision.txt";
  240. if(!fYunFileService.fileExist(ossVisionTxtPath)){
  241. throw new BusinessException(ErrorCode.FAILURE_CODE_4001, "vision.txt");
  242. }
  243. FileUtil.del(localImagePath + "/result/");
  244. FileUtil.del(localImagePath + "extras/");
  245. fYunFileService.downloadFile(ossObjPath, localImagePath + "extras/" + "mesh.obj");
  246. fYunFileService.downloadFile(ossMtlPath, localImagePath + "extras/" + mtlName);
  247. fYunFileService.downloadFileByCommand(localImagePath + "extras/", ossTexturePath);
  248. fYunFileService.downloadFile(ossVisionTxtPath, localImagePath + "vision.txt");
  249. //创建data.json
  250. JSONObject dataJson = new JSONObject();
  251. dataJson.put("obj2txt", true);
  252. dataJson.put("split_type", "SPLIT_V6");
  253. dataJson.put("data_describe", "double spherical");
  254. dataJson.put("skybox_type", "SKYBOX_V5");
  255. FileUtil.writeUtf8String(dataJson.toJSONString(), localImagePath + "data.json");
  256. //调用objToTxt算法
  257. CreateObjUtil.build3dModel(localImagePath, "");
  258. Thread.sleep(2000);
  259. String uploadJsonPath = localImagePath + "results/upload.json";
  260. boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, 3, 3000);
  261. if(!exist){
  262. throw new BusinessException(ErrorCode.FAILURE_CODE_5042);
  263. }
  264. String uploadData = FileUtil.readUtf8String(uploadJsonPath);
  265. JSONObject uploadJson = null;
  266. JSONArray array = null;
  267. if(uploadData!=null) {
  268. uploadJson = JSONObject.parseObject(uploadData);
  269. array = uploadJson.getJSONArray("upload");
  270. }
  271. if(array == null){
  272. log.error("upload.json数据出错");
  273. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  274. }
  275. Map<String,String> map = new HashMap<String,String>();
  276. JSONObject fileJson = null;
  277. String fileName = "";
  278. for(int i = 0, len = array.size(); i < len; i++) {
  279. fileJson = array.getJSONObject(i);
  280. fileName = fileJson.getString("file");
  281. String filePath = localImagePath + "results/" + fileName;
  282. //文件不存在抛出异常
  283. if(!FileUtil.exist(filePath)){
  284. throw new BusinessException(ErrorCode.FAILURE_CODE_4002, filePath);
  285. }
  286. //tex文件夹
  287. if (fileJson.getIntValue("clazz") == 15) {
  288. map.put(filePath, ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
  289. continue;
  290. }
  291. }
  292. CreateObjUtil.convertTxtToDam(localImagePath + "results/" + "modeldata.txt", localImagePath + "results/" + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
  293. // CreateObjUtil.convertDamToLzma(imagesBuffer.toString() + File.separator + "results" +File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
  294. // CreateObjUtil.convertTxtToDam(imagesBuffer.toString() + File.separator + "results" +File.separator+"modeldata.txt", imagesBuffer.toString() + File.separator + "results" + File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
  295. // map.put(imagesBuffer.toString() + File.separator + "results" +File.separator+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam.lzma", "images/images"+param.getNum()+"/"+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam.lzma");
  296. map.put(localImagePath + "results/" + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam", ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
  297. FileUtil.del(localImagePath + "vision.modeldata");
  298. CreateObjUtil.convertTxtToVisionmodeldata(localImagePath + "vision.txt", localImagePath + "vision.modeldata");
  299. map.put(localImagePath + "vision.modeldata", ossImagePath + "vision.modeldata");
  300. fYunFileService.uploadMulFiles(map);
  301. }
  302. private String updateScene4CreateVirtualScene(CreateFicTitiousSceneParamVO param){
  303. ScenePlus scenePlus = this.getByNum(param.getNum());
  304. ScenePlusExt scenePlusExt = null;
  305. SceneEditInfo sceneEditInfo = null;
  306. SceneEditInfoExt sceneEditInfoExt = null;
  307. SceneEditControls sceneEditControls = null;
  308. if(Objects.nonNull(scenePlus)){
  309. scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  310. sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  311. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  312. sceneEditControls = sceneEditControlsService.getByEditInfoId(sceneEditInfo.getId());
  313. }else {
  314. scenePlus = new ScenePlus();
  315. scenePlusExt = new ScenePlusExt();
  316. sceneEditInfo = new SceneEditInfo();
  317. sceneEditInfoExt = new SceneEditInfoExt();
  318. sceneEditControls = new SceneEditControls();
  319. }
  320. scenePlus.setNum(param.getNum());
  321. scenePlus.setUserId(param.getUserId());
  322. scenePlus.setTitle("四维看看");
  323. scenePlus.setDescription("<p>四维看看 让空间讲故事</p>");
  324. scenePlus.setSceneStatus(SceneStatus.SUCCESS.code());
  325. scenePlus.setPayStatus(PayStatus.PAY.code());
  326. scenePlus.setSceneSource(param.getSceneSource());
  327. this.saveOrUpdate(scenePlus);
  328. scenePlus = this.getByNum(param.getNum());
  329. scenePlusExt.setPlusId(scenePlus.getId());
  330. scenePlusExt.setWebSite(mainUrl + "/" + sceneUrl + param.getNum());
  331. scenePlusExt.setBuildType("V3");
  332. scenePlusExt.setSceneResolution(param.getSceneResolution());
  333. scenePlusExt.setSceneFrom(param.getSceneFrom());
  334. scenePlusExt.setSceneKind(param.getSceneKind());
  335. scenePlusExt.setModelKind(ModelKind.DAM.code());
  336. scenePlusExtService.saveOrUpdate(scenePlusExt);
  337. scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  338. sceneEditInfo.setScenePlusId(scenePlus.getId());
  339. sceneEditInfo.setVersion(Objects.isNull(sceneEditInfo.getVersion()) ? 0 : sceneEditInfo.getVersion() + 1);
  340. sceneEditInfo.setImgVersion(Objects.isNull(sceneEditInfo.getImgVersion()) ? 0 : sceneEditInfo.getImgVersion() + 1);
  341. sceneEditInfo.setTitle(scenePlus.getTitle());
  342. sceneEditInfo.setDescription(scenePlus.getDescription());
  343. sceneEditInfoService.saveOrUpdate(sceneEditInfo);
  344. sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  345. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  346. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  347. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  348. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  349. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  350. sceneEditControlsService.saveOrUpdate(sceneEditControls);
  351. sceneEditControls = sceneEditControlsService.getByEditInfoId(sceneEditInfo.getId());
  352. SceneJsonBean sceneJson = new SceneJsonBean();
  353. BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
  354. BeanUtil.copyProperties(sceneEditInfo, sceneJson);
  355. SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
  356. sceneJson.setControls(sceneEditControlsVO);
  357. sceneJson.setNum(param.getNum());
  358. sceneJson.setCreateTime(scenePlus.getCreateTime());
  359. sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
  360. sceneJson.setVersion(sceneEditInfo.getVersion());
  361. sceneJson.setImgVersion(sceneEditInfo.getImgVersion());
  362. sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
  363. sceneJson.setSceneKind(scenePlusExt.getSceneKind());
  364. sceneJson.setModelKind(scenePlusExt.getModelKind());
  365. sceneJson.setPayStatus(scenePlus.getPayStatus());
  366. String sceneJsonStr = JSON.toJSONString(sceneJson);
  367. //上传sceneJson文件
  368. fYunFileService.uploadFile(sceneJsonStr.getBytes(), String.format(UploadFilePath.DATA_VIEW_PATH, param.getNum()) + "scene.json");
  369. //scenejson写入缓存
  370. redisUtil.set(String.format(RedisKey.SCENE_JSON, param.getNum()), sceneJsonStr);
  371. return scenePlusExt.getWebSite();
  372. }
  373. @Override
  374. public PageInfo<SceneVO> getScenesByUserId(Long userId, PageScenesParamVo param) {
  375. param.setUserId(userId);
  376. //查询协作场景列表
  377. List<String> cooperationNumList = sceneCooperationService.getNumByUserIds(Arrays.asList(userId));
  378. param.setCooperationNumList(cooperationNumList);
  379. if (!ObjectUtils.isEmpty(param.getCameraType())) {
  380. switch (param.getCameraType()){
  381. case "mega":
  382. param.setSceneSourceIn(Arrays.asList(SceneSource.JG.code(), SceneSource.SG.code()));
  383. break;
  384. case "kankan":
  385. param.setSceneSourceNotIn(Arrays.asList(SceneSource.JG.code(), SceneSource.SG.code()));
  386. break;
  387. }
  388. }
  389. Page<ScenePlus> scenePage = this.baseMapper.pageList(new Page<>(param.getPageNum(), param.getPageSize()), param);
  390. if(CollUtil.isEmpty(scenePage.getRecords())){
  391. return PageInfo.PageInfo(scenePage);
  392. }
  393. List<Long> plusIdList = new ArrayList<>();
  394. List<String> megaSceneNumList = new ArrayList<>();
  395. Set<Long> cameraIds = new HashSet<>();
  396. scenePage.getRecords().stream().forEach(plus -> {
  397. plusIdList.add(plus.getId());
  398. if(plus.getSceneSource() == SceneSource.JG.code()){
  399. megaSceneNumList.add(plus.getNum());
  400. }
  401. if(Objects.nonNull(plus.getCameraId())){
  402. cameraIds.add(plus.getCameraId());
  403. }
  404. });
  405. Map<Long, String> cameraMap = new HashMap<>();
  406. Map<Long, String> cameraTypeMap = new HashMap<>();
  407. if(CollUtil.isNotEmpty(cameraIds)){
  408. cameraMap = cameraService
  409. .list(new LambdaQueryWrapper<Camera>().in(Camera::getId, cameraIds))
  410. .stream().collect(Collectors.toMap(Camera::getId, Camera::getSnCode));
  411. List<CameraDetail> cameraDetails = cameraDetailService.listByCameraIds(cameraIds);
  412. if(CollUtil.isNotEmpty(cameraDetails)){
  413. cameraDetails.stream().forEach(detail->{
  414. int cameraType = detail.getType();
  415. CameraTypeEnum cameraTypeEnum = CameraTypeEnum.get(cameraType);
  416. cameraTypeMap.put(detail.getCameraId(), cameraTypeEnum.getCameraName());
  417. });
  418. }
  419. }
  420. List<ScenePlusExt> scenePlusExtList = scenePlusExtService.list(new LambdaQueryWrapper<ScenePlusExt>().in(ScenePlusExt::getPlusId, plusIdList));
  421. Map<Long, ScenePlusExt> plusExtMap = new HashMap<>();
  422. scenePlusExtList.stream().forEach(ext->plusExtMap.put(ext.getPlusId(), ext));
  423. List<SceneEntity> megaSceneList = null;
  424. Map<String, SceneEntity> megaSceneMap = new HashMap<>();
  425. if(CollUtil.isNotEmpty(megaSceneNumList)){
  426. megaSceneList = sceneService.list(new LambdaQueryWrapper<SceneEntity>().in(SceneEntity::getSceneCode, megaSceneNumList));
  427. if(CollUtil.isNotEmpty(megaSceneList)){
  428. megaSceneList.stream().forEach(scene -> megaSceneMap.put(scene.getSceneCode(), scene));
  429. }
  430. }
  431. Map<Long, String> finalCameraMap = cameraMap;
  432. List<SceneVO> sceneVos = scenePage.getRecords().stream().map(scenePlus -> {
  433. SceneVO vo = new SceneVO();
  434. vo.setSceneCode(scenePlus.getNum());
  435. vo.setSceneName(scenePlus.getTitle());
  436. vo.setCreateTime(DateUtil.date2String(scenePlus.getCreateTime(), null));
  437. ScenePlusExt plusExt = plusExtMap.get(scenePlus.getId());
  438. if(Objects.nonNull(plusExt)){
  439. vo.setShootCount(plusExt.getShootCount());
  440. }
  441. vo.setSnCode(finalCameraMap.get(scenePlus.getCameraId()));
  442. vo.setCameraType(cameraTypeMap.get(scenePlus.getCameraId()));
  443. if (scenePlus.getSceneSource() == 4) {
  444. SceneEntity scene = megaSceneMap.get(scenePlus.getNum());
  445. if (Objects.nonNull(scene) && StrUtil.isNotEmpty(scene.getTitle())) {
  446. vo.setSceneName(scene.getTitle());
  447. }
  448. }
  449. return vo;
  450. }).collect(Collectors.toList());
  451. return PageInfo.PageInfo(scenePage.getCurrent(), scenePage.getSize(), scenePage.getTotal(), sceneVos);
  452. }
  453. @Override
  454. public Object getPointInfo(String sceneCode) {
  455. // 获取vision.txt 文件内容返回
  456. String content = fYunFileService.getFileContent(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode).concat("vision.txt"));
  457. JSONObject jsonObject = JSONObject.parseObject(content);
  458. return jsonObject.get("sweepLocations");
  459. }
  460. @Override
  461. public List<String> getSceneObjFilePaths(String sceneCode) {
  462. List<String> objFiles = fYunFileService.listRemoteFiles(String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode).concat("mesh"))
  463. .stream().map(file -> fYunFileConfig.getHost() + file).collect(Collectors.toList());
  464. return objFiles;
  465. }
  466. @Override
  467. public List<String> getScenePanoramicImageFiles(String sceneCode) {
  468. // 根据vision.txt 获取全景图文件
  469. String content = fYunFileService.getFileContent(String.format(UploadFilePath.IMG_VIEW_PATH, sceneCode).concat("vision.txt"));
  470. JSONObject jsonObject = JSONObject.parseObject(content);
  471. return jsonObject.getJSONArray("sweepLocations").stream()
  472. .map(json -> String.format(fYunFileConfig.getHost()
  473. + UploadFilePath.scene_result_data_path, sceneCode).concat("caches/images/")
  474. + ((JSONObject) json).getString("uuid").concat(".jpg")).collect(Collectors.toList());
  475. }
  476. @Override
  477. public ResultData getSceneViewUserFile(String sceneCode, Long userId) {
  478. ScenePlus scenePlus = this.getByNumAndUserId(userId, sceneCode);
  479. if (Objects.isNull(scenePlus)) {
  480. scenePlus = sceneCooperationService.getCooperaSceneByUserIdAndNum(userId, sceneCode);
  481. if(Objects.isNull(scenePlus)){
  482. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  483. }
  484. }
  485. if(Objects.isNull(scenePlus.getCameraId())){
  486. throw new BusinessException(ErrorCode.FAILURE_CODE_7010);
  487. }
  488. CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
  489. Integer cameraType = cameraDetail.getType();
  490. if(laserCamTypeList.contains(cameraType)){
  491. throw new BusinessException(ErrorCode.FAILURE_CODE_4004);
  492. }
  493. String userOssPath = String.format(UploadFilePath.USER_VIEW_PATH, scenePlus.getNum());
  494. List<String> userFileList = fYunFileService.listRemoteFiles(userOssPath);
  495. if(CollUtil.isEmpty(userFileList)){
  496. throw new BusinessException(ErrorCode.FAILURE_CODE_5027);
  497. }
  498. String userDowbloadPath = String.format(ConstantFilePath.OPENAPI_DOWNLOAD_PATH, scenePlus.getNum());
  499. String userLocalPath = userDowbloadPath.concat("user");
  500. String zipName = scenePlus.getNum().concat("_user.zip");
  501. String usesZipPath = userDowbloadPath.concat(zipName);
  502. fYunFileService.downloadFileByCommand(userLocalPath, userOssPath);
  503. ZipUtil.zip(userLocalPath, usesZipPath);
  504. String usesZipOssPath = String.format("downloads/scene/%s/user/", scenePlus.getNum()).concat(zipName);
  505. fYunFileService.uploadFileByCommand(usesZipPath, usesZipOssPath);
  506. return ResultData.ok(fYunFileConfig.getHost().concat(usesZipOssPath));
  507. }
  508. @Override
  509. public ResultData getSceneVideo(String sceneCode, Long userId) {
  510. ScenePlus scenePlus = this.getByNumAndUserId(userId, sceneCode);
  511. if (Objects.isNull(scenePlus)) {
  512. scenePlus = sceneCooperationService.getCooperaSceneByUserIdAndNum(userId, sceneCode);
  513. if(Objects.isNull(scenePlus)){
  514. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  515. }
  516. }
  517. if(Objects.isNull(scenePlus.getCameraId())){
  518. throw new BusinessException(ErrorCode.FAILURE_CODE_7010);
  519. }
  520. CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
  521. Integer cameraType = cameraDetail.getType();
  522. if(laserCamTypeList.contains(cameraType)){
  523. throw new BusinessException(ErrorCode.FAILURE_CODE_4004);
  524. }
  525. String userOssPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, scenePlus.getNum());
  526. List<String> userFileList = fYunFileService.listRemoteFiles(userOssPath);
  527. if(CollUtil.isEmpty(userFileList)){
  528. throw new BusinessException(ErrorCode.FAILURE_CODE_5027);
  529. }
  530. String userDowbloadPath = String.format(ConstantFilePath.OPENAPI_DOWNLOAD_PATH, scenePlus.getNum());
  531. String userLocalPath = userDowbloadPath.concat("video/");
  532. String zipName = scenePlus.getNum().concat("_video.zip");
  533. String usesZipPath = userDowbloadPath.concat(zipName);
  534. fYunFileService.downloadFileByCommand(userLocalPath, userOssPath);
  535. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode);
  536. if(fYunFileService.fileExist(dataViewPath.concat("Up.xml"))){
  537. fYunFileService.downloadFile(dataViewPath.concat("Up.xml"), userLocalPath.concat("Up.xml"));
  538. }
  539. if(fYunFileService.fileExist(dataViewPath.concat("Up2.xml"))){
  540. fYunFileService.downloadFile(dataViewPath.concat("Up2.xml"), userLocalPath.concat("Up2.xml"));
  541. }
  542. if(fYunFileService.fileExist(dataViewPath.concat("Up.txt"))){
  543. fYunFileService.downloadFile(dataViewPath.concat("Up.txt"), userLocalPath.concat("Up.txt"));
  544. }
  545. if(fYunFileService.fileExist(dataViewPath.concat("Up2.txt"))){
  546. fYunFileService.downloadFile(dataViewPath.concat("Up2.txt"), userLocalPath.concat("Up2.txt"));
  547. }
  548. String sceneJson = redisUtil.get(String.format(RedisKey.SCENE_JSON, sceneCode));
  549. if(StrUtil.isEmpty(sceneJson)){
  550. sceneJson = fYunFileService.getFileContent(dataViewPath.concat("scene.json"));
  551. }
  552. SceneJsonBean sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
  553. if(StrUtil.isEmpty(sceneJsonBean.getVideos())){
  554. sceneJsonBean.setVideos("{}");
  555. }
  556. FileUtil.writeUtf8String(sceneJsonBean.getVideos(), userLocalPath.concat("mapping.json"));
  557. ZipUtil.zip(userLocalPath, usesZipPath);
  558. String usesZipOssPath = String.format("downloads/scene/%s/video/", scenePlus.getNum()).concat(zipName);
  559. fYunFileService.uploadFileByCommand(usesZipPath, usesZipOssPath);
  560. FileUtil.del(userLocalPath);
  561. FileUtil.del(usesZipPath);
  562. return ResultData.ok(fYunFileConfig.getHost().concat(usesZipOssPath));
  563. }
  564. }