Pārlūkot izejas kodu

update mq topic

deason 1 mēnesi atpakaļ
vecāks
revīzija
0a87a2c00e

+ 2 - 2
examcloud-support/src/main/java/cn/com/qmth/examcloud/reports/commons/bean/AdminOperateReport.java

@@ -19,8 +19,8 @@ public class AdminOperateReport extends BaseReport {
         this.operateUserId = operateUserId;
         this.operate = operate;
         this.operateInfo = operateInfo;
-        this.topic = ReportsUtil.getReportTopic();
-        this.tag = Tag.ADMIN_OPERATE_INFO.getCode();
+        this.topic = ReportsUtil.curTopic(Tag.ADMIN_OPERATE_INFO);
+        this.tag = Tag.ADMIN_OPERATE_INFO.name();
     }
 
     public AdminOperateReport() {

+ 2 - 2
examcloud-support/src/main/java/cn/com/qmth/examcloud/reports/commons/bean/OnlineExamStudentReport.java

@@ -55,8 +55,8 @@ public class OnlineExamStudentReport extends BaseReport {
         this.studentId = studentId;
         this.examId = examId;
         this.examStudentId = examStudentId;
-        this.topic = ReportsUtil.getReportTopic();
-        this.tag = Tag.ONLINE_EXAM_STUDENT.getCode();
+        this.topic = ReportsUtil.curTopic(Tag.ONLINE_EXAM_STUDENT);
+        this.tag = Tag.ONLINE_EXAM_STUDENT.name();
     }
 
 }

+ 2 - 2
examcloud-support/src/main/java/cn/com/qmth/examcloud/reports/commons/bean/OnlineStudentReport.java

@@ -33,8 +33,8 @@ public class OnlineStudentReport extends BaseReport {
         super();
         this.rootOrgId = rootOrgId;
         this.studentId = studentId;
-        this.topic = ReportsUtil.getReportTopic();
-        this.tag = Tag.ONLINE_STUDENT.getCode();
+        this.topic = ReportsUtil.curTopic(Tag.ONLINE_STUDENT);
+        this.tag = Tag.ONLINE_STUDENT.name();
     }
 
 }

+ 2 - 2
examcloud-support/src/main/java/cn/com/qmth/examcloud/reports/commons/bean/OnlineUserReport.java

@@ -33,8 +33,8 @@ public class OnlineUserReport extends BaseReport {
         super();
         this.rootOrgId = rootOrgId;
         this.userId = userId;
-        this.topic = ReportsUtil.getReportTopic();
-        this.tag = Tag.ONLINE_USER.getCode();
+        this.topic = ReportsUtil.curTopic(Tag.ONLINE_USER);
+        this.tag = Tag.ONLINE_USER.name();
     }
 
 }

+ 2 - 2
examcloud-support/src/main/java/cn/com/qmth/examcloud/reports/commons/bean/OperateReport.java

