修复 ops_business_event_log 表中日志缺少 targetType 和 targetId 的问题
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled

This commit is contained in:
lzh
2026-02-01 02:05:41 +08:00
parent 41c4f57f05
commit 2afc173e18
6 changed files with 214 additions and 66 deletions

View File

@@ -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) {

View File

@@ -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) {
// 忽略解析错误,尝试下一个表达式
}
}
}
// 设置业务实体类型