From fddef31d6774d74d8b1c8a2afb847675f9694734 Mon Sep 17 00:00:00 2001 From: loujf Date: Mon, 6 Jun 2022 09:49:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=97=A5=E5=BF=97=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/nl/modules/log/MongoDBAppender.java | 3 ++ .../modules/log/rest/RootLogController.java | 12 ++++-- .../modules/log/service/RootLogService.java | 8 ++++ .../log/service/impl/RootLogServiceImpl.java | 42 +++++++++++++++---- 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppender.java b/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppender.java index 6af3945..551035e 100644 --- a/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppender.java +++ b/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppender.java @@ -2,6 +2,7 @@ package org.nl.modules.log; import ch.qos.logback.classic.spi.ILoggingEvent; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import org.bson.Document; import org.slf4j.Marker; @@ -24,6 +25,8 @@ public class MongoDBAppender extends MongoDBAppenderBase { protected Document toMongoDocument(ILoggingEvent eventObject) { final Document doc = new Document(); + doc.append("_id", IdUtil.simpleUUID()); + doc.append("date", DateUtil.now()); doc.append("source", source); try { diff --git a/nladmin-system/src/main/java/org/nl/modules/log/rest/RootLogController.java b/nladmin-system/src/main/java/org/nl/modules/log/rest/RootLogController.java index 0ad0ee4..5757799 100644 --- a/nladmin-system/src/main/java/org/nl/modules/log/rest/RootLogController.java +++ b/nladmin-system/src/main/java/org/nl/modules/log/rest/RootLogController.java @@ -11,10 +11,7 @@ import org.nl.modules.log.service.RootLogService; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.Map; @@ -39,4 +36,11 @@ public class RootLogController { return new ResponseEntity<>(rootLogService.queryAll(whereJson, page), HttpStatus.OK); } + @PostMapping( "/error") + @Log("查询异常详情") + @ApiOperation("查询异常详情") + public ResponseEntity findError(@RequestBody Map whereJson) { + return new ResponseEntity<>(rootLogService.findError(whereJson), HttpStatus.OK); + } + } diff --git a/nladmin-system/src/main/java/org/nl/modules/log/service/RootLogService.java b/nladmin-system/src/main/java/org/nl/modules/log/service/RootLogService.java index b76d889..7363c97 100644 --- a/nladmin-system/src/main/java/org/nl/modules/log/service/RootLogService.java +++ b/nladmin-system/src/main/java/org/nl/modules/log/service/RootLogService.java @@ -15,4 +15,12 @@ public interface RootLogService { * @return Map */ Map queryAll(Map whereJson, Pageable page); + + /** + * 查询异常详情 + * + * @param whereJson + * @return Log + */ + String findError(Map whereJson); } diff --git a/nladmin-system/src/main/java/org/nl/modules/log/service/impl/RootLogServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/log/service/impl/RootLogServiceImpl.java index 3f15590..75ef79a 100644 --- a/nladmin-system/src/main/java/org/nl/modules/log/service/impl/RootLogServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/modules/log/service/impl/RootLogServiceImpl.java @@ -1,10 +1,12 @@ package org.nl.modules.log.service.impl; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.modules.log.service.RootLogService; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -26,23 +28,47 @@ public class RootLogServiceImpl implements RootLogService { private final MongoTemplate mongoTemplate; @Override - public Map queryAll(Map whereJson, Pageable page) { - //查询条件 - Query query = Query.query(Criteria.where("level").is("INFO")); + public Map queryAll(Map whereJson, Pageable page){ + String log_type = (String) whereJson.get("log_type"); + String log_level = (String) whereJson.get("log_level"); + String begin_time = (String) whereJson.get("begin_time"); + String end_time = (String) whereJson.get("end_time"); + + Query query = new Query().with(Sort.by("date")); + + if (StrUtil.isEmpty(log_type)) { + log_type = "default"; + } + if (StrUtil.isNotEmpty(log_level)){ + query.addCriteria(Criteria.where("level").is(log_level)); + } + if (StrUtil.isNotEmpty(begin_time) && StrUtil.isNotEmpty(end_time)) { + query.addCriteria(Criteria.where("date") + .gte(begin_time) + .lte(end_time)); + } //根据条件得到的总条数 - long totalSize = mongoTemplate.count(query, Map.class, "log_root"); + long totalSize = mongoTemplate.count(query, Map.class, log_type); //处理分页 query.skip(page.getPageNumber()).limit(page.getPageSize()); - List list = mongoTemplate.find(query, Map.class, "log_root"); - + List list = mongoTemplate.find(query,Map.class, log_type); //封装前端分页查询结果 JSONObject result = new JSONObject(); result.put("content", list); result.put("totalElements", totalSize); - - mongoTemplate.findById("",null,null); return result; } + + @Override + public String findError(Map map) { + String message = (String) map.get("message"); +// String marker = (String) map.get("marker"); +// Query query = Query.query(Criteria.where("_id").is(id)).with(Sort.by("date")); +// JSONObject list = mongoTemplate.findOne(query,JSONObject.class,marker); + +// return list.getString("message"); + return message; + } }