SceneEditInfoServiceImpl.java 83 KB

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