init project v1.0.0

This commit is contained in:
zlt
2019-01-19 15:31:26 +08:00
parent 5c1cdaa54e
commit 19fecc3b05
728 changed files with 65634 additions and 0 deletions
@@ -0,0 +1,16 @@
package com.central;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author zlt
*/
@EnableDiscoveryClient
@SpringBootApplication
public class LogApp {
public static void main(String[] args) {
SpringApplication.run(LogApp.class, args);
}
}
@@ -0,0 +1,14 @@
package com.central.log.config;
import com.central.common.exception.DefaultExceptionAdvice;
import org.springframework.web.bind.annotation.ControllerAdvice;
/**
* 统一异常处理
*
* @author zlt
* @date 2018/12/22
*/
@ControllerAdvice
public class ExceptionAdvice extends DefaultExceptionAdvice {
}
@@ -0,0 +1,31 @@
package com.central.log.controller;
import com.central.common.model.PageResult;
import org.apache.commons.collections4.MapUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
/**
* 日志父类
*
* @author zlt
*/
public class LogController<E> {
public PageResult<E> getPage(@RequestParam Map<String, Object> params, BoolQueryBuilder builder, ElasticsearchRepository repository) {
// 分页参数
Pageable pageable = PageRequest.of(MapUtils.getInteger(params, "page") - 1, MapUtils.getInteger(params, "limit")
, Sort.Direction.DESC, "timestamp");
SearchQuery query = new NativeSearchQueryBuilder().withQuery(builder).withPageable(pageable).build();
Page<E> result = (Page<E>)repository.search(query);
return PageResult.<E>builder().data(result.getContent()).code(0).count(result.getTotalElements()).build();
}
}
@@ -0,0 +1,50 @@
package com.central.log.controller;
import cn.hutool.core.util.StrUtil;
import com.central.common.model.PageResult;
import com.central.log.dao.SlowQueryLogDao;
import com.central.log.model.SlowQueryLog;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* 慢查询日志
*
* @author zlt
*/
@RestController
public class SlowQueryLogController extends LogController<SlowQueryLog> {
private static final String ES_PARAM_QUERY = "query_str";
@Autowired
public SlowQueryLogDao logDao;
@ApiOperation(value = "系统日志查询列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
})
@GetMapping(value = "/slowQueryLog")
public PageResult<SlowQueryLog> getPage(@RequestParam Map<String, Object> params) {
BoolQueryBuilder builder = QueryBuilders.boolQuery();
String searchKey = (String) params.get("searchKey");
String searchValue = (String) params.get("searchValue");
if (StrUtil.isNotEmpty(searchKey)) {
if (ES_PARAM_QUERY.equals(searchKey)) {
// 模糊查询
builder.must(QueryBuilders.matchPhraseQuery(ES_PARAM_QUERY, searchValue.toUpperCase()));
}
}
return super.getPage(params, builder, logDao);
}
}
@@ -0,0 +1,64 @@
package com.central.log.controller;
import java.util.*;
import cn.hutool.core.util.StrUtil;
import com.central.common.model.PageResult;
import com.central.log.dao.SysLogDao;
import com.central.log.model.SysLog;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.index.query.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 系统日志
*
* @author zlt
*/
@RestController
public class SysLogController extends LogController<SysLog> {
private static final String ES_PARAM_MESSAGE = "message";
private static final String ES_PARAM_LOG_LEVEL = "logLevel";
private static final String ES_PARAM_APP_NAME = "appName";
private static final String ES_PARAM_CLASSNAME = "classname";
@Autowired
public SysLogDao logDao;
@ApiOperation(value = "系统日志查询列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
})
@GetMapping(value = "/sysLog")
public PageResult<SysLog> getPage(@RequestParam Map<String, Object> params) {
BoolQueryBuilder builder = QueryBuilders.boolQuery();
String searchKey = (String) params.get("searchKey");
String searchValue = (String) params.get("searchValue");
if (StrUtil.isNotEmpty(searchKey)) {
if (ES_PARAM_MESSAGE.equals(searchKey)) {
// 整词模糊查询 日志信息
builder.must(QueryBuilders.matchPhraseQuery(ES_PARAM_MESSAGE, searchValue));
}
if (ES_PARAM_LOG_LEVEL.equals(searchKey)) {
// 模糊查询
builder.must(QueryBuilders.matchPhraseQuery(ES_PARAM_LOG_LEVEL, searchValue.toUpperCase()));
}
if (ES_PARAM_APP_NAME.equals(searchKey)) {
// 模糊查询
builder.must(QueryBuilders.fuzzyQuery(ES_PARAM_APP_NAME, searchValue));
}
if (ES_PARAM_CLASSNAME.equals(searchKey)) {
// 模糊查询
builder.must(QueryBuilders.fuzzyQuery(ES_PARAM_CLASSNAME, searchValue));
}
}
return super.getPage(params, builder, logDao);
}
}
@@ -0,0 +1,13 @@
package com.central.log.dao;
import com.central.log.model.SlowQueryLog;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Component;
/**
* @author zlt
*/
@Component
public interface SlowQueryLogDao extends ElasticsearchRepository<SlowQueryLog, String> {
}
@@ -0,0 +1,13 @@
package com.central.log.dao;
import com.central.log.model.SysLog;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Component;
/**
* @author zlt
*/
@Component
public interface SysLogDao extends ElasticsearchRepository<SysLog, String> {
}
@@ -0,0 +1,27 @@
package com.central.log.model;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import java.util.Date;
/**
* 慢查询日志对象
*
* @author zlt
*/
@Data
@Document(indexName = "mysql-slowlog-*", type = "doc")
public class SlowQueryLog {
@Id
private String id;
private Date timestamp;
private String query_str;
private String user;
private String clientip;
private Float query_time;
private Float lock_time;
private Long rows_sent;
private Long rows_examined;
}
@@ -0,0 +1,27 @@
package com.central.log.model;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import java.util.Date;
/**
* 系统日志对象
*
* @author zlt
*/
@Data
@Document(indexName = "sys-log-*", type = "doc")
public class SysLog {
@Id
private String id;
private Date timestamp;
private String message;
private String threadName;
private String serverPort;
private String serverIp;
private String logLevel;
private String appName;
private String classname;
}