feat: update

This commit is contained in:
landaiqing
2024-07-23 10:31:01 +08:00
parent fb173be47f
commit 33dbf82b81
2 changed files with 47 additions and 52 deletions

View File

@@ -149,18 +149,18 @@ public class SchisandraAuthUserController {
schisandraAuthAddressBO.setAgent(userAgent.toString()); schisandraAuthAddressBO.setAgent(userAgent.toString());
schisandraAuthAddressBO.setUserId(result.getId()); schisandraAuthAddressBO.setUserId(result.getId());
schisandraAuthAddressBO.setIp(ip); schisandraAuthAddressBO.setIp(ip);
if(userAgent.getBrowser() != null) { if (userAgent.getBrowser() != null) {
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString()); schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
} }
if(userAgent.getBrowserVersion() != null){ if (userAgent.getBrowserVersion() != null) {
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().toString()); schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().toString());
} }
schisandraAuthAddressBO.setLocation(ip2region); schisandraAuthAddressBO.setLocation(ip2region);
SchisandraAuthAddressBO authAddressBO = schisandraAuthAddressDomainService.queryByUserId(result.getId()); SchisandraAuthAddressBO authAddressBO = schisandraAuthAddressDomainService.queryByUserId(result.getId());
if(ObjectUtils.isNotEmpty(authAddressBO)){ if (ObjectUtils.isNotEmpty(authAddressBO)) {
schisandraAuthAddressBO.setId(authAddressBO.getId()); schisandraAuthAddressBO.setId(authAddressBO.getId());
schisandraAuthAddressDomainService.update(schisandraAuthAddressBO); schisandraAuthAddressDomainService.update(schisandraAuthAddressBO);
}else{ } else {
Boolean add = schisandraAuthAddressDomainService.add(schisandraAuthAddressBO); Boolean add = schisandraAuthAddressDomainService.add(schisandraAuthAddressBO);
assert add; assert add;
} }
@@ -221,18 +221,18 @@ public class SchisandraAuthUserController {
schisandraAuthAddressBO.setAgent(userAgent.toString()); schisandraAuthAddressBO.setAgent(userAgent.toString());
schisandraAuthAddressBO.setUserId(result.getId()); schisandraAuthAddressBO.setUserId(result.getId());
schisandraAuthAddressBO.setIp(ip); schisandraAuthAddressBO.setIp(ip);
if(userAgent.getBrowser() != null) { if (userAgent.getBrowser() != null) {
schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString()); schisandraAuthAddressBO.setBrowser(userAgent.getBrowser().toString());
} }
if(userAgent.getBrowserVersion() != null){ if (userAgent.getBrowserVersion() != null) {
schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().toString()); schisandraAuthAddressBO.setBrowserVersion(userAgent.getBrowserVersion().toString());
} }
schisandraAuthAddressBO.setLocation(ip2region); schisandraAuthAddressBO.setLocation(ip2region);
SchisandraAuthAddressBO authAddressBO = schisandraAuthAddressDomainService.queryByUserId(result.getId()); SchisandraAuthAddressBO authAddressBO = schisandraAuthAddressDomainService.queryByUserId(result.getId());
if(ObjectUtils.isNotEmpty(authAddressBO)){ if (ObjectUtils.isNotEmpty(authAddressBO)) {
schisandraAuthAddressBO.setId(authAddressBO.getId()); schisandraAuthAddressBO.setId(authAddressBO.getId());
schisandraAuthAddressDomainService.update(schisandraAuthAddressBO); schisandraAuthAddressDomainService.update(schisandraAuthAddressBO);
}else{ } else {
Boolean add = schisandraAuthAddressDomainService.add(schisandraAuthAddressBO); Boolean add = schisandraAuthAddressDomainService.add(schisandraAuthAddressBO);
assert add; assert add;
} }
@@ -439,14 +439,20 @@ public class SchisandraAuthUserController {
/** /**
* 用户设置安全信息 * 用户设置安全信息
*
* @param schisandraAuthUserDTO * @param schisandraAuthUserDTO
* @return * @return
*/ */
@PostMapping("update") @PostMapping("update")
public Result update(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO){ public Result update(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {
SchisandraAuthUserBO schisandraAuthUserBO = SchisandraAuthUserDTOConverter.INSTANCE.convertDTOToBO(schisandraAuthUserDTO); SchisandraAuthUserBO schisandraAuthUserBO = SchisandraAuthUserDTOConverter.INSTANCE.convertDTOToBO(schisandraAuthUserDTO);
return Result.ok(schisandraAuthUserDomainService.update(schisandraAuthUserBO)); return Result.ok(schisandraAuthUserDomainService.update(schisandraAuthUserBO));
} }
@PostMapping("logout")
public Result logout(@RequestParam("userId") String userId) {
StpUtil.logout(userId);
return Result.ok();
}
} }

