项目整合,增加测试项目,es改为rest客户端接口查询
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -15,7 +15,7 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<fastjson.version>1.2.53</fastjson.version>
|
||||
<elasticsearch.version>6.8.0</elasticsearch.version>
|
||||
<elasticsearch.version>7.2.0</elasticsearch.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
@@ -27,6 +27,6 @@
|
||||
<module>zyplayer-doc-wiki</module>
|
||||
<module>zyplayer-doc-data</module>
|
||||
<module>zyplayer-doc-grpc</module>
|
||||
<module>zyplayer-doc-page</module>
|
||||
<module>zyplayer-doc-other</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<dozer.core.version>6.1.0</dozer.core.version>
|
||||
<alibaba.druid.version>1.1.9</alibaba.druid.version>
|
||||
<zyplayer.doc.version>1.0.2</zyplayer.doc.version>
|
||||
<elasticsearch.version>6.8.0</elasticsearch.version>
|
||||
<elasticsearch.version>7.2.0</elasticsearch.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -129,6 +129,11 @@
|
||||
<artifactId>reindex-client</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Date;
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-07-07
|
||||
*/
|
||||
@Document(indexName = "zyplayer_doc", indexType = "doc_wiki")
|
||||
@Document(indexName = "zyplayer_doc_wiki", indexType = "_doc")
|
||||
public class EsWikiPage {
|
||||
|
||||
private Long id;
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package com.zyplayer.doc.data.service.elasticsearch.service;
|
||||
|
||||
import com.zyplayer.doc.data.service.elasticsearch.entity.EsWikiPage;
|
||||
import com.zyplayer.doc.data.service.elasticsearch.support.ElasticSearchConfig;
|
||||
import com.zyplayer.doc.data.service.elasticsearch.support.EsAbstractService;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* wiki文档搜索
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-07-07
|
||||
*/
|
||||
@Service
|
||||
@ConditionalOnBean(ElasticSearchConfig.class)
|
||||
public class EsWikiPageService extends EsAbstractService<EsWikiPage> {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.zyplayer.doc.data.service.elasticsearch.support;
|
||||
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* 开启es客户端
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-07-07
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "zyplayer.doc.manage.elasticsearch", name = "open", havingValue = "true")
|
||||
public class ElasticSearchConfig {
|
||||
|
||||
@Value(value = "${zyplayer.doc.manage.elasticsearch.host:''}")
|
||||
private String host;
|
||||
@Value("${zyplayer.doc.manage.elasticsearch.port:''}")
|
||||
private String port;
|
||||
@Value("${zyplayer.doc.manage.elasticsearch.cluster-name:''}")
|
||||
private String clusterName;
|
||||
|
||||
@Bean
|
||||
public TransportClient esClient() throws UnknownHostException {
|
||||
Settings settings = Settings.builder()
|
||||
.put("cluster.name", clusterName)
|
||||
.put("client.transport.sniff", true)
|
||||
.build();
|
||||
TransportAddress master = new TransportAddress(InetAddress.getByName(host), Integer.valueOf(port));
|
||||
return new PreBuiltTransportClient(settings).addTransportAddress(master);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.zyplayer.doc.data.service.elasticsearch.support;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 开启es客户端
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-07-07
|
||||
*/
|
||||
@Configuration
|
||||
public class ElasticSearchUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger(ElasticSearchUtil.class);
|
||||
|
||||
@Value(value = "${zyplayer.doc.manage.elasticsearch.hostPort:''}")
|
||||
private String hostAndPort;
|
||||
@Value(value = "${zyplayer.doc.manage.elasticsearch.scheme:''}")
|
||||
private String esScheme;
|
||||
@Value("${zyplayer.doc.manage.elasticsearch.open:''}")
|
||||
private String elasticsearchOpen;
|
||||
|
||||
private static final Object createLock = new Object();
|
||||
private static Map<String, RestHighLevelClient> restClientMap = new ConcurrentHashMap<>();
|
||||
|
||||
public boolean isOpen() {
|
||||
return Objects.equals("true", elasticsearchOpen);
|
||||
}
|
||||
|
||||
public RestHighLevelClient getEsClient() {
|
||||
if (!this.isOpen()) {
|
||||
return null;
|
||||
}
|
||||
String mapKey = esScheme + "_" + hostAndPort;
|
||||
RestHighLevelClient restClient = restClientMap.get(mapKey);
|
||||
if (restClient == null) {
|
||||
synchronized (createLock) {
|
||||
restClient = restClientMap.get(mapKey);
|
||||
if (restClient == null) {
|
||||
try {
|
||||
// rest请求客户端
|
||||
// 例:10.16.32.12:9200,10.16.32.12:9201
|
||||
List<HttpHost> hostPortList = new LinkedList<>();
|
||||
for (String hostPortStr : hostAndPort.split(",")) {
|
||||
String[] splitArr = hostPortStr.split(":");
|
||||
hostPortList.add(new HttpHost(splitArr[0], Integer.valueOf(splitArr[1]), esScheme));
|
||||
}
|
||||
restClient = new RestHighLevelClient(RestClient.builder(hostPortList.toArray(new HttpHost[]{})));
|
||||
restClientMap.put(mapKey, restClient);
|
||||
} catch (Exception e) {
|
||||
logger.error("创建es客户端失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return restClient;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,39 @@
|
||||
package com.zyplayer.doc.data.service.elasticsearch.support;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dozer.Mapper;
|
||||
import org.elasticsearch.action.DocWriteResponse;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.action.update.UpdateResponse;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.text.Text;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* es抽象类
|
||||
@@ -38,7 +44,7 @@ public abstract class EsAbstractService<T> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(EsAbstractService.class);
|
||||
|
||||
@Resource
|
||||
private TransportClient transportClient;
|
||||
private ElasticSearchUtil elasticSearchUtil;
|
||||
@Resource
|
||||
private Mapper mapper;
|
||||
|
||||
@@ -56,37 +62,40 @@ public abstract class EsAbstractService<T> {
|
||||
return annotation.indexType();
|
||||
}
|
||||
|
||||
public boolean create(T table) {
|
||||
String pk = getPrimaryKey(table);
|
||||
IndexResponse indexResponse = this.transportClient
|
||||
.prepareIndex(this.getIndexName(), this.getIndexType())
|
||||
.setId(pk)
|
||||
.setSource(JSONObject.toJSONString(table), XContentType.JSON)
|
||||
.get();
|
||||
logger.debug("ElasticSearch create index with table, pk: {}", pk);
|
||||
return indexResponse.status() == RestStatus.CREATED;
|
||||
public boolean isOpen() {
|
||||
return elasticSearchUtil.isOpen();
|
||||
}
|
||||
|
||||
public boolean update(T table) {
|
||||
public boolean upsert(T table) {
|
||||
String pk = getPrimaryKey(table);
|
||||
UpdateResponse updateResponse = this.transportClient
|
||||
.prepareUpdate(this.getIndexName(), this.getIndexType(), pk)
|
||||
.setDoc(JSONObject.toJSONString(table), XContentType.JSON)
|
||||
.get();
|
||||
logger.info("ElasticSearch update index with table, pk: {}", pk);
|
||||
return updateResponse.status() == RestStatus.OK;
|
||||
UpdateRequest request = new UpdateRequest(this.getIndexName(), pk);
|
||||
request.timeout(TimeValue.timeValueMinutes(2));
|
||||
request.doc(JSON.toJSONString(table), XContentType.JSON);
|
||||
request.docAsUpsert(true);
|
||||
RestHighLevelClient esClient = elasticSearchUtil.getEsClient();
|
||||
try {
|
||||
UpdateResponse updateResponse = esClient.update(request, RequestOptions.DEFAULT);
|
||||
return updateResponse.status() == RestStatus.OK;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void delete(T table) {
|
||||
String pk = getPrimaryKey(table);
|
||||
DeleteResponse response = this.transportClient
|
||||
.prepareDelete(this.getIndexName(), this.getIndexType(), pk)
|
||||
.execute()
|
||||
.actionGet();
|
||||
if (response.getResult() == DocWriteResponse.Result.NOT_FOUND) {
|
||||
logger.warn("ElasticSearch delete index id: {} but not found!", pk);
|
||||
} else {
|
||||
logger.warn("ElasticSearch delete index id: {}", pk);
|
||||
RestHighLevelClient esClient = elasticSearchUtil.getEsClient();
|
||||
DeleteRequest request = new DeleteRequest(this.getIndexName(), pk);
|
||||
request.timeout(TimeValue.timeValueMinutes(2));
|
||||
try {
|
||||
DeleteResponse deleteResponse = esClient.delete(request, RequestOptions.DEFAULT);
|
||||
if (deleteResponse.getResult() == DocWriteResponse.Result.NOT_FOUND) {
|
||||
logger.warn("ElasticSearch delete index id: {} but not found!", pk);
|
||||
} else {
|
||||
logger.warn("ElasticSearch delete index id: {}", pk);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,16 +159,27 @@ public abstract class EsAbstractService<T> {
|
||||
highlightBuilder.preTags("<span style=\"color:red\">");
|
||||
highlightBuilder.postTags("</span>");
|
||||
highlightBuilder.field("*");
|
||||
SearchRequestBuilder requestBuilder = transportClient.prepareSearch(this.getIndexName()).setTypes(this.getIndexType())
|
||||
.setQuery(queryBuilders)
|
||||
.highlighter(highlightBuilder)
|
||||
.setFrom(startIndex).setSize(pageSize).setExplain(true);
|
||||
// 组装条件
|
||||
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
|
||||
sourceBuilder.query(queryBuilders)
|
||||
.highlighter(highlightBuilder).from(startIndex).size(pageSize)
|
||||
.timeout(new TimeValue(60, TimeUnit.SECONDS));
|
||||
// 查询指定字段
|
||||
if (fields != null && fields.length > 0) {
|
||||
requestBuilder.setFetchSource(fields, new String[]{});
|
||||
sourceBuilder.fetchSource(fields, new String[]{});
|
||||
}
|
||||
SearchResponse response = requestBuilder.execute().actionGet();
|
||||
return responseToList(response);
|
||||
// 组装请求
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices(this.getIndexName());
|
||||
searchRequest.source(sourceBuilder);
|
||||
RestHighLevelClient esClient = elasticSearchUtil.getEsClient();
|
||||
try {
|
||||
SearchResponse response = esClient.search(searchRequest, RequestOptions.DEFAULT);
|
||||
return responseToList(response);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public EsPage<T> responseToList(SearchResponse response) {
|
||||
@@ -184,7 +204,7 @@ public abstract class EsAbstractService<T> {
|
||||
tableList.add(table);
|
||||
}
|
||||
EsPage<T> esPage = new EsPage<>();
|
||||
esPage.setTotal(response.getHits().getTotalHits());
|
||||
esPage.setTotal(response.getHits().getTotalHits().value);
|
||||
esPage.setData(tableList);
|
||||
return esPage;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
<zyplayer.doc.version>1.0.2</zyplayer.doc.version>
|
||||
<!-- 打包跳过单元测试 -->
|
||||
<skipTests>true</skipTests>
|
||||
<elasticsearch.version>6.8.0</elasticsearch.version>
|
||||
<elasticsearch.version>7.2.0</elasticsearch.version>
|
||||
<destDir>${project.build.outputDirectory}/META-INF/resources/webjars/${project.artifactId}/${project.version}</destDir>
|
||||
</properties>
|
||||
<licenses>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<java.version>1.8</java.version>
|
||||
<!-- 打包跳过单元测试 -->
|
||||
<skipTests>true</skipTests>
|
||||
<elasticsearch.version>6.8.0</elasticsearch.version>
|
||||
<elasticsearch.version>7.2.0</elasticsearch.version>
|
||||
<destDir>${project.build.outputDirectory}/META-INF/resources/webjars/${project.artifactId}/${project.version}</destDir>
|
||||
<zyplayer.doc.version>1.0.2</zyplayer.doc.version>
|
||||
</properties>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
|
||||
<elasticsearch.version>6.8.0</elasticsearch.version>
|
||||
<elasticsearch.version>7.2.0</elasticsearch.version>
|
||||
<grpc.version>1.16.1</grpc.version>
|
||||
<protoc.version>3.6.1</protoc.version> <!-- Same version as grpc-proto -->
|
||||
<grpc-java-spring.version>0.0.3</grpc-java-spring.version>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<swagger.bootstrap.ui.version>1.9.4</swagger.bootstrap.ui.version>
|
||||
<springfox.swagger.ui.version>2.9.2</springfox.swagger.ui.version>
|
||||
<zyplayer.doc.version>1.0.2</zyplayer.doc.version>
|
||||
<elasticsearch.version>6.8.0</elasticsearch.version>
|
||||
<elasticsearch.version>7.2.0</elasticsearch.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -116,12 +116,6 @@
|
||||
<artifactId>zyplayer-doc-swagger</artifactId>
|
||||
<version>${zyplayer.doc.version}</version>
|
||||
</dependency>
|
||||
<!--zyplayer-doc-swagger-->
|
||||
<dependency>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-page-console</artifactId>
|
||||
<version>${zyplayer.doc.version}</version>
|
||||
</dependency>
|
||||
<!--swagger-bootstrap-ui-->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
@@ -154,6 +148,19 @@
|
||||
|
||||
<build>
|
||||
<finalName>zyplayer-doc-manage</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/webapp/static/console</directory>
|
||||
<targetPath>META-INF/resources/</targetPath>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -24,10 +24,10 @@ zyplayer:
|
||||
manage:
|
||||
elasticsearch:
|
||||
# 是否开启es,true或false,现在主要用在wiki文档的搜索,使用的es是6.8.0及以上版本
|
||||
open: false
|
||||
host: 127.0.0.1
|
||||
port: 9300
|
||||
cluster-name: zyplayer-doc
|
||||
open: true
|
||||
# es地址配置ip:port,多个使用英文逗号分割,例:127.0.0.1:9200,127.0.0.1:9201
|
||||
hostPort: 127.0.0.1:9200
|
||||
scheme: http
|
||||
# 版本和升级信息获取地址
|
||||
version: 1.0.2
|
||||
upgradePropertiesUrl: https://gitee.com/zyplayer/zyplayer-doc/raw/master/upgrade.properties
|
||||
|
||||
20
zyplayer-doc-other/pom.xml
Normal file
20
zyplayer-doc-other/pom.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<parent>
|
||||
<artifactId>zyplayer-doc</artifactId>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<version>1.0.2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>zyplayer-doc-other</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>zyplayer-doc-test</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
||||
67
zyplayer-doc-other/zyplayer-doc-test/pom.xml
Normal file
67
zyplayer-doc-other/zyplayer-doc-test/pom.xml
Normal file
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.6.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-test</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<zyplayer.doc.version>1.0.2</zyplayer.doc.version>
|
||||
<elasticsearch.version>7.2.0</elasticsearch.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-data</artifactId>
|
||||
<version>${zyplayer.doc.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-core</artifactId>
|
||||
<version>${zyplayer.doc.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-http</artifactId>
|
||||
<version>4.1.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.47</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.zyplayer.doc.test;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 程序启动器
|
||||
*/
|
||||
@EnableScheduling
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = {"com.zyplayer.doc.test", "com.zyplayer.doc.data"})
|
||||
public class Application extends SpringBootServletInitializer {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(Application.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.zyplayer.doc.test.config;
|
||||
|
||||
import org.dozer.DozerBeanMapperBuilder;
|
||||
import org.dozer.DozerConverter;
|
||||
import org.dozer.Mapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@Configuration
|
||||
public class MapperConfig {
|
||||
|
||||
@Bean
|
||||
public Mapper dozerBeanMapper() {
|
||||
DozerBeanMapperBuilder builder = DozerBeanMapperBuilder.create()
|
||||
.withCustomConverter(new DateStringConvert(Date.class, String.class))
|
||||
.withCustomConverter(new BigdecimalToStringConvert(BigDecimal.class, String.class));
|
||||
return builder.build();
|
||||
// return DozerBeanMapperBuilder.buildDefault();
|
||||
}
|
||||
|
||||
private class DateStringConvert extends DozerConverter<Date, String> {
|
||||
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public DateStringConvert(Class<Date> prototypeA, Class<String> prototypeB) {
|
||||
super(prototypeA, prototypeB);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTo(Date source, String destination) {
|
||||
destination = dateFormat.format(source);
|
||||
return destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date convertFrom(String source, Date destination) {
|
||||
try {
|
||||
destination = dateFormat.parse(source);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
}
|
||||
|
||||
private class BigdecimalToStringConvert extends DozerConverter<BigDecimal, String> {
|
||||
|
||||
public BigdecimalToStringConvert(Class<BigDecimal> prototypeA, Class<String> prototypeB) {
|
||||
super(prototypeA, prototypeB);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTo(BigDecimal source, String destination) {
|
||||
return source.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal convertFrom(String source, BigDecimal destination) {
|
||||
return BigDecimal.valueOf(Double.parseDouble(source));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.zyplayer.doc.test.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 接口文档,方便直接测试
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-07-07
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("接口文档")
|
||||
.description("欢迎使用")
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
//package com.zyplayer.doc.test.elasticsearch;
|
||||
//
|
||||
//import cn.hutool.core.date.DateTime;
|
||||
//import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
//import com.zyplayer.doc.core.json.ResponseJson;
|
||||
//import io.swagger.annotations.ApiImplicitParam;
|
||||
//import org.elasticsearch.action.ActionListener;
|
||||
//import org.elasticsearch.action.delete.DeleteResponse;
|
||||
//import org.elasticsearch.action.get.GetResponse;
|
||||
//import org.elasticsearch.action.get.MultiGetItemResponse;
|
||||
//import org.elasticsearch.action.get.MultiGetResponse;
|
||||
//import org.elasticsearch.action.index.IndexRequest;
|
||||
//import org.elasticsearch.action.search.MultiSearchResponse;
|
||||
//import org.elasticsearch.action.search.SearchRequest;
|
||||
//import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
//import org.elasticsearch.action.search.SearchResponse;
|
||||
//import org.elasticsearch.action.update.UpdateRequest;
|
||||
//import org.elasticsearch.client.transport.TransportClient;
|
||||
//import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
//import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
//import org.elasticsearch.index.query.QueryBuilder;
|
||||
//import org.elasticsearch.index.query.QueryBuilders;
|
||||
//import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||
//import org.elasticsearch.index.reindex.DeleteByQueryAction;
|
||||
//import org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder;
|
||||
//import org.elasticsearch.script.ScriptType;
|
||||
//import org.elasticsearch.script.mustache.SearchTemplateRequestBuilder;
|
||||
//import org.elasticsearch.search.SearchHit;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import java.util.*;
|
||||
//
|
||||
///**
|
||||
// * 测试es的控制器,依据官方文档7.2.0版本做的一些测试方法
|
||||
// * 不建议使用了,使用 rest 的客户端
|
||||
// * @author 暮光:城中城
|
||||
// * @since 2019年7月14日
|
||||
// */
|
||||
//@RestController
|
||||
//@RequestMapping("/zyplayer-doc-test/es")
|
||||
//public class TestEsController {
|
||||
// private static Logger logger = LoggerFactory.getLogger(TestEsController.class);
|
||||
//
|
||||
// @Autowired(required = false)
|
||||
// private TransportClient transportClient;
|
||||
//
|
||||
// private static final String ES_INDEX = "zyplayer_doc_test";
|
||||
// private static final String ES_INDEX_2 = "zyplayer_doc_test2";
|
||||
// private static final String ES_TYPE = "_doc";
|
||||
//
|
||||
// @GetMapping("/list")
|
||||
// public ResponseJson<Object> list() {
|
||||
// QueryBuilder queryBuilder = QueryBuilders.boolQuery();
|
||||
//
|
||||
// SearchRequestBuilder requestBuilder = transportClient.prepareSearch(ES_INDEX).setTypes(ES_TYPE)
|
||||
// .setQuery(queryBuilder)
|
||||
// .setFrom(0).setSize(100).setExplain(true);
|
||||
// SearchResponse response = requestBuilder.execute().actionGet();
|
||||
// List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
// for (SearchHit searchHit : response.getHits().getHits()) {
|
||||
// resultList.add(searchHit.getSourceAsMap());
|
||||
// }
|
||||
// return DocResponseJson.ok(resultList);
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/execute")
|
||||
// @ApiImplicitParam(name = "sql", value = "执行的DSL表达式", example = "{\"query\":{\"match\":{\"content\":\"测试\"}}}")
|
||||
// public ResponseJson<Object> execute(@RequestBody String sql) {
|
||||
// SearchRequest searchRequest = new SearchRequest().indices(ES_INDEX).types(ES_TYPE);
|
||||
// // 执行查询,测试语句:{"query":{"match":{"content":"测试"}}}
|
||||
// SearchResponse searchResponse = new SearchTemplateRequestBuilder(transportClient)
|
||||
// .setScript(sql)
|
||||
// .setScriptType(ScriptType.INLINE)
|
||||
// .setScriptParams(new HashMap<>())
|
||||
// .setRequest(searchRequest)
|
||||
// .get()
|
||||
// .getResponse();
|
||||
// // 解析结果
|
||||
// List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
// for (SearchHit searchHit : searchResponse.getHits().getHits()) {
|
||||
// Map<String, Object> sourceMap = searchHit.getSourceAsMap();
|
||||
// if (sourceMap != null) {
|
||||
// resultList.add(sourceMap);
|
||||
// }
|
||||
// }
|
||||
// return DocResponseJson.ok(resultList);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/get/{id}")
|
||||
// public ResponseJson<Object> getById(@PathVariable String id) {
|
||||
// // 通过ID获取
|
||||
// GetResponse response = transportClient.prepareGet(ES_INDEX, ES_TYPE, id).get();
|
||||
// return DocResponseJson.ok(response.getSource());
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/delete/{id}")
|
||||
// public ResponseJson<Object> deleteById(@PathVariable String id) {
|
||||
// // 通过ID删除
|
||||
// DeleteResponse response = transportClient.prepareDelete(ES_INDEX, ES_TYPE, id).get();
|
||||
// return DocResponseJson.ok(response.status());
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/delete")
|
||||
// public ResponseJson<Object> delete() {
|
||||
// // 条件删除
|
||||
// BulkByScrollResponse response =
|
||||
// new DeleteByQueryRequestBuilder(transportClient, DeleteByQueryAction.INSTANCE)
|
||||
// .filter(QueryBuilders.matchQuery("content", "xx"))
|
||||
// .source(ES_INDEX)
|
||||
// .get();
|
||||
// long deleted = response.getDeleted();
|
||||
// return DocResponseJson.ok(deleted);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/deleteAsync")
|
||||
// public ResponseJson<Object> deleteAsync() {
|
||||
// // 异步删除
|
||||
// new DeleteByQueryRequestBuilder(transportClient, DeleteByQueryAction.INSTANCE)
|
||||
// .filter(QueryBuilders.matchQuery("content", "测试"))
|
||||
// .source(ES_INDEX)
|
||||
// .execute(new ActionListener<BulkByScrollResponse>() {
|
||||
// @Override
|
||||
// public void onResponse(BulkByScrollResponse response) {
|
||||
// long deleted = response.getDeleted();
|
||||
// logger.info("已删除:{}", deleted);
|
||||
// }
|
||||
// @Override
|
||||
// public void onFailure(Exception e) {
|
||||
// logger.error("删除失败", e);
|
||||
// }
|
||||
// });
|
||||
// return DocResponseJson.ok();
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/update/{id}")
|
||||
// public ResponseJson<Object> update(@PathVariable String id) {
|
||||
// // 使用UpdateRequest更新
|
||||
// UpdateRequest updateRequest = new UpdateRequest();
|
||||
// updateRequest.index(ES_INDEX);
|
||||
// updateRequest.type(ES_TYPE);
|
||||
// updateRequest.id(id);
|
||||
// try {
|
||||
// updateRequest.doc(XContentFactory.jsonBuilder()
|
||||
// .startObject()
|
||||
// .field("content", "测试更新")
|
||||
// .endObject());
|
||||
// transportClient.update(updateRequest).get();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// // 使用prepareUpdate更新
|
||||
// try {
|
||||
// transportClient.prepareUpdate(ES_INDEX, ES_TYPE, id)
|
||||
// .setDoc(XContentFactory.jsonBuilder()
|
||||
// .startObject()
|
||||
// .field("content", "测试更新")
|
||||
// .endObject())
|
||||
// .get();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return DocResponseJson.ok();
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/upsert/{id}")
|
||||
// @ApiImplicitParam(name = "index", value = "选择索引,可选:1、2")
|
||||
// public ResponseJson<Object> upsert(@PathVariable String id, String index) {
|
||||
// try {
|
||||
// String indexUp = Objects.equals(index, "1") ? ES_INDEX : ES_INDEX_2;
|
||||
// IndexRequest indexRequest = new IndexRequest(indexUp, ES_TYPE, id)
|
||||
// .source(XContentFactory.jsonBuilder()
|
||||
// .startObject()
|
||||
// .field("content", "测试更新或新增-新增")
|
||||
// .field("createTime", DateTime.now().toString())
|
||||
// .endObject());
|
||||
// UpdateRequest updateRequest = new UpdateRequest(indexUp, ES_TYPE, id)
|
||||
// .doc(XContentFactory.jsonBuilder()
|
||||
// .startObject()
|
||||
// .field("content", "测试更新或新增-更新")
|
||||
// .endObject())
|
||||
// .upsert(indexRequest);
|
||||
// transportClient.update(updateRequest).get();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return DocResponseJson.ok();
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/multiGet")
|
||||
// public ResponseJson<Object> multiGet() {
|
||||
// MultiGetResponse multiGetItemResponses = transportClient.prepareMultiGet()
|
||||
// .add(ES_INDEX, ES_TYPE, "1") // 通过单ID查
|
||||
// .add(ES_INDEX, ES_TYPE, "2", "3", "4") // 通过多ID查
|
||||
// .add(ES_INDEX_2, ES_TYPE, "1") // 同时查询另一个索引
|
||||
// .get();
|
||||
// List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
// for (MultiGetItemResponse itemResponse : multiGetItemResponses) {
|
||||
// GetResponse response = itemResponse.getResponse();
|
||||
// if (response.isExists()) {
|
||||
// resultList.add(response.getSource());
|
||||
// }
|
||||
// }
|
||||
// return DocResponseJson.ok(resultList);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/multiSearch")
|
||||
// public ResponseJson<Object> multiSearch(String content) {
|
||||
// SearchRequestBuilder srb1 = transportClient.prepareSearch(ES_INDEX).setQuery(QueryBuilders.matchQuery("content", content)).setSize(10);
|
||||
// SearchRequestBuilder srb2 = transportClient.prepareSearch(ES_INDEX_2).setQuery(QueryBuilders.matchQuery("content", content)).setSize(10);
|
||||
// MultiSearchResponse multiSearchResponse = transportClient.prepareMultiSearch().add(srb1).add(srb2).get();
|
||||
// List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
// for (MultiSearchResponse.Item item : multiSearchResponse) {
|
||||
// for (SearchHit searchHit : item.getResponse().getHits().getHits()) {
|
||||
// Map<String, Object> sourceMap = searchHit.getSourceAsMap();
|
||||
// if (sourceMap != null) {
|
||||
// resultList.add(sourceMap);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return DocResponseJson.ok(resultList);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/terminateAfter")
|
||||
// public ResponseJson<Object> terminateAfter() {
|
||||
// SearchResponse sr = transportClient.prepareSearch(ES_INDEX)
|
||||
// .setTerminateAfter(1000)
|
||||
// .get();
|
||||
// if (sr.isTerminatedEarly()) {
|
||||
// // We finished early
|
||||
// return DocResponseJson.ok("成功");
|
||||
// }
|
||||
// return DocResponseJson.warn("失败");
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/other")
|
||||
// public ResponseJson<Object> other() {
|
||||
// // 都是些官网上的一些例子,不细跑了
|
||||
// BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
|
||||
// queryBuilder.must(QueryBuilders.matchQuery("content","xxx"));
|
||||
// queryBuilder.must(QueryBuilders.multiMatchQuery("xxx", "content", "name"));
|
||||
// queryBuilder.must(QueryBuilders.commonTermsQuery("content","xxx"));
|
||||
// queryBuilder.must(QueryBuilders.queryStringQuery("+xxx -aa"));
|
||||
// queryBuilder.must(QueryBuilders.simpleQueryStringQuery("+xxx -aa"));
|
||||
// // term query
|
||||
// queryBuilder.must(QueryBuilders.termQuery("content","xxx"));
|
||||
// queryBuilder.must(QueryBuilders.termsQuery("xxx", "content", "name"));
|
||||
// queryBuilder.must(QueryBuilders.rangeQuery("age")
|
||||
// .from(5)
|
||||
// .to(10)
|
||||
// .includeLower(true) // 相当于 >=
|
||||
// .includeUpper(false)); // 相当于 < ,true 表示 <=
|
||||
// queryBuilder.must(QueryBuilders.rangeQuery("age")
|
||||
// .gte("10")
|
||||
// .lt("20"));
|
||||
// queryBuilder.must(QueryBuilders.existsQuery("name"));
|
||||
// queryBuilder.must(QueryBuilders.prefixQuery("content", "xxx"));
|
||||
// queryBuilder.must(QueryBuilders.wildcardQuery("content", "k?mch*"));
|
||||
// queryBuilder.must(QueryBuilders.regexpQuery("content", "s.*y"));
|
||||
// queryBuilder.must(QueryBuilders.fuzzyQuery("content", "xxx"));
|
||||
// queryBuilder.must(QueryBuilders.idsQuery().addIds("1", "2", "3"));
|
||||
// queryBuilder.must(QueryBuilders.constantScoreQuery(QueryBuilders.termQuery("content","xxx")).boost(2.0f));
|
||||
// // 如果满足了这些条件的,则降低分数,原分数*0.5 则表示下降了一半
|
||||
// queryBuilder.must(QueryBuilders.boostingQuery(
|
||||
// QueryBuilders.termQuery("name","kimchy"),
|
||||
// QueryBuilders.termQuery("name","dadoonet"))
|
||||
// .negativeBoost(0.5f));
|
||||
// // 7.x 才支持
|
||||
//// queryBuilder.must(QueryBuilders.constantScoreQuery(QueryBuilders.termQuery("content","xxx")).boost(2.0f).tieBreaker(0.7f));
|
||||
// // filter:匹配内容必须出现在文档中,但不参与评分
|
||||
// queryBuilder.filter(QueryBuilders.matchQuery("content","xxx"));
|
||||
//
|
||||
//
|
||||
// SearchRequestBuilder requestBuilder = transportClient.prepareSearch(ES_INDEX).setTypes(ES_TYPE)
|
||||
// .setQuery(queryBuilder).setFrom(0).setSize(100).setExplain(true);
|
||||
// SearchResponse response = requestBuilder.execute().actionGet();
|
||||
// List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
// for (SearchHit searchHit : response.getHits().getHits()) {
|
||||
// resultList.add(searchHit.getSourceAsMap());
|
||||
// }
|
||||
// return DocResponseJson.ok(resultList);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.zyplayer.doc.test.elasticsearch;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.data.service.elasticsearch.entity.EsWikiPage;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
import org.elasticsearch.action.get.*;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.action.update.UpdateResponse;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.script.mustache.SearchTemplateRequest;
|
||||
import org.elasticsearch.script.mustache.SearchTemplateResponse;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 测试es的控制器,依据官方文档7.2.0版本做的一些测试方法
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年7月14日
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/zyplayer-doc-test/es-rest")
|
||||
public class TestEsRestController {
|
||||
private static Logger logger = LoggerFactory.getLogger(TestEsRestController.class);
|
||||
|
||||
private static final String ES_INDEX = "zyplayer_doc_test";
|
||||
private static final String ES_INDEX_2 = "zyplayer_doc_test2";
|
||||
private static final String ES_TYPE = "_doc";
|
||||
|
||||
// rest请求客户端
|
||||
private RestHighLevelClient client = new RestHighLevelClient(
|
||||
RestClient.builder(
|
||||
new HttpHost("127.0.0.1", 9200, "http")
|
||||
));
|
||||
|
||||
@GetMapping("/list")
|
||||
public ResponseJson<Object> list(String keywords) throws IOException {
|
||||
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
|
||||
sourceBuilder.query(QueryBuilders.termQuery("content", keywords));
|
||||
sourceBuilder.from(0);
|
||||
sourceBuilder.size(10);
|
||||
sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
|
||||
|
||||
String[] includeFields = new String[] {"content", "*Time"};
|
||||
String[] excludeFields = new String[] {"user"};
|
||||
sourceBuilder.fetchSource(includeFields, excludeFields);
|
||||
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.indices(ES_INDEX);
|
||||
searchRequest.source(sourceBuilder);
|
||||
|
||||
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||
|
||||
List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
|
||||
resultList.add(searchHit.getSourceAsMap());
|
||||
}
|
||||
return DocResponseJson.ok(resultList);
|
||||
}
|
||||
|
||||
@PostMapping("/execute")
|
||||
@ApiImplicitParam(name = "sql", value = "执行的DSL表达式", example = "{\"query\":{\"match\":{\"content\":\"测试\"}}}")
|
||||
public ResponseJson<Object> execute(@RequestBody String sql) throws IOException {
|
||||
SearchTemplateRequest request = new SearchTemplateRequest();
|
||||
request.setRequest(new SearchRequest(ES_INDEX).types(ES_TYPE));
|
||||
|
||||
request.setScriptType(ScriptType.INLINE);
|
||||
request.setScript(sql);
|
||||
// 可使用动态参数,{{field}},然后map为值
|
||||
// Map<String, Object> scriptParams = new HashMap<>();
|
||||
// scriptParams.put("field", "title");
|
||||
// scriptParams.put("value", "elasticsearch");
|
||||
// scriptParams.put("size", 5);
|
||||
// request.setScriptParams(scriptParams);
|
||||
|
||||
SearchTemplateResponse response = client.searchTemplate(request, RequestOptions.DEFAULT);
|
||||
|
||||
List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
for (SearchHit searchHit : response.getResponse().getHits()) {
|
||||
resultList.add(searchHit.getSourceAsMap());
|
||||
}
|
||||
return DocResponseJson.ok(resultList);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public ResponseJson<Object> getById(@PathVariable String id) throws Exception {
|
||||
GetRequest getRequest = new GetRequest(ES_INDEX, id);
|
||||
String[] includes = new String[]{"content", "*Time"};
|
||||
String[] excludes = Strings.EMPTY_ARRAY;
|
||||
FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes);
|
||||
getRequest.fetchSourceContext(fetchSourceContext);
|
||||
GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT);
|
||||
return DocResponseJson.ok(getResponse.getSource());
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{id}")
|
||||
public ResponseJson<Object> deleteById(@PathVariable String id) throws IOException {
|
||||
DeleteRequest request = new DeleteRequest(ES_INDEX, id);
|
||||
request.timeout(TimeValue.timeValueMinutes(2));
|
||||
DeleteResponse deleteResponse = client.delete(request, RequestOptions.DEFAULT);
|
||||
return DocResponseJson.ok(deleteResponse.getResult().name());
|
||||
}
|
||||
|
||||
@GetMapping("/delete")
|
||||
public ResponseJson<Object> delete() {
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/deleteAsync")
|
||||
public ResponseJson<Object> deleteAsync() {
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/update/{id}")
|
||||
public ResponseJson<Object> update(@PathVariable String id, EsWikiPage esWikiPage) throws IOException {
|
||||
UpdateRequest request = new UpdateRequest(ES_INDEX, id);
|
||||
request.timeout(TimeValue.timeValueMinutes(2));
|
||||
// 需要更新的内容
|
||||
esWikiPage.setUpdateTime(new Date());
|
||||
request.doc(JSON.toJSONString(esWikiPage), XContentType.JSON);
|
||||
UpdateResponse deleteResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
return DocResponseJson.ok(deleteResponse.getResult().name());
|
||||
}
|
||||
|
||||
@GetMapping("/upsert/{id}")
|
||||
@ApiImplicitParam(name = "esIndex", value = "选择索引,可选:1、2")
|
||||
public ResponseJson<Object> upsert(@PathVariable String id, String esIndex, EsWikiPage esWikiPage) throws IOException {
|
||||
String indexUp = Objects.equals(esIndex, "1") ? ES_INDEX : ES_INDEX_2;
|
||||
UpdateRequest request = new UpdateRequest(indexUp, id);
|
||||
request.timeout(TimeValue.timeValueMinutes(2));
|
||||
// 需要更新的内容
|
||||
esWikiPage.setUpdateTime(new Date());
|
||||
request.upsert(JSON.toJSONString(esWikiPage), XContentType.JSON);
|
||||
request.docAsUpsert(true);
|
||||
UpdateResponse deleteResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
return DocResponseJson.ok(deleteResponse.getResult().name());
|
||||
}
|
||||
|
||||
@GetMapping("/multiGet")
|
||||
public ResponseJson<Object> multiGet() throws IOException {
|
||||
String[] includes = new String[] {"content", "*Time"};
|
||||
String[] excludes = Strings.EMPTY_ARRAY;
|
||||
FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes);
|
||||
|
||||
MultiGetRequest request = new MultiGetRequest();
|
||||
request.add(new MultiGetRequest.Item(ES_INDEX, "id").fetchSourceContext(fetchSourceContext));
|
||||
request.add(new MultiGetRequest.Item(ES_INDEX_2, "id").fetchSourceContext(fetchSourceContext));
|
||||
|
||||
MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT);
|
||||
|
||||
List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
for (MultiGetItemResponse itemResponse : response.getResponses()) {
|
||||
resultList.add(itemResponse.getResponse().getSource());
|
||||
}
|
||||
return DocResponseJson.ok(resultList);
|
||||
}
|
||||
|
||||
@GetMapping("/multiSearch")
|
||||
public ResponseJson<Object> multiSearch(String content) {
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/terminateAfter")
|
||||
public ResponseJson<Object> terminateAfter() {
|
||||
return DocResponseJson.warn("失败");
|
||||
}
|
||||
|
||||
@GetMapping("/other")
|
||||
public ResponseJson<Object> other() {
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
spring:
|
||||
application:
|
||||
name: zyplayer-doc-test
|
||||
# mvc:
|
||||
# static-path-pattern: /**
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
|
||||
datasource:
|
||||
continue-on-error: true
|
||||
|
||||
# 端口和根路劲,main方法启动时需要,放tomcat后以tomcat的配置为准
|
||||
server:
|
||||
port: 8084
|
||||
servlet:
|
||||
context-path: /zyplayer-doc-test
|
||||
|
||||
# 整个文档项目的配置
|
||||
zyplayer:
|
||||
doc:
|
||||
# ------zyplayer_doc_manage相关配置------
|
||||
manage:
|
||||
elasticsearch:
|
||||
# 是否开启es,true或false,现在主要用在wiki文档的搜索,使用的es是6.8.0及以上版本
|
||||
open: true
|
||||
host: 127.0.0.1
|
||||
port: 9300
|
||||
cluster-name: zyplayer-doc
|
||||
# 管理端的数据库配置
|
||||
datasource:
|
||||
driverClassName: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/zyplayer_doc_manage?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false
|
||||
username: root
|
||||
password: root
|
||||
|
||||
# 下面的配置可以不用管了
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/**/*Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: com.zyplayer.doc.manage.repository.manage.entity
|
||||
typeEnumsPackage:
|
||||
global-config:
|
||||
# 数据库相关配置
|
||||
db-config:
|
||||
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID",ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
|
||||
id-type: AUTO
|
||||
#字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
|
||||
field-strategy: not_empty
|
||||
#驼峰下划线转换
|
||||
column-underline: true
|
||||
#数据库大写下划线转换
|
||||
#capital-mode: true
|
||||
#逻辑删除配置
|
||||
logic-delete-value: 0
|
||||
logic-not-delete-value: 1
|
||||
db-type: mysql
|
||||
#刷新mapper 调试神器
|
||||
refresh: true
|
||||
# 原生配置
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
cache-enabled: false
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<property name="outPattern" value="[%d{yyyy-MM-dd HH:mm:ss}][%-5level][%logger{0}] %msg%n"/>
|
||||
<!-- 文件历史数 -->
|
||||
<property name="maxHistory" value="7"/>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${outPattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<appender name="LOG_ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/web/logs/zyplayer-doc-test/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>/web/logs/zyplayer-doc-test/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<maxHistory>${maxHistory}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${outPattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<appender name="LOG_COMMON_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/web/logs/zyplayer-doc-test/common.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>/web/logs/zyplayer-doc-test/common.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<maxHistory>${maxHistory}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${outPattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<logger name="com.zyplayer.doc.manage.repository" level="warn" />
|
||||
<logger name="com.atomikos.jdbc" level="warn" />
|
||||
<logger name="com.atomikos.datasource.xa" level="warn" />
|
||||
<logger name="com.atomikos.icatch.imp" level="warn" />
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
<logger name="LOG_ERROR" level="info">
|
||||
<appender-ref ref="LOG_ERROR_FILE" />
|
||||
</logger>
|
||||
<logger name="LOG_COMMON" level="info">
|
||||
<appender-ref ref="LOG_COMMON_FILE" />
|
||||
</logger>
|
||||
</configuration>
|
||||
@@ -1,9 +0,0 @@
|
||||
# zyplayer-doc-page
|
||||
|
||||
#### 项目介绍
|
||||
用来存页面的,里面只有编译后的页面文件
|
||||
|
||||
模块的详细使用文档地址,部署必看:
|
||||
|
||||
http://doc.zyplayer.com/zyplayer-doc-manage/open-wiki.html?pageId=28&space=23f3f59a60824d21af9f7c3bbc9bc3cb
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-doc-page</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>zyplayer-page-console</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
@@ -1,9 +0,0 @@
|
||||
# console-page
|
||||
|
||||
#### 项目介绍
|
||||
用来存管理端页面的,里面只有编译后的页面文件
|
||||
|
||||
模块的详细使用文档地址,部署必看:
|
||||
|
||||
http://doc.zyplayer.com/zyplayer-doc-manage/open-wiki.html?pageId=28&space=23f3f59a60824d21af9f7c3bbc9bc3cb
|
||||
|
||||
@@ -1,191 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<groupId>com.zyplayer</groupId>
|
||||
<artifactId>zyplayer-page-console</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<description>管理页面前端</description>
|
||||
<url>https://gitee.com/zyplayer/zyplayer-doc</url>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>zyplayer</id>
|
||||
<name>暮光:城中城</name>
|
||||
<email>806783409@qq.com</email>
|
||||
<roles>
|
||||
<role>Java Development Engineer</role>
|
||||
</roles>
|
||||
<timezone>2018-05-22 16:06:06</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<zyplayer.doc.version>1.0.2</zyplayer.doc.version>
|
||||
<!-- 打包跳过单元测试 -->
|
||||
<skipTests>true</skipTests>
|
||||
<destDir>${project.build.outputDirectory}/META-INF/resources/webjars/${project.artifactId}/${project.version}</destDir>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
</dependencies>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<scm>
|
||||
<connection>scm:git@git.oschina.net:zyplayer/zyplayer-doc.git</connection>
|
||||
<developerConnection>scm:git@git.oschina.net:zyplayer/zyplayer-doc.git</developerConnection>
|
||||
<url>git@git.oschina.net:zyplayer/zyplayer-doc.git</url>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>snapshots</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<targetPath>META-INF/resources/</targetPath>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/webapp</directory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.2</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.18.1</version>
|
||||
<configuration>
|
||||
<skipTests>${skipTests}</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.2</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -35,7 +35,7 @@
|
||||
<java.version>1.8</java.version>
|
||||
<!-- 打包跳过单元测试 -->
|
||||
<skipTests>true</skipTests>
|
||||
<elasticsearch.version>6.8.0</elasticsearch.version>
|
||||
<elasticsearch.version>7.2.0</elasticsearch.version>
|
||||
<destDir>${project.build.outputDirectory}/META-INF/resources/webjars/${project.artifactId}/${project.version}</destDir>
|
||||
<zyplayer.doc.version>1.0.2</zyplayer.doc.version>
|
||||
</properties>
|
||||
|
||||
@@ -250,7 +250,7 @@ function exportDocument(){
|
||||
$("#exportDocumentModal .bottom-box").show();
|
||||
$("#exportDocumentModal .alert").addClass("hidden");
|
||||
$("#exportDocumentText").addClass("hidden");
|
||||
|
||||
|
||||
$('#exportDocumentUl').empty();
|
||||
for (var i = 0; i < documentJsonArr.length; i++) {
|
||||
$("#exportDocumentUl").append('<li index='+i+'>'+decodeURI(documentJsonArr[i].fullUrl)+'</li>');
|
||||
@@ -503,6 +503,10 @@ $("#apiPathTree").on("click", ".show-doc", function(){
|
||||
htmlStrExample = paramName;
|
||||
addRequestParamObj(requestParamObj, paramName, paramType, paramIn, required, paramDesc, example);
|
||||
}
|
||||
} else if("body" == tempParameters.in) {
|
||||
requestParamObj["p-body-obj"] = "";
|
||||
htmlStr = paramName;
|
||||
htmlStrExample = paramName;
|
||||
} else if("string" == tempParameters.schema.type) {
|
||||
htmlStr = paramName;
|
||||
htmlStrExample = paramName;
|
||||
@@ -1071,4 +1075,4 @@ function checkSystemUpgrade() {
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<zyplayer.doc.version>1.0.2</zyplayer.doc.version>
|
||||
<!-- 打包跳过单元测试 -->
|
||||
<skipTests>true</skipTests>
|
||||
<elasticsearch.version>6.8.0</elasticsearch.version>
|
||||
<elasticsearch.version>7.2.0</elasticsearch.version>
|
||||
<destDir>${project.build.outputDirectory}/META-INF/resources/webjars/${project.artifactId}/${project.version}</destDir>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -272,12 +272,12 @@ public class WikiPageController {
|
||||
wikiPageContentService.save(pageContent);
|
||||
}
|
||||
// 保存到es
|
||||
if (esWikiPageService != null) {
|
||||
if (esWikiPageService.isOpen()) {
|
||||
WikiPage wikiPageSel = wikiPageService.getById(wikiPage.getId());
|
||||
EsWikiPage esWikiPage = mapper.map(wikiPageSel, EsWikiPage.class);
|
||||
esWikiPage.setContent(content);
|
||||
esWikiPage.setPreview(preview);
|
||||
esWikiPageService.create(esWikiPage);
|
||||
esWikiPageService.upsert(esWikiPage);
|
||||
} else {
|
||||
logger.warn("未开启elasticsearch服务,建议开启");
|
||||
}
|
||||
@@ -313,7 +313,7 @@ public class WikiPageController {
|
||||
|
||||
@PostMapping("/searchByEs")
|
||||
public ResponseJson<Object> searchByEs(SearchByEsParam param) {
|
||||
if (esWikiPageService != null) {
|
||||
if (esWikiPageService.isOpen()) {
|
||||
Map<Long, WikiSpace> wikiSpaceMap = this.getCanVisitWikiSpace(param.getSpaceId());
|
||||
if (wikiSpaceMap.isEmpty()) {
|
||||
return DocResponseJson.ok();
|
||||
@@ -329,6 +329,9 @@ public class WikiPageController {
|
||||
boolQueryBuilder.must(QueryBuilders.termQuery("delFlag", "0"));
|
||||
boolQueryBuilder.must(QueryBuilders.termsQuery("spaceId", wikiSpaceMap.keySet().toArray()));
|
||||
EsPage<EsWikiPage> wikiPageEsPage = esWikiPageService.getDataByQuery(boolQueryBuilder, fields, param.getStartIndex(), param.getPageSize());
|
||||
if (wikiPageEsPage == null || wikiPageEsPage.getTotal() == null) {
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
// 组装数据
|
||||
List<EsWikiPage> esWikiPageList = wikiPageEsPage.getData();
|
||||
List<SpaceNewsVo> pageVoList = new LinkedList<>();
|
||||
|
||||
Reference in New Issue
Block a user