1.更改minio获取预签名工具方法 2.简化日志
This commit is contained in:
@@ -61,7 +61,7 @@ public class LoggingAspect {
|
|||||||
/**
|
/**
|
||||||
* Controller方法执行后记录日志
|
* Controller方法执行后记录日志
|
||||||
*/
|
*/
|
||||||
@AfterReturning(pointcut = "controllerMethods()", returning = "result")
|
// @AfterReturning(pointcut = "controllerMethods()", returning = "result")
|
||||||
public void logControllerAfterReturning(JoinPoint joinPoint, Object result) {
|
public void logControllerAfterReturning(JoinPoint joinPoint, Object result) {
|
||||||
logger.info("方法执行成功: {}.{}", joinPoint.getSignature().getDeclaringType().getSimpleName(), joinPoint.getSignature().getName());
|
logger.info("方法执行成功: {}.{}", joinPoint.getSignature().getDeclaringType().getSimpleName(), joinPoint.getSignature().getName());
|
||||||
logger.info("返回结果: {}", result);
|
logger.info("返回结果: {}", result);
|
||||||
@@ -81,7 +81,7 @@ public class LoggingAspect {
|
|||||||
/**
|
/**
|
||||||
* Service方法环绕通知,记录执行时间
|
* Service方法环绕通知,记录执行时间
|
||||||
*/
|
*/
|
||||||
@Around("serviceMethods()")
|
// @Around("serviceMethods()")
|
||||||
public Object logServiceAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
public Object logServiceAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
// String methodName = joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName();
|
// String methodName = joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName();
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.aida.lanecarford.common.constant.CommonConstants.MINIO_PATH_TIMEOUT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 进店记录服务实现类
|
* 进店记录服务实现类
|
||||||
*/
|
*/
|
||||||
@@ -77,7 +79,8 @@ public class VisitRecordServiceImpl extends ServiceImpl<VisitRecordMapper, Visit
|
|||||||
if (favoriteEffect != null && favoriteEffect.getResultImageUrl() != null) {
|
if (favoriteEffect != null && favoriteEffect.getResultImageUrl() != null) {
|
||||||
libraryVo.setDefaultImageUrl(minioUtil.convertToPresignedUrl(
|
libraryVo.setDefaultImageUrl(minioUtil.convertToPresignedUrl(
|
||||||
favoriteEffect.getResultImageUrl(),
|
favoriteEffect.getResultImageUrl(),
|
||||||
CommonConstant.MINIO_IMAGE_EXPIRE_TIME
|
// CommonConstant.MINIO_IMAGE_EXPIRE_TIME
|
||||||
|
MINIO_PATH_TIMEOUT
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
//如果仅进店未进行任何喜欢收藏结果,不做展示
|
//如果仅进店未进行任何喜欢收藏结果,不做展示
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ public class MinioUtil {
|
|||||||
* @param bucketName 桶名
|
* @param bucketName 桶名
|
||||||
* @return 预签名URL
|
* @return 预签名URL
|
||||||
*/
|
*/
|
||||||
public String getPresignedUrl(String objectName, int expires, String bucketName) {
|
/*public String getPresignedUrl(String objectName, int expires, String bucketName) {
|
||||||
try {
|
try {
|
||||||
return minioClient.getPresignedObjectUrl(
|
return minioClient.getPresignedObjectUrl(
|
||||||
GetPresignedObjectUrlArgs.builder()
|
GetPresignedObjectUrlArgs.builder()
|
||||||
@@ -360,6 +360,51 @@ public class MinioUtil {
|
|||||||
log.error("获取预签名URL失败: {}", e.getMessage(), e);
|
log.error("获取预签名URL失败: {}", e.getMessage(), e);
|
||||||
throw new MinioException("获取预签名URL失败", e);
|
throw new MinioException("获取预签名URL失败", e);
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
public String getPresignedUrl(String objectName, int expires, String bucketName) {
|
||||||
|
try {
|
||||||
|
log.info("生成预签名URL - 桶名: {}, 对象名: {}, 过期时间: {}秒", bucketName, objectName, expires);
|
||||||
|
|
||||||
|
// 检查桶是否存在
|
||||||
|
boolean bucketExists = minioClient.bucketExists(BucketExistsArgs.builder()
|
||||||
|
.bucket(bucketName)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
if (!bucketExists) {
|
||||||
|
log.error("桶不存在: {}", bucketName);
|
||||||
|
throw new MinioException("存储桶不存在: " + bucketName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查对象是否存在
|
||||||
|
try {
|
||||||
|
minioClient.statObject(StatObjectArgs.builder()
|
||||||
|
.bucket(bucketName)
|
||||||
|
.object(objectName)
|
||||||
|
.build());
|
||||||
|
log.info("对象存在: {}/{}", bucketName, objectName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("对象不存在: {}/{}, 错误: {}", bucketName, objectName, e.getMessage());
|
||||||
|
throw new MinioException("文件不存在: " + objectName, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
String presignedUrl = minioClient.getPresignedObjectUrl(
|
||||||
|
GetPresignedObjectUrlArgs.builder()
|
||||||
|
.method(Method.GET)
|
||||||
|
.bucket(bucketName)
|
||||||
|
.object(objectName)
|
||||||
|
.expiry(expires, TimeUnit.SECONDS)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info("预签名URL生成成功: {}", presignedUrl);
|
||||||
|
return presignedUrl;
|
||||||
|
|
||||||
|
} catch (MinioException e) {
|
||||||
|
throw e; // 重新抛出我们自定义的异常
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取预签名URL失败 - 桶: {}, 对象: {}, 错误: {}", bucketName, objectName, e.getMessage(), e);
|
||||||
|
throw new MinioException("获取预签名URL失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user