Skip to content

Commit

Permalink
初始化
Browse files Browse the repository at this point in the history
  • Loading branch information
hangsman committed Jan 15, 2022
1 parent 88622bd commit b745ea1
Show file tree
Hide file tree
Showing 42 changed files with 2,250 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name-template: 'v$RESOLVED_VERSION 🌈'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '🚀 Features'
labels:
- 'feature'
- title: '🐛 Bug Fixes'
labels:
- 'bug'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
exclude-labels:
- 'skip changelog'
template: |
## What’s Changed
$CHANGES
55 changes: 55 additions & 0 deletions .github/workflows/deploy-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy Snapshot

on:
# 支持手动触发构建
workflow_dispatch:
release:
# 创建release的时候触发
types: [ published ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Java and Maven
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'zulu'
- name: Cache m2 package
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn test
deploy-snapshot:
needs: test
if: ${{ success() }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Java and Maven
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'zulu'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_SECRET }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Publish to Sonatype
run: mvn deploy -Dmaven.test.skip=true
env:
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSWORD }}
MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
14 changes: 14 additions & 0 deletions .github/workflows/release-changes-log-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release Changes Log Drafter

on:
push:
branches:
- master

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
26 changes: 26 additions & 0 deletions .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test Pull Request

on:
pull_request:
paths:
- '*/*/src/**'
- pom.xml

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Java and Maven
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'zulu'
- name: Cache m2 package
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn test
130 changes: 130 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Operation Log

> 参考 [mzt-biz-log](https://github.com/mouzt/mzt-biz-log) 实现的一款基于 spring aop 操作日志记录工具 支持自定义方法处理
<p align="center">
<img src="https://maven-badges.herokuapp.com/maven-central/cn.hangsman.operationlog/operation-log/badge.svg" />
<a target="_blank" href="https://github.com/hangsman/operation-log/blob/master/LICENSE">
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" />
</a>
<img src="https://img.shields.io/badge/JDK-1.8+-green" />
</p>

## 快速开始

### 添加依赖

```xml

<dependency>
<groupId>cn.hangsman.operationlog</groupId>
<artifactId>operation-log-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>
```

### 启用注解

```java

@SpringBootApplication
@EnableOperationLog
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
```

### 添加 @OperationLog 注解

```java

@Service
public class OrderServiceImpl implements OrderService {
@Override
@OperationLog(
category = "创建订单",
fail = "订单创建失败:{#_errorMsg}",
content = "创建了一个订单 订单id: {#order.orderID}"
)
public Order createOrder(Order order) {
return new Order();
}
}
```

## 其他用法

### 日志记录

实现 `OperationLogRecorder`

```java
public interface OperationLogRecorder {
void record(OperationLogBody body);
}
```

### 自定义方法

实现 `SpelFunction` 来创建一个spel表达式方法

```java

@Service
public class JsonSpelFunction implements SpelFunction {
@Override
public Object apply(Object value) {
return JsonUtil.toJson(value);
}

@Override
public String functionName() {
return "json";
}
}
```

在模板中通过 `$方法名称(变量)` 来使用

```java

@Service
public class OrderServiceImpl implements OrderService {
@Override
@OperationLog(
category = "创建订单",
fail = "订单创建失败:{#_errorMsg}",
content = "创建了一个订单 订单id: {#order.orderID}",
detail = "{$json(#_ret)}"
)
public Order createOrder(Order order) {
return new Order();
}
}
```

### 前置处理

格式为 `变量名={spel函数}`

之后在其他模板中可以使用 `#变量名` 获取函数返回值

```java

@Service
public class UserServiceImpl implements UserService {
@Override
@OperationLog(
before = {"oldName={$oldNameFun(#user.id)}"},
content = "将用户名从 {#oldName} 修改为 {#user.username}")
public User updateName(User user) {

}
}
```

## 支持

如果您喜欢该项目,请给项目点亮⭐️,感谢!
31 changes: 31 additions & 0 deletions operation-log-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>operation-log-parent</artifactId>
<groupId>cn.hangsman.operationlog</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>operation-log-spring-boot-autoconfigure</artifactId>
<version>1.0.0</version>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>cn.hangsman.operationlog</groupId>
<artifactId>operation-log-core</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cn.hangsman.operationlog.spring.boot.annotation;

import cn.hangsman.operationlog.spring.boot.autoconfigure.OperationLogAutoConfiguration;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.Import;

import java.lang.annotation.*;

/**
* Created by 2022/1/11 13:30
*
* @author hangsman
* @since 1.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import({OperationLogImportSelector.class, OperationLogAutoConfiguration.class})
public @interface EnableOperationLog {

AdviceMode mode() default AdviceMode.PROXY;

boolean proxyTargetClass() default false;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cn.hangsman.operationlog.spring.boot.annotation;

import cn.hangsman.operationlog.spring.boot.autoconfigure.OperationLogProxyConfiguration;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.AdviceModeImportSelector;
import org.springframework.context.annotation.AutoProxyRegistrar;

/**
* Created by 2022/1/11 15:38
*
* @author hangsman
* @since 1.0
*/
public class OperationLogImportSelector extends AdviceModeImportSelector<EnableOperationLog> {

@Override
protected String[] selectImports(AdviceMode adviceMode) {
switch (adviceMode) {
case PROXY:
return new String[]{AutoProxyRegistrar.class.getName(), OperationLogProxyConfiguration.class.getName()};
case ASPECTJ:
return new String[]{"cn.hangsman.operationlog.spring.boot.autoconfigure.OperationLogProxyAutoConfiguration"};
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cn.hangsman.operationlog.spring.boot.autoconfigure;

import cn.hangsman.operationlog.spel.SpelFunction;
import cn.hangsman.operationlog.spel.SpelFunctionExpressionParser;
import cn.hangsman.operationlog.spel.SpelFunctionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
* Created by 2022/1/15 14:26
*
* @author hangsman
* @since 1.0
*/
@Configuration(proxyBeanMethods = false)
public class OperationLogAutoConfiguration {

@Bean
SpelFunctionExpressionParser spelFunctionExpressionParser() {
return new SpelFunctionExpressionParser();
}

@Bean
public SpelFunctionFactory spelFunctionFactory(List<SpelFunction> parseFunctions) {
return new SpelFunctionFactory(parseFunctions);
}
}
Loading

0 comments on commit b745ea1

Please sign in to comment.