SceneEditInfoServiceImpl.java 127 KB

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