删除不需要的代码,优化结构
This commit is contained in:
Binary file not shown.
@@ -13,9 +13,6 @@
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>zyplayer-doc-test</module>
|
||||
<module>zyplayer-doc-annotation</module>
|
||||
<module>zyplayer-doc-dubbo-libs</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,44 +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-doc-annotation</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>zyplayer-doc-annotation</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<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-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.zyplayer.doc.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface DocMethod {
|
||||
|
||||
/**
|
||||
* @return 方法的说明
|
||||
*/
|
||||
String value();
|
||||
|
||||
/**
|
||||
* @return 返回结果的说明
|
||||
*/
|
||||
String response() default "";
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.zyplayer.doc.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Repeatable(DocParams.class)
|
||||
public @interface DocParam {
|
||||
|
||||
/**
|
||||
* @return 说明
|
||||
*/
|
||||
String value();
|
||||
|
||||
/**
|
||||
* @return 字段名
|
||||
*/
|
||||
String name() default "";
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.zyplayer.doc.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface DocParams {
|
||||
|
||||
/**
|
||||
* @return 多个参数说明
|
||||
*/
|
||||
DocParam[] value();
|
||||
}
|
||||
@@ -1,108 +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-doc-dubbo-libs</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>zyplayer-doc-dubbo-libs</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--所有业务包放这里,打包之后在文档页面上传此jar-->
|
||||
<!--
|
||||
尝试过很多方式:
|
||||
比如在dubbo文档项目内,这样每次依赖的jar升级都需要重新发版
|
||||
比如自动下载远程仓库或读取本地仓库的jar来获取类,这样如果jar包里依赖了另外的jar则不可行了,需要解析整个maven依赖树,复杂度高
|
||||
当前找到的最合适的方式就是一个模块依赖所有需要的jar,然后打包后传上去,这样所有的依赖都在此包里了,也不需要重新发版
|
||||
如果你有更好的建议欢迎提出来探讨,非常乐意接受更加方便的建议!
|
||||
-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.zyplayer</groupId>-->
|
||||
<!-- <artifactId>dubbo-api</artifactId>-->
|
||||
<!-- <version>1.2</version>-->
|
||||
<!-- </dependency>-->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<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>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<!-- 在default生命周期的 validate阶段就执行resources插件的copy-resources目标 -->
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- 指定resources插件处理资源文件到哪个目录下 -->
|
||||
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
|
||||
<!-- 也可以用这样的方式<outputDirectory>target/classes</outputDirectory> -->
|
||||
<!-- 待处理的资源定义 -->
|
||||
<resources>
|
||||
<resource>
|
||||
<!-- 指定resources插件处理哪个目录下的资源文件 -->
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
|
||||
<resource>META-INF/spring.handlers</resource>
|
||||
</transformer>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
|
||||
<resource>META-INF/spring.schemas</resource>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,78 +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">
|
||||
|
||||
<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.1.1</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.1.1</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>-->
|
||||
<!--redis-->
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,31 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
package com.zyplayer.doc.test.config;
|
||||
|
||||
import com.github.dozermapper.core.Mapper;
|
||||
import com.github.dozermapper.core.DozerBeanMapperBuilder;
|
||||
import com.github.dozermapper.core.DozerConverter;
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,286 +0,0 @@
|
||||
//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);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -1,213 +0,0 @@
|
||||
//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.client.indices.GetMappingsRequest;
|
||||
//import org.elasticsearch.client.indices.GetMappingsResponse;
|
||||
//import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||
//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("/mappings")
|
||||
// public ResponseJson<Object> mappings() throws IOException {
|
||||
// GetMappingsRequest request = new GetMappingsRequest();
|
||||
//// request.indices(ES_INDEX);
|
||||
// request.setMasterTimeout(TimeValue.timeValueMinutes(1));
|
||||
// GetMappingsResponse getMappingResponse = client.indices().getMapping(request, RequestOptions.DEFAULT);
|
||||
// Map<String, MappingMetaData> allMappings = getMappingResponse.mappings();
|
||||
// MappingMetaData indexMapping = allMappings.get(ES_INDEX);
|
||||
// Map<String, Object> mapping = indexMapping.sourceAsMap();
|
||||
// // 相关文档地址
|
||||
// // https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-get-settings.html
|
||||
// // https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-settings.html
|
||||
// return DocResponseJson.ok(allMappings);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/other")
|
||||
// public ResponseJson<Object> other() {
|
||||
// return DocResponseJson.ok();
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@@ -1,205 +0,0 @@
|
||||
package com.zyplayer.doc.test.utils;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.Tuple;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* redis缓存工具类
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年08月25日
|
||||
*/
|
||||
public class RedisUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger(RedisUtil.class);
|
||||
private static JedisPool pool;
|
||||
|
||||
public static void init(String host, int port, int timeout) {
|
||||
if (pool != null) {
|
||||
logger.warn("redis连接池已初始化,请勿重复操作");
|
||||
return;
|
||||
}
|
||||
logger.info("初始化redis连接池...");
|
||||
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
poolConfig.setMaxTotal(200);
|
||||
poolConfig.setMaxIdle(50);
|
||||
poolConfig.setMinIdle(10);
|
||||
poolConfig.setTestOnReturn(true);
|
||||
pool = new JedisPool(poolConfig, host, port, timeout);
|
||||
logger.info("初始化redis连接池完毕");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取连接,执行,释放连接
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年08月25日
|
||||
* @param consumer 获取连接后的处理
|
||||
*/
|
||||
public static <T> T apply(Function<? super Jedis, ? extends T> consumer) {
|
||||
return expireAndApply(null, 0, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取连接,续期,执行,释放连接
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年08月25日
|
||||
* @param key 为空则不续期
|
||||
* @param expire 小于等于0则不续期
|
||||
* @param consumer 获取连接后的处理
|
||||
*/
|
||||
public static <T> T expireAndApply(String key, int expire, Function<? super Jedis, ? extends T> consumer) {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = pool.getResource();
|
||||
T result = consumer.apply(jedis);
|
||||
if (key != null && expire > 0) {
|
||||
jedis.expire(key, expire);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
logger.error("redis操作失败:{}", e.getMessage());
|
||||
return null;
|
||||
} finally {
|
||||
pool.returnResourceObject(jedis);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 累加
|
||||
*/
|
||||
public static Long incr(String key, int expire) {
|
||||
return expireAndApply(key, expire, jedis -> jedis.incr(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 浮点型累加
|
||||
*/
|
||||
public static Double incrByFloat(String key, Double value, int expire) {
|
||||
return expireAndApply(key, expire, jedis -> jedis.incrByFloat(key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 累加指定值
|
||||
*/
|
||||
public static Long incrByNum(String key, long num, int expire) {
|
||||
return expireAndApply(key, expire, jedis -> jedis.incrBy(key, num));
|
||||
}
|
||||
|
||||
/**
|
||||
* 排重set
|
||||
*/
|
||||
public static void uniqueSet(String key, int expire, String... member) {
|
||||
expireAndApply(key, expire, jedis -> jedis.sadd(key, member));
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断set中成员是否存在
|
||||
*/
|
||||
public static boolean checkExitInSet(String key, String member) {
|
||||
return apply(jedis -> jedis.sismember(key, member));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加到有序集合中
|
||||
*/
|
||||
public static void topSet(String key, String name, long score, int expire) {
|
||||
expireAndApply(key, expire, jedis -> jedis.zadd(key, score, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否存在
|
||||
*/
|
||||
public static boolean exists(String key) {
|
||||
return apply(jedis -> jedis.exists(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 续期
|
||||
*/
|
||||
public static void expire(String key, int seconds) {
|
||||
apply(jedis -> jedis.expire(key, seconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值
|
||||
*/
|
||||
public static String get(String key) {
|
||||
return apply(jedis -> jedis.get(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取long型值
|
||||
*/
|
||||
public static long getLong(String key) {
|
||||
return NumberUtils.toLong(get(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置值
|
||||
*/
|
||||
public static void set(String key, String value, int expire) {
|
||||
expireAndApply(key, expire, jedis -> jedis.set(key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置值
|
||||
* @param nxxx NX|XX, NX -- Only set the key if it does not already exist. XX -- Only set the key
|
||||
* if it already exist.
|
||||
* @param expx EX|PX, expire time units: EX = seconds; PX = milliseconds
|
||||
* @param time expire time in the units of {@param #expx}
|
||||
* @return Status code reply
|
||||
*/
|
||||
public static String set(String key, String value, String nxxx, String expx, Long time) {
|
||||
return apply(jedis -> jedis.set(key, value, nxxx, expx, time));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加List值
|
||||
*/
|
||||
public static Long sadd(String key, String... member) {
|
||||
return apply(jedis -> jedis.sadd(key, member));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除key
|
||||
*/
|
||||
public static void del(String key) {
|
||||
apply(jedis -> jedis.del(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊匹配获取key列表
|
||||
*/
|
||||
public static Set<String> keys(String pattern) {
|
||||
return apply(jedis -> jedis.keys(pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回值在指定区间内的集合
|
||||
*/
|
||||
public static Set<Tuple> zrevrangeWithScores(String topSetKey, int start, int end) {
|
||||
return apply(jedis -> jedis.zrevrangeWithScores(topSetKey, start, end));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将参数添加到 HyperLogLog 数据结构中
|
||||
*/
|
||||
public static Long pfadd(String key, String value, int expire) {
|
||||
return expireAndApply(key, expire, jedis -> jedis.pfadd(key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 HyperLogLog 的基数估算值
|
||||
*/
|
||||
public static long pfcount(String key) {
|
||||
return apply(jedis -> jedis.pfcount(key));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
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
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?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" />
|
||||
<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>
|
||||
Reference in New Issue
Block a user