|
|
@@ -29,11 +29,16 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
+import java.util.concurrent.Callable;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.Future;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@@ -41,13 +46,14 @@ public class ScheduleJob {
|
|
|
|
|
|
private static String indexKey = "deleteV3Dir:index";
|
|
|
private static String numKey = "deleteV3Dir:num";
|
|
|
+ private static String deleteNumKey = "deleteSceneDir:num";
|
|
|
private static String dataPathFormat = "data/data%s/";
|
|
|
private static String imgPathFormat = "images/images%s/";
|
|
|
private static String videoPathFormat = "video/video%s/";
|
|
|
private static String voicePathFormat = "voice/voice%s/";
|
|
|
|
|
|
- @Value("${userId}")
|
|
|
- private Long userId;
|
|
|
+// @Value("${userId:0}")
|
|
|
+// private Long userId;
|
|
|
@Value("${oss.bucket}")
|
|
|
private String bucket;
|
|
|
|
|
|
@@ -62,87 +68,121 @@ public class ScheduleJob {
|
|
|
@Autowired
|
|
|
private IScenePlusExtService scenePlusExtService;
|
|
|
|
|
|
- @Scheduled(fixedDelay = 2*24*60*60*1000)
|
|
|
- public void deleteV3Dir(){
|
|
|
-
|
|
|
- DateTime date = DateUtil.beginOfDay(DateUtil.offset(Calendar.getInstance().getTime(), DateField.DAY_OF_MONTH, -2));
|
|
|
+// @Scheduled(fixedDelay = 2*24*60*60*1000)
|
|
|
+// public void deleteV3Dir(){
|
|
|
+//
|
|
|
+// ExecutorService executorService = Executors.newFixedThreadPool(3);
|
|
|
+//
|
|
|
+// DateTime date = DateUtil.beginOfDay(DateUtil.offset(Calendar.getInstance().getTime(), DateField.DAY_OF_MONTH, -2));
|
|
|
+//
|
|
|
+// LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<ScenePro>();
|
|
|
+// wrapper.select(ScenePro::getNum);
|
|
|
+// wrapper.lt(ScenePro::getCreateTime, date);
|
|
|
+// wrapper.eq(ScenePro::getStatus, -2);
|
|
|
+// wrapper.eq(ScenePro::getIsUpgrade, 1);
|
|
|
+// if(Objects.nonNull(userId)){
|
|
|
+// wrapper.eq(ScenePro::getUserId, userId);
|
|
|
+// }
|
|
|
+// List<ScenePro> list = sceneProService.list(wrapper);
|
|
|
+// if(CollUtil.isEmpty(list)){
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// for (ScenePro scenePro : list) {
|
|
|
+// String num = scenePro.getNum();
|
|
|
+// try {
|
|
|
+// executorService.submit(()->{
|
|
|
+// deleteV3DirHandler(num);
|
|
|
+// });
|
|
|
+// }catch (Exception e){
|
|
|
+// log.error("删除v3目录失败,num" + num, e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<ScenePro>();
|
|
|
- wrapper.select(ScenePro::getNum);
|
|
|
- wrapper.lt(ScenePro::getCreateTime, date);
|
|
|
- wrapper.eq(ScenePro::getStatus, -2);
|
|
|
- wrapper.eq(ScenePro::getIsUpgrade, 1);
|
|
|
- if(Objects.nonNull(userId)){
|
|
|
- wrapper.eq(ScenePro::getUserId, userId);
|
|
|
- }
|
|
|
- List<ScenePro> list = sceneProService.list(wrapper);
|
|
|
+ @Scheduled(fixedDelay = 2*24*60*60*1000)
|
|
|
+ public void deleteSceneData(){
|
|
|
+ List<ScenePro> list = sceneProService.listDeleteScene();
|
|
|
if(CollUtil.isEmpty(list)){
|
|
|
return;
|
|
|
}
|
|
|
- Set<String> numSet = redisUtil.sGet(numKey);
|
|
|
+ Set<String> deleteNums = redisUtil.sGet(deleteNumKey);
|
|
|
for (ScenePro scenePro : list) {
|
|
|
String num = scenePro.getNum();
|
|
|
-
|
|
|
try {
|
|
|
+ log.info("删除全部场景数据开始,num:{}", num);
|
|
|
+ Thread.sleep(5000L);
|
|
|
+ log.info("删除全部场景数据开始,num:{}", num);
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("删除全部场景数据失败,num:" + num, e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void deleteV3DirHandler(String num){
|
|
|
|
|
|
- String dataPath = String.format(dataPathFormat, num);
|
|
|
+ try {
|
|
|
+ log.info("删除v3目录开始,num:{}", num);
|
|
|
|
|
|
- ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
|
|
|
- ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
+ String dataPath = String.format(dataPathFormat, num);
|
|
|
|
|
|
- String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
|
|
|
- String sceneJsonPath = dataViewPath + "scene.json";
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
+
|
|
|
+ String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
|
|
|
+ String sceneJsonPath = dataViewPath + "scene.json";
|
|
|
// if(!numSet.contains(num)){
|
|
|
- if(StrUtil.isNotEmpty(scenePlusExt.getVideos()) && scenePlusExt.getVideos().contains(dataPath)){
|
|
|
- scenePlusExt.setVideos(scenePlusExt.getVideos().replaceAll(dataPath, dataViewPath));
|
|
|
- scenePlusExtService.updateById(scenePlusExt);
|
|
|
- }
|
|
|
- String sceneJson = uploadToOssUtil.getObjectContent(bucket, sceneJsonPath);
|
|
|
- JSONObject sceneJsonObj = JSON.parseObject(sceneJson);
|
|
|
- sceneJsonObj.put("videos", JSON.parseObject(scenePlusExt.getVideos()));
|
|
|
- uploadToOssUtil.upload(sceneJsonObj.toJSONString().getBytes(), sceneJsonPath);
|
|
|
+ if(StrUtil.isNotEmpty(scenePlusExt.getVideos()) && scenePlusExt.getVideos().contains(dataPath)){
|
|
|
+ scenePlusExt.setVideos(scenePlusExt.getVideos().replaceAll(dataPath, dataViewPath));
|
|
|
+ scenePlusExtService.updateById(scenePlusExt);
|
|
|
+ }
|
|
|
+ String sceneJson = uploadToOssUtil.getObjectContent(bucket, sceneJsonPath);
|
|
|
+ JSONObject sceneJsonObj = JSON.parseObject(sceneJson);
|
|
|
+ sceneJsonObj.put("videos", JSON.parseObject(scenePlusExt.getVideos()));
|
|
|
+ uploadToOssUtil.upload(sceneJsonObj.toJSONString().getBytes(), sceneJsonPath);
|
|
|
|
|
|
- redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
|
|
|
+ redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
- //删除data目录
|
|
|
- List<String> dataList = uploadToOssUtil.listKeys(dataPath);
|
|
|
- if(CollUtil.isNotEmpty(dataList)){
|
|
|
- uploadToOssUtil.deleteFile(dataPath);
|
|
|
- }
|
|
|
-
|
|
|
- //删除img目录
|
|
|
- String imgPath = String.format(imgPathFormat, num);
|
|
|
- List<String> imgList = uploadToOssUtil.listKeys(imgPath);
|
|
|
- if(CollUtil.isNotEmpty(imgList)){
|
|
|
- uploadToOssUtil.deleteFile(imgPath);
|
|
|
- }
|
|
|
-
|
|
|
- //删除video目录
|
|
|
- String videoPath = String.format(videoPathFormat, num);
|
|
|
- List<String> videoList = uploadToOssUtil.listKeys(videoPath);
|
|
|
- if(CollUtil.isNotEmpty(videoList)){
|
|
|
- uploadToOssUtil.deleteFile(videoPath);
|
|
|
- }
|
|
|
-
|
|
|
- //删除voice目录
|
|
|
- String voicePath = String.format(voicePathFormat, num);
|
|
|
- List<String> voiceList = uploadToOssUtil.listKeys(voicePath);
|
|
|
- if(CollUtil.isNotEmpty(voiceList)){
|
|
|
- uploadToOssUtil.deleteFile(voicePath);
|
|
|
- }
|
|
|
-
|
|
|
- redisUtil.sSet(numKey, num);
|
|
|
+ //删除data目录
|
|
|
+ List<String> dataList = uploadToOssUtil.listKeys(dataPath);
|
|
|
+ if(CollUtil.isNotEmpty(dataList)){
|
|
|
+ uploadToOssUtil.deleteFile(dataPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除img目录
|
|
|
+ String imgPath = String.format(imgPathFormat, num);
|
|
|
+ List<String> imgList = uploadToOssUtil.listKeys(imgPath);
|
|
|
+ if(CollUtil.isNotEmpty(imgList)){
|
|
|
+ uploadToOssUtil.deleteFile(imgPath);
|
|
|
+ }
|
|
|
|
|
|
- }catch (Exception e){
|
|
|
- log.error("处理失败,num" + num, e);
|
|
|
+ //删除video目录
|
|
|
+ String videoPath = String.format(videoPathFormat, num);
|
|
|
+ List<String> videoList = uploadToOssUtil.listKeys(videoPath);
|
|
|
+ if(CollUtil.isNotEmpty(videoList)){
|
|
|
+ uploadToOssUtil.deleteFile(videoPath);
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ //删除voice目录
|
|
|
+ String voicePath = String.format(voicePathFormat, num);
|
|
|
+ List<String> voiceList = uploadToOssUtil.listKeys(voicePath);
|
|
|
+ if(CollUtil.isNotEmpty(voiceList)){
|
|
|
+ uploadToOssUtil.deleteFile(voicePath);
|
|
|
+ }
|
|
|
|
|
|
+ redisUtil.sSet(numKey, num);
|
|
|
|
|
|
+ log.info("删除v3目录完毕,num:{}", num);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("删除v3目录失败,num:" + num, e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|