ScenePlusServiceImpl.java 8.4 KB

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