SceneEditInfoServiceImpl.java 123 KB

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