SceneEditInfoServiceImpl.java 66 KB

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