Browse Source

从主线程中获取集团编码传递给创建报告的子线程

lixing 2 years ago
parent
commit
5f457457ac

+ 6 - 0
README.md

@@ -0,0 +1,6 @@
+# v4.0.0
+- 标准产品v4.0.0发布
+# v4.0.1
+- 修复标准产品v4.0.0遗留问题
+# v4.1.0
+- 多租户改造

+ 3 - 0
src/main/java/com/persagy/apm/report/outline/service/builder/impl/ReportGenerator.java

@@ -12,6 +12,7 @@ import com.persagy.apm.report.outline.model.ReportOutline;
 import com.persagy.apm.report.outline.service.IReportOutlineService;
 import com.persagy.apm.report.outline.service.builder.IReportGenerator;
 import com.persagy.apm.report.paragraphs.service.IParagraphBuilder;
+import com.persagy.framework.tenant.mybatis.datasource.db.holder.SaasContext;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.aop.framework.AopContext;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,6 +47,8 @@ public class ReportGenerator implements IReportGenerator {
     @Override
 //    @Transactional(rollbackFor = Exception.class)
     public void generateReport(ReportOutline reportOutline) {
+        log.info("正在生成报告:{}", reportOutline.getId());
+        log.info("当前集团编码:{}", SaasContext.getContextGroupCode());
         // 删除之前生成的段落
         deleteReportParagraphs(reportOutline);
         // 生成新的报告详情

+ 5 - 0
src/main/java/com/persagy/apm/report/outline/service/impl/GenerateReportThreadPool.java

@@ -4,6 +4,7 @@ import cn.hutool.core.thread.ExecutorBuilder;
 import com.persagy.apm.common.context.poems.PoemsContext;
 import com.persagy.apm.report.outline.model.ReportOutline;
 import com.persagy.apm.report.outline.service.builder.IReportGenerator;
+import com.persagy.framework.tenant.mybatis.datasource.db.holder.SaasContext;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -61,9 +62,12 @@ public class GenerateReportThreadPool {
         String userId = PoemsContext.getContext().getUserId();
         String pd = PoemsContext.getContext().getPd();
         String loginDevice = PoemsContext.getContext().getLoginDevice();
+        String groupCode = SaasContext.getContextGroupCode();
         // 添加Future任务,过期时间为5分钟
         FutureTask<String> future = new FutureTask<>(() -> {
+            // 将主线程中的缓存手动传递给子线程
             PoemsContext.setContext(userId, loginDevice, pd);
+            SaasContext.setContextGroupCode(groupCode);
             synchronized (reportOutline.getId().intern()) {
                 reportGenerator.generateReport(reportOutline);
             }
@@ -76,6 +80,7 @@ public class GenerateReportThreadPool {
                 try {
                     future.get(maxGenerateMinutes, TimeUnit.MINUTES);
                 } catch (InterruptedException | ExecutionException | TimeoutException e) {
+                    SaasContext.setContextGroupCode(groupCode);
                     log.error("生成报告发生异常", e);
                     future.cancel(true);
                     reportGenerator.updateReportOutlineInfoWhenFailure(reportOutline);