SceneEditInfoServiceImpl.java 127 KB

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