@@ -27,8 +27,8 @@ public class OperateReport extends BaseReport {
         this.examStudentId = examStudentId;
         this.operateUserType = operateClient;
         this.operate = operate;
-        this.topic = ReportsUtil.getReportTopic();
-        this.tag = Tag.OPERATE_INFO.getCode();
+        this.topic = ReportsUtil.curTopic(Tag.OPERATE_INFO);
+        this.tag = Tag.OPERATE_INFO.name();
     }
 
     public OperateReport() {

+ 11 - 51
examcloud-support/src/main/java/cn/com/qmth/examcloud/reports/commons/enums/Tag.java

@@ -3,73 +3,33 @@ package cn.com.qmth.examcloud.reports.commons.enums;
 public enum Tag {
 
     /**
-     * 学生
+     * 在线学生
      */
-    ONLINE_STUDENT("ONLINE_STUDENT", "examcloud_consumer_online_student", "学生"),
+    ONLINE_STUDENT,
 
     /**
-     * 考生
+     * 在线考生
      */
-    ONLINE_EXAM_STUDENT("ONLINE_EXAM_STUDENT", "examcloud_consumer_online_exam_student", "考生"),
+    ONLINE_EXAM_STUDENT,
 
     /**
-     * 后台用户
+     * 在线用户
      */
-    ONLINE_USER("ONLINE_USER", "examcloud_consumer_online_user", "后台用户"),
+    ONLINE_USER,
 
     /**
-     * 操作日志
+     * 学生相关操作日志
      */
-    OPERATE_INFO("OPERATE_INFO", "examcloud_consumer_operate_info", "操作日志"),
+    OPERATE_INFO,
 
     /**
      * 考试过程记录
      */
-    EXAM_PROCESS_RECORD("EXAM_PROCESS_RECORD", "examcloud_consumer_exam_process_record", "考试过程记录"),
+    EXAM_PROCESS_RECORD,
 
     /**
-     * 后台用户操作日志
+     * 管理端-用户相关操作日志
      */
-    ADMIN_OPERATE_INFO("ADMIN_OPERATE_INFO", "examcloud_consumer_admin_operate_info", "后台用户操作日志");
-
-    // ===========================================================================
-
-    /**
-     * 码
-     */
-    private String code;
-
-    /**
-     * 描述
-     */
-    private String group;
-
-    /**
-     * 描述
-     */
-    private String desc;
-
-    /**
-     * 构造函数
-     *
-     * @param desc
-     */
-    private Tag(String code, String group, String desc) {
-        this.code = code;
-        this.group = group;
-        this.desc = desc;
-    }
-
-    public String getDesc() {
-        return desc;
-    }
-
-    public String getCode() {
-        return code;
-    }
-
-    public String getGroup() {
-        return group;
-    }
+    ADMIN_OPERATE_INFO;
 
 }

+ 24 - 15
examcloud-support/src/main/java/cn/com/qmth/examcloud/reports/commons/util/ReportsUtil.java

@@ -1,15 +1,14 @@
 package cn.com.qmth.examcloud.reports.commons.util;
 
-import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.util.ThreadLocalUtil;
 import cn.com.qmth.examcloud.reports.commons.bean.BaseReport;
+import cn.com.qmth.examcloud.reports.commons.enums.Tag;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.support.IpUtil;
 import cn.com.qmth.examcloud.web.support.ServletUtil;
 import com.alibaba.fastjson.JSON;
 import com.aliyun.openservices.ons.api.*;
 import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -24,7 +23,13 @@ public class ReportsUtil {
 
     private static final Logger LOG = LoggerFactory.getLogger(ReportsUtil.class);
 
-    private static final String KEY = "mq-report-data";
+    private static final String GROUP_PRODUCER_PREFIX = "ec_producer_";
+
+    private static final String GROUP_CONSUMER_PREFIX = "ec_consumer_";
+
+    private static final String TOPIC_PREFIX = "ec_topic_";
+
+    private static final String DATA_KEY = "ec_mq_data";
 
     private static Producer producer;
 
@@ -43,7 +48,7 @@ public class ReportsUtil {
             properties.put(PropertyKeyConst.NAMESRV_ADDR, PropertyHolder.getString("examcloud.rocketmq.namesrv_addr"));
 
             // 生产组名称
-            properties.put(PropertyKeyConst.GROUP_ID, PropertyHolder.getString("examcloud.rocketmq.producer_group"));
+            properties.put(PropertyKeyConst.GROUP_ID, curProducerGroup());
 
             producer = ONSFactory.createProducer(properties);
             // 在发送消息前,必须调用 start 方法来启动 Producer,只需调用一次即可。
@@ -54,7 +59,7 @@ public class ReportsUtil {
 
     private static void sendReportRocket(Boolean onException) {
         @SuppressWarnings("unchecked")
-        List<BaseReport> list = (List<BaseReport>) ThreadLocalUtil.get(KEY);
+        List<BaseReport> list = (List<BaseReport>) ThreadLocalUtil.get(DATA_KEY);
         if (CollectionUtils.isNotEmpty(list)) {
             for (BaseReport b : list) {
                 if (!onException || (onException && b.getReportOnException())) {
@@ -79,7 +84,7 @@ public class ReportsUtil {
                     }
                 }
             }
-            ThreadLocalUtil.set(KEY, null);
+            ThreadLocalUtil.set(DATA_KEY, null);
         }
     }
 
@@ -90,10 +95,10 @@ public class ReportsUtil {
             }
             setReportCommonData(report);
             @SuppressWarnings("unchecked")
-            List<BaseReport> list = (List<BaseReport>) ThreadLocalUtil.get(KEY);
+            List<BaseReport> list = (List<BaseReport>) ThreadLocalUtil.get(DATA_KEY);
             if (list == null) {
                 list = new ArrayList<BaseReport>();
-                ThreadLocalUtil.set(KEY, list);
+                ThreadLocalUtil.set(DATA_KEY, list);
             }
             list.add(report);
         } catch (Exception e) {
@@ -119,15 +124,19 @@ public class ReportsUtil {
         report.setReportTime(new Date());
     }
 
-    public static String getReportTopic() {
-        String topic = PropertyHolder.getString("examcloud.rocketmq.topic");
-        if (StringUtils.isBlank(topic)) {
-            throw new StatusException("examcloud.rocketmq.topic 未配置");
-        }
-        return topic;
+    public static String curTopic(Tag tag) {
+        return TOPIC_PREFIX + tag.name().toLowerCase() + "_" + curProfile();
+    }
+
+    public static String curConsumerGroup(Tag tag) {
+        return GROUP_CONSUMER_PREFIX + tag.name().toLowerCase() + "_" + curProfile();
+    }
+
+    public static String curProducerGroup() {
+        return GROUP_PRODUCER_PREFIX + "_" + curProfile();
     }
 
-    public static String getProfile() {
+    public static String curProfile() {
         return PropertyHolder.getString("spring.profiles.active", "");
     }