修复 ops_business_event_log 表中日志缺少 targetType 和 targetId 的问题
This commit is contained in:
@@ -83,7 +83,9 @@ public class DispatchEngineImpl implements DispatchEngine {
|
||||
includeParams = true,
|
||||
includeResult = true,
|
||||
result = "#result.success",
|
||||
params = {"#context.orderId", "#context.businessType", "#context.priority"}
|
||||
params = {"#context.orderId", "#context.businessType", "#context.priority"},
|
||||
targetId = "#context.orderId",
|
||||
targetType = "order"
|
||||
)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public DispatchResult dispatch(OrderDispatchContext context) {
|
||||
|
||||
@@ -157,6 +157,30 @@ public class BusinessLogAspect {
|
||||
// 提取业务实体ID
|
||||
if (!businessLog.targetId().isEmpty()) {
|
||||
extractId(record, businessLog.targetId(), evalContext, "targetId", true);
|
||||
} else if (businessLog.scope() == LogScope.ORDER) {
|
||||
// 当使用旧版注解且 scope 为 ORDER 时,尝试从参数中提取 orderId 作为 targetId
|
||||
// 常见的参数名:orderId, context.orderId, request.orderId 等
|
||||
String[] possibleExpressions = {
|
||||
"#orderId",
|
||||
"#context.orderId",
|
||||
"#request.orderId",
|
||||
"#param.orderId",
|
||||
"#ctx.orderId"
|
||||
};
|
||||
|
||||
for (String expr : possibleExpressions) {
|
||||
try {
|
||||
Expression expression = parser.parseExpression(expr);
|
||||
Object value = expression.getValue(evalContext);
|
||||
if (value instanceof Long || value instanceof Integer) {
|
||||
long longValue = value instanceof Long ? (Long) value : ((Integer) value).longValue();
|
||||
record.setTargetId(longValue);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 忽略解析错误,尝试下一个表达式
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置业务实体类型
|
||||
|
||||
Reference in New Issue
Block a user