Commit 6552c317 authored by yanzg's avatar yanzg

修改公式和计算帮助类

parent 56714b5d
package com.yanzuoguang.cloud.aop; package com.yanzuoguang.cloud.aop;
import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.ExceptionHelper; import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.JsonHelper; import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
...@@ -35,7 +33,6 @@ import java.util.List; ...@@ -35,7 +33,6 @@ import java.util.List;
*/ */
public class BaseRequestAspect { public class BaseRequestAspect {
@Value("${spring.application.name}") @Value("${spring.application.name}")
protected String applicationName; protected String applicationName;
...@@ -51,12 +48,6 @@ public class BaseRequestAspect { ...@@ -51,12 +48,6 @@ public class BaseRequestAspect {
@Value("${yzg.reqSize:5000}") @Value("${yzg.reqSize:5000}")
private int reqSize = 5000; private int reqSize = 5000;
@Value("${yzg.log.notFilter:^.*login.*$}")
private String notFilter;
@Value("${yzg.log.filter:^.*log.*$}")
private String filter;
@Autowired @Autowired
private LogLocal logLocal; private LogLocal logLocal;
...@@ -72,30 +63,6 @@ public class BaseRequestAspect { ...@@ -72,30 +63,6 @@ public class BaseRequestAspect {
return this.logLocal.startLog(actionKey, String.format("%s:%s", this.applicationName, url), body); return this.logLocal.startLog(actionKey, String.format("%s:%s", this.applicationName, url), body);
} }
/**
* 初始化日志Vo
*
* @param url 请求路径
* @param joinPoint 请求参数
* @param responseResult 返回参数
* @return
*/
protected LogVo abc(String url, ProceedingJoinPoint joinPoint, ResponseResult responseResult) {
LogVo logInterVo = new LogVo();
logInterVo.setLogId(StringHelper.getNewID());
//平台名
logInterVo.setActionKey(applicationName);
//请求URL
logInterVo.setActionSubKey(url);
Object paraTo = getFirstDataParameter(joinPoint.getArgs());
//请求参数
logInterVo.setContent(JSON.toJSONString(paraTo));
//返回参数
logInterVo.setResult(JSON.toJSONString(responseResult));
logInterVo.setStatus(responseResult != null ? responseResult.getCode() : ResultConstants.SUCCESS);
return logInterVo;
}
/** /**
* 获取请求内容 * 获取请求内容
* *
...@@ -242,13 +209,7 @@ public class BaseRequestAspect { ...@@ -242,13 +209,7 @@ public class BaseRequestAspect {
tag, name, time, getMaxString(JsonHelper.serialize(responseResult))); tag, name, time, getMaxString(JsonHelper.serialize(responseResult)));
} }
// 日志请求不记录,防止死循环递归 logLocal.result(log, name, responseResult.getCode(), JsonHelper.serialize(responseResult));
boolean isLog = isLog(name, log.getActionSubKey());
if (isLog) {
logLocal.remove(log);
} else {
logLocal.result(log, responseResult.getCode(), JsonHelper.serialize(responseResult));
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
...@@ -258,23 +219,6 @@ public class BaseRequestAspect { ...@@ -258,23 +219,6 @@ public class BaseRequestAspect {
} }
} }
/**
* 是否属于日志服务
*
* @param name
* @param url
* @return
*/
private boolean isLog(String name, String url) {
boolean noFilter = applicationName.matches(notFilter) || name.matches(notFilter) || url.matches(notFilter);
if (noFilter) {
return false;
}
boolean isLog = applicationName.matches(filter) || name.matches(filter) || url.matches(filter);
return isLog;
}
/** /**
* 获取方法名称 * 获取方法名称
* *
......
...@@ -18,18 +18,27 @@ import java.util.*; ...@@ -18,18 +18,27 @@ import java.util.*;
*/ */
@Component @Component
public class LogLocal implements ThreadNext.Next, InitializingBean { public class LogLocal implements ThreadNext.Next, InitializingBean {
/** /**
* 缓存队列 * 缓存队列
*/ */
protected volatile Map<String, Timeout<LogVo>> cache = new Hashtable<>(); protected volatile Map<String, Timeout<LogVo>> cache = new Hashtable<>();
@Value("${spring.application.name}")
protected String applicationName;
/** /**
* 1个请求最长时间 * 1个请求最长时间
*/ */
@Value("${yzg.timeout:300000}") @Value("${yzg.timeout:300000}")
private int timeout; private int timeout;
@Value("${yzg.log.notFilter:^.*login.*$}")
private String notFilter;
@Value("${yzg.log.filter:^.*log.*$}")
private String filter;
/** /**
* 超时状态 * 超时状态
*/ */
...@@ -87,9 +96,26 @@ public class LogLocal implements ThreadNext.Next, InitializingBean { ...@@ -87,9 +96,26 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
* @return * @return
*/ */
public void result(LogVo log, String status, String result) { public void result(LogVo log, String status, String result) {
this.result(log, StringHelper.EMPTY, status, result);
}
/**
* 写入状态
*
* @param status
* @param result
* @return
*/
public void result(LogVo log, String name, String status, String result) {
// 日志请求不记录,防止死循环递归
boolean isLog = isLog(name, log.getActionSubKey());
if (isLog) {
this.remove(log);
} else {
Timeout<LogVo> timeout = cache.get(log.getLogId()); Timeout<LogVo> timeout = cache.get(log.getLogId());
result(timeout, log, status, result, true); result(timeout, log, status, result, true);
} }
}
/** /**
* 写入状态 * 写入状态
...@@ -132,6 +158,23 @@ public class LogLocal implements ThreadNext.Next, InitializingBean { ...@@ -132,6 +158,23 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
result(timeout, timeout.getData(), MAX_TIME, MAX_TIME_NAME, true); result(timeout, timeout.getData(), MAX_TIME, MAX_TIME_NAME, true);
} }
/**
* 是否属于日志服务
*
* @param name
* @param url
* @return
*/
private boolean isLog(String name, String url) {
boolean noFilter = applicationName.matches(notFilter) || name.matches(notFilter) || url.matches(notFilter);
if (noFilter) {
return false;
}
boolean isLog = applicationName.matches(filter) || name.matches(filter) || url.matches(filter);
return isLog;
}
/** /**
* 执行下一个函数,出现异常会继续执行 * 执行下一个函数,出现异常会继续执行
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment