Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -4,7 +4,6 @@ import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssAliDTOConverter;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssMinioDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssAliDTO;
|
||||
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||
import com.schisandra.oss.application.oss.core.ali.AliOssClient;
|
||||
@@ -12,11 +11,9 @@ import com.schisandra.oss.application.oss.core.ali.AliOssConfiguration;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
|
||||
import com.schisandra.oss.domain.redis.RedisUtil;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssAliDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -28,7 +25,9 @@ import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,6 +50,37 @@ public class SchisandraOssAliController {
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* @description: 预览文件
|
||||
* @param: [userId, bucket, filePath]
|
||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||
* @date: 2024/6/27 10:14
|
||||
*/
|
||||
@PostMapping("previewFile")
|
||||
public Result<String> previewMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String filePath) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(filePath, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String formattedDate = dateFormat.format(date);
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX, "previewFile", formattedDate, userId, filePath);
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
String url = bean.getAliPreviewUrl(filePath);
|
||||
map.put("url", url);
|
||||
map.put("time", formattedDate);
|
||||
redisUtil.setNx(key, map, 30L, TimeUnit.DAYS);
|
||||
return Result.ok(url);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回ali表所有数据
|
||||
*
|
||||
@@ -59,7 +89,7 @@ public class SchisandraOssAliController {
|
||||
@GetMapping("returnAll")
|
||||
public Result returnAll() {
|
||||
List<SchisandraOssAliBO> list = schisandraOssAliDomainService.selectAll();
|
||||
if(list.isEmpty()){
|
||||
if (list.isEmpty()) {
|
||||
return Result.fail();
|
||||
}
|
||||
return Result.ok(SchisandraOssAliDTOConverter.INSTANCE.convertBOToDTOList(list));
|
||||
@@ -67,7 +97,7 @@ public class SchisandraOssAliController {
|
||||
|
||||
|
||||
@GetMapping("init")
|
||||
public Result init(@RequestParam String userId,@RequestParam String Id) {
|
||||
public Result init(@RequestParam String userId, @RequestParam String Id) {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SchisandraOssAliController.init.userId:{}", userId);
|
||||
}
|
||||
@@ -76,15 +106,15 @@ public class SchisandraOssAliController {
|
||||
bo.setId(Long.valueOf(Id));
|
||||
bo.setUserId(Long.valueOf(userId));
|
||||
bo.setStatus(String.valueOf(true));
|
||||
if(schisandraOssAliDomainService.update(bo)){
|
||||
if (schisandraOssAliDomainService.update(bo)) {
|
||||
return aliOssConfiguration.aliOssClient(userId);
|
||||
}else{
|
||||
} else {
|
||||
return Result.fail("初始化失败");
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("shutdown")
|
||||
public Result shutdownAli(@RequestParam String userId,@RequestParam String Id){
|
||||
public Result shutdownAli(@RequestParam String userId, @RequestParam String Id) {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SchisandraOssAliController.shutdown.userId:{}", JSON.toJSONString(userId));
|
||||
}
|
||||
@@ -92,10 +122,10 @@ public class SchisandraOssAliController {
|
||||
bo.setId(Long.valueOf(Id));
|
||||
bo.setUserId(Long.valueOf(userId));
|
||||
bo.setStatus(String.valueOf(false));
|
||||
if(schisandraOssAliDomainService.update(bo)){
|
||||
SpringUtil.unregisterBean(OssConstant.OssType.ALI+ userId);
|
||||
if (schisandraOssAliDomainService.update(bo)) {
|
||||
SpringUtil.unregisterBean(OssConstant.OssType.ALI + userId);
|
||||
return Result.ok("关闭成功");
|
||||
}else{
|
||||
} else {
|
||||
return Result.fail("关闭失败");
|
||||
}
|
||||
}
|
||||
@@ -168,13 +198,13 @@ public class SchisandraOssAliController {
|
||||
@GetMapping("listDir")
|
||||
public Result<String> listAliDir(@RequestParam String userId, @RequestParam String bucket, @RequestParam String prefix) throws Exception {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI+ userId);
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
if (prefix == null)
|
||||
prefix = "";
|
||||
if(bean.listAliInfo(bucket, prefix) != null){
|
||||
if (bean.listAliInfo(bucket, prefix) != null) {
|
||||
return Result.ok(bean.listAliInfo(bucket, prefix));
|
||||
}else{
|
||||
} else {
|
||||
return Result.fail("获取文件目录信息失败");
|
||||
}
|
||||
|
||||
@@ -189,10 +219,10 @@ public class SchisandraOssAliController {
|
||||
@PostMapping("seleteBucket")
|
||||
public Result seleteBucket(@RequestParam String userId) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI+ userId);
|
||||
if(bean.selectAllBucket() != null){
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
if (bean.selectAllBucket() != null) {
|
||||
return Result.ok(bean.selectAllBucket());
|
||||
}else{
|
||||
} else {
|
||||
return Result.fail("查询失败");
|
||||
}
|
||||
|
||||
@@ -209,11 +239,11 @@ public class SchisandraOssAliController {
|
||||
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI+ userId);
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
if(bean.createBucket(bucket).equals(bucket)){
|
||||
if (bean.createBucket(bucket).equals(bucket)) {
|
||||
return Result.ok(bean.createBucket(bucket));
|
||||
}else{
|
||||
} else {
|
||||
return Result.fail("创建失败");
|
||||
}
|
||||
}
|
||||
@@ -231,9 +261,9 @@ public class SchisandraOssAliController {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
if(bean.deleteBucket(bucket).equals("yes")){
|
||||
if (bean.deleteBucket(bucket).equals("yes")) {
|
||||
return Result.ok(bean.deleteBucket(bucket));
|
||||
}else{
|
||||
} else {
|
||||
return Result.fail("删除失败,或许桶已经不存在");
|
||||
}
|
||||
}
|
||||
@@ -250,7 +280,10 @@ public class SchisandraOssAliController {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(fileName, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
//设置热力图
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
@@ -263,20 +296,16 @@ public class SchisandraOssAliController {
|
||||
} else {
|
||||
redisUtil.set(key, String.valueOf(1));
|
||||
}
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
if(bean.upLoad(is, fileName, true) != null){
|
||||
|
||||
if (bean.upLoad(is, fileName, true) != null) {
|
||||
return Result.ok(bean.upLoad(is, fileName, true));
|
||||
}else{
|
||||
} else {
|
||||
return Result.fail();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @description: 下载文件
|
||||
* @param: [schisandraOssAliDTO]
|
||||
|
@@ -66,7 +66,7 @@ public class SchisandraOssMinioController {
|
||||
@GetMapping("returnAll")
|
||||
public Result returnAll() {
|
||||
List<SchisandraOssMinioBO> list = schisandraOssMinioDomainService.selectAll();
|
||||
if(list.isEmpty()){
|
||||
if (list.isEmpty()) {
|
||||
return Result.fail();
|
||||
}
|
||||
return Result.ok(SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTOList(list));
|
||||
@@ -86,7 +86,7 @@ public class SchisandraOssMinioController {
|
||||
log.info("SchisandraOssMinioController.init.userId:{}", userId);
|
||||
}
|
||||
Preconditions.checkNotNull(userId, "用户id不能为空!");
|
||||
List<SchisandraOssMinioBO> list= schisandraOssMinioDomainService.getAllMinioInfoByUserId(Long.valueOf(userId));
|
||||
List<SchisandraOssMinioBO> list = schisandraOssMinioDomainService.getAllMinioInfoByUserId(Long.valueOf(userId));
|
||||
if (list.size() != 0) {
|
||||
return Result.fail(list);
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class SchisandraOssMinioController {
|
||||
bo.setUserId(Long.valueOf(userId));
|
||||
bo.setStatus(String.valueOf(false));
|
||||
if (schisandraOssMinioDomainService.update(bo)) {
|
||||
SpringUtil.unregisterBean(OssConstant.OssType.MINIO+userId);
|
||||
SpringUtil.unregisterBean(OssConstant.OssType.MINIO + userId);
|
||||
return Result.ok();
|
||||
} else {
|
||||
return Result.fail();
|
||||
@@ -132,7 +132,7 @@ public class SchisandraOssMinioController {
|
||||
@GetMapping("listDir")
|
||||
public Result<String> listMinioInfo(@RequestParam String userId, @RequestParam String dirName, @RequestParam String bucket) throws Exception {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.listDir(bucket, dirName));
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class SchisandraOssMinioController {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(listObjectsArgs, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
HashMap<String, InputStream> list = bean.getTargetDir(listObjectsArgs);
|
||||
|
||||
@@ -166,13 +166,13 @@ public class SchisandraOssMinioController {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String formattedDate = dateFormat.format(date);
|
||||
list.keySet().forEach( name -> {
|
||||
list.keySet().forEach(name -> {
|
||||
try {
|
||||
byte[] bytes = StreamUtils.copyToByteArray(list.get(name));
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX, "download", formattedDate, userId, name);
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
map.put("size", bytes.length);
|
||||
map.put("time",formattedDate);
|
||||
map.put("time", formattedDate);
|
||||
redisUtil.setNx(key, map, 30L, TimeUnit.DAYS);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -195,7 +195,7 @@ public class SchisandraOssMinioController {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(filePath, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
bean.delete(filePath);
|
||||
return Result.ok();
|
||||
@@ -216,7 +216,7 @@ public class SchisandraOssMinioController {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
//设置热力图
|
||||
Date date = new Date();
|
||||
@@ -226,7 +226,7 @@ public class SchisandraOssMinioController {
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
map.put("descreption", "这是一个文件");
|
||||
map.put("size", String.valueOf(file.getSize()));
|
||||
map.put("time",formattedDate);
|
||||
map.put("time", formattedDate);
|
||||
if (bean.upLoad(is, fileName, true) != null) {
|
||||
redisUtil.setNx(key, map, 30L, TimeUnit.DAYS);
|
||||
return Result.ok();
|
||||
@@ -251,7 +251,7 @@ public class SchisandraOssMinioController {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(oldFileName, "不能为空");
|
||||
Preconditions.checkNotNull(newFileName, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
bean.rename(oldFileName, newFileName);
|
||||
@@ -276,7 +276,7 @@ public class SchisandraOssMinioController {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(oldFilePath, "不能为空");
|
||||
Preconditions.checkNotNull(newFilePath, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
bean.copy(oldFilePath, newFilePath);
|
||||
@@ -298,7 +298,7 @@ public class SchisandraOssMinioController {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(filePath, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
Date date = new Date();
|
||||
@@ -306,7 +306,7 @@ public class SchisandraOssMinioController {
|
||||
String formattedDate = dateFormat.format(date);
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX, "previewFile", formattedDate, userId, filePath);
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
String url=bean.getMinioPreviewUrl(filePath);
|
||||
String url = bean.getMinioPreviewUrl(filePath);
|
||||
map.put("url", url);
|
||||
map.put("time", formattedDate);
|
||||
redisUtil.setNx(key, map, 30L, TimeUnit.DAYS);
|
||||
@@ -329,7 +329,7 @@ public class SchisandraOssMinioController {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(filePath, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
return Result.ok(bean.shareMinioFile(filePath, time));
|
||||
@@ -348,7 +348,7 @@ public class SchisandraOssMinioController {
|
||||
@PostMapping("seleteBucket")
|
||||
public Result<String> seleteBucket(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
return Result.ok(bean.selectAllBucket());
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ public class SchisandraOssMinioController {
|
||||
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.createBucket(bucket));
|
||||
}
|
||||
@@ -379,7 +379,7 @@ public class SchisandraOssMinioController {
|
||||
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.deleteBucket(bucket));
|
||||
}
|
||||
@@ -453,7 +453,7 @@ public class SchisandraOssMinioController {
|
||||
|
||||
@PostMapping("getBaseInfo")
|
||||
public Result getBaseInfo(@RequestParam String fileName, @RequestParam String userId) {
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
if (bean == null) {
|
||||
log.error("容器获取失败!");
|
||||
return null;
|
||||
|
@@ -6,7 +6,6 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.unit.DataSizeUtil;
|
||||
import cn.hutool.core.lang.hash.Hash;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -14,8 +13,6 @@ import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.common.utils.HttpHeaders;
|
||||
import com.aliyun.oss.model.*;
|
||||
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.ali.model.AliOssConfig;
|
||||
@@ -35,6 +32,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@@ -57,23 +55,29 @@ public class AliOssClient implements StandardOssClient {
|
||||
private OSS oss;
|
||||
private AliOssConfig aliOssConfig;
|
||||
|
||||
|
||||
public String getAliPreviewUrl(String fileName) {
|
||||
URL presignedUrl = oss.generatePresignedUrl(getBucketName(), fileName, new Date());
|
||||
return String.valueOf(presignedUrl);
|
||||
}
|
||||
|
||||
public String getAliBucketSize(String bucket) {
|
||||
ObjectListing objectListing = oss.listObjects(bucket, "");
|
||||
long x = 0L;
|
||||
List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
|
||||
for(OSSObjectSummary objectSummary : sums){
|
||||
x+=objectSummary.getSize();
|
||||
for (OSSObjectSummary objectSummary : sums) {
|
||||
x += objectSummary.getSize();
|
||||
}
|
||||
return DataSizeUtil.format(x);
|
||||
}
|
||||
|
||||
public List<HashMap<String,String>> selectAllBucket() {
|
||||
public List<HashMap<String, String>> selectAllBucket() {
|
||||
List<Bucket> buckets = oss.listBuckets();
|
||||
List<HashMap<String,String>> list1 = new ArrayList<>();
|
||||
List<HashMap<String, String>> list1 = new ArrayList<>();
|
||||
buckets.forEach(bucket -> {
|
||||
HashMap<String, String> names = new HashMap<>();
|
||||
names.put("name",bucket.getName());
|
||||
names.put("size",getAliBucketSize(bucket.getName()));
|
||||
names.put("name", bucket.getName());
|
||||
names.put("size", getAliBucketSize(bucket.getName()));
|
||||
list1.add(names);
|
||||
});
|
||||
return list1;
|
||||
@@ -85,12 +89,12 @@ public class AliOssClient implements StandardOssClient {
|
||||
* @return: java.util.List<com.schisandra.oss.application.oss.model.OssInfo>
|
||||
* @date: 2024/7/5 13:34
|
||||
*/
|
||||
public String transfer(String before){
|
||||
public String transfer(String before) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
|
||||
Date date = new Date();
|
||||
try{
|
||||
try {
|
||||
date = sdf.parse(before);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
|
||||
@@ -98,23 +102,23 @@ public class AliOssClient implements StandardOssClient {
|
||||
return formatStr;
|
||||
}
|
||||
|
||||
public List<OssInfo> listAliInfo(String bucket, String prefix){
|
||||
public List<OssInfo> listAliInfo(String bucket, String prefix) {
|
||||
// 列举文件。如果不设置Prefix,则列举存储空间下的所有文件。如果设置Prefix,则列举包含指定前缀的文件。
|
||||
ObjectListing objectListing = oss.listObjects(bucket, prefix);
|
||||
List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
|
||||
List<OssInfo> infos = new ArrayList<>();
|
||||
if(prefix == ""){
|
||||
for(OSSObjectSummary objectSummary : sums){
|
||||
if (prefix == "") {
|
||||
for (OSSObjectSummary objectSummary : sums) {
|
||||
OssInfo info = new OssInfo();
|
||||
|
||||
String[] split_path = objectSummary.getKey().split("/");
|
||||
if(split_path.length>=2)
|
||||
if (split_path.length >= 2)
|
||||
continue;
|
||||
|
||||
String[] split_path_again = split_path[0].split("\\.");
|
||||
if(split_path_again.length>=2) {
|
||||
if (split_path_again.length >= 2) {
|
||||
info.setIsDir(false);
|
||||
}else{
|
||||
} else {
|
||||
info.setIsDir(true);
|
||||
}
|
||||
info.setName(split_path[0]);
|
||||
@@ -126,21 +130,21 @@ public class AliOssClient implements StandardOssClient {
|
||||
infos.add(info);
|
||||
}
|
||||
|
||||
}else{
|
||||
for(OSSObjectSummary objectSummary : sums){
|
||||
} else {
|
||||
for (OSSObjectSummary objectSummary : sums) {
|
||||
OssInfo info = new OssInfo();
|
||||
|
||||
int x = prefix.split("/").length;
|
||||
String[] split_path = objectSummary.getKey().split("/");
|
||||
if(split_path.length>=x+2)
|
||||
if (split_path.length >= x + 2)
|
||||
continue;
|
||||
String[] split_path_again = split_path[split_path.length-1].split("\\.");
|
||||
if(split_path_again.length>=2){
|
||||
String[] split_path_again = split_path[split_path.length - 1].split("\\.");
|
||||
if (split_path_again.length >= 2) {
|
||||
info.setIsDir(false);
|
||||
}else{
|
||||
} else {
|
||||
info.setIsDir(true);
|
||||
}
|
||||
info.setName(split_path[split_path.length-1]);
|
||||
info.setName(split_path[split_path.length - 1]);
|
||||
info.setPath(objectSummary.getKey());
|
||||
info.setLength(DataSizeUtil.format(objectSummary.getSize()));
|
||||
|
||||
@@ -159,7 +163,7 @@ public class AliOssClient implements StandardOssClient {
|
||||
if (!oss.doesBucketExist(bucketName)) {
|
||||
Bucket bucket = oss.createBucket(bucketName);
|
||||
bucket.setRegion("chengdu");
|
||||
}else {
|
||||
} else {
|
||||
return "bucket already exists";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -169,14 +173,13 @@ public class AliOssClient implements StandardOssClient {
|
||||
}
|
||||
|
||||
public String deleteBucket(String bucketName) {
|
||||
try{
|
||||
if (oss.doesBucketExist(bucketName)){
|
||||
try {
|
||||
if (oss.doesBucketExist(bucketName)) {
|
||||
VoidResult voidResult = oss.deleteBucket(bucketName);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return "bucket does not exist";
|
||||
}
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "yes";
|
||||
|
@@ -1,38 +1,40 @@
|
||||
package com.schisandra.oss.application.oss.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author landaiqing
|
||||
* @version Info.java, v 1.1 2021/11/15 10:16 chenmin Exp $
|
||||
* Created on 2021/11/15
|
||||
*/
|
||||
@Data
|
||||
public class OssInfo {
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 是否是文件夹
|
||||
*/
|
||||
private Boolean isDir;
|
||||
/**
|
||||
* 存储路径
|
||||
*/
|
||||
private String path;
|
||||
/**
|
||||
* 对象大小
|
||||
*/
|
||||
private String length;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
/**
|
||||
* 最新修改时间
|
||||
*/
|
||||
private String lastUpdateTime;
|
||||
|
||||
}
|
||||
package com.schisandra.oss.application.oss.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author landaiqing
|
||||
* @version Info.java, v 1.1 2021/11/15 10:16 chenmin Exp $
|
||||
* Created on 2021/11/15
|
||||
*/
|
||||
@Data
|
||||
public class OssInfo implements Serializable {
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 是否是文件夹
|
||||
*/
|
||||
private Boolean isDir;
|
||||
/**
|
||||
* 存储路径
|
||||
*/
|
||||
private String path;
|
||||
/**
|
||||
* 对象大小
|
||||
*/
|
||||
private String length;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
/**
|
||||
* 最新修改时间
|
||||
*/
|
||||
private String lastUpdateTime;
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.schisandra.oss.job.job;
|
||||
|
||||
import com.schisandra.oss.domain.bo.SchisandraFileHeatmapBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraFileHeatmapDomainService;
|
||||
import com.xxl.job.core.context.XxlJobHelper;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
@@ -8,7 +7,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -19,17 +17,17 @@ public class OssHeatMapRedisToMysqlHandler {
|
||||
@XxlJob("ossHeatMapRedisToMysqlHandler")
|
||||
public void ossHeatMapRedisToMysqlHandler() throws Exception {
|
||||
XxlJobHelper.log("ossHeatMapRedisToMysqlHandler.starter");
|
||||
if (schisandraFileHeatmapDomainService.uploadHeatMapRedisToMysql()==1 ){
|
||||
XxlJobHelper.log("ossHeatMapRedisToMysqlHandler.upload.success");
|
||||
log.info("1");
|
||||
}else {
|
||||
XxlJobHelper.log("ossHeatMapRedisToMysqlHandler.fail");
|
||||
}
|
||||
if (schisandraFileHeatmapDomainService.downloadHeatMapRedisToMysql()==1){
|
||||
XxlJobHelper.log("ossHeatMapRedisToMysqlHandler.success");
|
||||
}else {
|
||||
XxlJobHelper.log("ossHeatMapRedisToMysqlHandler.download.fail");
|
||||
}
|
||||
if (schisandraFileHeatmapDomainService.uploadHeatMapRedisToMysql() == 1) {
|
||||
XxlJobHelper.log("ossHeatMapRedisToMysqlHandler.upload.success");
|
||||
log.info("1");
|
||||
} else {
|
||||
XxlJobHelper.log("ossHeatMapRedisToMysqlHandler.fail");
|
||||
}
|
||||
if (schisandraFileHeatmapDomainService.downloadHeatMapRedisToMysql() == 1) {
|
||||
XxlJobHelper.log("ossHeatMapRedisToMysqlHandler.success");
|
||||
} else {
|
||||
XxlJobHelper.log("ossHeatMapRedisToMysqlHandler.download.fail");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,56 +1,58 @@
|
||||
package com.schisandra.oss.common.entity;
|
||||
|
||||
import com.schisandra.oss.common.enums.ResultCodeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @description: 返回结果泛型类
|
||||
* @author: schisandra
|
||||
* @date: 2024/3/22 13:09
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> {
|
||||
|
||||
private Boolean success;
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
private T data;
|
||||
|
||||
public static Result ok() {
|
||||
Result result = new Result();
|
||||
result.setSuccess(true);
|
||||
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
||||
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result ok(T data) {
|
||||
Result result = new Result();
|
||||
result.setSuccess(true);
|
||||
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
||||
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result fail() {
|
||||
Result result = new Result();
|
||||
result.setSuccess(false);
|
||||
result.setCode(ResultCodeEnum.FAIL.getCode());
|
||||
result.setMessage(ResultCodeEnum.FAIL.getDesc());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result fail(T data) {
|
||||
Result result = new Result();
|
||||
result.setSuccess(false);
|
||||
result.setCode(ResultCodeEnum.FAIL.getCode());
|
||||
result.setMessage(ResultCodeEnum.FAIL.getDesc());
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
package com.schisandra.oss.common.entity;
|
||||
|
||||
import com.schisandra.oss.common.enums.ResultCodeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description: 返回结果泛型类
|
||||
* @author: schisandra
|
||||
* @date: 2024/3/22 13:09
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> implements Serializable {
|
||||
|
||||
private Boolean success;
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
private T data;
|
||||
|
||||
public static Result ok() {
|
||||
Result result = new Result();
|
||||
result.setSuccess(true);
|
||||
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
||||
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result ok(T data) {
|
||||
Result result = new Result();
|
||||
result.setSuccess(true);
|
||||
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
||||
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result fail() {
|
||||
Result result = new Result();
|
||||
result.setSuccess(false);
|
||||
result.setCode(ResultCodeEnum.FAIL.getCode());
|
||||
result.setMessage(ResultCodeEnum.FAIL.getDesc());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result fail(T data) {
|
||||
Result result = new Result();
|
||||
result.setSuccess(false);
|
||||
result.setCode(ResultCodeEnum.FAIL.getCode());
|
||||
result.setMessage(ResultCodeEnum.FAIL.getDesc());
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -72,12 +72,12 @@ mybatis-flex:
|
||||
xxl:
|
||||
job:
|
||||
admin:
|
||||
addresses: http://127.0.0.1:8080/xxl-job-admin
|
||||
addresses: http://1.95.0.111:8088/xxl-job-admin
|
||||
accessToken: default_token
|
||||
executor:
|
||||
appname: schisandra-cloud-storage-oss
|
||||
address:
|
||||
ip: 127.0.0.1
|
||||
port: 9999
|
||||
ip: 1.95.0.111
|
||||
port: 9998
|
||||
logpath: /data/applogs/xxl-job/jobhandler
|
||||
logretentiondays: 30
|
Reference in New Issue
Block a user