@@ -1,18 +1,25 @@
package com.schisandra.oss.application.controller ;
import cn.hutool.extra.spring.SpringUtil ;
import com.alibaba.fastjson.JSON ;
import com.google.common.base.Preconditions ;
import com.schisandra.oss.application.convert.SchisandraOssUpDTOConverter ;
import com.schisandra.oss.application.dto.SchisandraOssUpDTO ;
import com.schisandra.oss.application.oss.core.up.UpOssClient ;
import com.schisandra.oss.application.oss.core.up.UpOssConfiguration ;
import com.schisandra.oss.application.oss.model.OssInfo ;
import com.schisandra.oss.common.entity.Result ;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO ;
import com.schisandra.oss.domain.service.SchisandraOssUpDomainService ;
import lombok.SneakyThrows ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.web.bind.annotation.RequestBody ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RestController ;
import org.springframework.web.bind.annotation.* ;
import org.springframework.web.multipart.MultipartFile ;
import javax.annotation.Resource ;
import javax.servlet.ServletOutputStream ;
import javax.servlet.http.HttpServletResponse ;
import java.io.InputStream ;
/**
* 又拍云对象存储配置表 controller
@@ -28,36 +35,111 @@ public class SchisandraOssUpController {
@Resource
private SchisandraOssUpDomainService schisandraOssUpDomainService ;
@Resource
private UpOssConfiguration upOssConfiguration ;
/**
* 新增又拍云对象存储配置表
* @description: 初始化
* @param: []
* @return: void
* @author: landaiqing
* @date: 2024/6/28 上午11:36
*/
@Reque stMapping ( " add " )
@Po stMapping ( " init " )
public void init ( @RequestParam ( " userId " ) String userId ) {
try {
upOssConfiguration . upOssClient ( userId ) ;
log . info ( " 用户:{} 又拍云oss初始化成功 " , userId ) ;
} catch ( Exception e ) {
log . error ( " 用户:{} 又拍云oss初始化失败 " , userId ) ;
}
}
/**
* @description: 获取指定文件信息
* @param: [userId, fileName]
* @return: com.schisandra.oss.common.entity.Result
* @author: landaiqing
* @date: 2024/6/28 上午11:42
*/
@PostMapping ( " getInfo " )
public Result getInfo ( @RequestParam ( " userId " ) String userId , @RequestParam ( " fileName " ) String fileName ) {
UpOssClient bean = SpringUtil . getBean ( userId ) ;
OssInfo info = bean . getInfo ( fileName ) ;
return Result . ok ( info ) ;
}
/**
* @description: 单个文件上传
* @param: [userId, fileName, file, isOverride]
* @return: com.schisandra.oss.common.entity.Result
* @author: landaiqing
* @date: 2024/6/28 下午3:00
*/
@SneakyThrows
@PostMapping ( " upload " )
public Result upload ( @RequestParam ( " userId " ) String userId , @RequestParam ( " file " ) MultipartFile file , @RequestParam ( " isOverride " ) Boolean isOverride ) {
UpOssClient bean = SpringUtil . getBean ( userId ) ;
String originalFileName = file . getOriginalFilename ( ) ;
InputStream is = file . getInputStream ( ) ;
OssInfo ossInfo = bean . upLoad ( is , originalFileName , isOverride ) ;
return Result . ok ( ossInfo ) ;
}
/**
* @description: 删除文件
* @param: [userId, fileName]
* @return: com.schisandra.oss.common.entity.Result
* @author: landaiqing
* @date: 2024/6/28 下午3:21
*/
@PostMapping ( " deleteFile " )
public Result deleteFile ( @RequestParam ( " userId " ) String userId , @RequestParam ( " fileName " ) String fileName ) {
UpOssClient bean = SpringUtil . getBean ( userId ) ;
bean . delete ( fileName ) ;
return Result . ok ( ) ;
}
/**
* @description: 下载文件
* @param: [userId, fileName, response]
* @return: com.schisandra.oss.common.entity.Result
* @author: landaiqing
* @date: 2024/6/28 下午3:55
*/
@SneakyThrows
@GetMapping ( " download " )
public Result download ( @RequestParam ( " userId " ) String userId , @RequestParam ( " fileName " ) String fileName , HttpServletResponse response ) {
UpOssClient bean = SpringUtil . getBean ( userId ) ;
ServletOutputStream output = response . getOutputStream ( ) ;
response . setHeader ( " Content-Disposition " , " attachment;filename= " + fileName ) ;
response . setContentType ( " application/octet-stream " ) ;
response . setCharacterEncoding ( " UTF-8 " ) ;
bean . downLoad ( output , fileName ) ;
return Result . ok ( ) ;
}
/**
* @description: 新增又拍云对象存储配置
* @param: [schisandraOssUpDTO]
* @return: com.schisandra.oss.common.entity.Result<java.lang.Boolean>
* @author: landaiqing
* @date: 2024/6/28 下午3:14
*/
@PostMapping ( " add " )
public Result < Boolean > add ( @RequestBody SchisandraOssUpDTO schisandraOssUpDTO ) {
try {
if ( log . isInfoEnabled ( ) ) {
log . info ( " SchisandraOssUpController.add.dto:{} " , JSON . toJSONString ( schisandraOssUpDTO ) ) ;
}
Preconditions . checkNotNull ( schisandraOssUpDTO . getId ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUserId ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getBasePath ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getBucket Name ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUserName ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getPassword ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getTimeout ( ) , " 默认的超时时间: 30秒不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getApiDomain ( ) , " 默认为自动识别接入点不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getPartSize ( ) , " 分片大小,默认5MB不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getTaskNum ( ) , " 并发线程数,默认等于CPU的核数不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getStatus ( ) , " 状态不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getOpenAdvancedSetup ( ) , " 是否开启高级设置不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCreatedBy ( ) , " 创建人不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCreatedTime ( ) , " 创建时间不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUpdateTime ( ) , " 更新时间不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUpdateBy ( ) , " 更新人不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getIsDeleted ( ) , " 是否删除 0 未删除 1已删除不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getExtraJson ( ) , " 额外字段不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCreateBucket ( ) , " 当桶不存在,是否创建不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCheckBucket ( ) , " 启动检测桶,是否存在不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUser Id ( ) , " UserId 不能为空" ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getBasePath ( ) , " BasePath 不能为空" ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getBucketName ( ) , " BucketName 不能为空" ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUser Name ( ) , " UserName 不能为空" ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getPassword ( ) , " Password 不能为空" ) ;
SchisandraOssUpBO SchisandraOssUpBO = SchisandraOssUpDTOConverter . INSTANCE . convertDTOToBO ( schisandraOssUpDTO ) ;
return Result . ok ( schisandraOssUpDomainService . add ( SchisandraOssUpBO ) ) ;
} catch ( Exception e ) {
@@ -68,35 +150,19 @@ public class SchisandraOssUpController {
}
/**
* 修改又拍云对象存储配置表
* @description: 修改又拍云对象存储配置
* @param: [schisandraOssUpDTO]
* @return: com.schisandra.oss.common.entity.Result<java.lang.Boolean>
* @author: landaiqing
* @date: 2024/6/28 下午3:14
*/
@Reque stMapping ( " update " )
@Po stMapping ( " update " )
public Result < Boolean > update ( @RequestBody SchisandraOssUpDTO schisandraOssUpDTO ) {
try {
if ( log . isInfoEnabled ( ) ) {
log . info ( " SchisandraOssUpController.update.dto:{} " , JSON . toJSONString ( schisandraOssUpDTO ) ) ;
}
Preconditions . checkNotNull ( schisandraOssUpDTO . getId ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUserId ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getBasePath ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getBucketName ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUserName ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getPassword ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getTimeout ( ) , " 默认的超时时间: 30秒不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getApiDomain ( ) , " 默认为自动识别接入点不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getPartSize ( ) , " 分片大小,默认5MB不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getTaskNum ( ) , " 并发线程数,默认等于CPU的核数不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getStatus ( ) , " 状态不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getOpenAdvancedSetup ( ) , " 是否开启高级设置不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCreatedBy ( ) , " 创建人不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCreatedTime ( ) , " 创建时间不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUpdateTime ( ) , " 更新时间不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUpdateBy ( ) , " 更新人不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getIsDeleted ( ) , " 是否删除 0 未删除 1已删除不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getExtraJson ( ) , " 额外字段不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCreateBucket ( ) , " 当桶不存在,是否创建不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCheckBucket ( ) , " 启动检测桶,是否存在不能为空 " ) ;
SchisandraOssUpBO schisandraOssUpBO = SchisandraOssUpDTOConverter . INSTANCE . convertDTOToBO ( schisandraOssUpDTO ) ;
return Result . ok ( schisandraOssUpDomainService . update ( schisandraOssUpBO ) ) ;
} catch ( Exception e ) {
@@ -106,36 +172,22 @@ public class SchisandraOssUpController {
}
/**
* 删除又拍云对象存储配置表
* @description: 删除又拍云对象存储配置
* @param: [schisandraOssUpDTO]
* @return: com.schisandra.oss.common.entity.Result<java.lang.Boolean>
* @author: landaiqing
* @date: 2024/6/28 下午3:14
*/
@Request Mapping ( " delete " )
@Delete Mapping ( " delete " )
public Result < Boolean > delete ( @RequestBody SchisandraOssUpDTO schisandraOssUpDTO ) {
try {
if ( log . isInfoEnabled ( ) ) {
log . info ( " SchisandraOssUpController.delete.dto:{} " , JSON . toJSONString ( schisandraOssUpDTO ) ) ;
}
Preconditions . checkNotNull ( schisandraOssUpDTO . getId ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUserId ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getBasePath ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getBucketName ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUserName ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getPassword ( ) , " 不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getTimeout ( ) , " 默认的超时时间: 30秒不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getApiDomain ( ) , " 默认为自动识别接入点不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getPartSize ( ) , " 分片大小,默认5MB不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getTaskNum ( ) , " 并发线程数,默认等于CPU的核数不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getStatus ( ) , " 状态不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getOpenAdvancedSetup ( ) , " 是否开启高级设置不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCreatedBy ( ) , " 创建人不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCreatedTime ( ) , " 创建时间不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUpdateTime ( ) , " 更新时间不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getUpdateBy ( ) , " 更新人不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getIsDeleted ( ) , " 是否删除 0 未删除 1已删除不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getExtraJson ( ) , " 额外字段不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCreateBucket ( ) , " 当桶不存在,是否创建不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getCheckBucket ( ) , " 启动检测桶,是否存在不能为空 " ) ;
Preconditions . checkNotNull ( schisandraOssUpDTO . getId ( ) , " Id 不能为空" ) ;
SchisandraOssUpBO schisandraOssUpBO = SchisandraOssUpDTOConverter . INSTANCE . convertDTOToBO ( schisandraOssUpDTO ) ;
return Result . ok ( schisandraOssUpDomainService . delete ( schisandraOssUpBO ) ) ;
} catch ( Exception e ) {