添加操作日志服务.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.orion.ops.framework.biz.operator.log.config;
|
||||
|
||||
import com.alibaba.fastjson.serializer.ValueFilter;
|
||||
import com.orion.ops.framework.biz.operator.log.core.aspect.OperatorLogAspect;
|
||||
import com.orion.ops.framework.biz.operator.log.core.config.OperatorLogConfig;
|
||||
import com.orion.ops.framework.biz.operator.log.core.service.OperatorLogFrameworkService;
|
||||
import com.orion.ops.framework.biz.operator.log.core.service.OperatorLogFrameworkServiceDelegate;
|
||||
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.AutoConfigureOrderConst;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
|
||||
@@ -12,6 +14,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 操作日志配置类
|
||||
*
|
||||
@@ -24,6 +28,9 @@ import org.springframework.context.annotation.Primary;
|
||||
@EnableConfigurationProperties(OperatorLogConfig.class)
|
||||
public class OrionOperatorLogAutoConfiguration {
|
||||
|
||||
@Resource
|
||||
private ValueFilter desensitizeValueFilter;
|
||||
|
||||
/**
|
||||
* 操作日志委托类
|
||||
*
|
||||
@@ -48,6 +55,8 @@ public class OrionOperatorLogAutoConfiguration {
|
||||
@ConditionalOnBean(OperatorLogFrameworkServiceDelegate.class)
|
||||
public OperatorLogAspect operatorLogAspect(OperatorLogConfig operatorLogConfig,
|
||||
OperatorLogFrameworkService service) {
|
||||
// 设置脱敏过滤器
|
||||
OperatorLogs.setDesensitizeValueFilter(desensitizeValueFilter);
|
||||
return new OperatorLogAspect(operatorLogConfig, service);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.serializer.ValueFilter;
|
||||
import com.orion.lang.define.thread.ExecutorBuilder;
|
||||
import com.orion.lang.define.wrapper.Ref;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.json.matcher.ReplacementFormatters;
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.ops.framework.biz.operator.log.core.config.OperatorLogConfig;
|
||||
import com.orion.ops.framework.biz.operator.log.core.enums.ReturnType;
|
||||
@@ -70,6 +71,8 @@ public class OperatorLogAspect {
|
||||
@Around("@annotation(o)")
|
||||
public Object around(ProceedingJoinPoint joinPoint, OperatorLog o) throws Throwable {
|
||||
long start = System.currentTimeMillis();
|
||||
// 先清空上下文
|
||||
OperatorLogs.clear();
|
||||
try {
|
||||
// 执行
|
||||
Object result = joinPoint.proceed();
|
||||
@@ -192,9 +195,8 @@ public class OperatorLogAspect {
|
||||
* @param extra extra
|
||||
*/
|
||||
private void fillExtra(OperatorLogModel model, Map<String, Object> extra) {
|
||||
// 脱敏
|
||||
if (extra != null) {
|
||||
model.setExtra(JSON.toJSONString(extra, desensitizeValueFilter));
|
||||
model.setExtra(JSON.toJSONString(extra));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +211,7 @@ public class OperatorLogAspect {
|
||||
OperatorType type = OperatorTypeHolder.get(o.value());
|
||||
model.setModule(type.getModule());
|
||||
model.setType(type.getType());
|
||||
model.setLogInfo(Strings.format(type.getTemplate(), extra));
|
||||
model.setLogInfo(ReplacementFormatters.format(type.getTemplate(), extra));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.orion.ops.framework.biz.operator.log.core.constant;
|
||||
|
||||
/**
|
||||
* 操作日志常量
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/10/10 19:00
|
||||
*/
|
||||
public interface OperatorLogKeys {
|
||||
|
||||
String ID = "id";
|
||||
|
||||
String ID_LIST = "idList";
|
||||
|
||||
String CODE = "code";
|
||||
|
||||
String NAME = "name";
|
||||
|
||||
String USERNAME = "username";
|
||||
|
||||
String TITLE = "title";
|
||||
|
||||
String VALUE = "value";
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.orion.ops.framework.biz.operator.log.core.uitls;
|
||||
|
||||
import com.orion.lang.utils.reflect.BeanMap;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.ValueFilter;
|
||||
import com.orion.ops.framework.biz.operator.log.core.constant.OperatorLogKeys;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -12,10 +14,12 @@ import java.util.Map;
|
||||
* @version 1.0.0
|
||||
* @since 2023/10/10 11:32
|
||||
*/
|
||||
public class OperatorLogs {
|
||||
public class OperatorLogs implements OperatorLogKeys {
|
||||
|
||||
private static final String UN_SAVE_FLAG = "__un__save__";
|
||||
|
||||
private static ValueFilter desensitizeValueFilter;
|
||||
|
||||
private static final ThreadLocal<Map<String, Object>> EXTRA_HOLDER = new ThreadLocal<>();
|
||||
|
||||
private OperatorLogs() {
|
||||
@@ -54,7 +58,7 @@ public class OperatorLogs {
|
||||
add((Map<String, ?>) obj);
|
||||
return;
|
||||
}
|
||||
initMap().putAll(BeanMap.create(obj));
|
||||
initMap().putAll(JSON.parseObject(JSON.toJSONString(obj, desensitizeValueFilter)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,4 +119,8 @@ public class OperatorLogs {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void setDesensitizeValueFilter(ValueFilter desensitizeValueFilter) {
|
||||
OperatorLogs.desensitizeValueFilter = desensitizeValueFilter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ public class DesensitizeJsonSerializer extends JsonSerializer<Object> implements
|
||||
return this;
|
||||
}
|
||||
return prov.findValueSerializer(property.getType(), property);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user