feat: 分享圈列表,分享详情

This commit is contained in:
sjm
2024-07-15 23:14:46 +08:00
parent 5e868abcd7
commit 0cc06a171c
28 changed files with 234 additions and 115 deletions

View File

@@ -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]