|
@ -55,6 +55,13 @@ public class ActionLogAspect { |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
throw e; |
|
|
throw e; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//当操作行为是新增数据时,需要上报数据业务id |
|
|
|
|
|
if(actionLog.businessType().equals(BusinessType.INSERT)){ |
|
|
|
|
|
setBusinessId(args,actionLog,actionLogMessage); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 记录结束时间 |
|
|
// 记录结束时间 |
|
|
long endTime = System.currentTimeMillis(); |
|
|
long endTime = System.currentTimeMillis(); |
|
|
// 计算响应时间 |
|
|
// 计算响应时间 |
|
@ -139,6 +146,36 @@ public class ActionLogAspect { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setBusinessId(Object[] args,ActionLog actionLog,ActionLogMessage actionLogMessage){ |
|
|
|
|
|
Object arg = args[0]; |
|
|
|
|
|
Class<?> entityClass = actionLog.entityClass(); |
|
|
|
|
|
//获取tableId字段 |
|
|
|
|
|
String tableIdField = actionLog.idFieldName(); |
|
|
|
|
|
// String tableIdField = ""; |
|
|
|
|
|
// Field[] fields = entityClass.getDeclaredFields(); |
|
|
|
|
|
// for(Field field : fields) { |
|
|
|
|
|
// field.setAccessible(true); |
|
|
|
|
|
// if (field.isAnnotationPresent(TableId.class)) { |
|
|
|
|
|
// tableIdField = field.getName(); |
|
|
|
|
|
// break; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 将 arg 转换为 entityClass 类型的对象 |
|
|
|
|
|
Object afterEntity = entityClass.cast(arg); |
|
|
|
|
|
// 获取 tableIdField 对应的 Field 对象 |
|
|
|
|
|
Field idField = entityClass.getDeclaredField(tableIdField); |
|
|
|
|
|
idField.setAccessible(true); |
|
|
|
|
|
// 获取 id 的值 |
|
|
|
|
|
Long businessId = (Long)idField.get(afterEntity); |
|
|
|
|
|
actionLogMessage.setBusinessId(businessId); |
|
|
|
|
|
} catch (IllegalAccessException | NoSuchFieldException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|