|
|
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.net.multipart.UploadFile;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -52,8 +53,8 @@ public class ScheduleJob {
|
|
|
private static String videoPathFormat = "video/video%s/";
|
|
|
private static String voicePathFormat = "voice/voice%s/";
|
|
|
|
|
|
-// @Value("${userId:0}")
|
|
|
-// private Long userId;
|
|
|
+ @Value("${userId:}")
|
|
|
+ private Long userId;
|
|
|
@Value("${oss.bucket}")
|
|
|
private String bucket;
|
|
|
|
|
|
@@ -68,40 +69,41 @@ public class ScheduleJob {
|
|
|
@Autowired
|
|
|
private IScenePlusExtService scenePlusExtService;
|
|
|
|
|
|
-// @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);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
+ @Scheduled(fixedDelay = 2*24*60*60*1000)
|
|
|
+ public void deleteV3Dir(){
|
|
|
+
|
|
|
+ ExecutorService executorService = Executors.newFixedThreadPool(1);
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Scheduled(fixedDelay = 2*24*60*60*1000)
|
|
|
public void deleteSceneData(){
|
|
|
- List<ScenePro> list = sceneProService.listDeleteScene();
|
|
|
+ ExecutorService executorService = Executors.newFixedThreadPool(1);
|
|
|
+ List<ScenePro> list = sceneProService.listDeleteScene(userId);
|
|
|
if(CollUtil.isEmpty(list)){
|
|
|
return;
|
|
|
}
|
|
|
@@ -109,12 +111,11 @@ public class ScheduleJob {
|
|
|
for (ScenePro scenePro : list) {
|
|
|
String num = scenePro.getNum();
|
|
|
try {
|
|
|
- log.info("删除全部场景数据开始,num:{}", num);
|
|
|
- Thread.sleep(5000L);
|
|
|
- log.info("删除全部场景数据开始,num:{}", num);
|
|
|
-
|
|
|
+ executorService.submit(()->{
|
|
|
+ deleteSceneHandler(num);
|
|
|
+ });
|
|
|
}catch (Exception e){
|
|
|
- log.error("删除全部场景数据失败,num:" + num, e);
|
|
|
+ log.error("删除场景全部数据失败,num:" + num, e);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -135,20 +136,15 @@ public class ScheduleJob {
|
|
|
|
|
|
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);
|
|
|
+ redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
|
|
|
}
|
|
|
- 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));
|
|
|
-
|
|
|
-
|
|
|
-// }
|
|
|
|
|
|
//删除data目录
|
|
|
List<String> dataList = uploadToOssUtil.listKeys(dataPath);
|
|
|
@@ -185,6 +181,74 @@ public class ScheduleJob {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public void deleteSceneHandler(String num){
|
|
|
+
|
|
|
+ try {
|
|
|
+ log.info("删除场景全部数据开始,num:{}", num);
|
|
|
+ //删除data目录
|
|
|
+ String dataPath = String.format(dataPathFormat, num);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除dataview目录
|
|
|
+ String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
|
|
|
+ List<String> dataViewList = uploadToOssUtil.listKeys(dataViewPath);
|
|
|
+ if(CollUtil.isNotEmpty(dataViewList)){
|
|
|
+ uploadToOssUtil.deleteFile(dataViewPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除img目录
|
|
|
+ String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
|
|
|
+ List<String> imgViewList = uploadToOssUtil.listKeys(imgViewPath);
|
|
|
+ if(CollUtil.isNotEmpty(imgViewList)){
|
|
|
+ uploadToOssUtil.deleteFile(imgViewPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除video目录
|
|
|
+ String videoViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
|
|
|
+ List<String> videoViewList = uploadToOssUtil.listKeys(videoViewPath);
|
|
|
+ if(CollUtil.isNotEmpty(videoViewList)){
|
|
|
+ uploadToOssUtil.deleteFile(videoViewPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除voice目录
|
|
|
+ String voiceViewPath = String.format(UploadFilePath.VOICE_VIEW_PATH, num);
|
|
|
+ List<String> voiceViewList = uploadToOssUtil.listKeys(voiceViewPath);
|
|
|
+ if(CollUtil.isNotEmpty(voiceViewList)){
|
|
|
+ uploadToOssUtil.deleteFile(voiceViewPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ redisUtil.sSet(deleteNumKey, num);
|
|
|
+ log.info("删除场景全部数据结束,num:{}", num);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("删除场景全部数据失败,num:" + num, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
FileUtil.writeUtf8String(2 + 1 + "", "D:\\test\\bac\\test.txt");
|