ScenePlusServiceImpl.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package com.fdkankan.task.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import com.fdkankan.common.constant.UploadFilePath;
  9. import com.fdkankan.fyun.oss.UploadToOssUtil;
  10. import com.fdkankan.redis.constant.RedisKey;
  11. import com.fdkankan.redis.util.RedisUtil;
  12. import com.fdkankan.task.constant.TaskConstant;
  13. import com.fdkankan.task.entity.ScenePlus;
  14. import com.fdkankan.task.entity.ScenePlusExt;
  15. import com.fdkankan.task.mapper.IScenePlusMapper;
  16. import com.fdkankan.task.service.IScenePlusExtService;
  17. import com.fdkankan.task.service.IScenePlusService;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import java.util.List;
  22. /**
  23. * <p>
  24. * 场景主表 服务实现类
  25. * </p>
  26. *
  27. * @author
  28. * @since 2022-03-16
  29. */
  30. @Slf4j
  31. @Service
  32. public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlus> implements IScenePlusService {
  33. @Autowired
  34. private IScenePlusExtService scenePlusExtService;
  35. @Autowired
  36. private UploadToOssUtil uploadToOssUtil;
  37. @Autowired
  38. private RedisUtil redisUtil;
  39. @Override
  40. public ScenePlus getScenePlusByNumWithDelete(String num) {
  41. return null;
  42. }
  43. @Override
  44. public ScenePlus getScenePlusByNum(String num) {
  45. return this.getOne(new LambdaQueryWrapper<ScenePlus>().eq(ScenePlus::getNum, num));
  46. }
  47. public void deleteV3DirHandler(String num){
  48. try {
  49. log.info("删除v3目录开始,num:{}", num);
  50. String dataPath = String.format(TaskConstant.dataPathFormat, num);
  51. ScenePlus scenePlus = this.getScenePlusByNum(num);
  52. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  53. String bucket = scenePlusExt.getYunFileBucket();
  54. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  55. String sceneJsonPath = dataViewPath + "scene.json";
  56. if(StrUtil.isNotEmpty(scenePlusExt.getVideos()) && scenePlusExt.getVideos().contains(dataPath)){
  57. scenePlusExt.setVideos(scenePlusExt.getVideos().replaceAll(dataPath, dataViewPath));
  58. scenePlusExtService.updateById(scenePlusExt);
  59. String sceneJson = uploadToOssUtil.getObjectContent(bucket, sceneJsonPath);
  60. JSONObject sceneJsonObj = JSON.parseObject(sceneJson);
  61. sceneJsonObj.put("videos", JSON.parseObject(scenePlusExt.getVideos()));
  62. uploadToOssUtil.upload(bucket, sceneJsonObj.toJSONString().getBytes(), sceneJsonPath);
  63. redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
  64. }
  65. //删除data目录
  66. List<String> dataList = uploadToOssUtil.listKeys(bucket, dataPath);
  67. if(CollUtil.isNotEmpty(dataList)){
  68. uploadToOssUtil.deleteFile(bucket, dataPath);
  69. }
  70. //删除img目录
  71. String imgPath = String.format(TaskConstant.imgPathFormat, num);
  72. List<String> imgList = uploadToOssUtil.listKeys(bucket, imgPath);
  73. if(CollUtil.isNotEmpty(imgList)){
  74. uploadToOssUtil.deleteFile(bucket, imgPath);
  75. }
  76. //删除video目录
  77. String videoPath = String.format(TaskConstant.videoPathFormat, num);
  78. List<String> videoList = uploadToOssUtil.listKeys(bucket, videoPath);
  79. if(CollUtil.isNotEmpty(videoList)){
  80. uploadToOssUtil.deleteFile(bucket, videoPath);
  81. }
  82. //删除voice目录
  83. String voicePath = String.format(TaskConstant.voicePathFormat, num);
  84. List<String> voiceList = uploadToOssUtil.listKeys(bucket, voicePath);
  85. if(CollUtil.isNotEmpty(voiceList)){
  86. uploadToOssUtil.deleteFile(bucket, voicePath);
  87. }
  88. redisUtil.sSet(TaskConstant.numKey, num);
  89. log.info("删除v3目录完毕,num:{}", num);
  90. }catch (Exception e){
  91. log.info("删除v3目录失败,num:" + num, e);
  92. }
  93. }
  94. public void deleteSceneHandler(String num){
  95. try {
  96. log.info("删除场景全部数据开始,num:{}", num);
  97. ScenePlus scenePlus = this.baseMapper.selectDeleteScene(num);
  98. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  99. String bucket = scenePlusExt.getYunFileBucket();
  100. //删除data目录
  101. String dataPath = String.format(TaskConstant.dataPathFormat, num);
  102. List<String> dataList = uploadToOssUtil.listKeys(bucket, dataPath);
  103. if(CollUtil.isNotEmpty(dataList)){
  104. uploadToOssUtil.deleteFile(bucket, dataPath);
  105. }
  106. //删除img目录
  107. String imgPath = String.format(TaskConstant.imgPathFormat, num);
  108. List<String> imgList = uploadToOssUtil.listKeys(bucket, imgPath);
  109. if(CollUtil.isNotEmpty(imgList)){
  110. uploadToOssUtil.deleteFile(bucket, imgPath);
  111. }
  112. //删除video目录
  113. String videoPath = String.format(TaskConstant.videoPathFormat, num);
  114. List<String> videoList = uploadToOssUtil.listKeys(bucket, videoPath);
  115. if(CollUtil.isNotEmpty(videoList)){
  116. uploadToOssUtil.deleteFile(bucket, videoPath);
  117. }
  118. //删除voice目录
  119. String voicePath = String.format(TaskConstant.voicePathFormat, num);
  120. List<String> voiceList = uploadToOssUtil.listKeys(bucket, voicePath);
  121. if(CollUtil.isNotEmpty(voiceList)){
  122. uploadToOssUtil.deleteFile(bucket, voicePath);
  123. }
  124. //删除dataview目录
  125. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  126. List<String> dataViewList = uploadToOssUtil.listKeys(bucket, dataViewPath);
  127. if(CollUtil.isNotEmpty(dataViewList)){
  128. uploadToOssUtil.deleteFile(bucket, dataViewPath);
  129. }
  130. //删除img目录
  131. String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  132. List<String> imgViewList = uploadToOssUtil.listKeys(bucket, imgViewPath);
  133. if(CollUtil.isNotEmpty(imgViewList)){
  134. uploadToOssUtil.deleteFile(bucket, imgViewPath);
  135. }
  136. //删除video目录
  137. String videoViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
  138. List<String> videoViewList = uploadToOssUtil.listKeys(bucket, videoViewPath);
  139. if(CollUtil.isNotEmpty(videoViewList)){
  140. uploadToOssUtil.deleteFile(bucket, videoViewPath);
  141. }
  142. //删除voice目录
  143. String voiceViewPath = String.format(UploadFilePath.VOICE_VIEW_PATH, num);
  144. List<String> voiceViewList = uploadToOssUtil.listKeys(bucket, voiceViewPath);
  145. if(CollUtil.isNotEmpty(voiceViewList)){
  146. uploadToOssUtil.deleteFile(bucket, voiceViewPath);
  147. }
  148. //删除user目录
  149. String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
  150. List<String> userViewList = uploadToOssUtil.listKeys(bucket, userViewPath);
  151. if(CollUtil.isNotEmpty(userViewList)){
  152. uploadToOssUtil.deleteFile(bucket, userViewPath);
  153. }
  154. //删除user目录
  155. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  156. List<String> userEditList = uploadToOssUtil.listKeys(bucket, userEditPath);
  157. if(CollUtil.isNotEmpty(userEditList)){
  158. uploadToOssUtil.deleteFile(bucket, userEditPath);
  159. }
  160. redisUtil.sSet(TaskConstant.deleteNumKey, num);
  161. log.info("删除场景全部数据结束,num:{}", num);
  162. }catch (Exception e){
  163. log.error("删除场景全部数据失败,num:" + num, e);
  164. }
  165. }
  166. }