update to v2.0.0,新增搜索中心,并集成用户中心和日志中心;首页新增流量统计
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>search-center</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>search-client</artifactId>
|
||||
<description>搜索中心客户端</description>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-sentinel-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.central.search.annotation;
|
||||
|
||||
import com.central.search.client.service.impl.QueryServiceImpl;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 控制是否加载搜索中心客户端的Service
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@EnableFeignClients
|
||||
@Import(QueryServiceImpl.class)
|
||||
public @interface EnableSearchClient {
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.central.search.client.feign;
|
||||
|
||||
import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.search.client.feign.fallback.SearchServiceFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@FeignClient(name = ServiceNameConstants.SEARCH_SERVICE, fallbackFactory = SearchServiceFallbackFactory.class, decode404 = true)
|
||||
public interface AggregationService {
|
||||
/**
|
||||
* 查询文档列表
|
||||
* @param indexName 索引名
|
||||
* @param routing es的路由
|
||||
*/
|
||||
@GetMapping(value = "/agg/requestStat/{indexName}/{routing}")
|
||||
Map<String, Object> requestStatAgg(@PathVariable("indexName") String indexName, @PathVariable("routing") String routing);
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.central.search.client.feign;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.search.client.feign.fallback.SearchServiceFallbackFactory;
|
||||
import com.central.search.model.SearchDto;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@FeignClient(name = ServiceNameConstants.SEARCH_SERVICE, fallbackFactory = SearchServiceFallbackFactory.class, decode404 = true)
|
||||
public interface SearchService {
|
||||
/**
|
||||
* 查询文档列表
|
||||
* @param indexName 索引名
|
||||
* @param searchDto 搜索Dto
|
||||
*/
|
||||
@PostMapping(value = "/search/{indexName}")
|
||||
PageResult<JSONObject> strQuery(@PathVariable("indexName") String indexName, @RequestBody SearchDto searchDto);
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.central.search.client.feign.fallback;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.central.search.client.feign.AggregationService;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* searchService降级工场
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AggregationServiceFallbackFactory implements FallbackFactory<AggregationService> {
|
||||
@Override
|
||||
public AggregationService create(Throwable throwable) {
|
||||
return (indexName, routing) -> {
|
||||
log.error("通过索引{}搜索异常:{}", indexName, throwable);
|
||||
return MapUtil.newHashMap(0);
|
||||
};
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.central.search.client.feign.fallback;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.search.client.feign.SearchService;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* searchService降级工场
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SearchServiceFallbackFactory implements FallbackFactory<SearchService> {
|
||||
@Override
|
||||
public SearchService create(Throwable throwable) {
|
||||
return (indexName, searchDto) -> {
|
||||
log.error("通过索引{}搜索异常:{}", indexName, throwable);
|
||||
return PageResult.<JSONObject>builder().build();
|
||||
};
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.central.search.client.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.search.model.LogicDelDto;
|
||||
import com.central.search.model.SearchDto;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 搜索客户端接口
|
||||
*
|
||||
* @author zlt
|
||||
* @date 2019/4/24
|
||||
*/
|
||||
public interface IQueryService {
|
||||
/**
|
||||
* 查询文档列表
|
||||
* @param indexName 索引名
|
||||
* @param searchDto 搜索Dto
|
||||
*/
|
||||
PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto);
|
||||
|
||||
/**
|
||||
* 查询文档列表
|
||||
* @param indexName 索引名
|
||||
* @param searchDto 搜索Dto
|
||||
* @param logicDelDto 逻辑删除Dto
|
||||
*/
|
||||
PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto, LogicDelDto logicDelDto);
|
||||
|
||||
/**
|
||||
* 访问统计聚合查询
|
||||
* @param indexName 索引名
|
||||
* @param routing es的路由
|
||||
*/
|
||||
Map<String, Object> requestStatAgg(String indexName, String routing);
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package com.central.search.client.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.search.client.feign.AggregationService;
|
||||
import com.central.search.client.feign.SearchService;
|
||||
import com.central.search.client.service.IQueryService;
|
||||
import com.central.search.model.LogicDelDto;
|
||||
import com.central.search.model.SearchDto;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 搜索客户端Service
|
||||
*
|
||||
* @author zlt
|
||||
* @date 2019/4/24
|
||||
*/
|
||||
public class QueryServiceImpl implements IQueryService {
|
||||
@Resource
|
||||
private SearchService searchService;
|
||||
|
||||
@Resource
|
||||
private AggregationService aggregationService;
|
||||
|
||||
@Override
|
||||
public PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto) {
|
||||
return strQuery(indexName, searchDto, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<JSONObject> strQuery(String indexName, SearchDto searchDto, LogicDelDto logicDelDto) {
|
||||
setLogicDelQueryStr(searchDto, logicDelDto);
|
||||
return searchService.strQuery(indexName, searchDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼装逻辑删除的条件
|
||||
* @param searchDto 搜索dto
|
||||
* @param logicDelDto 逻辑删除dto
|
||||
*/
|
||||
private void setLogicDelQueryStr(SearchDto searchDto, LogicDelDto logicDelDto) {
|
||||
if (logicDelDto != null
|
||||
&& StrUtil.isNotEmpty(logicDelDto.getLogicDelField())
|
||||
&& StrUtil.isNotEmpty(logicDelDto.getLogicNotDelValue())) {
|
||||
String result;
|
||||
//搜索条件
|
||||
String queryStr = searchDto.getQueryStr();
|
||||
//拼凑逻辑删除的条件
|
||||
String logicStr = logicDelDto.getLogicDelField() + ":" + logicDelDto.getLogicNotDelValue();
|
||||
if (StrUtil.isNotEmpty(queryStr)) {
|
||||
result = "(" + queryStr + ") AND " + logicStr;
|
||||
} else {
|
||||
result = logicStr;
|
||||
}
|
||||
searchDto.setQueryStr(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问统计聚合查询
|
||||
* @param indexName 索引名
|
||||
* @param routing es的路由
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> requestStatAgg(String indexName, String routing) {
|
||||
return aggregationService.requestStatAgg(indexName, routing);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.central.search.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 聚合Item
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
public class AggItemVo {
|
||||
private String name;
|
||||
private Long value;
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.central.search.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 逻辑删除条件对象
|
||||
*
|
||||
* @author zlt
|
||||
* @date 2019/4/25
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class LogicDelDto {
|
||||
/**
|
||||
* 逻辑删除字段名
|
||||
*/
|
||||
private String logicDelField;
|
||||
/**
|
||||
* 逻辑删除字段未删除的值
|
||||
*/
|
||||
private String logicNotDelValue;
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.central.search.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2019/4/24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SearchDto implements Serializable {
|
||||
private static final long serialVersionUID = -2084416068307485742L;
|
||||
/**
|
||||
* 搜索关键字
|
||||
*/
|
||||
private String queryStr;
|
||||
/**
|
||||
* 当前页数
|
||||
*/
|
||||
private Integer page;
|
||||
/**
|
||||
* 每页显示数
|
||||
*/
|
||||
private Integer limit;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private String sortCol;
|
||||
/**
|
||||
* 是否显示高亮
|
||||
*/
|
||||
private Boolean isHighlighter;
|
||||
/**
|
||||
* es的路由
|
||||
*/
|
||||
private String routing;
|
||||
}
|
||||
Reference in New Issue
Block a user