SceneEditInfoServiceImpl.java 129 KB

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