update to v2.0.0,新增搜索中心,并集成用户中心和日志中心;首页新增流量统计

This commit is contained in:
zlt
2019-05-09 23:28:41 +08:00
parent 5d4c30df4b
commit a68441003a
108 changed files with 2356 additions and 278 deletions
@@ -1,5 +1,6 @@
package com.central;
import com.central.search.annotation.EnableSearchClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@@ -8,6 +9,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
* @author zlt
*/
@EnableDiscoveryClient
@EnableSearchClient
@SpringBootApplication
public class LogApp {
public static void main(String[] args) {
@@ -0,0 +1,27 @@
package com.central.log.controller;
import com.central.search.client.service.IQueryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* 访问统计
*
* @author zlt
* @date 2019/5/8
*/
@RestController
public class AggregationController {
@Autowired
private IQueryService queryService;
@ApiOperation(value = "访问统计")
@GetMapping(value = "/requestStat")
public Map<String, Object> requestStatAgg() {
return queryService.requestStatAgg("point-log-*","request-statistics");
}
}
@@ -1,31 +0,0 @@
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();
}
}
@@ -1,48 +1,36 @@
package com.central.log.controller;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.central.common.model.PageResult;
import com.central.log.dao.SlowQueryLogDao;
import com.central.log.model.SlowQueryLog;
import com.central.search.client.service.IQueryService;
import com.central.search.model.SearchDto;
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";
public class SlowQueryLogController {
@Autowired
public SlowQueryLogDao logDao;
private IQueryService queryService;
@ApiOperation(value = "系统日志查询列表")
@ApiOperation(value = "慢sql日志全文搜索列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer"),
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
})
@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) && StrUtil.isNotEmpty(searchValue)) {
// 模糊查询
builder.must(QueryBuilders.matchQuery(ES_PARAM_QUERY, searchValue));
}
return super.getPage(params, builder, logDao);
public PageResult<JSONObject> getPage(SearchDto searchDto) {
searchDto.setIsHighlighter(true);
searchDto.setSortCol("timestamp");
return queryService.strQuery("mysql-slowlog-*", searchDto);
}
}
@@ -1,18 +1,14 @@
package com.central.log.controller;
import java.util.*;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.central.common.model.PageResult;
import com.central.log.dao.SysLogDao;
import com.central.log.model.SysLog;
import com.central.search.client.service.IQueryService;
import com.central.search.model.SearchDto;
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;
/**
@@ -21,32 +17,20 @@ 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";
public class SysLogController {
@Autowired
public SysLogDao logDao;
private IQueryService queryService;
@ApiOperation(value = "系统日志查询列表")
@ApiOperation(value = "系统日志全文搜索列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer"),
@ApiImplicitParam(name = "queryStr", value = "搜索关键字", dataType = "String")
})
@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) && StrUtil.isNotEmpty(searchValue)) {
if (ES_PARAM_LOG_LEVEL.equals(searchKey)) {
searchValue = searchValue.toUpperCase();
}
// 模糊查询
builder.must(QueryBuilders.matchQuery(searchKey, searchValue));
}
return super.getPage(params, builder, logDao);
public PageResult<JSONObject> getPage(SearchDto searchDto) {
searchDto.setIsHighlighter(true);
searchDto.setSortCol("timestamp");
return queryService.strQuery("sys-log-*", searchDto);
}
}
@@ -1,13 +0,0 @@
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> {
}
@@ -1,13 +0,0 @@
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> {
}
@@ -1,27 +0,0 @@
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;
}
@@ -1,27 +0,0 @@
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;
}