SceneEditInfoServiceImpl.java 123 KB

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