View File

@@ -3,30 +3,20 @@ package com.schisandra.oss.application.controller;
import cn.hutool.core.util.ZipUtil; import cn.hutool.core.util.ZipUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import com.mybatisflex.annotation.RelationOneToMany;
import com.schisandra.oss.application.convert.SchisandraOssMinioDTOConverter; 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.dto.SchisandraOssMinioDTO;
import com.schisandra.oss.application.dto.SchisandraOssQiniuDTO;
import com.schisandra.oss.application.oss.constant.OssConstant; 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.MinioOssClient;
import com.schisandra.oss.application.oss.core.minio.MinioOssConfiguration; import com.schisandra.oss.application.oss.core.minio.MinioOssConfiguration;
import com.schisandra.oss.application.oss.model.OssInfo; import com.schisandra.oss.application.oss.model.OssInfo;
import com.schisandra.oss.common.entity.Result; import com.schisandra.oss.common.entity.Result;
import com.schisandra.oss.common.utils.CaffeineUtil; import com.schisandra.oss.common.utils.CaffeineUtil;
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO; import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
import com.schisandra.oss.domain.redis.RedisUtil; import com.schisandra.oss.domain.redis.RedisUtil;
import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService; import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService;
import io.minio.errors.*; import io.minio.errors.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -42,7 +32,6 @@ import java.net.URLEncoder;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -81,23 +70,23 @@ public class SchisandraOssMinioController {
public Result returnOneById(String Id) { public Result returnOneById(String Id) {
SchisandraOssMinioBO bo = schisandraOssMinioDomainService.selectOneById(Id); SchisandraOssMinioBO bo = schisandraOssMinioDomainService.selectOneById(Id);
SchisandraOssMinioDTO dto = SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTO(bo); SchisandraOssMinioDTO dto = SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTO(bo);
if(dto == null){ if (dto == null) {
return Result.fail("查询失败"); return Result.fail("查询失败");
} }
return Result.ok(dto); return Result.ok(dto);
} }
/** /**
* 返回当前用户minio表所有数据 * 返回当前用户minio表所有数据
*
* @param userId * @param userId
* @return * @return
*/ */
@GetMapping("return_online") @GetMapping("return_online")
public Result returnOnline(String userId) { public Result returnOnline(String userId) {
List<SchisandraOssMinioBO> list = schisandraOssMinioDomainService.selectAllPresent(userId); List<SchisandraOssMinioBO> list = schisandraOssMinioDomainService.selectAllPresent(userId);
if(list.isEmpty()){ if (list.isEmpty()) {
return Result.fail(); return Result.fail();
} }
return Result.ok(SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTOList(list)); return Result.ok(SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTOList(list));
@@ -178,12 +167,12 @@ public class SchisandraOssMinioController {
Preconditions.checkNotNull(userId, "不能为空"); Preconditions.checkNotNull(userId, "不能为空");
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket); bean.getMinioOssConfig().setBucketName(bucket);
List<OssInfo> object= (List<OssInfo>) caffeineUtil.caffeineBuild().getIfPresent(userId+bucket+dirName); List<OssInfo> object = (List<OssInfo>) caffeineUtil.caffeineBuild().getIfPresent(userId + bucket + dirName);
if (object != null) { if (object != null) {
return Result.ok(object); return Result.ok(object);
}else { } else {
List<OssInfo> list=bean.listDir(bucket,dirName); List<OssInfo> list = bean.listDir(bucket, dirName);
caffeineUtil.caffeineBuild().put(userId+bucket+dirName, list); caffeineUtil.caffeineBuild().put(userId + bucket + dirName, list);
return Result.ok(list); return Result.ok(list);
} }
@@ -245,7 +234,7 @@ public class SchisandraOssMinioController {
Preconditions.checkNotNull(bucket, "不能为空"); Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(userId, "不能为空"); Preconditions.checkNotNull(userId, "不能为空");
Preconditions.checkNotNull(filePath, "不能为空"); Preconditions.checkNotNull(filePath, "不能为空");
int index=filePath.lastIndexOf("/"); int index = filePath.lastIndexOf("/");
String fileName = filePath.substring(index + 1); String fileName = filePath.substring(index + 1);
caffeineUtil.caffeineBuild().invalidate("MinioListDir" + userId + bucket + fileName); caffeineUtil.caffeineBuild().invalidate("MinioListDir" + userId + bucket + fileName);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
@@ -262,17 +251,17 @@ public class SchisandraOssMinioController {
* @date: 2024/6/26 14:34 * @date: 2024/6/26 14:34
*/ */
@PostMapping(value = "uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public Result<Object> uploadMinioFile(SchisandraOssMinioDTO schisandraOssMinioDTO,@RequestParam MultipartFile file) throws IOException { public Result<Object> uploadMinioFile(SchisandraOssMinioDTO schisandraOssMinioDTO, @RequestParam MultipartFile file) throws IOException {
String path=schisandraOssMinioDTO.getPath(); String path = schisandraOssMinioDTO.getPath();
String bucket=schisandraOssMinioDTO.getBucketName(); String bucket = schisandraOssMinioDTO.getBucketName();
String userId=schisandraOssMinioDTO.getUserId(); String userId = schisandraOssMinioDTO.getUserId();
Preconditions.checkNotNull(path, "path不能为空"); Preconditions.checkNotNull(path, "path不能为空");
Preconditions.checkNotNull(bucket, "bucket不能为空"); Preconditions.checkNotNull(bucket, "bucket不能为空");
Preconditions.checkNotNull(userId, "userId不能为空"); Preconditions.checkNotNull(userId, "userId不能为空");
if (path.lastIndexOf("") == path.length() - 1) { if (path.lastIndexOf("") == path.length() - 1) {
path=path+file.getName(); path = path + file.getName();
}else{ } else {
path=path+"/"+file.getOriginalFilename(); path = path + "/" + file.getOriginalFilename();
} }
// 获取文件输入流 // 获取文件输入流
InputStream is = file.getInputStream(); InputStream is = file.getInputStream();
@@ -290,7 +279,7 @@ public class SchisandraOssMinioController {
map.put("time", formattedDate); map.put("time", formattedDate);
if (bean.upLoad(is, path, true) != null) { if (bean.upLoad(is, path, true) != null) {
redisUtil.setNx(key, map, 30L, TimeUnit.DAYS); redisUtil.setNx(key, map, 30L, TimeUnit.DAYS);
caffeineUtil.caffeineBuild().invalidate("MinioListDir"+userId+bucket+schisandraOssMinioDTO.getPath()); caffeineUtil.caffeineBuild().invalidate("MinioListDir" + userId + bucket + schisandraOssMinioDTO.getPath());
return Result.ok(); return Result.ok();
} else { } else {
return Result.fail(); return Result.fail();
@@ -312,7 +301,7 @@ public class SchisandraOssMinioController {
Preconditions.checkNotNull(bucket, "不能为空"); Preconditions.checkNotNull(bucket, "不能为空");
Preconditions.checkNotNull(oldFileName, "不能为空"); Preconditions.checkNotNull(oldFileName, "不能为空");
Preconditions.checkNotNull(newFileName, "不能为空"); Preconditions.checkNotNull(newFileName, "不能为空");
String path=oldFileName.substring(0,oldFileName.lastIndexOf("/")+1); String path = oldFileName.substring(0, oldFileName.lastIndexOf("/") + 1);
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket); bean.getMinioOssConfig().setBucketName(bucket);
try { try {
@@ -320,7 +309,7 @@ public class SchisandraOssMinioController {
} catch (Exception e) { } catch (Exception e) {
return Result.fail(e.getMessage()); return Result.fail(e.getMessage());
} }
caffeineUtil.caffeineBuild().invalidate("MinioListDir"+userId+bucket+path); caffeineUtil.caffeineBuild().invalidate("MinioListDir" + userId + bucket + path);
return Result.ok(); return Result.ok();
} }
@@ -340,14 +329,14 @@ public class SchisandraOssMinioController {
Preconditions.checkNotNull(oldFilePath, "不能为空"); Preconditions.checkNotNull(oldFilePath, "不能为空");
Preconditions.checkNotNull(newFilePath, "不能为空"); Preconditions.checkNotNull(newFilePath, "不能为空");
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
String path=oldFilePath.substring(0,oldFilePath.lastIndexOf("/")+1); String path = oldFilePath.substring(0, oldFilePath.lastIndexOf("/") + 1);
bean.getMinioOssConfig().setBucketName(bucket); bean.getMinioOssConfig().setBucketName(bucket);
try { try {
bean.copy(oldFilePath, newFilePath); bean.copy(oldFilePath, newFilePath);
} catch (Exception e) { } catch (Exception e) {
return Result.fail(e.getMessage()); return Result.fail(e.getMessage());
} }
caffeineUtil.caffeineBuild().invalidate("MinioListDir"+userId+bucket+path); caffeineUtil.caffeineBuild().invalidate("MinioListDir" + userId + bucket + path);
return Result.ok(); return Result.ok();
} }
@@ -415,28 +404,28 @@ public class SchisandraOssMinioController {
public Result<String> seleteBucket(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException { public Result<String> seleteBucket(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
Preconditions.checkNotNull(userId, "不能为空"); Preconditions.checkNotNull(userId, "不能为空");
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
List<HashMap<String,String>>list= (List<HashMap<String, String>>) caffeineUtil.caffeineBuild().getIfPresent("MinioBucket"+userId); List<HashMap<String, String>> list = (List<HashMap<String, String>>) caffeineUtil.caffeineBuild().getIfPresent("MinioBucket" + userId);
if (list!=null){ if (list != null) {
return Result.ok(list); return Result.ok(list);
} }
list=bean.selectAllBucket(); list = bean.selectAllBucket();
if (list==null){ if (list == null) {
return Result.fail(); return Result.fail();
} }
caffeineUtil.caffeineBuild().put("MinioBucket",list); caffeineUtil.caffeineBuild().put("MinioBucket", list);
return Result.ok(list); return Result.ok(list);
} }
@PostMapping("getBucketSize") @PostMapping("getBucketSize")
public Result<String> getBucketSize(@RequestParam String userId, @RequestParam String bucket) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException { public Result<String> getBucketSize(@RequestParam String userId, @RequestParam String bucket) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
Preconditions.checkNotNull(userId, "不能为空"); Preconditions.checkNotNull(userId, "不能为空");
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
String size= (String) caffeineUtil.caffeineBuild().getIfPresent("MinioBucket"+userId+bucket); String size = (String) caffeineUtil.caffeineBuild().getIfPresent("MinioBucket" + userId + bucket);
if (size!=null){ if (size != null) {
return Result.ok(size); return Result.ok(size);
} }
size=bean.getMinioBucketSize(bucket); size = bean.getMinioBucketSize(bucket);
caffeineUtil.caffeineBuild().put("MinioBucket"+userId+bucket,size); caffeineUtil.caffeineBuild().put("MinioBucket" + userId + bucket, size);
return Result.ok(size); return Result.ok(size);
} }
@@ -453,7 +442,7 @@ public class SchisandraOssMinioController {
Preconditions.checkNotNull(bucket, "不能为空"); Preconditions.checkNotNull(bucket, "不能为空");
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket); bean.getMinioOssConfig().setBucketName(bucket);
caffeineUtil.caffeineBuild().invalidate("MinioBucket"+userId); caffeineUtil.caffeineBuild().invalidate("MinioBucket" + userId);
return Result.ok(bean.createBucket(bucket)); return Result.ok(bean.createBucket(bucket));
} }
@@ -471,7 +460,7 @@ public class SchisandraOssMinioController {
Preconditions.checkNotNull(bucket, "不能为空"); Preconditions.checkNotNull(bucket, "不能为空");
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
bean.getMinioOssConfig().setBucketName(bucket); bean.getMinioOssConfig().setBucketName(bucket);
caffeineUtil.caffeineBuild().invalidate("MinioBucket"+userId); caffeineUtil.caffeineBuild().invalidate("MinioBucket" + userId);
return Result.ok(bean.deleteBucket(bucket)); return Result.ok(bean.deleteBucket(bucket));
} }