SceneEditInfoServiceImpl.java 123 KB

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