Commit a0cff7f2 authored by yanzg's avatar yanzg

修复等待时间

parent e1979def
......@@ -16,6 +16,8 @@ import java.util.Date;
@Component
public class CloudConfig {
public static final int DEFAULT_PRINT_TIME = 2 * 60 * 1000;
@Value("${spring.application.name}")
protected String applicationName;
......@@ -70,6 +72,11 @@ public class CloudConfig {
@Value("${yzg.gateway:^.*gateway.*$}")
private String gateWay;
/**
* 外网地址
*/
@Value("${yzg.count.print.time:" + DEFAULT_PRINT_TIME + "}")
private int logCountTime;
public String getApplicationName() {
return applicationName;
......@@ -152,4 +159,8 @@ public class CloudConfig {
public boolean isGateWay() {
return this.applicationName.toLowerCase().matches(this.gateWay);
}
public int getLogCountTime() {
return logCountTime;
}
}
package com.yanzuoguang.cloud.aop;
import com.yanzuoguang.util.base.CollectionString;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.thread.ThreadNext;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* 日志时间
*
* @author 颜佐光
*/
@Component
public class AspectLogTime implements ThreadNext.Next, InitializingBean {
public class AspectLogCountTime {
private static final String URL_PARA_START = "?";
......@@ -35,9 +28,12 @@ public class AspectLogTime implements ThreadNext.Next, InitializingBean {
*/
private String todayTime;
@Override
public void afterPropertiesSet() {
ThreadNext.start(this, "aspectLogTime");
public MemoryCache<AspectUrlCountVo> getTodayMemoryCache() {
return todayMemoryCache;
}
public String getTodayTime() {
return todayTime;
}
private void initToday() {
......@@ -104,20 +100,4 @@ public class AspectLogTime implements ThreadNext.Next, InitializingBean {
AspectUrlCountVo count = getCount(url);
count.addFinish(time, isError);
}
@Override
public boolean next() {
List<AspectUrlCountVo> rowList = new ArrayList<>(todayMemoryCache.getValues());
if (rowList.isEmpty()) {
return true;
}
rowList.sort(Comparator.comparingLong(AspectUrlCountVo::getTotalTime));
System.out.println(CollectionString.getCollectionString("接口从" + todayTime + "时执行次数:", rowList));
return true;
}
@Override
public int getNextTime() {
return 2 * 60 * 1000;
}
}
package com.yanzuoguang.cloud.aop;
import com.yanzuoguang.cloud.CloudConfig;
import com.yanzuoguang.util.base.CollectionString;
import com.yanzuoguang.util.thread.ThreadNext;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* 将请求次数日志输出
*
* @author 颜佐光
*/
@Component
public class AspectLogPrint implements ThreadNext.Next, InitializingBean {
private final CloudConfig cloudConfig;
private final AspectLogCountTime aspectLogCountTime;
public AspectLogPrint(CloudConfig cloudConfig, AspectLogCountTime aspectLogCountTime) {
this.cloudConfig = cloudConfig;
this.aspectLogCountTime = aspectLogCountTime;
}
@Override
public void afterPropertiesSet() {
ThreadNext.start(this, "aspectLogTime");
}
@Override
public boolean next() {
List<AspectUrlCountVo> rowList = new ArrayList<>(aspectLogCountTime.getTodayMemoryCache().getValues());
if (rowList.isEmpty()) {
return true;
}
rowList.sort(Comparator.comparingLong(AspectUrlCountVo::getTotalTime));
System.out.println(CollectionString.getCollectionString("接口从" + aspectLogCountTime.getTodayTime() + "时执行次数:", rowList));
return true;
}
@Override
public int getNextTime() {
return cloudConfig.getLogCountTime();
}
}
......@@ -21,16 +21,16 @@ public class AspectLogResult {
private final CloudConfig cloudConfig;
private final LogLocal logLocal;
private final AspectLogBody aspectLogBody;
private final AspectLogTime aspectLogTime;
private final AspectLogCountTime aspectLogCountTime;
private final ResponseResult<String> responseDefault = ResponseResult.result("操作成功");
public AspectLogResult(CloudConfig cloudConfig, LogLocal logLocal, AspectLogBody aspectLogBody, AspectLogTime aspectLogTime) {
public AspectLogResult(CloudConfig cloudConfig, LogLocal logLocal, AspectLogBody aspectLogBody, AspectLogCountTime aspectLogCountTime) {
this.cloudConfig = cloudConfig;
this.logLocal = logLocal;
this.aspectLogBody = aspectLogBody;
this.aspectLogTime = aspectLogTime;
this.aspectLogCountTime = aspectLogCountTime;
}
/**
......@@ -59,7 +59,7 @@ public class AspectLogResult {
boolean isError = resultEx != null;
boolean isLogDisplay = isLogCommon || isError;
// 记录请求时间
aspectLogTime.finish(fullUrl, time, isError);
aspectLogCountTime.finish(fullUrl, time, isError);
// ThreadHelper.waitRun(WAIT_MAX, WAIT_ITEM, k -> StringHelper.isEmpty(log.getLogId()))
if (StringHelper.isEmpty(log.getLogId()) || !isLogDisplay) {
return;
......
......@@ -17,13 +17,13 @@ public class AspectLogStart {
private final CloudConfig cloudConfig;
private final LogLocal logLocal;
private final AspectLogBody aspectLogBody;
private final AspectLogTime aspectLogTime;
private final AspectLogCountTime aspectLogCountTime;
public AspectLogStart(CloudConfig cloudConfig, LogLocal logLocal, AspectLogBody aspectLogBody, AspectLogTime aspectLogTime) {
public AspectLogStart(CloudConfig cloudConfig, LogLocal logLocal, AspectLogBody aspectLogBody, AspectLogCountTime aspectLogCountTime) {
this.cloudConfig = cloudConfig;
this.logLocal = logLocal;
this.aspectLogBody = aspectLogBody;
this.aspectLogTime = aspectLogTime;
this.aspectLogCountTime = aspectLogCountTime;
}
/**
......@@ -40,7 +40,7 @@ public class AspectLogStart {
public void requestLog(Class<?> cls, String tag, String url, Object requestBody, LogVo log, boolean logFlag) {
try {
String fullUrl = String.format("%s:%s", tag, url);
aspectLogTime.start(fullUrl);
aspectLogCountTime.start(fullUrl);
String body = aspectLogBody.getBodyString(requestBody);
if (logFlag) {
......
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