fix: AOP日志记录bug
This commit is contained in:
parent
615f6323c5
commit
6cb6961b38
|
@ -17,6 +17,8 @@ import org.springframework.stereotype.Component;
|
|||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
|
@ -30,6 +32,18 @@ public class UserRequestLogAop {
|
|||
@Autowired
|
||||
private UserRequestLogRepository userRequestLogRepository;
|
||||
|
||||
private boolean isSerializable(Object obj) {
|
||||
try {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(bytes);
|
||||
out.writeObject(obj);
|
||||
out.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Around(value = "execution(* cn.bunny.services.controller.*.*.*(..)) && !@annotation(cn.bunny.services.aop.annotation.ExcludeRequestLog)")
|
||||
public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
LoginVo loginVo = BaseContext.getLoginVo();
|
||||
|
@ -52,8 +66,9 @@ public class UserRequestLogAop {
|
|||
userRequestLog.setIpRegion(ipRegion);
|
||||
userRequestLog.setExecuteTime(executeTime);
|
||||
|
||||
|
||||
userRequestLog.setArg(JSON.toJSONString(args));
|
||||
// 判断传入参数能否被序列化
|
||||
Object saveArgs = isSerializable(args) ? JSON.toJSONString(args) : "";
|
||||
userRequestLog.setArg(JSON.toJSONString(saveArgs));
|
||||
|
||||
// 当前请求request
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
|
|
|
@ -41,6 +41,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
@ -60,6 +61,7 @@ import java.util.stream.Collectors;
|
|||
* @since 2024-11-07 16:49:19
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements BillService {
|
||||
|
||||
@Autowired
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
server:
|
||||
port: 1010
|
||||
logging:
|
||||
level:
|
||||
cn.bunny.service.mapper: info
|
||||
|
@ -43,5 +45,4 @@ bunny:
|
|||
secretKey: "02120212"
|
||||
bucket-name: financial
|
||||
|
||||
backPath: "D:\\MyData\\backup"
|
||||
bashPath: "D:\\MyData"
|
||||
bashPath: "D:\\MyData"
|
|
@ -1,6 +1,3 @@
|
|||
server:
|
||||
port: 1000
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: @profiles.active@
|
||||
|
|
Loading…
Reference in New Issue