feat: 定时清除lucene日志
This commit is contained in:
@@ -25,7 +25,7 @@ import java.util.Map;
|
|||||||
public class LuceneAppender extends AppenderBase<ILoggingEvent> {
|
public class LuceneAppender extends AppenderBase<ILoggingEvent> {
|
||||||
|
|
||||||
private Directory index;
|
private Directory index;
|
||||||
private IndexWriter indexWriter;
|
public static IndexWriter indexWriter;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.document.LongPoint;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.*;
|
||||||
import org.apache.lucene.index.Term;
|
|
||||||
import org.apache.lucene.queryparser.classic.QueryParser;
|
import org.apache.lucene.queryparser.classic.QueryParser;
|
||||||
import org.apache.lucene.search.*;
|
import org.apache.lucene.search.*;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
@@ -17,11 +16,14 @@ import org.apache.lucene.store.FSDirectory;
|
|||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.wltea.analyzer.lucene.IKAnalyzer;
|
import org.wltea.analyzer.lucene.IKAnalyzer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.text.ParseException;
|
||||||
import java.util.Calendar;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Map;
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lucene查询器
|
* lucene查询器
|
||||||
@@ -138,19 +140,48 @@ public class Searcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws IOException, ParseException {
|
||||||
String indexDir = "D:\\lucene\\index";
|
// String indexDir = "D:\\lucene\\index";
|
||||||
//查询这个字符串
|
// //查询这个字符串
|
||||||
JSONObject whereJson = new JSONObject();
|
// JSONObject whereJson = new JSONObject();
|
||||||
whereJson.put("size", "500");
|
// whereJson.put("size", "500");
|
||||||
whereJson.put("page", "1");
|
// whereJson.put("page", "1");
|
||||||
whereJson.put("message", "请求方法参数");
|
// whereJson.put("message", "请求方法参数");
|
||||||
// whereJson.put(LogMessageConstant.FIELD_TRACEID, "13244183367577216");
|
//// whereJson.put(LogMessageConstant.FIELD_TRACEID, "13244183367577216");
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
search(indexDir, whereJson);
|
// search(indexDir, whereJson);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
|
// 删除
|
||||||
|
// Directory directory = FSDirectory.open(Paths.get("D:\\lucene\\index"));
|
||||||
|
// IndexWriterConfig config = new IndexWriterConfig();
|
||||||
|
// IndexWriter writer = new IndexWriter(directory, config);
|
||||||
|
//
|
||||||
|
// String timestampAsString = "2023-10-25 14:36:12";
|
||||||
|
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
// Date date = dateFormat.parse(timestampAsString);
|
||||||
|
// long unixTimestamp = date.getTime(); // 获取Unix时间戳
|
||||||
|
//
|
||||||
|
// Query query = LongPoint.newRangeQuery("time", 0L, unixTimestamp);
|
||||||
|
// writer.deleteDocuments(query);
|
||||||
|
//
|
||||||
|
// writer.commit();
|
||||||
|
// writer.close();
|
||||||
|
// 获取当前时间
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
// 减去七天
|
||||||
|
LocalDateTime sevenDaysAgo = now.minus(7, ChronoUnit.DAYS);
|
||||||
|
// 转换为 Date 类型
|
||||||
|
Date sevenDaysAgoDate = Date.from(sevenDaysAgo.atZone(ZoneId.systemDefault()).toInstant());
|
||||||
|
// 获取时间戳
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
|
||||||
|
Date date = dateFormat.parse(String.valueOf(sevenDaysAgo));
|
||||||
|
long timestamp = date.getTime();
|
||||||
|
System.out.println(now);
|
||||||
|
System.out.println(sevenDaysAgo);
|
||||||
|
System.out.println(sevenDaysAgoDate);
|
||||||
|
System.out.println(timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package org.nl.system.service.quartz.task;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.lucene.document.LongPoint;
|
||||||
|
import org.apache.lucene.index.IndexWriter;
|
||||||
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.nl.config.lucene.LuceneAppender;
|
||||||
|
import org.nl.system.service.param.ISysParamService;
|
||||||
|
import org.nl.system.service.param.dao.Param;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lyd
|
||||||
|
* @Description: 自动删除lucene日志
|
||||||
|
* @Date: 2023/10/26
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class AutoClearLuceneData {
|
||||||
|
@Autowired
|
||||||
|
private ISysParamService paramService;
|
||||||
|
public void run() throws ParseException, IOException {
|
||||||
|
Param log_day = paramService.findByCode("log_day");
|
||||||
|
IndexWriter writer = LuceneAppender.indexWriter;
|
||||||
|
// 获取当前时间
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
// 减去七天
|
||||||
|
LocalDateTime sevenDaysAgo = now.minus(Long.parseLong(log_day.getValue()), ChronoUnit.DAYS);
|
||||||
|
// 获取时间戳
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
|
||||||
|
Date date = dateFormat.parse(String.valueOf(sevenDaysAgo));
|
||||||
|
long unixTimestamp = date.getTime(); // 获取Unix时间戳
|
||||||
|
Query query = LongPoint.newRangeQuery("time", 0L, unixTimestamp);
|
||||||
|
writer.deleteDocuments(query);
|
||||||
|
writer.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div v-loading.fullscreen.lock="fullscreenLoading" class="app-container">
|
||||||
<!--工具栏-->
|
<!--工具栏-->
|
||||||
<div class="head-container">
|
<div class="head-container">
|
||||||
<div v-if="crud.props.searchToggle">
|
<div v-if="crud.props.searchToggle">
|
||||||
@@ -539,6 +539,7 @@ export default {
|
|||||||
regionCodeParam: null,
|
regionCodeParam: null,
|
||||||
materialDialog: false,
|
materialDialog: false,
|
||||||
orderDialog: false,
|
orderDialog: false,
|
||||||
|
fullscreenLoading: false,
|
||||||
materialCode: null,
|
materialCode: null,
|
||||||
flag: 1
|
flag: 1
|
||||||
}
|
}
|
||||||
@@ -641,14 +642,14 @@ export default {
|
|||||||
},
|
},
|
||||||
// 下发
|
// 下发
|
||||||
submits(row) {
|
submits(row) {
|
||||||
this.crud.loading = true
|
this.fullscreenLoading = true
|
||||||
crudPdmBdWorkorder.submits(row).then(res => {
|
crudPdmBdWorkorder.submits(row).then(res => {
|
||||||
this.crud.notify('下发成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
this.crud.notify('下发成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||||
this.crud.toQuery()
|
this.crud.toQuery()
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.crud.loading = false
|
this.fullscreenLoading = false
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.crud.loading = false
|
this.fullscreenLoading = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
synchronize() {
|
synchronize() {
|
||||||
@@ -658,6 +659,8 @@ export default {
|
|||||||
this.crud.notify('同步成功!', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
this.crud.notify('同步成功!', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.fullscreenLoading = false
|
this.fullscreenLoading = false
|
||||||
|
}).finally(() => {
|
||||||
|
this.fullscreenLoading = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user