Commit 602a93df authored by yanzg's avatar yanzg

接口文档的支持

parent 3ec864d9
...@@ -60,11 +60,6 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -60,11 +60,6 @@ public class BaseRequestAspect implements ThreadNext.Next {
*/ */
protected volatile LinkedBlockingQueue<LogVo> cache = new LinkedBlockingQueue<LogVo>(); protected volatile LinkedBlockingQueue<LogVo> cache = new LinkedBlockingQueue<LogVo>();
/**
* 缓存的每次请求的结果
*/
protected MemoryCache<RequestCacheResult> cacheResult = new MemoryCache<>(cacheTime);
public BaseRequestAspect() { public BaseRequestAspect() {
ThreadNext.start(this, "save log error"); ThreadNext.start(this, "save log error");
} }
...@@ -263,10 +258,14 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -263,10 +258,14 @@ public class BaseRequestAspect implements ThreadNext.Next {
while (cache.size() > 0) { while (cache.size() > 0) {
LogVo item = cache.poll(); LogVo item = cache.poll();
if (item != null) { if (item != null) {
if (logFeign == null) { try {
logFeign = context.getBean(LogFeign.class); if (logFeign == null) {
logFeign = context.getBean(LogFeign.class);
}
logFeign.save(item);
} catch (Exception ex) {
ex.printStackTrace();
} }
logFeign.save(item);
} }
} }
return true; return true;
......
...@@ -36,9 +36,6 @@ public class WebAspect extends BaseRequestAspect { ...@@ -36,9 +36,6 @@ public class WebAspect extends BaseRequestAspect {
@Autowired @Autowired
private TokenServiceCall tokenServiceCall; private TokenServiceCall tokenServiceCall;
@Value("${yzg.reqUrl:}")
private String reqUrl;
@Value("${yzg.gateway:^.*gateway.*$}") @Value("${yzg.gateway:^.*gateway.*$}")
private String gateWay; private String gateWay;
...@@ -58,22 +55,22 @@ public class WebAspect extends BaseRequestAspect { ...@@ -58,22 +55,22 @@ public class WebAspect extends BaseRequestAspect {
*/ */
@Around(value = "webAspect()") @Around(value = "webAspect()")
public Object requestWebAround(ProceedingJoinPoint joinPoint) throws Throwable { public Object requestWebAround(ProceedingJoinPoint joinPoint) throws Throwable {
Object result = null;
boolean isGateWay = isGateWay();
if (isGateWay) {
result = executeMethod(joinPoint);
return result;
}
boolean clear = requestLogInit(); boolean clear = requestLogInit();
// 用户数据库记录 // 用户数据库记录
long start = requestLog(TAG, joinPoint); long start = requestLog(TAG, joinPoint);
Object result = null;
Exception ex = null; Exception ex = null;
Ref<Boolean> flag = new Ref<>(false); Ref<Boolean> flag = new Ref<>(false);
boolean isGateWay = isGateWay();
boolean isInit = false; boolean isInit = false;
try { try {
if (!isGateWay) { isInit = tokenServiceCall.tokenInit();
isInit = tokenServiceCall.tokenInit();
}
result = executeMethod(joinPoint); result = executeMethod(joinPoint);
if (!isGateWay) { tokenFinish(flag);
tokenFinish(flag);
}
return result; return result;
} catch (Exception e) { } catch (Exception e) {
ex = e; ex = e;
...@@ -85,9 +82,7 @@ public class WebAspect extends BaseRequestAspect { ...@@ -85,9 +82,7 @@ public class WebAspect extends BaseRequestAspect {
} }
} finally { } finally {
if (isInit) { if (isInit) {
if (!isGateWay) { tokenFinish(flag);
tokenFinish(flag);
}
TokenHelper.remove(); TokenHelper.remove();
} }
responseLog(clear, TAG, HttpAspectUtil.getHttpRequestUrl(), joinPoint, start, result, ex); responseLog(clear, TAG, HttpAspectUtil.getHttpRequestUrl(), joinPoint, start, result, ex);
...@@ -153,44 +148,6 @@ public class WebAspect extends BaseRequestAspect { ...@@ -153,44 +148,6 @@ public class WebAspect extends BaseRequestAspect {
* @throws Throwable * @throws Throwable
*/ */
private Object executeMethod(ProceedingJoinPoint joinPoint) throws Throwable { private Object executeMethod(ProceedingJoinPoint joinPoint) throws Throwable {
List<Object> dataParas = this.getDataParameters(joinPoint.getArgs()); return joinPoint.proceed();
boolean dataArgs = dataParas.isEmpty();
Method method = getMethod(joinPoint);
boolean isUrl = false;
if (!StringHelper.isEmpty(reqUrl)) {
String[] urls = reqUrl.split(",");
for (String url : urls) {
if (method.getName().matches(url)) {
isUrl = true;
break;
}
}
}
if (dataArgs || !isUrl) {
return joinPoint.proceed();
} else {
// 获取请求编号
Object firstArgs = dataParas.size() > 0 ? dataParas.get(0) : null;
String reqId = StringHelper.md5(JsonHelper.serialize(firstArgs));
String reqFull = StringHelper.getId(reqId, HttpAspectUtil.getHttpRequestUrl());
RequestCacheResult req = cacheResult.get(reqFull, new RequestCacheResult(reqFull));
// 缓存的键值对
if (req.getResult() == null) {
synchronized (req) {
if (req.getResult() == null) {
try {
req.setResult(joinPoint.proceed());
} catch (Exception ex) {
req.setResult(ex);
}
}
}
}
Object result = req.getResult();
if (result instanceof Throwable) {
throw (Throwable) result;
}
return result;
}
} }
} }
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