|
|
@ -3,6 +3,7 @@ package com.project.operation.aop; |
|
|
import com.project.base.domain.result.Result; |
|
|
import com.project.base.domain.result.Result; |
|
|
import com.project.ding.domain.dto.LoginDTO; |
|
|
import com.project.ding.domain.dto.LoginDTO; |
|
|
import com.project.ding.utils.JwtUtils; |
|
|
import com.project.ding.utils.JwtUtils; |
|
|
|
|
|
import com.project.ding.utils.SecurityUtils; |
|
|
import com.project.operation.annotation.OperationLog; |
|
|
import com.project.operation.annotation.OperationLog; |
|
|
import com.project.operation.application.impl.OperationLogApplicationService; |
|
|
import com.project.operation.application.impl.OperationLogApplicationService; |
|
|
import com.project.operation.domain.dto.OperationLogDTO; |
|
|
import com.project.operation.domain.dto.OperationLogDTO; |
|
|
@ -12,14 +13,11 @@ import jakarta.servlet.http.HttpServletRequest; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
import org.aspectj.lang.annotation.AfterReturning; |
|
|
|
|
|
import org.aspectj.lang.annotation.Around; |
|
|
import org.aspectj.lang.annotation.Around; |
|
|
import org.aspectj.lang.annotation.Aspect; |
|
|
import org.aspectj.lang.annotation.Aspect; |
|
|
import org.aspectj.lang.annotation.Pointcut; |
|
|
import org.aspectj.lang.annotation.Pointcut; |
|
|
import org.aspectj.lang.reflect.MethodSignature; |
|
|
import org.aspectj.lang.reflect.MethodSignature; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.security.core.Authentication; |
|
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder; |
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
@ -90,15 +88,9 @@ public class OperationLogAspect { |
|
|
operationLogDTO.setClientIp(request.getRemoteAddr()); |
|
|
operationLogDTO.setClientIp(request.getRemoteAddr()); |
|
|
|
|
|
|
|
|
// 收集登录用户ID
|
|
|
// 收集登录用户ID
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
|
|
String userId = SecurityUtils.getUserId(); |
|
|
if (authentication != null && authentication.getPrincipal() != null) { |
|
|
if (userId != null) { |
|
|
Object principal = authentication.getPrincipal(); |
|
|
operationLogDTO.setCreatorId(Long.parseLong(userId.toString())); |
|
|
try { |
|
|
|
|
|
Long userId = Long.parseLong(principal.toString()); |
|
|
|
|
|
operationLogDTO.setCreatorId(userId); |
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
|
log.warn("解析用户ID失败,principal:{}", principal, e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|