SceneEditInfoServiceImpl.java 123 KB

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