|
|
@@ -1,27 +1,39 @@
|
|
|
package com.fdkankan.task.schedule;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
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.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
+import com.fdkankan.common.constant.UploadFilePath;
|
|
|
import com.fdkankan.common.util.DateExtUtil;
|
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.task.entity.ScenePlus;
|
|
|
+import com.fdkankan.task.entity.ScenePlusExt;
|
|
|
import com.fdkankan.task.entity.ScenePro;
|
|
|
+import com.fdkankan.task.service.IScenePlusExtService;
|
|
|
+import com.fdkankan.task.service.IScenePlusService;
|
|
|
import com.fdkankan.task.service.ISceneProService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.io.File;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Calendar;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@@ -29,6 +41,15 @@ public class ScheduleJob {
|
|
|
|
|
|
private static String indexKey = "deleteV3Dir:index";
|
|
|
private static String numKey = "deleteV3Dir: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("${oss.bucket}")
|
|
|
+ private String bucket;
|
|
|
|
|
|
@Autowired
|
|
|
private ISceneProService sceneProService;
|
|
|
@@ -36,29 +57,91 @@ public class ScheduleJob {
|
|
|
private UploadToOssUtil uploadToOssUtil;
|
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusExtService scenePlusExtService;
|
|
|
|
|
|
- @Scheduled(fixedDelay = 10*1000)
|
|
|
+ @Scheduled(fixedDelay = 2*24*60*60*1000)
|
|
|
public void deleteV3Dir(){
|
|
|
|
|
|
- long index = redisUtil.incr(indexKey, 1) -1;
|
|
|
-
|
|
|
DateTime date = DateUtil.beginOfDay(DateUtil.offset(Calendar.getInstance().getTime(), DateField.DAY_OF_MONTH, -2));
|
|
|
|
|
|
- ScenePro scenePro = sceneProService.getOne(
|
|
|
- new LambdaQueryWrapper<ScenePro>()
|
|
|
- .lt(ScenePro::getCreateTime, date)
|
|
|
- .eq(ScenePro::getStatus, -2)
|
|
|
- .eq(ScenePro::getIsUpgrade, 1).last("limit " + index + " 1"));
|
|
|
-
|
|
|
- if(Objects.isNull(scenePro)){
|
|
|
+ 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;
|
|
|
}
|
|
|
+ Set<String> numSet = redisUtil.sGet(numKey);
|
|
|
+ for (ScenePro scenePro : list) {
|
|
|
+ String num = scenePro.getNum();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ String dataPath = String.format(dataPathFormat, num);
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("处理失败,num" + num, e);
|
|
|
+ }
|
|
|
|
|
|
- //处理文件
|
|
|
- // TODO: 2023/3/8
|
|
|
+ }
|
|
|
|
|
|
- //写入场景码
|
|
|
- redisUtil.sSet(numKey, scenePro.getNum());
|
|
|
|
|
|
}
|
|
|
|