|
@@ -0,0 +1,49 @@
|
|
|
+package com.xy.consumer.log;
|
|
|
+
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.xy.config.SysThreadPoolConfig;
|
|
|
+import com.xy.consumer.MqttConsumer;
|
|
|
+import com.xy.entity.LogOperate;
|
|
|
+import com.xy.entity.LogSysEvents;
|
|
|
+import com.xy.entity.LogTasks;
|
|
|
+import com.xy.mapper.LogOperateMapper;
|
|
|
+import com.xy.mapper.LogSysEventsMapper;
|
|
|
+import com.xy.mapper.LogTasksMapper;
|
|
|
+import com.xy.utils.LambdaUtils;
|
|
|
+import com.xy.utils.ThreadPoolUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 日志消费者
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class LogConsumer implements MqttConsumer {
|
|
|
+
|
|
|
+ private final LogOperateMapper logOperateMapper;
|
|
|
+
|
|
|
+ private final LogSysEventsMapper logSysEventsMapper;
|
|
|
+
|
|
|
+ private final LogTasksMapper logTasksMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean message(String topic, String payload) {
|
|
|
+ ThreadPoolUtils.excPoll(SysThreadPoolConfig.LOG_POLL, 1)
|
|
|
+ .execute(() -> {
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(payload);
|
|
|
+ String type = jsonObject.getStr(LambdaUtils.getProperty(LogOperate::getType));
|
|
|
+ if ("operate".equals(type)) {
|
|
|
+ logOperateMapper.insert(jsonObject.toBean(LogOperate.class));
|
|
|
+ }
|
|
|
+ if ("events".equals(type)) {
|
|
|
+ logSysEventsMapper.insert(jsonObject.toBean(LogSysEvents.class));
|
|
|
+ }
|
|
|
+ if ("tasks".equals(type)) {
|
|
|
+ logTasksMapper.insert(jsonObject.toBean(LogTasks.class));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|