add:日志清除按钮
This commit is contained in:
@@ -34,5 +34,11 @@ public class EsLogController {
|
||||
public ResponseEntity<Object> queryAll(@RequestBody LogQuery query) {
|
||||
return new ResponseEntity<>(esLogService.query(query), HttpStatus.OK);
|
||||
}
|
||||
@DeleteMapping("/clearLogs")
|
||||
@ApiOperation("清空日志")
|
||||
public ResponseEntity<Object> clearLogs(@RequestBody LogQuery query) {
|
||||
esLogService.clearLogs(query);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ import org.nl.modules.logging.service.dto.LogQuery;
|
||||
* @desc desc
|
||||
*/
|
||||
public interface EsLogService {
|
||||
|
||||
/**
|
||||
* 清空日志
|
||||
*/
|
||||
void clearLogs(LogQuery query);
|
||||
/**
|
||||
* 获取labels和values树
|
||||
* @return
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.nl.modules.logging.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
@@ -27,6 +29,7 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.FetchSourceFilter;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -99,6 +102,20 @@ public class EsLogServiceImpl implements EsLogService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearLogs(LogQuery logQuery) {
|
||||
String system = logQuery.getSystem();
|
||||
BoolQueryBuilder query = QueryBuilders.boolQuery();
|
||||
if (!StringUtils.isEmpty(system)){
|
||||
query.must().add(QueryBuilders.matchQuery("system", system));
|
||||
}
|
||||
long time = DateUtil.offset(new Date(), DateField.DAY_OF_MONTH, -10).getTime();
|
||||
String script = "doc['@timestamp'].value.millis < " + time + "L";
|
||||
query.must().add(QueryBuilders.scriptQuery(new Script(script)));
|
||||
DeleteQuery deleteQuery = new DeleteQuery();
|
||||
deleteQuery.setQuery(query);
|
||||
elasticsearchRestTemplate.delete(deleteQuery,new LogRepositoryDTO().getClass());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user