SceneEditInfoServiceImpl.java 122 KB

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