整理项目
parent
00de049698
commit
fefdadc58c
@ -1,6 +0,0 @@
|
||||
{
|
||||
"icu": "重症文件分段id",
|
||||
"sa": "手麻文件分段id",
|
||||
"examination": "检验报告文件分段id",
|
||||
"other": "其他文件分段id"
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<!--嘉时软件webservice响应模板-->
|
||||
<Response>
|
||||
<Result>
|
||||
<!--响应状态码 0代表成功 500 代表失败-->
|
||||
<Code>0</Code>
|
||||
<!--消息id 请求的 /Request/Msg/ID-->
|
||||
<MsgId>123456</MsgId>
|
||||
<!--成功消息 / 失败异常消息-->
|
||||
<Msg>成功!</Msg>
|
||||
</Result>
|
||||
</Response>
|
@ -1,10 +0,0 @@
|
||||
/.gradle
|
||||
/.idea
|
||||
classes/
|
||||
/.settings
|
||||
/build
|
||||
/.classpath
|
||||
/.project
|
||||
*.iml
|
||||
**/target
|
||||
|
@ -1,22 +0,0 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.docus</groupId>
|
||||
<artifactId>docus-bom</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>docus-starter-log</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,12 +0,0 @@
|
||||
package com.docus.log;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Import({EnableTrackGroupSelector.class})
|
||||
@Inherited
|
||||
public @interface EnableTrackGroup {
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.docus.log;
|
||||
|
||||
import com.docus.log.aspect.TrackGroupAspect;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class EnableTrackGroupConfiguration {
|
||||
|
||||
@Bean
|
||||
public TrackGroupAspect logTrackGroupAspect() {
|
||||
return new TrackGroupAspect();
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.docus.log;
|
||||
|
||||
import org.springframework.context.annotation.ImportSelector;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class EnableTrackGroupSelector implements ImportSelector {
|
||||
|
||||
@Override
|
||||
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
|
||||
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableTrackGroup.class.getName(), false));
|
||||
Assert.notNull(annotationAttributes, String.format(
|
||||
"@EnableTrackGroup is not present on importing class '%s' as expected",
|
||||
importingClassMetadata.getClassName()));
|
||||
return new String[]{EnableTrackGroupConfiguration.class.getName()};
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.docus.log;
|
||||
|
||||
public class EnableTrackGroupSettings {
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.docus.log.annotation;
|
||||
|
||||
import com.docus.log.processor.ITrackProcessor;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface LogTrackGroup {
|
||||
|
||||
String group();
|
||||
|
||||
String desc() default "";
|
||||
|
||||
String action();
|
||||
|
||||
Class<? extends ITrackProcessor> processor();
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.docus.log.annotation;
|
||||
|
||||
import com.docus.log.processor.ITrackProcessor;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface TrackGroup {
|
||||
|
||||
/**
|
||||
* 组概念
|
||||
*/
|
||||
String group() default "";
|
||||
|
||||
/**
|
||||
* 描述概念
|
||||
*/
|
||||
String desc() default "";
|
||||
|
||||
/**
|
||||
* 动作概念
|
||||
*/
|
||||
String action() default "";
|
||||
|
||||
/**
|
||||
* 初始化bean概念
|
||||
*/
|
||||
String[] beanNames() default {};
|
||||
|
||||
/**
|
||||
* 处理器概念
|
||||
*/
|
||||
Class<? extends ITrackProcessor> processor();
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package com.docus.log.aspect;
|
||||
|
||||
import com.docus.log.annotation.LogTrackGroup;
|
||||
import com.docus.log.annotation.TrackGroup;
|
||||
import com.docus.log.context.TrackContext;
|
||||
import com.docus.log.context.TrackHelper;
|
||||
import com.docus.log.processor.ITrackProcessor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author linruifeng
|
||||
*/
|
||||
@Aspect
|
||||
@Slf4j
|
||||
public class TrackGroupAspect {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
/**
|
||||
* 通用业务处理
|
||||
*/
|
||||
@Around("@annotation(trackGroup)")
|
||||
public Object execute(final ProceedingJoinPoint joinPoint, TrackGroup trackGroup) throws Throwable {
|
||||
log.info("=== AOP @TrackGroup 切面启动器监听处理事件开始 ===");
|
||||
TrackContext context = getContext(joinPoint, trackGroup);
|
||||
|
||||
ITrackProcessor processor = applicationContext.getAutowireCapableBeanFactory().createBean(trackGroup.processor());
|
||||
try {
|
||||
Object beforeResult = processor.beforeProcess(context);
|
||||
context.setBeforeResult(beforeResult);
|
||||
TrackContext.init(context.getParams());
|
||||
Object afterReturnResult = joinPoint.proceed();
|
||||
context.setAfterReturnResult(afterReturnResult);
|
||||
TrackHelper.setParams(context.getParams());
|
||||
return processor.process(context);
|
||||
} catch (Exception ex) {
|
||||
context.setError(true);
|
||||
context.setExMessageResult(ex.getMessage());
|
||||
return processor.process(context);
|
||||
} finally {
|
||||
processor.afterProcess(context);
|
||||
TrackContext.clear();
|
||||
log.info("=== AOP @TrackGroup 切面启动器监听处理事件结束 ===");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用日志处理
|
||||
*/
|
||||
@Around("@annotation(logTrackGroup)")
|
||||
public Object execute(final ProceedingJoinPoint joinPoint, LogTrackGroup logTrackGroup) throws Throwable {
|
||||
log.info("=== AOP @LogTrackGroup 切面启动器监听处理事件开始 ===");
|
||||
final Object result;
|
||||
TrackContext context = getContext(joinPoint, logTrackGroup);
|
||||
ITrackProcessor processor = applicationContext.getAutowireCapableBeanFactory().createBean(logTrackGroup.processor());
|
||||
try {
|
||||
result = joinPoint.proceed();
|
||||
context.setAfterReturnResult(result);
|
||||
processor.process(context);
|
||||
} catch (Exception ex) {
|
||||
context.setError(true);
|
||||
context.setExMessageResult(ex.getMessage());
|
||||
processor.process(context);
|
||||
throw new RuntimeException(ex.getMessage());
|
||||
}
|
||||
log.info("=== AOP @LogTrackGroup 切面启动器监听处理事件结束 ===");
|
||||
return result;
|
||||
}
|
||||
|
||||
private TrackContext getContext(final ProceedingJoinPoint joinPoint, TrackGroup logTrackGroup) {
|
||||
TrackContext context = new TrackContext();
|
||||
Signature signature = joinPoint.getSignature();
|
||||
context.setClassType(signature.getDeclaringType());
|
||||
context.setClassName(signature.getDeclaringTypeName());
|
||||
context.setMethodName(signature.getName());
|
||||
context.setArgs(joinPoint.getArgs());
|
||||
|
||||
context.setGroup(logTrackGroup.group());
|
||||
context.setDesc(logTrackGroup.desc());
|
||||
context.setAction(logTrackGroup.action());
|
||||
context.setBeanNames(logTrackGroup.beanNames());
|
||||
context.setProcessor(logTrackGroup.processor());
|
||||
context.setParams(new HashMap<>());
|
||||
return context;
|
||||
}
|
||||
|
||||
private TrackContext getContext(final ProceedingJoinPoint joinPoint, LogTrackGroup logTrackGroup) {
|
||||
TrackContext context = new TrackContext();
|
||||
Signature signature = joinPoint.getSignature();
|
||||
context.setClassType(signature.getDeclaringType());
|
||||
context.setClassName(signature.getDeclaringTypeName());
|
||||
context.setMethodName(signature.getName());
|
||||
context.setArgs(joinPoint.getArgs());
|
||||
|
||||
context.setGroup(logTrackGroup.group());
|
||||
context.setDesc(logTrackGroup.desc());
|
||||
context.setAction(logTrackGroup.action());
|
||||
context.setProcessor(logTrackGroup.processor());
|
||||
context.setParams(new HashMap<>());
|
||||
return context;
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.docus.log.context;
|
||||
|
||||
import com.docus.log.processor.ITrackProcessor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class TrackContext {
|
||||
private static final ThreadLocal<TrackContext> CONTEXT_HOLDER = new ThreadLocal<>();
|
||||
|
||||
private Class classType;
|
||||
private String className;
|
||||
private String methodName;
|
||||
private Object[] args;
|
||||
|
||||
private Object beforeResult;
|
||||
private Object afterReturnResult;
|
||||
private boolean error = false;
|
||||
private String exMessageResult;
|
||||
|
||||
private String group;
|
||||
private String desc;
|
||||
private String action;
|
||||
private String[] beanNames;
|
||||
private Class<? extends ITrackProcessor> processor;
|
||||
private Map<String, Object> params;
|
||||
|
||||
//初始化
|
||||
public static void init(Map<String, Object> params) {
|
||||
CONTEXT_HOLDER.remove();
|
||||
TrackContext context = new TrackContext();
|
||||
context.setParams(params);
|
||||
CONTEXT_HOLDER.set(context);
|
||||
}
|
||||
|
||||
public static TrackContext get() {
|
||||
return CONTEXT_HOLDER.get();
|
||||
}
|
||||
|
||||
//清除线程变量
|
||||
public static void clear() {
|
||||
CONTEXT_HOLDER.remove();
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package com.docus.log.context;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* helper for xxl-job
|
||||
*
|
||||
* @author xuxueli 2020-11-05
|
||||
*/
|
||||
public final class TrackHelper {
|
||||
|
||||
|
||||
// ---------------------- base info ----------------------
|
||||
|
||||
/**
|
||||
* current JobId
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Object getValue(String key) {
|
||||
TrackContext trackContext = TrackContext.get();
|
||||
if (trackContext == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trackContext.getParams().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* current JobParam
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, Object> getParams() {
|
||||
TrackContext trackContext = TrackContext.get();
|
||||
if (trackContext == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trackContext.getParams();
|
||||
}
|
||||
|
||||
public static void setParams(Map<String, Object> params) {
|
||||
TrackContext trackContext = TrackContext.get();
|
||||
if (trackContext == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
trackContext.getParams().putAll(params);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
TrackContext.clear();
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.docus.log.processor;
|
||||
|
||||
import com.docus.log.context.TrackContext;
|
||||
import com.docus.log.context.TrackHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class AbstractProcessor implements ITrackProcessor {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(AbstractProcessor.class);
|
||||
|
||||
public boolean validate(TrackContext context) {
|
||||
return context != null
|
||||
&& context.getGroup() != null
|
||||
&& context.getProcessor() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 前置通知
|
||||
*/
|
||||
@Override
|
||||
public Object beforeProcess(TrackContext context) {
|
||||
logger.info("=== AOP 前置通知 ===");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后置通知和异常通知
|
||||
*/
|
||||
@Override
|
||||
public Object process(TrackContext context) {
|
||||
if (validate(context)) {
|
||||
Object o = doProcess(context);
|
||||
TrackHelper.setParams(context.getParams());
|
||||
return o;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract Object doProcess(TrackContext context);
|
||||
|
||||
/**
|
||||
* 最后通知
|
||||
*/
|
||||
@Override
|
||||
public Object afterProcess(TrackContext context) {
|
||||
logger.info("=== AOP 最后通知 ===");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.docus.log.processor;
|
||||
|
||||
import com.docus.log.context.TrackContext;
|
||||
|
||||
public interface ITrackProcessor {
|
||||
|
||||
Object beforeProcess(TrackContext context);
|
||||
|
||||
Object process(TrackContext context);
|
||||
|
||||
Object afterProcess(TrackContext context);
|
||||
}
|
Loading…
Reference in New Issue