Browse Source

系统日志更新

master
loujf 3 years ago
parent
commit
fddef31d67
  1. 3
      nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppender.java
  2. 12
      nladmin-system/src/main/java/org/nl/modules/log/rest/RootLogController.java
  3. 8
      nladmin-system/src/main/java/org/nl/modules/log/service/RootLogService.java
  4. 40
      nladmin-system/src/main/java/org/nl/modules/log/service/impl/RootLogServiceImpl.java

3
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<ILoggingEvent> {
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 {

12
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<Object> findError(@RequestBody Map whereJson) {
return new ResponseEntity<>(rootLogService.findError(whereJson), HttpStatus.OK);
}
}

8
nladmin-system/src/main/java/org/nl/modules/log/service/RootLogService.java

@ -15,4 +15,12 @@ public interface RootLogService {
* @return Map<String,Object>
*/
Map<String,Object> queryAll(Map whereJson, Pageable page);
/**
* 查询异常详情
*
* @param whereJson
* @return Log
*/
String findError(Map whereJson);
}

40
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;
@ -27,22 +29,46 @@ public class RootLogServiceImpl implements RootLogService {
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page){
//查询条件
Query query = Query.query(Criteria.where("level").is("INFO"));
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<Map> list = mongoTemplate.find(query, Map.class, "log_root");
List<Map> 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;
}
}

Loading…
Cancel
Save