修复activiti,新增日志上传
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,7 +5,7 @@
|
||||
## backend
|
||||
**/target
|
||||
**/logs
|
||||
**/log
|
||||
/log
|
||||
|
||||
## front
|
||||
**/*.lock
|
||||
|
||||
@@ -6,44 +6,69 @@ spring:
|
||||
database-schema-update: true
|
||||
history-level: full
|
||||
db-history-used: true
|
||||
# redis:
|
||||
# database: 0
|
||||
# host: 192.168.100.145
|
||||
# port: 6379
|
||||
# password: root
|
||||
# lettuce:
|
||||
# pool:
|
||||
# # 连接池中的最大空闲连接 默认8
|
||||
# max-idle: 8
|
||||
# # 连接池中的最小空闲连接 默认0
|
||||
# min-idle: 0
|
||||
# # 连接池最大连接数 默认8 ,负数表示没有限制
|
||||
# max-active: 8
|
||||
# # 连接池最大阻塞等待时间(使用负值表示没有限制) 默认-1
|
||||
# max-wait: -1
|
||||
# timeout: 30000
|
||||
redis:
|
||||
database: 0
|
||||
host: 192.168.4.119
|
||||
port: 6379
|
||||
password:
|
||||
lettuce:
|
||||
pool:
|
||||
# 连接池中的最大空闲连接 默认8
|
||||
max-idle: 8
|
||||
# 连接池中的最小空闲连接 默认0
|
||||
min-idle: 0
|
||||
# 连接池最大连接数 默认8 ,负数表示没有限制
|
||||
max-active: 8
|
||||
# 连接池最大阻塞等待时间(使用负值表示没有限制) 默认-1
|
||||
max-wait: -1
|
||||
timeout: 30000
|
||||
datasource:
|
||||
url: jdbc:mysql://192.168.4.119:3306/activiti7?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
|
||||
username: root
|
||||
password: root
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
initialization-mode: always
|
||||
initialSize: 5
|
||||
minIdle: 5
|
||||
maxActive: 20
|
||||
maxWait: 60000
|
||||
timeBetweenEvictionRunsMillis: 60000
|
||||
minEvictableIdleTimeMillis: 300000
|
||||
validationQuery: select 'x'
|
||||
testWhileIdle: true
|
||||
testOnBorrow: false
|
||||
testOnReturn: false
|
||||
poolPreparedStatements: true
|
||||
filters: stat,wall,slf4j
|
||||
maxPoolPreparedStatementPerConnectionSize: 20
|
||||
useGlobalDataSourceStat: true
|
||||
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
|
||||
# url: jdbc:mysql://192.168.4.119:3306/activiti7?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
|
||||
# username: root
|
||||
# password: root
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# type: com.alibaba.druid.pool.DruidDataSource
|
||||
# initialization-mode: always
|
||||
# initialSize: 5
|
||||
# minIdle: 5
|
||||
# maxActive: 20
|
||||
# maxWait: 60000
|
||||
# timeBetweenEvictionRunsMillis: 60000
|
||||
# minEvictableIdleTimeMillis: 300000
|
||||
# validationQuery: select 'x'
|
||||
# testWhileIdle: true
|
||||
# testOnBorrow: false
|
||||
# testOnReturn: false
|
||||
# poolPreparedStatements: true
|
||||
# filters: stat,wall,slf4j
|
||||
# maxPoolPreparedStatementPerConnectionSize: 20
|
||||
# useGlobalDataSourceStat: true
|
||||
# connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
|
||||
druid:
|
||||
# 配置sqlite文件路径,需要填写绝对路径,推荐将sqlite文件放入到服务器上,而非程序jar包或war包中
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://192.168.4.119:3306/activiti7?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
|
||||
username: root
|
||||
password: root
|
||||
#使用Druid数据源
|
||||
initialSize: 5
|
||||
# 初始化大小,最小,最大
|
||||
minIdle: 5
|
||||
maxActive: 20
|
||||
# 配置获取连接等待超时的时间
|
||||
maxWait: 60000
|
||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||
timeBetweenEvictionRunsMillis: 60000
|
||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||
minEvictableIdleTimeMillis: 300000
|
||||
validationQuery: select 1
|
||||
testWhileIdle: true
|
||||
testOnBorrow: false
|
||||
testOnReturn: false
|
||||
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
|
||||
filters: stat,slf4j
|
||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
mvc:
|
||||
view:
|
||||
prefix: /templates/
|
||||
@@ -58,11 +83,11 @@ logging:
|
||||
pattern:
|
||||
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(-%5p) %clr(${PID:- }){magenta} --- %clr([%15.15t]){faint} %highlight(%-80.80logger{300}){cyan} %clr(:) %m %n%wEx"
|
||||
server:
|
||||
port: 8080
|
||||
port: 8081
|
||||
servlet:
|
||||
context-path: /activiti
|
||||
# 是否开启redis 用户登录,若开启此项,需要配置redis节点及相关配置,若不开启,需要注释掉redis相关配置信息
|
||||
isRedisLogin: true
|
||||
isRedisLogin: false
|
||||
# 用户登陆超时设置,单位为小时,此值不能为0
|
||||
login-time-out: 4
|
||||
swagger:
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.hcframe.base.module.log;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.hcframe.base.common.config.FrameConfig;
|
||||
import com.hcframe.base.module.log.model.RequestErrorInfo;
|
||||
import com.hcframe.base.module.log.model.RequestInfo;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author lhc
|
||||
*/
|
||||
@Component
|
||||
@Aspect
|
||||
public class RequestLogAspect {
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(RequestLogAspect.class);
|
||||
|
||||
public RequestLogAspect(FrameConfig frameConfig) {
|
||||
this.frameConfig = frameConfig;
|
||||
}
|
||||
|
||||
@Pointcut("execution(public * com..*.controller..*(..))")
|
||||
public void requestServer() {
|
||||
}
|
||||
|
||||
final
|
||||
FrameConfig frameConfig;
|
||||
|
||||
@Around("requestServer()")
|
||||
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
Object result = proceedingJoinPoint.proceed();
|
||||
|
||||
if (frameConfig.getShowControllerLog()) {
|
||||
RequestInfo requestInfo = new RequestInfo();
|
||||
requestInfo.setIp(request.getRemoteAddr());
|
||||
requestInfo.setUrl(request.getRequestURL().toString());
|
||||
requestInfo.setHttpMethod(request.getMethod());
|
||||
requestInfo.setClassMethod(String.format("%s.%s", proceedingJoinPoint.getSignature().getDeclaringTypeName(),
|
||||
proceedingJoinPoint.getSignature().getName()));
|
||||
requestInfo.setRequestParams(getRequestParamsByProceedingJoinPoint(proceedingJoinPoint));
|
||||
requestInfo.setResult(result);
|
||||
requestInfo.setTimeCost(System.currentTimeMillis() - start);
|
||||
LOGGER.info("Request Info : {}", JSON.toJSONString(requestInfo));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@AfterThrowing(pointcut = "requestServer()", throwing = "e")
|
||||
public void doAfterThrow(JoinPoint joinPoint, RuntimeException e) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
RequestErrorInfo requestErrorInfo = new RequestErrorInfo();
|
||||
requestErrorInfo.setIp(request.getRemoteAddr());
|
||||
requestErrorInfo.setUrl(request.getRequestURL().toString());
|
||||
requestErrorInfo.setHttpMethod(request.getMethod());
|
||||
requestErrorInfo.setClassMethod(String.format("%s.%s", joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName()));
|
||||
requestErrorInfo.setRequestParams(getRequestParamsByJoinPoint(joinPoint));
|
||||
requestErrorInfo.setException(e);
|
||||
LOGGER.error("Error Request Info : {}", JSON.toJSONString(requestErrorInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取入参
|
||||
*
|
||||
* @param proceedingJoinPoint
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Object> getRequestParamsByProceedingJoinPoint(ProceedingJoinPoint proceedingJoinPoint) {
|
||||
//参数名
|
||||
String[] paramNames = ((MethodSignature) proceedingJoinPoint.getSignature()).getParameterNames();
|
||||
//参数值
|
||||
Object[] paramValues = proceedingJoinPoint.getArgs();
|
||||
return buildRequestParam(paramNames, paramValues);
|
||||
}
|
||||
|
||||
private Map<String, Object> getRequestParamsByJoinPoint(JoinPoint joinPoint) {
|
||||
//参数名
|
||||
String[] paramNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames();
|
||||
//参数值
|
||||
Object[] paramValues = joinPoint.getArgs();
|
||||
return buildRequestParam(paramNames, paramValues);
|
||||
}
|
||||
|
||||
private Map<String, Object> buildRequestParam(String[] paramNames, Object[] paramValues) {
|
||||
Map<String, Object> requestParams = new HashMap<>();
|
||||
for (int i = 0; i < paramNames.length; i++) {
|
||||
Object value = paramValues[i];
|
||||
if ((value instanceof HttpServletRequest) || (value instanceof HttpServletResponse)) {
|
||||
continue;
|
||||
}
|
||||
//如果是文件对象
|
||||
if (value instanceof MultipartFile) {
|
||||
MultipartFile file = (MultipartFile) value;
|
||||
// 获取文件名
|
||||
value = file.getOriginalFilename();
|
||||
}
|
||||
requestParams.put(paramNames[i], value);
|
||||
}
|
||||
return requestParams;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hcframe.base.module.log.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 日志注解
|
||||
*
|
||||
* @author lhc
|
||||
*/
|
||||
// 方法注解
|
||||
@Target(ElementType.METHOD)
|
||||
// 运行时可见
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface LogAnno {
|
||||
// 记录日志的操作类型
|
||||
String operateType();
|
||||
// 记录日志主键
|
||||
String primaryKey() default "id";
|
||||
// 记录日志表
|
||||
String tableName() default "-";
|
||||
|
||||
boolean isBefore() default false;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.hcframe.base.module.log.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lhc
|
||||
*/
|
||||
@Data
|
||||
public class RequestErrorInfo implements Serializable {
|
||||
private static final long serialVersionUID = 2671491007419047891L;
|
||||
private String ip;
|
||||
private String url;
|
||||
private String httpMethod;
|
||||
private String classMethod;
|
||||
private Object requestParams;
|
||||
private RuntimeException exception;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.hcframe.base.module.log.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* @author lhc
|
||||
*/
|
||||
@Data
|
||||
public class RequestInfo implements Serializable {
|
||||
private static final long serialVersionUID = 386274939008099288L;
|
||||
private String ip;
|
||||
private String url;
|
||||
private String httpMethod;
|
||||
private String classMethod;
|
||||
private Object requestParams;
|
||||
private Object result;
|
||||
private Long timeCost;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user