提交修改

This commit is contained in:
quyixiao 2025-11-18 12:49:12 +08:00
parent a626661ee5
commit d78772a8be
4 changed files with 150 additions and 35 deletions

View File

@ -72,6 +72,22 @@ public class ApiConstants {
public static final String List = "List";
public static final String set = "set";
public static final String GET_BUYER_ID = "getBuyerId";
public static final String SET_USER_NAME = "setUsername";
public static final String SET_ADMIN_ID = "setAdminId";
public static final String APP_URI_START = "/app/";
public static final String MM_URI_START = "/mm/";
public static final String APP_TOKEN = "token";
public static final String MM_TOKEN = "mmToken";
public static final String MM_ADMIN_LOGIN_RUI = "/mm/admin/login";
public static final String get = "get";
/**
* 定时任务状态
@ -217,6 +233,21 @@ public class ApiConstants {
*/
public static String TRACE_ID = "logid";
/**
* traceId ,日志编号
*/
public static String on = "on";
/**
* traceId ,日志编号
*/
public static String trace_id = "traceId";
/**
* ip
*/

View File

@ -40,4 +40,60 @@ public class BuyerDTO {
//买家手机号
private String buyerPhone;
public Long getBuyerId() {
return buyerId;
}
public void setBuyerId(Long buyerId) {
this.buyerId = buyerId;
}
public String getBuyerName() {
return buyerName;
}
public void setBuyerName(String buyerName) {
this.buyerName = buyerName;
}
public Integer getFlag() {
return flag;
}
public void setFlag(Integer flag) {
this.flag = flag;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getBuyerWeixin() {
return buyerWeixin;
}
public void setBuyerWeixin(String buyerWeixin) {
this.buyerWeixin = buyerWeixin;
}
public String getBuyerPhone() {
return buyerPhone;
}
public void setBuyerPhone(String buyerPhone) {
this.buyerPhone = buyerPhone;
}
}

View File

@ -20,4 +20,36 @@ public class VVAdminDTO {
* 登录用户id
*/
private Long adminId;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public Long getExpireTime() {
return expireTime;
}
public void setExpireTime(Long expireTime) {
this.expireTime = expireTime;
}
public Long getAdminId() {
return adminId;
}
public void setAdminId(Long adminId) {
this.adminId = adminId;
}
}

View File

@ -51,7 +51,6 @@ public class ZhenZhenLogAop {
@Value("${eb.config.rabbitQueue.urlStatisticQueue}")
private String urlStatisticQueue;
@Autowired
private RabbitTemplate rabbitTemplate;
@ -59,6 +58,7 @@ public class ZhenZhenLogAop {
@Pointcut(value = "(" + " @within(org.springframework.web.bind.annotation.RestController) || " + " @within(org.springframework.stereotype.Controller)" + ")")
public void pointcut() {
}
@Around("pointcut()")
@ -71,9 +71,9 @@ public class ZhenZhenLogAop {
String className = "";
String uri = "";
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
String traceId = attributes.getRequest().getHeader("traceId");
String traceId = attributes.getRequest().getHeader(ApiConstants.trace_id);
if (StringUtils.isBlank(traceId)) {
traceId = OrderUtil.getUserPoolOrder("on");
traceId = OrderUtil.getUserPoolOrder(ApiConstants.on);
}
Long buyerId = null;
Long startTime = System.currentTimeMillis();
@ -84,9 +84,10 @@ public class ZhenZhenLogAop {
String describe = null;
// 如果不是小程序的url 则直接过滤掉
if (!uri.startsWith("/mm/") && !uri.startsWith("/app/")) {
if (!uri.startsWith(ApiConstants.MM_URI_START) && !uri.startsWith(ApiConstants.APP_URI_START)) {
return point.proceed();
}
String token = "";
try {
args = recordRequestLog(point.getArgs(), uri);
@ -97,14 +98,12 @@ public class ZhenZhenLogAop {
}
describe = AnnotationUtils.getAnnotationValueByMethod(method, "Describe", "value");
Class clazz = point.getTarget().getClass();
className = clazz.getName();
Object[] argArrs = point.getArgs();
if (uri.startsWith("/app/")) {
token = attributes.getRequest().getHeader("token");
if (uri.startsWith(ApiConstants.APP_URI_START)) {
token = attributes.getRequest().getHeader(ApiConstants.APP_TOKEN);
// 参数封装
if (argArrs != null && argArrs.length > 0) {
@ -112,9 +111,8 @@ public class ZhenZhenLogAop {
argArr.getClass().getDeclaredMethods();
List<Method> methods = new ArrayList<>();
getClassDeclaredMethods(argArr.getClass(), methods);
for (Method m : methods) {
if ("getBuyerId".equalsIgnoreCase(m.getName())) {
if (ApiConstants.GET_BUYER_ID.equalsIgnoreCase(m.getName())) {
m.setAccessible(true);
Object getBuyerId = m.invoke(argArr);
if (buyerId == null && getBuyerId != null) {
@ -135,20 +133,18 @@ public class ZhenZhenLogAop {
// m.setAccessible(true);
// m.invoke(argArr, new Object[]{buyerId});
//}
}
}
}
} else if (uri.startsWith("/mm/")) {
token = attributes.getRequest().getHeader("mmToken");
} else if (uri.startsWith(ApiConstants.MM_URI_START)) {
token = attributes.getRequest().getHeader(ApiConstants.MM_TOKEN);
Object tokenValue = redisUtils.get(token);
// 登录不拦截
if (!"/mm/admin/login".equals(uri)) {
if (!ApiConstants.MM_ADMIN_LOGIN_RUI.equals(uri)) {
if (tokenValue == null) {
return R.error("请登录");
}
}
if (tokenValue != null) {
try {
VVAdminDTO vvAdminDTO = JSONObject.parseObject(tokenValue + "", VVAdminDTO.class);
@ -158,28 +154,32 @@ public class ZhenZhenLogAop {
List<Method> methods = new ArrayList<>();
getClassDeclaredMethods(argArr.getClass(), methods);
for (Method m : methods) {
if ("setUserName".equalsIgnoreCase(m.getName())) {
if (ApiConstants.SET_USER_NAME.equalsIgnoreCase(m.getName())) {
m.setAccessible(true);
m.invoke(argArr, new Object[]{vvAdminDTO.getUsername()});
}
if ("setAdminId".equals(m.getName())) {
if (ApiConstants.SET_ADMIN_ID.equals(m.getName())) {
m.setAccessible(true);
m.invoke(argArr, new Object[]{vvAdminDTO.getAdminId()});
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
result = point.proceed();
if (result instanceof R) {
R r = (R) result;
Object object = r.getData();
convertImage(object,token);
}
} catch (Exception e) {
log.error("LogAop set error " + sb.toString(), e);
} finally {
@ -224,7 +224,7 @@ public class ZhenZhenLogAop {
for (Method method : methods) {
try {
method.setAccessible(true);
if (method.getName().startsWith("get")) {
if (method.getName().startsWith(ApiConstants.get )) {
Object image = method.invoke(object);
// 如果是基本数据类型
if (SanUtils.isBasicDataTypes(method.getReturnType())) {
@ -242,7 +242,6 @@ public class ZhenZhenLogAop {
}
String setMethodName = ApiConstants.set + method.getName().substring(3);
Method setMethod = methodMap.get(setMethodName);
setMethod.invoke(object, new Object[]{newImage});
}
}
@ -282,23 +281,20 @@ public class ZhenZhenLogAop {
.append("result:").append(JSON.toJSONString(result));
log.info(sb.toString());
rabbitTemplate.convertAndSend(urlStatisticQueue,
JSON.toJSONString(new VVRequestLogDTO(
token, // token
null,
traceId,
System.currentTimeMillis(), // 当前请求的接口
preUri, //日志编号
System.currentTimeMillis() - startTime,
args,
buyerId,
describe
)
));
if (preUri.startsWith("/app/")) {
rabbitTemplate.convertAndSend(urlStatisticQueue,
JSON.toJSONString(new VVRequestLogDTO(
token, // token
null,
traceId,
System.currentTimeMillis(), // 当前请求的接口
preUri, //日志编号
System.currentTimeMillis() - startTime,
args,
buyerId,
describe
)
));
}
}
private String recordRequestLog(Object[] argArrs, String uri) {