|
@@ -0,0 +1,58 @@
|
|
|
+package com.fdkankan.manage.thread;
|
|
|
+
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+import com.fdkankan.manage.common.RedisKeyUtil;
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ThreadService {
|
|
|
+ @Autowired
|
|
|
+ FYunFileServiceInterface fYunFileServiceInterface;
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
+
|
|
|
+ public void checkRestore(String num,String cloudBucket,String bucket,String folderName){
|
|
|
+ String redisKey = String.format(RedisKeyUtil.restStoreKey, num);
|
|
|
+ if(redisUtil.hasKey(redisKey)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ redisUtil.set(redisKey,folderName);
|
|
|
+ ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
|
|
|
+ //等待任务执行结束,在间隔2秒执行。
|
|
|
+ scheduledThreadPoolExecutor.scheduleWithFixedDelay(()->{
|
|
|
+ try {
|
|
|
+ Integer process = fYunFileServiceInterface.getRestoreFolderProcess(cloudBucket, folderName);
|
|
|
+ System.out.println(process);
|
|
|
+ log.info("ThreadService-cloudBucket:{},bucket:{},folderName:{},process:{}",cloudBucket,bucket,folderName,process);
|
|
|
+ if(process == 100){
|
|
|
+ fYunFileServiceInterface.copyFileBetweenBucket(cloudBucket,folderName,bucket,folderName);
|
|
|
+ log.info("ThreadService-copy-bucket");
|
|
|
+ scheduledThreadPoolExecutor.shutdown();
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("ThreadService-error:",e);
|
|
|
+ scheduledThreadPoolExecutor.shutdown();
|
|
|
+ throw new BusinessException(ResultCode.SCENE_NOT_STORE);
|
|
|
+ }finally {
|
|
|
+ redisUtil.del(redisKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ //任务启动多久之后 ,周期 每10s执行一次,时间单位
|
|
|
+ },1000,60*1000, TimeUnit.MILLISECONDS);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|