Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加actionType字段,便于查询某类操作类型的日志 #72

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bizlog-sdk/src/main/java/com/mzt/logapi/beans/LogRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ public class LogRecord {
* CodeVariableType 日志记录的ClassName、MethodName
*/
private Map<CodeVariableType, Object> codeVariable;

private String actionType;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class LogRecordOps {
private String extra;
private String condition;
private boolean isBatch;
private String actionType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@
* */
boolean isBatch() default false;

/**
* 操作类型,比如:增、删、改,可自定义枚举,便于查询某种操作类型的日志
*/
String actionType() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private void recordExecute(Object ret, Method method, Object[] args, Collection<
.action(expressionValues.get(action).get(x))
.fail(!success)
.createTime(new Date())
.actionType(operation.getActionType())
.build();
}).filter(x -> !StringUtils.isEmpty(x.getAction()))
.collect(Collectors.toList());
Expand All @@ -149,6 +150,7 @@ private void recordExecute(Object ret, Method method, Object[] args, Collection<
.action(expressionValues.get(action))
.fail(!success)
.createTime(new Date())
.actionType(operation.getActionType())
.build();

//如果 action 为空,不记录日志
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private LogRecordOps parseLogRecordAnnotation(AnnotatedElement ae, LogRecord rec
.extra(recordAnnotation.extra())
.condition(recordAnnotation.condition())
.isBatch(recordAnnotation.isBatch())
.actionType(recordAnnotation.actionType())
.build();
validateLogRecordOperation(ae, recordOps);
return recordOps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class OrderServiceImpl implements IOrderService {
subType = "MANAGER_VIEW",
extra = "{{#order.toString()}}",
success = "{{#order.purchaseName}}下了一个订单,购买商品「{{#order.productName}}」,测试变量「{{#innerOrder.productName}}」,下单结果:{{#_ret}}",
type = LogRecordType.ORDER, bizNo = "{{#order.orderNo}}")
type = LogRecordType.ORDER, bizNo = "{{#order.orderNo}}", actionType = "INSERT")
public boolean createOrder(Order order) {
log.info("【创建订单】orderNo={}", order.getOrderNo());
// db insert order
Expand All @@ -51,7 +51,7 @@ public boolean createOrder(Order order) {
extra = "{{#orders}}",
success = "{{#purchaseNameList}}下了一个订单,购买商品「{{#productNameList}}」,下单结果:{{#_ret}}",
type = LogRecordType.ORDER, bizNo = "{{#orderNoList}}",
isBatch = true)
isBatch = true, actionType = "INSERT")
public boolean createBatchOrder(List<Order> orders) {
Optional.ofNullable(orders).ifPresent(x -> {
x.forEach(y -> log.info("【创建订单】orderNo={}", y.getOrderNo()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class LogRecordPO {

private String codeVariable;

private String actionType;

public static LogRecordPO from(LogRecord logRecord) {
LogRecordPO logRecordPO = new LogRecordPO();
BeanUtils.copyProperties(logRecord, logRecordPO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void createOrder() {
Assert.assertNotNull(logRecord.getExtra());
Assert.assertEquals(logRecord.getBizNo(), order.getOrderNo());
Assert.assertFalse(logRecord.isFail());
Assert.assertEquals(logRecord.getActionType(), "INSERT");
logRecordService.clean();
}

Expand All @@ -59,11 +60,13 @@ public void testCreateBatchOrder() {
Assert.assertNotNull(recordA.getExtra());
Assert.assertEquals(recordA.getBizNo(), orderA.getOrderNo());
Assert.assertFalse(recordA.isFail());
Assert.assertEquals(recordA.getActionType(), "INSERT");
LogRecord recordB = records.get(1);
Assert.assertEquals(recordB.getAction(), "李四下了一个订单,购买商品「超值优惠黄焖鸡套餐」,下单结果:true");
Assert.assertNotNull(recordB.getExtra());
Assert.assertEquals(recordB.getBizNo(), orderB.getOrderNo());
Assert.assertFalse(recordB.isFail());
Assert.assertEquals(recordB.getActionType(), "INSERT");
}

@Test
Expand Down
1 change: 1 addition & 0 deletions bizlog-server/src/test/resources/sql/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ create table t_logrecord
`create_time` datetime(3) not null default current_time(3) comment '创建时间',
`extra` varchar(2000) not null default '' comment '扩展信息',
`code_variable` varchar(2000) not null default '' comment '代码变量信息',
`action_type` varchar(20) not null default '' comment '操作类型',
primary key (id)
);