1
This commit is contained in:
151
operation-log-aspect-starter/operation-log-aspect-starter.iml
Normal file
151
operation-log-aspect-starter/operation-log-aspect-starter.iml
Normal file
@ -0,0 +1,151 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="Spring" name="Spring">
|
||||
<configuration />
|
||||
</facet>
|
||||
<facet type="web" name="Web">
|
||||
<configuration>
|
||||
<webroots />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-openfeign-core:2.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.3.2.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.3.2.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.2.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-netflix-ribbon:2.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-netflix-archaius:2.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.github.openfeign.form:feign-form-spring:3.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.github.openfeign.form:feign-form:3.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.1.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-fileupload:commons-fileupload:1.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-io:commons-io:2.2" level="project" />
|
||||
<orderEntry type="module" module-name="common-base-starter" />
|
||||
<orderEntry type="library" name="Maven: org.apache.velocity:velocity-engine-core:2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger2:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.5.14" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.swagger:swagger-models:1.5.14" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-spi:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-core:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.7.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-schema:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-common:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-spring-web:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.11" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mapstruct:mapstruct:1.2.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-ui:2.8.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.caspar-chen:swagger-ui-layer:1.1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.3.2.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.3.2.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.3.2.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.37" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.glassfish:jakarta.el:3.0.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.37" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.2.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.2.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.7.20" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.belerweb:pinyin4j:2.5.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.83" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.12.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:guava:29.0-jre" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:2.11.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.3.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba:transmittable-thread-local:2.11.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:4.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: jakarta.validation:jakarta.validation-api:2.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-boot-starter:3.4.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus:3.4.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.4.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.3.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.3.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-extension:3.4.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-core:3.4.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-annotation:3.4.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.5.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:2.0.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:4.1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:4.1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.19" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.poi:poi:4.1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.zaxxer:SparseBitSet:1.2" level="project" />
|
||||
<orderEntry type="module" module-name="common-redis-starter" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:2.3.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.3.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-keyvalue:2.3.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.3.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-oxm:5.2.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.2.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.lettuce:lettuce-core:5.3.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.49.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.49.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.49.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.49.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.49.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.49.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.3.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:2.3.2.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.3.2.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.3.2.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.13.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.13.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.30" level="project" />
|
||||
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.2.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.2.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.2.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.2.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.9.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.github.openfeign:feign-hystrix:10.10.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.github.openfeign:feign-core:10.10.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.netflix.archaius:archaius-core:0.7.6" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: commons-configuration:commons-configuration:1.8" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: commons-lang:commons-lang:2.6" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.4.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.4.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.4.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.netflix.hystrix:hystrix-core:1.5.18" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.reactivex:rxjava:1.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hdrhistogram:HdrHistogram:2.1.9" level="project" />
|
||||
<orderEntry type="module" module-name="common-token-starter" />
|
||||
<orderEntry type="library" name="Maven: com.auth0:java-jwt:3.8.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.vividsolutions:jts:1.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.netflix.feign:feign-slf4j:8.14.4" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.netflix.feign:feign-core:8.14.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" />
|
||||
</component>
|
||||
</module>
|
95
operation-log-aspect-starter/pom.xml
Normal file
95
operation-log-aspect-starter/pom.xml
Normal file
@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.mosty</groupId>
|
||||
<artifactId>mosty-common</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>operation-log-aspect-starter</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<!-- <spring-cloud-dependencies.version>Hoxton.SR8</spring-cloud-dependencies.version>-->
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mosty</groupId>
|
||||
<artifactId>common-base-starter</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
<version>${spring-boot-dependencies.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||
<version>2.2.5.RELEASE</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-hystrix</artifactId>
|
||||
<version>10.10.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mosty</groupId>
|
||||
<artifactId>common-token-starter</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.feign</groupId>
|
||||
<artifactId>feign-slf4j</artifactId>
|
||||
<version>8.14.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.kafka</groupId>-->
|
||||
<!-- <artifactId>kafka-clients</artifactId>-->
|
||||
<!-- <version>2.6.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.kafka</groupId>-->
|
||||
<!-- <artifactId>spring-kafka</artifactId>-->
|
||||
<!-- <version>2.6.6</version>-->
|
||||
<!-- <scope>compile</scope>-->
|
||||
<!-- </dependency>-->
|
||||
</dependencies>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>mosty-nexus-releases</id>
|
||||
<name>release version</name>
|
||||
<url>http://47.108.232.77:8181/repository/maven-releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>mosty-nexus-snapshots</id>
|
||||
<name>snapshots version</name>
|
||||
<url>http://47.108.232.77:8181/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,204 @@
|
||||
package com.mosty.operation.log.aspect;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.support.spring.PropertyPreFilters;
|
||||
import com.mosty.common.base.entity.log.Log;
|
||||
import com.mosty.common.base.entity.log.SysOperLog;
|
||||
import com.mosty.common.base.exception.BusinessStatus;
|
||||
import com.mosty.common.base.threadpool.SimpleThreadPool;
|
||||
import com.mosty.common.base.util.IpUtil;
|
||||
import com.mosty.common.base.util.ServletUtils;
|
||||
import com.mosty.common.base.util.SpringIocContext;
|
||||
import com.mosty.common.base.util.StringUtils;
|
||||
import com.mosty.common.token.JWTUtil;
|
||||
import com.mosty.common.token.UserInfo;
|
||||
import com.mosty.operation.log.aspect.feign.OperationLogClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.mosty.common.base.constant.SystemConfigConstants.TOKEN_HEADER;
|
||||
import static com.mosty.common.base.entity.log.LogConst.LOG_THREAD_POOL;
|
||||
|
||||
|
||||
/**
|
||||
* 操作日志记录处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class LogAspect {
|
||||
|
||||
@Autowired
|
||||
private OperationLogClient operationLogClient;
|
||||
|
||||
// 排除敏感属性字段
|
||||
public static final String[] EXCLUDE_PROPERTIES = {"password", "oldPassword", "newPassword", "confirmPassword","zb"};
|
||||
|
||||
// 配置织入点
|
||||
@Pointcut("@annotation(com.mosty.common.base.entity.log.Log)")
|
||||
public void logPointCut() {
|
||||
}
|
||||
|
||||
// 处理完请求后执行
|
||||
@AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult")
|
||||
public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) {
|
||||
handleLog(joinPoint, controllerLog, null, jsonResult);
|
||||
}
|
||||
|
||||
// 拦截异常操作
|
||||
@AfterThrowing(value = "@annotation(controllerLog)", throwing = "e")
|
||||
public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e) {
|
||||
handleLog(joinPoint, controllerLog, e, null);
|
||||
}
|
||||
|
||||
protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) {
|
||||
try {
|
||||
|
||||
String token = ServletUtils.getRequest().getHeader(TOKEN_HEADER);
|
||||
// 获取当前的用户 从header中获取
|
||||
UserInfo userInfo = JWTUtil.getUserInfo(token);
|
||||
String ipAddress = IpUtil.getIpAddress(ServletUtils.getRequest());
|
||||
// *========数据库日志=========*//
|
||||
SysOperLog operLog = new SysOperLog();
|
||||
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
||||
// 请求的地址
|
||||
operLog.setOperIp(ipAddress);
|
||||
String url = ServletUtils.getRequest().getRequestURI();
|
||||
operLog.setOperUrl(url);
|
||||
// 添加服务名称
|
||||
if (url != null && url.length() >= 11) {
|
||||
String[] s = url.split("/");
|
||||
if (s.length >= 2 && s[1].contains("mosty-")) {
|
||||
operLog.setMkmc(s[1]);
|
||||
}
|
||||
}
|
||||
if (userInfo != null) {
|
||||
operLog.setOperName(userInfo.getUserLoginName());
|
||||
operLog.setOperUserId(String.valueOf(userInfo.getUserId()));
|
||||
operLog.setOperSfzh(userInfo.getIdEntityCard());
|
||||
if (StringUtils.isNotNull(userInfo.getDeptId())
|
||||
&& StringUtils.isNotEmpty(userInfo.getDeptName())) {
|
||||
operLog.setSsbm(userInfo.getDeptName());
|
||||
operLog.setSsbmid(String.valueOf(userInfo.getDeptId()));
|
||||
operLog.setSsbmdm(userInfo.getDeptCode());
|
||||
}
|
||||
}
|
||||
if (e != null) {
|
||||
operLog.setStatus(BusinessStatus.FAIL.ordinal());
|
||||
operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
|
||||
}
|
||||
// 设置方法名称
|
||||
String className = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
operLog.setMethod(className + "." + methodName + "()");
|
||||
// 设置请求方式
|
||||
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
||||
// 处理设置注解上的参数
|
||||
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
||||
|
||||
SimpleThreadPool.execute(LOG_THREAD_POOL, () -> {
|
||||
operationLogClient.addOperationLog(operLog);
|
||||
});
|
||||
} catch (Exception exp) {
|
||||
// 记录本地异常日志
|
||||
log.error("==前置通知异常==");
|
||||
log.error("异常信息:{}", exp.getMessage());
|
||||
exp.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 获取注解中对方法的描述信息 用于Controller层注解
|
||||
public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception {
|
||||
// 设置action动作
|
||||
operLog.setBusinessType(log.businessType().ordinal());
|
||||
// 设置标题
|
||||
operLog.setTitle(log.title());
|
||||
// 设置操作人类别
|
||||
operLog.setOperatorType(log.operatorType().ordinal());
|
||||
// 是否需要保存request,参数和值
|
||||
if (log.isSaveRequestData()) {
|
||||
// 获取参数的信息,传入到数据库中。
|
||||
setRequestValue(joinPoint, operLog);
|
||||
}
|
||||
// 是否需要保存response,参数和值
|
||||
if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) {
|
||||
operLog.setJsonResult(StringUtils.substring(JSONObject.toJSONString(jsonResult), 0, 2000));
|
||||
}
|
||||
}
|
||||
|
||||
// 获取请求的参数,放到log中
|
||||
private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception {
|
||||
Map<String, String[]> map = ServletUtils.getRequest().getParameterMap();
|
||||
if (StringUtils.isNotEmpty(map)) {
|
||||
String params = JSONObject.toJSONString(map, excludePropertyPreFilter());
|
||||
operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
||||
} else {
|
||||
Object args = joinPoint.getArgs();
|
||||
if (StringUtils.isNotNull(args)) {
|
||||
String params = argsArrayToString(joinPoint.getArgs());
|
||||
operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 忽略敏感属性
|
||||
public PropertyPreFilters.MySimplePropertyPreFilter excludePropertyPreFilter() {
|
||||
return new PropertyPreFilters().addFilter().addExcludes(EXCLUDE_PROPERTIES);
|
||||
}
|
||||
|
||||
// 参数拼装
|
||||
private String argsArrayToString(Object[] paramsArray) {
|
||||
StringBuilder params = new StringBuilder();
|
||||
if (paramsArray != null && paramsArray.length > 0) {
|
||||
for (Object o : paramsArray) {
|
||||
if (StringUtils.isNotNull(o) && !isFilterObject(o)) {
|
||||
try {
|
||||
Object jsonObj = JSONObject.toJSONString(o, excludePropertyPreFilter());
|
||||
params.append(jsonObj.toString()).append(" ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return params.toString().trim();
|
||||
}
|
||||
|
||||
// 判断是否需要过滤的对象
|
||||
@SuppressWarnings("rawtypes")
|
||||
public boolean isFilterObject(final Object o) {
|
||||
Class<?> clazz = o.getClass();
|
||||
if (clazz.isArray()) {
|
||||
return clazz.getComponentType().isAssignableFrom(MultipartFile.class);
|
||||
} else if (Collection.class.isAssignableFrom(clazz)) {
|
||||
Collection collection = (Collection) o;
|
||||
for (Object value : collection) {
|
||||
return value instanceof MultipartFile;
|
||||
}
|
||||
} else if (Map.class.isAssignableFrom(clazz)) {
|
||||
Map map = (Map) o;
|
||||
for (Object value : map.entrySet()) {
|
||||
Map.Entry entry = (Map.Entry) value;
|
||||
return entry.getValue() instanceof MultipartFile;
|
||||
}
|
||||
}
|
||||
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
||||
|| o instanceof BindingResult;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.mosty.operation.log.aspect;
|
||||
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* feign其他 微服务操作日志处理 启动器
|
||||
* @author kevin
|
||||
* @date 2022/6/7 5:01 下午
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Configuration
|
||||
@EnableFeignClients(basePackages = "com.mosty.operation.log.aspect")
|
||||
@ComponentScan(basePackages = "com.mosty.operation.log.aspect")
|
||||
public class OperationLogAspectAutoConfiguration {
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.mosty.operation.log.aspect.feign;
|
||||
|
||||
import com.mosty.common.base.domain.ResponseResult;
|
||||
import com.mosty.common.base.entity.log.SysOperLog;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* 添加操作日志
|
||||
* @author kevin
|
||||
* @date 2022/3/8 8:37 PM
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@FeignClient(value = "mosty-base", fallbackFactory = OperationLogFallbackFactory.class,
|
||||
contextId = "com.mosty.operation.log.aspect.feign.OperationLogClient")
|
||||
public interface OperationLogClient {
|
||||
|
||||
// 保存操作日志
|
||||
@PostMapping(value = "/mosty-base/provider/monitor/operateLog/save")
|
||||
ResponseResult<Boolean> addOperationLog(@RequestBody SysOperLog sysOperLog);
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.mosty.operation.log.aspect.feign;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.mosty.common.base.domain.ResponseResult;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 操作日志feign客户端
|
||||
* @author kevin
|
||||
* @date 2022/2/4 8:38 PM
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class OperationLogFallbackFactory implements FallbackFactory<OperationLogClient> {
|
||||
|
||||
@Override
|
||||
public OperationLogClient create(Throwable throwable) {
|
||||
log.error("fallback", throwable);
|
||||
return sysOperLog -> {
|
||||
log.error("参数:sysOperLog:{}", JSON.toJSONString(sysOperLog));
|
||||
return ResponseResult.fail(null);
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.mosty.operation.log.aspect.kafka;
|
||||
|
||||
//import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
//import org.apache.kafka.common.serialization.StringSerializer;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.kafka.core.DefaultKafkaProducerFactory;
|
||||
//import org.springframework.kafka.core.KafkaTemplate;
|
||||
//import org.springframework.kafka.core.ProducerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
//@Configuration
|
||||
public class KafkaProducerConfig {
|
||||
// @Value("${spring.kafka.bootstrap-servers}")
|
||||
// private String servers;
|
||||
// @Value("${spring.kafka.producer.retries}")
|
||||
// private int retries;
|
||||
// @Value("${spring.kafka.producer.acks}")
|
||||
// private String acks;
|
||||
// @Value("${spring.kafka.producer.batch-size}")
|
||||
// private int batchSize;
|
||||
// @Value("${spring.kafka.producer.properties.linger.ms}")
|
||||
// private int linger;
|
||||
// @Value("${spring.kafka.producer.buffer-memory}")
|
||||
// private int bufferMemory;
|
||||
//
|
||||
// public Map<String, Object> producerConfigs() {
|
||||
// Map<String, Object> props = new HashMap<>();
|
||||
// props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, servers);
|
||||
// props.put(ProducerConfig.RETRIES_CONFIG, retries);
|
||||
// props.put(ProducerConfig.ACKS_CONFIG, acks);
|
||||
// props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
|
||||
// props.put(ProducerConfig.LINGER_MS_CONFIG, linger);
|
||||
// props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
|
||||
// props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
|
||||
// props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
|
||||
// return props;
|
||||
// }
|
||||
//
|
||||
// public ProducerFactory<String, Object> producerFactory() {
|
||||
// return new DefaultKafkaProducerFactory<>(producerConfigs());
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public KafkaTemplate<String, Object> kafkaTemplate() {
|
||||
// KafkaTemplate template = new KafkaTemplate<String, Object>(producerFactory());
|
||||
// template.setDefaultTopic("platform-log"); // 设置默认的 topic
|
||||
// return template;
|
||||
// }
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.mosty.operation.log.aspect.OperationLogAspectAutoConfiguration
|
@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.mosty.operation.log.aspect.OperationLogAspectAutoConfiguration
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Thu Apr 18 12:45:12 CST 2024
|
||||
version=1.0.0-SNAPSHOT
|
||||
groupId=com.mosty
|
||||
artifactId=operation-log-aspect-starter
|
@ -0,0 +1,5 @@
|
||||
com\mosty\operation\log\aspect\feign\OperationLogFallbackFactory.class
|
||||
com\mosty\operation\log\aspect\feign\OperationLogClient.class
|
||||
com\mosty\operation\log\aspect\kafka\KafkaProducerConfig.class
|
||||
com\mosty\operation\log\aspect\LogAspect.class
|
||||
com\mosty\operation\log\aspect\OperationLogAspectAutoConfiguration.class
|
@ -0,0 +1,5 @@
|
||||
C:\tools\dy外网\mosty-common\operation-log-aspect-starter\src\main\java\com\mosty\operation\log\aspect\kafka\KafkaProducerConfig.java
|
||||
C:\tools\dy外网\mosty-common\operation-log-aspect-starter\src\main\java\com\mosty\operation\log\aspect\LogAspect.java
|
||||
C:\tools\dy外网\mosty-common\operation-log-aspect-starter\src\main\java\com\mosty\operation\log\aspect\OperationLogAspectAutoConfiguration.java
|
||||
C:\tools\dy外网\mosty-common\operation-log-aspect-starter\src\main\java\com\mosty\operation\log\aspect\feign\OperationLogFallbackFactory.java
|
||||
C:\tools\dy外网\mosty-common\operation-log-aspect-starter\src\main\java\com\mosty\operation\log\aspect\feign\OperationLogClient.java
|
Binary file not shown.
Reference in New Issue
Block a user