Commit e8f81291 authored by yanzg's avatar yanzg

修复异常提醒,从而正确的跟踪异常信息

parent 77fb7cbb
......@@ -2,8 +2,9 @@ package com.yanzuoguang.db.impl;
import com.yanzuoguang.db.ConfigDb;
import com.yanzuoguang.db.DbExecute;
import com.yanzuoguang.log.LogCountTime;
import com.yanzuoguang.util.helper.YzgTimeout;
import com.yanzuoguang.log.AspectLogResult;
import com.yanzuoguang.log.AspectLogStart;
import com.yanzuoguang.log.LogInfoVo;
import com.yanzuoguang.util.vo.MapRow;
import com.yanzuoguang.util.vo.Ref;
import org.springframework.jdbc.core.JdbcTemplate;
......@@ -24,13 +25,19 @@ public class DbExecuteImpl implements DbExecute {
private final JdbcTemplate jdbcTemplate;
private final DbExecutePrintSql printSql;
private final ConfigDb configDb;
private final LogCountTime logCountTime;
private final AspectLogStart aspectLogStart;
private final AspectLogResult aspectLogResult;
public DbExecuteImpl(JdbcTemplate jdbcTemplate, DbExecutePrintSql printSql, ConfigDb configDb, LogCountTime logCountTime) {
public DbExecuteImpl(JdbcTemplate jdbcTemplate,
DbExecutePrintSql printSql,
ConfigDb configDb,
AspectLogStart aspectLogStart,
AspectLogResult aspectLogResult) {
this.jdbcTemplate = jdbcTemplate;
this.printSql = printSql;
this.configDb = configDb;
this.logCountTime = logCountTime;
this.aspectLogStart = aspectLogStart;
this.aspectLogResult = aspectLogResult;
}
public JdbcTemplate getJdbc() {
......@@ -148,29 +155,24 @@ public class DbExecuteImpl implements DbExecute {
*/
private void executeSql(SqlInfo sqlInfo, DbSqlFunction<Ref<Integer>, Long> sqlFunction) {
// 开始记录日志
String fullUrl = String.format("Sql:%s:%s", sqlInfo.getTargetClass().getSimpleName(), sqlInfo.getSqlName());
logCountTime.start(fullUrl);
LogInfoVo log = aspectLogStart.requestLog(sqlInfo.getTargetClass(), "Sql",
String.format("%s:%s", sqlInfo.getTargetClass().getSimpleName(), sqlInfo.getSqlName()), sqlInfo, true);
// 开始时间
long start = System.currentTimeMillis();
Ref<Integer> row = new Ref<>(0);
sqlInfo.setSql(this.handleParas(sqlInfo.getSql()));
boolean isError = false;
try {
YzgTimeout.timeOut(sqlInfo.getTargetClass(), sqlInfo.getSqlName()
, () -> sqlFunction.accept(row, start)
// 打印超时的SQL语句
, (time) -> printSql.print(sqlInfo, time, row.value));
// 执行得函数
sqlFunction.accept(row, start);
// 写入日志
aspectLogResult.responseLog(log, row, null);
} catch (Exception ex) {
isError = true;
// 写入日志
aspectLogResult.responseLog(log, row, ex);
throw ex;
} finally {
// 写入日志
long time = System.currentTimeMillis() - start;
logCountTime.finish(fullUrl, time, isError);
// 打印sql语句
printSql.print(sqlInfo, time, row.value);
printSql.print(sqlInfo, log.getUseTime(), row.value);
}
}
......
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