SceneEditInfoServiceImpl.java 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912
  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.io.FileUtil;
  5. import cn.hutool.core.util.CharsetUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import cn.hutool.core.util.ZipUtil;
  8. import com.alibaba.fastjson.JSON;
  9. import com.alibaba.fastjson.JSONArray;
  10. import com.alibaba.fastjson.JSONObject;
  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.fdkankan.common.constant.*;
  16. import com.fdkankan.common.exception.BusinessException;
  17. import com.fdkankan.common.util.FileMd5Util;
  18. import com.fdkankan.common.util.FileSizeUtil;
  19. import com.fdkankan.common.util.FileUtils;
  20. import com.fdkankan.dxf.parse.utils.FdJsonToDxfUtil;
  21. import com.fdkankan.fyun.config.FYunFileConfig;
  22. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  23. import com.fdkankan.fyun.util.OssFileUtil;
  24. import com.fdkankan.model.constants.ConstantFilePath;
  25. import com.fdkankan.model.constants.UploadFilePath;
  26. import com.fdkankan.model.utils.ComputerUtil;
  27. import com.fdkankan.model.utils.CreateHouseJsonUtil;
  28. import com.fdkankan.model.utils.CreateObjUtil;
  29. import com.fdkankan.model.utils.SceneUtil;
  30. import com.fdkankan.redis.constant.RedisKey;
  31. import com.fdkankan.redis.constant.RedisLockKey;
  32. import com.fdkankan.redis.util.RedisLockUtil;
  33. import com.fdkankan.redis.util.RedisUtil;
  34. import com.fdkankan.scene.bean.*;
  35. import com.fdkankan.scene.entity.*;
  36. import com.fdkankan.scene.mapper.ISceneEditInfoMapper;
  37. import com.fdkankan.scene.service.*;
  38. import com.fdkankan.scene.vo.*;
  39. import com.fdkankan.web.response.ResultData;
  40. import com.google.common.collect.Lists;
  41. import com.google.errorprone.annotations.Var;
  42. import lombok.extern.slf4j.Slf4j;
  43. import org.springframework.beans.factory.annotation.Autowired;
  44. import org.springframework.beans.factory.annotation.Value;
  45. import org.springframework.cloud.context.config.annotation.RefreshScope;
  46. import org.springframework.stereotype.Service;
  47. import org.springframework.transaction.annotation.Transactional;
  48. import org.springframework.web.multipart.MultipartFile;
  49. import javax.annotation.Resource;
  50. import java.io.File;
  51. import java.io.IOException;
  52. import java.nio.charset.StandardCharsets;
  53. import java.util.*;
  54. import java.util.Map.Entry;
  55. import java.util.concurrent.CompletableFuture;
  56. import java.util.concurrent.atomic.AtomicInteger;
  57. import java.util.stream.Collectors;
  58. /**
  59. * <p>
  60. * 服务实现类
  61. * </p>
  62. *
  63. * @author
  64. * @since 2022-01-18
  65. */
  66. @Slf4j
  67. @RefreshScope
  68. @Service
  69. public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper, SceneEditInfo> implements ISceneEditInfoService {
  70. @Value("${fyun.host}")
  71. private String ossUrlPrefix;
  72. @Value("${fyun.type}")
  73. private String fyunType;
  74. @Value("${ecs.checkFile.maxTimes:20}")
  75. private int maxCheckTimes;
  76. @Value("${ecs.checkFile.waitTime:1000}")
  77. private int waitTime;
  78. @Autowired
  79. private ISceneEditControlsService sceneEditControlsService;
  80. @Autowired
  81. private ISceneProService sceneProService;
  82. @Resource
  83. private FYunFileServiceInterface fYunFileService;
  84. @Autowired
  85. RedisUtil redisUtil;
  86. @Autowired
  87. private RedisLockUtil redisLockUtil;
  88. @Autowired
  89. ISceneDataDownloadService sceneDataDownloadService;
  90. @Autowired
  91. private ISceneEditInfoExtService sceneEditInfoExtService;
  92. @Autowired
  93. IScenePlusService scenePlusService;
  94. @Autowired
  95. IScenePlusExtService scenePlusExtService;
  96. @Autowired
  97. private ISceneUploadService sceneUploadService;
  98. @Autowired
  99. private ICameraDetailService cameraDetailService;
  100. @Autowired
  101. private ICompanyService companyService;
  102. @Autowired
  103. private ISurveillanceService surveillanceService;
  104. @Autowired
  105. private ISceneAsynOperLogService sceneAsynOperLogService;
  106. @Autowired
  107. private ICutModelService cutModelService;
  108. @Autowired
  109. private ICommonService commonService;
  110. @Autowired
  111. private FYunFileConfig fYunFileConfig;
  112. @Autowired
  113. private ISceneDrawService sceneDrawService;
  114. @Autowired
  115. private ISceneDynamicPanelService sceneDynamicPanelService;
  116. @Transactional
  117. @Override
  118. public SceneEditInfoVO saveScene(SceneEditInfoParamVO param) {
  119. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  120. if(Objects.isNull(scenePlus)){
  121. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  122. }
  123. SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId());
  124. SceneEditControls sceneEditControlsDb = null;
  125. if(Objects.nonNull(sceneEditInfoDb)){
  126. sceneEditControlsDb = sceneEditControlsService.getBySceneEditId(sceneEditInfoDb.getId());
  127. }
  128. //用户上传的文件后缀名转小写
  129. this.lowercaseExtName(param);
  130. SceneEditInfo sceneEditInfo = BeanUtil.copyProperties(param, SceneEditInfo.class);
  131. sceneEditInfo.setScenePlusId(scenePlus.getId());
  132. if(Objects.isNull(sceneEditInfoDb)){
  133. this.save(sceneEditInfo);
  134. }else{
  135. sceneEditInfo.setId(sceneEditInfoDb.getId());
  136. sceneEditInfo.setVersion(sceneEditInfoDb.getVersion() + 1);
  137. this.updateById(sceneEditInfo);
  138. }
  139. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  140. if(Objects.nonNull(param.getSns())){
  141. sceneEditInfoExt.setSnsInfo(JSON.toJSONString(param.getSns()));
  142. }
  143. if(Objects.nonNull(param.getStarted())){
  144. sceneEditInfoExt.setStarted(JSON.toJSONString(param.getStarted()));
  145. }
  146. // else{
  147. // sceneEditInfoExt.setStarted("");
  148. // }
  149. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  150. if(Objects.nonNull(param.getControls())){
  151. SceneEditControls sceneEditControls = BeanUtil.copyProperties(param.getControls(), SceneEditControls.class);
  152. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  153. if(Objects.isNull(sceneEditControlsDb)){
  154. sceneEditControlsService.save(sceneEditControls);
  155. }else{
  156. sceneEditControls.setId(sceneEditControlsDb.getId());
  157. sceneEditControlsService.updateById(sceneEditControls);
  158. }
  159. }
  160. SceneEditInfoVO result = BeanUtil.copyProperties(param, SceneEditInfoVO.class);
  161. result.setCreateTime(sceneEditInfo.getCreateTime());
  162. return result;
  163. }
  164. private void lowercaseExtName(SceneEditInfoParamVO sceneEditInfo){
  165. if(StrUtil.isNotEmpty(sceneEditInfo.getMusic())){
  166. String extName = cn.hutool.core.io.FileUtil.extName(sceneEditInfo.getMusic());
  167. if(StrUtil.isNotEmpty(extName)){
  168. sceneEditInfo.setMusic(sceneEditInfo.getMusic().replace(extName, extName.toLowerCase()));
  169. }
  170. }
  171. if(StrUtil.isNotEmpty(sceneEditInfo.getMusicFile())){
  172. String extName = cn.hutool.core.io.FileUtil.extName(sceneEditInfo.getMusicFile());
  173. if(StrUtil.isNotEmpty(extName)){
  174. sceneEditInfo.setMusicFile(sceneEditInfo.getMusicFile().replace(extName, extName.toLowerCase()));
  175. }
  176. }
  177. }
  178. @Override
  179. public SceneEditInfo getBySceneProId(long sceneProId) {
  180. return this.getOne(new LambdaQueryWrapper<SceneEditInfo>()
  181. .eq(SceneEditInfo::getSceneProId, sceneProId));
  182. }
  183. @Override
  184. public SceneEditInfo getByScenePlusId(long scenePlusId) {
  185. return this.getOne(new LambdaQueryWrapper<SceneEditInfo>()
  186. .eq(SceneEditInfo::getScenePlusId, scenePlusId));
  187. }
  188. @Transactional
  189. @Override
  190. public ResultData publicScene(SceneEditInfoParamVO param) throws Exception{
  191. String num = param.getNum();
  192. //根据场景码查询数据库
  193. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  194. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  195. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  196. SceneEditInfoExt sceneEditInfoExt = null;
  197. SceneEditControls sceneEditControls = null;
  198. if(sceneEditInfo == null){
  199. sceneEditInfo = new SceneEditInfo();
  200. sceneEditInfo.setSceneProId(scenePlus.getId());
  201. }else{
  202. sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  203. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  204. }
  205. if(sceneEditInfoExt == null){
  206. sceneEditInfoExt = new SceneEditInfoExt();
  207. sceneEditInfoExt.setFloorPlanAngle(0f);
  208. sceneEditInfoExt.setFloorPlanCompass(0f);
  209. }
  210. String bucket = scenePlusExt.getYunFileBucket();
  211. //生成sceneJson
  212. SceneJsonBean sceneJson = new SceneJsonBean();
  213. BeanUtil.copyProperties(sceneEditInfoExt, sceneJson, "started");
  214. BeanUtil.copyProperties(sceneEditInfo, sceneJson);
  215. sceneJson.setFloorPlanUpload(JSON.parseArray(sceneEditInfo.getFloorPlanUpload()));
  216. SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
  217. sceneJson.setControls(sceneEditControlsVO);
  218. sceneJson.setNum(num);
  219. sceneJson.setCreateTime(scenePlus.getCreateTime());
  220. sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
  221. sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
  222. sceneJson.setSceneKind(scenePlusExt.getSceneKind());
  223. sceneJson.setModelKind(scenePlusExt.getModelKind());
  224. if(StrUtil.isNotEmpty(scenePlusExt.getVideos())){
  225. sceneJson.setVideos(scenePlusExt.getVideos());
  226. }
  227. //发布马赛克列表
  228. sceneJson.setMosaicList(this.getMosaicList(num));
  229. //发布分享配置
  230. sceneJson.setSns(JSON.parseObject(sceneEditInfoExt.getSnsInfo()));
  231. //发布启动页配置
  232. sceneJson.setStarted(JSON.parseObject(sceneEditInfoExt.getStarted()));
  233. //处理热点数据,生成hot.json
  234. this.publicHotData(num, bucket);
  235. //发布场景关联相关数据
  236. this.publicLinkSceneData(num, bucket);
  237. //发布滤镜数据
  238. this.publicFilterData(num, sceneEditInfoExt.getFilters(), bucket);
  239. //发布摄像头数据
  240. this.publicSurveillance(num, sceneEditInfoExt.getSurveillances(), bucket);
  241. //发布指示牌数据
  242. this.publicBillboardData(num, bucket);
  243. //发布模型裁剪
  244. cutModelService.publicCutModel(num, bucket);
  245. //发布场景绘制
  246. sceneDrawService.publicSceneDraw(num, bucket);
  247. sceneJson.setDynamicPanel(sceneDynamicPanelService.checkDynamicPanel(num));
  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. fYunFileService.uploadFile(bucket, JSON.toJSONBytes(sceneJson), sceneJsonPath);
  254. //删除发布数据中的user目录
  255. String publicUserPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
  256. List<String> userViewFileList = fYunFileService.listRemoteFiles(bucket, publicUserPath);
  257. if(CollUtil.isNotEmpty(userViewFileList)){
  258. fYunFileService.deleteFolder(bucket, publicUserPath);
  259. }
  260. //复制编辑目录到发布目录
  261. String editPath = String.format(UploadFilePath.USER_EDIT_PATH, param.getNum());
  262. String viewPath = String.format(UploadFilePath.USER_VIEW_PATH, param.getNum());
  263. fYunFileService.copyFileBetweenBucket(bucket, editPath, bucket, viewPath);
  264. //sceneJson放入缓存
  265. String key = String.format(RedisKey.SCENE_JSON, num);
  266. redisUtil.set(key, JSON.toJSONString(sceneJson));
  267. //入库
  268. if(sceneEditInfo.getId() == null){
  269. this.save(sceneEditInfo);
  270. }else{
  271. this.updateById(sceneEditInfo);
  272. }
  273. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  274. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  275. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  276. scenePlus.setTitle(sceneEditInfo.getTitle());
  277. scenePlus.setDescription(sceneEditInfo.getDescription());
  278. scenePlus.setHouseType(this.existsHouseType(bucket, num));
  279. scenePlusService.updateById(scenePlus);
  280. return ResultData.ok();
  281. }
  282. private int existsHouseType(String bucket, String num){
  283. String houseTypePath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "houseType.json";
  284. boolean exist = fYunFileService.fileExist(bucket, houseTypePath);
  285. return exist ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue();
  286. }
  287. private void publicSurveillance(String num, Integer surveillances, String bucket) throws IOException {
  288. String surveillanceJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "surveillance.json";
  289. if(surveillances == CommonStatus.NO.code().intValue()){
  290. fYunFileService.deleteFile(bucket, surveillanceJsonPath);
  291. return;
  292. }
  293. List<SurveillanceVO> surveillanceList = surveillanceService.listSurveillance(num);
  294. fYunFileService.uploadFile(bucket, JSON.toJSONString(surveillanceList).getBytes(StandardCharsets.UTF_8), surveillanceJsonPath);
  295. }
  296. private void publicFilterData(String num, int filters, String bucket) throws IOException {
  297. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  298. if(filters == CommonStatus.NO.code()){
  299. fYunFileService.deleteFile(bucket, userEditPath + "filter.json");
  300. return;
  301. }
  302. String key = String.format(RedisKey.SCENE_filter_DATA, num);
  303. List<String> list = redisUtil.lGet(key, 0, -1);
  304. JSONArray jsonArray = new JSONArray();
  305. list.stream().forEach(str->jsonArray.add(JSON.parseObject(str)));
  306. fYunFileService.uploadFile(bucket, JSON.toJSONBytes(jsonArray), userEditPath + "filter.json");
  307. }
  308. public void publicLinkSceneData(String num, String bucket) throws IOException {
  309. String imgEditPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  310. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  311. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  312. //清除发布目录中的场景关联图片
  313. if(fYunFileService.fileExist(bucket,imgViewPath + "panorama")){
  314. fYunFileService.deleteFolder(bucket,imgViewPath + "panorama");
  315. }
  316. //生成links.json并上传到发布目录
  317. String linkPanKey = String.format(RedisKey.SCENE_LINKPAN_DATA, num);
  318. Map<String, String> linkPanMap = redisUtil.hmget(linkPanKey);
  319. if(CollUtil.isEmpty(linkPanMap)){
  320. return;
  321. }
  322. List<JSONObject> tags = Lists.newArrayList();
  323. List<TagBean> tagBeanList = new ArrayList<>();
  324. if(CollUtil.isNotEmpty(linkPanMap)){
  325. linkPanMap.entrySet().stream().forEach(entry -> {
  326. JSONObject jsonObject = JSON.parseObject(entry.getValue());
  327. tagBeanList.add(
  328. TagBean.builder()
  329. .createTime(jsonObject.getLong("createTime"))
  330. .tag(jsonObject).build());
  331. });
  332. //按创建时间倒叙排序
  333. tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
  334. //移除createTime字段
  335. tags = tagBeanList.stream().map(tagBean -> {
  336. JSONObject tag = tagBean.getTag();
  337. tag.remove("createTime");
  338. return tag;
  339. }).collect(Collectors.toList());
  340. }
  341. String linkScenePath = userEditPath + "links.json";
  342. fYunFileService.uploadFile(bucket, JSON.toJSONString(tags).getBytes(StandardCharsets.UTF_8), linkScenePath);
  343. //拷贝编辑目录到发布目录
  344. fYunFileService.copyFileBetweenBucket(bucket, imgEditPath + "panorama", bucket, imgViewPath + "panorama");
  345. }
  346. private void publicHotData(String sceneNum, String bucket) throws IOException {
  347. String hotDataKey = String.format(RedisKey.SCENE_HOT_DATA, sceneNum);
  348. Map<String, String> hotMap = redisUtil.hmget(hotDataKey);
  349. JSONArray tags = new JSONArray();
  350. if(CollUtil.isNotEmpty(hotMap)){
  351. List<TagBean> tagBeanList = hotMap.entrySet().stream().map(entry -> {
  352. JSONObject jsonObject = JSON.parseObject(entry.getValue());
  353. return TagBean.builder()
  354. .createTime(jsonObject.getLong("createTime"))
  355. .tag(jsonObject).build();
  356. }).collect(Collectors.toList());
  357. //按创建时间倒叙排序
  358. tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
  359. //移除createTime字段
  360. tagBeanList.stream().forEach(tagBean -> {
  361. tags.add(tagBean.getTag());
  362. });
  363. }
  364. String hotJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, sceneNum) + "hot.json";
  365. fYunFileService.uploadFile(bucket, tags.toString().getBytes(), hotJsonPath);
  366. // this.saveTagsToSceneEditInfo(sceneNum, sceneEditInfo);
  367. }
  368. private void publicBillboardData(String sceneNum, String bucket) throws IOException {
  369. String Key = String.format(RedisKey.SCENE_BILLBOARDS, sceneNum);
  370. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, sceneNum) + "billboards.json";
  371. List<String> list = redisUtil.hgetValues(Key);
  372. if(CollUtil.isEmpty(list)){
  373. fYunFileService.deleteFile(bucket, userEditPath);
  374. return;
  375. }
  376. List<JSONObject> collect = list.stream().map(str -> JSON.parseObject(str)).collect(Collectors.toList());
  377. fYunFileService.uploadFile(bucket, JSON.toJSONString(collect).getBytes(), userEditPath);
  378. }
  379. @Override
  380. public SceneInfoVO getSceneInfo(@Var SceneInfoParamVO param) throws Exception{
  381. SceneInfoReqType sceneInfoReqType = SceneInfoReqType.get(param.getReqType());
  382. switch (sceneInfoReqType){
  383. //如果是编辑页面请求,查数据库
  384. case EDIT:
  385. return this.getSceneInfo4Edit(param.getNum());
  386. //如果是查看页面请求,查redis
  387. case VIEW:
  388. return this.getSceneInfo4View(param.getNum());
  389. }
  390. return null;
  391. }
  392. /**
  393. * <p>
  394. 编辑页面获取场景详情信息
  395. * </p>
  396. * @author dengsixing
  397. * @date 2022/1/21
  398. * @param num
  399. * @return com.fdkankan.scene.vo.SceneInfoVO
  400. **/
  401. private SceneInfoVO getSceneInfo4Edit(String num) throws Exception{
  402. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  403. if(Objects.isNull(scenePlus)){
  404. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  405. }
  406. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  407. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  408. if(Objects.isNull(sceneEditInfo)){
  409. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  410. }
  411. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  412. SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  413. SceneInfoVO sceneInfoVO = new SceneInfoVO();
  414. BeanUtil.copyProperties(sceneEditInfoExt, sceneInfoVO, "started");
  415. BeanUtil.copyProperties(sceneEditInfo, sceneInfoVO);
  416. sceneInfoVO.setFloorPlanUpload(JSON.parseArray(sceneEditInfo.getFloorPlanUpload()));
  417. if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){
  418. sceneInfoVO.setFloorPlanAngle(0f);
  419. }
  420. if(Objects.isNull(sceneInfoVO.getFloorPlanCompass())){
  421. sceneInfoVO.setFloorPlanCompass(0f);
  422. }
  423. sceneInfoVO.setControls(BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class));
  424. sceneInfoVO.setNum(num);
  425. sceneInfoVO.setCreateTime(scenePlusExt.getAlgorithmTime());
  426. sceneInfoVO.setSceneResolution(scenePlusExt.getSceneResolution());
  427. sceneInfoVO.setSceneFrom(scenePlusExt.getSceneFrom());
  428. sceneInfoVO.setSceneKind(scenePlusExt.getSceneKind());
  429. sceneInfoVO.setModelKind(scenePlusExt.getModelKind());
  430. sceneInfoVO.setVideos(scenePlusExt.getVideos());
  431. if(CommonStatus.YES.code().intValue() == sceneEditInfoExt.getMosaic()){
  432. sceneInfoVO.setMosaicList(this.getMosaicList(num));
  433. }
  434. sceneInfoVO.setSpace(FileSizeUtil.convert(scenePlusExt.getSpace(), FileSizeUnitType.MB.code()));
  435. sceneInfoVO.setSns(JSON.parseObject(sceneEditInfoExt.getSnsInfo()));
  436. sceneInfoVO.setStarted(JSON.parseObject(sceneEditInfoExt.getStarted()));
  437. this.SortBoxVideos(sceneInfoVO);
  438. this.setExtData(sceneInfoVO, scenePlus.getCameraId());
  439. //随心装特殊要求,由于随心装场景无法提供vision2.txt,故默认随心装场景关闭标尺功能
  440. if(SceneFrom.SXZ.code().equals(scenePlusExt.getSceneFrom())){
  441. sceneInfoVO.getControls().setShowRule(CommonStatus.NO.code().intValue());
  442. }
  443. sceneInfoVO.setDynamicPanel(sceneDynamicPanelService.checkDynamicPanel(num));
  444. return sceneInfoVO;
  445. }
  446. public static void main(String[] args) {
  447. String test = "";
  448. // JSONObject jsonObject = JSON.parseObject(test);
  449. System.out.println(JSON.toJSONString(test));
  450. }
  451. private void SortBoxVideos(SceneInfoVO sceneInfoVO){
  452. String boxVideos = sceneInfoVO.getBoxVideos();
  453. if(StrUtil.isEmpty(boxVideos)){
  454. return;
  455. }
  456. JSONArray boxVideoArr = JSON.parseArray(boxVideos);
  457. if(CollUtil.isEmpty(boxVideoArr)){
  458. return;
  459. }
  460. List<TagBean> tagBeanList = boxVideoArr.stream().map(o -> {
  461. JSONObject item = (JSONObject) o;
  462. return TagBean.builder()
  463. .createTime(item.getLong("createTime"))
  464. .tag(item).build();
  465. }).collect(Collectors.toList());
  466. //按创建时间倒叙排序
  467. tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
  468. //移除createTime字段
  469. List<JSONObject> boxVideoList = tagBeanList.stream().map(tagBean -> {
  470. JSONObject tag = tagBean.getTag();
  471. tag.remove("createTime");
  472. return tag;
  473. }).collect(Collectors.toList());
  474. sceneInfoVO.setBoxVideos(JSON.toJSONString(boxVideoList));
  475. }
  476. /**
  477. * <p>
  478. getInfo接口返回字段扩展
  479. * </p>
  480. * @author dengsixing
  481. * @date 2022/3/9
  482. **/
  483. private void setExtData(SceneInfoVO sceneInfoVO, Long cameraId) throws Exception{
  484. if(Objects.isNull(cameraId)){
  485. return;
  486. }
  487. CameraDetail cameraDetail = cameraDetailService.findByCameraId(cameraId);
  488. if(Objects.isNull(cameraDetail)){
  489. throw new BusinessException(ErrorCode.FAILURE_CODE_7010);
  490. }
  491. if(Objects.isNull(cameraDetail.getCompanyId())){
  492. return;
  493. }
  494. Company company = companyService.getById(cameraDetail.getCompanyId());
  495. if(Objects.isNull(company)){
  496. return;
  497. }
  498. sceneInfoVO.setDataSync(company.getDataSync());
  499. }
  500. /**
  501. * <p>
  502. 查看页面获取场景详情信息
  503. * </p>
  504. * @author dengsixing
  505. * @date 2022/1/21
  506. * @param num
  507. * @return com.fdkankan.scene.vo.SceneInfoVO
  508. **/
  509. private SceneInfoVO getSceneInfo4View(String num) throws Exception{
  510. //校验场景是否为空、封存、计算中
  511. ScenePlus scenePlus = scenePlusService.checkSceneAvail(num);
  512. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  513. //访问量+1
  514. scenePlusService.updateViewCount(num);
  515. String key = String.format(RedisKey.SCENE_JSON, num);
  516. String sceneJson = redisUtil.get(key);
  517. SceneInfoVO sceneInfoVO = null;
  518. //先查询redis
  519. if(StrUtil.isEmpty(sceneJson)) {
  520. String objectName = String.format(ConstantFilePath.SCENE_VIEW_DATA_DATA_SCENEJSON, num);
  521. sceneJson = fYunFileService.getFileContent(scenePlusExt.getYunFileBucket(), objectName);
  522. redisUtil.set(key, sceneJson);
  523. }
  524. sceneInfoVO = JSON.parseObject(sceneJson, SceneInfoVO.class);
  525. sceneInfoVO.setScenePassword(null);
  526. if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){
  527. sceneInfoVO.setFloorPlanAngle(0f);
  528. }
  529. if(Objects.isNull(sceneInfoVO.getFloorPlanCompass())){
  530. sceneInfoVO.setFloorPlanCompass(0f);
  531. }
  532. SceneEditControlsVO controls = sceneInfoVO.getControls();
  533. if(Objects.isNull(controls.getShowShare())){
  534. controls.setShowShare(CommonStatus.YES.code().intValue());
  535. }
  536. if(Objects.isNull(controls.getShowCapture())){
  537. controls.setShowCapture(CommonStatus.YES.code().intValue());
  538. }
  539. if(Objects.isNull(controls.getShowBillboardTitle())){
  540. controls.setShowBillboardTitle(CommonStatus.YES.code().intValue());
  541. }
  542. if(Objects.isNull(controls.getShowDrawTitle())){
  543. controls.setShowDrawTitle(CommonStatus.YES.code().intValue());
  544. }
  545. //随心装特殊要求,由于随心装场景无法提供vision2.txt,故默认随心装场景关闭标尺功能
  546. if(SceneFrom.SXZ.code().equals(scenePlusExt.getSceneFrom())){
  547. controls.setShowRule(CommonStatus.NO.code().intValue());
  548. }
  549. return sceneInfoVO;
  550. }
  551. @Override
  552. public ResultData saveCad(BaseDataParamVO param) throws Exception {
  553. String num = param.getNum();
  554. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  555. if(Objects.isNull(scenePlus))
  556. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  557. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  558. String bucket = scenePlusExt.getYunFileBucket();
  559. String editUserPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  560. String localDataPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  561. JSONObject fileInfoJson = JSON.parseObject(param.getData());
  562. Float angel = null;
  563. Float compass = null;
  564. String floorJsonData = fileInfoJson.getString("floorJsonData");
  565. if(StrUtil.isNotBlank(floorJsonData)){
  566. JSONObject jsonObject = JSON.parseObject(floorJsonData);
  567. angel = jsonObject.getFloat("angle");
  568. compass = jsonObject.getFloat("compass");
  569. }
  570. //处理户型图数据
  571. //上传floorplan_user.json文件
  572. FileUtils.writeFile(localDataPath + "floorplan_user.json", floorJsonData);
  573. fYunFileService.uploadFile(bucket, localDataPath + "floorplan_user.json", editUserPath + "floorplan.json");
  574. //写入数据库
  575. Byte floorPlanUser = null;
  576. if(StrUtil.isNotEmpty(floorJsonData)){
  577. JSONObject houseTypeJson = CreateHouseJsonUtil
  578. .createHouseTypeJsonByUser(localDataPath + "floorplan_user.json");
  579. if(Objects.nonNull(houseTypeJson)) {
  580. fYunFileService.uploadFile(bucket, houseTypeJson.toJSONString().getBytes(), editUserPath + "houseType.json");
  581. }
  582. floorPlanUser = CommonStatus.YES.code();
  583. }
  584. SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId());
  585. if(Objects.nonNull(sceneEditInfoDb)){
  586. LambdaUpdateWrapper<SceneEditInfo> updateWrapper = new LambdaUpdateWrapper<SceneEditInfo>()
  587. .setSql("version=version+" + 1)
  588. .eq(SceneEditInfo::getId, sceneEditInfoDb.getId());
  589. if(floorPlanUser != null){
  590. updateWrapper.set(SceneEditInfo::getFloorPlanUser, floorPlanUser);
  591. }
  592. this.update(updateWrapper);
  593. }else{
  594. sceneEditInfoDb = new SceneEditInfo();
  595. sceneEditInfoDb.setScenePlusId(scenePlus.getId());
  596. sceneEditInfoDb.setFloorPlanUser(floorPlanUser);
  597. this.save(sceneEditInfoDb);
  598. }
  599. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoDb.getId());
  600. if(Objects.isNull(sceneEditInfoExt)){
  601. sceneEditInfoExt = new SceneEditInfoExt();
  602. sceneEditInfoExt.setEditInfoId(sceneEditInfoDb.getId());
  603. }
  604. if(Objects.nonNull(angel)){
  605. sceneEditInfoExt.setFloorPlanAngle(angel);
  606. }
  607. if(Objects.nonNull(compass)){
  608. sceneEditInfoExt.setFloorPlanCompass(compass);
  609. }
  610. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  611. return ResultData.ok();
  612. }
  613. @Override
  614. public ResultData uploadDxf(MultipartFile file, String num) throws Exception {
  615. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  616. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  617. String extName = FileUtil.extName(file.getOriginalFilename());
  618. if(!"dxf".equals(extName)){
  619. throw new BusinessException(ErrorCode.FAILURE_CODE_7007.code(), ErrorCode.FAILURE_CODE_7007.formatMessage("dxf"));
  620. }
  621. String dfxPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + UUID.randomUUID() + "." + extName;
  622. String floorplanUserPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + UUID.randomUUID() + ".json";
  623. file.transferTo(new File(dfxPath));
  624. try {
  625. String editUserPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  626. FdJsonToDxfUtil.dxfToFdJson(dfxPath, floorplanUserPath);
  627. fYunFileService.uploadFile(scenePlusExt.getYunFileBucket(), floorplanUserPath, editUserPath + "floorplan.json");
  628. JSONObject houseTypeJson = CreateHouseJsonUtil
  629. .createHouseTypeJsonByUser(floorplanUserPath);
  630. if(Objects.nonNull(houseTypeJson)) {
  631. fYunFileService.uploadFile(scenePlusExt.getYunFileBucket(), houseTypeJson.toJSONString().getBytes(), editUserPath + "houseType.json");
  632. }
  633. SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId());
  634. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  635. .setSql("version=version+" + 1)
  636. .set(SceneEditInfo::getFloorPlanUser, 1)
  637. .eq(SceneEditInfo::getId, sceneEditInfoDb.getId()));
  638. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoDb.getId());
  639. sceneEditInfoExt.setFloorPlanAngle(0f);
  640. sceneEditInfoExt.setFloorPlanCompass(0f);
  641. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  642. }catch (Exception e){
  643. log.error("cad文件转换失败");
  644. ResultData.error(ErrorCode.FAILURE_CODE_7013);
  645. }finally {
  646. FileUtil.del(dfxPath);
  647. FileUtil.del(floorplanUserPath);
  648. }
  649. return ResultData.ok();
  650. }
  651. @Override
  652. public ResultData downloadDxf(String num) throws Exception {
  653. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  654. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  655. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  656. if(Objects.isNull(sceneEditInfo.getFloorPlanUser()) || sceneEditInfo.getFloorPlanUser() == CommonStatus.NO.code()){
  657. return ResultData.ok();
  658. }
  659. String localFloorplan = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + UUID.randomUUID() + ".json";
  660. fYunFileService.downloadFile(scenePlusExt.getYunFileBucket(),
  661. String.format(UploadFilePath.USER_EDIT_PATH, num) + "floorplan.json", localFloorplan);
  662. String localDxf = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + UUID.randomUUID() + ".dxf";
  663. FdJsonToDxfUtil.fdJsonToDxf(localFloorplan, localDxf);
  664. String key = OssFileUtil.getUploadTempFileKey(null, "dxf");
  665. fYunFileService.uploadFile(scenePlusExt.getYunFileBucket(), localDxf, key);
  666. String url = fYunFileConfig.getHost() + key;
  667. return ResultData.ok(url);
  668. }
  669. @Override
  670. public ResultData resetCad(String num) throws IOException {
  671. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  672. if(Objects.isNull(scenePlus))
  673. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  674. ScenePlusExt scenePlusExt = scenePlusExtService
  675. .getScenePlusExtByPlusId(scenePlus.getId());
  676. String bucket = scenePlusExt.getYunFileBucket();
  677. String path = scenePlusExt.getDataSource();
  678. //户型图上传 恢复默认并发布同时点击刷新查看页面,平面图会变形,所以这里先注释掉 bug-36281 2023-05-04
  679. // String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num);
  680. // String floorplanCadPath = ossResultPath + "floorplan_cad/";
  681. // fYunFileService.copyFileBetweenBucket(bucket, floorplanCadPath, bucket, String.format(UploadFilePath.USER_EDIT_PATH, num));
  682. // String userEditPath = UploadFilePath.USER_EDIT_PATH + "floor-cad-%s.%s";
  683. // String floorCadPath = path + "/results/floorplan_cad";
  684. // List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  685. // if(CollUtil.isNotEmpty(floorCadList)){
  686. // floorCadList.stream().forEach(str->{
  687. // String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  688. // String[] arr = substring.split("floor");
  689. // String[] arr2 = arr[1].split("\\.");
  690. // fYunFileService.uploadFile(bucket, str, String.format(userEditPath, num, arr2[0], arr2[1]));
  691. // });
  692. // }
  693. //根据floorplan_cad.json生成houseType.json
  694. this.uploadHouseTypeJson(num, bucket);
  695. SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId());
  696. SceneEditInfoExt sceneEditInfoExt = null;
  697. if(Objects.nonNull(sceneEditInfoDb)){
  698. LambdaUpdateWrapper<SceneEditInfo> updateWrapper = new LambdaUpdateWrapper<SceneEditInfo>()
  699. .setSql("version=version+" + 1)
  700. .set(SceneEditInfo::getFloorPlanUser, CommonStatus.NO.code())
  701. .eq(SceneEditInfo::getId, sceneEditInfoDb.getId());
  702. this.update(updateWrapper);
  703. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoDb.getId());
  704. }else{
  705. sceneEditInfoDb = new SceneEditInfo();
  706. sceneEditInfoDb.setScenePlusId(scenePlus.getId());
  707. sceneEditInfoDb.setFloorPlanUser(CommonStatus.NO.code());
  708. this.save(sceneEditInfoDb);
  709. }
  710. if(Objects.isNull(sceneEditInfoExt)){
  711. sceneEditInfoExt = new SceneEditInfoExt();
  712. sceneEditInfoDb.setScenePlusId(scenePlus.getId());
  713. sceneEditInfoExt.setEditInfoId(sceneEditInfoDb.getId());
  714. }
  715. sceneEditInfoExt.setFloorPlanAngle(0f);
  716. sceneEditInfoExt.setFloorPlanCompass(0f);
  717. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  718. return ResultData.ok();
  719. }
  720. private void uploadHouseTypeJson(String num, String bucket) throws IOException {
  721. JSONObject result = new JSONObject();
  722. result.put("name", "houseType.json");
  723. result.put("version", "2.1");
  724. String floorplanCadPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "floorplan_cad.json";
  725. if(!fYunFileService.fileExist(bucket, floorplanCadPath)){
  726. log.warn("生成houseType.json失败,原因:floorplan_cad.json文件不存在,num:{}", num);
  727. return;
  728. }
  729. String floorcadStr = fYunFileService.getFileContent(bucket, floorplanCadPath);
  730. JSONObject floorcadObj = JSON.parseObject(floorcadStr);
  731. JSONArray floors = floorcadObj.getJSONArray("floors");
  732. JSONArray targetFloors = new JSONArray();
  733. result.put("floors", targetFloors);
  734. for(int i = 0; i < floors.size(); i++){
  735. JSONObject floor = (JSONObject)floors.get(i);
  736. JSONArray[] pointsAndWalls = this.createHouseTypeJsonHandler(floor);
  737. JSONArray points = pointsAndWalls[0];
  738. JSONArray walls = pointsAndWalls[1];
  739. JSONObject targetFloor = new JSONObject();
  740. targetFloor.put("points", points);
  741. targetFloor.put("walls", walls);
  742. targetFloors.add(targetFloor);
  743. }
  744. String hourseTypeJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "houseType.json";
  745. fYunFileService.uploadFile(bucket, result.toJSONString().getBytes(), hourseTypeJsonPath);
  746. }
  747. private JSONArray[] createHouseTypeJsonHandler(JSONObject floor){
  748. JSONArray[] result = new JSONArray[2];
  749. //处理点
  750. Map<Integer, VertexBean> vertexMap = new HashMap<>();
  751. Map<String, PointBean> pointMap = new HashMap<>();
  752. Map<Integer, String> vpMap = new HashMap<>();
  753. JSONArray vertexArr = floor.getJSONArray("vertex-xy");
  754. for(int i = 0; i < vertexArr.size(); i++){
  755. Object o = vertexArr.get(i);
  756. VertexBean vertexBean = JSON.parseObject(JSON.toJSONString(o), VertexBean.class);
  757. Integer vertexId = vertexBean.getId();
  758. vertexMap.put(vertexId, vertexBean);
  759. String pointId = "Point" + i;
  760. pointMap.put(pointId, PointBean.builder().vectorId(pointId).x(vertexBean.getX()).y(vertexBean.getY()).build());
  761. vpMap.put(vertexId, pointId);
  762. }
  763. //处理墙
  764. Map<Integer, SegmentBean> segmentMap = new HashMap<>();
  765. Map<String, WallBean> wallMap = new HashMap<>();
  766. Map<Integer, String> swMap = new HashMap<>();
  767. JSONArray segmentArr = floor.getJSONArray("segment");
  768. Map<String, String> startMap = new HashMap<>();
  769. Map<String, String> endMap = new HashMap<>();
  770. for(int i = 0; i < segmentArr.size(); i++){
  771. Object o = segmentArr.get(i);
  772. SegmentBean segmentBean = JSON.parseObject(JSON.toJSONString(o), SegmentBean.class);
  773. String startPointId = vpMap.get(segmentBean.getA());
  774. String endPointId = vpMap.get(segmentBean.getB());
  775. segmentBean.setStartPointId(startPointId);
  776. segmentBean.setEndPointId(endPointId);
  777. Integer segmentId = segmentBean.getId();
  778. segmentMap.put(segmentId, segmentBean);
  779. String wallId = "Wall" + i;
  780. WallBean wallBean = WallBean.builder()
  781. .vectorId(wallId)
  782. .start(segmentBean.getStartPointId())
  783. .end(segmentBean.getEndPointId())
  784. .children(new String[]{})
  785. .width(0.2d)
  786. .build();
  787. wallMap.put(wallId, wallBean);
  788. startMap.put(wallBean.getStart(), wallBean.getVectorId());
  789. endMap.put(wallBean.getEnd(), wallBean.getVectorId());
  790. swMap.put(segmentId, wallId);
  791. }
  792. Collection<PointBean> pointBeans = pointMap.values();
  793. for (PointBean pointBean : pointBeans) {
  794. Map<String, String> parent = new HashMap<>();
  795. String startParent = startMap.get(pointBean.getVectorId());
  796. String endParent = endMap.get(pointBean.getVectorId());
  797. parent.put(startParent, "start");
  798. parent.put(endParent, "end");
  799. pointBean.setParent(parent);
  800. }
  801. JSONArray pointArr = JSON.parseArray(JSON.toJSONString(pointBeans));
  802. result[0] = pointArr;
  803. Collection<WallBean> wallBeans = wallMap.values();
  804. JSONArray wallArr = JSON.parseArray(JSON.toJSONString(wallBeans));
  805. result[1] = wallArr;
  806. return result;
  807. }
  808. @Override
  809. public ResultData renameCad(RenameCadParamVO param) throws IOException {
  810. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  811. if(Objects.isNull(scenePlus)){
  812. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  813. }
  814. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  815. String bucket = scenePlusExt.getYunFileBucket();
  816. String key = String.format(UploadFilePath.USER_EDIT_PATH, param.getNum()) + "floorplan.json";
  817. String floorplanJson = fYunFileService.getFileContent(bucket, key);
  818. if(StrUtil.isEmpty(floorplanJson)){
  819. return ResultData.ok();
  820. }
  821. Map<Integer, String> renameMap = new HashMap<>();
  822. param.getFloors().stream().forEach(floor->{
  823. renameMap.put(floor.getSubgroup(), floor.getName());
  824. });
  825. JSONObject jsonObject = JSON.parseObject(floorplanJson);
  826. if(Objects.isNull(jsonObject)){
  827. return ResultData.ok();
  828. }
  829. JSONArray floorArr = jsonObject.getJSONArray("floors");
  830. if(CollUtil.isEmpty(floorArr)){
  831. return ResultData.ok();
  832. }
  833. for (Object o : floorArr) {
  834. JSONObject item = (JSONObject)o;
  835. int subgroup = item.getIntValue("subgroup");
  836. String name = renameMap.get(subgroup);
  837. if(StrUtil.isEmpty(name)){
  838. continue;
  839. }
  840. item.put("name", name);
  841. }
  842. fYunFileService.uploadFile(bucket, jsonObject.toJSONString().getBytes(), key);
  843. return ResultData.ok();
  844. }
  845. private JSONObject updateFloorName(String sourceFloors, String targeFloors){
  846. JSONArray sourceFloorsJson = JSON.parseArray(sourceFloors);
  847. JSONObject targeFloorsJson = JSONObject.parseObject(targeFloors);
  848. JSONArray array = targeFloorsJson.getJSONArray("floors");
  849. for (int i = 0; i < array.size(); ++i) {
  850. JSONObject targetFloor = array.getJSONObject(i);
  851. int targetId = targetFloor.getIntValue("id");
  852. for (int j = 0; j < sourceFloorsJson.size(); ++j) {
  853. JSONObject floor = sourceFloorsJson.getJSONObject(j);
  854. int id = floor.getIntValue("id");
  855. String name = floor.getString("name");
  856. if (targetId != id)
  857. continue;
  858. targetFloor.put("name", name);
  859. }
  860. }
  861. return targeFloorsJson;
  862. }
  863. @Override
  864. public void upgradeVersionById(Long id) {
  865. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  866. .setSql("version=version+" + 1)
  867. .eq(SceneEditInfo::getId, id));
  868. }
  869. @Override
  870. public void upgradeVersionAndImgVersionById(Long id) {
  871. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  872. .setSql("version=version + " + 1)
  873. .setSql("img_version=img_version + " + 1)
  874. .eq(SceneEditInfo::getId, id));
  875. }
  876. @Override
  877. public void upgradeSceneJsonVersion(String num, int version, Integer imgVersion, String bucket) throws IOException {
  878. //更新redis缓存版本号
  879. String key = String.format(RedisKey.SCENE_JSON, num);
  880. String sceneJson = redisUtil.get(key);
  881. if(StrUtil.isNotEmpty(sceneJson)){
  882. SceneJsonBean sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
  883. if(Objects.nonNull(version)){
  884. sceneJsonBean.setVersion(version);
  885. }
  886. if(Objects.nonNull(imgVersion)){
  887. sceneJsonBean.setImgVersion(imgVersion);
  888. }
  889. redisUtil.set(key, JSON.toJSONString(sceneJsonBean));
  890. }
  891. //更新oss scene.json版本号
  892. String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
  893. sceneJson= fYunFileService.getFileContent(bucket, sceneJsonPath);
  894. if(StrUtil.isNotEmpty(sceneJson)){
  895. SceneJsonBean sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
  896. if(Objects.nonNull(version)){
  897. sceneJsonBean.setVersion(version);
  898. }
  899. if(Objects.nonNull(imgVersion)){
  900. sceneJsonBean.setImgVersion(imgVersion);
  901. }
  902. fYunFileService.uploadFile(bucket, JSON.toJSONString(sceneJsonBean).getBytes(StandardCharsets.UTF_8), sceneJsonPath);
  903. }
  904. }
  905. @Override
  906. public ResultData uploadPanorama(String num, MultipartFile file) throws Exception {
  907. if(!file.getOriginalFilename().endsWith(".zip") && !file.getOriginalFilename().endsWith(".jpg")){
  908. throw new BusinessException(ErrorCode.FAILURE_CODE_7007, "jpg或者zip");
  909. }
  910. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  911. if(scenePlus == null){
  912. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  913. }
  914. //查询是否存在等待中的异步操作记录,如果存在,抛出业务异常,终止操作
  915. sceneAsynOperLogService.checkSceneAsynOper(num, null, SceneAsynModuleType.UPLOAD_DOWNLOAD.code() , SceneAsynFuncType.PANORAMIC_IMAGE.code());
  916. //清除全景图异步操作记录,防止再次下载的时候请求到旧的压缩包
  917. sceneAsynOperLogService.cleanLog(num, SceneAsynModuleType.UPLOAD_DOWNLOAD.code(), SceneAsynFuncType.PANORAMIC_IMAGE.code());
  918. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  919. String bucket = scenePlusExt.getYunFileBucket();
  920. //原始计算根目录
  921. // String path = "F:\\test";
  922. String path = scenePlusExt.getDataSource();
  923. //全景图计算根目录
  924. String target = path + "_images";
  925. //解压缩文件存放目录
  926. String targetImagesPath = target + "/extras/images/";
  927. //压缩文件保存目录
  928. String zipTargetFilePath = targetImagesPath + file.getOriginalFilename();
  929. //判断全景图缓存是否存在,如果不存在,从计算目录中拷贝到缓存目录
  930. // this.cachePanorama(path, num);
  931. //先删除本地文件
  932. FileUtils.deleteDirectory(targetImagesPath);
  933. File targetFile = new File(zipTargetFilePath);
  934. if(!targetFile.getParentFile().exists()){
  935. targetFile.getParentFile().mkdirs();
  936. }
  937. file.transferTo(targetFile);
  938. //如果是压缩包上传,需要解压缩
  939. int async = CommonStatus.NO.code();
  940. if(file.getOriginalFilename().endsWith(".zip")){
  941. //标记为异步处理
  942. async = CommonStatus.YES.code();
  943. //解压zip包
  944. ZipUtil.unzip(zipTargetFilePath,targetImagesPath, CharsetUtil.CHARSET_GBK);
  945. //删除压缩包
  946. FileUtils.delFile(zipTargetFilePath);
  947. }
  948. //判断文件夹目录结构,图片必须放在压缩包根目录下,不支持空文件夹或其他格式文件上传
  949. File[] files = new File(targetImagesPath).listFiles();
  950. Arrays.stream(files).forEach(item->{
  951. if(item.isDirectory()){
  952. throw new BusinessException(ErrorCode.FAILURE_CODE_7018);
  953. }
  954. });
  955. //获取解压后的文件列表
  956. List<String> uploadFileList = FileUtils.getFileList(targetImagesPath);
  957. if(CollUtil.isEmpty(uploadFileList)){
  958. throw new BusinessException(ErrorCode.FAILURE_CODE_5062);
  959. }
  960. //判断是否有可用的jpg文件
  961. boolean existJpg = false;
  962. if(CollUtil.isNotEmpty(uploadFileList)){
  963. existJpg = uploadFileList.stream().anyMatch(str -> {
  964. if(str.endsWith(".jpg")){
  965. return true;
  966. }
  967. return false;
  968. });
  969. }
  970. if(!existJpg){
  971. throw new BusinessException(ErrorCode.FAILURE_CODE_5062);
  972. }
  973. //比对图片列表,不存在的要返回名称集合
  974. String ossVisionPath = String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt";
  975. String visionPath = String.format(ConstantFilePath.SCENE_DATA_PATH_V4, num) + "vision.txt";
  976. fYunFileService.downloadFile(ossVisionPath, visionPath);
  977. List<String> panoramaImageList = SceneUtil.getPanoramaImageList(visionPath);
  978. List<String> notExistFileList = uploadFileList.stream().filter(filePath -> {
  979. filePath = filePath.substring(filePath.lastIndexOf(File.separator) + 1);
  980. if(CollUtil.isEmpty(panoramaImageList) || panoramaImageList.contains(filePath)){
  981. return false;
  982. }
  983. return true;
  984. }).collect(Collectors.toList());
  985. if(CollUtil.isNotEmpty(notExistFileList)){
  986. //删除错误文件
  987. notExistFileList.parallelStream().forEach(filePath->{
  988. FileUtils.deleteFile(filePath);
  989. });
  990. }
  991. //判断成功的图片,如果成功图片为0,就直接返回,不需要执行算法
  992. uploadFileList = FileUtils.getFileList(targetImagesPath);
  993. if(CollUtil.isEmpty(uploadFileList)){
  994. if(CollUtil.isNotEmpty(notExistFileList)){
  995. notExistFileList = notExistFileList.stream().map(filePath -> {
  996. return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
  997. }).collect(Collectors.toList());
  998. }
  999. return ResultData.ok(new UploadPanoramaVO(0,0, notExistFileList));
  1000. }
  1001. //上传
  1002. Map<String, String> map = new HashMap<>();
  1003. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  1004. fYunFileService.downloadFile(bucket, imgViewPath + "vision.modeldata", target + File.separator + "extras" + File.separator + "vision.modeldata");
  1005. CreateObjUtil.convertVisionmodeldataToTxt(target + File.separator + "extras" + File.separator + "vision.modeldata",
  1006. target + File.separator + "extras" + File.separator + "vision.txt");
  1007. String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num);
  1008. fYunFileService.downloadFile(bucket, ossResultPath + "data.json", target + File.separator+"data.json");
  1009. fYunFileService.downloadFile(bucket, ossResultPath + "project.json", target + File.separator+"project.json");
  1010. //data.json增加extras为执行重建算法
  1011. String data = FileUtils.readFile(target + File.separator+"data.json");
  1012. if(data != null){
  1013. JSONObject floorplanJson = new JSONObject();
  1014. floorplanJson.put("has_source_images", true);
  1015. floorplanJson.put("has_vision_txt", true);
  1016. JSONObject dataJson = JSONObject.parseObject(data);
  1017. dataJson.put("extras", floorplanJson);
  1018. dataJson.put("split_type", "SPLIT_V8");
  1019. //V5表示不需要生成high,low文件
  1020. String skyboxType = "SKYBOX_V6";
  1021. if(scenePlusExt.getSceneScheme() == 11){
  1022. skyboxType = "SKYBOX_V7";
  1023. }
  1024. //sceneScheme为3切成瓦片图
  1025. if(scenePlusExt.getSceneScheme() == 3){
  1026. if("4k".equals(scenePlusExt.getSceneResolution())){
  1027. skyboxType = "SKYBOX_V14";
  1028. }else{
  1029. skyboxType = "SKYBOX_V13";
  1030. }
  1031. }
  1032. dataJson.put("skybox_type", skyboxType);
  1033. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  1034. }
  1035. if(new File(target + File.separator + "capture").exists()){
  1036. new File(target + File.separator + "capture").delete();
  1037. }
  1038. if(new File(target + File.separator + "results").exists()){
  1039. FileUtils.delAllFile(target + File.separator + "results");
  1040. }
  1041. fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", target + File.separator + "capture/data.fdage");
  1042. //如果部分成功,则需要返回成功数量和失败列表
  1043. if(CollUtil.isNotEmpty(notExistFileList)){
  1044. notExistFileList = notExistFileList.stream().map(filePath -> {
  1045. return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
  1046. }).collect(Collectors.toList());
  1047. }
  1048. UploadPanoramaVO uploadPanoramaVO = new UploadPanoramaVO();
  1049. uploadPanoramaVO.setAsyn(async);
  1050. if(async == CommonStatus.YES.code().intValue()){
  1051. List<String> finalUploadFileList = uploadFileList;
  1052. List<String> finalNotExistFileList = notExistFileList;
  1053. CompletableFuture.runAsync(() -> {
  1054. SceneAsynOperLog sceneAsynOperLog = new SceneAsynOperLog();
  1055. sceneAsynOperLog.setNum(num);
  1056. sceneAsynOperLog.setOperType(SceneAsynOperType.UPLOAD.code());
  1057. sceneAsynOperLog.setModule(SceneAsynModuleType.UPLOAD_DOWNLOAD.code());
  1058. sceneAsynOperLog.setFunc(SceneAsynFuncType.PANORAMIC_IMAGE.code());
  1059. if(CollUtil.isNotEmpty(finalNotExistFileList)){
  1060. Map<String, Object> extData = new HashMap<>();
  1061. extData.put("successCnt", finalUploadFileList.size());
  1062. extData.put("failList", finalNotExistFileList);
  1063. sceneAsynOperLog.setExtData(JSON.toJSONString(extData));
  1064. }
  1065. sceneAsynOperLogService.save(sceneAsynOperLog);
  1066. try {
  1067. this.uploadPanoramaHandler(num,bucket,target,imgViewPath, finalUploadFileList,targetImagesPath);
  1068. sceneAsynOperLog.setState(CommonOperStatus.SUCCESS.code());
  1069. } catch (Exception e) {
  1070. log.error("上传全景图报错,num:" + num, e);
  1071. sceneAsynOperLog.setState(CommonOperStatus.FAILD.code());
  1072. }
  1073. sceneAsynOperLogService.updateById(sceneAsynOperLog);
  1074. });
  1075. }else{
  1076. this.uploadPanoramaHandler(num,bucket,target,imgViewPath,uploadFileList,targetImagesPath);
  1077. if(CollUtil.isNotEmpty(notExistFileList)){
  1078. uploadPanoramaVO.setSuccessCnt(uploadFileList.size());
  1079. uploadPanoramaVO.setFailList(notExistFileList);
  1080. }
  1081. }
  1082. return ResultData.ok(uploadPanoramaVO);
  1083. }
  1084. public void uploadPanoramaHandler(String num, String bucket, String target, String imgViewPath, List<String> uploadFileList, String targetImagesPath) throws Exception {
  1085. CreateObjUtil.build3dModel(target , "1");
  1086. String uploadJsonPath= target + File.separator + "results" +File.separator+"upload.json";
  1087. Thread.sleep(2000);
  1088. boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
  1089. if(!exist){
  1090. throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
  1091. }
  1092. String uploadData = FileUtils.readFile(uploadJsonPath);
  1093. JSONObject uploadJson = null;
  1094. JSONArray array = null;
  1095. if(uploadData!=null) {
  1096. uploadJson = JSONObject.parseObject(uploadData);
  1097. array = uploadJson.getJSONArray("upload");
  1098. }
  1099. if(array == null){
  1100. throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
  1101. }
  1102. Map<String, String> map = new HashMap<>();
  1103. JSONObject fileJson = null;
  1104. String fileName = "";
  1105. for(int i = 0, len = array.size(); i < len; i++) {
  1106. fileJson = array.getJSONObject(i);
  1107. fileName = fileJson.getString("file");
  1108. //文件不存在抛出异常
  1109. if (!new File(target + File.separator + "results" + File.separator + fileName)
  1110. .exists()) {
  1111. throw new Exception(
  1112. target + File.separator + "results" + File.separator + fileName + "文件不存在");
  1113. }
  1114. //high文件夹
  1115. if (fileJson.getIntValue("clazz") == 3) {
  1116. map.put(target + File.separator + "results" + File.separator + fileName,
  1117. imgViewPath + "pan/high/" + fileName.replace("high/", ""));
  1118. continue;
  1119. }
  1120. //low文件夹
  1121. if (fileJson.getIntValue("clazz") == 4) {
  1122. map.put(target + File.separator + "results" + File.separator + fileName,
  1123. imgViewPath + "pan/low/" + fileName.replace("low/", ""));
  1124. continue;
  1125. }
  1126. //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
  1127. if (fileJson.getIntValue("clazz") == 5) {
  1128. map.put(target + File.separator + "results" + File.separator + fileName,
  1129. imgViewPath + fileName);
  1130. continue;
  1131. }
  1132. //tiles文件夹,亚马逊瓦片图
  1133. if (fileJson.getIntValue("clazz") == 7) {
  1134. map.put(target + File.separator + "results" + File.separator + fileName,
  1135. imgViewPath + fileName);
  1136. continue;
  1137. }
  1138. }
  1139. //用户上传的全景图上传到ossresult目录
  1140. String ossCachesImagesPath = String.format(UploadFilePath.scene_result_data_path, num) + "caches/images/";
  1141. uploadFileList.stream().forEach(srcPath->{
  1142. map.put(srcPath, srcPath.replace(targetImagesPath, ossCachesImagesPath));
  1143. });
  1144. if(map.size()>0) {
  1145. fYunFileService.uploadMulFiles(bucket, map);
  1146. }
  1147. //更新数据库版本号
  1148. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1149. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1150. this.upgradeVersionAndImgVersionById(sceneEditInfo.getId());
  1151. //更新scenejson缓存和oss文件版本号
  1152. this.upgradeSceneJsonVersion(num, sceneEditInfo.getVersion() + 1, sceneEditInfo.getImgVersion() + 1, bucket);
  1153. }
  1154. @Override
  1155. public ResultData downloadPanorama(FileParamVO param) throws Exception {
  1156. String num = param.getNum();
  1157. String fileName = param.getFileName();
  1158. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1159. if(Objects.isNull(scenePlus)){
  1160. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1161. }
  1162. //查询是否存在等待中的异步操作记录,如果存在,抛出业务异常,终止操作
  1163. sceneAsynOperLogService.checkSceneAsynOper(num,null, SceneAsynModuleType.UPLOAD_DOWNLOAD.code() , SceneAsynFuncType.PANORAMIC_IMAGE.code());
  1164. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1165. String bucket = scenePlusExt.getYunFileBucket();
  1166. String path = scenePlusExt.getDataSource();
  1167. String cachePath = String.format(ConstantFilePath.SCENE_CACHE, num);
  1168. String imgCachePath = String.format(UploadFilePath.IMG_CACHES_PATH, num);
  1169. String localImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
  1170. String cacheFormat = "downloads/scene/%s/caches/";
  1171. String cacheImageFormat = "downloads/scene/%s/caches/images/";
  1172. //判断全景图缓存是否存在,如果不存在,从计算目录中拷贝到缓存目录
  1173. // this.cachePanorama(scenePlusExt.getDataSource(), num);
  1174. //根据vision.txt获取到有效的全景图名称
  1175. String ossVisionPath = String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt";
  1176. String visionPath = String.format(ConstantFilePath.SCENE_DATA_PATH_V4, num) + "vision.txt";
  1177. fYunFileService.downloadFile(ossVisionPath, visionPath);
  1178. List<String> panoramaImageList = SceneUtil.getPanoramaImageList(visionPath);
  1179. if(CollUtil.isEmpty(panoramaImageList)){
  1180. throw new BusinessException(ErrorCode.FAILURE_CODE_5063);
  1181. }
  1182. Map<String, Object> map = new HashMap<>();
  1183. //标记是否是异步操作,默认是同步操作
  1184. //如果入参文件名不为空,则是单个文件下载,不需要打包
  1185. String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num) + "caches/images/";
  1186. if(StrUtil.isNotEmpty(fileName)){
  1187. //如果是单张图片,直接提供oss url
  1188. // if(!fYunFileService.fileExist(bucket, ossResultPath + fileName)){
  1189. // throw new BusinessException(ErrorCode.FAILURE_CODE_5063);
  1190. // }
  1191. if(!panoramaImageList.contains(fileName)){
  1192. throw new BusinessException(ErrorCode.FAILURE_CODE_5063);
  1193. }
  1194. String url = ossResultPath + fileName;
  1195. String downloadName = fileName;
  1196. map.put("asyn", CommonStatus.NO.code());
  1197. map.put("fileUrl", url + "?t=" + System.currentTimeMillis());
  1198. map.put("fileName", downloadName);
  1199. return ResultData.ok(map);
  1200. }else{
  1201. //清除旧的下载记录
  1202. sceneAsynOperLogService.cleanLog(num, SceneAsynModuleType.UPLOAD_DOWNLOAD.code(), SceneAsynFuncType.PANORAMIC_IMAGE.code(), SceneAsynOperType.DOWNLOAD.code());
  1203. //开始异步执行下载全景图压缩包操作
  1204. CompletableFuture.runAsync(() -> {
  1205. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1206. SceneAsynOperLog sceneAsynOperLog = new SceneAsynOperLog();
  1207. sceneAsynOperLog.setNum(num);
  1208. sceneAsynOperLog.setOperType(SceneAsynOperType.DOWNLOAD.code());
  1209. sceneAsynOperLog.setModule(SceneAsynModuleType.UPLOAD_DOWNLOAD.code());
  1210. sceneAsynOperLog.setFunc(SceneAsynFuncType.PANORAMIC_IMAGE.code());
  1211. sceneAsynOperLog.setVersion(sceneEditInfo.getImgVersion());
  1212. sceneAsynOperLogService.save(sceneAsynOperLog);
  1213. try {
  1214. //下载到本地目录
  1215. FileUtil.del(localImagesPath);
  1216. fYunFileService.downloadFileByCommand(bucket, localImagesPath, ossResultPath);
  1217. //移除非必须文件
  1218. List<String> fileNames = FileUtil.listFileNames(localImagesPath);
  1219. fileNames.stream().forEach(name->{
  1220. if(!panoramaImageList.contains(name)){
  1221. FileUtil.del(localImagesPath + name);
  1222. }
  1223. });
  1224. String downloadName = num + "_images.zip";
  1225. long start = Calendar.getInstance().getTimeInMillis();
  1226. //打包
  1227. String zipPath = cachePath + downloadName;
  1228. ZipUtil.zip(localImagesPath, zipPath);
  1229. long end1 = Calendar.getInstance().getTimeInMillis();
  1230. log.info("打包耗时:" + (end1 - start));
  1231. //上传压缩包
  1232. fYunFileService.uploadFileByCommand(bucket, zipPath, String.format(cacheFormat, num) + downloadName);
  1233. String url = String.format(cacheFormat, num) + downloadName;
  1234. long end2 = Calendar.getInstance().getTimeInMillis();
  1235. log.info("上传耗时:" + (end2 - end1));
  1236. //删除本地压缩包
  1237. FileUtils.deleteFile(zipPath);
  1238. //删除本地目录
  1239. FileUtils.deleteDirectory(localImagesPath);
  1240. sceneAsynOperLog.setState(CommonOperStatus.SUCCESS.code());
  1241. sceneAsynOperLog.setUrl(url);
  1242. }catch (Exception e){
  1243. sceneAsynOperLog.setState(CommonOperStatus.FAILD.code());
  1244. log.error("下载全景图压缩包失败,num:" + num, e);
  1245. }
  1246. sceneAsynOperLogService.saveOrUpdate(sceneAsynOperLog);
  1247. });
  1248. map.put("asyn", CommonStatus.YES.code());
  1249. return ResultData.ok(map);
  1250. }
  1251. }
  1252. private void cachePanorama(String dataSource, String num){
  1253. String cachedImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, num);
  1254. if(FileUtil.exist(cachedImagesPath) && CollUtil.isNotEmpty(FileUtil.listFileNames(cachedImagesPath))){
  1255. return;
  1256. }
  1257. //将全景图缓存到缓存目录
  1258. List<String> imagesList = FileUtil.listFileNames(dataSource + "/caches/images");
  1259. //先清除旧的全景图
  1260. cn.hutool.core.io.FileUtil.del(cachedImagesPath);
  1261. String visionPath = dataSource + "/results/vision.txt";
  1262. List<String> panoramaImageList = SceneUtil.getPanoramaImageList(visionPath);
  1263. imagesList.stream().forEach(fileName -> {
  1264. if (panoramaImageList.contains(fileName)) {
  1265. String srcPath = dataSource + "/caches/images/" + fileName;
  1266. String targetPath = cachedImagesPath + fileName;
  1267. log.info("源文件:{}, 目标文件:{}", srcPath, targetPath);
  1268. cn.hutool.core.io.FileUtil.copy(srcPath, targetPath, true);
  1269. }
  1270. });
  1271. }
  1272. @Override
  1273. public void saveTagsToSceneEditInfo(String num, SceneEditInfo sceneEditInfo){
  1274. //查询缓存是否包含热点数据
  1275. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  1276. Map<String, String> allTagsMap = redisUtil.hmget(key);
  1277. boolean hashTags = false;
  1278. for (Entry<String, String> tagMap : allTagsMap.entrySet()) {
  1279. if(StrUtil.isEmpty(tagMap.getValue())){
  1280. continue;
  1281. }
  1282. hashTags = true;
  1283. break;
  1284. }
  1285. //更改热点状态
  1286. sceneEditInfo.setTags(hashTags ? CommonStatus.YES.code() : CommonStatus.NO.code());
  1287. //version 是空的代表 sceneEditInfo记录集不存在
  1288. if(sceneEditInfo.getVersion() != null){
  1289. sceneEditInfo.setVersion(sceneEditInfo.getVersion() + 1);
  1290. }
  1291. }
  1292. @Override
  1293. public ResultData saveVideoBox(FileNameAndDataParamVO param) throws Exception {
  1294. JSONObject boxVideo = JSONObject.parseObject(param.getData());
  1295. String sid = boxVideo.getString("sid");
  1296. if(StrUtil.isEmpty(sid)){
  1297. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  1298. }
  1299. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1300. if(Objects.isNull(scenePlus))
  1301. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1302. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1303. String bucket = scenePlusExt.getYunFileBucket();
  1304. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1305. //转换视频格式
  1306. commonService.transferToFlv(param.getNum(), param.getFileName(), bucket);
  1307. //生成boxVideos数据
  1308. String boxVideos = this.createBoxVideos(param.getNum(), sid, boxVideo, sceneEditInfo, OperationType.ADDORUPDATE.code());
  1309. //更新数据库
  1310. this.updateBoxVideos(sceneEditInfo, scenePlus.getId(), boxVideos);
  1311. return ResultData.ok();
  1312. }
  1313. @Override
  1314. public ResultData deleteVideoBox(DeleteSidParamVO param) throws Exception {
  1315. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1316. if(Objects.isNull(scenePlus))
  1317. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1318. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1319. //根据sid移除json
  1320. String boxVideos = this.createBoxVideos(param.getNum(), param.getSid(), null, sceneEditInfo, OperationType.DELETE.code());
  1321. //写数据库
  1322. this.updateBoxVideos(sceneEditInfo,scenePlus.getId(),boxVideos);
  1323. return ResultData.ok();
  1324. }
  1325. @Override
  1326. public ResultData saveBoxPhoto(BaseDataParamVO param) throws Exception {
  1327. JSONObject boxPhoto = JSONObject.parseObject(param.getData());
  1328. String sid = boxPhoto.getString("sid");
  1329. if(StrUtil.isEmpty(sid)){
  1330. throw new BusinessException(ServerCode.PARAM_REQUIRED, sid);
  1331. }
  1332. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1333. if(Objects.isNull(scenePlus))
  1334. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1335. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1336. //生成boxVideos数据
  1337. String boxPhotos = this.createBoxPhotos(param.getNum(), sid, boxPhoto, sceneEditInfo, OperationType.ADDORUPDATE.code());
  1338. //更新数据库
  1339. this.updateBoxPhotos(sceneEditInfo, boxPhotos);
  1340. return ResultData.ok();
  1341. }
  1342. @Override
  1343. public ResultData deleteBoxPhoto(DeleteSidParamVO param) throws Exception {
  1344. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1345. if(Objects.isNull(scenePlus))
  1346. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1347. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1348. //根据sid移除json
  1349. String boxPhotos = this.createBoxPhotos(param.getNum(), param.getSid(), null, sceneEditInfo, OperationType.DELETE.code());
  1350. //写数据库
  1351. this.updateBoxPhotos(sceneEditInfo, boxPhotos);
  1352. return ResultData.ok();
  1353. }
  1354. @Override
  1355. public DownloadVO downloadBallScreenVideo(BallScreenVideoParamVO param) {
  1356. String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, param.getNum()) + param.getFileName();
  1357. String url = ossUrlPrefix + videoPath + "?t=" + System.currentTimeMillis();
  1358. return DownloadVO.builder()
  1359. .fileName(param.getFileName())
  1360. .url(url)
  1361. .build();
  1362. }
  1363. @Override
  1364. public ResultData uploadBallScreenVideo(String num, String fileName, MultipartFile file) throws Exception {
  1365. //校验格式
  1366. if(!fileName.endsWith(".mp4")){
  1367. throw new BusinessException(ErrorCode.FAILURE_CODE_7016);
  1368. }
  1369. String videosViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
  1370. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1371. if(scenePlus == null){
  1372. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1373. }
  1374. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1375. String bucket = scenePlusExt.getYunFileBucket();
  1376. String path = scenePlusExt.getDataSource();
  1377. //校验文件名
  1378. String videos = scenePlusExt.getVideos();
  1379. if(StrUtil.isEmpty(videos)){
  1380. throw new BusinessException(ErrorCode.FAILURE_CODE_7012);
  1381. }
  1382. JSONObject videosJson = JSON.parseObject(videos);
  1383. JSONArray dataArr = videosJson.getJSONArray("data");
  1384. boolean exists = false;
  1385. for (Object o : dataArr) {
  1386. JSONObject jsonObject = (JSONObject)o;
  1387. if(jsonObject.getString("id").equals(fileName.replace(".mp4", ""))){
  1388. exists = true;
  1389. break;
  1390. }
  1391. }
  1392. if(!exists){
  1393. throw new BusinessException(ErrorCode.FAILURE_CODE_7012);
  1394. }
  1395. if(path != null && !"".equals(path) && path.startsWith("http")){
  1396. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  1397. }
  1398. String target = path + "_images";
  1399. String filePath = target + File.separator + "extras/video" + File.separator + fileName;
  1400. File targetFile = new File(filePath);
  1401. if(!targetFile.getParentFile().exists()){
  1402. targetFile.getParentFile().mkdirs();
  1403. }
  1404. //保存视频到本地
  1405. file.transferTo(targetFile);
  1406. File video = new File(target + File.separator + "extras/video");
  1407. //如果文件夹或者文件不存在,跳出
  1408. if(!video.exists() || video.listFiles() == null || video.listFiles().length == 0){
  1409. throw new BusinessException(ErrorCode.FAILURE_CODE_7009);
  1410. }
  1411. for(String videoName : video.list()){
  1412. log.info("球幕视频名称:{}", videoName);
  1413. fYunFileService.uploadFile(bucket, target + File.separator + "extras/video/" + videoName,videosViewPath + videoName);
  1414. CreateObjUtil.mp4ToFlv(target + File.separator + "extras/video/" + videoName,
  1415. target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"));
  1416. fYunFileService.uploadFile(bucket, target + File.separator + "extras/video/" + videoName.replace("mp4", "flv"),videosViewPath + videoName.replace("mp4", "flv"));
  1417. //覆盖原始视频资源
  1418. // FileUtils.copyFile(target + File.separator + "extras/video/" + videoName,
  1419. // path + File.separator + "caches/videos/" + videoName, true);
  1420. }
  1421. FileUtils.deleteDirectory(target + File.separator + "extras/video/");
  1422. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1423. this.upgradeVersionById(sceneEditInfo.getId());
  1424. //更新scenejson缓存和oss文件版本号
  1425. this.upgradeSceneJsonVersion(num, sceneEditInfo.getVersion() + 1, null, bucket);
  1426. return ResultData.ok();
  1427. }
  1428. @Override
  1429. public void upgradeVersionToSceneJson(String num, String bucket) throws Exception{
  1430. String key = String.format(RedisKey.SCENE_JSON, num);
  1431. String objectName = String.format(ConstantFilePath.SCENE_VIEW_DATA_DATA_SCENEJSON, num);
  1432. String objectContent = fYunFileService.getFileContent(bucket, objectName);
  1433. SceneJsonBean sceneJsonBean = JSON.parseObject(objectContent, SceneJsonBean.class);
  1434. sceneJsonBean.setVersion(sceneJsonBean.getVersion() +1);
  1435. fYunFileService.uploadFile(bucket, JSON.toJSONString(sceneJsonBean).getBytes(), objectName);
  1436. redisUtil.set(key, JSON.toJSONString(sceneJsonBean));
  1437. }
  1438. @Override
  1439. public ResultData sceneSync(String num, String type, String floorPlanJson, String ajkJson, String cameraJson,
  1440. MultipartFile[] files) throws Exception {
  1441. String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
  1442. String lockKey = String.format(RedisLockKey.LOCK_SCENE_SYNC, num);
  1443. Boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_2_HOUR);
  1444. if(!lock){
  1445. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  1446. }
  1447. try {
  1448. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1449. if(scenePlus == null){
  1450. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1451. }
  1452. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1453. String bucket = scenePlusExt.getYunFileBucket();
  1454. //更新scene.json文件
  1455. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + num + File.separator + "scene.json");
  1456. if(strsceneInfos == null)
  1457. new File(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + num + File.separator + "scene.json").createNewFile();
  1458. String path = scenePlusExt.getDataSource();// /mnt/data/0662c5389/831989883441512448/4898cab04f8c_202104141602356060/
  1459. if(path != null && !"".equals(path) && path.startsWith("http")){
  1460. path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
  1461. }
  1462. String target = path + "_ajk"; // /mnt/data/0662c5389/831989883441512448/4898cab04f8c_202104141602356060_ajk
  1463. File editPath = new File(target);
  1464. if(!editPath.exists()){
  1465. editPath.mkdirs();
  1466. }
  1467. //创建文件夹软连接并且复制data.json和project.json
  1468. if(new File(target + File.separator + "capture").exists()){
  1469. new File(target + File.separator + "capture").delete();
  1470. }
  1471. if(new File(target + File.separator + "caches").exists()){
  1472. //删除link
  1473. new File(target + File.separator + "caches" + File.separator + "images").delete();
  1474. //删除所有文件
  1475. FileUtils.delAllFile(target + File.separator + "caches");
  1476. }
  1477. if(new File(target + File.separator + "results").exists()){
  1478. FileUtils.delAllFile(target + File.separator + "results");
  1479. }
  1480. //创建文件夹,并link文件夹
  1481. new File(target + File.separator + "caches").mkdirs();
  1482. fYunFileService.downloadFileByCommand(target + File.separator + "capture", SceneUtil.getHomePath(path));
  1483. // CreateObjUtil.createSoftConnection(path + File.separator + "capture", target + File.separator + "capture");
  1484. if(new File(path + File.separator + "caches" + File.separator + "images").exists()){
  1485. CreateObjUtil.createSoftConnection(path + File.separator + "caches" + File.separator + "images", target + File.separator + "caches" + File.separator + "images");
  1486. }
  1487. String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num);
  1488. fYunFileService.downloadFile(bucket, ossResultPath + "data.json", target + File.separator+"data.json");
  1489. fYunFileService.downloadFile(bucket, ossResultPath + "project.json", target + File.separator+"project.json");
  1490. // FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
  1491. // FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
  1492. //data.json增加extras为执行重建算法
  1493. String project = FileUtils.readFile(target + File.separator+"project.json");
  1494. if(project != null){
  1495. JSONObject projectJson = JSONObject.parseObject(project);
  1496. projectJson.put("parent", projectJson.get("uuid"));
  1497. projectJson.put("uuid", UUID.randomUUID().toString());
  1498. projectJson.put("time", System.currentTimeMillis());
  1499. FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
  1500. }
  1501. String data = FileUtils.readFile(target + File.separator+"data.json");
  1502. if(data != null){
  1503. JSONObject floorplanJson = new JSONObject();
  1504. floorplanJson.put("has_floor_ajk_json", true);
  1505. floorplanJson.put("has_vision_txt", true);
  1506. floorplanJson.put("has_floorplan_json", true);
  1507. JSONObject dataJson = JSONObject.parseObject(data);
  1508. dataJson.put("extras", floorplanJson);
  1509. //V5表示不需要生成high,low文件
  1510. dataJson.put("skybox_type", "SKYBOX_V8");
  1511. dataJson.put("split_type", "SPLIT_V10");
  1512. FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
  1513. }
  1514. //文件上传的位置可以自定义
  1515. log.info("画墙重建模型开始");
  1516. File targetFile = new File(target + File.separator + "extras" + File.separator + "floor_ajk.json");
  1517. if(!targetFile.getParentFile().exists()){
  1518. targetFile.getParentFile().mkdirs();
  1519. }
  1520. if(targetFile.exists()){
  1521. FileUtils.deleteFile(target + File.separator + "extras" + File.separator + "floor_ajk.json");
  1522. }
  1523. // 保存
  1524. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floorplan.json", new String(floorPlanJson.getBytes(), "UTF-8"));
  1525. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "floor_ajk.json", new String(ajkJson.getBytes(), "UTF-8"));
  1526. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+num + File.separator + "floor_ajk.json", new String(ajkJson.getBytes(), "UTF-8"));
  1527. FileUtils.writeFile(target + File.separator + "extras" + File.separator + "vision.txt", new String(cameraJson.getBytes(), "UTF-8"));
  1528. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+num + File.separator + "camera.json", new String(cameraJson.getBytes(), "UTF-8"));
  1529. for(int i = 0; i < files.length; i ++){
  1530. File cadImg = new File(target + File.separator + "extras" + File.separator + "Floorplans/" + files[i].getOriginalFilename());
  1531. if(!cadImg.getParentFile().exists()){
  1532. cadImg.getParentFile().mkdirs();
  1533. }
  1534. if(cadImg.exists())
  1535. {
  1536. cadImg.delete();
  1537. }
  1538. files[i].transferTo(cadImg);
  1539. }
  1540. //下载封面图
  1541. FileUtils.downLoadFromUrl(scenePlusExt.getThumb() + "?t=" + System.currentTimeMillis(),
  1542. "Cover.png", target + File.separator + "extras" + File.separator + "CoverImage");
  1543. //转换成jpg
  1544. FileUtils.pngToJpg(target + File.separator + "extras" + File.separator + "CoverImage/Cover.png",
  1545. target + File.separator + "extras" + File.separator + "CoverImage/Cover.jpg");
  1546. //安居客算法运行
  1547. log.info("安居客算法:开始建模——"+num);
  1548. CreateObjUtil.build3dModelOld(target , "1");
  1549. String uploadJsonPath = target + File.separator + "results" + File.separator + "upload.json";
  1550. log.info("uploadJsonPath=" + uploadJsonPath);
  1551. //因为共享目录有延迟,这里循环检测算法是否计算完毕3次,每次隔五秒
  1552. boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
  1553. if(!exist){
  1554. throw new BusinessException(ErrorCode.FAILURE_CODE_7017);
  1555. }
  1556. String zipPath = target + File.separator + "results/" + num + ".zip";
  1557. new File(zipPath).delete();
  1558. ZipUtil.zip(target + File.separator + "results/ajk/", zipPath);
  1559. // String command = "bash /opt/ossutil/gzip.sh " + zipPath.replace(".zip", "") + " " + target + File.separator + "results/ajk/";
  1560. // log.info("压缩文件:" + command);
  1561. // CreateObjUtil.callshell(command);
  1562. if(!new File(zipPath).exists()){
  1563. return ResultData.error(ErrorCode.FAILURE_CODE_5043);
  1564. }
  1565. String fileMD5 = FileMd5Util.getFileMD5(new File(zipPath));
  1566. fYunFileService.uploadFileByCommand(bucket, zipPath, "data_download/" + num + ".zip");
  1567. SceneDataDownload sceneDataDownload = sceneDataDownloadService.findBySceneNum(num);
  1568. if(sceneDataDownload == null){
  1569. sceneDataDownload = new SceneDataDownload();
  1570. sceneDataDownload.setSceneNum(num);
  1571. sceneDataDownload.setDownloadPath(ossUrlPrefix + "data_download/" + num + ".zip");
  1572. sceneDataDownload.setFileMd5(fileMD5);
  1573. sceneDataDownloadService.save(sceneDataDownload);
  1574. return ResultData.ok();
  1575. }
  1576. sceneDataDownload.setFileMd5(fileMD5);
  1577. sceneDataDownload.setUpdateTime(Calendar.getInstance().getTime());
  1578. sceneDataDownloadService.updateById(sceneDataDownload);
  1579. }catch (Exception e){
  1580. log.error("画墙重建模型失败...", e);
  1581. throw new BusinessException(ErrorCode.FAILURE_CODE_5039);
  1582. }finally {
  1583. redisLockUtil.unlockLua(lockKey, lockVal);
  1584. }
  1585. return ResultData.ok();
  1586. }
  1587. @Override
  1588. public ResultData checkKey(SceneCheckKeyParamVO param) throws Exception {
  1589. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1590. if(Objects.isNull(scenePlus)){
  1591. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1592. }
  1593. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1594. String bucket = scenePlusExt.getYunFileBucket();
  1595. SceneJsonBean sceneJsonBean = null;
  1596. String sceneJson = redisUtil.get(String.format(RedisKey.SCENE_JSON, param.getNum()));
  1597. if(StrUtil.isEmpty(sceneJson)){
  1598. sceneJson = fYunFileService.getFileContent(bucket,
  1599. String.format(UploadFilePath.DATA_VIEW_PATH, param.getNum()) + "scene.json");
  1600. }
  1601. sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
  1602. if(!param.getPassword().equals(sceneJsonBean.getScenePassword())){
  1603. throw new BusinessException(ErrorCode.FAILURE_CODE_5021);
  1604. }
  1605. return ResultData.ok();
  1606. }
  1607. @Override
  1608. public ResultData addMosaics(BaseDataParamVO param) throws Exception {
  1609. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1610. if(Objects.isNull(scenePlus)){
  1611. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1612. }
  1613. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1614. //如果redis数据丢失,从本地文件中同步马赛克数据到redis
  1615. this.syncMosaicFromFileToRedis(param.getNum());
  1616. Map<String, String> map = new HashMap<>();
  1617. JSONArray jsonArray = JSON.parseArray(param.getData());
  1618. for (Object o : jsonArray) {
  1619. JSONObject mosaic = (JSONObject) o;
  1620. String panoId = mosaic.getString("panoId");
  1621. if(StrUtil.isEmpty(panoId)){
  1622. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1623. }
  1624. map.put(panoId, JSON.toJSONString(mosaic));
  1625. }
  1626. String key = String.format(RedisKey.SCENE_MOSAIC_DATA, param.getNum());
  1627. redisUtil.hmset(key, map);
  1628. //写入本地文件,作为备份
  1629. this.writeMosaic(param.getNum());
  1630. //更新数据库
  1631. this.updateMosaicFlag(param.getNum());
  1632. //更新版本号
  1633. this.upgradeVersionById(sceneEditInfo.getId());
  1634. return ResultData.ok();
  1635. }
  1636. private void updateMosaicFlag(String num) throws InterruptedException {
  1637. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1638. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId());
  1639. String key = String.format(RedisKey.SCENE_MOSAIC_DATA, num);
  1640. boolean flag = redisUtil.hasKey(key);
  1641. if(flag){
  1642. sceneEditInfoExt.setMosaic(Integer.valueOf(CommonStatus.YES.code()));
  1643. }else{
  1644. sceneEditInfoExt.setMosaic(Integer.valueOf(CommonStatus.NO.code()));
  1645. }
  1646. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  1647. }
  1648. /**
  1649. * <p>
  1650. 保证马赛克数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
  1651. **/
  1652. private void syncMosaicFromFileToRedis(String num) throws Exception{
  1653. String key = String.format(RedisKey.SCENE_MOSAIC_DATA, num);
  1654. boolean exist = redisUtil.hasKey(key);
  1655. if(exist){
  1656. return;
  1657. }
  1658. // String uuid = cn.hutool.core.lang.UUID.randomUUID().toString();
  1659. String lockKey = String.format(RedisLockKey.LOCK_MOSAIC_DATA_SYNC, num);
  1660. boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
  1661. if(!lock){
  1662. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  1663. }
  1664. try{
  1665. exist = redisUtil.hasKey(key);
  1666. if(exist){
  1667. return;
  1668. }
  1669. String filePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "mosaic.json";
  1670. String mosaicData = FileUtils.readUtf8String(filePath);
  1671. if(StrUtil.isEmpty(mosaicData)){
  1672. return;
  1673. }
  1674. JSONArray jsonArray = JSON.parseArray(mosaicData);
  1675. if(CollUtil.isEmpty(jsonArray)){
  1676. return;
  1677. }
  1678. Map<String, String> map = new HashMap<>();
  1679. for (Object o : jsonArray) {
  1680. JSONObject jo = (JSONObject)o;
  1681. map.put(jo.getString("panoId"), jo.toJSONString());
  1682. }
  1683. redisUtil.hmset(key, map);
  1684. }finally {
  1685. redisLockUtil.unlockLua(lockKey);
  1686. }
  1687. }
  1688. /**
  1689. * <p>
  1690. 保证马赛克数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
  1691. **/
  1692. private void writeMosaic(String num) throws Exception{
  1693. String mosaicPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "mosaic.json";
  1694. String key = String.format(RedisKey.SCENE_MOSAIC_DATA, num);
  1695. Map<String, String> mosaicMap = redisUtil.hmget(key);
  1696. if(CollUtil.isEmpty(mosaicMap)){
  1697. FileUtils.deleteFile(mosaicPath);
  1698. return;
  1699. }
  1700. List<String> mosaicList = Lists.newArrayList(mosaicMap.values());
  1701. JSONArray jsonArr = new JSONArray();
  1702. mosaicList.stream().forEach(mosaic->{
  1703. jsonArr.add(JSONObject.parseObject(mosaic));
  1704. });
  1705. String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
  1706. String lockKey = String.format(RedisLockKey.LOCK_MOSAIC_JSON, num);
  1707. boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_1_MINUTE);
  1708. if(!lock){
  1709. return;
  1710. }
  1711. try{
  1712. FileUtils.writeFile(mosaicPath, jsonArr.toJSONString());
  1713. }finally {
  1714. redisLockUtil.unlockLua(lockKey, lockVal);
  1715. }
  1716. }
  1717. @Override
  1718. public ResultData uploadLinkPan(String num, String sid, String fileName, MultipartFile file) throws Exception {
  1719. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1720. if(scenePlus == null){
  1721. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1722. }
  1723. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1724. String bucket = scenePlusExt.getYunFileBucket();
  1725. String localImagesPath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, num);
  1726. String path = scenePlusExt.getDataSource();
  1727. String target = localImagesPath + "panorama/" + sid;
  1728. FileUtils.deleteDirectory(target);
  1729. //文件写如本地磁盘
  1730. String filePath = target + File.separator + "extras/images" + File.separator + fileName;
  1731. File targetFile = new File(filePath);
  1732. if(!targetFile.getParentFile().exists()){
  1733. targetFile.getParentFile().mkdirs();
  1734. }
  1735. file.transferTo(targetFile);
  1736. //调用算法切全景图
  1737. String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num);
  1738. fYunFileService.downloadFile(bucket, ossResultPath + "data.json", target + File.separator+"data.json");
  1739. fYunFileService.downloadFile(bucket, ossResultPath + "project.json", target + File.separator+"project.json");
  1740. JSONObject visionJson = new JSONObject();
  1741. JSONArray visionArray = new JSONArray();
  1742. visionJson.put("uuid", sid);
  1743. visionJson.put("group", 1);
  1744. visionJson.put("subgroup", 0);
  1745. visionArray.add(visionJson);
  1746. JSONObject vision = new JSONObject();
  1747. vision.put("sweepLocations", visionArray);
  1748. cn.hutool.core.io.FileUtil.writeString(vision.toString(), target + "/extras" + File.separator + "vision.txt", StandardCharsets.UTF_8);
  1749. //data.json增加extras为执行重建算法
  1750. String type = "4k";
  1751. String data = FileUtils.readFile(target + File.separator + "data.json");
  1752. if(data != null){
  1753. JSONObject floorplanJson = new JSONObject();
  1754. floorplanJson.put("has_source_images", true);
  1755. floorplanJson.put("has_vision_txt", true);
  1756. JSONObject dataJson = JSONObject.parseObject(data);
  1757. dataJson.put("extras", floorplanJson);
  1758. dataJson.put("split_type", "SPLIT_V8");//替换全景图算法
  1759. String skyboxType = "SKYBOX_V6";//默认4k minion
  1760. if(SceneFrom.PRO.code().equals(scenePlusExt.getSceneFrom())){
  1761. skyboxType = "SKYBOX_V7";
  1762. type = "2k";
  1763. }
  1764. if(scenePlusExt.getSceneScheme() == 3){
  1765. if("4k".equals(scenePlusExt.getSceneResolution())){
  1766. skyboxType = "SKYBOX_V14";
  1767. }else{
  1768. skyboxType = "SKYBOX_V13";
  1769. }
  1770. }
  1771. dataJson.put("skybox_type", skyboxType);
  1772. cn.hutool.core.io.FileUtil.writeString(dataJson.toString(), target + File.separator+"data.json", StandardCharsets.UTF_8);
  1773. }
  1774. //创建文件夹软连接并且复制data.json和project.json
  1775. String capturePath = target + File.separator + "capture";
  1776. String resultPath = target + File.separator + "results";
  1777. log.info("场景关联上传全景图:capturePath={}", capturePath);
  1778. log.info("场景关联上传全景图:resultPath={}", resultPath);
  1779. if(cn.hutool.core.io.FileUtil.exist(capturePath)){
  1780. cn.hutool.core.io.FileUtil.del(capturePath);
  1781. }
  1782. if(cn.hutool.core.io.FileUtil.exist(resultPath)){
  1783. cn.hutool.core.io.FileUtil.del(resultPath);
  1784. }
  1785. //下载data.fdage
  1786. fYunFileService.downloadFile(ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") + "/data.fdage", capturePath + "/data.fdage");
  1787. CreateObjUtil.build3dModel(target , "1");
  1788. //读取upload文件,获取需要上传的文件
  1789. JSONArray array = ComputerUtil.getUploadArray(resultPath + "/upload.json", this.maxCheckTimes, this.waitTime);
  1790. Map<String, String> map = new HashMap<>();
  1791. JSONObject fileJson;
  1792. String uploadFile, uploadFilePath;
  1793. String imgEditPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  1794. for(int i = 0, len = array.size(); i < len; i++){
  1795. fileJson = array.getJSONObject(i);
  1796. uploadFile = fileJson.getString("file");
  1797. uploadFilePath = resultPath +File.separator + uploadFile;
  1798. //文件不存在抛出异常
  1799. if(!cn.hutool.core.io.FileUtil.exist(uploadFilePath)){
  1800. throw new Exception(uploadFilePath + "文件不存在");
  1801. }
  1802. Integer clazz = fileJson.getIntValue("clazz");
  1803. if(Objects.isNull(clazz)){
  1804. continue;
  1805. }
  1806. if(clazz == 4 || clazz == 5 || clazz == 7){
  1807. map.put(uploadFilePath, imgEditPath + "panorama/" + sid + File.separator + uploadFile);
  1808. }
  1809. }
  1810. //上传全景图
  1811. map.put(filePath, imgEditPath + "panorama/" + sid + "/high/" + fileName);
  1812. fYunFileService.uploadMulFiles(bucket, map);
  1813. Map<String, String> result = new HashMap<>();
  1814. result.put("type", type);
  1815. return ResultData.ok(result);
  1816. }
  1817. @Override
  1818. public ResultData saveLinkPan(SaveLinkPanParamVO param) throws Exception {
  1819. String num = param.getNum();
  1820. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1821. if(Objects.isNull(scenePlus)){
  1822. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1823. }
  1824. //添加场景关联数据
  1825. this.addOrUpdateLinPan(num, param.getLinkPans());
  1826. //添加场景关联图标
  1827. this.addOrUpdateLinkPanStyles(num, param.getStyles());
  1828. //场景关联数据备份到本地
  1829. this.writeLinkScene(num);
  1830. //更新场景关联标识、升级版本号
  1831. this.setLinkScenesAndUpgradeVersion(scenePlus.getId(), num);
  1832. return ResultData.ok();
  1833. }
  1834. @Override
  1835. public ResultData deleteStyles(DeleteStylesParamVO param) throws Exception {
  1836. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1837. if (scenePlus == null)
  1838. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1839. List<String> sidList = param.getSidList();
  1840. this.syncLinkPanStylesFromFileToRedis(param.getNum());
  1841. String key = String.format(RedisKey.SCENE_LINKPAN_STYLES, param.getNum());
  1842. List<String> deleteList = redisUtil.hMultiGet(key, sidList);
  1843. redisUtil.hdel(key, sidList.toArray());
  1844. //写入本地文件,作为备份
  1845. this.writeLinkScene(param.getNum());
  1846. //删除oss文件
  1847. List<String> deleteFileList = deleteList.stream().map(str -> {
  1848. JSONObject parse = JSON.parseObject(str);
  1849. return parse.getString("url");
  1850. }).collect(Collectors.toList());
  1851. sceneUploadService.delete(
  1852. DeleteFileParamVO.builder()
  1853. .num(param.getNum())
  1854. .fileNames(deleteFileList)
  1855. .bizType(FileBizType.LINK_STYLE.code()).build());
  1856. return ResultData.ok();
  1857. }
  1858. @Override
  1859. public ResultData deleteLinkPan(DeleteLinkPanParamVO param) throws Exception {
  1860. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  1861. if (scenePlus == null)
  1862. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  1863. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  1864. String bucket = scenePlusExt.getYunFileBucket();
  1865. List<String> deleteSidList = param.getSidList();
  1866. //处理删除状态数据
  1867. this.deletelinkPanData(param.getNum(), deleteSidList, bucket);
  1868. //写入本地文件,作为备份
  1869. this.writeLinkScene(param.getNum());
  1870. //更新场景关联标识、升级版本号
  1871. this.setLinkScenesAndUpgradeVersion(scenePlus.getId(), param.getNum());
  1872. return ResultData.ok();
  1873. }
  1874. private void deletelinkPanData(String num, List<String> deleteSidList, String bucket) throws Exception {
  1875. if(CollUtil.isEmpty(deleteSidList)){
  1876. return;
  1877. }
  1878. this.syncLinPanFromFileToRedis(num);
  1879. //从redis中加载热点数据
  1880. String key = String.format(RedisKey.SCENE_LINKPAN_DATA, num);
  1881. List<String> deletDataList = redisUtil.hMultiGet(key, deleteSidList);
  1882. if(CollUtil.isEmpty(deletDataList))
  1883. return;
  1884. List<String> thumbNameList = deleteSidList.stream().map(sid -> {
  1885. String linkPan = redisUtil.hget(key, sid);
  1886. JSONObject linkPanObj = JSON.parseObject(linkPan);
  1887. return FileUtil.getPrefix(linkPanObj.getString("thumb"));
  1888. }).collect(Collectors.toList());
  1889. //从redis中移除热点数据
  1890. redisUtil.hdel(key, deleteSidList.toArray());
  1891. //删除oss文件
  1892. String imgEditPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  1893. thumbNameList.stream().forEach(thumbName->{
  1894. fYunFileService.deleteFolder(bucket, imgEditPath + "panorama/" + thumbName);
  1895. });
  1896. }
  1897. @Override
  1898. public ResultData listLinkPan(String num) throws Exception {
  1899. this.syncLinPanFromFileToRedis(num);
  1900. this.syncLinkPanStylesFromFileToRedis(num);
  1901. JSONObject result = new JSONObject();
  1902. //查询场景关联数据
  1903. String key = String.format(RedisKey.SCENE_LINKPAN_DATA, num);
  1904. Map<String, String> allTagsMap = redisUtil.hmget(key);
  1905. List<JSONObject> tags = Lists.newArrayList();
  1906. List<TagBean> tagBeanList = new ArrayList<>();
  1907. if(CollUtil.isNotEmpty(allTagsMap)){
  1908. allTagsMap.entrySet().stream().forEach(entry -> {
  1909. JSONObject jsonObject = JSON.parseObject(entry.getValue());
  1910. tagBeanList.add(
  1911. TagBean.builder()
  1912. .createTime(jsonObject.getLong("createTime"))
  1913. .tag(jsonObject).build());
  1914. });
  1915. //按创建时间倒叙排序
  1916. tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
  1917. //移除createTime字段
  1918. tags = tagBeanList.stream().map(tagBean -> {
  1919. JSONObject tag = tagBean.getTag();
  1920. tag.remove("createTime");
  1921. return tag;
  1922. }).collect(Collectors.toList());
  1923. }
  1924. result.put("tags", tags);
  1925. //封装styles数据
  1926. List<JSONObject> styles = Lists.newArrayList();
  1927. key = String.format(RedisKey.SCENE_LINKPAN_STYLES, num);
  1928. Map<String, String> styleMap = redisUtil.hmget(key);
  1929. if(CollUtil.isNotEmpty(styleMap)) {
  1930. for (String style : styleMap.values()) {
  1931. styles.add(JSON.parseObject(style));
  1932. }
  1933. }
  1934. //图标按写入时间排序
  1935. styles = this.sortStyles(styles);
  1936. result.put("styles", styles);
  1937. return ResultData.ok(result);
  1938. }
  1939. private List<JSONObject> sortStyles(List<JSONObject> styles){
  1940. if(CollUtil.isEmpty(styles)){
  1941. return null;
  1942. }
  1943. //统计使用频次
  1944. List<StyleBean> styleBeans = Lists.newArrayList();
  1945. for (JSONObject style : styles) {
  1946. Long createTime = style.getLong("createTime");
  1947. createTime = Objects.isNull(createTime) ? Calendar.getInstance().getTimeInMillis() : createTime;
  1948. style.remove("createTime");
  1949. styleBeans.add(
  1950. StyleBean.builder().style(style)
  1951. .createTime(createTime).build());
  1952. }
  1953. //排序
  1954. List<JSONObject> styleList = Lists.newArrayList();
  1955. if(CollUtil.isNotEmpty(styleBeans)){
  1956. styleList = styleBeans.stream().sorted(Comparator.comparing(StyleBean::getCreateTime).reversed())
  1957. .map(item -> {
  1958. return item.getStyle();
  1959. }).collect(Collectors.toList());
  1960. }
  1961. return styleList;
  1962. }
  1963. private void setLinkScenesAndUpgradeVersion(Long scenePlusId, String num){
  1964. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlusId);
  1965. //查询缓存是否有场景关联数据
  1966. String key = String.format(RedisKey.SCENE_LINKPAN_DATA, num);
  1967. Map<String, String> allTagsMap = redisUtil.hmget(key);
  1968. boolean hashTags = false;
  1969. for (Entry<String, String> tagMap : allTagsMap.entrySet()) {
  1970. if(StrUtil.isEmpty(tagMap.getValue())){
  1971. continue;
  1972. }
  1973. hashTags = true;
  1974. break;
  1975. }
  1976. //更新linkscenes字段
  1977. sceneEditInfoExtService.update(
  1978. new LambdaUpdateWrapper<SceneEditInfoExt>()
  1979. .set(SceneEditInfoExt::getLinks, hashTags ? CommonStatus.YES.code() : CommonStatus.NO.code())
  1980. .eq(SceneEditInfoExt::getEditInfoId, sceneEditInfo.getId()));
  1981. //更新场景版本
  1982. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  1983. .setSql("version=version+" + 1)
  1984. .setSql("link_version=link_version+" + 1)
  1985. .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
  1986. }
  1987. /**
  1988. * <p>
  1989. 热点数据保存
  1990. * </p>
  1991. * @author dengsixing
  1992. * @date 2022/3/3
  1993. **/
  1994. private void writeLinkScene(String num) throws Exception{
  1995. String dataKey = String.format(RedisKey.SCENE_LINKPAN_DATA, num);
  1996. Map<String, String> tagMap = redisUtil.hmget(dataKey);
  1997. List<String> tagList = Lists.newArrayList();
  1998. tagMap.entrySet().stream().forEach(entry->{
  1999. if(StrUtil.isNotEmpty(entry.getValue())){
  2000. tagList.add(entry.getValue());
  2001. }
  2002. });
  2003. JSONObject jsonObject = new JSONObject();
  2004. JSONArray tagJsonArr = new JSONArray();
  2005. if(CollUtil.isNotEmpty(tagList)){
  2006. tagList.stream().forEach(linkPan->{
  2007. tagJsonArr.add(JSONObject.parseObject(linkPan));
  2008. });
  2009. }
  2010. jsonObject.put("tags", tagJsonArr);
  2011. String stylesKey = String.format(RedisKey.SCENE_LINKPAN_STYLES, num);
  2012. Map<String, String> styleMap = redisUtil.hmget(stylesKey);
  2013. List<JSONObject> styleList = Lists.newArrayList();
  2014. if(CollUtil.isNotEmpty(styleMap)){
  2015. styleMap.values().stream().forEach(style->{
  2016. styleList.add(JSONObject.parseObject(style));
  2017. });
  2018. }
  2019. jsonObject.put("styles", styleList);
  2020. String linkScenePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "links.json";
  2021. String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
  2022. String lockKey = String.format(RedisLockKey.LOCK_LINK_SCENE_JSON, num);
  2023. boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_1_MINUTE);
  2024. if(!lock){
  2025. return;
  2026. }
  2027. try{
  2028. cn.hutool.core.io.FileUtil.writeUtf8String(jsonObject.toJSONString(), linkScenePath);
  2029. }finally {
  2030. redisLockUtil.unlockLua(lockKey, lockVal);
  2031. }
  2032. }
  2033. private void addOrUpdateLinkPanStyles(String num, List<JSONObject> styles) throws Exception{
  2034. this.syncLinkPanStylesFromFileToRedis(num);
  2035. if(CollUtil.isEmpty(styles)){
  2036. return;
  2037. }
  2038. long time = Calendar.getInstance().getTimeInMillis();
  2039. Map<String, String> styleMap = new HashMap<>();
  2040. AtomicInteger index = new AtomicInteger();
  2041. styles.stream().forEach(style->{
  2042. String id = style.getString("sid");
  2043. style.put("createTime", time + index.getAndIncrement());
  2044. styleMap.put(id, style.toJSONString());
  2045. });
  2046. String key = String.format(RedisKey.SCENE_LINKPAN_STYLES, num);
  2047. redisUtil.hmset(key, styleMap);
  2048. }
  2049. /**
  2050. * <p>
  2051. 保证icons数据安全性,当redis宕机导致icons数据丢失时,可以从文件中读取,恢复到redis
  2052. * </p>
  2053. * @author dengsixing
  2054. * @date 2022/3/3
  2055. **/
  2056. private void syncLinkPanStylesFromFileToRedis(String num) throws Exception{
  2057. String key = String.format(RedisKey.SCENE_LINKPAN_STYLES, num);
  2058. boolean exist = redisUtil.hasKey(key);
  2059. if(exist){
  2060. return;
  2061. }
  2062. String lockKey = String.format(RedisLockKey.LOCK_LINKPAN_STYLES_SYNC, num);
  2063. String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
  2064. boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_1_MINUTE);
  2065. if(!lock){
  2066. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  2067. }
  2068. try{
  2069. exist = redisUtil.hasKey(key);
  2070. if(exist){
  2071. return;
  2072. }
  2073. String linkSceneFilePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  2074. String linkSceneData = FileUtils.readUtf8String(linkSceneFilePath + "links.json");
  2075. if(StrUtil.isEmpty(linkSceneData)){
  2076. return;
  2077. }
  2078. JSONObject jsonObject = JSON.parseObject(linkSceneData);
  2079. JSONArray stylesArr = jsonObject.getJSONArray("styles");
  2080. if(CollUtil.isEmpty(stylesArr)){
  2081. return;
  2082. }
  2083. Map<String, String> styleMap = new HashMap<>();
  2084. for (Object style : stylesArr) {
  2085. JSONObject styleObj = (JSONObject)style;
  2086. String id = styleObj.getString("sid");
  2087. styleMap.put(id, styleObj.toJSONString());
  2088. }
  2089. redisUtil.hmset(key, styleMap);
  2090. }finally {
  2091. redisLockUtil.unlockLua(lockKey, lockVal);
  2092. }
  2093. }
  2094. private void addOrUpdateLinPan(String num, List<JSONObject> linkPanList) throws Exception{
  2095. Map<String, String> addOrUpdateMap = new HashMap<>();
  2096. int i = 0;
  2097. for (JSONObject jsonObject : linkPanList) {
  2098. jsonObject.put("createTime", Calendar.getInstance().getTimeInMillis() + i++);
  2099. addOrUpdateMap.put(jsonObject.getString("sid"), jsonObject.toJSONString());
  2100. }
  2101. this.syncLinPanFromFileToRedis(num);
  2102. //处理新增和修改数据
  2103. this.addOrUpdateLinkPanHandler(num, addOrUpdateMap);
  2104. }
  2105. /**
  2106. * <p>
  2107. 保证热点数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
  2108. * </p>
  2109. * @author dengsixing
  2110. * @date 2022/3/3
  2111. **/
  2112. private void syncLinPanFromFileToRedis(String num) throws Exception{
  2113. String key = String.format(RedisKey.SCENE_LINKPAN_DATA, num);
  2114. boolean exist = redisUtil.hasKey(key);
  2115. if(exist){
  2116. return;
  2117. }
  2118. String lockKey = String.format(RedisLockKey.LOCK_LINKPAN_DATA_SYNC, num);
  2119. String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
  2120. boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_1_MINUTE);
  2121. if(!lock){
  2122. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  2123. }
  2124. try{
  2125. exist = redisUtil.hasKey(key);
  2126. if(exist){
  2127. return;
  2128. }
  2129. String linkSceneFilePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  2130. String linkSceneData = FileUtils.readUtf8String(linkSceneFilePath + "links.json");
  2131. if(StrUtil.isEmpty(linkSceneData)){
  2132. return;
  2133. }
  2134. JSONObject jsonObject = JSON.parseObject(linkSceneData);
  2135. JSONArray tagsArr = jsonObject.getJSONArray("tags");
  2136. if(CollUtil.isEmpty(tagsArr)){
  2137. return;
  2138. }
  2139. Map<String, String> map = new HashMap<>();
  2140. for (Object o : tagsArr) {
  2141. JSONObject jo = (JSONObject)o;
  2142. map.put(jo.getString("sid"), jo.toJSONString());
  2143. }
  2144. redisUtil.hmset(key, map);
  2145. }finally {
  2146. redisLockUtil.unlockLua(lockKey, lockVal);
  2147. }
  2148. }
  2149. private void addOrUpdateLinkPanHandler(String num, Map<String, String> addOrUpdateMap){
  2150. if(CollUtil.isEmpty(addOrUpdateMap))
  2151. return;
  2152. //数据验证,新增、修改状态,linkPan不能为空
  2153. for (String sid : addOrUpdateMap.keySet()) {
  2154. String linkPan = addOrUpdateMap.get(sid);
  2155. if(StrUtil.isEmpty(linkPan)){
  2156. throw new BusinessException(ErrorCode.FAILURE_CODE_7022);
  2157. }
  2158. }
  2159. //批量写入缓存
  2160. String key = String.format(RedisKey.SCENE_LINKPAN_DATA, num);
  2161. redisUtil.hmset(key, addOrUpdateMap);
  2162. }
  2163. private void updateBoxVideos(SceneEditInfo sceneEditInfo, Long scenePlusId, String boxVideos){
  2164. if(Objects.isNull(sceneEditInfo)){
  2165. sceneEditInfo = new SceneEditInfo();
  2166. sceneEditInfo.setScenePlusId(scenePlusId);
  2167. sceneEditInfo.setBoxVideos(boxVideos);
  2168. this.save(sceneEditInfo);
  2169. }else{
  2170. this.update(new UpdateWrapper<SceneEditInfo>()
  2171. .setSql("version = version + 1")
  2172. .set("box_videos", boxVideos)
  2173. .eq("id", sceneEditInfo.getId()));
  2174. }
  2175. }
  2176. private void updateBoxPhotos(SceneEditInfo sceneEditInfo, String boxPhotos){
  2177. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  2178. .set(SceneEditInfo::getBoxPhotos, boxPhotos)
  2179. .setSql("version = version + 1")
  2180. .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
  2181. }
  2182. private String createBoxVideos(
  2183. String num, String sid, JSONObject boxVideo,
  2184. SceneEditInfo sceneEditInfo, int type) throws Exception{
  2185. String boxVideos = null;
  2186. if(sceneEditInfo != null){
  2187. boxVideos = sceneEditInfo.getBoxVideos();
  2188. }
  2189. JSONArray boxVideosJson = null;
  2190. if (StrUtil.isNotEmpty(boxVideos)) {
  2191. boxVideosJson = JSONArray.parseArray(boxVideos);
  2192. }else {
  2193. boxVideosJson = new JSONArray();
  2194. }
  2195. if(boxVideosJson.size() > 0){
  2196. int i = 1;
  2197. long timeInMillis = Calendar.getInstance().getTimeInMillis();
  2198. for (Object o : boxVideosJson) {
  2199. JSONObject item = (JSONObject)o;
  2200. if(Objects.nonNull(item.getLong("createTime"))){
  2201. continue;
  2202. }
  2203. item.put("createTime", timeInMillis - (i++));
  2204. }
  2205. }
  2206. String result = null;
  2207. //删除
  2208. if(type == OperationType.DELETE.code()){
  2209. Set<String> deleteVidoeFile = new HashSet<>();
  2210. Set<String> deletePicFile = new HashSet<>();
  2211. if(boxVideosJson.size() == 0)
  2212. return null;
  2213. for(int i=0;i<boxVideosJson.size();++i){
  2214. JSONObject ele = boxVideosJson.getJSONObject(i);
  2215. if(ele.getString("sid").equals(sid)){
  2216. String poster = ele.getString("poster");
  2217. if(StrUtil.isNotEmpty(poster))
  2218. deletePicFile.add(poster);
  2219. String url = ele.getString("url");
  2220. if(StrUtil.isNotEmpty(url)){
  2221. deleteVidoeFile.add(url);
  2222. deleteVidoeFile.add(url.replace(".mp4",".flv"));
  2223. }
  2224. boxVideosJson.remove(i);
  2225. }
  2226. }
  2227. //删除资源文件
  2228. if(CollUtil.isNotEmpty(deleteVidoeFile))
  2229. sceneUploadService.delete(
  2230. DeleteFileParamVO.builder().num(num)
  2231. .bizType(FileBizType.BOX_VIDEO.code())
  2232. .fileNames(new ArrayList<>(deleteVidoeFile)).build());
  2233. //删除资源文件
  2234. if(CollUtil.isNotEmpty(deleteVidoeFile))
  2235. sceneUploadService.delete(
  2236. DeleteFileParamVO.builder().num(num)
  2237. .bizType(FileBizType.BOX_POSTER.code())
  2238. .fileNames(new ArrayList<>(deletePicFile)).build());
  2239. }else{
  2240. boxVideo.put("createTime", Calendar.getInstance().getTimeInMillis());
  2241. //更新
  2242. boolean exist = false;
  2243. for(int i=0;i<boxVideosJson.size();++i){
  2244. JSONObject ele = boxVideosJson.getJSONObject(i);
  2245. if(ele.getString("sid").equals(sid)){
  2246. boxVideosJson.set(i, boxVideo);
  2247. exist = true;
  2248. }
  2249. }
  2250. //新增
  2251. if(!exist){
  2252. boxVideosJson.add(boxVideo);
  2253. }
  2254. boxVideosJson.clear();
  2255. boxVideosJson.add(boxVideo);
  2256. }
  2257. if(boxVideosJson.size() != 0){
  2258. result = boxVideosJson.toJSONString();
  2259. }
  2260. return result;
  2261. }
  2262. private String createBoxPhotos(String num, String sid, JSONObject boxPhoto, SceneEditInfo sceneEditInfo, int type) throws Exception{
  2263. String boxPhotos = null;
  2264. if(sceneEditInfo != null){
  2265. boxPhotos = sceneEditInfo.getBoxPhotos();
  2266. }
  2267. JSONArray boxPhotosJson = null;
  2268. if (StrUtil.isNotEmpty(boxPhotos)) {
  2269. boxPhotosJson = JSONArray.parseArray(boxPhotos);
  2270. }else {
  2271. boxPhotosJson = new JSONArray();
  2272. }
  2273. String result = null;
  2274. //删除
  2275. if(type == OperationType.DELETE.code()){
  2276. Set<String> deleteFile = new HashSet<>();
  2277. if(boxPhotosJson.size() == 0)
  2278. return null;
  2279. for(int i=0;i<boxPhotosJson.size();++i){
  2280. JSONObject ele = boxPhotosJson.getJSONObject(i);
  2281. if(ele.getString("sid").equals(sid)){
  2282. String poster = ele.getString("poster");
  2283. if(StrUtil.isNotEmpty(poster))
  2284. deleteFile.add(poster);
  2285. String url = ele.getString("url");
  2286. if(StrUtil.isNotEmpty(url))
  2287. deleteFile.add(url);
  2288. boxPhotosJson.remove(i);
  2289. }
  2290. }
  2291. //删除资源文件
  2292. if(CollUtil.isNotEmpty(deleteFile))
  2293. sceneUploadService.delete(
  2294. DeleteFileParamVO.builder().num(num)
  2295. .bizType(FileBizType.BOX_VIDEO.code())
  2296. .fileNames(new ArrayList<>(deleteFile)).build());
  2297. }else{
  2298. //更新
  2299. boolean exist = false;
  2300. for(int i=0;i<boxPhotosJson.size();++i){
  2301. JSONObject ele = boxPhotosJson.getJSONObject(i);
  2302. if(ele.getString("sid").equals(sid)){
  2303. boxPhoto.put("createTime", ele.getLong("createTime"));
  2304. boxPhotosJson.set(i, boxPhoto);
  2305. exist = true;
  2306. }
  2307. }
  2308. //新增
  2309. if(!exist){
  2310. boxPhoto.put("createTime", Calendar.getInstance().getTimeInMillis());
  2311. boxPhotosJson.add(boxPhoto);
  2312. }
  2313. }
  2314. if(boxPhotosJson.size() != 0){
  2315. List<BoxPhotoBean> list = Lists.newArrayList();
  2316. for (Object o : boxPhotosJson) {
  2317. JSONObject jsonObject = (JSONObject)o;
  2318. list.add(BoxPhotoBean.builder().createTime(jsonObject.getLong("createTime")).boxPhoto(jsonObject).build());
  2319. }
  2320. //按创建时间倒叙排序
  2321. list.sort(Comparator.comparingLong(BoxPhotoBean::getCreateTime).reversed());
  2322. // list转JSONArray
  2323. JSONArray array = new JSONArray();
  2324. list.stream().forEach(bean->{
  2325. array.add(bean.getBoxPhoto());
  2326. });
  2327. result = array.toJSONString();
  2328. }
  2329. return result;
  2330. }
  2331. @Override
  2332. public ResultData deleteMosaics(DeleteMosaicParamVO param) throws Exception {
  2333. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  2334. if(Objects.isNull(scenePlus)){
  2335. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2336. }
  2337. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  2338. //如果redis数据丢失,从本地文件中同步马赛克数据到redis
  2339. this.syncMosaicFromFileToRedis(param.getNum());
  2340. String key = String.format(RedisKey.SCENE_MOSAIC_DATA, param.getNum());
  2341. redisUtil.hdel(key, param.getPanoIdList().toArray());
  2342. //写入本地文件,作为备份
  2343. this.writeMosaic(param.getNum());
  2344. //更新数据库
  2345. this.updateMosaicFlag(param.getNum());
  2346. //更新版本号
  2347. this.upgradeVersionById(sceneEditInfo.getId());
  2348. return ResultData.ok();
  2349. }
  2350. @Override
  2351. public List<JSONObject> getMosaicList(String num) throws Exception {
  2352. //如果redis数据丢失,从本地文件中同步马赛克数据到redis
  2353. this.syncMosaicFromFileToRedis(num);
  2354. String key = String.format(RedisKey.SCENE_MOSAIC_DATA, num);
  2355. Map<String, String> map = redisUtil.hmget(key);
  2356. if(CollUtil.isEmpty(map)){
  2357. ResultData.ok(new String[0]);
  2358. }
  2359. return map.values().stream()
  2360. .map(mosaic-> JSON.parseObject(mosaic))
  2361. .collect(Collectors.toList());
  2362. }
  2363. @Override
  2364. public ResultData addWaterMark(BaseFileParamVO param) throws Exception {
  2365. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  2366. if(Objects.isNull(scenePlus)){
  2367. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2368. }
  2369. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService
  2370. .getByScenePlusId(scenePlus.getId());
  2371. sceneEditInfoExt.setWaterMark(param.getFileName());
  2372. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  2373. return ResultData.ok();
  2374. }
  2375. @Override
  2376. public ResultData deleteWaterMark(BaseFileParamVO param) throws Exception {
  2377. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  2378. if(Objects.isNull(scenePlus)){
  2379. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2380. }
  2381. sceneUploadService.delete(
  2382. DeleteFileParamVO.builder()
  2383. .num(param.getNum())
  2384. .fileNames(Lists.newArrayList(param.getFileName()))
  2385. .bizType(FileBizType.WATERMARK.code()).build());
  2386. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId());
  2387. sceneEditInfoExt.setWaterMark("");
  2388. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  2389. return ResultData.ok();
  2390. }
  2391. @Override
  2392. public ResultData saveFilter(SaveFiltersParamVO param) throws Exception {
  2393. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  2394. if(Objects.isNull(scenePlus)){
  2395. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  2396. }
  2397. String key = String.format(RedisKey.SCENE_filter_DATA, param.getNum());
  2398. redisUtil.del(key);//前端将全量数据传过来,所以这里先清空历史数据,然后保存前端数据即可
  2399. JSONArray filterArr = JSON.parseArray(param.getData());
  2400. int filters = CommonStatus.YES.code();
  2401. //如果页面选择恢复默认,filters字段值为否
  2402. if(Objects.nonNull(param.getReset()) && param.getReset() == CommonStatus.YES.code().intValue()){
  2403. filters = CommonStatus.NO.code();
  2404. }else{
  2405. if(CollUtil.isNotEmpty(filterArr)){
  2406. List<String> filterList = filterArr.stream().map(item->JSON.toJSONString(item)).collect(Collectors.toList());
  2407. redisUtil.lRightPushAll(key, filterList);
  2408. }else{
  2409. filters = CommonStatus.NO.code();
  2410. }
  2411. }
  2412. //写本地文件,作为备份
  2413. this.writeFilter(param.getNum());
  2414. //更新数据库
  2415. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId());
  2416. sceneEditInfoExt.setFilters(filters);
  2417. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  2418. //更新版本号
  2419. this.upgradeVersionById(sceneEditInfoExt.getEditInfoId());
  2420. return ResultData.ok();
  2421. }
  2422. private void writeFilter(String num) throws Exception{
  2423. String filterPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "filter.json";
  2424. String key = String.format(RedisKey.SCENE_filter_DATA, num);
  2425. List<String> filters = redisUtil.lGet(key, 0, -1);
  2426. if(CollUtil.isEmpty(filters)){
  2427. FileUtils.deleteFile(filterPath);
  2428. return;
  2429. }
  2430. String lockKey = String.format(RedisLockKey.LOCK_filter_JSON, num);
  2431. String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
  2432. boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_1_MINUTE);
  2433. if(!lock){
  2434. return;
  2435. }
  2436. try{
  2437. FileUtils.writeFile(filterPath, JSON.toJSONString(filters));
  2438. }finally {
  2439. redisLockUtil.unlockLua(lockKey, lockVal);
  2440. }
  2441. }
  2442. private void syncFiltersFromFileToRedis(String num) throws Exception{
  2443. String key = String.format(RedisKey.SCENE_filter_DATA, num);
  2444. boolean exist = redisUtil.hasKey(key);
  2445. if(exist){
  2446. return;
  2447. }
  2448. String lockKey = String.format(RedisLockKey.LOCK_FILTER_DATA_SYNC, num);
  2449. String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
  2450. boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_1_MINUTE);
  2451. if(!lock){
  2452. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  2453. }
  2454. try{
  2455. exist = redisUtil.hasKey(key);
  2456. if(exist){
  2457. return;
  2458. }
  2459. String filePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  2460. String filterData = FileUtils.readUtf8String(filePath + "filter.json");
  2461. if(StrUtil.isEmpty(filterData)){
  2462. return;
  2463. }
  2464. JSONArray jsonArray = JSON.parseArray(filterData);
  2465. if(CollUtil.isEmpty(jsonArray)){
  2466. return;
  2467. }
  2468. redisUtil.lRightPushAll(key, jsonArray.stream().collect(Collectors.toList()));
  2469. }finally {
  2470. redisLockUtil.unlockLua(lockKey, lockVal);
  2471. }
  2472. }
  2473. @Override
  2474. public ResultData listFilter(BaseSceneParamVO param) throws Exception {
  2475. //同步数据
  2476. this.syncFiltersFromFileToRedis(param.getNum());
  2477. //查询redis
  2478. String key = String.format(RedisKey.SCENE_filter_DATA, param.getNum());
  2479. List<String> list = redisUtil.lGet(key, 0, -1);
  2480. List<JSONObject> collect =
  2481. list.stream().map(str -> JSON.parseObject(str)).collect(Collectors.toList());
  2482. return ResultData.ok(collect);
  2483. }
  2484. }