SceneEditInfoServiceImpl.java 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649
  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. if(StrUtil.isNotEmpty(fileName)){
  891. //如果是单张图片,直接提供oss url
  892. String localFilePath = localImagesPath + fileName;
  893. String ossFilePath = imgCachePath + fileName;
  894. uploadToOssUtil.upload(localFilePath, ossFilePath);
  895. url = ossUrlPrefix + ossFilePath;
  896. // FileUtils.downLoadFromUrl(imageUrl, fileName, localImagesPath);
  897. downloadName = fileName;
  898. }else{
  899. //从vision.txt中读取有效全景图名称列表
  900. // String visionPath = path + "/results/vision.txt";
  901. // List<String> imageList = SceneUtil.getPanoramaImageList(visionPath);
  902. //
  903. // //先下载到本地
  904. // List<String> keyList = cn.hutool.core.io.FileUtil.listFileNames(imgCachePath);
  905. // if (!StorageType.LOCAL.code().equals(this.type)) {// TODO: 2022/2/15 这里有可能有问题,可能还需要考虑本地部署的情况
  906. //// System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "8");
  907. // keyList.stream().forEach(key->{
  908. // String file = key.substring(key.lastIndexOf("/") + 1);
  909. // if(imageList.contains(file)){
  910. // String imageUrl = ossUrlPrefix + imgCachePath + file + "?t=" + System.currentTimeMillis();
  911. // FileUtils.downLoadFromUrl(imageUrl, file, localImagesPath);
  912. // }
  913. // });
  914. // }
  915. if(!cn.hutool.core.io.FileUtil.exist(localImagesPath)){
  916. throw new BusinessException(ErrorCode.FAILURE_CODE_7006);
  917. }
  918. downloadName = num + "_images.zip";
  919. //打包
  920. String zipPath = cachePath + downloadName;
  921. ZipUtil.zip(localImagesPath, zipPath);
  922. //上传压缩包
  923. uploadToOssUtil.upload(zipPath, String.format(cacheFormat, num) + downloadName);
  924. url = ossUrlPrefix + String.format(cacheFormat, num) + downloadName;
  925. //删除本地压缩包
  926. FileUtils.deleteFile(zipPath);
  927. // //删除本地目录
  928. // FileUtils.deleteDirectory(localImagesPath);
  929. }
  930. Map<String, Object> map = new HashMap<>();
  931. map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
  932. map.put("fileName", downloadName);
  933. return ResultData.ok(map);
  934. }
  935. @Override
  936. public void saveTagsToSceneEditInfo(String num, SceneEditInfo sceneEditInfo){
  937. //查询缓存是否包含热点数据
  938. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  939. Map<String, String> allTagsMap = redisUtil.hmget(key);
  940. boolean hashTags = false;
  941. for (Entry<String, String> tagMap : allTagsMap.entrySet()) {
  942. if(StrUtil.isEmpty(tagMap.getValue())){
  943. continue;
  944. }
  945. hashTags = true;
  946. break;
  947. }
  948. //更改热点状态
  949. sceneEditInfo.setTags(hashTags ? CommonStatus.YES.code() : CommonStatus.NO.code());
  950. //version 是空的代表 sceneEditInfo记录集不存在
  951. if(sceneEditInfo.getVersion() != null){
  952. sceneEditInfo.setVersion(sceneEditInfo.getVersion() + 1);
  953. }
  954. }
  955. @Override
  956. public ResultData saveVideoBox(FileNameAndDataParamVO param) throws Exception {
  957. JSONObject boxVideo = JSONObject.parseObject(param.getData());
  958. String sid = boxVideo.getString("sid");
  959. if(StrUtil.isEmpty(sid)){
  960. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  961. }
  962. // ScenePro scenePro = sceneProService.findBySceneNum(param.getNum());
  963. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  964. if(Objects.isNull(scenePlus))
  965. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  966. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  967. //转换视频格式
  968. this.transferToFlv(param.getNum(), param.getFileName());
  969. //生成boxVideos数据
  970. String boxVideos = this.createBoxVideos(param.getNum(), sid, boxVideo, sceneEditInfo, OperationType.ADDORUPDATE.code());
  971. //更新数据库
  972. this.updateBoxVideos(sceneEditInfo, scenePlus.getId(), boxVideos);
  973. return ResultData.ok();
  974. }
  975. @Override
  976. public ResultData deleteVideoBox(DeleteSidParamVO param) throws Exception {
  977. // ScenePro scenePro = sceneProService.findBySceneNum(param.getNum());
  978. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  979. if(Objects.isNull(scenePlus))
  980. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  981. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  982. //根据sid移除json
  983. String boxVideos = this.createBoxVideos(param.getNum(), param.getSid(), null, sceneEditInfo, OperationType.DELETE.code());
  984. //写数据库
  985. this.updateBoxVideos(sceneEditInfo,scenePlus.getId(),boxVideos);
  986. return ResultData.ok();
  987. }
  988. @Override
  989. public ResultData saveBoxPhoto(BaseDataParamVO param) throws Exception {
  990. JSONObject boxPhoto = JSONObject.parseObject(param.getData());
  991. String sid = boxPhoto.getString("sid");
  992. if(StrUtil.isEmpty(sid)){
  993. throw new BusinessException(ServerCode.PARAM_REQUIRED, sid);
  994. }
  995. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  996. if(Objects.isNull(scenePlus))
  997. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  998. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  999. //生成boxVideos数据
  1000. String boxPhotos = this.createBoxPhotos(param.getNum(), sid, boxPhoto, sceneEditInfo, OperationType.ADDORUPDATE.code());
  1001. //更新数据库
  1002. this.updateBoxPhotos(sceneEditInfo, boxPhotos);
  1003. return ResultData.ok();
  1004. }
  1005. @Override
  1006. public ResultData deleteBoxPhoto(DeleteSidParamVO param) throws Exception {
  1007. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1008. if(Objects.isNull(scenePlus))
  1009. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1010. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1011. //根据sid移除json
  1012. String boxPhotos = this.createBoxPhotos(param.getNum(), param.getSid(), null, sceneEditInfo, OperationType.DELETE.code());
  1013. //写数据库
  1014. this.updateBoxPhotos(sceneEditInfo, boxPhotos);
  1015. return ResultData.ok();
  1016. }
  1017. @Override
  1018. public DownloadVO downloadBallScreenVideo(BallScreenVideoParamVO param) {
  1019. String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, param.getNum()) + param.getFileName();
  1020. String url = ossUrlPrefix + videoPath + "?t=" + System.currentTimeMillis();
  1021. return DownloadVO.builder()
  1022. .fileName(param.getFileName())
  1023. .url(url)
  1024. .build();
  1025. }
  1026. @Override
  1027. public ResultData uploadBallScreenVideo(String num, String fileName, MultipartFile file) throws Exception {
  1028. //校验格式
  1029. if(!fileName.endsWith(".mp4")){
  1030. throw new BusinessException(ErrorCode.FAILURE_CODE_7016);
  1031. }
  1032. String videosViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
  1033. // ScenePro scenePro = sceneProService.findBySceneNum(num);
  1034. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1035. if(scenePlus == null){
  1036. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1037. }
  1038. // SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  1039. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1040. String path = scenePlusExt.getDataSource();
  1041. //校验文件名
  1042. String videos = scenePlusExt.getVideos();
  1043. if(StrUtil.isEmpty(videos)){
  1044. throw new BusinessException(ErrorCode.FAILURE_CODE_7012);
  1045. }
  1046. JSONObject videosJson = JSON.parseObject(videos);
  1047. JSONArray dataArr = videosJson.getJSONArray("data");
  1048. boolean exists = false;
  1049. for (Object o : dataArr) {
  1050. JSONObject jsonObject = (JSONObject)o;
  1051. if(jsonObject.getString("id").equals(fileName.replace(".mp4", ""))){
  1052. exists = true;
  1053. break;
  1054. }
  1055. }
  1056. if(!exists){
  1057. throw new BusinessException(ErrorCode.FAILURE_CODE_7012);
  1058. }
  1059. if(path != null && !"".equals(path) && path.startsWith("http")){
  1060. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  1061. }
  1062. String target = path + "_images";
  1063. String filePath = target + File.separator + "extras/video" + File.separator + fileName;
  1064. File targetFile = new File(filePath);
  1065. if(!targetFile.getParentFile().exists()){
  1066. targetFile.getParentFile().mkdirs();
  1067. }
  1068. //保存视频到本地
  1069. file.transferTo(targetFile);
  1070. File video = new File(target + File.separator + "extras/video");
  1071. //如果文件夹或者文件不存在,跳出
  1072. if(!video.exists() || video.listFiles() == null || video.listFiles().length == 0){
  1073. throw new BusinessException(ErrorCode.FAILURE_CODE_7009);
  1074. }
  1075. for(String videoName : video.list()){
  1076. log.info("球幕视频名称:{}", videoName);
  1077. uploadToOssUtil.upload(target + File.separator + "extras/video/" + videoName,videosViewPath + videoName);
  1078. CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
  1079. target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
  1080. uploadToOssUtil.upload(target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),videosViewPath + videoName.replace("mp4", "flv"));
  1081. //覆盖原始视频资源
  1082. FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
  1083. path + File.separator + "caches/videos/" + videoName, true);
  1084. }
  1085. FileUtils.deleteDirectory(target + File.separator + "extras/video/");
  1086. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1087. this.upgradeVersionById(sceneEditInfo.getId());
  1088. //更新scene.json版本号
  1089. this.upgradeVersionToSceneJson(num);
  1090. return ResultData.ok();
  1091. }
  1092. @Override
  1093. public void upgradeVersionToSceneJson(String num) throws Exception{
  1094. String key = String.format(RedisKey.SCENE_JSON, num);
  1095. String objectName = String.format(ConstantFilePath.SCENE_VIEW_DATA_DATA_SCENEJSON, num);
  1096. String objectContent = uploadToOssUtil.getObjectContent(bucket, objectName);
  1097. SceneJsonBean sceneJsonBean = JSON.parseObject(objectContent, SceneJsonBean.class);
  1098. sceneJsonBean.setVersion(sceneJsonBean.getVersion() +1);
  1099. uploadToOssUtil.upload(JSON.toJSONString(sceneJsonBean).getBytes(), objectName);
  1100. redisUtil.set(key, JSON.toJSONString(sceneJsonBean));
  1101. }
  1102. @Override
  1103. public ResultData sceneSync(String num, String type, String floorPlanJson, String ajkJson, String cameraJson,
  1104. MultipartFile[] files) throws Exception {
  1105. String lockKey = String.format(RedisLockKey.LOCK_SCENE_SYNC, num);
  1106. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_2_HOUR);
  1107. if(!lock){
  1108. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  1109. }
  1110. try {
  1111. // ScenePro scenePro = sceneProService.findBySceneNum(num);
  1112. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1113. if(scenePlus == null){
  1114. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1115. }
  1116. // SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  1117. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1118. //更新scene.json文件
  1119. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + num + File.separator + "scene.json");
  1120. if(strsceneInfos == null)
  1121. new File(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + num + File.separator + "scene.json").createNewFile();
  1122. String path = scenePlusExt.getDataSource();// /mnt/data/0662c5389/831989883441512448/4898cab04f8c_202104141602356060/
  1123. if(path != null && !"".equals(path) && path.startsWith("http")){
  1124. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  1125. }
  1126. String target = path + "_ajk"; // /mnt/data/0662c5389/831989883441512448/4898cab04f8c_202104141602356060_ajk
  1127. File editPath = new File(target);
  1128. if(!editPath.exists()){
  1129. editPath.mkdirs();
  1130. }
  1131. //创建文件夹软连接并且复制data.json和project.json
  1132. if(new File(target + File.separator + "capture").exists()){
  1133. new File(target + File.separator + "capture").delete();
  1134. }
  1135. if(new File(target + File.separator + "caches").exists()){
  1136. //删除link
  1137. new File(target + File.separator + "caches" + File.separator + "images").delete();
  1138. //删除所有文件
  1139. FileUtils.delAllFile(target + File.separator + "caches");
  1140. }
  1141. if(new File(target + File.separator + "results").exists()){
  1142. FileUtils.delAllFile(target + File.separator + "results");
  1143. }
  1144. //创建文件夹,并link文件夹
  1145. new File(target + File.separator + "caches").mkdirs();
  1146. CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
  1147. if(new File(path + File.separator + "caches" + File.separator + "images").exists()){
  1148. CreateObjUtil.createSoftConnection(path + File.separator + "caches" + File.separator + "images", target + File.separator + "caches" + File.separator + "images");
  1149. }
  1150. FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  1151. FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  1152. //data.json增加extras为执行重建算法
  1153. String project = FileUtils.readFile(target + File.separator+"project.json");
  1154. if(project != null){
  1155. JSONObject projectJson = JSONObject.parseObject(project);
  1156. projectJson.put("parent", projectJson.get("uuid"));
  1157. projectJson.put("uuid", UUID.randomUUID().toString());
  1158. projectJson.put("time", System.currentTimeMillis());
  1159. FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
  1160. }
  1161. String data = FileUtils.readFile(target + File.separator+"data.json");
  1162. if(data != null){
  1163. JSONObject floorplanJson = new JSONObject();
  1164. floorplanJson.put("has_floor_ajk_json", true);
  1165. floorplanJson.put("has_vision_txt", true);
  1166. floorplanJson.put("has_floorplan_json", true);
  1167. JSONObject dataJson = JSONObject.parseObject(data);
  1168. dataJson.put("extras", floorplanJson);
  1169. //V5表示不需要生成high,low文件
  1170. dataJson.put("skybox_type", "SKYBOX_V8");
  1171. dataJson.put("split_type", "SPLIT_V10");
  1172. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  1173. }
  1174. //文件上传的位置可以自定义
  1175. log.info("画墙重建模型开始");
  1176. File targetFile = new File(target + File.separator + "extras" + File.separator + "floor_ajk.json");
  1177. if(!targetFile.getParentFile().exists()){
  1178. targetFile.getParentFile().mkdirs();
  1179. }
  1180. if(targetFile.exists()){
  1181. FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "floor_ajk.json");
  1182. }
  1183. // 保存
  1184. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floorplan.json", new String(floorPlanJson.getBytes(), "UTF-8"));
  1185. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floor_ajk.json", new String(ajkJson.getBytes(), "UTF-8"));
  1186. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+num + File.separator + "floor_ajk.json", new String(ajkJson.getBytes(), "UTF-8"));
  1187. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "vision.txt", new String(cameraJson.getBytes(), "UTF-8"));
  1188. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+num + File.separator + "camera.json", new String(cameraJson.getBytes(), "UTF-8"));
  1189. for(int i = 0; i < files.length; i ++){
  1190. File cadImg = new File(target + File.separator + "extras" + File.separator + "Floorplans/" + files[i].getOriginalFilename());
  1191. if(!cadImg.getParentFile().exists()){
  1192. cadImg.getParentFile().mkdirs();
  1193. }
  1194. if(cadImg.exists())
  1195. {
  1196. cadImg.delete();
  1197. }
  1198. files[i].transferTo(cadImg);
  1199. }
  1200. //下载封面图
  1201. FileUtils.downLoadFromUrl(scenePlusExt.getThumb() + "?t=" + System.currentTimeMillis(),
  1202. "Cover.png", target + File.separator + "extras" + File.separator + "CoverImage");
  1203. //转换成jpg
  1204. FileUtils.pngToJpg(target + File.separator + "extras" + File.separator + "CoverImage/Cover.png",
  1205. target + File.separator + "extras" + File.separator + "CoverImage/Cover.jpg");
  1206. //安居客算法运行
  1207. log.info("安居客算法:开始建模——"+num);
  1208. CreateObjUtil.build3dModel(target , "1");
  1209. String uploadJsonPath = target + File.separator + "results" + File.separator + "upload.json";
  1210. log.info("uploadJsonPath=" + uploadJsonPath);
  1211. //因为共享目录有延迟,这里循环检测算法是否计算完毕3次,每次隔五秒
  1212. boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
  1213. if(!exist){
  1214. throw new BusinessException(ErrorCode.FAILURE_CODE_7017);
  1215. }
  1216. String zipPath = target + File.separator + "results/" + num + ".zip";
  1217. new File(zipPath).delete();
  1218. ZipUtil.zip(target + File.separator + "results/ajk/", zipPath);
  1219. // String command = "bash /opt/ossutil/gzip.sh " + zipPath.replace(".zip", "") + " " + target + File.separator + "results/ajk/";
  1220. // log.info("压缩文件:" + command);
  1221. // CreateObjUtil.callshell(command);
  1222. if(!new File(zipPath).exists()){
  1223. return ResultData.error(ErrorCode.FAILURE_CODE_5043);
  1224. }
  1225. String fileMD5 = FileMd5Util.getFileMD5(new File(zipPath));
  1226. uploadToOssUtil.upload(zipPath, "data_download/" + num + ".zip");
  1227. SceneDataDownload sceneDataDownload = sceneDataDownloadService.findBySceneNum(num);
  1228. if(sceneDataDownload == null){
  1229. sceneDataDownload = new SceneDataDownload();
  1230. sceneDataDownload.setNum(num);
  1231. sceneDataDownload.setDownloadPath(ossUrlPrefix + "data_download/" + num + ".zip");
  1232. sceneDataDownload.setFileMd5(fileMD5);
  1233. sceneDataDownloadService.save(sceneDataDownload);
  1234. return ResultData.ok();
  1235. }
  1236. sceneDataDownload.setFileMd5(fileMD5);
  1237. sceneDataDownload.setUpdateTime(Calendar.getInstance().getTime());
  1238. sceneDataDownloadService.updateById(sceneDataDownload);
  1239. }catch (Exception e){
  1240. log.error("画墙重建模型失败...", e);
  1241. throw new BusinessException(ErrorCode.FAILURE_CODE_5039);
  1242. }finally {
  1243. redisLockUtil.unlockLua(lockKey);
  1244. }
  1245. return ResultData.ok();
  1246. }
  1247. @Override
  1248. public ResultData checkKey(SceneCheckKeyParamVO param) throws Exception {
  1249. SceneJsonBean sceneJsonBean = null;
  1250. String sceneJson = redisUtil.get(String.format(RedisKey.SCENE_JSON, param.getNum()));
  1251. if(StrUtil.isEmpty(sceneJson)){
  1252. sceneJson = uploadToOssUtil.getObjectContent(bucket, String.format(UploadFilePath.DATA_VIEW_PATH + "scene.json"));
  1253. }
  1254. sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
  1255. if(!param.getPassword().equals(sceneJsonBean.getScenePassword())){
  1256. throw new BusinessException(ErrorCode.FAILURE_CODE_5021);
  1257. }
  1258. return ResultData.ok();
  1259. }
  1260. private void updateBoxVideos(SceneEditInfo sceneEditInfo, Long scenePlusId, String boxVideos){
  1261. if(Objects.isNull(sceneEditInfo)){
  1262. sceneEditInfo = new SceneEditInfo();
  1263. sceneEditInfo.setScenePlusId(scenePlusId);
  1264. sceneEditInfo.setBoxVideos(boxVideos);
  1265. this.save(sceneEditInfo);
  1266. }else{
  1267. this.update(new UpdateWrapper<SceneEditInfo>()
  1268. .setSql("version = version + 1")
  1269. .set("box_videos", boxVideos)
  1270. .eq("id", sceneEditInfo.getId()));
  1271. }
  1272. }
  1273. private void updateBoxPhotos(SceneEditInfo sceneEditInfo, String boxPhotos){
  1274. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  1275. .set(SceneEditInfo::getBoxPhotos, boxPhotos)
  1276. .setSql("version = version + 1")
  1277. .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
  1278. }
  1279. private String createBoxVideos(
  1280. String num, String sid, JSONObject boxVideo,
  1281. SceneEditInfo sceneEditInfo, int type) throws Exception{
  1282. String boxVideos = null;
  1283. if(sceneEditInfo != null){
  1284. boxVideos = sceneEditInfo.getBoxVideos();
  1285. }
  1286. JSONArray boxVideosJson = null;
  1287. if (StrUtil.isNotEmpty(boxVideos)) {
  1288. boxVideosJson = JSONArray.parseArray(boxVideos);
  1289. }else {
  1290. boxVideosJson = new JSONArray();
  1291. }
  1292. String result = null;
  1293. //删除
  1294. if(type == OperationType.DELETE.code()){
  1295. Set<String> deleteFile = new HashSet<>();
  1296. if(boxVideosJson.size() == 0)
  1297. return null;
  1298. for(int i=0;i<boxVideosJson.size();++i){
  1299. JSONObject ele = boxVideosJson.getJSONObject(i);
  1300. if(ele.getString("sid").equals(sid)){
  1301. String poster = ele.getString("poster");
  1302. if(StrUtil.isNotEmpty(poster))
  1303. deleteFile.add(poster);
  1304. String url = ele.getString("url");
  1305. if(StrUtil.isNotEmpty(url)){
  1306. deleteFile.add(url);
  1307. deleteFile.add(url.replace(".mp4",".flv"));
  1308. }
  1309. boxVideosJson.remove(i);
  1310. }
  1311. }
  1312. //删除资源文件
  1313. if(CollUtil.isNotEmpty(deleteFile))
  1314. sceneUploadService.delete(
  1315. DeleteFileParamVO.builder().num(num)
  1316. .bizType(FileBizType.BOX_VIDEO.code())
  1317. .fileNames(new ArrayList<>(deleteFile)).build());
  1318. }else{
  1319. // TODO: 2022/3/1 目前需求只保留一个,所以这里先注释掉,sid不同时,不追加
  1320. //更新
  1321. // boolean exist = false;
  1322. // for(int i=0;i<boxVideosJson.size();++i){
  1323. // JSONObject ele = boxVideosJson.getJSONObject(i);
  1324. // if(ele.getString("sid").equals(sid)){
  1325. // boxVideosJson.set(i, boxVideo);
  1326. // exist = true;
  1327. // }
  1328. // }
  1329. // //新增
  1330. // if(!exist){
  1331. // boxVideosJson.add(boxVideo);
  1332. // }
  1333. boxVideosJson.clear();
  1334. boxVideosJson.add(boxVideo);
  1335. }
  1336. if(boxVideosJson.size() != 0){
  1337. result = boxVideosJson.toJSONString();
  1338. }
  1339. return result;
  1340. }
  1341. private String createBoxPhotos(String num, String sid, JSONObject boxPhoto, SceneEditInfo sceneEditInfo, int type) throws Exception{
  1342. String boxPhotos = null;
  1343. if(sceneEditInfo != null){
  1344. boxPhotos = sceneEditInfo.getBoxPhotos();
  1345. }
  1346. JSONArray boxPhotosJson = null;
  1347. if (StrUtil.isNotEmpty(boxPhotos)) {
  1348. boxPhotosJson = JSONArray.parseArray(boxPhotos);
  1349. }else {
  1350. boxPhotosJson = new JSONArray();
  1351. }
  1352. String result = null;
  1353. //删除
  1354. if(type == OperationType.DELETE.code()){
  1355. Set<String> deleteFile = new HashSet<>();
  1356. if(boxPhotosJson.size() == 0)
  1357. return null;
  1358. for(int i=0;i<boxPhotosJson.size();++i){
  1359. JSONObject ele = boxPhotosJson.getJSONObject(i);
  1360. if(ele.getString("sid").equals(sid)){
  1361. String poster = ele.getString("poster");
  1362. if(StrUtil.isNotEmpty(poster))
  1363. deleteFile.add(poster);
  1364. String url = ele.getString("url");
  1365. if(StrUtil.isNotEmpty(url))
  1366. deleteFile.add(url);
  1367. boxPhotosJson.remove(i);
  1368. }
  1369. }
  1370. //删除资源文件
  1371. if(CollUtil.isNotEmpty(deleteFile))
  1372. sceneUploadService.delete(
  1373. DeleteFileParamVO.builder().num(num)
  1374. .bizType(FileBizType.BOX_VIDEO.code())
  1375. .fileNames(new ArrayList<>(deleteFile)).build());
  1376. }else{
  1377. //更新
  1378. boolean exist = false;
  1379. for(int i=0;i<boxPhotosJson.size();++i){
  1380. JSONObject ele = boxPhotosJson.getJSONObject(i);
  1381. if(ele.getString("sid").equals(sid)){
  1382. boxPhoto.put("createTime", ele.getLong("createTime"));
  1383. boxPhotosJson.set(i, boxPhoto);
  1384. exist = true;
  1385. }
  1386. }
  1387. //新增
  1388. if(!exist){
  1389. boxPhoto.put("createTime", Calendar.getInstance().getTimeInMillis());
  1390. boxPhotosJson.add(boxPhoto);
  1391. }
  1392. }
  1393. if(boxPhotosJson.size() != 0){
  1394. List<BoxPhotoBean> list = Lists.newArrayList();
  1395. for (Object o : boxPhotosJson) {
  1396. JSONObject jsonObject = (JSONObject)o;
  1397. list.add(BoxPhotoBean.builder().createTime(jsonObject.getLong("createTime")).boxPhoto(jsonObject).build());
  1398. }
  1399. //按创建时间倒叙排序
  1400. list.sort(Comparator.comparingLong(BoxPhotoBean::getCreateTime).reversed());
  1401. // list转JSONArray
  1402. JSONArray array = new JSONArray();
  1403. list.stream().forEach(bean->{
  1404. array.add(bean.getBoxPhoto());
  1405. });
  1406. result = array.toJSONString();
  1407. }
  1408. return result;
  1409. }
  1410. private void transferToFlv(String num, String fileName) throws Exception {
  1411. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  1412. String localImagesPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  1413. String localFilePath = localImagesPath + fileName;
  1414. File targetFile = new File(localImagesPath);
  1415. if (!targetFile.exists()){
  1416. targetFile.mkdirs();
  1417. }
  1418. targetFile = new File(localFilePath);
  1419. if (targetFile.exists()){
  1420. FileUtils.deleteFile(localFilePath);
  1421. }
  1422. //从用户编辑目录中下载视频到本地
  1423. if (!StorageType.LOCAL.code().equals(this.type)) {
  1424. String filePath = userEditPath + fileName;
  1425. String imageUrl = ossUrlPrefix + filePath + "?t=" + System.currentTimeMillis();
  1426. FileUtils.downLoadFromUrl(imageUrl, fileName, localImagesPath);
  1427. }
  1428. //视频格式转换
  1429. CreateObjUtil.mp4ToFlv(localFilePath, localFilePath.replace("mp4", "flv"));
  1430. //上传
  1431. String flvFileName = fileName.replace("mp4", "flv");
  1432. // uploadToOssUtil.upload(localFilePath, userEditPath + fileName);
  1433. uploadToOssUtil.upload(localFilePath.replace("mp4", "flv"), userEditPath+flvFileName);
  1434. }
  1435. }