feat: ①up,tencent,minio,qiniu,ali,sftp添加convertEntityToBOList ②注册注销bean(init,shutdown) ③controller层部分返回未修改->Result.ok

This commit is contained in:
sjm
2024-07-13 20:27:38 +08:00
parent 4693ce76e6
commit d2a73d9771
39 changed files with 829 additions and 551 deletions

View File

@@ -4,12 +4,15 @@ 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;
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;
@@ -53,27 +56,51 @@ public class SchisandraOssAliController {
* @return
*/
@GetMapping("returnAll")
public List<SchisandraOssAliDTO> returnAll() {
return aliOssConfiguration.selectAll();
public Result returnAll() {
List<SchisandraOssAliBO> list = schisandraOssAliDomainService.selectAll();
if(list.isEmpty()){
return Result.fail();
}
return Result.ok(SchisandraOssAliDTOConverter.INSTANCE.convertBOToDTOList(list));
}
@GetMapping("init")
public void init(@RequestParam String userId) {
public Result init(@RequestParam String userId,@RequestParam String Id) {
if (log.isInfoEnabled()) {
log.info("SchisandraOssAliController.init.userId:{}", userId);
}
Preconditions.checkNotNull(userId, "用户id不能为空");
try {
aliOssConfiguration.aliOssClient(userId);
log.info("用户: " + userId + "-> ali oss 初始化完成!");
} catch (Exception e) {
log.error("用户: " + userId + "-> ali oss 初始化失败!", e.getMessage(), e);
SchisandraOssAliBO bo = new SchisandraOssAliBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.ALI+ userId));
bo.setStatus(String.valueOf(true));
if(schisandraOssAliDomainService.update(bo)){
return aliOssConfiguration.aliOssClient(userId);
}else{
return Result.fail("初始化失败");
}
}
@PostMapping("shutdown")
public Result shutdownAli(@RequestParam String userId,@RequestParam String Id){
if (log.isInfoEnabled()) {
log.info("SchisandraOssAliController.shutdown.userId:{}", JSON.toJSONString(userId));
}
SchisandraOssAliBO bo = new SchisandraOssAliBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.ALI + userId));
bo.setStatus(String.valueOf(false));
if(schisandraOssAliDomainService.update(bo)){
SpringUtil.unregisterBean(OssConstant.OssType.ALI+ userId);
return Result.ok("关闭成功");
}else{
return Result.fail("关闭失败");
}
}
/**
* 新增
* 新增阿里配置表
*/
@RequestMapping("add")
public Result<Boolean> add(@RequestBody SchisandraOssAliDTO schisandraOssAliDTO) {
@@ -118,7 +145,6 @@ public class SchisandraOssAliController {
*/
@RequestMapping("delete")
public Result<Boolean> delete(@RequestBody SchisandraOssAliDTO schisandraOssAliDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SchisandraOssAliController.delete.dto:{}", JSON.toJSONString(schisandraOssAliDTO));
@@ -130,7 +156,6 @@ public class SchisandraOssAliController {
log.error("SchisandraOssAliController.delete.error:{}", e.getMessage(), e);
return Result.fail("删除信息失败");
}
}
/**
@@ -142,11 +167,16 @@ 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(userId);
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI+ userId);
bean.getAliOssConfig().setBucketName(bucket);
if (prefix == null)
prefix = "";
return Result.ok(bean.listAliInfo(bucket, prefix));
if(bean.listAliInfo(bucket, prefix) != null){
return Result.ok(bean.listAliInfo(bucket, prefix));
}else{
return Result.fail("获取文件目录信息失败");
}
}
@@ -158,8 +188,13 @@ public class SchisandraOssAliController {
@PostMapping("seleteBucket")
public Result<String> seleteBucket(@RequestParam String userId) {
Preconditions.checkNotNull(userId, "不能为空");
AliOssClient bean = SpringUtil.getBean(userId);
return Result.ok(bean.selectAllBucket());
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI+ userId);
if(bean.selectAllBucket() != null){
return Result.ok(bean.selectAllBucket());
}else{
return Result.fail("查询失败");
}
}
/**
@@ -173,9 +208,13 @@ public class SchisandraOssAliController {
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket) {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
AliOssClient bean = SpringUtil.getBean(userId);
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI+ userId);
bean.getAliOssConfig().setBucketName(bucket);
return Result.ok(bean.createBucket(bucket));
if(bean.createBucket(bucket).equals(bucket)){
return Result.ok(bean.createBucket(bucket));
}else{
return Result.fail("创建失败");
}
}
/**
@@ -189,9 +228,13 @@ public class SchisandraOssAliController {
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
AliOssClient bean = SpringUtil.getBean(userId);
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
bean.getAliOssConfig().setBucketName(bucket);
return Result.ok(bean.deleteBucket(bucket));
if(bean.deleteBucket(bucket).equals("yes")){
return Result.ok(bean.deleteBucket(bucket));
}else{
return Result.fail("删除失败,或许桶已经不存在");
}
}
@@ -221,30 +264,37 @@ public class SchisandraOssAliController {
}
// 获取文件输入流
InputStream is = file.getInputStream();
AliOssClient bean = SpringUtil.getBean(userId);
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
bean.getAliOssConfig().setBucketName(bucket);
return Result.ok(bean.upLoad(is, fileName, true));
if(bean.upLoad(is, fileName, true) != null){
return Result.ok(bean.upLoad(is, fileName, true));
}else{
return Result.fail();
}
}
/**
* @description: 下载文件
* @param: [schisandraOssMinioDTO]
* @param: [schisandraOssAliDTO]
* @return: voiD
* @date: 2024/6/26 13:56
*/
@GetMapping("downloadFile")
public void getAliFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath, HttpServletResponse response) throws Exception {
public Result getAliFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath, HttpServletResponse response) throws Exception {
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(filePath, "不能为空");
AliOssClient bean = SpringUtil.getBean(userId);
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
bean.getAliOssConfig().setBucketName(bucket);
ServletOutputStream output = response.getOutputStream();
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filePath.substring(filePath.lastIndexOf("/") + 1), "UTF-8"));
response.setContentType("application/octet-stream");
response.setCharacterEncoding("UTF-8");
bean.downLoad(output, filePath);
return Result.ok();
}
/**
@@ -254,11 +304,11 @@ public class SchisandraOssAliController {
* @date: 2024/6/26 14:34
*/
@PostMapping("deleteFile")
public Result deleteAliFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
public Result<String> deleteAliFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(filePath, "不能为空");
AliOssClient bean = SpringUtil.getBean(userId);
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
bean.getAliOssConfig().setBucketName(bucket);
bean.delete(filePath);
return Result.ok();
@@ -278,7 +328,7 @@ public class SchisandraOssAliController {
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(oldFileName, "不能为空");
Preconditions.checkNotNull(newFileName, "不能为空");
AliOssClient bean = SpringUtil.getBean(userId);
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
bean.getAliOssConfig().setBucketName(bucket);
try {
bean.rename(oldFileName, newFileName);

View File

@@ -3,13 +3,18 @@ package com.schisandra.oss.application.controller;
import cn.hutool.core.util.ZipUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.aliyun.oss.internal.OSSConstants;
import com.google.common.base.Preconditions;
import com.schisandra.oss.application.convert.SchisandraOssMinioDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssQiniuDTOConverter;
import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
import com.schisandra.oss.application.oss.constant.OssConstant;
import com.schisandra.oss.application.oss.core.minio.MinioOssClient;
import com.schisandra.oss.application.oss.core.minio.MinioOssConfiguration;
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.bo.SchisandraOssQiniuBO;
import com.schisandra.oss.domain.redis.RedisUtil;
import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService;
import io.minio.errors.*;
@@ -58,8 +63,12 @@ public class SchisandraOssMinioController {
* @return
*/
@GetMapping("returnAll")
public List<SchisandraOssMinioDTO> returnAll() {
return minioOssConfiguration.selectAll();
public Result returnAll() {
List<SchisandraOssMinioBO> list = schisandraOssMinioDomainService.selectAll();
if(list.isEmpty()){
return Result.fail();
}
return Result.ok(SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTOList(list));
}
@@ -71,17 +80,36 @@ public class SchisandraOssMinioController {
* @date: 2024/5/15 13:34
*/
@PostMapping("init")
public void initMinio(@RequestParam String userId) {
public Result initMinio(@RequestParam String userId,@RequestParam String Id) {
if (log.isInfoEnabled()) {
log.info("SchisandraOssMinioController.init.userId:{}", userId);
}
Preconditions.checkNotNull(userId, "用户id不能为空");
SchisandraOssMinioBO bo = new SchisandraOssMinioBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.MINIO + userId));
bo.setStatus(String.valueOf(true));
if(schisandraOssMinioDomainService.update(bo)){
return minioOssConfiguration.minioOssClient(userId);
}else{
return Result.fail("初始化失败");
}
}
Result result = minioOssConfiguration.minioOssClient(userId);
if (result.getSuccess()) {
log.info("用户: {}-> minio 初始化完成!", userId);
} else {
log.error("用户: {}-> minio 初始化完成!", userId);
@PostMapping("shutdown")
public Result shutdownMinio(@RequestParam String userId,@RequestParam String Id){
if (log.isInfoEnabled()) {
log.info("SchisandraOssMinioController.shutdown.userId:{}", JSON.toJSONString(userId));
}
SchisandraOssMinioBO bo = new SchisandraOssMinioBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.MINIO + userId));
bo.setStatus(String.valueOf(false));
if(schisandraOssMinioDomainService.update(bo)){
SpringUtil.unregisterBean(OssConstant.OssType.MINIO + userId);
return Result.ok("关闭成功");
}else{
return Result.fail("关闭失败");
}
}
@@ -92,10 +120,10 @@ public class SchisandraOssMinioController {
* @author zlg
* @date: 2024/6/26 13:55
*/
@GetMapping("listMinioDir")
@GetMapping("listDir")
public Result<String> listMinioInfo(@RequestParam String userId, @RequestParam String dirName, @RequestParam String bucket) throws Exception {
Preconditions.checkNotNull(userId, "不能为空");
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket);
return Result.ok(bean.listDir(bucket, dirName));
}
@@ -107,12 +135,12 @@ public class SchisandraOssMinioController {
* @author zlg
* @date: 2024/6/26 13:56
*/
@GetMapping("downloadMinioFile")
@GetMapping("downloadFile")
public void getMinioFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam List<String> listObjectsArgs, HttpServletResponse response) throws Exception {
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(listObjectsArgs, "不能为空");
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket);
HashMap<String, InputStream> list = bean.getTargetDir(listObjectsArgs);
ServletOutputStream output = response.getOutputStream();
@@ -133,12 +161,12 @@ public class SchisandraOssMinioController {
* @author zlg
* @date: 2024/6/26 14:34
*/
@PostMapping("deleteMinioFile")
@PostMapping("deleteFile")
public Result deleteMinioFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(filePath, "不能为空");
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket);
bean.delete(filePath);
return Result.ok();
@@ -151,7 +179,7 @@ public class SchisandraOssMinioController {
* @author zlg
* @date: 2024/6/26 14:34
*/
@PostMapping("uploadMinioFile")
@PostMapping("uploadFile")
public Result<Object> uploadMinioFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(fileName, "不能为空");
@@ -171,7 +199,7 @@ public class SchisandraOssMinioController {
// 获取文件输入流
InputStream is = file.getInputStream();
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket);
return Result.ok(bean.upLoad(is, fileName, true));
@@ -185,14 +213,14 @@ public class SchisandraOssMinioController {
* @author zlg
* @date: 2024/6/27 9:41
*/
@PostMapping("renameMinioFile")
@PostMapping("renameFile")
public Result renameMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFileName, @RequestParam String newFileName) throws IOException {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(oldFileName, "不能为空");
Preconditions.checkNotNull(newFileName, "不能为空");
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket);
try {
bean.rename(oldFileName, newFileName);
@@ -209,14 +237,14 @@ public class SchisandraOssMinioController {
* @author zlg
* @date: 2024/6/27 9:52
*/
@PostMapping("copyMinioFile")
@PostMapping("copyFile")
public Result copyMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFilePath, @RequestParam String newFilePath) throws IOException {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(oldFilePath, "不能为空");
Preconditions.checkNotNull(newFilePath, "不能为空");
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket);
try {
bean.copy(oldFilePath, newFilePath);
@@ -233,12 +261,12 @@ public class SchisandraOssMinioController {
* @author zlg
* @date: 2024/6/27 10:14
*/
@PostMapping("previewMinioFile")
@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, "不能为空");
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket);
try {
return Result.ok(bean.getMinioPreviewUrl(filePath));
@@ -255,12 +283,12 @@ public class SchisandraOssMinioController {
* @author zlg
* @date: 2024/6/27 10:17
*/
@PostMapping("shareMinioFile")
@PostMapping("shareFile")
public Result<String> shareMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String filePath, @RequestParam int time) throws IOException {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(filePath, "不能为空");
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket);
try {
return Result.ok(bean.shareMinioFile(filePath, time));
@@ -279,7 +307,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(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
return Result.ok(bean.selectAllBucket());
}
@@ -294,7 +322,7 @@ public class SchisandraOssMinioController {
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket) {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket);
return Result.ok(bean.createBucket(bucket));
}
@@ -310,7 +338,7 @@ public class SchisandraOssMinioController {
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket);
return Result.ok(bean.deleteBucket(bucket));
}
@@ -384,7 +412,7 @@ public class SchisandraOssMinioController {
@PostMapping("getBaseInfo")
public Result getBaseInfo(@RequestParam String fileName, @RequestParam String userId) {
MinioOssClient bean = SpringUtil.getBean(userId);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
if (bean == null) {
log.error("容器获取失败!");
return null;

View File

@@ -4,14 +4,20 @@ import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Preconditions;
import com.schisandra.oss.application.convert.SchisandraOssQiniuDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssSftpDTOConverter;
import com.schisandra.oss.application.dto.SchisandraOssQiniuDTO;
import com.schisandra.oss.application.oss.constant.OssConstant;
import com.schisandra.oss.application.oss.core.qiniu.QiNiuOssClient;
import com.schisandra.oss.application.oss.core.qiniu.QiNiuOssConfiguration;
import com.schisandra.oss.application.oss.exception.OssException;
import com.schisandra.oss.application.oss.model.OssInfo;
import com.schisandra.oss.common.entity.Result;
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
import com.schisandra.oss.domain.bo.SchisandraOssSftpBO;
import com.schisandra.oss.domain.redis.RedisUtil;
import com.schisandra.oss.domain.service.SchisandraOssQiniuDomainService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -52,8 +58,12 @@ public class SchisandraOssQiniuController {
* @return
*/
@GetMapping("returnAll")
public List<SchisandraOssQiniuDTO> returnAll() {
return qiNiuOssConfiguration.selectAll();
public Result returnAll() {
List<SchisandraOssQiniuBO> list = schisandraOssQiniuDomainService.selectAll();
if(list.isEmpty()){
return Result.fail();
}
return Result.ok(SchisandraOssQiniuDTOConverter.INSTANCE.convertBOToDTOList(list));
}
/**
@@ -65,9 +75,14 @@ public class SchisandraOssQiniuController {
@GetMapping("listDir")
public Result<String> listQiniuInfo(@RequestParam String userId, @RequestParam String prefix, @RequestParam String bucket) throws Exception {
Preconditions.checkNotNull(userId, "不能为空");
QiNiuOssClient bean = SpringUtil.getBean(userId);
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU+ userId);
bean.getQiNiuOssConfig().setBucketName(bucket);
return Result.ok(bean.listfile(bucket, prefix));
if(bean.listfile(bucket, prefix).isEmpty()){
return Result.fail();
}else{
return Result.ok(bean.listfile(bucket, prefix));
}
}
/**
@@ -83,7 +98,7 @@ public class SchisandraOssQiniuController {
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(oldFileName, "不能为空");
Preconditions.checkNotNull(newFileName, "不能为空");
QiNiuOssClient bean = SpringUtil.getBean(userId);
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU+ userId);
bean.getQiNiuOssConfig().setBucketName(bucket);
try {
bean.rename(oldFileName, newFileName);
@@ -107,7 +122,7 @@ public class SchisandraOssQiniuController {
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(oldFilePath, "不能为空");
Preconditions.checkNotNull(newFilePath, "不能为空");
QiNiuOssClient bean = SpringUtil.getBean(userId);
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU+ userId);
bean.getQiNiuOssConfig().setBucketName(bucket);
try {
bean.copy(oldFilePath, newFilePath);
@@ -127,7 +142,7 @@ public class SchisandraOssQiniuController {
*/
@GetMapping("downloadFile")
public void download_open(@RequestParam String userId, @RequestParam String endpoint, @RequestParam String filename, HttpServletResponse response) throws IOException {
QiNiuOssClient bean = SpringUtil.getBean(userId);
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU+ userId);
bean.getQiNiuOssConfig().setEndpoint(endpoint);
ServletOutputStream output = response.getOutputStream();
@@ -150,10 +165,14 @@ public class SchisandraOssQiniuController {
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(filePath, "不能为空");
QiNiuOssClient bean = SpringUtil.getBean(userId);
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU+ userId);
bean.getQiNiuOssConfig().setBucketName(bucket);
bean.delete(filePath);
return Result.ok();
try{
bean.delete(filePath);
return Result.ok();
}catch(OssException e){
return Result.fail();
}
}
@@ -184,9 +203,12 @@ public class SchisandraOssQiniuController {
// 获取文件输入流
InputStream is = file.getInputStream();
QiNiuOssClient bean = SpringUtil.getBean(userId);
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU+ userId);
bean.getQiNiuOssConfig().setBucketName(bucket);
return Result.ok(bean.upLoad(is, fileName, true));
if(bean.upLoad(is, fileName, true) != null){
return Result.ok(bean.upLoad(is, fileName, true));
}
return Result.fail();
}
@@ -196,11 +218,16 @@ public class SchisandraOssQiniuController {
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
* @date: 2024/7/8 17:37
*/
@GetMapping("seleteBucket")
public Result<String> seleteBucket(@RequestParam String userId) {
@SneakyThrows
@PostMapping("seleteBucket")
public Result seleteBucket(@RequestParam String userId) {
Preconditions.checkNotNull(userId, "不能为空");
QiNiuOssClient bean = SpringUtil.getBean(userId);
return Result.ok(bean.selectAllBucket());
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU+ userId);
if(bean.selectAllBucket().isEmpty()){
return Result.fail();
}
else
return Result.ok(bean.selectAllBucket());
}
/**
@@ -210,12 +237,16 @@ public class SchisandraOssQiniuController {
* @date: 2024/7/8 17:38
*/
@PostMapping("deleteBucket")
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
public Result deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
QiNiuOssClient bean = SpringUtil.getBean(userId);
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU+ userId);
bean.getQiNiuOssConfig().setBucketName(bucket);
return Result.ok(bean.deleteBucket(bucket));
if(bean.deleteBucket(bucket) == 1){
return Result.ok();
}else
return Result.fail("删除桶失败");
}
/**
@@ -225,18 +256,21 @@ public class SchisandraOssQiniuController {
* @param bucket
* @return
*/
@SneakyThrows
@PostMapping("createBucket")
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket, @RequestParam String region) {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
QiNiuOssClient bean = SpringUtil.getBean(userId);
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU+ userId);
bean.getQiNiuOssConfig().setBucketName(bucket);
bean.getQiNiuOssConfig().setRegion(region);
try {
if(bean.createBucket(bucket, region) == 1){
return Result.ok(bean.createBucket(bucket, region));
} catch (IOException e) {
throw new RuntimeException(e);
}
}else
return Result.fail("创建桶失败");
}
/**
@@ -246,17 +280,36 @@ public class SchisandraOssQiniuController {
* @date: 2024/7/8 13:34
*/
@PostMapping("init")
public void initQiniu(@RequestParam String userId) {
public Result initQiniu(@RequestParam String userId,@RequestParam String Id) {
if (log.isInfoEnabled()) {
log.info("SchisandraOssQiniuController.init.userId:{}", userId);
}
Preconditions.checkNotNull(userId, "用户id不能为空");
SchisandraOssQiniuBO bo = new SchisandraOssQiniuBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.QINIU+ userId));
bo.setStatus(String.valueOf(true));
if(schisandraOssQiniuDomainService.update(bo)){
return qiNiuOssConfiguration.qiNiuOssClient(userId);
}else{
return Result.fail("初始化失败");
}
}
Result result = qiNiuOssConfiguration.qiNiuOssClient(userId);
if (result != null) {
log.info("用户: {}-> qiniu 初始化完成!", userId);
} else {
log.error("用户: {}-> qiniu 初始化失败!", userId);
@PostMapping("shutdown")
public Result shutdownQiniu(@RequestParam String userId,@RequestParam String Id){
if (log.isInfoEnabled()) {
log.info("SchisandraOssQiniuController.shutdown.userId:{}", JSON.toJSONString(userId));
}
SchisandraOssQiniuBO bo = new SchisandraOssQiniuBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.QINIU + userId));
bo.setStatus(String.valueOf(false));
if(schisandraOssQiniuDomainService.update(bo)){
SpringUtil.unregisterBean(OssConstant.OssType.QINIU + userId);
return Result.ok("关闭成功");
}else{
return Result.fail("关闭失败");
}
}
@@ -271,37 +324,6 @@ public class SchisandraOssQiniuController {
if (log.isInfoEnabled()) {
log.info("SchisandraOssQiniuController.add.dto:{}", JSON.toJSONString(schisandraOssQiniuDTO));
}
Preconditions.checkNotNull(schisandraOssQiniuDTO.getId(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUserId(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getBasePath(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getAccessKey(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getSecretKey(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getBucketName(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getRegion(), "使用的Region不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUseHttpsDomains(), "空间相关上传管理操作是否使用 https , 默认 是不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getAccUpHostFirst(), "空间相关上传管理操作是否使用代理加速上传,默认 是不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUseDefaultUpHostIfNone(), "使用 AutoRegion 时,如果从区域信息得到上传 host 失败,使用默认的上传域名上传,默认 是upload.qiniup.com,uploadz1.qiniup.com,upload-z2.qiniup.com,upload-na0.qiniup.com,upload-as0.qiniup.com不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getPutThreshold(), "如果文件大小大于此值则使用断点上传, 否则使用Form上传不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getConnectTimeout(), "连接超时时间 单位秒(默认10s)不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getWriteTimeout(), "写超时时间 单位秒(默认 0 , 不超时)不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getReadTimeout(), "回复超时时间 单位秒(默认30s)不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getDispatcherMaxRequests(), "底层HTTP库所有的并发执行的请求数量不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getDispatcherMaxRequestsPerHost(), "底层HTTP库对每个独立的Host进行并发请求的数量不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getConnectionPoolMaxIdleCount(), "底层HTTP库中复用连接对象的最大空闲数量不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getConnectionPoolMaxIdleMinutes(), "底层HTTP库中复用连接对象的回收周期单位分钟不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getRetryMax(), "上传失败重试次数不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getPartSize(), "分片大小,默认5MB不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getTaskNum(), "并发线程数,默认等于CPU的核数不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getStatus(), "状态不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getOpenAdvancedSetup(), "是否开启高级设置不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCreatedBy(), "创建人不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCreatedTime(), "创建时间不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUpdateTime(), "更新时间不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUpdateBy(), "更新人不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getIsDeleted(), "是否删除 0 未删除 1已删除不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getExtraJson(), "额外字段不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCreateBucket(), "当桶不存在,是否创建不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCheckBucket(), "启动检测桶,是否存在不能为空");
SchisandraOssQiniuBO SchisandraOssQiniuBO = SchisandraOssQiniuDTOConverter.INSTANCE.convertDTOToBO(schisandraOssQiniuDTO);
return Result.ok(schisandraOssQiniuDomainService.add(SchisandraOssQiniuBO));
} catch (Exception e) {
@@ -321,37 +343,7 @@ public class SchisandraOssQiniuController {
if (log.isInfoEnabled()) {
log.info("SchisandraOssQiniuController.update.dto:{}", JSON.toJSONString(schisandraOssQiniuDTO));
}
Preconditions.checkNotNull(schisandraOssQiniuDTO.getId(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUserId(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getBasePath(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getAccessKey(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getSecretKey(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getBucketName(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getRegion(), "使用的Region不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUseHttpsDomains(), "空间相关上传管理操作是否使用 https , 默认 是不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getAccUpHostFirst(), "空间相关上传管理操作是否使用代理加速上传,默认 是不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUseDefaultUpHostIfNone(), "使用 AutoRegion 时,如果从区域信息得到上传 host 失败,使用默认的上传域名上传,默认 是upload.qiniup.com,uploadz1.qiniup.com,upload-z2.qiniup.com,upload-na0.qiniup.com,upload-as0.qiniup.com不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getPutThreshold(), "如果文件大小大于此值则使用断点上传, 否则使用Form上传不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getConnectTimeout(), "连接超时时间 单位秒(默认10s)不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getWriteTimeout(), "写超时时间 单位秒(默认 0 , 不超时)不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getReadTimeout(), "回复超时时间 单位秒(默认30s)不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getDispatcherMaxRequests(), "底层HTTP库所有的并发执行的请求数量不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getDispatcherMaxRequestsPerHost(), "底层HTTP库对每个独立的Host进行并发请求的数量不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getConnectionPoolMaxIdleCount(), "底层HTTP库中复用连接对象的最大空闲数量不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getConnectionPoolMaxIdleMinutes(), "底层HTTP库中复用连接对象的回收周期单位分钟不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getRetryMax(), "上传失败重试次数不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getPartSize(), "分片大小,默认5MB不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getTaskNum(), "并发线程数,默认等于CPU的核数不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getStatus(), "状态不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getOpenAdvancedSetup(), "是否开启高级设置不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCreatedBy(), "创建人不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCreatedTime(), "创建时间不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUpdateTime(), "更新时间不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUpdateBy(), "更新人不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getIsDeleted(), "是否删除 0 未删除 1已删除不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getExtraJson(), "额外字段不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCreateBucket(), "当桶不存在,是否创建不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCheckBucket(), "启动检测桶,是否存在不能为空");
SchisandraOssQiniuBO schisandraOssQiniuBO = SchisandraOssQiniuDTOConverter.INSTANCE.convertDTOToBO(schisandraOssQiniuDTO);
return Result.ok(schisandraOssQiniuDomainService.update(schisandraOssQiniuBO));
} catch (Exception e) {
@@ -371,37 +363,6 @@ public class SchisandraOssQiniuController {
if (log.isInfoEnabled()) {
log.info("SchisandraOssQiniuController.delete.dto:{}", JSON.toJSONString(schisandraOssQiniuDTO));
}
Preconditions.checkNotNull(schisandraOssQiniuDTO.getId(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUserId(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getBasePath(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getAccessKey(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getSecretKey(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getBucketName(), "不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getRegion(), "使用的Region不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUseHttpsDomains(), "空间相关上传管理操作是否使用 https , 默认 是不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getAccUpHostFirst(), "空间相关上传管理操作是否使用代理加速上传,默认 是不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUseDefaultUpHostIfNone(), "使用 AutoRegion 时,如果从区域信息得到上传 host 失败,使用默认的上传域名上传,默认 是upload.qiniup.com,uploadz1.qiniup.com,upload-z2.qiniup.com,upload-na0.qiniup.com,upload-as0.qiniup.com不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getPutThreshold(), "如果文件大小大于此值则使用断点上传, 否则使用Form上传不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getConnectTimeout(), "连接超时时间 单位秒(默认10s)不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getWriteTimeout(), "写超时时间 单位秒(默认 0 , 不超时)不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getReadTimeout(), "回复超时时间 单位秒(默认30s)不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getDispatcherMaxRequests(), "底层HTTP库所有的并发执行的请求数量不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getDispatcherMaxRequestsPerHost(), "底层HTTP库对每个独立的Host进行并发请求的数量不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getConnectionPoolMaxIdleCount(), "底层HTTP库中复用连接对象的最大空闲数量不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getConnectionPoolMaxIdleMinutes(), "底层HTTP库中复用连接对象的回收周期单位分钟不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getRetryMax(), "上传失败重试次数不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getPartSize(), "分片大小,默认5MB不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getTaskNum(), "并发线程数,默认等于CPU的核数不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getStatus(), "状态不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getOpenAdvancedSetup(), "是否开启高级设置不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCreatedBy(), "创建人不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCreatedTime(), "创建时间不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUpdateTime(), "更新时间不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getUpdateBy(), "更新人不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getIsDeleted(), "是否删除 0 未删除 1已删除不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getExtraJson(), "额外字段不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCreateBucket(), "当桶不存在,是否创建不能为空");
Preconditions.checkNotNull(schisandraOssQiniuDTO.getCheckBucket(), "启动检测桶,是否存在不能为空");
SchisandraOssQiniuBO schisandraOssQiniuBO = SchisandraOssQiniuDTOConverter.INSTANCE.convertDTOToBO(schisandraOssQiniuDTO);
return Result.ok(schisandraOssQiniuDomainService.delete(schisandraOssQiniuBO));
} catch (Exception e) {

View File

@@ -3,14 +3,19 @@ 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.SchisandraOssQiniuDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssSftpDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssTencentDTOConverter;
import com.schisandra.oss.application.dto.SchisandraOssSftpDTO;
import com.schisandra.oss.application.oss.constant.OssConstant;
import com.schisandra.oss.application.oss.core.qiniu.QiNiuOssClient;
import com.schisandra.oss.application.oss.core.sftp.SftpOssClient;
import com.schisandra.oss.application.oss.core.sftp.SftpOssConfiguration;
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.SchisandraOssSftpBO;
import com.schisandra.oss.domain.bo.SchisandraOssTencentBO;
import com.schisandra.oss.domain.redis.RedisUtil;
import com.schisandra.oss.domain.service.SchisandraOssSftpDomainService;
import lombok.SneakyThrows;
@@ -55,8 +60,12 @@ public class SchisandraOssSftpController {
* @return
*/
@GetMapping("returnAll")
public List<SchisandraOssSftpDTO> returnAll() {
return sftpOssConfiguration.selectAll();
public Result returnAll() {
List<SchisandraOssSftpBO> list = schisandraOssSftpDomainService.selectAll();
if(list.isEmpty()){
return Result.fail();
}
return Result.ok(SchisandraOssSftpDTOConverter.INSTANCE.convertBOToDTOList(list));
}
/**
@@ -71,7 +80,7 @@ public class SchisandraOssSftpController {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(oldFilePath, "不能为空");
Preconditions.checkNotNull(newFilePath, "不能为空");
QiNiuOssClient bean = SpringUtil.getBean(userId);
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.SFTP + userId);
try {
bean.copy(oldFilePath, newFilePath);
} catch (Exception e) {
@@ -89,7 +98,7 @@ public class SchisandraOssSftpController {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(oldFileName, "不能为空");
Preconditions.checkNotNull(newFileName, "不能为空");
SftpOssClient bean = SpringUtil.getBean(userId);
SftpOssClient bean = SpringUtil.getBean(OssConstant.OssType.SFTP + userId);
try {
bean.rename(oldFileName, newFileName);
} catch (Exception e) {
@@ -107,7 +116,7 @@ public class SchisandraOssSftpController {
@GetMapping("listDir")
public Result<String> listSftpInfo(@RequestParam String userId, @RequestParam String prefix) throws Exception {
Preconditions.checkNotNull(userId, "不能为空");
SftpOssClient bean = SpringUtil.getBean(userId);
SftpOssClient bean = SpringUtil.getBean(OssConstant.OssType.SFTP + userId);
return Result.ok(bean.listfile(prefix));
}
@@ -117,7 +126,7 @@ public class SchisandraOssSftpController {
*/
@PostMapping("deleteFile")
public Result deleteSftpFile(@RequestParam String userId, @RequestParam String fileName) {
SftpOssClient bean = SpringUtil.getBean(userId);
SftpOssClient bean = SpringUtil.getBean(OssConstant.OssType.SFTP + userId);
bean.delete(fileName);
return Result.ok();
}
@@ -129,7 +138,7 @@ public class SchisandraOssSftpController {
@GetMapping("downloadFile")
public void downloadSftpFile(@RequestParam String userId, @RequestParam String filename, HttpServletResponse response) throws IOException {
SftpOssClient bean = SpringUtil.getBean(userId);
SftpOssClient bean = SpringUtil.getBean(OssConstant.OssType.SFTP + userId);
ServletOutputStream output = response.getOutputStream();
@@ -164,7 +173,7 @@ public class SchisandraOssSftpController {
// 获取文件输入流
InputStream is = file.getInputStream();
SftpOssClient bean = SpringUtil.getBean(userId);
SftpOssClient bean = SpringUtil.getBean(OssConstant.OssType.SFTP + userId);
return Result.ok(bean.upLoad(is, fileName, true));
}
@@ -177,17 +186,36 @@ public class SchisandraOssSftpController {
* @date: 2024/7/12 13:34
*/
@PostMapping("init")
public void initSftp(@RequestParam String userId) {
public Result initSftp(@RequestParam String userId,@RequestParam String Id) {
if (log.isInfoEnabled()) {
log.info("SchisandraOssSftpController.init.userId:{}", userId);
}
Preconditions.checkNotNull(userId, "用户id不能为空");
SchisandraOssSftpBO bo = new SchisandraOssSftpBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.SFTP+ userId));
bo.setStatus(String.valueOf(true));
if(schisandraOssSftpDomainService.update(bo)){
return sftpOssConfiguration.sftpOssClient(userId);
}else{
return Result.fail("初始化失败");
}
}
Result result = sftpOssConfiguration.sftpOssClient(userId);
if (result != null) {
log.info("用户: {}-> sftp 初始化完成!", userId);
} else {
log.error("用户: {}-> sftp 初始化失败!", userId);
@PostMapping("shutdown")
public Result shutdownSftp(@RequestParam String userId,@RequestParam String Id){
if (log.isInfoEnabled()) {
log.info("SchisandraOssSftpController.shutdown.userId:{}", JSON.toJSONString(userId));
}
SchisandraOssSftpBO bo = new SchisandraOssSftpBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.SFTP + userId));
bo.setStatus(String.valueOf(false));
if(schisandraOssSftpDomainService.update(bo)){
SpringUtil.unregisterBean(OssConstant.OssType.SFTP+ userId);
return Result.ok("关闭成功");
}else{
return Result.fail("关闭失败");
}
}
@@ -202,28 +230,6 @@ public class SchisandraOssSftpController {
if (log.isInfoEnabled()) {
log.info("SchisandraOssSftpController.add.dto:{}", JSON.toJSONString(schisandraOssSftpDTO));
}
Preconditions.checkNotNull(schisandraOssSftpDTO.getId(), "不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getUserId(), "不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getHost(), "主机不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getPort(), "端口不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getBasePath(), "不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getUser(), "不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getPassword(), "不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getCharset(), "编码不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getConnectionTimeout(), "连接超时时长,单位毫秒不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getSoTimeout(), "Socket连接超时时长单位毫秒不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getServerLanguageCode(), "设置服务器语言不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getSystemKey(), "设置服务器系统关键词不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getPartSize(), "分片大小,默认5MB不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getTaskNum(), "并发线程数,默认等于CPU的核数不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getStatus(), "状态不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getOpenAdvancedSetup(), "是否开启高级设置不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getCreatedBy(), "创建人不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getCreatedTime(), "创建时间不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getUpdateTime(), "更新时间不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getUpdateBy(), "更新人不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getIsDeleted(), "是否删除 0 未删除 1已删除不能为空");
Preconditions.checkNotNull(schisandraOssSftpDTO.getExtraJson(), "额外字段不能为空");
SchisandraOssSftpBO SchisandraOssSftpBO = SchisandraOssSftpDTOConverter.INSTANCE.convertDTOToBO(schisandraOssSftpDTO);
return Result.ok(schisandraOssSftpDomainService.add(SchisandraOssSftpBO));
} catch (Exception e) {

View File

@@ -8,14 +8,18 @@ import com.qcloud.cos.model.CopyResult;
import com.qcloud.cos.model.DeleteObjectsRequest;
import com.qcloud.cos.model.DeleteObjectsResult;
import com.schisandra.oss.application.convert.SchisandraOssTencentDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssUpDTOConverter;
import com.schisandra.oss.application.dto.SchisandraOssTencentDTO;
import com.schisandra.oss.application.dto.SchisandraOssUpDTO;
import com.schisandra.oss.application.oss.constant.OssConstant;
import com.schisandra.oss.application.oss.core.minio.MinioOssClient;
import com.schisandra.oss.application.oss.core.tencent.TencentOssClient;
import com.schisandra.oss.application.oss.core.tencent.TencentOssConfiguration;
import com.schisandra.oss.common.entity.Result;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.bo.SchisandraOssTencentBO;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
import com.schisandra.oss.domain.redis.RedisUtil;
import com.schisandra.oss.domain.service.SchisandraOssTencentDomainService;
import io.minio.errors.*;
@@ -56,28 +60,49 @@ public class SchisandraOssTencentController {
* @return
*/
@GetMapping("returnAll")
public List<SchisandraOssTencentDTO> returnAll() {
return tencentOssConfiguration.selectAll();
public Result returnAll() {
List<SchisandraOssTencentBO> list = schisandraOssTencentDomainService.selectAll();
if(list.isEmpty()){
return Result.fail();
}
return Result.ok(SchisandraOssTencentDTOConverter.INSTANCE.convertBOToDTOList(list));
}
@PostMapping("init")
public void initTencent(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
public Result initTencent(@RequestParam String userId,@RequestParam String Id){
if (log.isInfoEnabled()) {
log.info("SchisandraOssTencentController.init.userId:{}", userId);
}
Preconditions.checkNotNull(userId, "用户id不能为空");
Result result = tencentOssConfiguration.tencentOssClient(userId);
if (result.getSuccess()) {
log.info("用户: {}-> TencentOSS 初始化完成!", userId);
} else {
log.error("用户: {}-> TencentOSS 初始化完成!", userId);
SchisandraOssTencentBO bo = new SchisandraOssTencentBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.TENCENT+ userId));
bo.setStatus(String.valueOf(true));
if(schisandraOssTencentDomainService.update(bo)){
return tencentOssConfiguration.tencentOssClient(userId);
}else{
return Result.fail("初始化失败");
}
}
@PostMapping("shutdown")
public Result shutdownTencent(@RequestParam String userId,@RequestParam String Id){
if (log.isInfoEnabled()) {
log.info("SchisandraOssTencentController.shutdown.userId:{}", JSON.toJSONString(userId));
}
SchisandraOssTencentBO bo = new SchisandraOssTencentBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.TENCENT + userId));
bo.setStatus(String.valueOf(false));
if(schisandraOssTencentDomainService.update(bo)){
SpringUtil.unregisterBean(OssConstant.OssType.TENCENT+ userId);
return Result.ok("关闭成功");
}else{
return Result.fail("关闭失败");
}
}
/**
* @description: 查询所有存储桶
* @param: [userId]
@@ -88,7 +113,7 @@ public class SchisandraOssTencentController {
@PostMapping("seleteBucket")
public Result<String> seleteBucket(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
Preconditions.checkNotNull(userId, "不能为空");
TencentOssClient bean = SpringUtil.getBean(userId);
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT+ userId);
return Result.ok(bean.selectAllBucket());
}
/**
@@ -98,11 +123,11 @@ public class SchisandraOssTencentController {
* @author zlg
* @date: 2024/6/29 13:28
*/
@GetMapping("listTencentDir")
public Result<String> listMinioInfo(@RequestParam String userId, @RequestParam String dirName,@RequestParam String bucket) throws Exception {
@GetMapping("listDir")
public Result<String> listTencentInfo(@RequestParam String userId, @RequestParam String dirName,@RequestParam String bucket) throws Exception {
Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(userId, "不能为空");
TencentOssClient bean = SpringUtil.getBean(userId);
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT+ userId);
bean.getTencentOssConfig().setBucketName(bucket);
return Result.ok(bean.listTargetDir(bucket, dirName));
}
@@ -117,7 +142,7 @@ public class SchisandraOssTencentController {
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket,@RequestParam String appId) {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
TencentOssClient bean = SpringUtil.getBean(userId);
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT+ userId);
// bean.getTencentOssConfig().setBucketName(bucket);
return Result.ok(bean.createBuctet(bucket,appId));
}
@@ -132,7 +157,7 @@ public class SchisandraOssTencentController {
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket,@RequestParam String appId) {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
TencentOssClient bean = SpringUtil.getBean(userId);
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT+ userId);
// bean.getTencentOssConfig().setBucketName(bucket);
if (bean.deleteBucket(bucket,appId)){
return Result.ok();
@@ -147,11 +172,11 @@ public class SchisandraOssTencentController {
* @author zlg
* @date: 2024/6/29 13:27
*/
@GetMapping("shareTencentUrl")
@GetMapping("shareUrl")
public Result<String> shareTencentUrl(@RequestParam String userId, @RequestParam String bucket,@RequestParam String target) {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
TencentOssClient bean = SpringUtil.getBean(userId);
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT+ userId);
return Result.ok(bean.shareTencentObject(bucket,target));
}
/**
@@ -168,7 +193,7 @@ public class SchisandraOssTencentController {
if (!target.isEmpty()){
target=target+"/"+file.getOriginalFilename();
}
TencentOssClient bean = SpringUtil.getBean(userId);
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT+ userId);
InputStream is = file.getInputStream();
bean.getTencentOssConfig().setBucketName(bucket);
//设置热力图
@@ -192,11 +217,11 @@ public class SchisandraOssTencentController {
* @author zlg
* @date: 2024/7/1 16:02
*/
@GetMapping("downloadTencent")
@GetMapping("downloadFile")
public Result<String> downloadTencent(@RequestParam String userId, @RequestParam String bucket, @RequestParam String target) {
Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(bucket, "不能为空");
TencentOssClient bean = SpringUtil.getBean(userId);
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT+ userId);
return Result.ok(bean.downloadTencent(bucket,target));
}
/**
@@ -206,10 +231,10 @@ public class SchisandraOssTencentController {
* @author zlg
* @date: 2024/7/1 16:02
*/
@PostMapping("moveTencent")
@PostMapping("moveFile")
public Result<String> moveTencent(@RequestParam String userId, @RequestParam String sourceBucket, @RequestParam String targetBucket, @RequestParam String targetName,@RequestParam String SourceName) throws IOException {
Preconditions.checkNotNull(userId, "不能为空");
TencentOssClient bean = SpringUtil.getBean(userId);
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT+ userId);
CopyResult copyResult = bean.moveTencent(SourceName, targetName, sourceBucket, targetBucket);
if (copyResult==null){
return Result.fail();
@@ -223,10 +248,10 @@ public class SchisandraOssTencentController {
* @author zlg
* @date: 2024/7/1 16:02
*/
@PostMapping("copyTencent")
@PostMapping("copyFile")
public Result<String> copyTencent(@RequestParam String userId, @RequestParam String sourceBucket, @RequestParam String targetBucket, @RequestParam String targetName,@RequestParam String SourceName) throws IOException {
Preconditions.checkNotNull(userId, "不能为空");
TencentOssClient bean = SpringUtil.getBean(userId);
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT+ userId);
CopyResult copyResult = bean.copyTencent(SourceName,targetName , sourceBucket, targetBucket);
if (copyResult==null){
return Result.fail();
@@ -240,10 +265,10 @@ public class SchisandraOssTencentController {
* @author zlg
* @date: 2024/7/1 16:02
*/
@PostMapping("deleteTencent")
@PostMapping("deleteFile")
public Result<String> deleteTencent(@RequestParam String userId, @RequestParam String bucketName, @RequestParam List<DeleteObjectsRequest.KeyVersion> target) throws IOException {
Preconditions.checkNotNull(userId, "不能为空");
TencentOssClient bean = SpringUtil.getBean(userId);
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT+ userId);
DeleteObjectsResult deleteResult = bean.deleteTencent(bucketName, target);
if (deleteResult==null){
return Result.fail();
@@ -265,42 +290,6 @@ public class SchisandraOssTencentController {
if (log.isInfoEnabled()) {
log.info("SchisandraOssTencentController.add.dto:{}", JSON.toJSONString(schisandraOssTencentDTO));
}
Preconditions.checkNotNull(schisandraOssTencentDTO.getId(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getUserId(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getBasePath(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getBucketName(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getSecretId(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getSecretKey(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getRegion(), "地域不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getHttpProtocol(), "连接OSS所采用的协议HTTP或HTTPS默认为HTTPS。不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getEndPointSuffix(), "域名后缀不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getHttpProxyIp(), "http proxy代理如果使用http proxy代理需要设置IP与端口不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getHttpProxyPort(), "代理服务器端口不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getProxyUserName(), "代理服务器验证的用户名。不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getProxyPassword(), "代理服务器验证的密码。不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getUseBasicAuth(), "是否使用基本身份验证不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getSignExpired(), "多次签名的过期时间,单位秒不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getConnectionRequestTimeout(), "获取连接的超时时间, 单位ms不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getConnectionTimeout(), "默认连接超时, 单位ms不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getSocketTimeout(), "SOCKET读取超时时间, 单位ms不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getMaxConnectionsCount(), "最大HTTP连接数不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getIdleConnectionAlive(), "空闲连接存活时间不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getUserAgent(), "user_agent标识不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getReadLimit(), "读取限制不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getCiSpecialRequest(), "数据万象特殊请求配置不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getMaxErrorRetry(), "请求失败后最大的重试次数。默认3次。不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getExtraJson(), "额外json不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getStatus(), "状态不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getCreatedBy(), "创建人不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getCreatedTime(), "创建时间不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getUpdateTime(), "更新时间不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getUpdateBy(), "更新人不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getIsDeleted(), "是否删除 0 未删除 1已删除不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getOpenAdvancedSetup(), "是否开启高级设置不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getCreateBucket(), "当桶不存在,是否创建不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getCheckBucket(), "启动检测桶,是否存在不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getPartSize(), "分片大小,默认5MB不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getTaskNum(), "并发线程数,默认等于CPU的核数不能为空");
SchisandraOssTencentBO SchisandraOssTencentBO = SchisandraOssTencentDTOConverter.INSTANCE.convertDTOToBO(schisandraOssTencentDTO);
return Result.ok(schisandraOssTencentDomainService.add(SchisandraOssTencentBO));
} catch (Exception e) {
@@ -320,42 +309,6 @@ public class SchisandraOssTencentController {
if (log.isInfoEnabled()) {
log.info("SchisandraOssTencentController.update.dto:{}", JSON.toJSONString(schisandraOssTencentDTO));
}
Preconditions.checkNotNull(schisandraOssTencentDTO.getId(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getUserId(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getBasePath(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getBucketName(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getSecretId(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getSecretKey(), "不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getRegion(), "地域不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getHttpProtocol(), "连接OSS所采用的协议HTTP或HTTPS默认为HTTPS。不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getEndPointSuffix(), "域名后缀不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getHttpProxyIp(), "http proxy代理如果使用http proxy代理需要设置IP与端口不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getHttpProxyPort(), "代理服务器端口不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getProxyUserName(), "代理服务器验证的用户名。不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getProxyPassword(), "代理服务器验证的密码。不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getUseBasicAuth(), "是否使用基本身份验证不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getSignExpired(), "多次签名的过期时间,单位秒不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getConnectionRequestTimeout(), "获取连接的超时时间, 单位ms不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getConnectionTimeout(), "默认连接超时, 单位ms不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getSocketTimeout(), "SOCKET读取超时时间, 单位ms不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getMaxConnectionsCount(), "最大HTTP连接数不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getIdleConnectionAlive(), "空闲连接存活时间不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getUserAgent(), "user_agent标识不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getReadLimit(), "读取限制不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getCiSpecialRequest(), "数据万象特殊请求配置不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getMaxErrorRetry(), "请求失败后最大的重试次数。默认3次。不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getExtraJson(), "额外json不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getStatus(), "状态不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getCreatedBy(), "创建人不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getCreatedTime(), "创建时间不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getUpdateTime(), "更新时间不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getUpdateBy(), "更新人不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getIsDeleted(), "是否删除 0 未删除 1已删除不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getOpenAdvancedSetup(), "是否开启高级设置不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getCreateBucket(), "当桶不存在,是否创建不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getCheckBucket(), "启动检测桶,是否存在不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getPartSize(), "分片大小,默认5MB不能为空");
Preconditions.checkNotNull(schisandraOssTencentDTO.getTaskNum(), "并发线程数,默认等于CPU的核数不能为空");
SchisandraOssTencentBO schisandraOssTencentBO = SchisandraOssTencentDTOConverter.INSTANCE.convertDTOToBO(schisandraOssTencentDTO);
return Result.ok(schisandraOssTencentDomainService.update(schisandraOssTencentBO));
} catch (Exception e) {

View File

@@ -5,10 +5,12 @@ 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.constant.OssConstant;
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.SchisandraOssAliBO;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
import com.schisandra.oss.domain.service.SchisandraOssUpDomainService;
import lombok.SneakyThrows;
@@ -44,8 +46,12 @@ public class SchisandraOssUpController {
* @return
*/
@GetMapping("returnAll")
public List<SchisandraOssUpDTO> returnAll() {
return upOssConfiguration.selectAll();
public Result returnAll() {
List<SchisandraOssUpBO> list = schisandraOssUpDomainService.selectAll();
if(list.isEmpty()){
return Result.fail();
}
return Result.ok(SchisandraOssUpDTOConverter.INSTANCE.convertBOToDTOList(list));
}
/**
@@ -56,14 +62,37 @@ public class SchisandraOssUpController {
* @date: 2024/6/28 上午11:36
*/
@PostMapping("init")
public void init(@RequestParam("userId") String userId) {
try {
upOssConfiguration.upOssClient(userId);
log.info("用户:{} 又拍云oss初始化成功", userId);
} catch (Exception e) {
log.error("用户:{} 又拍云oss初始化失败", userId);
public Result init(@RequestParam String userId,@RequestParam String Id) {
if (log.isInfoEnabled()) {
log.info("SchisandraOssUpController.init.userId:{}", userId);
}
Preconditions.checkNotNull(userId, "用户id不能为空");
SchisandraOssUpBO bo = new SchisandraOssUpBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.UP+ userId));
bo.setStatus(String.valueOf(true));
if(schisandraOssUpDomainService.update(bo)){
return upOssConfiguration.upOssClient(userId);
}else{
return Result.fail("初始化失败");
}
}
@PostMapping("shutdown")
public Result shutdownUp(@RequestParam String userId,@RequestParam String Id){
if (log.isInfoEnabled()) {
log.info("SchisandraOssUpController.shutdown.userId:{}", JSON.toJSONString(userId));
}
SchisandraOssUpBO bo = new SchisandraOssUpBO();
bo.setId(Long.valueOf(Id));
bo.setUserId(Long.valueOf(OssConstant.OssType.UP + userId));
bo.setStatus(String.valueOf(false));
if(schisandraOssUpDomainService.update(bo)){
SpringUtil.unregisterBean(OssConstant.OssType.UP+ userId);
return Result.ok("关闭成功");
}else{
return Result.fail("关闭失败");
}
}
/**
@@ -75,7 +104,7 @@ public class SchisandraOssUpController {
*/
@PostMapping("getInfo")
public Result getInfo(@RequestParam("userId") String userId, @RequestParam("fileName") String fileName) {
UpOssClient bean = SpringUtil.getBean(userId);
UpOssClient bean = SpringUtil.getBean(OssConstant.OssType.UP+ userId);
OssInfo info = bean.getInfo(fileName);
return Result.ok(info);
}
@@ -88,9 +117,9 @@ public class SchisandraOssUpController {
* @date: 2024/6/28 下午3:00
*/
@SneakyThrows
@PostMapping("upload")
@PostMapping("uploadFile")
public Result upload(@RequestParam("userId") String userId, @RequestParam("file") MultipartFile file, @RequestParam("isOverride") Boolean isOverride) {
UpOssClient bean = SpringUtil.getBean(userId);
UpOssClient bean = SpringUtil.getBean(OssConstant.OssType.UP+ userId);
String originalFileName = file.getOriginalFilename();
InputStream is = file.getInputStream();
OssInfo ossInfo = bean.upLoad(is, originalFileName, isOverride);
@@ -106,7 +135,7 @@ public class SchisandraOssUpController {
*/
@PostMapping("deleteFile")
public Result deleteFile(@RequestParam("userId") String userId, @RequestParam("fileName") String fileName) {
UpOssClient bean = SpringUtil.getBean(userId);
UpOssClient bean = SpringUtil.getBean(OssConstant.OssType.UP+ userId);
bean.delete(fileName);
return Result.ok();
}
@@ -121,7 +150,7 @@ public class SchisandraOssUpController {
@SneakyThrows
@GetMapping("download")
public Result download(@RequestParam("userId") String userId, @RequestParam("fileName") String fileName, HttpServletResponse response) {
UpOssClient bean = SpringUtil.getBean(userId);
UpOssClient bean = SpringUtil.getBean(OssConstant.OssType.UP+ userId);
ServletOutputStream output = response.getOutputStream();
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
response.setContentType("application/octet-stream");

View File

@@ -32,6 +32,8 @@ public class SchisandraUserOssController {
private final String USER_OSS_PREFIX = "oss:user:heat";
@Resource
RedisUtil redisUtil;
/**
* 新增用户对象存储映射表
*/
@@ -151,6 +153,4 @@ public class SchisandraUserOssController {
String key = redisUtil.buildKey(USER_OSS_PREFIX+":"+userId);
return Result.ok(redisUtil.getDataFromDirectory(key));
}
}

View File

@@ -2,10 +2,14 @@ package com.schisandra.oss.application.convert;
import com.schisandra.oss.application.dto.SchisandraOssAliDTO;
import com.schisandra.oss.application.dto.SchisandraUserOssDTO;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.bo.SchisandraUserOssBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* dto转换器
*
@@ -19,5 +23,5 @@ public interface SchisandraOssAliDTOConverter {
SchisandraOssAliBO convertDTOToBO(SchisandraOssAliDTO schisandraOssAliDTO);
SchisandraOssAliDTO convertBOToDTO(SchisandraOssAliBO schisandraOssAli);
List<SchisandraOssAliDTO> convertBOToDTOList(List<SchisandraOssAliBO> schisandraAliBOList);
}

View File

@@ -1,10 +1,14 @@
package com.schisandra.oss.application.convert;
import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
import com.schisandra.oss.application.dto.SchisandraOssQiniuDTO;
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 七牛云对象存储配置表 dto转换器
*
@@ -19,4 +23,5 @@ public interface SchisandraOssQiniuDTOConverter {
SchisandraOssQiniuBO convertDTOToBO(SchisandraOssQiniuDTO schisandraOssQiniuDTO);
SchisandraOssQiniuDTO convertBOToDTO(SchisandraOssQiniuBO schisandraOssQiniuBO);
List<SchisandraOssQiniuDTO> convertBOToDTOList(List<SchisandraOssQiniuBO> SchisandraOssQiniuBOList);
}

View File

@@ -1,10 +1,14 @@
package com.schisandra.oss.application.convert;
import com.schisandra.oss.application.dto.SchisandraOssQiniuDTO;
import com.schisandra.oss.application.dto.SchisandraOssSftpDTO;
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
import com.schisandra.oss.domain.bo.SchisandraOssSftpBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* sftp存储配置表 dto转换器
*
@@ -19,4 +23,5 @@ public interface SchisandraOssSftpDTOConverter {
SchisandraOssSftpBO convertDTOToBO(SchisandraOssSftpDTO schisandraOssSftpDTO);
SchisandraOssSftpDTO convertBOToDTO(SchisandraOssSftpBO schisandraOssSftpBO);
List<SchisandraOssSftpDTO> convertBOToDTOList(List<SchisandraOssSftpBO> SchisandraOssSftpBOList);
}

View File

@@ -1,10 +1,14 @@
package com.schisandra.oss.application.convert;
import com.schisandra.oss.application.dto.SchisandraOssSftpDTO;
import com.schisandra.oss.application.dto.SchisandraOssTencentDTO;
import com.schisandra.oss.domain.bo.SchisandraOssSftpBO;
import com.schisandra.oss.domain.bo.SchisandraOssTencentBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 腾讯云对象存储配置表 dto转换器
*
@@ -20,4 +24,5 @@ public interface SchisandraOssTencentDTOConverter {
SchisandraOssTencentDTO convertBOToDTO(SchisandraOssTencentBO schisandraOssTencentBO);
List<SchisandraOssTencentDTO> convertBOToDTOList(List<SchisandraOssTencentBO> SchisandraOssTencentBOList);
}

View File

@@ -1,10 +1,14 @@
package com.schisandra.oss.application.convert;
import com.schisandra.oss.application.dto.SchisandraOssTencentDTO;
import com.schisandra.oss.application.dto.SchisandraOssUpDTO;
import com.schisandra.oss.domain.bo.SchisandraOssTencentBO;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 又拍云对象存储配置表 dto转换器
*
@@ -19,4 +23,5 @@ public interface SchisandraOssUpDTOConverter {
SchisandraOssUpBO convertDTOToBO(SchisandraOssUpDTO schisandraOssUpDTO);
SchisandraOssUpDTO convertBOToDTO(SchisandraOssUpBO schisandraOssUpBO);
List<SchisandraOssUpDTO> convertBOToDTOList(List<SchisandraOssUpBO> SchisandraOssUpBOList);
}

View File

@@ -6,6 +6,7 @@ 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;
@@ -13,6 +14,8 @@ 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;
@@ -54,11 +57,21 @@ public class AliOssClient implements StandardOssClient {
private OSS oss;
private AliOssConfig aliOssConfig;
public List<String> selectAllBucket() {
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();
}
return DataSizeUtil.format(x);
}
public HashMap<String,String> selectAllBucket() {
List<Bucket> buckets = oss.listBuckets();
List<String> names = new ArrayList<>();
HashMap<String,String> names = new HashMap<>();
buckets.forEach(bucket -> {
names.add(bucket.getName());
names.put(bucket.getName(),getAliBucketSize(bucket.getName()));
});
return names;
}

View File

@@ -7,9 +7,11 @@ import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.comm.Protocol;
import com.schisandra.oss.application.convert.SchisandraOssAliDTOConverter;
import com.schisandra.oss.application.dto.SchisandraOssAliDTO;
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.AliOssClientConfig;
import com.schisandra.oss.application.oss.core.ali.model.AliOssConfig;
import com.schisandra.oss.common.entity.Result;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.service.SchisandraOssAliDomainService;
import lombok.extern.slf4j.Slf4j;
@@ -31,19 +33,10 @@ import java.util.concurrent.CompletableFuture;
public class AliOssConfiguration {
@Resource
SchisandraOssAliDomainService schisandraOssAliDomainService;
private SchisandraOssAliDomainService schisandraOssAliDomainService;
public List<SchisandraOssAliDTO> selectAll(){
List<SchisandraOssAliBO> schisandraOssAliBO_list = schisandraOssAliDomainService.selectAll();
List<SchisandraOssAliDTO> schisandraOssAliDTO_list = new ArrayList<>();
for (SchisandraOssAliBO schisandraOssAliBO : schisandraOssAliBO_list ){
SchisandraOssAliDTO schisandraOssAliDTO = SchisandraOssAliDTOConverter.INSTANCE.convertBOToDTO(schisandraOssAliBO);
schisandraOssAliDTO_list.add(schisandraOssAliDTO);
}
return schisandraOssAliDTO_list;
}
public StandardOssClient aliOssClient(String userId) {
public Result aliOssClient(String userId) {
CompletableFuture<SchisandraOssAliDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
SchisandraOssAliBO schisandraOssAliBO = schisandraOssAliDomainService.getAliOssConfig(Long.valueOf(userId));
SchisandraOssAliDTO schisandraOssAliDTO = SchisandraOssAliDTOConverter.INSTANCE.convertBOToDTO(schisandraOssAliBO);
@@ -52,16 +45,20 @@ public class AliOssConfiguration {
SchisandraOssAliDTO ali = futurePrice.join();
if (ObjectUtil.isEmpty(ali)) {
log.error("ali oss配置信息获取失败");
return null;
return Result.fail();
}
AliOssConfig aliOssConfig = new AliOssConfig();
aliOssConfig.setEndpoint(ali.getEndpoint());
aliOssConfig.setAccessKeyId(ali.getAccessKeyId());
aliOssConfig.setAccessKeySecret(ali.getAccessKeySecret());
aliOssConfig.setBasePath(ali.getBasePath());
SpringUtil.registerBean(userId, aliOssClient(aliOssConfig));
return aliOssClient(aliOssConfig);
try{
SpringUtil.registerBean(OssConstant.OssType.ALI+ userId, aliOssClient(aliOssConfig));
return Result.ok();
}catch(Exception e){
e.printStackTrace();
return Result.fail();
}
}
public AliOssClient aliOssClient(AliOssConfig aliOssConfig) {

View File

@@ -6,7 +6,9 @@ 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.dto.SchisandraOssMinioDTO;
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;
import com.schisandra.oss.application.oss.core.minio.model.MinioOssClientConfig;
import com.schisandra.oss.application.oss.core.minio.model.MinioOssConfig;
import com.schisandra.oss.common.entity.Result;
@@ -39,43 +41,28 @@ public class MinioOssConfiguration {
@Resource
private SchisandraOssMinioDomainService schisandraOssMinioDomainService;
public List<SchisandraOssMinioDTO> selectAll(){
List<SchisandraOssMinioBO> schisandraOssMinioBO_list = schisandraOssMinioDomainService.selectAll();
List<SchisandraOssMinioDTO> schisandraOssAliDTO_list = new ArrayList<>();
for (SchisandraOssMinioBO schisandraOssMinioBO : schisandraOssMinioBO_list ){
SchisandraOssMinioDTO schisandraOssMinioDTO = SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTO(schisandraOssMinioBO);
schisandraOssAliDTO_list.add(schisandraOssMinioDTO);
}
return schisandraOssAliDTO_list;
}
public Result minioOssClient(String userId) {
try {
SchisandraOssMinioDTO minio = minioOssConfiguration.getSchisandraOssMinioDTO(userId);
if (minio == null) return null;
MinioOssConfig minioOssConfig = new MinioOssConfig();
minioOssConfig.setBasePath(minio.getBasePath());
minioOssConfig.setBucketName(minio.getBucketName());
minioOssConfig.setAccessKey(minio.getAccessKey());
minioOssConfig.setSecretKey(minio.getSecretKey());
minioOssConfig.setEndpoint(minio.getEndpoint());
minioOssConfig.init();
if (Boolean.parseBoolean(minio.getOpenAdvancedSetup())) {
MinioOssClientConfig minioOssClientConfig = new MinioOssClientConfig();
minioOssClientConfig.setWriteTimeout(minio.getWriteTimeout());
minioOssClientConfig.setConnectTimeout(minio.getConnectTimeout());
minioOssClientConfig.setReadTimeout(minio.getReadTimeout());
minioOssClientConfig.setFollowSslRedirects(Boolean.parseBoolean(minio.getFollowSslRedirects()));
minioOssClientConfig.setRetryOnConnectionFailure(Boolean.parseBoolean(minio.getRetryOnConnectionFailure()));
minioOssClientConfig.setPingInterval(minio.getPingInterval());
minioOssClientConfig.setFollowRedirects(Boolean.parseBoolean(minio.getFollowRedirects()));
minioOssClientConfig.setCallTimeout(minio.getCallTimeout());
minioOssConfig.setClientConfig(minioOssClientConfig);
}
SpringUtil.registerBean(userId, minioOssClient(minioOssConfig));
CompletableFuture<SchisandraOssMinioDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
SchisandraOssMinioBO schisandraOssMinioBO = schisandraOssMinioDomainService.getMinioConfig(Long.valueOf(userId));
SchisandraOssMinioDTO schisandraOssMinioDTO = SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTO(schisandraOssMinioBO);
return schisandraOssMinioDTO;
});
SchisandraOssMinioDTO minio = futurePrice.join();
if (ObjectUtil.isEmpty(minio)) {
log.error("minio oss配置信息获取失败");
return Result.fail();
}
MinioOssConfig minioOssConfig = new MinioOssConfig();
minioOssConfig.setEndpoint(minio.getEndpoint());
minioOssConfig.setAccessKey(minio.getAccessKey());
minioOssConfig.setSecretKey(minio.getSecretKey());
minioOssConfig.setBasePath(minio.getBasePath());
try{
SpringUtil.registerBean(OssConstant.OssType.MINIO+ userId, minioOssClient(minioOssConfig));
return Result.ok();
} catch (Exception e) {
log.error("MinioOssConfiguration.minioOssClient:{}", e.getMessage(), e);
}catch(Exception e){
e.printStackTrace();
return Result.fail();
}
}

View File

@@ -27,6 +27,9 @@ import com.schisandra.oss.application.oss.model.OssInfo;
import com.schisandra.oss.application.oss.model.download.DownloadCheckPoint;
import com.schisandra.oss.application.oss.model.download.DownloadObjectStat;
import com.schisandra.oss.application.oss.utils.OssPathUtil;
import io.minio.ListObjectsArgs;
import io.minio.Result;
import io.minio.messages.Item;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -66,15 +69,18 @@ public class QiNiuOssClient implements StandardOssClient {
private QiNiuOssConfig qiNiuOssConfig;
private Configuration configuration;
/*
* 将时间转换为时间戳
*/
@SneakyThrows
public static long dateToStamp(String s) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(s);
long ts = date.getTime();
return ts;
public String getQiniuBucketSize(String bucket) {
String delimiter = "";
Long x = 0L;
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucket, "", 1000, delimiter);
while (fileListIterator.hasNext()) {
FileInfo[] items = fileListIterator.next();
for (FileInfo item : items) {
x += item.fsize;
}
}
return DataSizeUtil.format(x);
}
/**
@@ -86,7 +92,6 @@ public class QiNiuOssClient implements StandardOssClient {
public List<OssInfo> listfile(String bucket, String prefix) {
String delimiter = "";
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucket, prefix, 1000, delimiter);
List<OssInfo> infos = new ArrayList<>();
while (fileListIterator.hasNext()){
@@ -143,11 +148,13 @@ public class QiNiuOssClient implements StandardOssClient {
}
}
@SneakyThrows
public String[] selectAllBucket() {
String[] buckets = bucketManager.buckets();
return buckets;
public HashMap<String, String> selectAllBucket() throws IOException{
String[] list = bucketManager.buckets();
HashMap<String, String> names = new HashMap<>();
for(int i=0;i<list.length;i++){
names.put(list[i],getQiniuBucketSize(list[i]));
}
return names;
}
@@ -176,7 +183,6 @@ public class QiNiuOssClient implements StandardOssClient {
System.out.println(re.code());
System.out.println(re.toString());
return re.code();
}
}

View File

@@ -7,15 +7,20 @@ import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import com.schisandra.oss.application.convert.SchisandraOssAliDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssQiniuDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssUpDTOConverter;
import com.schisandra.oss.application.dto.SchisandraOssAliDTO;
import com.schisandra.oss.application.dto.SchisandraOssQiniuDTO;
import com.schisandra.oss.application.dto.SchisandraOssUpDTO;
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;
import com.schisandra.oss.application.oss.core.qiniu.model.QiNiuOssClientConfig;
import com.schisandra.oss.application.oss.core.qiniu.model.QiNiuOssConfig;
import com.schisandra.oss.application.oss.model.SliceConfig;
import com.schisandra.oss.common.entity.Result;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
import com.schisandra.oss.domain.service.SchisandraOssQiniuDomainService;
@@ -45,16 +50,6 @@ public class QiNiuOssConfiguration {
@Resource
private SchisandraOssQiniuDomainService schisandraOssQiniuDomainService;
public List<SchisandraOssQiniuDTO> selectAll(){
List<SchisandraOssQiniuBO> schisandraOssQiniuBO_list = schisandraOssQiniuDomainService.selectAll();
List<SchisandraOssQiniuDTO> schisandraOssQiniuDTO_list = new ArrayList<>();
for (SchisandraOssQiniuBO schisandraOssQiniuBO : schisandraOssQiniuBO_list ){
SchisandraOssQiniuDTO schisandraOssQiniuDTO = SchisandraOssQiniuDTOConverter.INSTANCE.convertBOToDTO(schisandraOssQiniuBO);
schisandraOssQiniuDTO_list.add(schisandraOssQiniuDTO);
}
return schisandraOssQiniuDTO_list;
}
public SchisandraOssQiniuDTO getSchisandraOssQiNDTO(String userId) {
CompletableFuture<SchisandraOssQiniuDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
@@ -71,22 +66,28 @@ public class QiNiuOssConfiguration {
}
public Result qiNiuOssClient(String userId) {
try {
SchisandraOssQiniuDTO qiniu = qiniuOssConfiguration.getSchisandraOssQiNDTO(userId);
if (qiniu == null) return null;
QiNiuOssConfig qiniuOssConfig = new QiNiuOssConfig();
qiniuOssConfig.setBasePath(qiniu.getBasePath());
qiniuOssConfig.setBucketName(qiniu.getBucketName());
qiniuOssConfig.setAccessKey(qiniu.getAccessKey());
qiniuOssConfig.setSecretKey(qiniu.getSecretKey());
qiniuOssConfig.setRegion(qiniu.getRegion());
qiniuOssConfig.setEndpoint(qiniu.getEndpoint());
qiniuOssConfig.init();
SpringUtil.registerBean(userId, qiNiuOssClient(qiniuOssConfig));
CompletableFuture<SchisandraOssQiniuDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
SchisandraOssQiniuBO schisandraOssQiniuBO = schisandraOssQiniuDomainService.getQiniuOssConfig(userId);
SchisandraOssQiniuDTO schisandraOssQiniuDTO = SchisandraOssQiniuDTOConverter.INSTANCE.convertBOToDTO(schisandraOssQiniuBO);
return schisandraOssQiniuDTO;
});
SchisandraOssQiniuDTO qiniu = futurePrice.join();
if (ObjectUtil.isEmpty(qiniu)) {
log.error("qiniu oss配置信息获取失败");
return Result.fail();
}
QiNiuOssConfig qiniuOssConfig = new QiNiuOssConfig();
qiniuOssConfig.setBasePath(qiniu.getBasePath());
qiniuOssConfig.setBucketName(qiniu.getBucketName());
qiniuOssConfig.setAccessKey(qiniu.getAccessKey());
qiniuOssConfig.setSecretKey(qiniu.getSecretKey());
qiniuOssConfig.setRegion(qiniu.getRegion());
qiniuOssConfig.setEndpoint(qiniu.getEndpoint());
try{
SpringUtil.registerBean(OssConstant.OssType.QINIU+ userId, qiNiuOssClient(qiniuOssConfig));
return Result.ok();
} catch (Exception e) {
log.error("QiniuOssConfiguration.qiniuOssClient:{}", e.getMessage(), e);
}catch(Exception e){
e.printStackTrace();
return Result.fail();
}
}

View File

@@ -2,13 +2,18 @@ package com.schisandra.oss.application.oss.core.sftp;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.extra.ssh.Sftp;
import com.schisandra.oss.application.convert.SchisandraOssAliDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssSftpDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssUpDTOConverter;
import com.schisandra.oss.application.dto.SchisandraOssAliDTO;
import com.schisandra.oss.application.dto.SchisandraOssSftpDTO;
import com.schisandra.oss.application.dto.SchisandraOssUpDTO;
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;
import com.schisandra.oss.application.oss.core.sftp.model.SftpOssConfig;
import com.schisandra.oss.common.entity.Result;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.bo.SchisandraOssSftpBO;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
import com.schisandra.oss.domain.service.SchisandraOssSftpDomainService;
@@ -33,16 +38,6 @@ public class SftpOssConfiguration {
public static final String DEFAULT_BEAN_NAME = "sftpOssClient";
public List<SchisandraOssSftpDTO> selectAll(){
List<SchisandraOssSftpBO> schisandraOssSftpBO_list = schisandraOssSftpDomainService.selectAll();
List<SchisandraOssSftpDTO> schisandraOssSdtpDTO_list = new ArrayList<>();
for (SchisandraOssSftpBO shisandraOssSftpBO : schisandraOssSftpBO_list ){
SchisandraOssSftpDTO schisandraOssSftpDTO = SchisandraOssSftpDTOConverter.INSTANCE.convertBOToDTO(shisandraOssSftpBO);
schisandraOssSdtpDTO_list.add(schisandraOssSftpDTO);
}
return schisandraOssSdtpDTO_list;
}
public SchisandraOssSftpDTO getSchisandraOssSftpDTO(String userId) {
CompletableFuture<SchisandraOssSftpDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
SchisandraOssSftpBO sftpBO = schisandraOssSftpDomainService.getSftpOssConfig(userId);
@@ -59,21 +54,27 @@ public class SftpOssConfiguration {
public Result sftpOssClient(String userId) {
try {
SchisandraOssSftpDTO sftp = sftpOssConfiguration.getSchisandraOssSftpDTO(userId);
if (sftp == null) return null;
SftpOssConfig sftpOssConfig = new SftpOssConfig();
sftpOssConfig.setBasePath(sftp.getBasePath());
sftpOssConfig.setHost(sftp.getHost());
sftpOssConfig.setPort(sftp.getPort());
sftpOssConfig.setPassword(sftp.getPassword());
sftpOssConfig.setCharset(sftp.getCharset());
sftpOssConfig.init();
SpringUtil.registerBean(userId, sftpOssClient(sftpOssConfig));
CompletableFuture<SchisandraOssSftpDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
SchisandraOssSftpBO schisandraOssSftpBO = schisandraOssSftpDomainService.getSftpOssConfig(userId);
SchisandraOssSftpDTO schisandraOssSftpDTO = SchisandraOssSftpDTOConverter.INSTANCE.convertBOToDTO(schisandraOssSftpBO);
return schisandraOssSftpDTO;
});
SchisandraOssSftpDTO sftp = futurePrice.join();
if (ObjectUtil.isEmpty(sftp)) {
log.error("sftp oss配置信息获取失败");
return Result.fail();
}
SftpOssConfig sftpOssConfig = new SftpOssConfig();
sftpOssConfig.setBasePath(sftp.getBasePath());
sftpOssConfig.setHost(sftp.getHost());
sftpOssConfig.setPort(sftp.getPort());
sftpOssConfig.setPassword(sftp.getPassword());
sftpOssConfig.setCharset(sftp.getCharset());
try{
SpringUtil.registerBean(OssConstant.OssType.SFTP+ userId, sftpOssClient(sftpOssConfig));
return Result.ok();
} catch (Exception e) {
log.error("SftpOssConfiguration.qiniuOssClient:{}", e.getMessage(), e);
}catch(Exception e){
e.printStackTrace();
return Result.fail();
}
}

View File

@@ -10,14 +10,19 @@ import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.region.Region;
import com.schisandra.oss.application.convert.SchisandraOssAliDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssTencentDTOConverter;
import com.schisandra.oss.application.convert.SchisandraOssUpDTOConverter;
import com.schisandra.oss.application.dto.SchisandraOssAliDTO;
import com.schisandra.oss.application.dto.SchisandraOssTencentDTO;
import com.schisandra.oss.application.dto.SchisandraOssUpDTO;
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;
import com.schisandra.oss.application.oss.core.tencent.model.TencentOssClientConfig;
import com.schisandra.oss.application.oss.core.tencent.model.TencentOssConfig;
import com.schisandra.oss.common.entity.Result;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.bo.SchisandraOssTencentBO;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
import com.schisandra.oss.domain.service.SchisandraOssTencentDomainService;
@@ -29,6 +34,7 @@ import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import static com.tencentcloudapi.common.profile.Region.Chengdu;
@@ -46,47 +52,33 @@ public class TencentOssConfiguration {
@Resource
private SchisandraOssTencentDomainService schisandraOssTencentDomainService;
public List<SchisandraOssTencentDTO> selectAll(){
List<SchisandraOssTencentBO> schisandraOssTencentBO_list = schisandraOssTencentDomainService.selectAll();
List<SchisandraOssTencentDTO> schisandraOssTencentDTO_list = new ArrayList<>();
for (SchisandraOssTencentBO schisandraOssTencentBO : schisandraOssTencentBO_list ){
SchisandraOssTencentDTO schisandraOssTencentDTO = SchisandraOssTencentDTOConverter.INSTANCE.convertBOToDTO(schisandraOssTencentBO);
schisandraOssTencentDTO_list.add(schisandraOssTencentDTO);
}
return schisandraOssTencentDTO_list;
}
public Result tencentOssClient(String userId) {
SchisandraOssTencentBO schisandraOssTencentBO = schisandraOssTencentDomainService.getTencentOssConfig(userId);
SchisandraOssTencentDTO schisandraOssTencentDTO = SchisandraOssTencentDTOConverter.INSTANCE.convertBOToDTO(schisandraOssTencentBO);
if (ObjectUtil.isEmpty(schisandraOssTencentDTO)) {
log.error("Tencent oss配置信息获取失败");
return null;
CompletableFuture<SchisandraOssTencentDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
SchisandraOssTencentBO schisandraOssTencentBO = schisandraOssTencentDomainService.getTencentOssConfig(userId);
SchisandraOssTencentDTO schisandraOssTencentDTO = SchisandraOssTencentDTOConverter.INSTANCE.convertBOToDTO(schisandraOssTencentBO);
return schisandraOssTencentDTO;
});
SchisandraOssTencentDTO tencent = futurePrice.join();
if (ObjectUtil.isEmpty(tencent)) {
log.error("tencent oss配置信息获取失败");
return Result.fail();
}
String secretId = schisandraOssTencentDTO.getSecretId();
String secretKey = schisandraOssTencentDTO.getSecretKey();
TencentOssConfig tencentOssConfig = new TencentOssConfig();
tencentOssConfig.setSecretId(secretId);
tencentOssConfig.setSecretKey(secretKey);
// COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
// Region region = new Region();
//高级设置
tencentOssConfig.setSecretId(tencent.getSecretId());
tencentOssConfig.setSecretKey(tencent.getSecretKey());
TencentOssClientConfig tencentOssClientConfig = new TencentOssClientConfig();
tencentOssClientConfig.setRegion("ap-chengdu");
// COSClient cosClient = new COSClient(cred, clientConfig.toClientConfig());
tencentOssConfig.setClientConfig(tencentOssClientConfig);
//
try {
SpringUtil.registerBean(userId, tencentOssClient(tencentOssConfig));
try{
SpringUtil.registerBean(OssConstant.OssType.TENCENT+ userId, tencentOssClient(tencentOssConfig));
return Result.ok();
} catch (Exception e) {
log.error("TencentOssConfiguration.tencentOssClient:{}", e.getMessage(), e);
}catch(Exception e){
e.printStackTrace();
return Result.fail();
}
}
private StandardOssClient tencentOssClient(TencentOssConfig tencentOssConfig) {
TencentOssClientConfig clientConfig = Optional.ofNullable(tencentOssConfig.getClientConfig()).orElse(new TencentOssClientConfig());
COSCredentials cosCredentials = cosCredentials(tencentOssConfig);

View File

@@ -11,9 +11,11 @@ import com.schisandra.oss.application.dto.SchisandraOssUcloudDTO;
import com.schisandra.oss.application.dto.SchisandraOssUpDTO;
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;
import com.schisandra.oss.application.oss.core.up.model.UpOssClientConfig;
import com.schisandra.oss.application.oss.core.up.model.UpOssConfig;
import com.schisandra.oss.application.oss.model.SliceConfig;
import com.schisandra.oss.common.entity.Result;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.bo.SchisandraOssUcloudBO;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
@@ -36,6 +38,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
/**
* @description:
@@ -53,38 +56,31 @@ public class UpOssConfiguration {
@Resource
private SchisandraOssUpDomainService schisandraOssUpDomainService;
public List<SchisandraOssUpDTO> selectAll(){
List<SchisandraOssUpBO> schisandraOssUpBO_list = schisandraOssUpDomainService.selectAll();
List<SchisandraOssUpDTO> schisandraOssUpDTO_list = new ArrayList<>();
for (SchisandraOssUpBO schisandraOssUpBO : schisandraOssUpBO_list ){
public Result upOssClient(String userId) {
CompletableFuture<SchisandraOssUpDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
SchisandraOssUpBO schisandraOssUpBO = schisandraOssUpDomainService.getUpOssConfig(userId);
SchisandraOssUpDTO schisandraOssUpDTO = SchisandraOssUpDTOConverter.INSTANCE.convertBOToDTO(schisandraOssUpBO);
schisandraOssUpDTO_list.add(schisandraOssUpDTO);
return schisandraOssUpDTO;
});
SchisandraOssUpDTO up = futurePrice.join();
if (ObjectUtil.isEmpty(up)) {
log.error("up oss配置信息获取失败");
return Result.fail();
}
return schisandraOssUpDTO_list;
}
public StandardOssClient upOssClient(String userId) {
SchisandraOssUpBO schisandraOssUpBO = schisandraOssUpDomainService.getUpOssConfig(userId);
SchisandraOssUpDTO schisandraOssUpDTO = SchisandraOssUpDTOConverter.INSTANCE.convertBOToDTO(schisandraOssUpBO);
log.info("Up oss配置信息获取成功{}", schisandraOssUpDTO);
if (ObjectUtil.isEmpty(schisandraOssUpDTO)) {
log.error("Up oss配置信息获取失败");
return null;
}
String userName = schisandraOssUpDTO.getUserName();
String password = schisandraOssUpDTO.getPassword();
String bucketName = schisandraOssUpDTO.getBucketName();
String basePath = schisandraOssUpDTO.getBasePath();
UpOssConfig upOssConfig = new UpOssConfig();
upOssConfig.setUserName(userName);
upOssConfig.setPassword(password);
upOssConfig.setBucketName(bucketName);
upOssConfig.setBasePath(basePath);
SpringUtil.registerBean(userId, upOssClient(upOssConfig));
return upOssClient(upOssConfig);
upOssConfig.setUserName(up.getUserName());
upOssConfig.setPassword(up.getPassword());
upOssConfig.setBucketName(up.getBucketName());
upOssConfig.setBasePath(up.getBasePath());
try{
SpringUtil.registerBean(OssConstant.OssType.UP+ userId, upOssClient(upOssConfig));
return Result.ok();
}catch(Exception e){
e.printStackTrace();
return Result.fail();
}
}
private UpOssClient upOssClient(UpOssConfig upOssConfig) {

View File

@@ -0,0 +1,56 @@
package com.schisandra.oss.common.enums;
public enum OssName {
/**
* 阿里oss
*/
ALI("阿里云OSS"),
/**
* Minio oss
*/
MINIO("MinIO"),
/**
* 又拍OSS
*/
UP("又拍云USS"),
/**
* SFTP
*/
SFTP("sftp"),
/**
* 腾讯OSS
*/
TENCENT("腾讯云COS"),
/**
* 百度OSS
*/
BAIDU("百度云BOS"),
/**
* 华为OSS
*/
HUAWEI("华为云OBS"),
/**
* 网易 OSS
*/
WANGYI("网易云NOS"),
/**
* 七牛 oss
*/
QINIU("七牛云Kodo");
public String type;
OssName(String type) {
this.type = type;
}
public static OssType getByType(String type) {
for (OssType resultKeyEnum : OssType.values()) {
if (resultKeyEnum.type.equals(type)) {
return resultKeyEnum;
}
}
return null;
}
}

View File

@@ -0,0 +1,56 @@
package com.schisandra.oss.common.enums;
public enum OssType {
/**
* 阿里oss
*/
ALI("ali"),
/**
* Minio oss
*/
MINIO("minio"),
/**
* 又拍OSS
*/
UP("up"),
/**
* SFTP
*/
SFTP("sftp"),
/**
* 腾讯OSS
*/
TENCENT("tencent"),
/**
* 百度OSS
*/
BAIDU("baidu"),
/**
* 华为OSS
*/
HUAWEI("huawei"),
/**
* 网易 OSS
*/
WANGYI("wangyi"),
/**
* 七牛 oss
*/
QINIU("qiniu");
public String type;
OssType(String type) {
this.type = type;
}
public static OssType getByType(String type) {
for (OssType resultKeyEnum : OssType.values()) {
if (resultKeyEnum.type.equals(type)) {
return resultKeyEnum;
}
}
return null;
}
}

View File

@@ -6,6 +6,8 @@ package com.schisandra.oss.domain.convert;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* bo转换器
*
@@ -20,4 +22,5 @@ public interface SchisandraOssAliBOConverter {
SchisandraOssAli convertBOToEntity(SchisandraOssAliBO schisandraOssAliBO);
SchisandraOssAliBO convertEntityToBO(SchisandraOssAli schisandraOssAli);
List<SchisandraOssAliBO> convertEntityToBOList(List<SchisandraOssAli> list);
}

View File

@@ -5,6 +5,8 @@ import com.schisandra.oss.infra.basic.entity.SchisandraOssQiniu;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 七牛云对象存储配置表 bo转换器
*
@@ -18,5 +20,5 @@ public interface SchisandraOssQiniuBOConverter {
SchisandraOssQiniu convertBOToEntity(SchisandraOssQiniuBO schisandraOssQiniuBO);
SchisandraOssQiniuBO convertEntityToBO(SchisandraOssQiniu schisandraOssQiniu);
List<SchisandraOssQiniuBO > convertEntityToBOList(List<SchisandraOssQiniu> schisandraOssQiniu);
}

View File

@@ -5,6 +5,8 @@ import com.schisandra.oss.infra.basic.entity.SchisandraOssSftp;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* sftp存储配置表 bo转换器
*
@@ -18,5 +20,5 @@ public interface SchisandraOssSftpBOConverter {
SchisandraOssSftp convertBOToEntity(SchisandraOssSftpBO schisandraOssSftpBO);
SchisandraOssSftpBO convertEntityToBO(SchisandraOssSftp schisandraOssSftp);
List<SchisandraOssSftpBO> convertEntityToBOList(List<SchisandraOssSftp> schisandraOssSftp);
}

View File

@@ -5,6 +5,8 @@ import com.schisandra.oss.infra.basic.entity.SchisandraOssTencent;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 腾讯云对象存储配置表 bo转换器
*
@@ -19,5 +21,5 @@ public interface SchisandraOssTencentBOConverter {
SchisandraOssTencent convertBOToEntity(SchisandraOssTencentBO schisandraOssTencentBO);
SchisandraOssTencentBO convertEntityToBO(SchisandraOssTencent schisandraOssTencent);
List<SchisandraOssTencentBO> convertEntityToBOList(List<SchisandraOssTencent> schisandraOssTencent);
}

View File

@@ -5,6 +5,8 @@ import com.schisandra.oss.infra.basic.entity.SchisandraOssUp;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 又拍云对象存储配置表 bo转换器
*
@@ -18,5 +20,5 @@ public interface SchisandraOssUpBOConverter {
SchisandraOssUp convertBOToEntity(SchisandraOssUpBO schisandraOssUpBO);
SchisandraOssUpBO convertEntityToBO(SchisandraOssUp schisandraOssUp);
List<SchisandraOssUpBO> convertEntityToBOList(List<SchisandraOssUp> schisandraOssUp);
}

View File

@@ -2,6 +2,7 @@ package com.schisandra.oss.domain.service;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import java.util.List;

View File

@@ -28,4 +28,6 @@ public interface SchisandraUserOssDomainService {
Boolean delete(SchisandraUserOssBO schisandraUserOssBO);
List<SchisandraUserOssBO> queryOSSByUserId(Long userId);
SchisandraUserOssBO queryOSSByTypeAndUserId(Long userId,String type);
}

View File

@@ -2,16 +2,23 @@ package com.schisandra.oss.domain.service.impl;
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
import com.schisandra.oss.common.enums.OssName;
import com.schisandra.oss.common.enums.OssType;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.bo.SchisandraUserOssBO;
import com.schisandra.oss.domain.convert.SchisandraOssAliBOConverter;
import com.schisandra.oss.domain.convert.SchisandraUserOssBOConverter;
import com.schisandra.oss.domain.service.SchisandraOssAliDomainService;
import com.schisandra.oss.infra.basic.entity.SchisandraOssAli;
import com.schisandra.oss.infra.basic.entity.SchisandraUserOss;
import com.schisandra.oss.infra.basic.service.SchisandraOssAliService;
import com.schisandra.oss.infra.basic.service.SchisandraUserOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -26,9 +33,25 @@ public class SchisandraOssAliDomainServiceImpl implements SchisandraOssAliDomain
@Resource
private SchisandraOssAliService schisandraOssAliService;
@Resource
private SchisandraUserOssService schisandraUserOssService;
@Override
public Boolean add(SchisandraOssAliBO schisandraOssAliBO) {
SchisandraUserOss userOss = schisandraUserOssService.queryOSSByTypeAndUserId(schisandraOssAliBO.getUserId(), String.valueOf(OssType.ALI));
if(userOss == null){
SchisandraUserOss schisandraUserOss = new SchisandraUserOss();
schisandraUserOss.setUserId(schisandraOssAliBO.getUserId());
schisandraUserOss.setIsDeleted(0);
schisandraUserOss.setCreatedTime(new Date());
schisandraUserOss.setOssType(String.valueOf(OssType.ALI));
schisandraUserOss.setConfigcount(1);
schisandraUserOss.setName(String.valueOf(OssName.ALI));
schisandraUserOssService.insert(schisandraUserOss);
}else{
userOss.setConfigcount(userOss.getConfigcount()+1);
schisandraUserOssService.update(userOss);
}
SchisandraOssAli schisandraOssAli = SchisandraOssAliBOConverter.INSTANCE.convertBOToEntity(schisandraOssAliBO);
schisandraOssAli.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
return schisandraOssAliService.insert(schisandraOssAli) > 0;
@@ -59,12 +82,6 @@ public class SchisandraOssAliDomainServiceImpl implements SchisandraOssAliDomain
@Override
public List<SchisandraOssAliBO> selectAll() {
List<SchisandraOssAli> list = schisandraOssAliService.selectAll();
List<SchisandraOssAliBO> schisandraOssAliBO_list = new ArrayList<>();
for (SchisandraOssAli schisandraOssAli : list) {
SchisandraOssAliBO schisandraOssAliBO = SchisandraOssAliBOConverter.INSTANCE.convertEntityToBO(schisandraOssAli);
schisandraOssAliBO_list.add(schisandraOssAliBO);
}
return schisandraOssAliBO_list;
return SchisandraOssAliBOConverter.INSTANCE.convertEntityToBOList(list);
}
}

View File

@@ -2,6 +2,8 @@ package com.schisandra.oss.domain.service.impl;
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
import com.schisandra.oss.common.enums.OssName;
import com.schisandra.oss.common.enums.OssType;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
import com.schisandra.oss.domain.convert.SchisandraOssAliBOConverter;
@@ -9,12 +11,15 @@ import com.schisandra.oss.domain.convert.SchisandraOssMinioBOConverter;
import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService;
import com.schisandra.oss.infra.basic.entity.SchisandraOssAli;
import com.schisandra.oss.infra.basic.entity.SchisandraOssMinio;
import com.schisandra.oss.infra.basic.entity.SchisandraUserOss;
import com.schisandra.oss.infra.basic.service.SchisandraOssMinioService;
import com.schisandra.oss.infra.basic.service.SchisandraUserOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -29,9 +34,25 @@ public class SchisandraOssMinioDomainServiceImpl implements SchisandraOssMinioDo
@Resource
private SchisandraOssMinioService schisandraOssMinioService;
@Resource
private SchisandraUserOssService schisandraUserOssService;
@Override
public Boolean add(SchisandraOssMinioBO schisandraOssMinioBO) {
SchisandraUserOss userOss = schisandraUserOssService.queryOSSByTypeAndUserId(schisandraOssMinioBO.getUserId(),String.valueOf(OssType.MINIO));
if(userOss == null){
SchisandraUserOss schisandraUserOss = new SchisandraUserOss();
schisandraUserOss.setUserId(schisandraOssMinioBO.getUserId());
schisandraUserOss.setIsDeleted(0);
schisandraUserOss.setCreatedTime(new Date());
schisandraUserOss.setOssType(String.valueOf(OssType.MINIO));
schisandraUserOss.setName(String.valueOf(OssName.MINIO));
schisandraUserOss.setConfigcount(1);
schisandraUserOssService.insert(schisandraUserOss);
}else{
userOss.setConfigcount(userOss.getConfigcount()+1);
schisandraUserOssService.update(userOss);
}
SchisandraOssMinio schisandraOssMinio = SchisandraOssMinioBOConverter.INSTANCE.convertBOToEntity(schisandraOssMinioBO);
schisandraOssMinio.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
return schisandraOssMinioService.insert(schisandraOssMinio) > 0;
@@ -68,12 +89,7 @@ public class SchisandraOssMinioDomainServiceImpl implements SchisandraOssMinioDo
@Override
public List<SchisandraOssMinioBO> selectAll(){
List<SchisandraOssMinio> list = schisandraOssMinioService.selectAll();
List<SchisandraOssMinioBO> schisandraOssMinioBO_list = new ArrayList<>();
for (SchisandraOssMinio schisandraOssMinio : list) {
SchisandraOssMinioBO schisandraOssMinioBO = SchisandraOssMinioBOConverter.INSTANCE.convertEntityToBO(schisandraOssMinio);
schisandraOssMinioBO_list.add(schisandraOssMinioBO);
}
return schisandraOssMinioBO_list;
return SchisandraOssMinioBOConverter.INSTANCE.convertEntityToBOList(list);
}
}

View File

@@ -1,6 +1,8 @@
package com.schisandra.oss.domain.service.impl;
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
import com.schisandra.oss.common.enums.OssName;
import com.schisandra.oss.common.enums.OssType;
import com.schisandra.oss.domain.bo.SchisandraOssJdBO;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
import com.schisandra.oss.domain.convert.SchisandraOssJdBOConverter;
@@ -11,12 +13,15 @@ import com.schisandra.oss.domain.service.SchisandraOssQiniuDomainService;
import com.schisandra.oss.infra.basic.entity.SchisandraOssJd;
import com.schisandra.oss.infra.basic.entity.SchisandraOssQiniu;
import com.schisandra.oss.infra.basic.entity.SchisandraOssUp;
import com.schisandra.oss.infra.basic.entity.SchisandraUserOss;
import com.schisandra.oss.infra.basic.service.SchisandraOssQiniuService;
import com.schisandra.oss.infra.basic.service.SchisandraUserOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -31,9 +36,26 @@ public class SchisandraOssQiniuDomainServiceImpl implements SchisandraOssQiniuDo
@Resource
private SchisandraOssQiniuService schisandraOssQiniuService;
@Resource
private SchisandraUserOssService schisandraUserOssService;
@Override
public Boolean add(SchisandraOssQiniuBO schisandraOssQiniuBO) {
SchisandraUserOss userOss = schisandraUserOssService.queryOSSByTypeAndUserId(schisandraOssQiniuBO.getUserId(), String.valueOf(OssType.QINIU));
if(userOss == null){
SchisandraUserOss schisandraUserOss = new SchisandraUserOss();
schisandraUserOss.setUserId(schisandraOssQiniuBO.getUserId());
schisandraUserOss.setIsDeleted(0);
schisandraUserOss.setCreatedTime(new Date());
schisandraUserOss.setOssType(String.valueOf(OssType.QINIU));
schisandraUserOss.setName(String.valueOf(OssName.QINIU));
schisandraUserOss.setConfigcount(1);
schisandraUserOssService.insert(schisandraUserOss);
}else{
userOss.setConfigcount(userOss.getConfigcount()+1);
schisandraUserOssService.update(userOss);
}
SchisandraOssQiniu schisandraOssQiniu = SchisandraOssQiniuBOConverter.INSTANCE.convertBOToEntity(schisandraOssQiniuBO);
schisandraOssQiniu.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
return schisandraOssQiniuService.insert(schisandraOssQiniu) > 0;
@@ -63,11 +85,6 @@ public class SchisandraOssQiniuDomainServiceImpl implements SchisandraOssQiniuDo
@Override
public List<SchisandraOssQiniuBO> selectAll(){
List<SchisandraOssQiniu> list = schisandraOssQiniuService.selectAll();
List<SchisandraOssQiniuBO> SchisandraOssQiniuBO_list = new ArrayList<>();
for (SchisandraOssQiniu schisandraOssQiniu : list) {
SchisandraOssQiniuBO schisandraOssQiniuBO = SchisandraOssQiniuBOConverter.INSTANCE.convertEntityToBO(schisandraOssQiniu);
SchisandraOssQiniuBO_list.add(schisandraOssQiniuBO);
}
return SchisandraOssQiniuBO_list;
return SchisandraOssQiniuBOConverter.INSTANCE.convertEntityToBOList(list);
}
}

View File

@@ -1,6 +1,8 @@
package com.schisandra.oss.domain.service.impl;
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
import com.schisandra.oss.common.enums.OssName;
import com.schisandra.oss.common.enums.OssType;
import com.schisandra.oss.domain.bo.SchisandraOssFtpBO;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
import com.schisandra.oss.domain.convert.SchisandraOssFtpBOConverter;
@@ -11,12 +13,15 @@ import com.schisandra.oss.domain.service.SchisandraOssSftpDomainService;
import com.schisandra.oss.infra.basic.entity.SchisandraOssFtp;
import com.schisandra.oss.infra.basic.entity.SchisandraOssSftp;
import com.schisandra.oss.infra.basic.entity.SchisandraOssUp;
import com.schisandra.oss.infra.basic.entity.SchisandraUserOss;
import com.schisandra.oss.infra.basic.service.SchisandraOssSftpService;
import com.schisandra.oss.infra.basic.service.SchisandraUserOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -31,9 +36,24 @@ public class SchisandraOssSftpDomainServiceImpl implements SchisandraOssSftpDoma
@Resource
private SchisandraOssSftpService schisandraOssSftpService;
@Resource
private SchisandraUserOssService schisandraUserOssService;
@Override
public Boolean add(SchisandraOssSftpBO schisandraOssSftpBO) {
SchisandraUserOss userOss = schisandraUserOssService.queryOSSByTypeAndUserId(schisandraOssSftpBO.getUserId(), String.valueOf(OssType.SFTP));
if(userOss == null){
SchisandraUserOss schisandraUserOss = new SchisandraUserOss();
schisandraUserOss.setUserId(schisandraOssSftpBO.getUserId());
schisandraUserOss.setIsDeleted(0);
schisandraUserOss.setCreatedTime(new Date());
schisandraUserOss.setOssType(String.valueOf(OssType.SFTP));
schisandraUserOss.setName(String.valueOf(OssName.SFTP));
schisandraUserOss.setConfigcount(1);
schisandraUserOssService.insert(schisandraUserOss);
}else{
userOss.setConfigcount(userOss.getConfigcount()+1);
schisandraUserOssService.update(userOss);
}
SchisandraOssSftp schisandraOssSftp = SchisandraOssSftpBOConverter.INSTANCE.convertBOToEntity(schisandraOssSftpBO);
schisandraOssSftp.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
return schisandraOssSftpService.insert(schisandraOssSftp) > 0;
@@ -63,11 +83,6 @@ public class SchisandraOssSftpDomainServiceImpl implements SchisandraOssSftpDoma
@Override
public List<SchisandraOssSftpBO> selectAll(){
List<SchisandraOssSftp> list = schisandraOssSftpService.selectAll();
List<SchisandraOssSftpBO> SchisandraOssSftpBO_list = new ArrayList<>();
for (SchisandraOssSftp schisandraOssSftp : list) {
SchisandraOssSftpBO schisandraOssSftpBO = SchisandraOssSftpBOConverter.INSTANCE.convertEntityToBO(schisandraOssSftp);
SchisandraOssSftpBO_list.add(schisandraOssSftpBO);
}
return SchisandraOssSftpBO_list;
return SchisandraOssSftpBOConverter.INSTANCE.convertEntityToBOList(list);
}
}

View File

@@ -1,6 +1,8 @@
package com.schisandra.oss.domain.service.impl;
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
import com.schisandra.oss.common.enums.OssName;
import com.schisandra.oss.common.enums.OssType;
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
import com.schisandra.oss.domain.convert.SchisandraOssQiniuBOConverter;
@@ -11,12 +13,15 @@ import com.schisandra.oss.domain.service.SchisandraOssTencentDomainService;
import com.schisandra.oss.infra.basic.entity.SchisandraOssQiniu;
import com.schisandra.oss.infra.basic.entity.SchisandraOssTencent;
import com.schisandra.oss.infra.basic.entity.SchisandraOssUp;
import com.schisandra.oss.infra.basic.entity.SchisandraUserOss;
import com.schisandra.oss.infra.basic.service.SchisandraOssTencentService;
import com.schisandra.oss.infra.basic.service.SchisandraUserOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -31,9 +36,25 @@ public class SchisandraOssTencentDomainServiceImpl implements SchisandraOssTence
@Resource
private SchisandraOssTencentService schisandraOssTencentService;
@Resource
private SchisandraUserOssService schisandraUserOssService;
@Override
public Boolean add(SchisandraOssTencentBO schisandraOssTencentBO) {
SchisandraUserOss userOss = schisandraUserOssService.queryOSSByTypeAndUserId(schisandraOssTencentBO.getUserId(),String.valueOf(OssType.TENCENT));
if(userOss == null){
SchisandraUserOss schisandraUserOss = new SchisandraUserOss();
schisandraUserOss.setUserId(schisandraOssTencentBO.getUserId());
schisandraUserOss.setIsDeleted(0);
schisandraUserOss.setCreatedTime(new Date());
schisandraUserOss.setOssType(String.valueOf(OssType.TENCENT));
schisandraUserOss.setConfigcount(1);
schisandraUserOss.setName(String.valueOf(OssName.TENCENT));
schisandraUserOssService.insert(schisandraUserOss);
}else{
userOss.setConfigcount(userOss.getConfigcount()+1);
schisandraUserOssService.update(userOss);
}
SchisandraOssTencent schisandraOssTencent = SchisandraOssTencentBOConverter.INSTANCE.convertBOToEntity(schisandraOssTencentBO);
schisandraOssTencent.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
return schisandraOssTencentService.insert(schisandraOssTencent) > 0;
@@ -63,11 +84,6 @@ public class SchisandraOssTencentDomainServiceImpl implements SchisandraOssTence
@Override
public List<SchisandraOssTencentBO> selectAll(){
List<SchisandraOssTencent> list = schisandraOssTencentService.selectAll();
List<SchisandraOssTencentBO> SchisandraOssTencentBO_list = new ArrayList<>();
for (SchisandraOssTencent schisandraOssTencent : list) {
SchisandraOssTencentBO schisandraOssUpBO = SchisandraOssTencentBOConverter.INSTANCE.convertEntityToBO(schisandraOssTencent);
SchisandraOssTencentBO_list.add(schisandraOssUpBO);
}
return SchisandraOssTencentBO_list;
return SchisandraOssTencentBOConverter.INSTANCE.convertEntityToBOList(list);
}
}

View File

@@ -8,12 +8,15 @@ import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
import com.schisandra.oss.domain.service.SchisandraOssUpDomainService;
import com.schisandra.oss.infra.basic.entity.SchisandraOssMinio;
import com.schisandra.oss.infra.basic.entity.SchisandraOssUp;
import com.schisandra.oss.infra.basic.entity.SchisandraUserOss;
import com.schisandra.oss.infra.basic.service.SchisandraOssUpService;
import com.schisandra.oss.infra.basic.service.SchisandraUserOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -28,9 +31,24 @@ public class SchisandraOssUpDomainServiceImpl implements SchisandraOssUpDomainSe
@Resource
private SchisandraOssUpService schisandraOssUpService;
@Resource
private SchisandraUserOssService schisandraUserOssService;
@Override
public Boolean add(SchisandraOssUpBO schisandraOssUpBO) {
SchisandraUserOss schisandraUserOss = schisandraUserOssService.queryOSSByTypeAndUserId(schisandraOssUpBO.getUserId(),"up");
if(schisandraUserOss == null){
SchisandraUserOss x = new SchisandraUserOss();
x.setUserId(schisandraOssUpBO.getUserId());
x.setIsDeleted(0);
x.setCreatedTime(new Date());
x.setOssType("up");
x.setConfigcount(1);
schisandraUserOssService.insert(x);
}else{
schisandraUserOss.setConfigcount(schisandraUserOss.getConfigcount()+1);
schisandraUserOssService.update(schisandraUserOss);
}
SchisandraOssUp schisandraOssUp = SchisandraOssUpBOConverter.INSTANCE.convertBOToEntity(schisandraOssUpBO);
schisandraOssUp.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
return schisandraOssUpService.insert(schisandraOssUp) > 0;
@@ -59,12 +77,7 @@ public class SchisandraOssUpDomainServiceImpl implements SchisandraOssUpDomainSe
@Override
public List<SchisandraOssUpBO> selectAll(){
List<SchisandraOssUp> list = schisandraOssUpService.selectAll();
List<SchisandraOssUpBO> SchisandraOssUpBO_list = new ArrayList<>();
for (SchisandraOssUp schisandraOssUp : list) {
SchisandraOssUpBO schisandraOssUpBO = SchisandraOssUpBOConverter.INSTANCE.convertEntityToBO(schisandraOssUp);
SchisandraOssUpBO_list.add(schisandraOssUpBO);
}
return SchisandraOssUpBO_list;
return SchisandraOssUpBOConverter.INSTANCE.convertEntityToBOList(list);
}
}

View File

@@ -54,4 +54,11 @@ public class SchisandraUserOssDomainServiceImpl implements SchisandraUserOssDoma
return SchisandraUserOssBOList;
}
@Override
public SchisandraUserOssBO queryOSSByTypeAndUserId(Long userId,String type ) {
SchisandraUserOssBO schisandraUserOssBO = SchisandraUserOssBOConverter
.INSTANCE.convertEntityToBO(schisandraUserOssService.queryOSSByTypeAndUserId(userId, type));
return schisandraUserOssBO;
}
}

View File

@@ -49,6 +49,9 @@ public class SchisandraUserOss implements Serializable {
@Column("name")
private String name;
@Column("config_count")
private Integer configcount;
/**
*
*/

View File

@@ -3,6 +3,7 @@ package com.schisandra.oss.infra.basic.service;
import com.schisandra.oss.infra.basic.entity.SchisandraUserOss;
import java.util.List;
import java.util.function.Predicate;
/**
* 用户对象存储映射表 表服务接口
@@ -46,5 +47,5 @@ public interface SchisandraUserOssService {
List<SchisandraUserOss> queryOSSByUserId(Long userId);
SchisandraUserOss queryOSSByTypeAndUserId(Long userId,String Type);
}

View File

@@ -71,5 +71,8 @@ public class SchisandraUserOssServiceImpl implements SchisandraUserOssService {
return this.schisandraUserOssDao.selectListByCondition(SchisandraUserOssTableDef.SCHISANDRA_USER_OSS.USER_ID.eq(userId));
}
@Override
public SchisandraUserOss queryOSSByTypeAndUserId(Long userId,String type) {
return this.schisandraUserOssDao.selectOneByCondition(SchisandraUserOssTableDef.SCHISANDRA_USER_OSS.USER_ID.eq(userId).and(SchisandraUserOssTableDef.SCHISANDRA_USER_OSS.OSS_TYPE.eq(type)));
}
}