dsx 2 лет назад
Родитель
Сommit
d48bb86a05

+ 0 - 1
4dkankan-task/pom.xml

@@ -80,7 +80,6 @@
     </dependencies>
 
     <build>
-        <finalName>${artifactId}</finalName>
         <plugins>
             <plugin>
                 <groupId>org.springframework.boot</groupId>

+ 4 - 0
4dkankan-task/src/main/java/com/fdkankan/task/mapper/ISceneProMapper.java

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fdkankan.task.entity.ScenePro;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
  * <p>
  * pro场景表 Mapper 接口
@@ -15,4 +17,6 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface ISceneProMapper extends BaseMapper<ScenePro> {
 
+    List<ScenePro> selectDeleteScene();
+
 }

+ 102 - 62
4dkankan-task/src/main/java/com/fdkankan/task/schedule/ScheduleJob.java

@@ -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) {

+ 4 - 0
4dkankan-task/src/main/java/com/fdkankan/task/service/ISceneProService.java

@@ -3,6 +3,8 @@ package com.fdkankan.task.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.task.entity.ScenePro;
 
+import java.util.List;
+
 /**
  * <p>
  * pro场景表 服务类
@@ -13,6 +15,8 @@ import com.fdkankan.task.entity.ScenePro;
  */
 public interface ISceneProService extends IService<ScenePro> {
 
+    List<ScenePro> listDeleteScene();
+
 
 
 }

+ 6 - 1
4dkankan-task/src/main/java/com/fdkankan/task/service/impl/SceneProServiceImpl.java

@@ -7,6 +7,8 @@ import com.fdkankan.task.service.ISceneProService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * pro场景表 服务实现类
@@ -20,5 +22,8 @@ import org.springframework.stereotype.Service;
 public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
 
 
-
+    @Override
+    public List<ScenePro> listDeleteScene() {
+        return this.baseMapper.selectDeleteScene();
+    }
 }

+ 1 - 1
4dkankan-task/src/main/resources/bootstrap.yml

@@ -6,7 +6,7 @@ spring:
       config:
         username: nacos
         password: nacos
-        server-addr: 120.24.144.164:8848
+        server-addr: 4dmanage-uat.autohome.com.cn
         file-extension: yaml
         namespace: 4dkankan-qczj
         extension-configs:

+ 10 - 0
4dkankan-task/src/main/resources/mapper.task/SceneProMapper.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fdkankan.task.mapper.ISceneProMapper">
+
+    <select id="selectDeleteScene" resultType="com.fdkankan.task.entity.ScenePro">
+        select t.num from t_scene_pro t where t.rec_status = 'I';
+    </select>
+
+
+</mapper>