add:es日志,接入未测试
todo:添加日志删除按钮及日志条数显示
This commit is contained in:
137
mes/hd/nladmin-system/src/main/java/org/nl/aspect/LogAspect.java
Normal file
137
mes/hd/nladmin-system/src/main/java/org/nl/aspect/LogAspect.java
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.aspect;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.nl.modules.system.util.BaseCode;
|
||||
import org.nl.utils.RequestHolder;
|
||||
import org.nl.utils.SecurityUtils;
|
||||
import org.nl.utils.StringUtils;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Component
|
||||
@Aspect
|
||||
@Slf4j
|
||||
public class LogAspect {
|
||||
|
||||
|
||||
@Pointcut("execution(* org.nl.wms.*.rest..*.*(..))")
|
||||
public void logPointCut() {
|
||||
}
|
||||
|
||||
@Around("logPointCut()")
|
||||
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
String params = getParameter(method, joinPoint.getArgs());
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
String url = request.getRequestURI();
|
||||
|
||||
MDC.put("requestMethod",url);
|
||||
MDC.put("requestIp", StringUtils.getIp(request));
|
||||
MDC.put("traceId", BaseCode.intToChars(IdUtil.getSnowflake(1, 1).nextId()));
|
||||
MDC.put("requestTime", DateUtil.now());
|
||||
|
||||
Object result;
|
||||
long comming = System.currentTimeMillis();
|
||||
try {
|
||||
log.info("[--request--][请求接口:{}][请求参数:{}]",url,params);
|
||||
result = joinPoint.proceed();
|
||||
|
||||
}catch (Exception ex){
|
||||
StringBuffer errorStack = new StringBuffer();
|
||||
errorStack.append("<br/>【异常堆栈:");
|
||||
String errorMsg = ex.getMessage();
|
||||
int x = 0;
|
||||
StackTraceElement[] stackTrace = ex.getStackTrace();
|
||||
if (stackTrace!=null && stackTrace.length>0){
|
||||
for (StackTraceElement stack : stackTrace) {
|
||||
x++;errorStack.append(stack.toString().replaceAll("<",">")).append("<br/>");
|
||||
if (x>10){ break; }
|
||||
}
|
||||
}
|
||||
log.error("[-requestError-][请求接口:{}]【异常信息:{}】[请求参数:{}] {}", url,errorMsg,params, errorStack.append("】").toString());
|
||||
throw ex;
|
||||
}finally {
|
||||
log.info("[--response--][请求接口:{} 执行结束][耗时:{}s]",url,(System.currentTimeMillis() - comming)/1000);
|
||||
MDC.clear();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据方法和传入的参数获取请求参数
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
try {
|
||||
return SecurityUtils.getCurrentUsername();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.nl.config;
|
||||
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.filter.FilterEventAdapter;
|
||||
import com.alibaba.druid.proxy.jdbc.JdbcParameter;
|
||||
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.StatementProxy;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import com.mysql.cj.jdbc.result.ResultSetImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.MDC;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2023/2/10 11:27 上午
|
||||
*/
|
||||
@Slf4j
|
||||
public class DruidFilter extends FilterEventAdapter {
|
||||
|
||||
@Override
|
||||
public int preparedStatement_executeUpdate(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
|
||||
|
||||
return super.preparedStatement_executeUpdate(chain, statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
|
||||
|
||||
return super.statement_executeUpdate(chain, statement, sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void statementExecuteAfter(StatementProxy statement, String sql, boolean result) {
|
||||
String traceId = MDC.get("traceId");
|
||||
int size = statement.getParametersSize();
|
||||
String executeSql = sql;
|
||||
int count = 0;
|
||||
try {
|
||||
count=statement.getUpdateCount();
|
||||
}catch (Exception ex){ }
|
||||
if (StringUtils.isNotEmpty(traceId) && count>0) {
|
||||
if (size > 0) {
|
||||
Collection<JdbcParameter> values = statement.getParameters().values();
|
||||
List<Object> params = new ArrayList<>();
|
||||
for (JdbcParameter value : values) {
|
||||
params.add(value.getValue());
|
||||
}
|
||||
executeSql = SQLUtils.format(executeSql, JdbcUtils.MYSQL, params);
|
||||
}
|
||||
log.info("[----SQL----][update][ SQL: {} ]", executeSql);
|
||||
}
|
||||
super.statementExecuteAfter(statement, sql, result);
|
||||
}
|
||||
@Override
|
||||
public ResultSetProxy statement_getResultSet(FilterChain chain, StatementProxy statement) throws SQLException {
|
||||
ResultSetProxy rs = super.statement_getResultSet(chain, statement);
|
||||
String executeSql = statement.getLastExecuteSql();
|
||||
String traceId = MDC.get("traceId");
|
||||
if (StringUtils.isNotEmpty(traceId)){
|
||||
int result = 0;
|
||||
if (rs != null) {
|
||||
ResultSetImpl rss = rs.getResultSetRaw().unwrap(ResultSetImpl.class);
|
||||
result = rss.getRows().size();
|
||||
}
|
||||
try {
|
||||
int size = statement.getParametersSize();
|
||||
if (size>0){
|
||||
Collection<JdbcParameter> values = statement.getParameters().values();
|
||||
List<Object> params = new ArrayList<>();
|
||||
for (JdbcParameter value : values) {
|
||||
params.add(value.getValue());
|
||||
}
|
||||
executeSql = SQLUtils.format(executeSql, JdbcUtils.MYSQL, params);
|
||||
}
|
||||
}catch (Exception ex){
|
||||
log.warn("[-SQL解析异常-][{}]",ex.getMessage());
|
||||
}
|
||||
log.info("[----SQL----][select][执行结果:{}][ SQL: {} ]",result, executeSql);
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.nl.config;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2023/2/13 9:58 上午
|
||||
*/
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ESConfig {
|
||||
|
||||
@Value(("${es.index}"))
|
||||
private String index;
|
||||
|
||||
|
||||
public String getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(String index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,6 @@ public class WebSocketServer {
|
||||
* */
|
||||
public static void sendInfo(SocketMsg socketMsg,@PathParam("sid") String sid) throws IOException {
|
||||
String message = JSONObject.toJSONString(socketMsg);
|
||||
log.info("推送消息到"+sid+",推送内容:"+message);
|
||||
for (WebSocketServer item : webSocketSet) {
|
||||
try {
|
||||
//这里可以设定只推送给这个sid的,为null则全部推送
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.nl.modules.system.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2023/2/8 4:06 下午
|
||||
*/
|
||||
@Document(indexName = "#{@ESConfig.index}", type = "whxr_log")
|
||||
@Data
|
||||
public class LogRepositoryDTO {
|
||||
|
||||
private String message;
|
||||
private String host;
|
||||
private String logLevel;
|
||||
private String logger;
|
||||
private String requestTime;
|
||||
private String requestIp;
|
||||
@Id
|
||||
private String id;
|
||||
private String traceId;
|
||||
private String requestMethod;
|
||||
private String thread;
|
||||
private String system;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.nl.modules.system.enums;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public enum LevelEnum {
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR;
|
||||
public static LevelEnum checkLevel(String level){
|
||||
if (!StringUtils.isEmpty(level)){
|
||||
for (LevelEnum value : LevelEnum.values()) {
|
||||
if (value.name().equals(level)){
|
||||
return value;
|
||||
};
|
||||
}
|
||||
}
|
||||
return LevelEnum.DEBUG;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.nl.modules.system.repository;
|
||||
|
||||
import org.nl.modules.system.domain.LogRepositoryDTO;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2023/2/8 4:11 下午
|
||||
*/
|
||||
@Repository
|
||||
public interface EsLogRepository extends ElasticsearchRepository<LogRepositoryDTO, String> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.nl.modules.system.rest;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.system.service.EsLogService;
|
||||
import org.nl.modules.system.service.dto.LogQuery;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author ldjun
|
||||
* @version 1.0
|
||||
* @date 2023年01月29日 18:55
|
||||
* @desc desc
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/esLog")
|
||||
public class EsLogController {
|
||||
private final EsLogService esLogService;
|
||||
|
||||
|
||||
@GetMapping("/labels/{type}")
|
||||
@ApiOperation("获取标签")
|
||||
public ResponseEntity<Object> labelsValues(@PathVariable String type) {
|
||||
return new ResponseEntity<>(esLogService.getLabelsValues(type), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
@ApiOperation("日志查询")
|
||||
public ResponseEntity<Object> queryAll(@RequestBody LogQuery query) {
|
||||
return new ResponseEntity<>(esLogService.query(query), HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.nl.modules.system.service;
|
||||
|
||||
import cn.hutool.db.PageResult;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import org.nl.modules.system.service.dto.LogQuery;
|
||||
|
||||
/**
|
||||
* @author ldjun
|
||||
* @version 1.0
|
||||
* @date 2023年02月07日 14:34
|
||||
* @desc desc
|
||||
*/
|
||||
public interface EsLogService {
|
||||
/**
|
||||
* 获取labels和values树
|
||||
* @return
|
||||
*/
|
||||
JSONArray getLabelsValues(String type);
|
||||
|
||||
/**
|
||||
* 日志查询
|
||||
* @param logQuery
|
||||
* @return
|
||||
*/
|
||||
PageResult query(LogQuery logQuery);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.nl.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2023/2/8 5:18 下午
|
||||
*/
|
||||
@Data
|
||||
public class LogQuery {
|
||||
/**
|
||||
* 创建时间范围查询
|
||||
*/
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
/**
|
||||
* 追踪id
|
||||
*/
|
||||
private String traceId;
|
||||
/**
|
||||
* 日志内容模糊匹配
|
||||
*/
|
||||
private String message;
|
||||
/**
|
||||
* 日志级别
|
||||
*/
|
||||
private String logLevel;
|
||||
/**
|
||||
* 系统标签
|
||||
*/
|
||||
private String system;
|
||||
/**
|
||||
* 是否只查询Http相关请求
|
||||
*/
|
||||
private Boolean isRequest = Boolean.TRUE;
|
||||
/**
|
||||
* 是否过滤wql日志
|
||||
*/
|
||||
private Boolean filterSql = Boolean.TRUE;
|
||||
|
||||
private Integer size = 20;
|
||||
|
||||
private Integer page = 1;
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package org.nl.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.db.PageResult;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.nl.modules.system.domain.LogRepositoryDTO;
|
||||
import org.nl.modules.system.enums.LevelEnum;
|
||||
import org.nl.modules.system.repository.EsLogRepository;
|
||||
import org.nl.modules.system.service.EsLogService;
|
||||
import org.nl.modules.system.service.dto.LogQuery;
|
||||
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.FetchSourceFilter;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ldjun
|
||||
* @version 1.0
|
||||
* @date 2023年02月07日 14:35
|
||||
* @desc desc
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EsLogServiceImpl implements EsLogService {
|
||||
|
||||
private final EsLogRepository esLogRepository;
|
||||
|
||||
private final ElasticsearchRestTemplate elasticsearchRestTemplate;
|
||||
|
||||
@Override
|
||||
public PageResult query(LogQuery logQuery){
|
||||
PageResult page = new PageResult();
|
||||
if (logQuery != null){
|
||||
BoolQueryBuilder query = QueryBuilders.boolQuery(); //requestMethod
|
||||
extractedParam(logQuery, query);
|
||||
Iterable<LogRepositoryDTO> all = esLogRepository.search(query, PageRequest.of(logQuery.getPage()-1,logQuery.getSize(), Sort.by("@timestamp").descending()));
|
||||
page.addAll(((AggregatedPageImpl) all).getContent());
|
||||
page.setTotal((int) ((AggregatedPageImpl) all).getTotalElements());
|
||||
page.setPage(logQuery.getPage());
|
||||
page.setPageSize(logQuery.getSize());
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
private void extractedParam(LogQuery logQuery, BoolQueryBuilder query) {
|
||||
if (StringUtils.isNotEmpty(logQuery.getLogLevel())){
|
||||
query.must().add(QueryBuilders.matchQuery("logLevel", LevelEnum.checkLevel(logQuery.getLogLevel())));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(logQuery.getSystem())){
|
||||
query.must().add(QueryBuilders.matchQuery("system", logQuery.getSystem()));
|
||||
}
|
||||
if (logQuery.getIsRequest()){
|
||||
query.must().add(QueryBuilders.existsQuery("requestMethod"));
|
||||
}
|
||||
if (logQuery.getFilterSql()){
|
||||
query.mustNot().add(QueryBuilders.wildcardQuery("logger","org.nl.modules.wql.core.engine.*"));
|
||||
}
|
||||
query.mustNot().add(QueryBuilders.matchPhraseQuery("logger","org.elasticsearch.client.RestClient"));
|
||||
if (StringUtils.isNotEmpty(logQuery.getTraceId())){
|
||||
query.must().add(QueryBuilders.matchQuery("traceId", logQuery.getTraceId()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(logQuery.getMessage())){
|
||||
query.must().add(QueryBuilders.matchPhraseQuery("message", logQuery.getMessage()));
|
||||
}
|
||||
if (logQuery.getEndTime()!=null ){
|
||||
String script = "doc['@timestamp'].value.millis < " + logQuery.getEndTime().getTime() + "L";
|
||||
query.must().add(QueryBuilders.scriptQuery(new Script(script)));
|
||||
}
|
||||
if (logQuery.getStartTime()!=null){
|
||||
String script = "doc['@timestamp'].value.millis > " + logQuery.getStartTime().getTime() + "L";
|
||||
query.must().add(QueryBuilders.scriptQuery(new Script(script)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public JSONArray getLabelsValues(String type) {
|
||||
JSONArray result = new JSONArray();
|
||||
FetchSourceFilter fetchSourceFilter = new FetchSourceFilter(new String[]{type}, null);
|
||||
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder();
|
||||
queryBuilder.withCollapseField(type+".keyword");
|
||||
queryBuilder.withSourceFilter(fetchSourceFilter);
|
||||
queryBuilder.addAggregation(AggregationBuilders.terms(type).field(type+".keyword").size(100));
|
||||
Aggregations agg = elasticsearchRestTemplate.query(queryBuilder.build(), SearchResponse::getAggregations);
|
||||
Terms terms = agg.get(type);
|
||||
List<? extends Terms.Bucket> buckets = terms.getBuckets();
|
||||
if (!CollectionUtils.isEmpty(buckets)){
|
||||
buckets.stream().map(Terms.Bucket::getKeyAsString).forEach(v-> {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("label", v);
|
||||
item.put("value", v);
|
||||
result.add(item);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
* @return /
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(key = "'user:' + #p0")
|
||||
// @Cacheable(key = "'user:' + #p0")
|
||||
public List<MenuDto> findByUser(Long currentUserId) {
|
||||
List<RoleSmallDto> roles = roleService.findByUsersId(currentUserId);
|
||||
Set<Long> roleIds = roles.stream().map(RoleSmallDto::getId).collect(Collectors.toSet());
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.nl.modules.system.util;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2023/2/9 2:54 下午
|
||||
*/
|
||||
public class BaseCode {
|
||||
|
||||
static final char[] MySerials = new char[]{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p','q','r','s','t','u','v','w','x','y','z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P','Q','R','S','T','U','V','W','X','Y','Z'};
|
||||
|
||||
|
||||
public static final String intToChars(long n){
|
||||
String s = "";
|
||||
if (n == 0) {
|
||||
s = "0";
|
||||
}
|
||||
while (n != 0) {
|
||||
int i = (int) (n % MySerials.length);
|
||||
char c = MySerials[i];
|
||||
s = c + s;
|
||||
n = n / MySerials.length;
|
||||
}
|
||||
for (int x = s.length();x<5;x++){
|
||||
s="0"+s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -47,12 +47,12 @@ public class Init implements ApplicationRunner, BeanFactoryAware, ApplicationCon
|
||||
private void init() throws Exception {
|
||||
//初始化WQL
|
||||
initWql();
|
||||
//随线程启动
|
||||
initApplicationAutoInitialExecuter();
|
||||
initWebAutoInitialExecuter();
|
||||
//初始化任务调度
|
||||
initQuartz();
|
||||
//用户岗位表【sys_users_roles】
|
||||
// //随线程启动
|
||||
// initApplicationAutoInitialExecuter();
|
||||
// initWebAutoInitialExecuter();
|
||||
// //初始化任务调度
|
||||
// initQuartz();
|
||||
// //用户岗位表【sys_users_roles】
|
||||
System.out.println("项目启动成功!");
|
||||
}
|
||||
private void initOracle(){
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "es.index",
|
||||
"type": "java.lang.String",
|
||||
"description": "Description for es.index."
|
||||
}
|
||||
] }
|
||||
@@ -0,0 +1 @@
|
||||
druid.filters.DruidFilter=org.nl.config.DruidFilter
|
||||
@@ -15,6 +15,22 @@ erp:
|
||||
|
||||
#配置数据源
|
||||
spring:
|
||||
data:
|
||||
elasticsearch:
|
||||
repositories:
|
||||
enabled: true
|
||||
client:
|
||||
reactive:
|
||||
#endpoints: 172.31.185.110:9200,172.31.154.9:9200 #内网
|
||||
endpoints: 47.96.133.178:8200 #外网
|
||||
# endpoints: http://10.1.3.90:9200 #外网
|
||||
elasticsearch:
|
||||
rest:
|
||||
#uris: 172.31.185.110:9200,172.31.154.9:9200 #内网
|
||||
uris: 47.96.133.178:8200 #外网
|
||||
# uris: http://10.1.3.90:9200 #外网
|
||||
username: elastic
|
||||
password: 123456
|
||||
datasource:
|
||||
druid:
|
||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||
@@ -58,16 +74,8 @@ spring:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
reset-enable: false
|
||||
filter:
|
||||
stat:
|
||||
enabled: true
|
||||
# 记录慢SQL
|
||||
log-slow-sql: true
|
||||
slow-sql-millis: 1000
|
||||
merge-sql: true
|
||||
wall:
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
filters:
|
||||
DruidFilter,stat
|
||||
redis:
|
||||
#数据库索引
|
||||
database: 2
|
||||
@@ -158,4 +166,6 @@ logging:
|
||||
file:
|
||||
path: C:\log\wms
|
||||
config: classpath:logback-spring.xml
|
||||
es:
|
||||
index: whxr_log
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ spring:
|
||||
freemarker:
|
||||
check-template-location: false
|
||||
profiles:
|
||||
active: prod
|
||||
active: dev
|
||||
jackson:
|
||||
time-zone: GMT+8
|
||||
data:
|
||||
|
||||
@@ -14,6 +14,7 @@ https://juejin.cn/post/6844903775631572999
|
||||
<property name="log.pattern"
|
||||
value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)"/>
|
||||
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/>
|
||||
<springProperty scope="context" name="esIndex" source="es.index"/>
|
||||
<property name="LOG_HOME" value="${logPath}"/>
|
||||
<!--引入默认的一些设置-->
|
||||
<include resource="log/XrToMes.xml"/>
|
||||
@@ -48,6 +49,66 @@ https://juejin.cn/post/6844903775631572999
|
||||
</encoder>
|
||||
|
||||
</appender>
|
||||
<appender name="esLogAppender" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
|
||||
<url>http://47.96.133.178:8200/_bulk</url>
|
||||
<index>${esIndex}</index>
|
||||
<type>whxr_log</type>
|
||||
<loggerName>es-logger</loggerName> <!-- optional -->
|
||||
<errorLoggerName>es-error-logger</errorLoggerName> <!-- optional -->
|
||||
<connectTimeout>30000</connectTimeout> <!-- optional (in ms, default 30000) -->
|
||||
<errorsToStderr>false</errorsToStderr> <!-- optional (default false) -->
|
||||
<includeCallerData>false</includeCallerData> <!-- optional (default false) -->
|
||||
<logsToStderr>false</logsToStderr> <!-- optional (default false) -->
|
||||
<maxQueueSize>104857600</maxQueueSize> <!-- optional (default 104857600) -->
|
||||
<maxRetries>3</maxRetries> <!-- optional (default 3) -->
|
||||
<readTimeout>30000</readTimeout> <!-- optional (in ms, default 30000) -->
|
||||
<sleepTime>250</sleepTime> <!-- optional (in ms, default 250) -->
|
||||
<rawJsonMessage>false</rawJsonMessage> <!-- optional (default false) -->
|
||||
<includeMdc>false</includeMdc> <!-- optional (default false) -->
|
||||
<maxMessageSize>20000</maxMessageSize> <!-- optional (default -1 -->
|
||||
<!-- <authentication class="com.internetitem.logback.elasticsearch.config.BasicAuthentication" /> <!– optional –>-->
|
||||
<properties>
|
||||
<property>
|
||||
<name>system</name>
|
||||
<value>mes</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>traceId</name>
|
||||
<value>%X{traceId}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>logLevel</name>
|
||||
<value>%level</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>requestMethod</name>
|
||||
<value>%X{requestMethod}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>requestTime</name>
|
||||
<value>%d{yyyy-MM-dd HH:mm:ss.SSS}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>requestIp</name>
|
||||
<value>%X{requestIp}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>thread</name>
|
||||
<value>%thread</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>logger</name>
|
||||
<value>%logger</value>
|
||||
</property>
|
||||
</properties>
|
||||
<headers>
|
||||
<header>
|
||||
<name>Content-Type</name>
|
||||
<value>application/json</value>
|
||||
</header>
|
||||
</headers>
|
||||
</appender>
|
||||
|
||||
|
||||
<!--异步到文件-->
|
||||
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
@@ -58,9 +119,14 @@ https://juejin.cn/post/6844903775631572999
|
||||
|
||||
<!--开发环境:打印控制台-->
|
||||
<springProfile name="dev">
|
||||
<root level="debug">
|
||||
<root level="info">
|
||||
<appender-ref ref="esLogAppender"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
<!-- <logger name="es-logger" level="warn" additivity="false">-->
|
||||
<!-- <appender-ref ref="esLogAppender"/>-->
|
||||
<!-- <appender-ref ref="CONSOLE"/>-->
|
||||
<!-- </logger>-->
|
||||
<logger name="org.springframework" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
@@ -99,10 +165,14 @@ https://juejin.cn/post/6844903775631572999
|
||||
|
||||
<!--生产环境:打印控制台和输出到文件-->
|
||||
<springProfile name="prod">
|
||||
<root level="debug">
|
||||
<!-- <appender-ref ref="CONSOLE"/>-->
|
||||
<root level="info">
|
||||
<appender-ref ref="esLogAppender"/>
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</root>
|
||||
<logger name="es-logger" level="warn" additivity="false">
|
||||
<appender-ref ref="esLogAppender"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
<logger name="org.springframework" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
|
||||
Reference in New Issue
Block a user