|
@@ -1,117 +1,117 @@
|
|
|
-package com.fdkankan.job.job;
|
|
|
-
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.io.FileUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.extra.spring.SpringUtil;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.aliyun.oss.OSSClient;
|
|
|
-import com.aliyun.oss.model.ListObjectsRequest;
|
|
|
-import com.aliyun.oss.model.OSSObjectSummary;
|
|
|
-import com.aliyun.oss.model.ObjectListing;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.fdkankan.common.constant.PayStatus;
|
|
|
-import com.fdkankan.common.util.FileUtils;
|
|
|
-import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
-import com.fdkankan.job.entity.*;
|
|
|
-import com.fdkankan.job.service.*;
|
|
|
-import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
-import com.fdkankan.model.constants.UploadFilePath;
|
|
|
-import com.fdkankan.redis.util.RedisUtil;
|
|
|
-import com.xxl.job.core.context.XxlJobHelper;
|
|
|
-import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * v4场景回退v3
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @author dengsixing
|
|
|
- * @since 2022/12/16
|
|
|
- **/
|
|
|
-@Slf4j
|
|
|
-@Component
|
|
|
-public class CountSizeOssHandler {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private FYunFileServiceInterface fYunFileService;
|
|
|
- @Autowired
|
|
|
- OSSClient ossClient;
|
|
|
-
|
|
|
- @XxlJob("countSizeOssHandler")
|
|
|
- public void V4toV3Handler(){
|
|
|
- XxlJobHelper.log("countSizeOssHandler start.....");
|
|
|
-
|
|
|
- List<String> dirList = null;
|
|
|
- String dirs = XxlJobHelper.getJobParam();
|
|
|
- if(StrUtil.isNotEmpty(dirs)){
|
|
|
- dirList = Arrays.asList(dirs.split(","));
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Long> map = new HashMap<>();
|
|
|
-
|
|
|
- try {
|
|
|
- boolean flag = true;
|
|
|
- String nextMaker = null;
|
|
|
- ListObjectsRequest listObjectsRequest = new ListObjectsRequest("4dkankan");
|
|
|
- //指定下一级文件
|
|
|
- listObjectsRequest.setPrefix(dirs);
|
|
|
- //设置分页的页容量
|
|
|
- listObjectsRequest.setMaxKeys(200);
|
|
|
- do {
|
|
|
- //获取下一页的起始点,它的下一项
|
|
|
- listObjectsRequest.setMarker(nextMaker);
|
|
|
- ObjectListing objectListing = ossClient.listObjects(listObjectsRequest);
|
|
|
- for (OSSObjectSummary objectSummary : objectListing.getObjectSummaries()) {
|
|
|
- String key = objectSummary.getKey();
|
|
|
- try {
|
|
|
- String[] split = key.split("/");
|
|
|
- key = split[1];
|
|
|
- Long size = map.get(key);
|
|
|
- if(Objects.isNull(size)){
|
|
|
- size = 0L;
|
|
|
- }
|
|
|
- size += objectSummary.getSize();
|
|
|
- map.put(key, size);
|
|
|
- }catch (Exception e){
|
|
|
- log.error("错误的key:{}", key);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- nextMaker = objectListing.getNextMarker();
|
|
|
- //全部执行完后,为false
|
|
|
- flag = objectListing.isTruncated();
|
|
|
- } while (flag);
|
|
|
-
|
|
|
- Set<String> strings = map.keySet();
|
|
|
- Long total = 0L;
|
|
|
- for (String key : strings) {
|
|
|
- total += map.get(key);
|
|
|
- log.info(key + ":" + map.get(key));
|
|
|
- }
|
|
|
-
|
|
|
- log.info("总大小:{}", total);
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("失败了", e);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- XxlJobHelper.log("countSizeOssHandler end.....");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+//package com.fdkankan.job.job;
|
|
|
+//
|
|
|
+//import cn.hutool.core.collection.CollUtil;
|
|
|
+//import cn.hutool.core.io.FileUtil;
|
|
|
+//import cn.hutool.core.util.StrUtil;
|
|
|
+//import cn.hutool.extra.spring.SpringUtil;
|
|
|
+//import com.alibaba.fastjson.JSON;
|
|
|
+//import com.alibaba.fastjson.JSONObject;
|
|
|
+//import com.aliyun.oss.OSSClient;
|
|
|
+//import com.aliyun.oss.model.ListObjectsRequest;
|
|
|
+//import com.aliyun.oss.model.OSSObjectSummary;
|
|
|
+//import com.aliyun.oss.model.ObjectListing;
|
|
|
+//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+//import com.fdkankan.common.constant.PayStatus;
|
|
|
+//import com.fdkankan.common.util.FileUtils;
|
|
|
+//import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+//import com.fdkankan.job.entity.*;
|
|
|
+//import com.fdkankan.job.service.*;
|
|
|
+//import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
+//import com.fdkankan.model.constants.UploadFilePath;
|
|
|
+//import com.fdkankan.redis.util.RedisUtil;
|
|
|
+//import com.xxl.job.core.context.XxlJobHelper;
|
|
|
+//import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.beans.factory.annotation.Value;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//import org.springframework.util.CollectionUtils;
|
|
|
+//
|
|
|
+//import java.io.File;
|
|
|
+//import java.util.*;
|
|
|
+//import java.util.stream.Collectors;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * <p>
|
|
|
+// * v4场景回退v3
|
|
|
+// * </p>
|
|
|
+// *
|
|
|
+// * @author dengsixing
|
|
|
+// * @since 2022/12/16
|
|
|
+// **/
|
|
|
+//@Slf4j
|
|
|
+//@Component
|
|
|
+//public class CountSizeOssHandler {
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private FYunFileServiceInterface fYunFileService;
|
|
|
+// @Autowired
|
|
|
+// OSSClient ossClient;
|
|
|
+//
|
|
|
+// @XxlJob("countSizeOssHandler")
|
|
|
+// public void V4toV3Handler(){
|
|
|
+// XxlJobHelper.log("countSizeOssHandler start.....");
|
|
|
+//
|
|
|
+// List<String> dirList = null;
|
|
|
+// String dirs = XxlJobHelper.getJobParam();
|
|
|
+// if(StrUtil.isNotEmpty(dirs)){
|
|
|
+// dirList = Arrays.asList(dirs.split(","));
|
|
|
+// }
|
|
|
+//
|
|
|
+// Map<String, Long> map = new HashMap<>();
|
|
|
+//
|
|
|
+// try {
|
|
|
+// boolean flag = true;
|
|
|
+// String nextMaker = null;
|
|
|
+// ListObjectsRequest listObjectsRequest = new ListObjectsRequest("4dkankan");
|
|
|
+// //指定下一级文件
|
|
|
+// listObjectsRequest.setPrefix(dirs);
|
|
|
+// //设置分页的页容量
|
|
|
+// listObjectsRequest.setMaxKeys(200);
|
|
|
+// do {
|
|
|
+// //获取下一页的起始点,它的下一项
|
|
|
+// listObjectsRequest.setMarker(nextMaker);
|
|
|
+// ObjectListing objectListing = ossClient.listObjects(listObjectsRequest);
|
|
|
+// for (OSSObjectSummary objectSummary : objectListing.getObjectSummaries()) {
|
|
|
+// String key = objectSummary.getKey();
|
|
|
+// try {
|
|
|
+// String[] split = key.split("/");
|
|
|
+// key = split[1];
|
|
|
+// Long size = map.get(key);
|
|
|
+// if(Objects.isNull(size)){
|
|
|
+// size = 0L;
|
|
|
+// }
|
|
|
+// size += objectSummary.getSize();
|
|
|
+// map.put(key, size);
|
|
|
+// }catch (Exception e){
|
|
|
+// log.error("错误的key:{}", key);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// nextMaker = objectListing.getNextMarker();
|
|
|
+// //全部执行完后,为false
|
|
|
+// flag = objectListing.isTruncated();
|
|
|
+// } while (flag);
|
|
|
+//
|
|
|
+// Set<String> strings = map.keySet();
|
|
|
+// Long total = 0L;
|
|
|
+// for (String key : strings) {
|
|
|
+// total += map.get(key);
|
|
|
+// log.info(key + ":" + map.get(key));
|
|
|
+// }
|
|
|
+//
|
|
|
+// log.info("总大小:{}", total);
|
|
|
+//
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("失败了", e);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// XxlJobHelper.log("countSizeOssHandler end.....");
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//}
|