trackHelper
parent
da9c63579a
commit
3de81870cb
@ -0,0 +1,29 @@
|
||||
package com.docus.server.tool;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ProcessorContext {
|
||||
//线程变量,请求线程内有效
|
||||
private static final ThreadLocal<ProcessorContext> current = new ThreadLocal<>();
|
||||
private String jsonStr;
|
||||
|
||||
//初始化
|
||||
public static void init(String jsonStr) {
|
||||
current.remove();
|
||||
ProcessorContext context = new ProcessorContext();
|
||||
context.jsonStr = jsonStr;
|
||||
current.set(context);
|
||||
}
|
||||
|
||||
//获取当前现场request
|
||||
public static ProcessorContext get() {
|
||||
return current.get();
|
||||
}
|
||||
|
||||
//清除线程变量
|
||||
public static void clear() {
|
||||
current.remove();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
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();
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue