SceneEditInfoServiceImpl.java 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.net.multipart.UploadFile;
  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.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  11. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  12. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  14. import com.dtflys.forest.exceptions.ForestRuntimeException;
  15. import com.dtflys.forest.http.ForestRequest;
  16. import com.dtflys.forest.http.ForestResponse;
  17. import com.fdkankan.common.constant.*;
  18. import com.fdkankan.common.exception.BusinessException;
  19. import com.fdkankan.common.response.Result;
  20. import com.fdkankan.common.response.ResultData;
  21. import com.fdkankan.common.util.ComputerUtil;
  22. import com.fdkankan.common.util.CreateObjUtil;
  23. import com.fdkankan.common.util.FileMd5Util;
  24. import com.fdkankan.common.util.FileUtil;
  25. import com.fdkankan.common.util.FileUtils;
  26. import com.fdkankan.common.util.SceneUtil;
  27. import com.fdkankan.fyun.constant.StorageType;
  28. import com.fdkankan.fyun.oss.UploadToOssUtil;
  29. import com.fdkankan.platform.api.feign.PlatformGoodsClient;
  30. import com.fdkankan.platform.api.feign.PlatformUserClient;
  31. import com.fdkankan.platform.api.dto.CameraDetail;
  32. import com.fdkankan.platform.api.dto.Company;
  33. import com.fdkankan.redis.constant.RedisKey;
  34. import com.fdkankan.redis.constant.RedisLockKey;
  35. import com.fdkankan.redis.util.RedisLockUtil;
  36. import com.fdkankan.redis.util.RedisUtil;
  37. import com.fdkankan.scene.api.dto.SceneInfoDTO;
  38. import com.fdkankan.scene.bean.BoxPhotoBean;
  39. import com.fdkankan.scene.bean.SceneJsonBean;
  40. import com.fdkankan.scene.bean.TagBean;
  41. import com.fdkankan.scene.callback.FdkkMiniReqErrorCallback;
  42. import com.fdkankan.scene.callback.FdkkMiniReqSuccessCallback;
  43. import com.fdkankan.scene.entity.SceneDataDownload;
  44. import com.fdkankan.scene.entity.SceneEditControls;
  45. import com.fdkankan.scene.entity.SceneEditInfo;
  46. import com.fdkankan.scene.entity.SceneEditInfoExt;
  47. import com.fdkankan.scene.entity.ScenePlus;
  48. import com.fdkankan.scene.entity.ScenePlusExt;
  49. import com.fdkankan.scene.entity.ScenePro;
  50. import com.fdkankan.scene.factory.FloorLogoHandlerFactory;
  51. import com.fdkankan.scene.factory.MusicHandlerFactory;
  52. import com.fdkankan.scene.factory.ScreenshotHandlerFactory;
  53. import com.fdkankan.scene.httpclient.FdkankanMiniClient;
  54. import com.fdkankan.scene.mapper.ISceneEditInfoMapper;
  55. import com.fdkankan.scene.service.ISceneDataDownloadService;
  56. import com.fdkankan.scene.service.ISceneEditControlsService;
  57. import com.fdkankan.scene.service.ISceneEditInfoExtService;
  58. import com.fdkankan.scene.service.ISceneEditInfoService;
  59. import com.fdkankan.scene.service.IScenePlusExtService;
  60. import com.fdkankan.scene.service.IScenePlusService;
  61. import com.fdkankan.scene.service.ISceneProExtService;
  62. import com.fdkankan.scene.service.ISceneProService;
  63. import com.fdkankan.scene.service.ISceneUploadService;
  64. import com.fdkankan.scene.vo.*;
  65. import com.google.common.collect.Lists;
  66. import com.google.errorprone.annotations.Var;
  67. import java.io.File;
  68. import java.nio.charset.Charset;
  69. import java.util.ArrayList;
  70. import java.util.Arrays;
  71. import java.util.Comparator;
  72. import java.util.Date;
  73. import java.util.HashMap;
  74. import java.util.HashSet;
  75. import java.util.List;
  76. import java.util.Map;
  77. import java.util.Map.Entry;
  78. import java.util.Set;
  79. import java.util.UUID;
  80. import java.util.stream.Collectors;
  81. import lombok.extern.slf4j.Slf4j;
  82. import org.springframework.beans.factory.annotation.Autowired;
  83. import org.springframework.beans.factory.annotation.Value;
  84. import org.springframework.cloud.context.config.annotation.RefreshScope;
  85. import org.springframework.stereotype.Service;
  86. import java.io.IOException;
  87. import java.util.Calendar;
  88. import java.util.Objects;
  89. import org.springframework.transaction.annotation.Transactional;
  90. import org.springframework.web.multipart.MultipartFile;
  91. /**
  92. * <p>
  93. * 服务实现类
  94. * </p>
  95. *
  96. * @author
  97. * @since 2022-01-18
  98. */
  99. @Slf4j
  100. @RefreshScope
  101. @Service
  102. public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper, SceneEditInfo> implements ISceneEditInfoService {
  103. @Value("${oss.prefix.ali}")
  104. private String prefixAli;
  105. @Value("${oss.prefix.url}")
  106. private String ossUrlPrefix;
  107. @Value("${upload.type}")
  108. private String type;
  109. @Value("${oss.bucket:4dkankan}")
  110. private String bucket;
  111. @Value("${main.url}")
  112. private String mainUrl;
  113. @Value("${ecs.checkFile.maxTimes:5}")
  114. private int maxCheckTimes;
  115. @Value("${ecs.checkFile.waitTime:5000}")
  116. private int waitTime;
  117. @Value("${http.host.4dkankanMini}")
  118. private String fkankanMiniHost;
  119. @Autowired
  120. private ISceneEditControlsService sceneEditControlsService;
  121. @Autowired
  122. private ISceneProService sceneProService;
  123. @Autowired
  124. private UploadToOssUtil uploadToOssUtil;
  125. @Autowired
  126. RedisUtil redisUtil;
  127. @Autowired
  128. private ISceneProExtService sceneProExtService;
  129. @Autowired
  130. private RedisLockUtil redisLockUtil;
  131. @Autowired
  132. ISceneDataDownloadService sceneDataDownloadService;
  133. @Autowired
  134. PlatformGoodsClient platformGoodsClient;
  135. @Autowired
  136. PlatformUserClient platformUserClient;
  137. @Autowired
  138. private ISceneEditInfoExtService sceneEditInfoExtService;
  139. @Autowired
  140. IScenePlusService scenePlusService;
  141. @Autowired
  142. IScenePlusExtService scenePlusExtService;
  143. @Autowired
  144. private FdkankanMiniClient fdkankanMiniClient;
  145. @Autowired
  146. private ISceneUploadService sceneUploadService;
  147. @Transactional
  148. @Override
  149. public SceneEditInfoVO saveScene(SceneEditInfoParamVO param) {
  150. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  151. // ScenePro scenePro = sceneProService.findBySceneNum(param.getNum());
  152. if(Objects.isNull(scenePlus)){
  153. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  154. }
  155. SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId());
  156. SceneEditControls sceneEditControlsDb = null;
  157. if(Objects.nonNull(sceneEditInfoDb)){
  158. sceneEditControlsDb = sceneEditControlsService.getBySceneEditId(sceneEditInfoDb.getId());
  159. }
  160. SceneEditInfo sceneEditInfo = BeanUtil.copyProperties(param, SceneEditInfo.class);
  161. sceneEditInfo.setScenePlusId(scenePlus.getId());
  162. if(Objects.isNull(sceneEditInfoDb)){
  163. this.save(sceneEditInfo);
  164. }else{
  165. sceneEditInfo.setId(sceneEditInfoDb.getId());
  166. sceneEditInfo.setVersion(sceneEditInfoDb.getVersion() + 1);
  167. this.updateById(sceneEditInfo);
  168. }
  169. if(Objects.nonNull(param.getControls())){
  170. SceneEditControls sceneEditControls = BeanUtil.copyProperties(param.getControls(), SceneEditControls.class);
  171. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  172. if(Objects.isNull(sceneEditControlsDb)){
  173. sceneEditControlsService.save(sceneEditControls);
  174. }else{
  175. sceneEditControls.setId(sceneEditControlsDb.getId());
  176. sceneEditControlsService.updateById(sceneEditControls);
  177. }
  178. }
  179. SceneEditInfoVO result = BeanUtil.copyProperties(param, SceneEditInfoVO.class);
  180. result.setCreateTime(sceneEditInfo.getCreateTime());
  181. return result;
  182. }
  183. @Override
  184. public SceneEditInfo getBySceneProId(long sceneProId) {
  185. return this.getOne(new LambdaQueryWrapper<SceneEditInfo>()
  186. .eq(SceneEditInfo::getSceneProId, sceneProId));
  187. }
  188. @Override
  189. public SceneEditInfo getByScenePlusId(long scenePlusId) {
  190. return this.getOne(new LambdaQueryWrapper<SceneEditInfo>()
  191. .eq(SceneEditInfo::getScenePlusId, scenePlusId));
  192. }
  193. @Transactional
  194. @Override
  195. public ResultData publicScene(SceneEditInfoParamVO param) throws Exception{
  196. String num = param.getNum();
  197. //根据场景码查询数据库
  198. ScenePro scenePro = sceneProService.findBySceneNum(num);
  199. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  200. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  201. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  202. SceneEditInfoExt sceneEditInfoExt = null;
  203. SceneEditControls sceneEditControls = null;
  204. if(sceneEditInfo == null){
  205. sceneEditInfo = new SceneEditInfo();
  206. sceneEditInfo.setSceneProId(scenePlus.getId());
  207. }else{
  208. sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  209. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  210. }
  211. if(sceneEditInfoExt == null){
  212. sceneEditInfoExt = new SceneEditInfoExt();
  213. sceneEditInfoExt.setFloorPlanAngle(0f);
  214. sceneEditInfoExt.setFloorPlanCompass(0f);
  215. }
  216. // if(sceneEditControls == null){
  217. // sceneEditControls = new SceneEditControls();
  218. // }
  219. //生成sceneJson
  220. SceneJsonBean sceneJson = new SceneJsonBean();
  221. BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
  222. BeanUtil.copyProperties(sceneEditInfo, sceneJson);
  223. SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
  224. sceneJson.setControls(sceneEditControlsVO);
  225. sceneJson.setNum(num);
  226. // if(StrUtil.isNotEmpty(sceneEditInfo.getFloorPlanPath())){
  227. // sceneJson.setFloorPlanPaths(sceneEditInfo.getFloorPlanPath().split(","));
  228. // }
  229. sceneJson.setCreateTime(scenePlus.getCreateTime());
  230. sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
  231. sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
  232. if(StrUtil.isNotEmpty(scenePlusExt.getVideos())){
  233. sceneJson.setVideos(scenePlusExt.getVideos());
  234. }
  235. //处理热点数据,生成hot.json
  236. this.publicHotData(num, sceneEditInfo);
  237. // TODO: 2022/3/2 这里的逻辑放在上传球幕视频接口中做了,这里先暂时注释掉,以后要删除
  238. //处理球幕视频
  239. // this.buildVideo(sceneEditInfo, sceneProExt.getDataSource(), sceneNum);
  240. //本地写sceneJson文件
  241. String localSceneJsonPath = String.format(ConstantFilePath.SCENE_DATA_PATH_V4, num) + "scene.json";
  242. FileUtils.writeFile(localSceneJsonPath, JSON.toJSONString(sceneJson));
  243. //上传sceneJson文件
  244. String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", num);
  245. uploadToOssUtil.upload(JSON.toJSONBytes(sceneJson), sceneJsonPath);
  246. //sceneJson放入缓存
  247. String key = String.format(RedisKey.SCENE_JSON, num);
  248. redisUtil.set(key, JSON.toJSONString(sceneJson));
  249. //删除发布数据中的user目录
  250. String publicUserPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
  251. uploadToOssUtil.deleteFile(publicUserPath);
  252. // String editUserPath = String.format(UploadFilePath.USER_EDIT_PATH, sceneNum);
  253. //复制编辑目录到发布目录
  254. String editPath = String.format(UploadFilePath.USER_EDIT_PATH, param.getNum());
  255. String viewPath = String.format(UploadFilePath.USER_VIEW_PATH, param.getNum());
  256. uploadToOssUtil.copyFiles(editPath,viewPath);
  257. //入库
  258. if(sceneEditInfo.getId() == null){
  259. this.save(sceneEditInfo);
  260. }else{
  261. this.updateById(sceneEditInfo);
  262. }
  263. sceneEditInfoExt.setSceneProId(scenePro.getId());
  264. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  265. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  266. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  267. // sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  268. // if(sceneEditControls.getId() == null){
  269. // sceneEditControlsService.save(sceneEditControls);
  270. // }else{
  271. // sceneEditControlsService.updateById(sceneEditControls);
  272. // }
  273. return ResultData.ok();
  274. }
  275. private void buildVideo(SceneEditInfo sceneEditInfo, String path, String num) throws Exception{
  276. if(CommonStatus.NO.equals(sceneEditInfo.getBuildVideoStatus())){
  277. return;
  278. }
  279. if(path != null && !"".equals(path) && path.startsWith("http")){
  280. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  281. }
  282. String target = path + "_images";
  283. log.info("球幕视频路径:{}", target + File.separator + "extras/video");
  284. File video = new File(target + File.separator + "extras/video");
  285. //如果文件夹或者文件不存在,跳出
  286. if(!video.exists() || video.listFiles() == null || video.listFiles().length == 0){
  287. return;
  288. }
  289. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  290. for(String videoName : video.list()){
  291. log.info("球幕视频名称:{}", videoName);
  292. uploadToOssUtil.upload(target + File.separator + "extras/video/" + videoName,userEditPath + videoName);
  293. CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
  294. target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
  295. uploadToOssUtil.upload(target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),userEditPath + videoName.replace("mp4", "flv"));
  296. //覆盖原始视频资源
  297. FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
  298. path + File.separator + "caches/videos/" + videoName, true);
  299. }
  300. FileUtils.deleteDirectory(target + File.separator + "extras/video/");
  301. //重置状态
  302. sceneEditInfo.setBuildVideoStatus(CommonStatus.NO.code());
  303. }
  304. private void publicHotData(String sceneNum, SceneEditInfo sceneEditInfo) throws IOException {
  305. String hotDataKey = String.format(RedisKey.SCENE_HOT_DATA, sceneNum);
  306. Map<String, String> hotMap = redisUtil.hmget(hotDataKey);
  307. List<String> hotList = Lists.newArrayList();
  308. hotMap.entrySet().stream().forEach(entry->{
  309. if(StrUtil.isNotEmpty(entry.getValue())){
  310. hotList.add(entry.getValue());
  311. }
  312. });
  313. if(CollUtil.isNotEmpty(hotList)){
  314. JSONArray jsonhots = new JSONArray();
  315. hotList.stream().forEach(hot->{
  316. jsonhots.add(JSONObject.parseObject(hot));
  317. });
  318. String hotJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, sceneNum) + "hot.json";
  319. uploadToOssUtil.upload(jsonhots.toString().getBytes(), hotJsonPath);
  320. //修改tags状态为是,标识有热点数据
  321. this.saveTagsToSceneEditInfo(sceneNum, sceneEditInfo);
  322. }
  323. }
  324. @Override
  325. public SceneInfoVO getSceneInfo(@Var SceneInfoParamVO param) throws Exception{
  326. SceneInfoReqType sceneInfoReqType = SceneInfoReqType.get(param.getReqType());
  327. switch (sceneInfoReqType){
  328. //如果是编辑页面请求,查数据库
  329. case EDIT:
  330. return this.getSceneInfo4Edit(param.getNum());
  331. //如果是查看页面请求,查redis
  332. case VIEW:
  333. return this.getSceneInfo4View(param.getNum());
  334. }
  335. return null;
  336. }
  337. @Override
  338. public SceneInfoDTO getSceneInfo4Download(SceneInfoParamVO param) throws Exception{
  339. SceneInfoVO sceneInfo4View = this.getSceneInfo4View(param.getNum());
  340. if(Objects.isNull(sceneInfo4View)){
  341. return null;
  342. }
  343. SceneInfoDTO sceneInfoDTO = BeanUtil.copyProperties(sceneInfo4View, SceneInfoDTO.class);
  344. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  345. sceneInfoDTO.setSceneSource(scenePlus.getSceneSource());
  346. return sceneInfoDTO;
  347. }
  348. /**
  349. * <p>
  350. 编辑页面获取场景详情信息
  351. * </p>
  352. * @author dengsixing
  353. * @date 2022/1/21
  354. * @param num
  355. * @return com.fdkankan.scene.vo.SceneInfoVO
  356. **/
  357. private SceneInfoVO getSceneInfo4Edit(String num) throws Exception{
  358. // ScenePro scenePro = sceneProService.findBySceneNum(num);
  359. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  360. if(Objects.isNull(scenePlus)){
  361. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  362. }
  363. // SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  364. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  365. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  366. if(Objects.isNull(sceneEditInfo)){
  367. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  368. }
  369. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  370. SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  371. SceneInfoVO sceneInfoVO = new SceneInfoVO();
  372. BeanUtil.copyProperties(sceneEditInfoExt, sceneInfoVO);
  373. BeanUtil.copyProperties(sceneEditInfo, sceneInfoVO);
  374. if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){
  375. sceneInfoVO.setFloorPlanAngle(0f);
  376. }
  377. if(Objects.isNull(sceneInfoVO.getFloorPlanCompass())){
  378. sceneInfoVO.setFloorPlanCompass(0f);
  379. }
  380. sceneInfoVO.setControls(BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class));
  381. sceneInfoVO.setNum(num);
  382. //生成sceneJson
  383. // if(StrUtil.isNotEmpty(sceneEditInfo.getFloorPlanPath())){
  384. // sceneInfoVO.setFloorPlanPaths(sceneEditInfo.getFloorPlanPath().split(","));
  385. // }
  386. sceneInfoVO.setCreateTime(scenePlus.getCreateTime());
  387. sceneInfoVO.setSceneResolution(scenePlusExt.getSceneResolution());
  388. sceneInfoVO.setSceneFrom(scenePlusExt.getSceneFrom());
  389. sceneInfoVO.setVideos(scenePlusExt.getVideos());
  390. // TODO: 2022/4/24 v3版本停机要切换---------------------------start
  391. // this.setExtData(sceneInfoVO, scenePlus.getCameraId());
  392. this.setExtDataFromV3(sceneInfoVO, scenePlus.getCameraId());
  393. // TODO: 2022/4/24 v3版本停机要切换---------------------------end
  394. return sceneInfoVO;
  395. }
  396. /**
  397. * <p>
  398. getInfo接口返回字段扩展
  399. * </p>
  400. * @author dengsixing
  401. * @date 2022/3/9
  402. **/
  403. private void setExtDataFromV3(SceneInfoVO sceneInfoVO, Long cameraId) throws Exception{
  404. if(Objects.isNull(cameraId)){
  405. return;
  406. }
  407. String url = fkankanMiniHost + "/api/user/camera/getDataSyncByCameraId?cameraId=" + cameraId;
  408. Result<String> dataSyncResult = fdkankanMiniClient
  409. .getDataSyncType(url, new FdkkMiniReqSuccessCallback(), new FdkkMiniReqErrorCallback());
  410. if(!"[]".equals(dataSyncResult.getData())){
  411. sceneInfoVO.setDataSync(dataSyncResult.getData());
  412. }
  413. }
  414. /**
  415. * <p>
  416. getInfo接口返回字段扩展
  417. * </p>
  418. * @author dengsixing
  419. * @date 2022/3/9
  420. **/
  421. private void setExtData(SceneInfoVO sceneInfoVO, Long cameraId) throws Exception{
  422. ResultData<CameraDetail> cameraResultData = platformGoodsClient.getCameraDetailByCameraId(cameraId);
  423. if(!cameraResultData.getSuccess()){
  424. throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
  425. }
  426. CameraDetail camera = cameraResultData.getData();
  427. if(Objects.isNull(camera)){
  428. throw new BusinessException(ErrorCode.FAILURE_CODE_7010);
  429. }
  430. if(Objects.isNull(camera.getCompanyId())){
  431. return;
  432. }
  433. ResultData<Company> companyResultData = platformUserClient.getCompanyById(camera.getCompanyId());
  434. if(!companyResultData.getSuccess()){
  435. throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
  436. }
  437. Company company = companyResultData.getData();
  438. if(Objects.isNull(company)){
  439. return;
  440. }
  441. sceneInfoVO.setDataSync(company.getDataSync());
  442. }
  443. /**
  444. * <p>
  445. 查看页面获取场景详情信息
  446. * </p>
  447. * @author dengsixing
  448. * @date 2022/1/21
  449. * @param num
  450. * @return com.fdkankan.scene.vo.SceneInfoVO
  451. **/
  452. private SceneInfoVO getSceneInfo4View(String num) throws Exception{
  453. // ScenePro scenePro = sceneProService.findBySceneNum(num);
  454. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  455. String key = String.format(RedisKey.SCENE_JSON, num);
  456. String sceneJson = redisUtil.get(key);
  457. SceneInfoVO sceneInfoVO = null;
  458. //先查询redis
  459. if(StrUtil.isNotEmpty(sceneJson)) {
  460. sceneInfoVO = JSON.parseObject(sceneJson, SceneInfoVO.class);
  461. // TODO: 2022/4/24 v3版本停机要切换---------------------------start
  462. // this.setExtData(sceneInfoVO, scenePlus.getCameraId());
  463. this.setExtDataFromV3(sceneInfoVO, scenePlus.getCameraId());
  464. // TODO: 2022/4/24 v3版本停机要切换---------------------------end
  465. sceneInfoVO.setScenePassword(null);
  466. if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){
  467. sceneInfoVO.setFloorPlanAngle(0f);
  468. }
  469. if(Objects.isNull(sceneInfoVO.getFloorPlanCompass())){
  470. sceneInfoVO.setFloorPlanCompass(0f);
  471. }
  472. return sceneInfoVO;
  473. }
  474. //如果redis没找到,从scene.json中获取
  475. String objectName = String.format(ConstantFilePath.SCENE_VIEW_DATA_DATA_SCENEJSON, num);
  476. String objectContent = uploadToOssUtil.getObjectContent(bucket, objectName);
  477. if(StrUtil.isEmpty(objectContent))
  478. return null;
  479. sceneInfoVO = JSON.parseObject(objectContent, SceneInfoVO.class);
  480. // TODO: 2022/4/24 v3版本停机要切换---------------------------start
  481. // this.setExtData(sceneInfoVO, scenePlus.getCameraId());
  482. this.setExtDataFromV3(sceneInfoVO, scenePlus.getCameraId());
  483. // TODO: 2022/4/24 v3版本停机要切换---------------------------end
  484. sceneInfoVO.setScenePassword(null);
  485. if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){
  486. sceneInfoVO.setFloorPlanAngle(0f);
  487. }
  488. if(Objects.isNull(sceneInfoVO.getFloorPlanCompass())){
  489. sceneInfoVO.setFloorPlanCompass(0f);
  490. }
  491. redisUtil.set(key, JSON.toJSONString(sceneInfoVO));
  492. return sceneInfoVO;
  493. }
  494. @Override
  495. // @Transactional
  496. public ResultData saveUpload(SaveUploadParamVO param) throws Exception {
  497. FileBizType fileBizType = FileBizType.get(param.getBizType());
  498. String num = param.getNum();
  499. String fileInfo = param.getFileInfo();
  500. if(Objects.isNull(fileBizType)){
  501. throw new BusinessException(ErrorCode.FAILURE_CODE_7003);
  502. }
  503. switch (fileBizType){
  504. case MUSIC:
  505. return new MusicHandlerFactory().getHandler().save(num, fileInfo);
  506. case FLOOR_LOGO:
  507. return new FloorLogoHandlerFactory().getHandler().save(num, fileInfo);
  508. // case FLOOR_PLAN:
  509. // return new FloorPlanHandlerFactory().getHandler().save(num, fileInfo);
  510. case SCREENSHOT:
  511. return new ScreenshotHandlerFactory().getHandler().save(num, fileInfo);
  512. }
  513. return ResultData.ok();
  514. }
  515. @Override
  516. public ResultData saveCad(BaseDataParamVO param) throws Exception {
  517. String num = param.getNum();
  518. // ScenePro scenePro = sceneProService.findBySceneNum(num);
  519. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  520. if(Objects.isNull(scenePlus))
  521. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  522. String editUserPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  523. String localDataPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  524. JSONObject fileInfoJson = JSON.parseObject(param.getData());
  525. Float angel = null;
  526. Float compass = null;
  527. String floorJsonData = fileInfoJson.getString("floorJsonData");
  528. if(StrUtil.isNotBlank(floorJsonData)){
  529. JSONObject jsonObject = JSON.parseObject(floorJsonData);
  530. angel = jsonObject.getFloat("angle");
  531. compass = jsonObject.getFloat("compass");
  532. }
  533. //处理户型图数据
  534. //上传floorplan_user.json文件
  535. FileUtils.writeFile(localDataPath + "floorplan_user.json", floorJsonData);
  536. uploadToOssUtil.upload(localDataPath + "floorplan_user.json", editUserPath + "floorplan_user.json");
  537. //写入数据库
  538. Byte floorPlanUser = null;
  539. if(StrUtil.isNotEmpty(floorJsonData)){
  540. floorPlanUser = CommonStatus.YES.code();
  541. }
  542. SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId());
  543. if(Objects.nonNull(sceneEditInfoDb)){
  544. LambdaUpdateWrapper<SceneEditInfo> updateWrapper = new LambdaUpdateWrapper<SceneEditInfo>()
  545. .setSql("version=version+" + 1)
  546. .eq(SceneEditInfo::getId, sceneEditInfoDb.getId());
  547. if(floorPlanUser != null){
  548. updateWrapper.set(SceneEditInfo::getFloorPlanUser, floorPlanUser);
  549. }
  550. this.update(updateWrapper);
  551. }else{
  552. sceneEditInfoDb = new SceneEditInfo();
  553. sceneEditInfoDb.setScenePlusId(scenePlus.getId());
  554. sceneEditInfoDb.setFloorPlanUser(floorPlanUser);
  555. this.save(sceneEditInfoDb);
  556. }
  557. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoDb.getId());
  558. if(Objects.isNull(sceneEditInfoExt)){
  559. sceneEditInfoExt = new SceneEditInfoExt();
  560. sceneEditInfoExt.setEditInfoId(sceneEditInfoDb.getId());
  561. }
  562. if(Objects.nonNull(angel)){
  563. sceneEditInfoExt.setFloorPlanAngle(angel);
  564. }
  565. if(Objects.nonNull(compass)){
  566. sceneEditInfoExt.setFloorPlanCompass(compass);
  567. }
  568. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  569. return ResultData.ok();
  570. }
  571. @Override
  572. public ResultData resetCad(String num){
  573. ScenePro scenePro = sceneProService.findBySceneNum(num);
  574. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  575. if(Objects.isNull(scenePlus))
  576. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  577. SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId());
  578. SceneEditInfoExt sceneEditInfoExt = null;
  579. if(Objects.nonNull(sceneEditInfoDb)){
  580. LambdaUpdateWrapper<SceneEditInfo> updateWrapper = new LambdaUpdateWrapper<SceneEditInfo>()
  581. .setSql("version=version+" + 1)
  582. .set(SceneEditInfo::getFloorPlanUser, CommonStatus.NO.code())
  583. .eq(SceneEditInfo::getId, sceneEditInfoDb.getId());
  584. this.update(updateWrapper);
  585. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoDb.getId());
  586. }else{
  587. sceneEditInfoDb = new SceneEditInfo();
  588. sceneEditInfoDb.setSceneProId(scenePro.getId());
  589. sceneEditInfoDb.setScenePlusId(scenePlus.getId());
  590. sceneEditInfoDb.setFloorPlanUser(CommonStatus.NO.code());
  591. this.save(sceneEditInfoDb);
  592. }
  593. if(Objects.isNull(sceneEditInfoExt)){
  594. sceneEditInfoExt = new SceneEditInfoExt();
  595. sceneEditInfoExt.setSceneProId(scenePro.getId());
  596. sceneEditInfoDb.setScenePlusId(scenePlus.getId());
  597. sceneEditInfoExt.setEditInfoId(sceneEditInfoDb.getId());
  598. }
  599. sceneEditInfoExt.setFloorPlanAngle(0f);
  600. sceneEditInfoExt.setFloorPlanCompass(0f);
  601. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  602. return ResultData.ok();
  603. }
  604. @Override
  605. public ResultData renameCad(RenameCadParamVO param) throws IOException {
  606. String key = String.format(UploadFilePath.DATA_VIEW_PATH, param.getNum()) + "floorplan_cad.json";
  607. String floorplanCadJson = uploadToOssUtil.getObjectContent(this.bucket, key);
  608. if(StrUtil.isEmpty(floorplanCadJson)){
  609. return ResultData.ok();
  610. }
  611. Map<Integer, String> renameMap = new HashMap<>();
  612. param.getFloors().stream().forEach(floor->{
  613. renameMap.put(floor.getSubgroup(), floor.getName());
  614. });
  615. JSONObject jsonObject = JSON.parseObject(floorplanCadJson);
  616. if(Objects.isNull(jsonObject)){
  617. return ResultData.ok();
  618. }
  619. JSONArray floorArr = jsonObject.getJSONArray("floors");
  620. if(CollUtil.isEmpty(floorArr)){
  621. return ResultData.ok();
  622. }
  623. for (Object o : floorArr) {
  624. JSONObject item = (JSONObject)o;
  625. int subgroup = item.getIntValue("subgroup");
  626. String name = renameMap.get(subgroup);
  627. if(StrUtil.isEmpty(name)){
  628. continue;
  629. }
  630. item.put("name", name);
  631. }
  632. uploadToOssUtil.upload(jsonObject.toJSONString().getBytes(), key);
  633. return ResultData.ok();
  634. }
  635. private JSONObject updateFloorName(String sourceFloors, String targeFloors){
  636. JSONArray sourceFloorsJson = JSON.parseArray(sourceFloors);
  637. JSONObject targeFloorsJson = JSONObject.parseObject(targeFloors);
  638. JSONArray array = targeFloorsJson.getJSONArray("floors");
  639. for (int i = 0; i < array.size(); ++i) {
  640. JSONObject targetFloor = array.getJSONObject(i);
  641. int targetId = targetFloor.getIntValue("id");
  642. for (int j = 0; j < sourceFloorsJson.size(); ++j) {
  643. JSONObject floor = sourceFloorsJson.getJSONObject(j);
  644. int id = floor.getIntValue("id");
  645. String name = floor.getString("name");
  646. if (targetId != id)
  647. continue;
  648. targetFloor.put("name", name);
  649. }
  650. }
  651. return targeFloorsJson;
  652. }
  653. @Override
  654. public void upgradeVersionById(Long id) {
  655. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  656. .setSql("version=version+" + 1)
  657. .eq(SceneEditInfo::getId, id));
  658. }
  659. @Override
  660. public ResultData uploadPanorama(String num, MultipartFile file) throws Exception {
  661. //校验压缩包格式
  662. // log.info("全景图压缩包文件名:" + file.getOriginalFilename());
  663. // if(!file.getOriginalFilename().endsWith(".zip")){
  664. // throw new BusinessException(ErrorCode.FAILURE_CODE_7015);
  665. // }
  666. if(!file.getOriginalFilename().endsWith(".zip") && !file.getOriginalFilename().endsWith(".jpg")){
  667. throw new BusinessException(ErrorCode.FAILURE_CODE_7007, "jpg或者zip");
  668. }
  669. // ScenePro scenePro = sceneProService.findBySceneNum(num);
  670. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  671. if(scenePlus == null){
  672. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  673. }
  674. // SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  675. ScenePlusExt scenePlusExt = scenePlusExtService
  676. .getScenePlusExtByPlusId(scenePlus.getId());
  677. //原始计算根目录
  678. // String path = "F:\\test";
  679. String path = scenePlusExt.getDataSource();
  680. //全景图计算根目录
  681. String target = path + "_images";
  682. //解压缩文件存放目录
  683. String targetImagesPath = target + "/extras/images/";
  684. //压缩文件保存目录
  685. String zipTargetFilePath = targetImagesPath + file.getOriginalFilename();
  686. //压缩包保存到本地
  687. // String cachePath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
  688. //先删除本地文件
  689. FileUtils.deleteDirectory(targetImagesPath);
  690. File targetFile = new File(zipTargetFilePath);
  691. if(!targetFile.getParentFile().exists()){
  692. targetFile.getParentFile().mkdirs();
  693. }
  694. file.transferTo(targetFile);
  695. //如果是压缩包上传,需要解压缩
  696. if(file.getOriginalFilename().endsWith(".zip")){
  697. //解压zip包
  698. FileUtil.unZip(zipTargetFilePath, targetImagesPath);
  699. // FileUtils.decompress(zipTargetFilePath, targetImagesPath);
  700. //删除压缩包
  701. FileUtil.delFile(zipTargetFilePath);
  702. }
  703. //判断文件夹目录结构,图片必须放在压缩包根目录下,不支持空文件夹或其他格式文件上传
  704. File[] files = new File(targetImagesPath).listFiles();
  705. Arrays.stream(files).forEach(item->{
  706. if(item.isDirectory()){
  707. throw new BusinessException(ErrorCode.FAILURE_CODE_7018);
  708. }
  709. });
  710. //获取解压后的文件列表
  711. List<String> uploadFileList = FileUtil.getFileList(targetImagesPath);
  712. if(CollUtil.isEmpty(uploadFileList)){
  713. throw new BusinessException(ErrorCode.FAILURE_CODE_5062);
  714. }
  715. //判断是否有可用的jpg文件
  716. boolean existJpg = false;
  717. if(CollUtil.isNotEmpty(uploadFileList)){
  718. existJpg = uploadFileList.stream().anyMatch(str -> {
  719. if(str.endsWith(".jpg")){
  720. return true;
  721. }
  722. return false;
  723. });
  724. }
  725. if(!existJpg){
  726. throw new BusinessException(ErrorCode.FAILURE_CODE_5062);
  727. }
  728. //列出caches/images中的文件列表
  729. String imgCachePath = String.format(UploadFilePath.IMG_CACHES_PATH, num);
  730. //比对图片列表,不存在的要返回名称集合
  731. String visionPath = path + "/results/vision.txt";
  732. List<String> panoramaImageList = SceneUtil.getPanoramaImageList(visionPath);
  733. List<String> notExistFileList = uploadFileList.stream().filter(filePath -> {
  734. filePath = filePath.substring(filePath.lastIndexOf(File.separator) + 1);
  735. if(!panoramaImageList.contains(filePath)){
  736. return false;
  737. }
  738. return true;
  739. }).collect(Collectors.toList());
  740. if(CollUtil.isNotEmpty(notExistFileList)){
  741. //删除错误文件
  742. notExistFileList.parallelStream().forEach(filePath->{
  743. FileUtils.deleteFile(filePath);
  744. });
  745. }
  746. //判断成功的图片,如果成功图片为0,就直接返回,不需要执行算法
  747. uploadFileList = FileUtil.getFileList(targetImagesPath);
  748. if(CollUtil.isEmpty(uploadFileList)){
  749. if(CollUtil.isNotEmpty(notExistFileList)){
  750. notExistFileList = notExistFileList.stream().map(filePath -> {
  751. return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
  752. }).collect(Collectors.toList());
  753. }
  754. return ResultData.ok(new UploadPanoramaVO(0, notExistFileList));
  755. }
  756. //上传
  757. Map<String, String> map = new HashMap<>();
  758. // uploadFileList.stream().forEach(filePath->{
  759. // map.put(filePath, filePath.replace(targetImagesPath, imgCachePath));
  760. // });
  761. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  762. FileUtils.downLoadFromUrl(ossUrlPrefix + imgViewPath + "vision.modeldata" + "?m="+new Date().getTime(),
  763. "vision.modeldata", target + File.separator + "extras" + File.separator);
  764. CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision.modeldata",
  765. target + File.separator + "extras" + File.separator + "vision.txt");
  766. FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  767. FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  768. //data.json增加extras为执行重建算法
  769. String data = FileUtils.readFile(target + File.separator+"data.json");
  770. if(data != null){
  771. JSONObject floorplanJson = new JSONObject();
  772. floorplanJson.put("has_source_images", true);
  773. floorplanJson.put("has_vision_txt", true);
  774. JSONObject dataJson = JSONObject.parseObject(data);
  775. dataJson.put("extras", floorplanJson);
  776. //V5表示不需要生成high,low文件
  777. dataJson.put("skybox_type", "SKYBOX_V6");
  778. if(scenePlusExt.getSceneScheme() == 11){
  779. dataJson.put("skybox_type", "SKYBOX_V7");
  780. }
  781. dataJson.put("split_type", "SPLIT_V8");
  782. //sceneScheme为3切成瓦片图
  783. if(scenePlusExt.getSceneScheme() == 3){
  784. dataJson.put("skybox_type", "SKYBOX_V4");
  785. }
  786. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  787. }
  788. if(new File(target + File.separator + "capture").exists()){
  789. new File(target + File.separator + "capture").delete();
  790. }
  791. if(new File(target + File.separator + "results").exists()){
  792. FileUtils.delAllFile(target + File.separator + "results");
  793. }
  794. if(StorageType.AWS.code().equals(this.type)){
  795. //亚马逊保持旧方式,超链接capture
  796. CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
  797. }
  798. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/");
  799. CreateObjUtil.build3dModel(target , "1");
  800. String uploadJsonPath= target + File.separator + "results" +File.separator+"upload.json";
  801. Thread.sleep(2000);
  802. boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
  803. if(!exist){
  804. throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
  805. }
  806. String uploadData = FileUtils.readFile(uploadJsonPath);
  807. JSONObject uploadJson = null;
  808. JSONArray array = null;
  809. if(uploadData!=null) {
  810. uploadJson = JSONObject.parseObject(uploadData);
  811. array = uploadJson.getJSONArray("upload");
  812. }
  813. if(array == null){
  814. throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
  815. }
  816. JSONObject fileJson = null;
  817. String fileName = "";
  818. for(int i = 0, len = array.size(); i < len; i++) {
  819. fileJson = array.getJSONObject(i);
  820. fileName = fileJson.getString("file");
  821. //文件不存在抛出异常
  822. if (!new File(target + File.separator + "results" + File.separator + fileName)
  823. .exists()) {
  824. throw new Exception(
  825. target + File.separator + "results" + File.separator + fileName + "文件不存在");
  826. }
  827. //high文件夹
  828. if (fileJson.getIntValue("clazz") == 3) {
  829. map.put(target + File.separator + "results" + File.separator + fileName,
  830. imgViewPath + "pan/high/" + fileName.replace("high/", ""));
  831. continue;
  832. }
  833. //low文件夹
  834. if (fileJson.getIntValue("clazz") == 4) {
  835. map.put(target + File.separator + "results" + File.separator + fileName,
  836. imgViewPath + "pan/low/" + fileName.replace("low/", ""));
  837. continue;
  838. }
  839. //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
  840. if (fileJson.getIntValue("clazz") == 5) {
  841. map.put(target + File.separator + "results" + File.separator + fileName,
  842. imgViewPath + fileName);
  843. continue;
  844. }
  845. //tiles文件夹,亚马逊瓦片图
  846. if (fileJson.getIntValue("clazz") == 7) {
  847. map.put(target + File.separator + "results" + File.separator + fileName,
  848. imgViewPath + fileName);
  849. continue;
  850. }
  851. }
  852. if(map.size()>0) {
  853. uploadToOssUtil.uploadMulFiles(map);
  854. }
  855. //拷贝修改后的全景图到缓存目录
  856. String cachedImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
  857. uploadFileList.stream().forEach(srcPath->{
  858. cn.hutool.core.io.FileUtil.copy(srcPath, srcPath.replace(targetImagesPath, cachedImagesPath), true);
  859. });
  860. //更新版本号
  861. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  862. this.upgradeVersionById(sceneEditInfo.getId());
  863. //如果部分成功,则需要返回成功数量和失败列表
  864. if(CollUtil.isNotEmpty(notExistFileList)){
  865. notExistFileList = notExistFileList.stream().map(filePath -> {
  866. return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
  867. }).collect(Collectors.toList());
  868. return ResultData.ok(new UploadPanoramaVO(uploadFileList.size(), notExistFileList));
  869. }
  870. return ResultData.ok();
  871. }
  872. @Override
  873. public ResultData downloadPanorama(FileParamVO param) throws Exception {
  874. String num = param.getNum();
  875. String fileName = param.getFileName();
  876. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  877. if(Objects.isNull(scenePlus)){
  878. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  879. }
  880. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  881. String path = scenePlusExt.getDataSource();
  882. String cachePath = String.format(ConstantFilePath.SCENE_CACHE, num);
  883. String imgCachePath = String.format(UploadFilePath.IMG_CACHES_PATH, num);
  884. String localImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
  885. String cacheFormat = "downloads/scene/%s/caches/";
  886. String cacheImageFormat = "downloads/scene/%s/caches/images/";
  887. String url = null;
  888. String downloadName = null;
  889. //删除本地文件
  890. FileUtils.deleteDirectory(localImagesPath);
  891. //如果入参文件名不为空,则是单个文件下载,不需要打包
  892. if(StrUtil.isNotEmpty(fileName)){
  893. //如果是单张图片,直接提供oss url
  894. String localFilePath = localImagesPath + fileName;
  895. String ossFilePath = imgCachePath + fileName;
  896. uploadToOssUtil.upload(localFilePath, ossFilePath);
  897. url = ossUrlPrefix + ossFilePath;
  898. // FileUtils.downLoadFromUrl(imageUrl, fileName, localImagesPath);
  899. downloadName = fileName;
  900. }else{
  901. //从vision.txt中读取有效全景图名称列表
  902. // String visionPath = path + "/results/vision.txt";
  903. // List<String> imageList = SceneUtil.getPanoramaImageList(visionPath);
  904. //
  905. // //先下载到本地
  906. // List<String> keyList = cn.hutool.core.io.FileUtil.listFileNames(imgCachePath);
  907. // if (!StorageType.LOCAL.code().equals(this.type)) {// TODO: 2022/2/15 这里有可能有问题,可能还需要考虑本地部署的情况
  908. //// System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "8");
  909. // keyList.stream().forEach(key->{
  910. // String file = key.substring(key.lastIndexOf("/") + 1);
  911. // if(imageList.contains(file)){
  912. // String imageUrl = ossUrlPrefix + imgCachePath + file + "?t=" + System.currentTimeMillis();
  913. // FileUtils.downLoadFromUrl(imageUrl, file, localImagesPath);
  914. // }
  915. // });
  916. // }
  917. downloadName = num + "_images.zip";
  918. //打包
  919. String zipPath = cachePath + downloadName;
  920. ZipUtil.zip(localImagesPath, zipPath);
  921. //上传压缩包
  922. uploadToOssUtil.upload(zipPath, String.format(cacheFormat, num) + downloadName);
  923. url = ossUrlPrefix + String.format(cacheFormat, num) + downloadName;
  924. //删除本地压缩包
  925. FileUtils.deleteFile(zipPath);
  926. // //删除本地目录
  927. // FileUtils.deleteDirectory(localImagesPath);
  928. }
  929. Map<String, Object> map = new HashMap<>();
  930. map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
  931. map.put("fileName", downloadName);
  932. return ResultData.ok(map);
  933. }
  934. @Override
  935. public void saveTagsToSceneEditInfo(String num, SceneEditInfo sceneEditInfo){
  936. //查询缓存是否包含热点数据
  937. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  938. Map<String, String> allTagsMap = redisUtil.hmget(key);
  939. boolean hashTags = false;
  940. for (Entry<String, String> tagMap : allTagsMap.entrySet()) {
  941. if(StrUtil.isEmpty(tagMap.getValue())){
  942. continue;
  943. }
  944. hashTags = true;
  945. break;
  946. }
  947. //更改热点状态
  948. sceneEditInfo.setTags(hashTags ? CommonStatus.YES.code() : CommonStatus.NO.code());
  949. //version 是空的代表 sceneEditInfo记录集不存在
  950. if(sceneEditInfo.getVersion() != null){
  951. sceneEditInfo.setVersion(sceneEditInfo.getVersion() + 1);
  952. }
  953. }
  954. @Override
  955. public ResultData saveVideoBox(FileNameAndDataParamVO param) throws Exception {
  956. JSONObject boxVideo = JSONObject.parseObject(param.getData());
  957. String sid = boxVideo.getString("sid");
  958. if(StrUtil.isEmpty(sid)){
  959. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  960. }
  961. // ScenePro scenePro = sceneProService.findBySceneNum(param.getNum());
  962. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  963. if(Objects.isNull(scenePlus))
  964. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  965. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  966. //转换视频格式
  967. this.transferToFlv(param.getNum(), param.getFileName());
  968. //生成boxVideos数据
  969. String boxVideos = this.createBoxVideos(param.getNum(), sid, boxVideo, sceneEditInfo, OperationType.ADDORUPDATE.code());
  970. //更新数据库
  971. this.updateBoxVideos(sceneEditInfo, scenePlus.getId(), boxVideos);
  972. return ResultData.ok();
  973. }
  974. @Override
  975. public ResultData deleteVideoBox(DeleteSidParamVO param) throws Exception {
  976. // ScenePro scenePro = sceneProService.findBySceneNum(param.getNum());
  977. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  978. if(Objects.isNull(scenePlus))
  979. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  980. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  981. //根据sid移除json
  982. String boxVideos = this.createBoxVideos(param.getNum(), param.getSid(), null, sceneEditInfo, OperationType.DELETE.code());
  983. //写数据库
  984. this.updateBoxVideos(sceneEditInfo,scenePlus.getId(),boxVideos);
  985. return ResultData.ok();
  986. }
  987. @Override
  988. public ResultData saveBoxPhoto(BaseDataParamVO param) throws Exception {
  989. JSONObject boxPhoto = JSONObject.parseObject(param.getData());
  990. String sid = boxPhoto.getString("sid");
  991. if(StrUtil.isEmpty(sid)){
  992. throw new BusinessException(ServerCode.PARAM_REQUIRED, sid);
  993. }
  994. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  995. if(Objects.isNull(scenePlus))
  996. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  997. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  998. //生成boxVideos数据
  999. String boxPhotos = this.createBoxPhotos(param.getNum(), sid, boxPhoto, sceneEditInfo, OperationType.ADDORUPDATE.code());
  1000. //更新数据库
  1001. this.updateBoxPhotos(sceneEditInfo, boxPhotos);
  1002. return ResultData.ok();
  1003. }
  1004. @Override
  1005. public ResultData deleteBoxPhoto(DeleteSidParamVO param) throws Exception {
  1006. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1007. if(Objects.isNull(scenePlus))
  1008. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1009. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1010. //根据sid移除json
  1011. String boxPhotos = this.createBoxPhotos(param.getNum(), param.getSid(), null, sceneEditInfo, OperationType.DELETE.code());
  1012. //写数据库
  1013. this.updateBoxPhotos(sceneEditInfo, boxPhotos);
  1014. return ResultData.ok();
  1015. }
  1016. @Override
  1017. public DownloadVO downloadBallScreenVideo(BallScreenVideoParamVO param) {
  1018. String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, param.getNum()) + param.getFileName();
  1019. String url = ossUrlPrefix + videoPath + "?t=" + System.currentTimeMillis();
  1020. return DownloadVO.builder()
  1021. .fileName(param.getFileName())
  1022. .url(url)
  1023. .build();
  1024. }
  1025. @Override
  1026. public ResultData uploadBallScreenVideo(String num, String fileName, MultipartFile file) throws Exception {
  1027. //校验格式
  1028. if(!fileName.endsWith(".mp4")){
  1029. throw new BusinessException(ErrorCode.FAILURE_CODE_7016);
  1030. }
  1031. String videosViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
  1032. // ScenePro scenePro = sceneProService.findBySceneNum(num);
  1033. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1034. if(scenePlus == null){
  1035. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1036. }
  1037. // SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  1038. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1039. String path = scenePlusExt.getDataSource();
  1040. //校验文件名
  1041. String videos = scenePlusExt.getVideos();
  1042. if(StrUtil.isEmpty(videos)){
  1043. throw new BusinessException(ErrorCode.FAILURE_CODE_7012);
  1044. }
  1045. JSONObject videosJson = JSON.parseObject(videos);
  1046. JSONArray dataArr = videosJson.getJSONArray("data");
  1047. boolean exists = false;
  1048. for (Object o : dataArr) {
  1049. JSONObject jsonObject = (JSONObject)o;
  1050. if(jsonObject.getString("id").equals(fileName.replace(".mp4", ""))){
  1051. exists = true;
  1052. break;
  1053. }
  1054. }
  1055. if(!exists){
  1056. throw new BusinessException(ErrorCode.FAILURE_CODE_7012);
  1057. }
  1058. if(path != null && !"".equals(path) && path.startsWith("http")){
  1059. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  1060. }
  1061. String target = path + "_images";
  1062. String filePath = target + File.separator + "extras/video" + File.separator + fileName;
  1063. File targetFile = new File(filePath);
  1064. if(!targetFile.getParentFile().exists()){
  1065. targetFile.getParentFile().mkdirs();
  1066. }
  1067. //保存视频到本地
  1068. file.transferTo(targetFile);
  1069. File video = new File(target + File.separator + "extras/video");
  1070. //如果文件夹或者文件不存在,跳出
  1071. if(!video.exists() || video.listFiles() == null || video.listFiles().length == 0){
  1072. throw new BusinessException(ErrorCode.FAILURE_CODE_7009);
  1073. }
  1074. for(String videoName : video.list()){
  1075. log.info("球幕视频名称:{}", videoName);
  1076. uploadToOssUtil.upload(target + File.separator + "extras/video/" + videoName,videosViewPath + videoName);
  1077. CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
  1078. target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
  1079. uploadToOssUtil.upload(target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),videosViewPath + videoName.replace("mp4", "flv"));
  1080. //覆盖原始视频资源
  1081. FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
  1082. path + File.separator + "caches/videos/" + videoName, true);
  1083. }
  1084. FileUtils.deleteDirectory(target + File.separator + "extras/video/");
  1085. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1086. this.upgradeVersionById(sceneEditInfo.getId());
  1087. //更新scene.json版本号
  1088. this.upgradeVersionToSceneJson(num);
  1089. return ResultData.ok();
  1090. }
  1091. @Override
  1092. public void upgradeVersionToSceneJson(String num) throws Exception{
  1093. String key = String.format(RedisKey.SCENE_JSON, num);
  1094. String objectName = String.format(ConstantFilePath.SCENE_VIEW_DATA_DATA_SCENEJSON, num);
  1095. String objectContent = uploadToOssUtil.getObjectContent(bucket, objectName);
  1096. SceneJsonBean sceneJsonBean = JSON.parseObject(objectContent, SceneJsonBean.class);
  1097. sceneJsonBean.setVersion(sceneJsonBean.getVersion() +1);
  1098. uploadToOssUtil.upload(JSON.toJSONString(sceneJsonBean).getBytes(), objectName);
  1099. redisUtil.set(key, JSON.toJSONString(sceneJsonBean));
  1100. }
  1101. @Override
  1102. public ResultData sceneSync(String num, String type, String floorPlanJson, String ajkJson, String cameraJson,
  1103. MultipartFile[] files) throws Exception {
  1104. String lockKey = String.format(RedisLockKey.LOCK_SCENE_SYNC, num);
  1105. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_2_HOUR);
  1106. if(!lock){
  1107. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  1108. }
  1109. try {
  1110. // ScenePro scenePro = sceneProService.findBySceneNum(num);
  1111. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1112. if(scenePlus == null){
  1113. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1114. }
  1115. // SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  1116. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1117. //更新scene.json文件
  1118. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + num + File.separator + "scene.json");
  1119. if(strsceneInfos == null)
  1120. new File(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + num + File.separator + "scene.json").createNewFile();
  1121. String path = scenePlusExt.getDataSource();// /mnt/data/0662c5389/831989883441512448/4898cab04f8c_202104141602356060/
  1122. if(path != null && !"".equals(path) && path.startsWith("http")){
  1123. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  1124. }
  1125. String target = path + "_ajk"; // /mnt/data/0662c5389/831989883441512448/4898cab04f8c_202104141602356060_ajk
  1126. File editPath = new File(target);
  1127. if(!editPath.exists()){
  1128. editPath.mkdirs();
  1129. }
  1130. //创建文件夹软连接并且复制data.json和project.json
  1131. if(new File(target + File.separator + "capture").exists()){
  1132. new File(target + File.separator + "capture").delete();
  1133. }
  1134. if(new File(target + File.separator + "caches").exists()){
  1135. //删除link
  1136. new File(target + File.separator + "caches" + File.separator + "images").delete();
  1137. //删除所有文件
  1138. FileUtils.delAllFile(target + File.separator + "caches");
  1139. }
  1140. if(new File(target + File.separator + "results").exists()){
  1141. FileUtils.delAllFile(target + File.separator + "results");
  1142. }
  1143. //创建文件夹,并link文件夹
  1144. new File(target + File.separator + "caches").mkdirs();
  1145. CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
  1146. if(new File(path + File.separator + "caches" + File.separator + "images").exists()){
  1147. CreateObjUtil.createSoftConnection(path + File.separator + "caches" + File.separator + "images", target + File.separator + "caches" + File.separator + "images");
  1148. }
  1149. FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  1150. FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  1151. //data.json增加extras为执行重建算法
  1152. String project = FileUtils.readFile(target + File.separator+"project.json");
  1153. if(project != null){
  1154. JSONObject projectJson = JSONObject.parseObject(project);
  1155. projectJson.put("parent", projectJson.get("uuid"));
  1156. projectJson.put("uuid", UUID.randomUUID().toString());
  1157. projectJson.put("time", System.currentTimeMillis());
  1158. FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
  1159. }
  1160. String data = FileUtils.readFile(target + File.separator+"data.json");
  1161. if(data != null){
  1162. JSONObject floorplanJson = new JSONObject();
  1163. floorplanJson.put("has_floor_ajk_json", true);
  1164. floorplanJson.put("has_vision_txt", true);
  1165. floorplanJson.put("has_floorplan_json", true);
  1166. JSONObject dataJson = JSONObject.parseObject(data);
  1167. dataJson.put("extras", floorplanJson);
  1168. //V5表示不需要生成high,low文件
  1169. dataJson.put("skybox_type", "SKYBOX_V8");
  1170. dataJson.put("split_type", "SPLIT_V10");
  1171. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  1172. }
  1173. //文件上传的位置可以自定义
  1174. log.info("画墙重建模型开始");
  1175. File targetFile = new File(target + File.separator + "extras" + File.separator + "floor_ajk.json");
  1176. if(!targetFile.getParentFile().exists()){
  1177. targetFile.getParentFile().mkdirs();
  1178. }
  1179. if(targetFile.exists()){
  1180. FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "floor_ajk.json");
  1181. }
  1182. // 保存
  1183. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floorplan.json", new String(floorPlanJson.getBytes(), "UTF-8"));
  1184. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floor_ajk.json", new String(ajkJson.getBytes(), "UTF-8"));
  1185. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+num + File.separator + "floor_ajk.json", new String(ajkJson.getBytes(), "UTF-8"));
  1186. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "vision.txt", new String(cameraJson.getBytes(), "UTF-8"));
  1187. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+num + File.separator + "camera.json", new String(cameraJson.getBytes(), "UTF-8"));
  1188. for(int i = 0; i < files.length; i ++){
  1189. File cadImg = new File(target + File.separator + "extras" + File.separator + "Floorplans/" + files[i].getOriginalFilename());
  1190. if(!cadImg.getParentFile().exists()){
  1191. cadImg.getParentFile().mkdirs();
  1192. }
  1193. if(cadImg.exists())
  1194. {
  1195. cadImg.delete();
  1196. }
  1197. files[i].transferTo(cadImg);
  1198. }
  1199. //下载封面图
  1200. FileUtils.downLoadFromUrl(scenePlusExt.getThumb() + "?t=" + System.currentTimeMillis(),
  1201. "Cover.png", target + File.separator + "extras" + File.separator + "CoverImage");
  1202. //转换成jpg
  1203. FileUtils.pngToJpg(target + File.separator + "extras" + File.separator + "CoverImage/Cover.png",
  1204. target + File.separator + "extras" + File.separator + "CoverImage/Cover.jpg");
  1205. //安居客算法运行
  1206. log.info("安居客算法:开始建模——"+num);
  1207. CreateObjUtil.build3dModel(target , "1");
  1208. String uploadJsonPath = target + File.separator + "results" + File.separator + "upload.json";
  1209. log.info("uploadJsonPath=" + uploadJsonPath);
  1210. //因为共享目录有延迟,这里循环检测算法是否计算完毕3次,每次隔五秒
  1211. boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
  1212. if(!exist){
  1213. throw new BusinessException(ErrorCode.FAILURE_CODE_7017);
  1214. }
  1215. String zipPath = target + File.separator + "results/" + num + ".zip";
  1216. new File(zipPath).delete();
  1217. ZipUtil.zip(target + File.separator + "results/ajk/", zipPath);
  1218. // String command = "bash /opt/ossutil/gzip.sh " + zipPath.replace(".zip", "") + " " + target + File.separator + "results/ajk/";
  1219. // log.info("压缩文件:" + command);
  1220. // CreateObjUtil.callshell(command);
  1221. if(!new File(zipPath).exists()){
  1222. return ResultData.error(ErrorCode.FAILURE_CODE_5043);
  1223. }
  1224. String fileMD5 = FileMd5Util.getFileMD5(new File(zipPath));
  1225. uploadToOssUtil.upload(zipPath, "data_download/" + num + ".zip");
  1226. SceneDataDownload sceneDataDownload = sceneDataDownloadService.findBySceneNum(num);
  1227. if(sceneDataDownload == null){
  1228. sceneDataDownload = new SceneDataDownload();
  1229. sceneDataDownload.setNum(num);
  1230. sceneDataDownload.setDownloadPath(ossUrlPrefix + "data_download/" + num + ".zip");
  1231. sceneDataDownload.setFileMd5(fileMD5);
  1232. sceneDataDownloadService.save(sceneDataDownload);
  1233. return ResultData.ok();
  1234. }
  1235. sceneDataDownload.setFileMd5(fileMD5);
  1236. sceneDataDownload.setUpdateTime(Calendar.getInstance().getTime());
  1237. sceneDataDownloadService.updateById(sceneDataDownload);
  1238. }catch (Exception e){
  1239. log.error("画墙重建模型失败...", e);
  1240. throw new BusinessException(ErrorCode.FAILURE_CODE_5039);
  1241. }finally {
  1242. redisLockUtil.unlockLua(lockKey);
  1243. }
  1244. return ResultData.ok();
  1245. }
  1246. @Override
  1247. public ResultData checkKey(SceneCheckKeyParamVO param) throws Exception {
  1248. SceneJsonBean sceneJsonBean = null;
  1249. String sceneJson = redisUtil.get(String.format(RedisKey.SCENE_JSON, param.getNum()));
  1250. if(StrUtil.isEmpty(sceneJson)){
  1251. sceneJson = uploadToOssUtil.getObjectContent(bucket, String.format(UploadFilePath.DATA_VIEW_PATH + "scene.json"));
  1252. }
  1253. sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
  1254. if(!param.getPassword().equals(sceneJsonBean.getScenePassword())){
  1255. throw new BusinessException(ErrorCode.FAILURE_CODE_5021);
  1256. }
  1257. return ResultData.ok();
  1258. }
  1259. private void updateBoxVideos(SceneEditInfo sceneEditInfo, Long scenePlusId, String boxVideos){
  1260. if(Objects.isNull(sceneEditInfo)){
  1261. sceneEditInfo = new SceneEditInfo();
  1262. sceneEditInfo.setScenePlusId(scenePlusId);
  1263. sceneEditInfo.setBoxVideos(boxVideos);
  1264. this.save(sceneEditInfo);
  1265. }else{
  1266. this.update(new UpdateWrapper<SceneEditInfo>()
  1267. .setSql("version = version + 1")
  1268. .set("box_videos", boxVideos)
  1269. .eq("id", sceneEditInfo.getId()));
  1270. }
  1271. }
  1272. private void updateBoxPhotos(SceneEditInfo sceneEditInfo, String boxPhotos){
  1273. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  1274. .set(SceneEditInfo::getBoxPhotos, boxPhotos)
  1275. .setSql("version = version + 1")
  1276. .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
  1277. }
  1278. private String createBoxVideos(
  1279. String num, String sid, JSONObject boxVideo,
  1280. SceneEditInfo sceneEditInfo, int type) throws Exception{
  1281. String boxVideos = null;
  1282. if(sceneEditInfo != null){
  1283. boxVideos = sceneEditInfo.getBoxVideos();
  1284. }
  1285. JSONArray boxVideosJson = null;
  1286. if (StrUtil.isNotEmpty(boxVideos)) {
  1287. boxVideosJson = JSONArray.parseArray(boxVideos);
  1288. }else {
  1289. boxVideosJson = new JSONArray();
  1290. }
  1291. String result = null;
  1292. //删除
  1293. if(type == OperationType.DELETE.code()){
  1294. Set<String> deleteFile = new HashSet<>();
  1295. if(boxVideosJson.size() == 0)
  1296. return null;
  1297. for(int i=0;i<boxVideosJson.size();++i){
  1298. JSONObject ele = boxVideosJson.getJSONObject(i);
  1299. if(ele.getString("sid").equals(sid)){
  1300. String poster = ele.getString("poster");
  1301. if(StrUtil.isNotEmpty(poster))
  1302. deleteFile.add(poster);
  1303. String url = ele.getString("url");
  1304. if(StrUtil.isNotEmpty(url)){
  1305. deleteFile.add(url);
  1306. deleteFile.add(url.replace(".mp4",".flv"));
  1307. }
  1308. boxVideosJson.remove(i);
  1309. }
  1310. }
  1311. //删除资源文件
  1312. if(CollUtil.isNotEmpty(deleteFile))
  1313. sceneUploadService.delete(
  1314. DeleteFileParamVO.builder().num(num)
  1315. .bizType(FileBizType.BOX_VIDEO.code())
  1316. .fileNames(new ArrayList<>(deleteFile)).build());
  1317. }else{
  1318. // TODO: 2022/3/1 目前需求只保留一个,所以这里先注释掉,sid不同时,不追加
  1319. //更新
  1320. // boolean exist = false;
  1321. // for(int i=0;i<boxVideosJson.size();++i){
  1322. // JSONObject ele = boxVideosJson.getJSONObject(i);
  1323. // if(ele.getString("sid").equals(sid)){
  1324. // boxVideosJson.set(i, boxVideo);
  1325. // exist = true;
  1326. // }
  1327. // }
  1328. // //新增
  1329. // if(!exist){
  1330. // boxVideosJson.add(boxVideo);
  1331. // }
  1332. boxVideosJson.clear();
  1333. boxVideosJson.add(boxVideo);
  1334. }
  1335. if(boxVideosJson.size() != 0){
  1336. result = boxVideosJson.toJSONString();
  1337. }
  1338. return result;
  1339. }
  1340. private String createBoxPhotos(String num, String sid, JSONObject boxPhoto, SceneEditInfo sceneEditInfo, int type) throws Exception{
  1341. String boxPhotos = null;
  1342. if(sceneEditInfo != null){
  1343. boxPhotos = sceneEditInfo.getBoxPhotos();
  1344. }
  1345. JSONArray boxPhotosJson = null;
  1346. if (StrUtil.isNotEmpty(boxPhotos)) {
  1347. boxPhotosJson = JSONArray.parseArray(boxPhotos);
  1348. }else {
  1349. boxPhotosJson = new JSONArray();
  1350. }
  1351. String result = null;
  1352. //删除
  1353. if(type == OperationType.DELETE.code()){
  1354. Set<String> deleteFile = new HashSet<>();
  1355. if(boxPhotosJson.size() == 0)
  1356. return null;
  1357. for(int i=0;i<boxPhotosJson.size();++i){
  1358. JSONObject ele = boxPhotosJson.getJSONObject(i);
  1359. if(ele.getString("sid").equals(sid)){
  1360. String poster = ele.getString("poster");
  1361. if(StrUtil.isNotEmpty(poster))
  1362. deleteFile.add(poster);
  1363. String url = ele.getString("url");
  1364. if(StrUtil.isNotEmpty(url))
  1365. deleteFile.add(url);
  1366. boxPhotosJson.remove(i);
  1367. }
  1368. }
  1369. //删除资源文件
  1370. if(CollUtil.isNotEmpty(deleteFile))
  1371. sceneUploadService.delete(
  1372. DeleteFileParamVO.builder().num(num)
  1373. .bizType(FileBizType.BOX_VIDEO.code())
  1374. .fileNames(new ArrayList<>(deleteFile)).build());
  1375. }else{
  1376. //更新
  1377. boolean exist = false;
  1378. for(int i=0;i<boxPhotosJson.size();++i){
  1379. JSONObject ele = boxPhotosJson.getJSONObject(i);
  1380. if(ele.getString("sid").equals(sid)){
  1381. boxPhoto.put("createTime", ele.getLong("createTime"));
  1382. boxPhotosJson.set(i, boxPhoto);
  1383. exist = true;
  1384. }
  1385. }
  1386. //新增
  1387. if(!exist){
  1388. boxPhoto.put("createTime", Calendar.getInstance().getTimeInMillis());
  1389. boxPhotosJson.add(boxPhoto);
  1390. }
  1391. }
  1392. if(boxPhotosJson.size() != 0){
  1393. List<BoxPhotoBean> list = Lists.newArrayList();
  1394. for (Object o : boxPhotosJson) {
  1395. JSONObject jsonObject = (JSONObject)o;
  1396. list.add(BoxPhotoBean.builder().createTime(jsonObject.getLong("createTime")).boxPhoto(jsonObject).build());
  1397. }
  1398. //按创建时间倒叙排序
  1399. list.sort(Comparator.comparingLong(BoxPhotoBean::getCreateTime).reversed());
  1400. // list转JSONArray
  1401. JSONArray array = new JSONArray();
  1402. list.stream().forEach(bean->{
  1403. array.add(bean.getBoxPhoto());
  1404. });
  1405. result = array.toJSONString();
  1406. }
  1407. return result;
  1408. }
  1409. private void transferToFlv(String num, String fileName) throws Exception {
  1410. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  1411. String localImagesPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  1412. String localFilePath = localImagesPath + fileName;
  1413. File targetFile = new File(localImagesPath);
  1414. if (!targetFile.exists()){
  1415. targetFile.mkdirs();
  1416. }
  1417. targetFile = new File(localFilePath);
  1418. if (targetFile.exists()){
  1419. FileUtils.deleteFile(localFilePath);
  1420. }
  1421. //从用户编辑目录中下载视频到本地
  1422. if (!StorageType.LOCAL.code().equals(this.type)) {
  1423. String filePath = userEditPath + fileName;
  1424. String imageUrl = ossUrlPrefix + filePath + "?t=" + System.currentTimeMillis();
  1425. FileUtils.downLoadFromUrl(imageUrl, fileName, localImagesPath);
  1426. }
  1427. //视频格式转换
  1428. CreateObjUtil.mp4ToFlv(localFilePath, localFilePath.replace("mp4", "flv"));
  1429. //上传
  1430. String flvFileName = fileName.replace("mp4", "flv");
  1431. // uploadToOssUtil.upload(localFilePath, userEditPath + fileName);
  1432. uploadToOssUtil.upload(localFilePath.replace("mp4", "flv"), userEditPath+flvFileName);
  1433. }
  1434. }