|
|
@ -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<String, Object> queryAll(Map whereJson, Pageable page) { |
|
|
|
//查询条件
|
|
|
|
Query query = Query.query(Criteria.where("level").is("INFO")); |
|
|
|
public Map<String, Object> 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<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; |
|
|
|
} |
|
|
|
} |
|
|
|