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