Commit 0ed3022a authored by yanzg's avatar yanzg

修复等待时间

parent 2617307d
......@@ -3,7 +3,7 @@ package com.yanzuoguang.util.base;
import com.yanzuoguang.util.helper.StringHelper;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
......@@ -26,7 +26,7 @@ public class CollectionString {
*/
public static <T> String getCollectionString(String tag, Collection<T> rowList) {
// 每个字段的长度
Map<String, Integer> mapFieldCount = new HashMap<>(15);
Map<String, Integer> mapFieldCount = new LinkedHashMap<>(15);
// 每个值的长度
rowList.forEach(k -> ObjectEach.each(k, (name, value, field) -> {
// 获取字符串
......
......@@ -18,15 +18,13 @@ import org.springframework.stereotype.Component;
@Component
public class AspectLogResult {
public static final int WAIT_MAX = 30;
public static final int WAIT_ITEM = 10;
private final CloudConfig cloudConfig;
private final LogLocal logLocal;
private final AspectLogBody aspectLogBody;
private final AspectLogTime aspectLogTime;
private final ResponseResult<Object> responseDefault = new ResponseResult();
private final ResponseResult<String> responseDefault = ResponseResult.result("操作成功");
public AspectLogResult(CloudConfig cloudConfig, LogLocal logLocal, AspectLogBody aspectLogBody, AspectLogTime aspectLogTime) {
this.cloudConfig = cloudConfig;
......@@ -52,39 +50,41 @@ public class AspectLogResult {
public void responseLog(Class<?> cls, String tag, String url, boolean logFlag, long start,
Object requestBody, Object result, Exception resultEx, LogVo log) {
try {
// 执行时间
long time = System.currentTimeMillis() - start;
// 全路径
String fullUrl = String.format("%s:%s", tag, url);
// ThreadHelper.waitRun(WAIT_MAX, WAIT_ITEM, k -> StringHelper.isEmpty(log.getLogId()));
if (StringHelper.isEmpty(log.getLogId())) {
// 输出日志标记
boolean isLogCommon = logFlag && this.cloudConfig.isLogCommon();
boolean isLogDatabase = resultEx != null;
boolean isLogDisplay = isLogCommon || isLogDatabase;
// 记录请求时间
aspectLogTime.finish(fullUrl, time, isLogDatabase);
// ThreadHelper.waitRun(WAIT_MAX, WAIT_ITEM, k -> StringHelper.isEmpty(log.getLogId()))
if (StringHelper.isEmpty(log.getLogId()) || !isLogDisplay) {
return;
}
String body = aspectLogBody.getBodyString(requestBody);
if (!StringHelper.compare(log.getContent(), body)) {
log.setContentTo(body);
}
long time = System.currentTimeMillis() - start;
boolean isLogCommon = logFlag && this.cloudConfig.isLogCommon();
boolean isLogDatabase = resultEx != null;
boolean isLogDisplay = isLogCommon || isLogDatabase;
// 处理结果
ResponseResult responseResult = responseDefault;
ResponseResult<?> responseResult;
if (result instanceof ResponseResult) {
responseResult = (ResponseResult) result;
responseResult = (ResponseResult<?>) result;
} else if (result != null) {
responseResult = ResponseResult.result(result);
} else if (resultEx != null) {
responseResult = ExceptionHelper.getError(resultEx);
} else {
responseResult = responseDefault;
}
if (isLogDisplay) {
// 执行时间
if (resultEx != null) {
responseResult = ExceptionHelper.getError(resultEx);
}
String json = JsonHelper.serialize(responseResult);
Log.error(cls, resultEx, "%s [ %s ] time %d ms, result: %s", tag, url, time, aspectLogBody.getMaxString(json));
if (isLogDatabase) {
logLocal.result(log, responseResult.getCode(), json);
}
String json = JsonHelper.serialize(responseResult);
Log.error(cls, resultEx, "%s [ %s ] time %d ms, result: %s", tag, url, time, aspectLogBody.getMaxString(json));
if (isLogDatabase) {
logLocal.result(log, responseResult.getCode(), json);
}
aspectLogTime.finish(fullUrl, time, isLogDatabase);
} catch (Exception e) {
e.printStackTrace();
} finally {
......
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