diff --git a/pom.xml b/pom.xml
index 52da86c7044089d0f39a4a3b6e26298a59caf8a5..094212f46db93c632e6ba941a62bb0736fc3f801 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,6 +49,7 @@
3.3.4
2.2.2.RELEASE
+ 1.8.7
3.4
2.4
@@ -81,6 +82,11 @@
import
pom
+
+ org.aspectj
+ aspectjweaver
+ ${aspectjweaver.version}
+
diff --git a/sdk/pom.xml b/sdk/pom.xml
index 17a78ba02e84151c61d16385ac168fa3d0c4ea7b..c1f4d052f8879881ef2a5b7191ce282965f5acd7 100644
--- a/sdk/pom.xml
+++ b/sdk/pom.xml
@@ -29,5 +29,9 @@
org.springframework.boot
spring-boot-autoconfigure
+
+ org.aspectj
+ aspectjweaver
+
\ No newline at end of file
diff --git a/sdk/src/main/java/cn/icanci/loopstack/bic/sdk/BicAutoConfiguration.java b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/BicAutoConfiguration.java
similarity index 30%
rename from sdk/src/main/java/cn/icanci/loopstack/bic/sdk/BicAutoConfiguration.java
rename to sdk/src/main/java/cn/icanci/loopstack/bic/burying/BicAutoConfiguration.java
index cefc3c1f03e7cdcf0cf79cf83387864e65309a69..ac08633b1b03ede4b9c2579f4105927153cf38b4 100644
--- a/sdk/src/main/java/cn/icanci/loopstack/bic/sdk/BicAutoConfiguration.java
+++ b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/BicAutoConfiguration.java
@@ -1,32 +1,52 @@
-package cn.icanci.loopstack.bic.sdk;
+package cn.icanci.loopstack.bic.burying;
+
+import javax.annotation.Resource;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
-import cn.icanci.loopstack.bic.sdk.properties.BicProperties;
+import cn.icanci.loopstack.bic.burying.burying.BuryingBuilder;
+import cn.icanci.loopstack.bic.burying.properties.BicProperties;
+import cn.icanci.loopstack.bic.burying.system.SystemConstant;
+import cn.icanci.loopstack.bic.burying.thread.BicDataCachePool;
+import cn.icanci.loopstack.bic.burying.thread.BicEscalationService;
+import cn.icanci.loopstack.bic.burying.thread.TriggerThread;
/**
* @author icanci
* @since 1.0 Created in 2023/08/19 12:02
*/
@Configuration
-@ComponentScan({ "cn.icanci.loopstack.bic.sdk" })
+@ComponentScan({ "cn.icanci.loopstack.bic.burying" })
@EnableConfigurationProperties(BicProperties.class)
@AutoConfigureBefore
public class BicAutoConfiguration implements CommandLineRunner {
- /** Spring 上下文 */
- private ApplicationContext context;
-
- public BicAutoConfiguration(ApplicationContext context) {
- this.context = context;
- }
+ @Resource
+ private BicProperties bicProperties;
+ @Resource
+ private BicEscalationService bicEscalationService;
@Override
public void run(String... args) throws Exception {
- // no op
+ // 对服务数据进行修正
+ fixBicProperties();
+ BuryingBuilder.setBicProperties(bicProperties);
+ BicDataCachePool.setBicProperties(bicProperties);
+ TriggerThread.setBicProperties(bicProperties, bicEscalationService);
+ }
+
+ private void fixBicProperties() {
+ long maxBatchSubmitTime = bicProperties.getMaxBatchSubmitTime();
+ if (maxBatchSubmitTime <= 0 || maxBatchSubmitTime > SystemConstant.MAX_BATCH_SUBMIT_TIME) {
+ bicProperties.setMaxBatchSubmitTime(SystemConstant.MAX_BATCH_SUBMIT_TIME);
+ }
+
+ long maxBatchSize = bicProperties.getMaxBatchSize();
+ if (maxBatchSize <= 0 || maxBatchSize > SystemConstant.MAX_BATCH_SIZE) {
+ bicProperties.setMaxBatchSize(SystemConstant.MAX_BATCH_SIZE);
+ }
}
}
diff --git a/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/BuryingBuilder.java b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/BuryingBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..4966e92d724bdc1ea8b960f7e07550e1581c03e5
--- /dev/null
+++ b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/BuryingBuilder.java
@@ -0,0 +1,57 @@
+package cn.icanci.loopstack.bic.burying.burying;
+
+import java.io.Serializable;
+
+import cn.icanci.loopstack.bic.burying.burying.aop.ThreadLocalUtils;
+import cn.icanci.loopstack.bic.burying.properties.BicProperties;
+import cn.icanci.loopstack.bic.burying.system.LoggerLevelEnum;
+
+/**
+ * @author icanci
+ * @since 1.0 Created in 2023/09/28 13:19
+ */
+public class BuryingBuilder implements Serializable {
+ private static BicProperties bicProperties;
+
+ public static void setBicProperties(BicProperties bicProperties) {
+ BuryingBuilder.bicProperties = bicProperties;
+ }
+
+ public static BuryingDTO debug(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
+ return common(traceId, businessNo, module, category, subCategory, ext, message, LoggerLevelEnum.DEBUG);
+ }
+
+ public static BuryingDTO info(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
+ return common(traceId, businessNo, module, category, subCategory, ext, message, LoggerLevelEnum.INFO);
+ }
+
+ public static BuryingDTO warning(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
+ return common(traceId, businessNo, module, category, subCategory, ext, message, LoggerLevelEnum.WARNING);
+ }
+
+ public static BuryingDTO error(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
+ return common(traceId, businessNo, module, category, subCategory, ext, message, LoggerLevelEnum.ERROR);
+ }
+
+ private static BuryingDTO common(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message,
+ LoggerLevelEnum loggerLevel) {
+
+ String useCase = ThreadLocalUtils.getUseCase();
+ String uk = ThreadLocalUtils.getUk();
+
+ BuryingDTO burying = new BuryingDTO();
+ burying.setSystemKey(bicProperties.getSystemKey());
+ burying.setTraceId(traceId);
+ burying.setBusinessNo(businessNo);
+ burying.setUseCase(useCase);
+ burying.setModule(module);
+ burying.setCategory(category);
+ burying.setSubCategory(subCategory);
+ burying.setExt(ext);
+ burying.setTime(System.currentTimeMillis());
+ burying.setMessage(message);
+ burying.setLoggerLevel(loggerLevel.name());
+ burying.setUniqueKey(uk);
+ return burying;
+ }
+}
diff --git a/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/BuryingDTO.java b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/BuryingDTO.java
new file mode 100644
index 0000000000000000000000000000000000000000..5ba072e9c9dc159070ce48fd2c8792049b4ba459
--- /dev/null
+++ b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/BuryingDTO.java
@@ -0,0 +1,131 @@
+package cn.icanci.loopstack.bic.burying.burying;
+
+import java.io.Serializable;
+
+/**
+ * @author icanci
+ * @since 1.0 Created in 2023/09/28 13:19
+ */
+public class BuryingDTO implements Serializable {
+ private static final long serialVersionUID = 1L;
+ /** TraceId */
+ private String traceId;
+ /** 业务标识 */
+ private String businessNo;
+ /** 系统应用唯一标识 */
+ private String systemKey;
+ /** 应用系统用例 */
+ private String useCase;
+ /** 模块 */
+ private String module;
+ /** 分类,用于区分同模块下不同的展示类型 */
+ private String category;
+ /** 子模块,用于区分同模块下不同的展示类型 */
+ private String subCategory;
+ /** 扩展属性 */
+ private String ext;
+ /** 时间 */
+ private long time;
+ /** 执行数据 */
+ private String message;
+ /** 日志等级 */
+ private String loggerLevel;
+ /** 数据的唯一标识 */
+ private String uniqueKey;
+
+ public String getTraceId() {
+ return traceId;
+ }
+
+ public void setTraceId(String traceId) {
+ this.traceId = traceId;
+ }
+
+ public String getBusinessNo() {
+ return businessNo;
+ }
+
+ public void setBusinessNo(String businessNo) {
+ this.businessNo = businessNo;
+ }
+
+ public String getSystemKey() {
+ return systemKey;
+ }
+
+ public void setSystemKey(String systemKey) {
+ this.systemKey = systemKey;
+ }
+
+ public String getUseCase() {
+ return useCase;
+ }
+
+ public void setUseCase(String useCase) {
+ this.useCase = useCase;
+ }
+
+ public String getModule() {
+ return module;
+ }
+
+ public void setModule(String module) {
+ this.module = module;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getSubCategory() {
+ return subCategory;
+ }
+
+ public void setSubCategory(String subCategory) {
+ this.subCategory = subCategory;
+ }
+
+ public String getExt() {
+ return ext;
+ }
+
+ public void setExt(String ext) {
+ this.ext = ext;
+ }
+
+ public long getTime() {
+ return time;
+ }
+
+ public void setTime(long time) {
+ this.time = time;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getLoggerLevel() {
+ return loggerLevel;
+ }
+
+ public void setLoggerLevel(String loggerLevel) {
+ this.loggerLevel = loggerLevel;
+ }
+
+ public String getUniqueKey() {
+ return uniqueKey;
+ }
+
+ public void setUniqueKey(String uniqueKey) {
+ this.uniqueKey = uniqueKey;
+ }
+}
diff --git a/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/BuryingHolder.java b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/BuryingHolder.java
new file mode 100644
index 0000000000000000000000000000000000000000..eb5f338645d5c80f41ed4c0dc5fe0c5ffdd90c6f
--- /dev/null
+++ b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/BuryingHolder.java
@@ -0,0 +1,34 @@
+package cn.icanci.loopstack.bic.burying.burying;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.StringJoiner;
+
+/**
+ * @author icanci
+ * @since 1.0 Created in 2023/08/19 18:20
+ */
+public class BuryingHolder implements Serializable {
+
+ private List buryingList;
+
+ public BuryingHolder() {
+ }
+
+ public BuryingHolder(List buryingList) {
+ this.buryingList = buryingList;
+ }
+
+ public List getBuryingList() {
+ return buryingList;
+ }
+
+ public void setBuryingList(List buryingList) {
+ this.buryingList = buryingList;
+ }
+
+ @Override
+ public String toString() {
+ return new StringJoiner(",").add("buryingList=" + buryingList).toString();
+ }
+}
diff --git a/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/LoggerBuryingUtils.java b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/LoggerBuryingUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..188f9403e5a3be31dfa94592f7fe30eaf57c3b08
--- /dev/null
+++ b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/LoggerBuryingUtils.java
@@ -0,0 +1,133 @@
+package cn.icanci.loopstack.bic.burying.burying;
+
+import cn.icanci.loopstack.bic.burying.thread.BicDataCachePool;
+
+/**
+ * @author icanci
+ * @since 1.0 Created in 2023/09/27 16:32
+ */
+@SuppressWarnings("unused")
+public class LoggerBuryingUtils {
+
+ private static final String EMPTY = "";
+
+ public static void debug(String traceId, String message) {
+ BuryingDTO burying = BuryingBuilder.info(traceId, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void debug(String traceId, String businessNo, String message) {
+ BuryingDTO burying = BuryingBuilder.info(traceId, businessNo, EMPTY, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void debug(String traceId, String businessNo, String module, String message) {
+ BuryingDTO burying = BuryingBuilder.debug(traceId, businessNo, module, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void debug(String traceId, String businessNo, String module, String category, String message) {
+ BuryingDTO burying = BuryingBuilder.debug(traceId, businessNo, module, category, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void debug(String traceId, String businessNo, String module, String category, String subCategory, String message) {
+ BuryingDTO burying = BuryingBuilder.debug(traceId, businessNo, module, category, subCategory, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void debug(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
+ BuryingDTO burying = BuryingBuilder.debug(traceId, businessNo, module, category, subCategory, ext, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void info(String traceId, String message) {
+ BuryingDTO burying = BuryingBuilder.info(traceId, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void info(String traceId, String businessNo, String message) {
+ BuryingDTO burying = BuryingBuilder.info(traceId, businessNo, EMPTY, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void info(String traceId, String businessNo, String module, String message) {
+ BuryingDTO burying = BuryingBuilder.info(traceId, businessNo, module, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void info(String traceId, String businessNo, String module, String category, String message) {
+ BuryingDTO burying = BuryingBuilder.info(traceId, businessNo, module, category, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void info(String traceId, String businessNo, String module, String category, String subCategory, String message) {
+ BuryingDTO burying = BuryingBuilder.info(traceId, businessNo, module, category, subCategory, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void info(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
+ BuryingDTO burying = BuryingBuilder.info(traceId, businessNo, module, category, subCategory, ext, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void warning(String traceId, String message) {
+ BuryingDTO burying = BuryingBuilder.warning(traceId, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void warning(String traceId, String businessNo, String message) {
+ BuryingDTO burying = BuryingBuilder.warning(traceId, businessNo, EMPTY, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void warning(String traceId, String businessNo, String module, String message) {
+ BuryingDTO burying = BuryingBuilder.warning(traceId, businessNo, module, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void warning(String traceId, String businessNo, String module, String category, String message) {
+ BuryingDTO burying = BuryingBuilder.warning(traceId, businessNo, module, category, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void warning(String traceId, String businessNo, String module, String category, String subCategory, String message) {
+ BuryingDTO burying = BuryingBuilder.warning(traceId, businessNo, module, category, subCategory, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void warning(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
+ BuryingDTO burying = BuryingBuilder.warning(traceId, businessNo, module, category, subCategory, ext, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void error(String traceId, String message) {
+ BuryingDTO burying = BuryingBuilder.error(traceId, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void error(String traceId, String businessNo, String message) {
+ BuryingDTO burying = BuryingBuilder.error(traceId, businessNo, EMPTY, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void error(String traceId, String businessNo, String module, String message) {
+ BuryingDTO burying = BuryingBuilder.error(traceId, businessNo, module, EMPTY, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void error(String traceId, String businessNo, String module, String category, String message) {
+ BuryingDTO burying = BuryingBuilder.error(traceId, businessNo, module, category, EMPTY, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void error(String traceId, String businessNo, String module, String category, String subCategory, String message) {
+ BuryingDTO burying = BuryingBuilder.error(traceId, businessNo, module, category, subCategory, EMPTY, message);
+ BicDataCachePool.add(burying);
+ }
+
+ public static void error(String traceId, String businessNo, String module, String category, String subCategory, String ext, String message) {
+ BuryingDTO burying = BuryingBuilder.error(traceId, businessNo, module, category, subCategory, ext, message);
+ BicDataCachePool.add(burying);
+ }
+}
diff --git a/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/aop/SysLog.java b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/aop/SysLog.java
new file mode 100644
index 0000000000000000000000000000000000000000..86db4d041037df85efd91e647c6726c58e33f642
--- /dev/null
+++ b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/aop/SysLog.java
@@ -0,0 +1,16 @@
+package cn.icanci.loopstack.bic.burying.burying.aop;
+
+import java.lang.annotation.*;
+
+/**
+ * 系统关键节点
+ *
+ * @author icanci
+ * @since 1.0 Created in 2023/09/27 15:12
+ */
+@Documented
+@Target({ ElementType.METHOD })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface SysLog {
+
+}
diff --git a/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/aop/SysLogAspect.java b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/aop/SysLogAspect.java
new file mode 100644
index 0000000000000000000000000000000000000000..9faa1762d4f1d7ea3f574af9fa655b1630c5c5df
--- /dev/null
+++ b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/aop/SysLogAspect.java
@@ -0,0 +1,29 @@
+package cn.icanci.loopstack.bic.burying.burying.aop;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author icanci
+ * @since 1.0 Created in 2023/09/27 16:17
+ */
+@Aspect
+@Service
+public class SysLogAspect {
+ @Around(value = "execution(* *(..)) && @annotation(sysLog))", argNames = "point,sysLog")
+ public Object round(final ProceedingJoinPoint point, SysLog sysLog) throws Throwable {
+ String clazz = ThreadLocalUtils.getClazz();
+ String method = ThreadLocalUtils.getMethod();
+ try {
+ ThreadLocalUtils.fillThreadContext(point);
+ return point.proceed();
+ } finally {
+ ThreadLocalUtils.removeThreadContext();
+ ThreadLocalUtils.setClazz(clazz);
+ ThreadLocalUtils.setMethod(method);
+ }
+ }
+
+}
diff --git a/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/aop/ThreadLocalUtils.java b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/aop/ThreadLocalUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..42af890682cd384bce8e78035cac9eaf9c9b61d6
--- /dev/null
+++ b/sdk/src/main/java/cn/icanci/loopstack/bic/burying/burying/aop/ThreadLocalUtils.java
@@ -0,0 +1,87 @@
+package cn.icanci.loopstack.bic.burying.burying.aop;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.reflect.MethodSignature;
+
+import lombok.val;
+
+/**
+ * @author icanci
+ * @since 1.0 Created in 2023/09/27 16:25
+ */
+public class ThreadLocalUtils {
+ private static final String UK_FORMAT = "%s#%s#%s";
+ private static final String USE_CASE_KEY = "$USE_CASE_KEY$";
+ private static final String CLASS_KEY = "$CLASS_KEY$";
+ private static final String METHOD_KEY = "$METHOD_KEY$";
+
+ private static final ThreadLocal