|
|
@@ -0,0 +1,48 @@
|
|
|
+package com.cec.plugins.service.task;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.cec.plugins.domain.reported.SystemLogDto;
|
|
|
+import com.cec.plugins.enumerate.TaskEnum;
|
|
|
+import com.cec.plugins.service.RedisClientSource;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.boot.ApplicationArguments;
|
|
|
+import org.springframework.boot.ApplicationRunner;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author zhanghaijun
|
|
|
+ * @date 2023/11/28 23:00
|
|
|
+ * @description [一句话描述该类的功能]
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class LogService implements ApplicationRunner {
|
|
|
+
|
|
|
+ private final RedisClientSource redisClientSource;
|
|
|
+ private final ReportService reportService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(ApplicationArguments args) throws Exception {
|
|
|
+ log.info("订阅redis, key: {}", "LOGINFO");
|
|
|
+ redisClientSource.subscribe("LOGINFO", SystemLogDto.LogItem.class, logItem -> {
|
|
|
+ SystemLogDto dto = new SystemLogDto();
|
|
|
+ String taskId = redisClientSource.getCacheStr(TaskEnum.TaskId.getKey());
|
|
|
+ if (StrUtil.isBlank(taskId)) {
|
|
|
+ log.error("------系统日志上报,任务Id为空");
|
|
|
+ }
|
|
|
+ dto.setTaskId(StrUtil.firstNonBlank(taskId, ""));
|
|
|
+ if (StrUtil.isBlank(logItem.getRecordId())) {
|
|
|
+ logItem.setRecordId(IdUtil.fastSimpleUUID());
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(logItem.getRecordTime())) {
|
|
|
+ logItem.setRecordTime(DateUtil.now());
|
|
|
+ }
|
|
|
+ dto.addLog(logItem);
|
|
|
+ reportService.reportPlatform("/data/api/v1/systemLog", dto);
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|