rev: lucene
This commit is contained in:
@@ -4,10 +4,8 @@ import cn.dev33.satoken.annotation.SaIgnore;
|
|||||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
||||||
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
|
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
|
||||||
import com.alicp.jetcache.anno.config.EnableMethodCache;
|
import com.alicp.jetcache.anno.config.EnableMethodCache;
|
||||||
import io.github.forezp.distributedlimitcore.annotation.Limit;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.nl.common.annotation.RepeatSubmit;
|
|
||||||
import org.nl.config.SpringContextHolder;
|
import org.nl.config.SpringContextHolder;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@@ -16,16 +14,12 @@ import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactor
|
|||||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||||
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.retry.annotation.Backoff;
|
|
||||||
import org.springframework.retry.annotation.EnableRetry;
|
import org.springframework.retry.annotation.EnableRetry;
|
||||||
import org.springframework.retry.annotation.Retryable;
|
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.time.LocalTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开启审计功能 -> @EnableJpaAuditing
|
* 开启审计功能 -> @EnableJpaAuditing
|
||||||
* https://www.cnblogs.com/niceyoo/p/10908647.html
|
* https://www.cnblogs.com/niceyoo/p/10908647.html
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
package org.nl.common.logging.aspect;
|
package org.nl.common.logging.aspect;
|
||||||
|
|
||||||
@@ -30,7 +30,8 @@ import org.nl.common.utils.RequestHolder;
|
|||||||
import org.nl.common.utils.SecurityUtils;
|
import org.nl.common.utils.SecurityUtils;
|
||||||
import org.nl.common.utils.StringUtils;
|
import org.nl.common.utils.StringUtils;
|
||||||
import org.nl.common.utils.ThrowableUtil;
|
import org.nl.common.utils.ThrowableUtil;
|
||||||
import org.nl.common.logging.domain.Log;
|
import org.nl.system.service.logging.ISysLogService;
|
||||||
|
import org.nl.system.service.logging.dao.SysLog;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@@ -46,41 +47,39 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
* @date 2018-11-24
|
* @date 2018-11-24
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Aspect
|
@Aspect
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LogAspect {
|
public class LogAspect {
|
||||||
|
|
||||||
private final LogService logService;
|
private final ISysLogService logService;
|
||||||
|
|
||||||
ThreadLocal<Long> currentTime = new ThreadLocal<>();
|
ThreadLocal<Long> currentTime = new ThreadLocal<>();
|
||||||
|
|
||||||
public LogAspect(LogService logService) {
|
public LogAspect(ISysLogService logService) {
|
||||||
this.logService = logService;
|
this.logService = logService;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* 配置切入点
|
* 配置切入点
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
@Pointcut("@annotation(org.nl.common.logging.annotation.Log)")
|
@Pointcut("@annotation(org.nl.common.logging.annotation.Log)")
|
||||||
public void logPointcut() {
|
public void logPointcut() {
|
||||||
// 该方法无方法体,主要为了让同类中其他方法使用此切入点
|
// 该方法无方法体,主要为了让同类中其他方法使用此切入点
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* 配置环绕通知,使用在方法logPointcut()上注册的切入点
|
* 配置环绕通知,使用在方法logPointcut()上注册的切入点
|
||||||
*
|
*
|
||||||
* @param joinPoint join point for advice
|
* @param joinPoint join point for advice
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
@Around("logPointcut()")
|
@Around("logPointcut()")
|
||||||
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
@@ -96,24 +95,23 @@ public class LogAspect {
|
|||||||
String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
||||||
String params = getParameter(method, joinPoint.getArgs());
|
String params = getParameter(method, joinPoint.getArgs());
|
||||||
|
|
||||||
log.info("请求uri:{}", request.getRequestURI());
|
log.info("请求路径:{}", request.getRequestURI());
|
||||||
log.info("请求方法:{}", methodName);
|
log.info("请求方法:{}", methodName);
|
||||||
log.info("请求方法参数:{}", params);
|
log.info("请求方法参数:{}", params);
|
||||||
|
|
||||||
Object result;
|
Object result;
|
||||||
currentTime.set(System.currentTimeMillis());
|
currentTime.set(System.currentTimeMillis());
|
||||||
result = joinPoint.proceed();
|
result = joinPoint.proceed();
|
||||||
Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get());
|
SysLog log = new SysLog("INFO", System.currentTimeMillis() - currentTime.get());
|
||||||
currentTime.remove();
|
currentTime.remove();
|
||||||
|
|
||||||
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), joinPoint, log);
|
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), joinPoint, log);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* 根据方法和传入的参数获取请求参数
|
* 根据方法和传入的参数获取请求参数
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
private String getParameter(Method method, Object[] args) {
|
private String getParameter(Method method, Object[] args) {
|
||||||
List<Object> argList = new ArrayList<>();
|
List<Object> argList = new ArrayList<>();
|
||||||
@@ -142,19 +140,19 @@ public class LogAspect {
|
|||||||
return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList);
|
return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList);
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* 配置异常通知
|
* 配置异常通知
|
||||||
*
|
*
|
||||||
* @param joinPoint join point for advice
|
* @param joinPoint join point for advice
|
||||||
* @param e exception
|
* @param e exception
|
||||||
*//*
|
*/
|
||||||
|
|
||||||
@AfterThrowing(pointcut = "logPointcut()", throwing = "e")
|
@AfterThrowing(pointcut = "logPointcut()", throwing = "e")
|
||||||
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
||||||
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime.get());
|
SysLog log = new SysLog("ERROR", System.currentTimeMillis() - currentTime.get());
|
||||||
currentTime.remove();
|
currentTime.remove();
|
||||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
|
log.setException_detail(ThrowableUtil.getStackTrace(e).getBytes());
|
||||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||||
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log);
|
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log);
|
||||||
}
|
}
|
||||||
@@ -167,4 +165,3 @@ public class LogAspect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|||||||
@@ -2,17 +2,22 @@ package org.nl.config.lucene;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
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.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
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;
|
||||||
import org.apache.lucene.store.FSDirectory;
|
import org.apache.lucene.store.FSDirectory;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
|
import org.nl.system.service.lucene.LogMessageConstant;
|
||||||
|
import org.wltea.analyzer.lucene.IKAnalyzer;
|
||||||
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -26,33 +31,30 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class Searcher {
|
public class Searcher {
|
||||||
|
|
||||||
public static Map<String, Object> search(String indexDir, String ext,Map whereJson) throws Exception {
|
public static Map<String, Object> search(String indexDir, JSONObject whereJson) throws Exception {
|
||||||
//获取要查询的路径,也就是索引所在的位置
|
//获取要查询的路径,也就是索引所在的位置
|
||||||
Directory dir = FSDirectory.open(Paths.get(indexDir));
|
Directory dir = FSDirectory.open(Paths.get(indexDir));
|
||||||
IndexReader reader = DirectoryReader.open(dir);
|
IndexReader reader = DirectoryReader.open(dir);
|
||||||
//构建IndexSearcher
|
//构建IndexSearcher
|
||||||
IndexSearcher searcher = new IndexSearcher(reader);
|
IndexSearcher searcher = new IndexSearcher(reader);
|
||||||
//标准分词器,会自动去掉空格啊,is a the等单词
|
//标准分词器,会自动去掉空格啊,is a the等单词
|
||||||
// Analyzer analyzer = new StandardAnalyzer();
|
Analyzer analyzer = new IKAnalyzer(true);
|
||||||
// Analyzer analyzer = new IKAnalyzer(false);
|
|
||||||
//查询解析器
|
|
||||||
// QueryParser queryParser = new QueryParser("fieldContent", analyzer);
|
|
||||||
|
|
||||||
//记录索引开始时间
|
//记录索引开始时间
|
||||||
long startTime = System.currentTimeMillis();
|
// long startTime = System.currentTimeMillis();
|
||||||
// 实际上Lucene本身不支持分页。因此我们需要自己进行逻辑分页。我们要准备分页参数:
|
// 实际上Lucene本身不支持分页。因此我们需要自己进行逻辑分页。我们要准备分页参数:
|
||||||
int pageSize = Integer.parseInt(whereJson.get("size").toString());// 每页条数
|
int pageSize = Integer.parseInt(whereJson.get("size").toString());// 每页条数
|
||||||
int pageNum = Integer.parseInt(whereJson.get("page").toString());// 当前页码
|
int pageNum = Integer.parseInt(whereJson.get("page").toString()) - 1;// 当前页码
|
||||||
int start = pageNum * pageSize;// 当前页的起始条数
|
int start = pageNum * pageSize;// 当前页的起始条数
|
||||||
int end = start + pageSize;// 当前页的结束条数(不能包含)
|
int end = start + pageSize;// 当前页的结束条数(不能包含)
|
||||||
// 创建排序对象,需要排序字段SortField,参数:字段的名称、字段的类型、是否反转如果是false,升序。true降序
|
// 创建排序对象,需要排序字段SortField,参数:字段的名称、字段的类型、是否反转如果是false,升序。true降序
|
||||||
Sort sort = new Sort(new SortField("logTime", SortField.Type.DOC,true));
|
Sort sort = new Sort(new SortField("timestamp", SortField.Type.DOC,true));
|
||||||
|
|
||||||
TopDocs docs = null;
|
TopDocs docs = null;
|
||||||
BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();
|
BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();
|
||||||
//时间范围查询
|
//时间范围查询
|
||||||
String startDate = (String) whereJson.get("begin_time");
|
String startDate = whereJson.getString("begin_time");
|
||||||
String endDate = (String) whereJson.get("end_time");
|
String endDate = whereJson.getString("end_time");
|
||||||
Calendar calendar=Calendar.getInstance();
|
Calendar calendar=Calendar.getInstance();
|
||||||
calendar.set(1970, 0, 1);
|
calendar.set(1970, 0, 1);
|
||||||
if (startDate == null){
|
if (startDate == null){
|
||||||
@@ -65,74 +67,71 @@ public class Searcher {
|
|||||||
} else {
|
} else {
|
||||||
endDate = LuceneIndexWriter.getDate(endDate);
|
endDate = LuceneIndexWriter.getDate(endDate);
|
||||||
}
|
}
|
||||||
TermRangeQuery termRangeQuery = new TermRangeQuery("logTime", new BytesRef(startDate), new BytesRef(endDate), true, true);
|
// 字段之间的与或非关系,MUST表示and,MUST_NOT表示not,SHOULD表示or,有几个fields就必须有几个clauses
|
||||||
|
TermRangeQuery termRangeQuery = new TermRangeQuery("timestamp", new BytesRef(startDate), new BytesRef(endDate), true, true);
|
||||||
booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST);
|
booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST);
|
||||||
if (whereJson.get("device_code") != null){
|
if (ObjectUtil.isNotEmpty(whereJson.get(LogMessageConstant.FIELD_MESSAGE))){
|
||||||
Query termQuery = new TermQuery(new Term("device_code", (String) whereJson.get("device_code")));
|
//查询解析器
|
||||||
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST);
|
QueryParser queryParser = new QueryParser("message", analyzer);
|
||||||
}
|
Query query = queryParser.parse(whereJson.getString("message"));
|
||||||
if (whereJson.get("method") != null){
|
|
||||||
Query termQuery = new TermQuery(new Term("method", (String) whereJson.get("method")));
|
|
||||||
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST);
|
|
||||||
}
|
|
||||||
if (whereJson.get("status_code") != null){
|
|
||||||
Query termQuery = new TermQuery(new Term("status_code", (String) whereJson.get("status_code")));
|
|
||||||
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST);
|
|
||||||
}
|
|
||||||
if (whereJson.get("requestparam") != null){
|
|
||||||
WildcardQuery query = new WildcardQuery(new Term("requestparam", "*"+(String) whereJson.get("requestparam")+"*"));
|
|
||||||
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
|
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
|
||||||
}
|
}
|
||||||
if (whereJson.get("responseparam") != null){
|
if (ObjectUtil.isNotEmpty(whereJson.get(LogMessageConstant.FIELD_TRACEID))){
|
||||||
WildcardQuery query = new WildcardQuery(new Term("responseparam", "*"+(String) whereJson.get("responseparam")+"*"));
|
//查询解析器
|
||||||
booleanQueryBuilder.add(query,BooleanClause.Occur.MUST);
|
TermQuery termQuery = new TermQuery(new Term(LogMessageConstant.FIELD_TRACEID,
|
||||||
|
whereJson.get(LogMessageConstant.FIELD_TRACEID).toString().trim()));
|
||||||
|
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
||||||
}
|
}
|
||||||
if (whereJson.get("blurry") != null) {
|
if (ObjectUtil.isNotEmpty(whereJson.get(LogMessageConstant.FIELD_LEVEL))){
|
||||||
WildcardQuery query = new WildcardQuery(new Term("fieldContent", "*"+(String) whereJson.get("blurry")+"*"));
|
//查询解析器
|
||||||
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
|
TermQuery termQuery = new TermQuery(new Term(LogMessageConstant.FIELD_LEVEL,
|
||||||
|
whereJson.get(LogMessageConstant.FIELD_LEVEL).toString()));
|
||||||
|
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
||||||
}
|
}
|
||||||
docs = searcher.search(booleanQueryBuilder.build(), end,sort);
|
docs = searcher.search(booleanQueryBuilder.build(), end,sort);
|
||||||
//记录索引时间
|
//记录索引时间
|
||||||
long endTime = System.currentTimeMillis();
|
// long endTime = System.currentTimeMillis();
|
||||||
log.info("匹配{}共耗时{}毫秒",booleanQueryBuilder.build(),(endTime-startTime));
|
// log.info("匹配{}共耗时{}毫秒",booleanQueryBuilder.build(),(endTime-startTime));
|
||||||
log.info("查询到{}条日志文件", docs.totalHits.value);
|
// log.info("查询到{}条日志文件", docs.totalHits.value);
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
ScoreDoc[] scoreDocs = docs.scoreDocs;
|
ScoreDoc[] scoreDocs = docs.scoreDocs;
|
||||||
if (end > docs.totalHits.value) end = (int) docs.totalHits.value;
|
if (end > docs.totalHits.value) end = (int) docs.totalHits.value;
|
||||||
JSONArray array = new JSONArray();
|
|
||||||
|
|
||||||
for (int i = start; i < end; i++) {
|
for (int i = start; i < end; i++) {
|
||||||
ScoreDoc scoreDoc = scoreDocs[i];
|
ScoreDoc scoreDoc = scoreDocs[i];
|
||||||
Document doc = reader.document(scoreDoc.doc);
|
Document doc = reader.document(scoreDoc.doc);
|
||||||
JSONObject object = new JSONObject();
|
String logInfo = LogMessageConstant.COLOR_YELLOW + doc.get(LogMessageConstant.FIELD_TRACEID) +
|
||||||
object.put("content",doc.get("fieldContent"));
|
LogMessageConstant.COLOR_RESET + " - " +
|
||||||
object.put("device_code",doc.get("device_code"));
|
LogMessageConstant.COLOR_RED + doc.get(LogMessageConstant.FIELD_TIMESTAMP) +
|
||||||
object.put("logTime",doc.get("logTime"));
|
LogMessageConstant.COLOR_RESET + " - " +
|
||||||
object.put("method",doc.get("method"));
|
LogMessageConstant.COLOR_GREEN + "[" + doc.get(LogMessageConstant.FIELD_THREAD) + "]" +
|
||||||
object.put("status_code",doc.get("status_code"));
|
LogMessageConstant.COLOR_RESET + " - " +
|
||||||
object.put("requestparam",doc.get("requestparam"));
|
LogMessageConstant.COLOR_BLACK + doc.get(LogMessageConstant.FIELD_LEVEL) +
|
||||||
object.put("responseparam",doc.get("responseparam"));
|
LogMessageConstant.COLOR_RESET + " - " +
|
||||||
if(doc.get("fieldContent") != null) {
|
LogMessageConstant.COLOR_MAGENTA + doc.get(LogMessageConstant.FIELD_CLASS_NAME) +
|
||||||
array.add(object);
|
LogMessageConstant.COLOR_RESET + " - " +
|
||||||
}
|
LogMessageConstant.COLOR_BLACK + doc.get(LogMessageConstant.FIELD_MESSAGE);
|
||||||
}
|
// System.out.println(logInfo);
|
||||||
for(Object logDto:array){
|
list.add(logInfo);
|
||||||
log.info(logDto.toString());
|
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
JSONObject jo = new JSONObject();
|
JSONObject jo = new JSONObject();
|
||||||
jo.put("content", array);
|
jo.put("content", list);
|
||||||
jo.put("totalElements", docs.totalHits.value);
|
jo.put("totalElements", docs.totalHits.value);
|
||||||
return jo;
|
return jo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String indexDir = "D:\\lucene\\index";
|
String indexDir = "D:\\lucene\\debug_log";
|
||||||
//查询这个字符串
|
//查询这个字符串
|
||||||
String q = "07.832";
|
JSONObject whereJson = new JSONObject();
|
||||||
Map whereJson = null;
|
whereJson.put("size", "500");
|
||||||
|
whereJson.put("page", "0");
|
||||||
|
// whereJson.put("message", "traceId");
|
||||||
|
whereJson.put(LogMessageConstant.FIELD_TRACEID, "13236874421038464");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
search(indexDir, q,whereJson);
|
search(indexDir, whereJson);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.nl.system.controller.lucence;
|
package org.nl.system.controller.lucence;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -9,10 +12,7 @@ import org.nl.system.service.lucene.LuceneService;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -25,11 +25,11 @@ public class LuceneController {
|
|||||||
|
|
||||||
private final LuceneService luceneService;
|
private final LuceneService luceneService;
|
||||||
|
|
||||||
@GetMapping("/getAll")
|
@PostMapping("/getAll")
|
||||||
@Log("日志检索")
|
@Log("日志检索")
|
||||||
@ApiOperation("日志检索")
|
@ApiOperation("日志检索")
|
||||||
//@PreAuthorize("@el.check('task:list')")
|
//@PreAuthorize("@el.check('task:list')")
|
||||||
public ResponseEntity<Object> get(@RequestParam Map whereJson, Pageable page) {
|
public ResponseEntity<Object> get(@RequestBody JSONObject whereJson) {
|
||||||
return new ResponseEntity<>(luceneService.getAll(whereJson, page), HttpStatus.OK);
|
return new ResponseEntity<>(luceneService.getAll(whereJson), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package org.nl.system.service.logging;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.nl.common.domain.query.PageQuery;
|
import org.nl.common.domain.query.PageQuery;
|
||||||
import org.nl.system.service.logging.dao.SysLog;
|
import org.nl.system.service.logging.dao.SysLog;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -41,4 +43,15 @@ public interface ISysLogService extends IService<SysLog> {
|
|||||||
* 删除所有操作日志
|
* 删除所有操作日志
|
||||||
*/
|
*/
|
||||||
void delAllByInfo();
|
void delAllByInfo();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存日志数据
|
||||||
|
* @param username 用户
|
||||||
|
* @param browser 浏览器
|
||||||
|
* @param ip 请求IP
|
||||||
|
* @param joinPoint /
|
||||||
|
* @param log 日志实体
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, SysLog log);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -16,6 +17,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
* @since 2023-05-08
|
* @since 2023-05-08
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@TableName("sys_log")
|
@TableName("sys_log")
|
||||||
public class SysLog implements Serializable {
|
public class SysLog implements Serializable {
|
||||||
@@ -51,5 +53,8 @@ public class SysLog implements Serializable {
|
|||||||
|
|
||||||
private String create_time;
|
private String create_time;
|
||||||
|
|
||||||
|
public SysLog(String logType, Long time) {
|
||||||
|
this.log_type = logType;
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,35 @@
|
|||||||
package org.nl.system.service.logging.impl;
|
package org.nl.system.service.logging.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
import org.nl.common.domain.query.PageQuery;
|
import org.nl.common.domain.query.PageQuery;
|
||||||
|
import org.nl.common.logging.annotation.Log;
|
||||||
|
import org.nl.common.utils.StringUtils;
|
||||||
import org.nl.common.utils.ValidationUtil;
|
import org.nl.common.utils.ValidationUtil;
|
||||||
import org.nl.system.service.logging.ISysLogService;
|
import org.nl.system.service.logging.ISysLogService;
|
||||||
import org.nl.system.service.logging.dao.SysLog;
|
import org.nl.system.service.logging.dao.SysLog;
|
||||||
import org.nl.system.service.logging.dao.mapper.SysLogMapper;
|
import org.nl.system.service.logging.dao.mapper.SysLogMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Parameter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,4 +86,60 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
|
|||||||
public void delAllByInfo() {
|
public void delAllByInfo() {
|
||||||
logMapper.delete(new LambdaQueryWrapper<SysLog>().eq(SysLog::getLog_type, "INFO"));
|
logMapper.delete(new LambdaQueryWrapper<SysLog>().eq(SysLog::getLog_type, "INFO"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, SysLog logDto) {
|
||||||
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
|
Method method = signature.getMethod();
|
||||||
|
Log aopLog = method.getAnnotation(Log.class);
|
||||||
|
|
||||||
|
// 方法路径
|
||||||
|
String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
||||||
|
|
||||||
|
// 描述
|
||||||
|
if (logDto != null) {
|
||||||
|
logDto.setDescription(aopLog.value());
|
||||||
|
}
|
||||||
|
assert logDto != null;
|
||||||
|
logDto.setRequest_ip(ip);
|
||||||
|
|
||||||
|
logDto.setAddress(StringUtils.getCityInfo(logDto.getRequest_ip()));
|
||||||
|
logDto.setMethod(methodName);
|
||||||
|
logDto.setUsername(username);
|
||||||
|
logDto.setParams(getParameter(method, joinPoint.getArgs()));
|
||||||
|
logDto.setBrowser(browser);
|
||||||
|
logDto.setLog_id(IdUtil.getSnowflake(1,1).nextIdStr());
|
||||||
|
logDto.setCreate_time(DateUtil.now());
|
||||||
|
logMapper.insert(logDto);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据方法和传入的参数获取请求参数
|
||||||
|
*/
|
||||||
|
private String getParameter(Method method, Object[] args) {
|
||||||
|
List<Object> argList = new ArrayList<>();
|
||||||
|
Parameter[] parameters = method.getParameters();
|
||||||
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
|
//将RequestBody注解修饰的参数作为请求参数
|
||||||
|
RequestBody requestBody = parameters[i].getAnnotation(RequestBody.class);
|
||||||
|
if (requestBody != null) {
|
||||||
|
argList.add(args[i]);
|
||||||
|
}
|
||||||
|
//将RequestParam注解修饰的参数作为请求参数
|
||||||
|
RequestParam requestParam = parameters[i].getAnnotation(RequestParam.class);
|
||||||
|
if (requestParam != null) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
String key = parameters[i].getName();
|
||||||
|
if (!StrUtil.isEmpty(requestParam.value())) {
|
||||||
|
key = requestParam.value();
|
||||||
|
}
|
||||||
|
map.put(key, args[i]);
|
||||||
|
argList.add(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (argList.size() == 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package org.nl.system.service.lucene;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lyd
|
||||||
|
* @Description: 定义lucene相关常量
|
||||||
|
* @Date: 2023/8/25
|
||||||
|
*/
|
||||||
|
public class LogMessageConstant {
|
||||||
|
/** 级别 */
|
||||||
|
public final static String FIELD_LEVEL = "level";
|
||||||
|
/** 时间 */
|
||||||
|
public final static String FIELD_TIMESTAMP = "timestamp";
|
||||||
|
/** 类的限定名 */
|
||||||
|
public final static String FIELD_CLASS_NAME = "logger";
|
||||||
|
/** 线程名 */
|
||||||
|
public final static String FIELD_THREAD = "thread";
|
||||||
|
/** 日志内容 */
|
||||||
|
public final static String FIELD_MESSAGE = "message";
|
||||||
|
public final static String FIELD_TRACEID = "tlogTraceId";
|
||||||
|
// 定义颜色值
|
||||||
|
/** 文本颜色:黑色 */
|
||||||
|
public final static String COLOR_BLACK = "\u001B[30m";
|
||||||
|
/** 文本颜色:红色 */
|
||||||
|
public final static String COLOR_RED = "\u001B[31m";
|
||||||
|
/** 文本颜色:绿色 */
|
||||||
|
public final static String COLOR_GREEN = "\u001B[32m";
|
||||||
|
/** 文本颜色:黄色 */
|
||||||
|
public final static String COLOR_YELLOW = "\u001B[33m";
|
||||||
|
/** 文本颜色:蓝色 */
|
||||||
|
public final static String COLOR_BLUE = "\u001B[34m";
|
||||||
|
/** 文本颜色:品红色 */
|
||||||
|
public final static String COLOR_MAGENTA = "\u001B[35m";
|
||||||
|
/** 文本颜色:青色 */
|
||||||
|
public final static String COLOR_CYAN = "\u001B[36m";
|
||||||
|
/** 文本颜色:白色 */
|
||||||
|
public final static String COLOR_WHITE = "\u001B[37m";
|
||||||
|
/** 文本颜色重置 */
|
||||||
|
public final static String COLOR_RESET = "\u001B[0m";
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package org.nl.system.service.lucene;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ldjun
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2023年08月24日 13:00
|
||||||
|
* @desc desc
|
||||||
|
*/
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
|
import ch.qos.logback.core.AppenderBase;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
|
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||||
|
import org.apache.lucene.document.*;
|
||||||
|
import org.apache.lucene.index.IndexWriter;
|
||||||
|
import org.apache.lucene.index.IndexWriterConfig;
|
||||||
|
import org.apache.lucene.store.Directory;
|
||||||
|
import org.apache.lucene.store.FSDirectory;
|
||||||
|
import org.wltea.analyzer.lucene.IKAnalyzer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class LuceneAppender extends AppenderBase<ILoggingEvent> {
|
||||||
|
|
||||||
|
private Directory index;
|
||||||
|
private IndexWriter indexWriter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
super.start();
|
||||||
|
String indexPath = "D:\\lucene\\debug_log";
|
||||||
|
try {
|
||||||
|
index = FSDirectory.open(Paths.get(indexPath));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化 Lucene 索引
|
||||||
|
Analyzer analyzer = new IKAnalyzer();
|
||||||
|
IndexWriterConfig config = new IndexWriterConfig(analyzer);
|
||||||
|
try {
|
||||||
|
indexWriter = new IndexWriter(index, config);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void append(ILoggingEvent event) {
|
||||||
|
String message = event.getFormattedMessage();
|
||||||
|
Map<String, String> mdcPropertyMap = event.getMDCPropertyMap();
|
||||||
|
Document doc = new Document();
|
||||||
|
String formattedDateTime = DateUtil.format(new java.util.Date(event.getTimeStamp()), "yyyy-MM-dd HH:mm:ss.SSS");
|
||||||
|
doc.add(new StringField(LogMessageConstant.FIELD_LEVEL, event.getLevel().toString(), Field.Store.YES));
|
||||||
|
doc.add(new StringField(LogMessageConstant.FIELD_TIMESTAMP, formattedDateTime,Field.Store.YES));
|
||||||
|
doc.add(new StoredField(LogMessageConstant.FIELD_CLASS_NAME, event.getLoggerName()));
|
||||||
|
doc.add(new StoredField(LogMessageConstant.FIELD_THREAD, event.getThreadName()));
|
||||||
|
if (ObjectUtil.isNotEmpty(mdcPropertyMap)) {
|
||||||
|
String traceId = mdcPropertyMap.get(LogMessageConstant.FIELD_TRACEID);
|
||||||
|
if (ObjectUtil.isNotEmpty(traceId)) {
|
||||||
|
doc.add(new StringField(LogMessageConstant.FIELD_TRACEID, traceId,Field.Store.YES));
|
||||||
|
} else {
|
||||||
|
doc.add(new StringField(LogMessageConstant.FIELD_TRACEID, "无生成链路ID",Field.Store.YES));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
doc.add(new StringField(LogMessageConstant.FIELD_TRACEID, "无生成链路ID",Field.Store.YES));
|
||||||
|
}
|
||||||
|
doc.add(new TextField(LogMessageConstant.FIELD_MESSAGE, message, Field.Store.YES));
|
||||||
|
try {
|
||||||
|
indexWriter.addDocument(doc);
|
||||||
|
indexWriter.commit();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
super.stop();
|
||||||
|
try {
|
||||||
|
indexWriter.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.nl.system.service.lucene;
|
package org.nl.system.service.lucene;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -15,5 +16,5 @@ public interface LuceneService {
|
|||||||
* @param page 分页参数
|
* @param page 分页参数
|
||||||
* @return Map<String, Object>
|
* @return Map<String, Object>
|
||||||
*/
|
*/
|
||||||
Map<String, Object> getAll(Map whereJson, Pageable page);
|
Map<String, Object> getAll(JSONObject whereJson);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ public class LuceneServiceImpl implements LuceneService {
|
|||||||
private String luceneUrl;
|
private String luceneUrl;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getAll(Map whereJson, Pageable page) {
|
public Map<String, Object> getAll(JSONObject whereJson) {
|
||||||
JSONObject jo = new JSONObject();
|
JSONObject jo = new JSONObject();
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = (JSONObject) Searcher.search(luceneUrl, "", whereJson);
|
JSONObject jsonObject = (JSONObject) Searcher.search(luceneUrl, whereJson);
|
||||||
JSONArray array = jsonObject.getJSONArray("content");
|
JSONArray array = jsonObject.getJSONArray("content");
|
||||||
int totalElements = Integer.parseInt(jsonObject.get("totalElements").toString());
|
int totalElements = Integer.parseInt(jsonObject.get("totalElements").toString());
|
||||||
jo.put("content", array);
|
jo.put("content", array);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.nl.common.utils.SecurityUtils;
|
|||||||
import org.nl.wms.sch.region.service.ISchBaseRegionService;
|
import org.nl.wms.sch.region.service.ISchBaseRegionService;
|
||||||
import org.nl.wms.sch.region.service.dao.mapper.SchBaseRegionMapper;
|
import org.nl.wms.sch.region.service.dao.mapper.SchBaseRegionMapper;
|
||||||
import org.nl.wms.sch.region.service.dao.SchBaseRegion;
|
import org.nl.wms.sch.region.service.dao.SchBaseRegion;
|
||||||
|
import org.slf4j.MDC;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -39,6 +40,9 @@ public class SchBaseRegionServiceImpl extends ServiceImpl<SchBaseRegionMapper, S
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<SchBaseRegion> queryAll(Map whereJson, PageQuery page) {
|
public IPage<SchBaseRegion> queryAll(Map whereJson, PageQuery page) {
|
||||||
|
MDC.put("log_type", "region");
|
||||||
|
log.info("区域查询:{}", whereJson);
|
||||||
|
log.error("这是第二个日志");
|
||||||
String workshop_code = ObjectUtil.isNotEmpty(whereJson.get("workshop_code")) ? whereJson.get("workshop_code").toString() : null;
|
String workshop_code = ObjectUtil.isNotEmpty(whereJson.get("workshop_code")) ? whereJson.get("workshop_code").toString() : null;
|
||||||
String blurry = ObjectUtil.isNotEmpty(whereJson.get("blurry")) ? whereJson.get("blurry").toString() : null;
|
String blurry = ObjectUtil.isNotEmpty(whereJson.get("blurry")) ? whereJson.get("blurry").toString() : null;
|
||||||
Boolean is_has_workder = ObjectUtil.isNotEmpty(whereJson.get("is_has_workder")) ? Boolean.valueOf(whereJson.get("is_has_workder").toString()) : null;
|
Boolean is_has_workder = ObjectUtil.isNotEmpty(whereJson.get("is_has_workder")) ? Boolean.valueOf(whereJson.get("is_has_workder").toString()) : null;
|
||||||
@@ -50,6 +54,7 @@ public class SchBaseRegionServiceImpl extends ServiceImpl<SchBaseRegionMapper, S
|
|||||||
.orderByAsc(SchBaseRegion::getOrder_seq);
|
.orderByAsc(SchBaseRegion::getOrder_seq);
|
||||||
IPage<SchBaseRegion> pages = new Page<>(page.getPage() + 1, page.getSize());
|
IPage<SchBaseRegion> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||||
schBaseRegionMapper.selectPage(pages, lam);
|
schBaseRegionMapper.selectPage(pages, lam);
|
||||||
|
MDC.remove("log_type");
|
||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.nl.wms.sch.task.service.dao.mapper.SchBaseTaskconfigMapper;
|
|||||||
import org.nl.wms.sch.task_manage.AbstractTask;
|
import org.nl.wms.sch.task_manage.AbstractTask;
|
||||||
import org.nl.wms.sch.task_manage.task.TaskFactory;
|
import org.nl.wms.sch.task_manage.task.TaskFactory;
|
||||||
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
|
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
|
||||||
|
import org.slf4j.MDC;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -50,6 +51,9 @@ public class SchBaseTaskServiceImpl extends ServiceImpl<SchBaseTaskMapper, SchBa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<SchBaseTask> queryAll(Map whereJson, PageQuery page) {
|
public IPage<SchBaseTask> queryAll(Map whereJson, PageQuery page) {
|
||||||
|
MDC.put("log", "SchBaseTask");
|
||||||
|
log.info("参数:{}", whereJson);
|
||||||
|
MDC.remove("log");
|
||||||
String task_code = ObjectUtil.isNotEmpty(whereJson.get("task_code"))
|
String task_code = ObjectUtil.isNotEmpty(whereJson.get("task_code"))
|
||||||
? whereJson.get("task_code").toString() : null;
|
? whereJson.get("task_code").toString() : null;
|
||||||
String vehicle_code = ObjectUtil.isNotEmpty(whereJson.get("vehicle_code"))
|
String vehicle_code = ObjectUtil.isNotEmpty(whereJson.get("vehicle_code"))
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||||
|
<properties>
|
||||||
|
<comment>IK Analyzer 扩展配置</comment>
|
||||||
|
<!--用户可以在这里配置自己的扩展字典 -->
|
||||||
|
<entry key="ext_dict">ext.dic;</entry>
|
||||||
|
|
||||||
|
<!--用户可以在这里配置自己的扩展停止词字典-->
|
||||||
|
<entry key="ext_stopwords">stopword.dic;</entry>
|
||||||
|
|
||||||
|
</properties>
|
||||||
@@ -111,4 +111,4 @@ mybatis-plus:
|
|||||||
id-type: INPUT
|
id-type: INPUT
|
||||||
lucene:
|
lucene:
|
||||||
index:
|
index:
|
||||||
path: D:\lucene\index
|
path: D:\lucene\debug_log
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
</encoder>
|
</encoder>
|
||||||
|
|
||||||
</appender>
|
</appender>
|
||||||
|
<appender name="luceneAppender" class="org.nl.system.service.lucene.LuceneAppender" />
|
||||||
<!--异步到文件-->
|
<!--异步到文件-->
|
||||||
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||||
<discardingThreshold>0</discardingThreshold>
|
<discardingThreshold>0</discardingThreshold>
|
||||||
@@ -58,6 +58,7 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
<springProfile name="dev">
|
<springProfile name="dev">
|
||||||
<root level="debug">
|
<root level="debug">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="luceneAppender"/>
|
||||||
</root>
|
</root>
|
||||||
<logger name="org.springframework" level="ERROR" additivity="false">
|
<logger name="org.springframework" level="ERROR" additivity="false">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
|||||||
1241
nladmin-system/nlsso-server/src/main/resources/stopword.dic
Normal file
1241
nladmin-system/nlsso-server/src/main/resources/stopword.dic
Normal file
File diff suppressed because it is too large
Load Diff
@@ -129,7 +129,8 @@ export default {
|
|||||||
},
|
},
|
||||||
initWebSocket() {
|
initWebSocket() {
|
||||||
// const wsUri = (process.env.VUE_APP_WS_API === '/' ? '/' : (process.env.VUE_APP_WS_API + '/')) + 'messageInfo'
|
// const wsUri = (process.env.VUE_APP_WS_API === '/' ? '/' : (process.env.VUE_APP_WS_API + '/')) + 'messageInfo'
|
||||||
const wsUri = window.g.prod.VUE_APP_BASE_API.replace('http', 'ws') + '/webSocket/' + 'messageInfo'
|
const wsUri = process.env.VUE_APP_WS_API.replace('http', 'ws') + '/webSocket/' + 'messageInfo'
|
||||||
|
// const wsUri = 'ws://127.0.0.1:8089/ws/webSocket/' + 'messageInfo'
|
||||||
this.websock = new WebSocket(wsUri)
|
this.websock = new WebSocket(wsUri)
|
||||||
this.websock.onerror = this.webSocketOnError
|
this.websock.onerror = this.webSocketOnError
|
||||||
this.websock.onmessage = this.webSocketOnMessage
|
this.websock.onmessage = this.webSocketOnMessage
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import request from '@/utils/request'
|
|||||||
export function getLogData(param) {
|
export function getLogData(param) {
|
||||||
return request({
|
return request({
|
||||||
url: 'api/lucene/getAll',
|
url: 'api/lucene/getAll',
|
||||||
method: 'get',
|
method: 'post',
|
||||||
data: param
|
data: param
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,102 +1,140 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<div class="head-container">
|
<div class="head-container">
|
||||||
<Search />
|
<el-form
|
||||||
<crudOperation />
|
:inline="true"
|
||||||
|
class="demo-form-inline"
|
||||||
|
label-position="right"
|
||||||
|
label-width="90px"
|
||||||
|
label-suffix=":"
|
||||||
|
>
|
||||||
|
<el-form-item label="日志级别">
|
||||||
|
<el-select
|
||||||
|
v-model="query.level"
|
||||||
|
clearable
|
||||||
|
size="mini"
|
||||||
|
placeholder="日志级别"
|
||||||
|
class="filter-item"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in levelOptions"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="模糊搜索">
|
||||||
|
<el-input
|
||||||
|
v-model="query.message"
|
||||||
|
clearable
|
||||||
|
size="mini"
|
||||||
|
placeholder="日志内容"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="链路ID">
|
||||||
|
<el-input
|
||||||
|
v-model="query.tlogTraceId"
|
||||||
|
clearable
|
||||||
|
size="mini"
|
||||||
|
placeholder="请输入链路ID"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="时间">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="query.createTime"
|
||||||
|
type="datetimerange"
|
||||||
|
range-separator="至"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期">
|
||||||
|
</el-date-picker>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" size="mini" @click="queryData">
|
||||||
|
查询
|
||||||
|
</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
<!--表格渲染-->
|
<!--表格渲染-->
|
||||||
<el-table
|
<el-card shadow="hover" style="width: 100%" class="log-warpper">
|
||||||
ref="table"
|
<div style="width: 100%">
|
||||||
v-loading="crud.loading"
|
<div v-for="(log, index) in logs" :key="index">
|
||||||
:data="crud.data"
|
<div style="margin-bottom: 5px; font-size: 14px;" v-html="log" />
|
||||||
style="width: 100%;"
|
</div>
|
||||||
@selection-change="crud.selectionChangeHandler"
|
</div>
|
||||||
>
|
</el-card>
|
||||||
<!-- <el-table-column type="selection" width="55"/>-->
|
<!-- 分页 -->
|
||||||
<!-- <el-table-column v-if="false" prop="id" label="id"/>-->
|
<el-pagination
|
||||||
<el-table-column prop="operate" width="50" label="操作" />
|
:page-sizes="[100, 500, 1000]"
|
||||||
<el-table-column prop="device_code" label="设备号" />
|
:page-size.sync="query.size"
|
||||||
<el-table-column prop="task_code" label="任务编号" />
|
:total="query.total"
|
||||||
<el-table-column prop="instruct_code" label="指令编号" />
|
:current-page.sync="query.page"
|
||||||
<el-table-column prop="method" label="方法" />
|
style="margin-top: 8px;"
|
||||||
<el-table-column prop="status_code" label="状态码" />
|
layout="total, prev, pager, next, sizes"
|
||||||
<el-table-column prop="requestparam" label="请求参数" />
|
@size-change="handleSizeChange"
|
||||||
<el-table-column prop="responseparam" label="返回参数" />
|
@current-change="handleCurrentChange"
|
||||||
<el-table-column prop="logTime" width="170" label="记录时间" />
|
/>
|
||||||
<el-table-column prop="content" width="500" label="内容详情" />
|
|
||||||
|
|
||||||
</el-table>
|
|
||||||
<!--分页组件-->
|
|
||||||
<pagination />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Search from './search.vue'
|
import luceneOperation from '@/views/lucene/api/lucene'
|
||||||
import CRUD, { crud, header, presenter } from '@crud/crud'
|
import { default as AnsiUp } from 'ansi_up'
|
||||||
import crudOperation from '@crud/CRUD.operation'
|
|
||||||
import pagination from '@crud/Pagination'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'LuceneLog',
|
name: 'LuceneLog',
|
||||||
components: { Search, pagination, crudOperation },
|
|
||||||
mixins: [presenter(), header(), crud()],
|
|
||||||
cruds: function() {
|
|
||||||
return CRUD({
|
|
||||||
title: '系统参数', url: 'api/lucene/getAll', idField: 'id', sort: 'id,desc',
|
|
||||||
queryOnPresenterCreated: true,
|
|
||||||
optShow: {
|
|
||||||
add: false,
|
|
||||||
edit: false,
|
|
||||||
del: false,
|
|
||||||
download: false
|
|
||||||
},
|
|
||||||
page: {
|
|
||||||
size: 40,
|
|
||||||
total: 0,
|
|
||||||
page: 0
|
|
||||||
},
|
|
||||||
query: {
|
|
||||||
createTime: [new Date(new Date().setTime(new Date().getTime() - 3600 * 1000 * 24)), new Date()]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
query: { blurry: '123' },
|
|
||||||
permission: {
|
permission: {
|
||||||
add: ['admin', 'param:add'],
|
add: ['admin', 'param:add'],
|
||||||
edit: ['admin', 'param:edit'],
|
edit: ['admin', 'param:edit'],
|
||||||
del: ['admin', 'param:del']
|
del: ['admin', 'param:del']
|
||||||
},
|
},
|
||||||
|
levelOptions: [{
|
||||||
rules: {}
|
value: 'DEBUG',
|
||||||
|
label: 'DEBUG'
|
||||||
|
}, {
|
||||||
|
value: 'INFO',
|
||||||
|
label: 'INFO'
|
||||||
|
}, {
|
||||||
|
value: 'ERROR',
|
||||||
|
label: 'ERROR'
|
||||||
|
}, {
|
||||||
|
value: 'WARN',
|
||||||
|
label: 'WARN'
|
||||||
|
}],
|
||||||
|
rules: {},
|
||||||
|
logs: [],
|
||||||
|
query: {
|
||||||
|
tlogTraceId: '',
|
||||||
|
message: '',
|
||||||
|
page: 0,
|
||||||
|
size: 100,
|
||||||
|
total: 0,
|
||||||
|
createTime: ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
this.queryData()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 钩子:在获取表格数据之前执行,false 则代表不获取数据
|
handleSizeChange(val) {
|
||||||
[CRUD.HOOK.beforeRefresh]() {
|
this.query.size = val
|
||||||
return true
|
this.queryData()
|
||||||
},
|
},
|
||||||
confirmDelAll() {
|
handleCurrentChange(val) {
|
||||||
this.$confirm(`确认清空所有操作日志吗?`, '提示', {
|
this.query.page = val
|
||||||
confirmButtonText: '确定',
|
this.queryData()
|
||||||
cancelButtonText: '取消',
|
},
|
||||||
type: 'warning'
|
queryData() {
|
||||||
}).then(() => {
|
luceneOperation.getLogData(this.query).then(res => {
|
||||||
this.crud.delAllLoading = true
|
var ansi_up = new AnsiUp()
|
||||||
delAll('device_execute').then(res => {
|
// 数据初始化
|
||||||
this.crud.delAllLoading = false
|
for (const i in res.content) {
|
||||||
this.crud.dleChangePage(1)
|
this.logs[i] = ansi_up.ansi_to_html(res.content[i])
|
||||||
this.crud.delSuccessNotify()
|
}
|
||||||
this.crud.toQuery()
|
// this.logs = res.content
|
||||||
}).catch(err => {
|
this.query.total = res.totalElements
|
||||||
this.crud.delAllLoading = false
|
|
||||||
console.log(err.response.data.message)
|
|
||||||
})
|
|
||||||
}).catch(() => {
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +1,24 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="crud.props.searchToggle">
|
<div v-if="crud.props.searchToggle">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="query.device_code"
|
v-model="query.message"
|
||||||
clearable
|
clearable
|
||||||
size="small"
|
size="small"
|
||||||
placeholder="请输入你要搜索的设备号"
|
placeholder="请输入内容"
|
||||||
style="width: 200px;"
|
style="width: 200px;"
|
||||||
class="filter-item"
|
class="filter-item"
|
||||||
/>
|
/>
|
||||||
<el-input
|
<el-input
|
||||||
v-model="query.method"
|
v-model="query.tlogTraceId"
|
||||||
clearable
|
clearable
|
||||||
size="small"
|
size="small"
|
||||||
placeholder="请输入你要搜索的方法名"
|
placeholder="请输入链路ID"
|
||||||
style="width: 200px;"
|
|
||||||
class="filter-item"
|
|
||||||
/>
|
|
||||||
<el-input
|
|
||||||
v-model="query.status_code"
|
|
||||||
clearable
|
|
||||||
size="small"
|
|
||||||
placeholder="请输入你要搜索的状态码"
|
|
||||||
style="width: 200px;"
|
|
||||||
class="filter-item"
|
|
||||||
/>
|
|
||||||
<el-input
|
|
||||||
v-model="query.requestparam"
|
|
||||||
clearable
|
|
||||||
size="small"
|
|
||||||
placeholder="请输入你要搜索的请求参数"
|
|
||||||
style="width: 200px;"
|
|
||||||
class="filter-item"
|
|
||||||
/>
|
|
||||||
<el-input
|
|
||||||
v-model="query.responseparam"
|
|
||||||
clearable
|
|
||||||
size="small"
|
|
||||||
placeholder="请输入你要搜索的返回参数"
|
|
||||||
style="width: 200px;"
|
|
||||||
class="filter-item"
|
|
||||||
/>
|
|
||||||
<el-input
|
|
||||||
v-model="query.blurry"
|
|
||||||
clearable
|
|
||||||
size="small"
|
|
||||||
placeholder="请输入你要搜索的内容详情"
|
|
||||||
style="width: 200px;"
|
style="width: 200px;"
|
||||||
class="filter-item"
|
class="filter-item"
|
||||||
/>
|
/>
|
||||||
<!--
|
<!--
|
||||||
<date-range-picker v-model="query.createTime" class="date-item" />
|
<date-range-picker v-model="query.createTime" class="date-item" />
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-model="query.createTime"
|
v-model="query.createTime"
|
||||||
type="datetimerange"
|
type="datetimerange"
|
||||||
|
|||||||
Reference in New Issue
Block a user