SceneEditInfoServiceImpl.java 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  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.img.ImgUtil;
  5. import cn.hutool.core.io.FileUtil;
  6. import cn.hutool.core.io.IoUtil;
  7. import cn.hutool.core.util.CharsetUtil;
  8. import cn.hutool.core.util.StrUtil;
  9. import cn.hutool.core.util.ZipUtil;
  10. import com.alibaba.fastjson.JSON;
  11. import com.alibaba.fastjson.JSONArray;
  12. import com.alibaba.fastjson.JSONObject;
  13. import com.baomidou.dynamic.datasource.annotation.DS;
  14. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  15. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  16. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  17. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  18. import com.fdkankan.common.constant.*;
  19. import com.fdkankan.common.exception.BusinessException;
  20. import com.fdkankan.common.util.FileUtils;
  21. import com.fdkankan.redis.constant.RedisKey;
  22. import com.fdkankan.redis.util.RedisClient;
  23. import com.fdkankan.scene.bean.BoxPhotoBean;
  24. import com.fdkankan.scene.bean.ResultData;
  25. import com.fdkankan.scene.bean.SceneJsonBean;
  26. import com.fdkankan.scene.bean.TagBean;
  27. import com.fdkankan.scene.entity.*;
  28. import com.fdkankan.scene.httpclient.CustomHttpClient;
  29. import com.fdkankan.scene.mapper.SceneEditInfoMapper;
  30. import com.fdkankan.scene.service.*;
  31. import com.fdkankan.scene.vo.*;
  32. import com.google.common.collect.Lists;
  33. import org.owasp.esapi.errors.EncodingException;
  34. import org.owasp.esapi.errors.ValidationException;
  35. import org.springframework.beans.factory.annotation.Autowired;
  36. import org.springframework.beans.factory.annotation.Value;
  37. import org.springframework.stereotype.Service;
  38. import org.springframework.transaction.annotation.Transactional;
  39. import org.springframework.web.multipart.MultipartFile;
  40. import javax.annotation.Resource;
  41. import java.io.File;
  42. import java.io.IOException;
  43. import java.io.InputStream;
  44. import java.nio.charset.StandardCharsets;
  45. import java.util.*;
  46. import java.util.concurrent.CompletableFuture;
  47. import java.util.stream.Collectors;
  48. /**
  49. * <p>
  50. * 服务实现类
  51. * </p>
  52. *
  53. * @author
  54. * @since 2024-10-09
  55. */
  56. @DS("vr")
  57. @Service
  58. public class SceneEditInfoServiceImpl extends ServiceImpl<SceneEditInfoMapper, SceneEditInfo> implements SceneEditInfoService {
  59. private final static String SQL_ADD_VERSION = "version=version+";
  60. @Value("${tieta.device-address:#{null}}")
  61. private String deviceAddress;
  62. //
  63. @Autowired
  64. private SceneEditControlsService sceneEditControlsService;
  65. @Resource
  66. private FYunFileService fYunFileService;
  67. @Resource
  68. private RedisClient redisClient;
  69. @Autowired
  70. private SceneEditInfoExtService sceneEditInfoExtService;
  71. @Autowired
  72. private SceneService sceneService;
  73. @Autowired
  74. private SceneFileMappingService sceneFileMappingService;
  75. @Resource
  76. CustomHttpClient customHttpClient;
  77. @Autowired
  78. private SceneAsynOperLogService sceneAsynOperLogService;
  79. @Autowired
  80. private ICommonService commonService;
  81. /**
  82. * 保存场景基础设置
  83. * @param param
  84. * @return com.fdkankan.scene.vo.SceneEditInfoVO
  85. */
  86. @Transactional
  87. @Override
  88. public SceneEditInfoVO saveScene(SceneEditInfoParamVO param) {
  89. //查询场景主表
  90. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  91. //场景不存在返回业务异常:场景为空
  92. if(Objects.isNull(scenePlus)){
  93. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  94. }
  95. SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId());
  96. SceneEditControls sceneEditControlsDb = null;
  97. if(Objects.nonNull(sceneEditInfoDb)){
  98. sceneEditControlsDb = sceneEditControlsService.getBySceneEditId(sceneEditInfoDb.getId());
  99. }
  100. //用户上传的文件后缀名转小写
  101. this.lowercaseExtName(param);
  102. SceneEditInfo sceneEditInfo = BeanUtil.copyProperties(param, SceneEditInfo.class);
  103. sceneEditInfo.setScenePlusId(scenePlus.getId());
  104. //编辑数据表记录,有则更新,无则插入
  105. if(Objects.isNull(sceneEditInfoDb)){
  106. this.save(sceneEditInfo);
  107. }else{
  108. sceneEditInfo.setId(sceneEditInfoDb.getId());
  109. sceneEditInfo.setVersion(sceneEditInfoDb.getVersion() + 1);
  110. this.updateById(sceneEditInfo);
  111. }
  112. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  113. if(Objects.isNull(sceneEditInfoExt)){
  114. sceneEditInfoExt = new SceneEditInfoExt();
  115. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  116. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  117. }
  118. if(Objects.nonNull(param.getSns())){
  119. sceneEditInfoExt.setSnsInfo(JSON.toJSONString(param.getSns()));
  120. }
  121. if(Objects.nonNull(param.getStarted())){
  122. sceneEditInfoExt.setStarted(JSON.toJSONString(param.getStarted()));
  123. }
  124. //更新场景编辑信息扩展表
  125. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  126. if(Objects.nonNull(param.getControls())){
  127. SceneEditControls sceneEditControls = BeanUtil.copyProperties(param.getControls(), SceneEditControls.class);
  128. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  129. if(Objects.isNull(sceneEditControlsDb)){
  130. sceneEditControlsService.save(sceneEditControls);
  131. }else{
  132. sceneEditControls.setId(sceneEditControlsDb.getId());
  133. sceneEditControlsService.updateById(sceneEditControls);
  134. }
  135. }
  136. scenePlus.setTitle(param.getTitle());
  137. scenePlus.setDescription(param.getDescription());
  138. //更新场景表
  139. sceneService.updateById(scenePlus);
  140. SceneEditInfoVO result = BeanUtil.copyProperties(param, SceneEditInfoVO.class);
  141. result.setCreateTime(sceneEditInfo.getCreateTime());
  142. return result;
  143. }
  144. private void lowercaseExtName(SceneEditInfoParamVO sceneEditInfo){
  145. if(StrUtil.isNotEmpty(sceneEditInfo.getMusic())){
  146. String extName = cn.hutool.core.io.FileUtil.extName(sceneEditInfo.getMusic());
  147. if(StrUtil.isNotEmpty(extName)){
  148. sceneEditInfo.setMusic(sceneEditInfo.getMusic().replace(extName, extName.toLowerCase()));
  149. }
  150. }
  151. if(StrUtil.isNotEmpty(sceneEditInfo.getMusicFile())){
  152. String extName = cn.hutool.core.io.FileUtil.extName(sceneEditInfo.getMusicFile());
  153. if(StrUtil.isNotEmpty(extName)){
  154. sceneEditInfo.setMusicFile(sceneEditInfo.getMusicFile().replace(extName, extName.toLowerCase()));
  155. }
  156. }
  157. }
  158. @Override
  159. public SceneEditInfo getByScenePlusId(long scenePlusId) {
  160. return this.getOne(new LambdaQueryWrapper<SceneEditInfo>()
  161. .eq(SceneEditInfo::getScenePlusId, scenePlusId));
  162. }
  163. private void publicFilterData(String num, Integer subgroup, String upTime, Integer cacheKeyHasTime, int filters) throws IOException, EncodingException, ValidationException {
  164. String userEditPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
  165. String fileKey = userEditPath + "filter.json";
  166. if(filters == CommonStatus.NO.code()){
  167. sceneFileMappingService.delByNumAndKey(num, subgroup, upTime, fileKey);
  168. return;
  169. }
  170. String key = String.format(RedisKey.SCENE_filter_DATA, RedisKey.getNumStr(num, subgroup, upTime, cacheKeyHasTime));
  171. List<String> list = redisClient.lGet(key, 0, -1);
  172. JSONArray jsonArray = new JSONArray();
  173. list.stream().forEach(str->jsonArray.add(JSON.parseObject(str)));
  174. fYunFileService.uploadFile(num, subgroup, upTime, JSON.toJSONBytes(jsonArray), userEditPath + "filter.json");
  175. }
  176. @Override
  177. public SceneInfoVO getSceneInfo(String num, Integer subgroup, String upTimeKey, byte reqType) throws Exception{
  178. SceneInfoReqType sceneInfoReqType = SceneInfoReqType.get(reqType);
  179. if(Objects.isNull(subgroup)){
  180. subgroup = 0;
  181. }
  182. SceneInfoVO sceneInfo = null;
  183. switch (sceneInfoReqType){
  184. //如果是编辑页面请求,查数据库
  185. case EDIT:
  186. sceneInfo = this.getSceneInfo4Edit(num, subgroup, upTimeKey);
  187. //俊波要求这两个字段编辑页一定是1
  188. sceneInfo.getControls().setShowDollhouse(CommonStatus.YES.code());
  189. sceneInfo.getControls().setShowFloorplan(CommonStatus.YES.code());
  190. break;
  191. //如果是查看页面请求,查redis
  192. case VIEW:
  193. sceneInfo = this.getSceneInfo4Edit(num, subgroup, upTimeKey);
  194. sceneInfo.setScenePassword(null);
  195. //俊波要求这两个字段查看页一定是0
  196. sceneInfo.getControls().setShowDollhouse(CommonStatus.NO.code());
  197. sceneInfo.getControls().setShowFloorplan(CommonStatus.NO.code());
  198. //查询机房列表
  199. List<Scene> sceneList = sceneService.listByStationcode(sceneInfo.getStationCode());
  200. List<Map<String, String>> roomList = new ArrayList<>();
  201. for (Scene scene : sceneList) {
  202. if(scene.getNum().equals(sceneInfo.getNum())){
  203. continue;
  204. }
  205. Map<String, String> item = new HashMap<>();
  206. item.put("stationCode", scene.getStationcode());
  207. item.put("roomEntityID", scene.getNum());
  208. item.put("title", scene.getTitle());
  209. roomList.add(item);
  210. }
  211. sceneInfo.setEntityList(roomList);
  212. //查询历史列表
  213. sceneInfo.setHistoryList(sceneService.listByNumLast3(sceneInfo.getNum()));
  214. break;
  215. default:
  216. break;
  217. }
  218. sceneInfo.setDeviceAddress(deviceAddress);
  219. return sceneInfo;
  220. }
  221. /**
  222. * <p>
  223. 编辑页面获取场景详情信息
  224. * </p>
  225. * @author dengsixing
  226. * @date 2022/1/21
  227. * @param num
  228. * @return com.fdkankan.scene.vo.SceneInfoVO
  229. **/
  230. private SceneInfoVO getSceneInfo4Edit(String num, Integer subgroup, String upTime) throws Exception{
  231. Scene scenePlus = sceneService.getByNum(num, subgroup, upTime);
  232. if(Objects.isNull(scenePlus)){
  233. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  234. }
  235. upTime = scenePlus.getUpTimeKey();
  236. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  237. if(Objects.isNull(sceneEditInfo)){
  238. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  239. }
  240. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  241. SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  242. SceneInfoVO sceneInfoVO = new SceneInfoVO();
  243. BeanUtil.copyProperties(sceneEditInfoExt, sceneInfoVO, "started");
  244. BeanUtil.copyProperties(sceneEditInfo, sceneInfoVO);
  245. sceneInfoVO.setFloorPlanUpload(JSON.parseArray(sceneEditInfo.getFloorPlanUpload()));
  246. if(Objects.isNull(sceneInfoVO.getFloorPlanAngle())){
  247. sceneInfoVO.setFloorPlanAngle(0f);
  248. }
  249. if(Objects.isNull(sceneInfoVO.getFloorPlanCompass())){
  250. sceneInfoVO.setFloorPlanCompass(0f);
  251. }
  252. sceneInfoVO.setControls(BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class));
  253. sceneInfoVO.setNum(num);
  254. sceneInfoVO.setSceneResolution(scenePlus.getSceneresolution());
  255. sceneInfoVO.setSceneFrom(scenePlus.getScenefrom());
  256. sceneInfoVO.setSceneKind(scenePlus.getScenekind());
  257. sceneInfoVO.setModelKind(scenePlus.getModelkind());
  258. if(CommonStatus.YES.code().intValue() == sceneEditInfoExt.getMosaic()){
  259. sceneInfoVO.setMosaicList(this.getMosaicList(num, subgroup, upTime));
  260. }
  261. sceneInfoVO.setSns(JSON.parseObject(sceneEditInfoExt.getSnsInfo()));
  262. sceneInfoVO.setStarted(JSON.parseObject(sceneEditInfoExt.getStarted()));
  263. sceneInfoVO.setSubgroup(scenePlus.getSubgroup());
  264. sceneInfoVO.setStationCode(scenePlus.getStationcode());
  265. sceneInfoVO.setExtinguisher(scenePlus.getExtinguisher());
  266. long count = sceneService.count(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getUpTimeKey, upTime).ne(Scene::getSubgroup, 0));
  267. if(count > 0){
  268. sceneInfoVO.setHasHighAndLow(CommonStatus.YES.code());
  269. }else{
  270. sceneInfoVO.setHasHighAndLow(CommonStatus.NO.code());
  271. }
  272. //读取全的vision.txt
  273. String visionTxtKey = String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt";
  274. List<SceneFileMapping> sceneFileMappings = sceneFileMappingService.list(
  275. new LambdaQueryWrapper<SceneFileMapping>()
  276. .eq(SceneFileMapping::getNum, num)
  277. .eq(SceneFileMapping::getUpTime, upTime)
  278. .eq(SceneFileMapping::getKey, visionTxtKey)
  279. .eq(SceneFileMapping::getSubgroup, -1));
  280. SceneFileMapping sceneFileMapping = null;
  281. if(CollUtil.isNotEmpty(sceneFileMappings)){
  282. sceneFileMapping = sceneFileMappings.get(0);
  283. String content = null;
  284. try (InputStream inputStream = customHttpClient.downloadFileToInputStream(sceneFileMapping.getUrl())){
  285. content = IoUtil.read(inputStream, StandardCharsets.UTF_8);
  286. }
  287. if(StrUtil.isNotEmpty(content)){
  288. sceneInfoVO.setVisions(JSON.parseObject(content));
  289. }
  290. }
  291. sceneInfoVO.setShootTime(scenePlus.getShootTime());
  292. sceneInfoVO.setUpTime(scenePlus.getUpTime());
  293. sceneInfoVO.setAlgorithmTime(scenePlus.getAlgorithmTime());
  294. sceneInfoVO.setId(scenePlus.getId());
  295. sceneInfoVO.setUpTimeKey(scenePlus.getUpTimeKey());
  296. return sceneInfoVO;
  297. }
  298. @Override
  299. public ResultData saveCad(BaseDataParamVO param) throws Exception {
  300. String num = param.getNum();
  301. Scene scenePlus = sceneService.getByNum(num, param.getSubgroup(),param.getUpTimeKey());
  302. if(Objects.isNull(scenePlus))
  303. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  304. String editUserPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
  305. JSONObject fileInfoJson = JSON.parseObject(param.getData());
  306. Float angel = null;
  307. Float compass = null;
  308. String floorJsonData = fileInfoJson.getString("floorJsonData");
  309. if(StrUtil.isNotBlank(floorJsonData)){
  310. JSONObject jsonObject = JSON.parseObject(floorJsonData);
  311. angel = jsonObject.getFloat("angle");
  312. compass = jsonObject.getFloat("compass");
  313. }
  314. //处理户型图数据
  315. //上传floorplan_user.json文件
  316. fYunFileService.uploadFile(num, param.getSubgroup(), param.getUpTimeKey(), floorJsonData.getBytes(StandardCharsets.UTF_8), editUserPath + "floorplan.json");
  317. //写入数据库
  318. Integer floorPlanUser = null;
  319. if(StrUtil.isNotEmpty(floorJsonData)){
  320. floorPlanUser = CommonStatus.YES.code();
  321. }
  322. SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId());
  323. if(Objects.nonNull(sceneEditInfoDb)){
  324. LambdaUpdateWrapper<SceneEditInfo> updateWrapper = new LambdaUpdateWrapper<SceneEditInfo>()
  325. .setSql(SQL_ADD_VERSION + 1)
  326. .eq(SceneEditInfo::getId, sceneEditInfoDb.getId());
  327. if(floorPlanUser != null){
  328. updateWrapper.set(SceneEditInfo::getFloorPlanUser, floorPlanUser);
  329. }
  330. this.update(updateWrapper);
  331. }else{
  332. sceneEditInfoDb = new SceneEditInfo();
  333. sceneEditInfoDb.setScenePlusId(scenePlus.getId());
  334. sceneEditInfoDb.setFloorPlanUser(floorPlanUser);
  335. this.save(sceneEditInfoDb);
  336. }
  337. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoDb.getId());
  338. if(Objects.isNull(sceneEditInfoExt)){
  339. sceneEditInfoExt = new SceneEditInfoExt();
  340. sceneEditInfoExt.setEditInfoId(sceneEditInfoDb.getId());
  341. }
  342. if(Objects.nonNull(angel)){
  343. sceneEditInfoExt.setFloorPlanAngle(angel);
  344. }
  345. if(Objects.nonNull(compass)){
  346. sceneEditInfoExt.setFloorPlanCompass(compass);
  347. }
  348. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  349. return ResultData.ok();
  350. }
  351. @Override
  352. public ResultData resetCad(String num, Integer subgroup, String upTime) throws IOException {
  353. Scene scenePlus = sceneService.getByNum(num, subgroup, upTime);
  354. if(Objects.isNull(scenePlus))
  355. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  356. SceneEditInfo sceneEditInfoDb = this.getByScenePlusId(scenePlus.getId());
  357. SceneEditInfoExt sceneEditInfoExt = null;
  358. if(Objects.nonNull(sceneEditInfoDb)){
  359. LambdaUpdateWrapper<SceneEditInfo> updateWrapper = new LambdaUpdateWrapper<SceneEditInfo>()
  360. .setSql(SQL_ADD_VERSION + 1)
  361. .set(SceneEditInfo::getFloorPlanUser, CommonStatus.NO.code())
  362. .eq(SceneEditInfo::getId, sceneEditInfoDb.getId());
  363. this.update(updateWrapper);
  364. sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoDb.getId());
  365. }else{
  366. sceneEditInfoDb = new SceneEditInfo();
  367. sceneEditInfoDb.setScenePlusId(scenePlus.getId());
  368. sceneEditInfoDb.setFloorPlanUser(CommonStatus.NO.code());
  369. this.save(sceneEditInfoDb);
  370. }
  371. if(Objects.isNull(sceneEditInfoExt)){
  372. sceneEditInfoExt = new SceneEditInfoExt();
  373. sceneEditInfoDb.setScenePlusId(scenePlus.getId());
  374. sceneEditInfoExt.setEditInfoId(sceneEditInfoDb.getId());
  375. }
  376. sceneEditInfoExt.setFloorPlanAngle(0f);
  377. sceneEditInfoExt.setFloorPlanCompass(0f);
  378. sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
  379. return ResultData.ok();
  380. }
  381. @Override
  382. public ResultData renameCad(RenameCadParamVO param) throws IOException, EncodingException, ValidationException {
  383. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  384. if(Objects.isNull(scenePlus)){
  385. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  386. }
  387. String key = String.format(UploadFilePath.USER_VIEW_PATH, param.getNum()) + "floorplan.json";
  388. String floorplanJson = fYunFileService.getFileContent(key, param.getSubgroup(), param.getUpTimeKey());
  389. if(StrUtil.isEmpty(floorplanJson)){
  390. return ResultData.ok();
  391. }
  392. Map<Integer, String> renameMap = new HashMap<>();
  393. param.getFloors().stream().forEach(floor->{
  394. renameMap.put(floor.getSubgroup(), floor.getName());
  395. });
  396. JSONObject jsonObject = JSON.parseObject(floorplanJson);
  397. if(Objects.isNull(jsonObject)){
  398. return ResultData.ok();
  399. }
  400. JSONArray floorArr = jsonObject.getJSONArray("floors");
  401. if(CollUtil.isEmpty(floorArr)){
  402. return ResultData.ok();
  403. }
  404. for (Object o : floorArr) {
  405. JSONObject item = (JSONObject)o;
  406. int subgroup = item.getIntValue("subgroup");
  407. String name = renameMap.get(subgroup);
  408. if(StrUtil.isEmpty(name)){
  409. continue;
  410. }
  411. item.put("name", name);
  412. }
  413. fYunFileService.uploadFile(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), jsonObject.toJSONString().getBytes(), key);
  414. return ResultData.ok();
  415. }
  416. @Override
  417. public void upgradeVersionById(Long id) {
  418. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  419. .setSql(SQL_ADD_VERSION + 1)
  420. .eq(SceneEditInfo::getId, id));
  421. }
  422. @Override
  423. public void upgradeVersionAndImgVersionById(Long id) {
  424. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  425. .setSql("version=version + " + 1)
  426. .setSql("img_version=img_version + " + 1)
  427. .eq(SceneEditInfo::getId, id));
  428. }
  429. @Override
  430. public void upgradeSceneJsonVersion(String num, Integer subgroup, String upTime, Integer cacheKeyHasTime, int version, Integer imgVersion) throws IOException, EncodingException, ValidationException {
  431. //更新redis缓存版本号
  432. String key = String.format(RedisKey.SCENE_JSON, RedisKey.getNumStr(num, subgroup, upTime, cacheKeyHasTime));
  433. String sceneJson = redisClient.get(key);
  434. if(StrUtil.isNotEmpty(sceneJson)){
  435. SceneJsonBean sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
  436. if(Objects.nonNull(version)){
  437. sceneJsonBean.setVersion(version);
  438. }
  439. if(Objects.nonNull(imgVersion)){
  440. sceneJsonBean.setImgVersion(imgVersion);
  441. }
  442. redisClient.add(key, JSON.toJSONString(sceneJsonBean));
  443. }
  444. //更新oss scene.json版本号
  445. String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
  446. sceneJson= fYunFileService.getFileContent(sceneJsonPath, subgroup, upTime);
  447. if(StrUtil.isNotEmpty(sceneJson)){
  448. SceneJsonBean sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
  449. if(Objects.nonNull(version)){
  450. sceneJsonBean.setVersion(version);
  451. }
  452. if(Objects.nonNull(imgVersion)){
  453. sceneJsonBean.setImgVersion(imgVersion);
  454. }
  455. fYunFileService.uploadFile(num, subgroup, upTime, JSON.toJSONString(sceneJsonBean).getBytes(StandardCharsets.UTF_8), sceneJsonPath);
  456. }
  457. }
  458. // @Override
  459. // public ResultData uploadPanorama(String num, Integer subgroup, String upTime, MultipartFile file) throws Exception {
  460. //
  461. // if(!file.getOriginalFilename().endsWith(".zip") && !file.getOriginalFilename().endsWith(".jpg")){
  462. // throw new BusinessException(ErrorCode.FAILURE_CODE_7007, "jpg或者zip");
  463. // }
  464. //
  465. // Scene scenePlus = sceneService.getByNum(num, subgroup, upTime);
  466. // if(scenePlus == null){
  467. // throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  468. // }
  469. //
  470. // //查询是否存在等待中的异步操作记录,如果存在,抛出业务异常,终止操作
  471. // sceneAsynOperLogService.checkSceneAsynOper(scenePlus.getId(), null, SceneAsynModuleType.UPLOAD_DOWNLOAD.code() , SceneAsynFuncType.PANORAMIC_IMAGE.code());
  472. //
  473. // //清除全景图异步操作记录,防止再次下载的时候请求到旧的压缩包
  474. // sceneAsynOperLogService.cleanLog(scenePlus.getId(), SceneAsynModuleType.UPLOAD_DOWNLOAD.code(), SceneAsynFuncType.PANORAMIC_IMAGE.code());
  475. //
  476. // //原始计算根目录
  477. // String numStr = RedisKey.getNumStr(num, subgroup, upTime, scenePlus.getCacheKeyHasTime());
  478. // String path = String.format(ConstantFilePath.SCENE_USER_PATH_V4, numStr);
  479. // //全景图计算根目录
  480. // String target = path + "_images";
  481. // //解压缩文件存放目录
  482. // String targetImagesPath = target + "/extras/images/";
  483. // //压缩文件保存目录
  484. // String zipTargetFilePath = targetImagesPath + file.getOriginalFilename();
  485. //
  486. // //先删除本地文件
  487. // FileUtil.del(targetImagesPath);
  488. // File targetFile = new File(zipTargetFilePath);
  489. // if(!targetFile.getParentFile().exists()){
  490. // targetFile.getParentFile().mkdirs();
  491. // }
  492. // file.transferTo(targetFile);
  493. //
  494. // //如果是压缩包上传,需要解压缩
  495. // int async = CommonStatus.NO.code();
  496. // if(file.getOriginalFilename().endsWith(".zip")){
  497. //
  498. // //标记为异步处理
  499. // async = CommonStatus.YES.code();
  500. //
  501. // //解压zip包
  502. // ZipUtil.unzip(zipTargetFilePath,targetImagesPath, CharsetUtil.CHARSET_GBK);
  503. // //删除压缩包
  504. // FileUtil.del(zipTargetFilePath);
  505. // }
  506. //
  507. // //判断文件夹目录结构,图片必须放在压缩包根目录下,不支持空文件夹或其他格式文件上传
  508. // File[] files = new File(targetImagesPath).listFiles();
  509. // Arrays.stream(files).forEach(item->{
  510. // if(item.isDirectory()){
  511. // throw new BusinessException(ErrorCode.FAILURE_CODE_7018);
  512. // }
  513. // });
  514. //
  515. // //获取解压后的文件列表
  516. // List<String> uploadFileList = FileUtils.getFileList(targetImagesPath);
  517. // if(CollUtil.isEmpty(uploadFileList)){
  518. // throw new BusinessException(ErrorCode.FAILURE_CODE_5062);
  519. // }
  520. //
  521. // //判断是否有可用的jpg文件
  522. // boolean existJpg = false;
  523. // if(CollUtil.isNotEmpty(uploadFileList)){
  524. // existJpg = uploadFileList.stream().anyMatch(str -> {
  525. // if(str.endsWith(".jpg")){
  526. // return true;
  527. // }
  528. // return false;
  529. // });
  530. // }
  531. // if(!existJpg){
  532. // throw new BusinessException(ErrorCode.FAILURE_CODE_5062);
  533. // }
  534. //
  535. // //比对图片列表,不存在的要返回名称集合
  536. // List<SceneFileMapping> sceneFileMappings = sceneFileMappingService.getByScene(num, subgroup, upTime);
  537. // List<SceneFileMapping> panList = sceneFileMappings.stream().filter(v -> v.getKey().contains("images/pan/high/")).collect(Collectors.toList());
  538. // Map<String, SceneFileMapping> panMap = panList.stream().collect(Collectors.toMap(v -> FileUtil.getName(v.getKey()), v -> v));
  539. // List<String> panoramaImageList = panList.stream().map(v -> FileUtil.getName(v.getKey())).collect(Collectors.toList());
  540. //
  541. // List<String> notExistFileList = uploadFileList.stream().filter(filePath -> {
  542. // filePath = filePath.substring(filePath.lastIndexOf(File.separator) + 1);
  543. // if(CollUtil.isEmpty(panoramaImageList) || panoramaImageList.contains(filePath)){
  544. // return false;
  545. // }
  546. // return true;
  547. // }).collect(Collectors.toList());
  548. //
  549. // if(CollUtil.isNotEmpty(notExistFileList)){
  550. // //删除错误文件
  551. // notExistFileList.parallelStream().forEach(filePath->{
  552. // FileUtil.del(filePath);
  553. // });
  554. // }
  555. //
  556. // //判断成功的图片,如果成功图片为0,就直接返回,不需要执行算法
  557. // uploadFileList = FileUtils.getFileList(targetImagesPath);
  558. // if(CollUtil.isEmpty(uploadFileList)){
  559. // if(CollUtil.isNotEmpty(notExistFileList)){
  560. // notExistFileList = notExistFileList.stream().map(filePath -> {
  561. // return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
  562. // }).collect(Collectors.toList());
  563. // }
  564. // return ResultData.ok(new UploadPanoramaVO(0,0, notExistFileList));
  565. // }
  566. //
  567. // //上传
  568. // Map<String, String> map = new HashMap<>();
  569. //
  570. // String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  571. //
  572. // //如果部分成功,则需要返回成功数量和失败列表
  573. // if(CollUtil.isNotEmpty(notExistFileList)){
  574. // notExistFileList = notExistFileList.stream().map(filePath -> {
  575. // return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
  576. // }).collect(Collectors.toList());
  577. // }
  578. //
  579. // UploadPanoramaVO uploadPanoramaVO = new UploadPanoramaVO();
  580. // uploadPanoramaVO.setAsyn(async);
  581. // if(async == CommonStatus.YES.code().intValue()){
  582. // List<String> finalUploadFileList = uploadFileList;
  583. // List<String> finalNotExistFileList = notExistFileList;
  584. // CompletableFuture.runAsync(() -> {
  585. // SceneAsynOperLog sceneAsynOperLog = new SceneAsynOperLog();
  586. // sceneAsynOperLog.setNum(num);
  587. // sceneAsynOperLog.setOperType(SceneAsynOperType.UPLOAD.code());
  588. // sceneAsynOperLog.setModule(SceneAsynModuleType.UPLOAD_DOWNLOAD.code());
  589. // sceneAsynOperLog.setFunc(SceneAsynFuncType.PANORAMIC_IMAGE.code());
  590. // if(CollUtil.isNotEmpty(finalNotExistFileList)){
  591. // Map<String, Object> extData = new HashMap<>();
  592. // extData.put("successCnt", finalUploadFileList.size());
  593. // extData.put("failList", finalNotExistFileList);
  594. // sceneAsynOperLog.setExtData(JSON.toJSONString(extData));
  595. // }
  596. // sceneAsynOperLogService.save(sceneAsynOperLog);
  597. // try {
  598. // this.uploadPanoramaHandler(num,subgroup,upTime,target,imgViewPath, finalUploadFileList,targetImagesPath);
  599. // sceneAsynOperLog.setState(CommonOperStatus.SUCCESS.code());
  600. // } catch (Exception e) {
  601. // log.error("上传全景图报错,num:" + num, e);
  602. // sceneAsynOperLog.setState(CommonOperStatus.FAILD.code());
  603. // }
  604. // sceneAsynOperLogService.updateById(sceneAsynOperLog);
  605. // });
  606. // }else{
  607. // this.uploadPanoramaHandler(num,subgroup,upTime,target,imgViewPath,uploadFileList,targetImagesPath);
  608. // if(CollUtil.isNotEmpty(notExistFileList)){
  609. // uploadPanoramaVO.setSuccessCnt(uploadFileList.size());
  610. // uploadPanoramaVO.setFailList(notExistFileList);
  611. // }
  612. // }
  613. //
  614. // FileUtil.del(target);
  615. // return ResultData.ok(uploadPanoramaVO);
  616. // }
  617. //
  618. // public void uploadPanoramaHandler(String num, Integer subgroup, String upTime, String target, String imgViewPath, List<String> uploadFileList, String targetImagesPath) throws Exception {
  619. //
  620. // Map<String, String> map = new HashMap<>();
  621. // String resultPath = target + File.separator + "results/";
  622. // FileUtil.mkdir(resultPath);
  623. //
  624. // //4K
  625. // String highPath = resultPath + "pan/high/";
  626. // //512
  627. // String lowPath = resultPath + "pan/low/";
  628. // List<String> origImgs = FileUtil.listFileNames(targetImagesPath);
  629. // for (String origImg : origImgs) {
  630. // FileUtil.copy(targetImagesPath + origImg, highPath + origImg, true);
  631. // map.put(highPath + origImg, imgViewPath + "pan/high/" + origImg);
  632. // ImgUtil.scale(new File(highPath + origImg), new File(lowPath + origImg), 0.125f);
  633. // map.put(lowPath + origImg, imgViewPath + "pan/low/" + origImg);
  634. // }
  635. //
  636. // if(map.size()>0) {
  637. // fYunFileService.uploadMulFiles(num, subgroup, upTime, map);
  638. // }
  639. //
  640. // //更新数据库版本号
  641. // Scene scenePlus = sceneService.getByNum(num, subgroup, upTime);
  642. // SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  643. // this.upgradeVersionAndImgVersionById(sceneEditInfo.getId());
  644. // //更新scenejson缓存和oss文件版本号
  645. // this.upgradeSceneJsonVersion(num, subgroup, upTime, scenePlus.getCacheKeyHasTime(), sceneEditInfo.getVersion() + 1, sceneEditInfo.getImgVersion() + 1);
  646. // }
  647. //
  648. // @Override
  649. // public ResultData downloadPanorama(FileParamVO param) throws Exception {
  650. //
  651. // String num = param.getNum();
  652. // Integer subgroup = param.getSubgroup();
  653. // String upTimeKey = param.getUpTimeKey();
  654. // String fileName = param.getFileName();
  655. //
  656. // Scene scenePlus = sceneService.getByNum(num, subgroup, upTimeKey);
  657. // if(Objects.isNull(scenePlus)){
  658. // throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  659. // }
  660. //
  661. // //查询是否存在等待中的异步操作记录,如果存在,抛出业务异常,终止操作
  662. // sceneAsynOperLogService.checkSceneAsynOper(scenePlus.getId(),null, SceneAsynModuleType.UPLOAD_DOWNLOAD.code() , SceneAsynFuncType.PANORAMIC_IMAGE.code());
  663. //
  664. // String numStr = RedisKey.getNumStr(num, subgroup, upTimeKey, scenePlus.getCacheKeyHasTime());
  665. // String cachePath = String.format(ConstantFilePath.SCENE_CACHE, numStr);
  666. // String localImagesPath = String.format(ConstantFilePath.SCENE_CACHE_IMAGES, numStr);
  667. //
  668. // String cacheFormat = "downloads/scene/%s/caches/";
  669. // String cacheImageFormat = "downloads/scene/%s/caches/images/";
  670. //
  671. // List<SceneFileMapping> sceneFileMappings = sceneFileMappingService.getByScene(num, subgroup, upTimeKey);
  672. // List<SceneFileMapping> panList = sceneFileMappings.stream().filter(v -> v.getKey().contains("images/pan/high/")).collect(Collectors.toList());
  673. // Map<String, SceneFileMapping> panMap = panList.stream().collect(Collectors.toMap(v -> FileUtil.getName(v.getKey()), v -> v));
  674. //
  675. //// List<String> panoramaImageList = panList.stream().map(v -> FileUtil.getName(v.getKey())).collect(Collectors.toList());
  676. //
  677. // Map<String, Object> map = new HashMap<>();
  678. //
  679. // //标记是否是异步操作,默认是同步操作
  680. // //如果入参文件名不为空,则是单个文件下载,不需要打包
  681. // if(StrUtil.isNotEmpty(fileName)){
  682. // if(!panMap.keySet().contains(fileName)){
  683. // throw new BusinessException(ErrorCode.FAILURE_CODE_5063);
  684. // }
  685. // String url = panMap.get(fileName).getKey();
  686. // String downloadName = fileName;
  687. // map.put("asyn", CommonStatus.NO.code());
  688. // map.put("fileUrl", url);
  689. // map.put("fileName", downloadName);
  690. // return ResultData.ok(map);
  691. // }else{
  692. // //清除旧的下载记录
  693. // sceneAsynOperLogService.cleanLog(scenePlus.getId(), SceneAsynModuleType.UPLOAD_DOWNLOAD.code(), SceneAsynFuncType.PANORAMIC_IMAGE.code(), SceneAsynOperType.DOWNLOAD.code());
  694. //
  695. // //开始异步执行下载全景图压缩包操作
  696. // CompletableFuture.runAsync(() -> {
  697. // SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  698. // SceneAsynOperLog sceneAsynOperLog = new SceneAsynOperLog();
  699. // sceneAsynOperLog.setNum(num);
  700. // sceneAsynOperLog.setSceneId(scenePlus.getId());
  701. // sceneAsynOperLog.setOperType(SceneAsynOperType.DOWNLOAD.code());
  702. // sceneAsynOperLog.setModule(SceneAsynModuleType.UPLOAD_DOWNLOAD.code());
  703. // sceneAsynOperLog.setFunc(SceneAsynFuncType.PANORAMIC_IMAGE.code());
  704. // sceneAsynOperLog.setVersion(sceneEditInfo.getImgVersion());
  705. // sceneAsynOperLogService.save(sceneAsynOperLog);
  706. // try {
  707. //
  708. // //下载到本地目录
  709. // FileUtil.del(localImagesPath);
  710. // for (SceneFileMapping sceneFileMapping : panList) {
  711. // customHttpClient.downloadFile(sceneFileMapping.getUrl(), localImagesPath, fileName);
  712. //
  713. // }
  714. //
  715. // String downloadName = num + "_images.zip";
  716. // //打包
  717. // String zipPath = cachePath + downloadName;
  718. // ZipUtil.zip(localImagesPath, zipPath);
  719. // //上传压缩包
  720. // fYunFileService.uploadFile(num, subgroup,upTimeKey,zipPath, String.format(cacheFormat, num) + downloadName);
  721. // String url = String.format(cacheFormat, num) + downloadName;
  722. // //删除本地压缩包
  723. // FileUtil.del(zipPath);
  724. // //删除本地目录
  725. // FileUtil.del(localImagesPath);
  726. // sceneAsynOperLog.setState(CommonOperStatus.SUCCESS.code());
  727. // sceneAsynOperLog.setUrl(url);
  728. // }catch (Exception e){
  729. // sceneAsynOperLog.setState(CommonOperStatus.FAILD.code());
  730. // log.error("下载全景图压缩包失败,num:" + num, e);
  731. // }
  732. // sceneAsynOperLogService.saveOrUpdate(sceneAsynOperLog);
  733. // });
  734. //
  735. // map.put("asyn", CommonStatus.YES.code());
  736. // return ResultData.ok(map);
  737. // }
  738. // }
  739. @Override
  740. public void saveTagsToSceneEditInfo(String num, Integer subgroup, String upTime, Integer cacheKeyHasTime, SceneEditInfo sceneEditInfo){
  741. //查询缓存是否包含热点数据
  742. String key = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(num, subgroup, upTime, cacheKeyHasTime));
  743. Map<String, String> allTagsMap = redisClient.hmget(key);
  744. boolean hashTags = false;
  745. for (Map.Entry<String, String> tagMap : allTagsMap.entrySet()) {
  746. if(StrUtil.isEmpty(tagMap.getValue())){
  747. continue;
  748. }
  749. hashTags = true;
  750. break;
  751. }
  752. //更改热点状态
  753. sceneEditInfo.setTags(hashTags ? CommonStatus.YES.code() : CommonStatus.NO.code());
  754. //version 是空的代表 sceneEditInfo记录集不存在
  755. if(sceneEditInfo.getVersion() != null){
  756. sceneEditInfo.setVersion(sceneEditInfo.getVersion() + 1);
  757. }
  758. }
  759. @Override
  760. public ResultData checkKey(SceneCheckKeyParamVO param) throws Exception {
  761. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  762. if(Objects.isNull(scenePlus)){
  763. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  764. }
  765. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  766. if(!param.getPassword().equals(sceneEditInfo.getScenePassword())){
  767. throw new BusinessException(ErrorCode.FAILURE_CODE_5021);
  768. }
  769. return ResultData.ok();
  770. }
  771. @Override
  772. public ResultData addMosaics(BaseDataParamVO param) throws Exception {
  773. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  774. if(Objects.isNull(scenePlus)){
  775. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  776. }
  777. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  778. Map<String, String> map = new HashMap<>();
  779. JSONArray jsonArray = JSON.parseArray(param.getData());
  780. for (Object o : jsonArray) {
  781. JSONObject mosaic = (JSONObject) o;
  782. String panoId = mosaic.getString("panoId");
  783. if(StrUtil.isEmpty(panoId)){
  784. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  785. }
  786. map.put(panoId, JSON.toJSONString(mosaic));
  787. }
  788. String key = String.format(RedisKey.SCENE_MOSAIC_DATA, RedisKey.getNumStr(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime()));
  789. redisClient.hmset(key, map);
  790. //更新数据库
  791. this.updateMosaicFlag(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime());
  792. //更新版本号
  793. this.upgradeVersionById(sceneEditInfo.getId());
  794. return ResultData.ok();
  795. }
  796. private void updateMosaicFlag(String num, Integer subgroup, String upTime, Integer cacheKeyHasTime){
  797. Scene scenePlus = sceneService.getByNum(num, subgroup, upTime);
  798. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId());
  799. String key = String.format(RedisKey.SCENE_MOSAIC_DATA, RedisKey.getNumStr(num, subgroup, upTime, cacheKeyHasTime));
  800. Map<String, String> hmget = redisClient.hmget(key);
  801. if(CollUtil.isNotEmpty(hmget)){
  802. sceneEditInfoExt.setMosaic(CommonStatus.YES.code());
  803. }else{
  804. sceneEditInfoExt.setMosaic(CommonStatus.NO.code());
  805. }
  806. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  807. }
  808. @Override
  809. public ResultData listLinkPan(String num, Integer subgroup, String upTime) throws Exception {
  810. JSONObject result = new JSONObject();
  811. // //查询场景关联数据
  812. List<JSONObject> tags = Lists.newArrayList();
  813. result.put("tags", tags);
  814. // //封装styles数据
  815. List<JSONObject> styles = Lists.newArrayList();
  816. result.put("styles", styles);
  817. return ResultData.ok(result);
  818. }
  819. @Override
  820. public ResultData deleteMosaics(DeleteMosaicParamVO param) throws Exception {
  821. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  822. if(Objects.isNull(scenePlus)){
  823. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  824. }
  825. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  826. String key = String.format(RedisKey.SCENE_MOSAIC_DATA, RedisKey.getNumStr(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime()));
  827. redisClient.hdel(key, param.getPanoIdList());
  828. //更新数据库
  829. this.updateMosaicFlag(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime());
  830. //更新版本号
  831. this.upgradeVersionById(sceneEditInfo.getId());
  832. return ResultData.ok();
  833. }
  834. @Override
  835. public List<JSONObject> getMosaicList(String num, Integer subgroup, String upTime) throws Exception {
  836. Scene scene = sceneService.getByNum(num, subgroup, upTime);
  837. if(Objects.isNull(scene)){
  838. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  839. }
  840. String key = String.format(RedisKey.SCENE_MOSAIC_DATA, RedisKey.getNumStr(num, subgroup, upTime, scene.getCacheKeyHasTime()));
  841. Map<String, String> map = redisClient.hmget(key);
  842. if(CollUtil.isEmpty(map)){
  843. ResultData.ok(new String[0]);
  844. }
  845. return map.values().stream()
  846. .map(mosaic-> JSON.parseObject(mosaic))
  847. .collect(Collectors.toList());
  848. }
  849. @Override
  850. public ResultData addWaterMark(BaseFileParamVO param) throws Exception {
  851. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  852. if(Objects.isNull(scenePlus)){
  853. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  854. }
  855. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService
  856. .getByScenePlusId(scenePlus.getId());
  857. sceneEditInfoExt.setWaterMark(param.getFileName());
  858. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  859. return ResultData.ok();
  860. }
  861. @Override
  862. public ResultData deleteWaterMark(BaseFileParamVO param) throws Exception {
  863. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  864. if(Objects.isNull(scenePlus)){
  865. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  866. }
  867. String key = String.format(UploadFilePath.USER_VIEW_PATH, param.getNum()) + param.getFileName();
  868. fYunFileService.deleteFile(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), key);
  869. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId());
  870. sceneEditInfoExt.setWaterMark("");
  871. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  872. return ResultData.ok();
  873. }
  874. @Override
  875. public ResultData saveFilter(SaveFiltersParamVO param) throws Exception {
  876. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  877. if(Objects.isNull(scenePlus)){
  878. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  879. }
  880. String key = String.format(RedisKey.SCENE_filter_DATA, RedisKey.getNumStr(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime()));
  881. //前端将全量数据传过来,所以这里先清空历史数据,然后保存前端数据即可
  882. redisClient.del(key);
  883. JSONArray filterArr = JSON.parseArray(param.getData());
  884. int filters = CommonStatus.YES.code();
  885. //如果页面选择恢复默认,filters字段值为否
  886. if(Objects.nonNull(param.getReset()) && param.getReset() == CommonStatus.YES.code().intValue()){
  887. filters = CommonStatus.NO.code();
  888. }else{
  889. if(CollUtil.isNotEmpty(filterArr)){
  890. List<String> filterList = filterArr.stream().map(v->JSON.toJSONString(v)).collect(Collectors.toList());
  891. redisClient.lLeftPush(key, filterList);
  892. }else{
  893. filters = CommonStatus.NO.code();
  894. }
  895. }
  896. //更新数据库
  897. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId());
  898. sceneEditInfoExt.setFilters(filters);
  899. sceneEditInfoExtService.updateById(sceneEditInfoExt);
  900. //更新版本号
  901. this.upgradeVersionById(sceneEditInfoExt.getEditInfoId());
  902. this.publicFilterData(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime(), filters);
  903. return ResultData.ok();
  904. }
  905. @Override
  906. public ResultData listFilter(BaseSceneParamVO param) throws Exception {
  907. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  908. if(Objects.isNull(scenePlus)){
  909. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  910. }
  911. //查询redis
  912. String key = String.format(RedisKey.SCENE_filter_DATA, RedisKey.getNumStr(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime()));
  913. List<String> list = redisClient.lGet(key, 0, -1);
  914. List<JSONObject> collect =
  915. list.stream().map(str -> JSON.parseObject(str)).collect(Collectors.toList());
  916. return ResultData.ok(collect);
  917. }
  918. @Override
  919. public ResultData saveVideoBox(FileNameAndDataParamVO param) throws Exception {
  920. JSONObject boxVideo = JSONObject.parseObject(param.getData());
  921. String sid = boxVideo.getString("sid");
  922. if(StrUtil.isEmpty(sid)){
  923. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  924. }
  925. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  926. if(Objects.isNull(scenePlus))
  927. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  928. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  929. //转换视频格式
  930. commonService.transferToFlv(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), scenePlus.getCacheKeyHasTime(), param.getFileName());
  931. //生成boxVideos数据
  932. String boxVideos = this.createBoxVideos(sid, boxVideo, sceneEditInfo, OperationType.ADDORUPDATE.code());
  933. //更新数据库
  934. this.updateBoxVideos(sceneEditInfo, scenePlus.getId(), boxVideos);
  935. return ResultData.ok();
  936. }
  937. @Override
  938. public ResultData deleteVideoBox(DeleteSidParamVO param) throws Exception {
  939. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  940. if(Objects.isNull(scenePlus))
  941. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  942. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  943. //根据sid移除json
  944. String boxVideos = this.createBoxVideos(param.getSid(), null, sceneEditInfo, OperationType.DELETE.code());
  945. //写数据库
  946. this.updateBoxVideos(sceneEditInfo,scenePlus.getId(),boxVideos);
  947. return ResultData.ok();
  948. }
  949. private String createBoxVideos(String sid, JSONObject boxVideo,
  950. SceneEditInfo sceneEditInfo, int type) throws Exception{
  951. String boxVideos = null;
  952. if(sceneEditInfo != null){
  953. boxVideos = sceneEditInfo.getBoxVideos();
  954. }
  955. JSONArray boxVideosJson = null;
  956. if (StrUtil.isNotEmpty(boxVideos)) {
  957. boxVideosJson = JSONArray.parseArray(boxVideos);
  958. }else {
  959. boxVideosJson = new JSONArray();
  960. }
  961. if(boxVideosJson.size() > 0){
  962. int i = 1;
  963. long timeInMillis = Calendar.getInstance().getTimeInMillis();
  964. for (Object o : boxVideosJson) {
  965. JSONObject item = (JSONObject)o;
  966. if(Objects.nonNull(item.getLong(ConstantField.CREATE_TIME))){
  967. continue;
  968. }
  969. item.put(ConstantField.CREATE_TIME, timeInMillis - (i++));
  970. }
  971. }
  972. String result = null;
  973. //删除
  974. if(type == OperationType.DELETE.code()){
  975. Set<String> deleteVidoeFile = new HashSet<>();
  976. Set<String> deletePicFile = new HashSet<>();
  977. if(boxVideosJson.size() == 0)
  978. return null;
  979. for(int i=0;i<boxVideosJson.size();++i){
  980. JSONObject ele = boxVideosJson.getJSONObject(i);
  981. if(ele.getString("sid").equals(sid)){
  982. String poster = ele.getString("poster");
  983. if(StrUtil.isNotEmpty(poster))
  984. deletePicFile.add(poster);
  985. String url = ele.getString("url");
  986. if(StrUtil.isNotEmpty(url)){
  987. deleteVidoeFile.add(url);
  988. deleteVidoeFile.add(url.replace(".mp4",".flv"));
  989. }
  990. boxVideosJson.remove(i);
  991. }
  992. }
  993. }else{
  994. boxVideo.put(ConstantField.CREATE_TIME, Calendar.getInstance().getTimeInMillis());
  995. //更新
  996. boolean exist = false;
  997. for(int i=0;i<boxVideosJson.size();++i){
  998. JSONObject ele = boxVideosJson.getJSONObject(i);
  999. if(ele.getString("sid").equals(sid)){
  1000. boxVideosJson.set(i, boxVideo);
  1001. exist = true;
  1002. }
  1003. }
  1004. //新增
  1005. if(!exist){
  1006. boxVideosJson.add(boxVideo);
  1007. }
  1008. boxVideosJson.clear();
  1009. boxVideosJson.add(boxVideo);
  1010. }
  1011. if(boxVideosJson.size() != 0){
  1012. result = boxVideosJson.toJSONString();
  1013. }
  1014. return result;
  1015. }
  1016. private void updateBoxVideos(SceneEditInfo sceneEditInfo, Long scenePlusId, String boxVideos){
  1017. if(Objects.isNull(sceneEditInfo)){
  1018. sceneEditInfo = new SceneEditInfo();
  1019. sceneEditInfo.setScenePlusId(scenePlusId);
  1020. sceneEditInfo.setBoxVideos(boxVideos);
  1021. this.save(sceneEditInfo);
  1022. }else{
  1023. this.update(new UpdateWrapper<SceneEditInfo>()
  1024. .setSql("version = version + 1")
  1025. .set("box_videos", boxVideos)
  1026. .eq("id", sceneEditInfo.getId()));
  1027. }
  1028. }
  1029. @Override
  1030. public ResultData saveBoxPhoto(BaseDataParamVO param) throws Exception {
  1031. JSONObject boxPhoto = JSONObject.parseObject(param.getData());
  1032. String sid = boxPhoto.getString("sid");
  1033. if(StrUtil.isEmpty(sid)){
  1034. throw new BusinessException(ErrorCode.PARAM_REQUIRED, sid);
  1035. }
  1036. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  1037. if(Objects.isNull(scenePlus))
  1038. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1039. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1040. //生成boxVideos数据
  1041. String boxPhotos = this.createBoxPhotos(sid, boxPhoto, sceneEditInfo, OperationType.ADDORUPDATE.code());
  1042. //更新数据库
  1043. this.updateBoxPhotos(sceneEditInfo, boxPhotos);
  1044. return ResultData.ok();
  1045. }
  1046. @Override
  1047. public ResultData deleteBoxPhoto(DeleteSidParamVO param) throws Exception {
  1048. Scene scenePlus = sceneService.getByNum(param.getNum(), param.getSubgroup(), param.getUpTimeKey());
  1049. if(Objects.isNull(scenePlus))
  1050. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1051. SceneEditInfo sceneEditInfo = this.getByScenePlusId(scenePlus.getId());
  1052. //根据sid移除json
  1053. String boxPhotos = this.createBoxPhotos(param.getSid(), null, sceneEditInfo, OperationType.DELETE.code());
  1054. //写数据库
  1055. this.updateBoxPhotos(sceneEditInfo, boxPhotos);
  1056. return ResultData.ok();
  1057. }
  1058. private void updateBoxPhotos(SceneEditInfo sceneEditInfo, String boxPhotos){
  1059. this.update(new LambdaUpdateWrapper<SceneEditInfo>()
  1060. .set(SceneEditInfo::getBoxPhotos, boxPhotos)
  1061. .setSql("version = version + 1")
  1062. .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
  1063. }
  1064. private String createBoxPhotos(String sid, JSONObject boxPhoto, SceneEditInfo sceneEditInfo, int type) throws Exception{
  1065. String boxPhotos = null;
  1066. if(sceneEditInfo != null){
  1067. boxPhotos = sceneEditInfo.getBoxPhotos();
  1068. }
  1069. JSONArray boxPhotosJson = null;
  1070. if (StrUtil.isNotEmpty(boxPhotos)) {
  1071. boxPhotosJson = JSONArray.parseArray(boxPhotos);
  1072. }else {
  1073. boxPhotosJson = new JSONArray();
  1074. }
  1075. String result = null;
  1076. //删除
  1077. if(type == OperationType.DELETE.code()){
  1078. Set<String> deleteFile = new HashSet<>();
  1079. if(boxPhotosJson.size() == 0)
  1080. return null;
  1081. for(int i=0;i<boxPhotosJson.size();++i){
  1082. JSONObject ele = boxPhotosJson.getJSONObject(i);
  1083. if(ele.getString("sid").equals(sid)){
  1084. String poster = ele.getString("poster");
  1085. if(StrUtil.isNotEmpty(poster))
  1086. deleteFile.add(poster);
  1087. String url = ele.getString("url");
  1088. if(StrUtil.isNotEmpty(url))
  1089. deleteFile.add(url);
  1090. boxPhotosJson.remove(i);
  1091. }
  1092. }
  1093. }else{
  1094. //更新
  1095. boolean exist = false;
  1096. for(int i=0;i<boxPhotosJson.size();++i){
  1097. JSONObject ele = boxPhotosJson.getJSONObject(i);
  1098. if(ele.getString("sid").equals(sid)){
  1099. boxPhoto.put(ConstantField.CREATE_TIME, ele.getLong(ConstantField.CREATE_TIME));
  1100. boxPhotosJson.set(i, boxPhoto);
  1101. exist = true;
  1102. }
  1103. }
  1104. //新增
  1105. if(!exist){
  1106. boxPhoto.put(ConstantField.CREATE_TIME, Calendar.getInstance().getTimeInMillis());
  1107. boxPhotosJson.add(boxPhoto);
  1108. }
  1109. }
  1110. if(boxPhotosJson.size() != 0){
  1111. List<BoxPhotoBean> list = Lists.newArrayList();
  1112. for (Object o : boxPhotosJson) {
  1113. JSONObject jsonObject = (JSONObject)o;
  1114. list.add(BoxPhotoBean.builder().createTime(jsonObject.getLong(ConstantField.CREATE_TIME)).boxPhoto(jsonObject).build());
  1115. }
  1116. //按创建时间倒叙排序
  1117. list.sort(Comparator.comparingLong(BoxPhotoBean::getCreateTime).reversed());
  1118. // list转JSONArray
  1119. JSONArray array = new JSONArray();
  1120. list.stream().forEach(bean->{
  1121. array.add(bean.getBoxPhoto());
  1122. });
  1123. result = array.toJSONString();
  1124. }
  1125. return result;
  1126. }
  1127. }