Skip to content

Commit

Permalink
Merge pull request #51 from mouzt/feature/version2
Browse files Browse the repository at this point in the history
版本2.0
  • Loading branch information
mouzt authored Feb 27, 2022
2 parents a5091e7 + 746592d commit 37a12a1
Show file tree
Hide file tree
Showing 43 changed files with 1,894 additions and 300 deletions.
2 changes: 1 addition & 1 deletion bizlog-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>bizlog-sdk</artifactId>
<version>1.1.1</version>
<version>2.0.0</version>
<parent>
<groupId>io.github.mouzt</groupId>
<artifactId>mzt-biz-log</artifactId>
Expand Down
47 changes: 40 additions & 7 deletions bizlog-sdk/src/main/java/com/mzt/logapi/beans/LogRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,59 @@
@NoArgsConstructor
@ToString
public class LogRecord {
/**
* id
*/
private Serializable id;
/**
* 租户
*/
private String tenant;
@NotBlank(message = "bizKey required")
@Length(max = 200, message = "appKey max length is 200")
private String bizKey;

/**
* 保存的操作日志的类型,比如:订单类型、商品类型
*
* @since 2.0.0 从 prefix 修改为了type
*/
@NotBlank(message = "type required")
@Length(max = 200, message = "type max length is 200")
private String type;
/**
* 日志的子类型,比如订单的C端日志,和订单的B端日志,type都是订单类型,但是子类型不一样
* @since 2.0.0 从 category 修改为 subtype
*/
private String subType;

/**
* 日志绑定的业务标识
*/
@NotBlank(message = "bizNo required")
@Length(max = 200, message = "bizNo max length is 200")
private String bizNo;

/**
* 操作人
*/
@NotBlank(message = "operator required")
@Length(max = 63, message = "operator max length 63")
private String operator;

/**
* 日志内容
*/
@NotBlank(message = "opAction required")
@Length(max = 511, message = "operator max length 511")
private String action;

/**
* 记录是否是操作失败的日志
*/
private boolean fail;
private String category;
/**
* 日志的创建时间
*/
private Date createTime;
private String detail;
/**
* 日志的额外信息
* @since 2.0.0 从detail 修改为extra
*/
private String extra;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class LogRecordOps {
private String successLogTemplate;
private String failLogTemplate;
private String operatorId;
private String bizKey;
private String type;
private String bizNo;
private String category;
private String detail;
private String subType;
private String extra;
private String condition;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ public interface ILogRecordService {
/**
* 返回最多100条记录
*
* @param bizKey 日志前缀+bizNo
* @param type 操作日志类型
* @param bizNo 操作日志的业务标识,比如:订单号
* @return 操作日志列表
*/
List<LogRecord> queryLog(String bizKey);
List<LogRecord> queryLog(String bizNo, String type);

/**
* 返回最多100条记录
*
* @param bizNo 业务标识
* @param type 操作日志类型
* @param subType 操作日志子类型
* @param bizNo 操作日志的业务标识,比如:订单号
* @return 操作日志列表
*/
List<LogRecord> queryLogByBizNo(String bizNo);
List<LogRecord> queryLogByBizNo(String bizNo, String type, String subType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ public void record(LogRecord logRecord) {
}

@Override
public List<LogRecord> queryLog(String bizKey) {
// return logRecordMapper.queryByBizKey(bizKey);
public List<LogRecord> queryLog(String bizNo, String type) {
return Lists.newArrayList();
}

@Override
public List<LogRecord> queryLogByBizNo(String bizNo) {

// return logRecordMapper.queryByBizNo(bizNo);
public List<LogRecord> queryLogByBizNo(String bizNo, String type, String subType) {
return Lists.newArrayList();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.mzt.logapi.starter.annotation;

import java.lang.annotation.*;

/**
* @author muzhantong
* create on 2020/4/29 3:22 下午
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface LogRecord {
/**
* 方法执行成功后的日志模版
*/
String success();

/**
* 方法执行失败后的日志模版
*/
String fail() default "";

/**
* 日志的操作人
*/
String operator() default "";

/**
* 操作日志的类型,比如:订单类型、商品类型
*/
String type();

/**
* 日志的子类型,比如订单的C端日志,和订单的B端日志,type都是订单类型,但是子类型不一样
*/
String subType() default "";

/**
* 日志绑定的业务标识
*/
String bizNo();

/**
* 日志的额外信息
*/
String extra() default "";

String condition() default "";
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ private void recordExecute(Object ret, Method method, Object[] args, Collection<
if (logConditionPassed(operation.getCondition(), expressionValues)) {
LogRecord logRecord = LogRecord.builder()
.tenant(tenantId)
.bizKey(expressionValues.get(operation.getBizKey()))
.type(expressionValues.get(operation.getType()))
.bizNo(expressionValues.get(operation.getBizNo()))
.operator(getRealOperatorId(operation, operatorIdFromService, expressionValues))
.category(operation.getCategory())
.detail(expressionValues.get(operation.getDetail()))
.subType(operation.getSubType())
.extra(expressionValues.get(operation.getExtra()))
.action(expressionValues.get(action))
.fail(!success)
.createTime(new Date())
Expand All @@ -135,7 +135,7 @@ private void recordExecute(Object ret, Method method, Object[] args, Collection<
}

private List<String> getSpElTemplates(LogRecordOps operation, String action) {
List<String> spElTemplates = Lists.newArrayList(operation.getBizKey(), operation.getBizNo(), action, operation.getDetail());
List<String> spElTemplates = Lists.newArrayList(operation.getType(), operation.getBizNo(), action, operation.getExtra());
if (!StringUtils.isEmpty(operation.getCondition())) {
spElTemplates.add(operation.getCondition());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mzt.logapi.starter.support.aop;

import com.mzt.logapi.beans.LogRecordOps;
import com.mzt.logapi.starter.annotation.LogRecordAnnotation;
import com.mzt.logapi.starter.annotation.LogRecord;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.util.ClassUtils;
Expand Down Expand Up @@ -38,26 +38,26 @@ public Collection<LogRecordOps> computeLogRecordOperations(Method method, Class<
}

private Collection<LogRecordOps> parseLogRecordAnnotations(AnnotatedElement ae) {
Collection<LogRecordAnnotation> logRecordAnnotationAnnotations = AnnotatedElementUtils.getAllMergedAnnotations(ae, LogRecordAnnotation.class);
Collection<LogRecord> logRecordAnnotationAnnotations = AnnotatedElementUtils.getAllMergedAnnotations(ae, LogRecord.class);
Collection<LogRecordOps> ret = null;
if (!logRecordAnnotationAnnotations.isEmpty()) {
ret = lazyInit(ret);
for (LogRecordAnnotation recordAnnotation : logRecordAnnotationAnnotations) {
for (LogRecord recordAnnotation : logRecordAnnotationAnnotations) {
ret.add(parseLogRecordAnnotation(ae, recordAnnotation));
}
}
return ret;
}

private LogRecordOps parseLogRecordAnnotation(AnnotatedElement ae, LogRecordAnnotation recordAnnotation) {
private LogRecordOps parseLogRecordAnnotation(AnnotatedElement ae, LogRecord recordAnnotation) {
LogRecordOps recordOps = LogRecordOps.builder()
.successLogTemplate(recordAnnotation.success())
.failLogTemplate(recordAnnotation.fail())
.bizKey(recordAnnotation.prefix().concat("_").concat(recordAnnotation.bizNo()))
.type(recordAnnotation.type())
.bizNo(recordAnnotation.bizNo())
.operatorId(recordAnnotation.operator())
.category(StringUtils.isEmpty(recordAnnotation.category()) ? recordAnnotation.prefix() : recordAnnotation.category())
.detail(recordAnnotation.detail())
.subType(recordAnnotation.subType())
.extra(recordAnnotation.extra())
.condition(recordAnnotation.condition())
.build();
validateLogRecordOperation(ae, recordOps);
Expand Down
30 changes: 22 additions & 8 deletions bizlog-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,30 @@
</parent>


<!-- <properties>-->
<!-- <maven.deploy.skip>true</maven.deploy.skip>-->
<!-- </properties>-->
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>

<dependency>
<groupId>io.github.mouzt</groupId>
<artifactId>bizlog-sdk</artifactId>
<version>2.0.0</version>
</dependency>

<!--druid 依赖-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>

<dependency>
<groupId>com.github.colincatsu</groupId>
<artifactId>fast-object-diff</artifactId>
Expand All @@ -33,11 +52,6 @@
<artifactId>hutool-all</artifactId>
<version>5.5.9</version>
</dependency>
<dependency>
<groupId>io.github.mouzt</groupId>
<artifactId>bizlog-sdk</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mzt.logserver.service;
package com.mzt.logserver;

import com.mzt.logserver.beans.Order;
import com.mzt.logserver.pojo.Order;

/**
* @author muzhantong
Expand Down
6 changes: 4 additions & 2 deletions bizlog-server/src/main/java/com/mzt/logserver/Main.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.mzt.logserver;

import com.mzt.logapi.starter.annotation.EnableLogRecord;
import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@SpringBootApplication
@EnableTransactionManagement
@MapperScan(basePackages = "com.mzt.logserver.repository.mapper", annotationClass = Mapper.class)
@EnableLogRecord(tenant = "com.mzt.test")
public class Main {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mzt.logserver.service;
package com.mzt.logserver;

import org.apache.catalina.User;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mzt.logserver.configuration;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DataSourceAutoConfig {

@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DruidDataSource dataSource() {
return new DruidDataSource();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mzt.logserver.function;

import com.mzt.logapi.service.IParseFunction;
import com.mzt.logserver.beans.Order;
import com.mzt.logserver.pojo.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
Expand Down
Loading

0 comments on commit 37a12a1

Please sign in to comment.