SceneEditInfoServiceImpl.java 81 KB

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