--------去掉对es的支持和依赖,默认去掉对hive的包依赖,maven依赖关系优化,页面位置调整,增加build.bat的支持,支持jar直接启动,去掉历史遗留的无用前端代码,依赖的maven包升级--------
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package com.zyplayer.doc.data.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInterceptor;
|
||||
import com.zyplayer.doc.data.repository.support.interceptor.SqlLogInterceptor;
|
||||
import com.zyplayer.doc.data.utils.DruidDataSourceUtil;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
@@ -30,14 +32,7 @@ public class MybatisPlusConfig {
|
||||
/**
|
||||
* MYSQL 分页
|
||||
**/
|
||||
private static final PageHelper MYSQL_PAGE_HELPER;
|
||||
|
||||
static {
|
||||
MYSQL_PAGE_HELPER = new PageHelper();
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("dialect", "mysql");
|
||||
MYSQL_PAGE_HELPER.setProperties(properties);
|
||||
}
|
||||
private static final PageInterceptor MYSQL_PAGE_HELPER = new PageInterceptor();
|
||||
|
||||
/**
|
||||
* 数据库配置
|
||||
@@ -56,7 +51,7 @@ public class MybatisPlusConfig {
|
||||
@Value("${zyplayer.doc.manage.datasource.password}")
|
||||
private String password;
|
||||
@Resource
|
||||
private PaginationInterceptor paginationInterceptor;
|
||||
private MybatisPlusInterceptor paginationInterceptor;
|
||||
|
||||
@Bean(name = "manageDatasource")
|
||||
public DataSource manageDatasource() throws Exception {
|
||||
@@ -67,7 +62,7 @@ public class MybatisPlusConfig {
|
||||
public MybatisSqlSessionFactoryBean manageSqlSessionFactory() throws Exception {
|
||||
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
|
||||
sqlSessionFactoryBean.setDataSource(manageDatasource());
|
||||
sqlSessionFactoryBean.setPlugins(new Interceptor[]{SQL_LOG_INTERCEPTOR, MYSQL_PAGE_HELPER, paginationInterceptor});
|
||||
sqlSessionFactoryBean.setPlugins(SQL_LOG_INTERCEPTOR, MYSQL_PAGE_HELPER, paginationInterceptor);
|
||||
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mapper/manage/*Mapper.xml"));
|
||||
@@ -76,7 +71,9 @@ public class MybatisPlusConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor();
|
||||
public MybatisPlusInterceptor paginationInterceptor() {
|
||||
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
|
||||
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
|
||||
return mybatisPlusInterceptor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,94 +1,47 @@
|
||||
package com.zyplayer.doc.data.repository.support.generator;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
|
||||
public class CodeGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final String[] tableName = {"swagger_doc"};
|
||||
String url = "jdbc:mysql://127.0.0.1:3306/zyplayer_doc_manage?useUnicode=true&useSSL=false&characterEncoding=utf8";
|
||||
String projectPath = System.getProperty("user.dir") + "/zyplayer-doc-data";
|
||||
String outputDir = projectPath + "/src/main/java";
|
||||
String mapperDir = projectPath + "/src/main/resources/mapper/manage/";
|
||||
|
||||
final String moduleName = "manage";
|
||||
// final String[] tableName = { "zyplayer_storage", "auth_info", "user_auth", "user_info", "db_datasource" };
|
||||
// final String[] tableName = { "wiki_space", "wiki_page", "wiki_page_content", "wiki_page_file", "wiki_page_comment", "wiki_page_zan" };
|
||||
// final String[] tableName = { "db_datasource", "es_datasource", "db_favorite" };
|
||||
final String[] tableName = {"swagger_doc", "swagger_request_param", "swagger_global_param"};
|
||||
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
final String projectPath = System.getProperty("user.dir") + "/zyplayer-doc-data";
|
||||
gc.setOutputDir(projectPath + "/src/main/java");
|
||||
gc.setAuthor("暮光:城中城");
|
||||
gc.setOpen(false);
|
||||
gc.setFileOverride(true);// 是否覆盖
|
||||
gc.setDateType(DateType.ONLY_DATE);
|
||||
gc.setServiceName("%sService");
|
||||
gc.setControllerName("Generator%sController");
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/zyplayer_doc_manage?useUnicode=true&useSSL=false&characterEncoding=utf8");
|
||||
// dsc.setSchemaName("public");
|
||||
dsc.setDriverName("com.mysql.jdbc.Driver");
|
||||
dsc.setUsername("root");
|
||||
dsc.setPassword("root");
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
final PackageConfig pc = new PackageConfig();
|
||||
pc.setModuleName(null);
|
||||
pc.setParent("com.zyplayer.doc.data");
|
||||
pc.setController("web.generator");
|
||||
pc.setEntity("repository.manage.entity");
|
||||
pc.setMapper("repository.manage.mapper");
|
||||
pc.setService("service.manage");
|
||||
pc.setServiceImpl("service.manage.impl");
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 自定义配置
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
public void initMap() {
|
||||
// to do nothing
|
||||
}
|
||||
};
|
||||
List<FileOutConfig> focList = new ArrayList<>();
|
||||
focList.add(new FileOutConfig("/templates/mapper.xml.ftl") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return projectPath + "/src/main/resources/mapper/" + moduleName + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
||||
}
|
||||
});
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
mpg.setTemplate(new TemplateConfig().setXml(null));
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
// strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
|
||||
strategy.setEntityLombokModel(false);
|
||||
strategy.setRestControllerStyle(true);
|
||||
// strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
|
||||
// strategy.setSuperEntityColumns("id");
|
||||
strategy.setInclude(tableName);// 表名
|
||||
strategy.setControllerMappingHyphenStyle(true);
|
||||
strategy.setTablePrefix(pc.getModuleName() + "_");
|
||||
mpg.setStrategy(strategy);
|
||||
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
|
||||
mpg.execute();
|
||||
FastAutoGenerator.create(url, "root", "root")
|
||||
.globalConfig(builder -> {
|
||||
builder.author("暮光:城中城") // 设置作者
|
||||
.outputDir(outputDir)
|
||||
.dateType(DateType.ONLY_DATE)
|
||||
.fileOverride(); // 覆盖已生成文件
|
||||
})
|
||||
.packageConfig(builder -> {
|
||||
builder.parent("com.zyplayer.doc.data") // 设置父包名
|
||||
.moduleName("") // 设置父包模块名
|
||||
.controller("web.generator")
|
||||
.entity("repository.manage.entity")
|
||||
.mapper("repository.manage.mapper")
|
||||
.service("service.manage")
|
||||
.serviceImpl("service.manage.impl")
|
||||
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, mapperDir));
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
builder.addInclude(tableName) // 设置需要生成的表名
|
||||
.enableCapitalMode()
|
||||
.serviceBuilder()
|
||||
.formatServiceFileName("%sService")
|
||||
.formatServiceImplFileName("%sServiceImpl");
|
||||
})
|
||||
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
|
||||
.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zyplayer.doc.data.repository.support.interceptor;
|
||||
|
||||
import org.apache.ibatis.cache.CacheKey;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
@@ -20,8 +21,9 @@ import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
@Intercepts({
|
||||
@Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class }),
|
||||
@Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class })
|
||||
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}),
|
||||
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
|
||||
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}),
|
||||
})
|
||||
public class SqlLogInterceptor implements Interceptor {
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
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.EsAbstractService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* wiki文档搜索
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-07-07
|
||||
*/
|
||||
@Service
|
||||
public class EsWikiPageService extends EsAbstractService<EsWikiPage> {
|
||||
|
||||
@Override
|
||||
public Class<EsWikiPage> getObjClass() {
|
||||
return EsWikiPage.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryKey(EsWikiPage tableIndex) {
|
||||
return String.valueOf(tableIndex.getId());
|
||||
}
|
||||
}
|
||||
//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.EsAbstractService;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
///**
|
||||
// * wiki文档搜索
|
||||
// *
|
||||
// * @author 暮光:城中城
|
||||
// * @since 2019-07-07
|
||||
// */
|
||||
//@Service
|
||||
//public class EsWikiPageService extends EsAbstractService<EsWikiPage> {
|
||||
//
|
||||
// @Override
|
||||
// public Class<EsWikiPage> getObjClass() {
|
||||
// return EsWikiPage.class;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getPrimaryKey(EsWikiPage tableIndex) {
|
||||
// return String.valueOf(tableIndex.getId());
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
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;
|
||||
}
|
||||
return this.getEsClient(hostAndPort, esScheme);
|
||||
}
|
||||
|
||||
public RestHighLevelClient getEsClient(String hostPort, String scheme) {
|
||||
String mapKey = scheme + "_" + hostPort;
|
||||
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 : hostPort.split(",")) {
|
||||
String[] splitArr = hostPortStr.split(":");
|
||||
hostPortList.add(new HttpHost(splitArr[0], Integer.valueOf(splitArr[1]), scheme));
|
||||
}
|
||||
restClient = new RestHighLevelClient(RestClient.builder(hostPortList.toArray(new HttpHost[]{})));
|
||||
restClientMap.put(mapKey, restClient);
|
||||
} catch (Exception e) {
|
||||
logger.error("创建es客户端失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return restClient;
|
||||
}
|
||||
}
|
||||
//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;
|
||||
// }
|
||||
// return this.getEsClient(hostAndPort, esScheme);
|
||||
// }
|
||||
//
|
||||
// public RestHighLevelClient getEsClient(String hostPort, String scheme) {
|
||||
// String mapKey = scheme + "_" + hostPort;
|
||||
// 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 : hostPort.split(",")) {
|
||||
// String[] splitArr = hostPortStr.split(":");
|
||||
// hostPortList.add(new HttpHost(splitArr[0], Integer.valueOf(splitArr[1]), scheme));
|
||||
// }
|
||||
// restClient = new RestHighLevelClient(RestClient.builder(hostPortList.toArray(new HttpHost[]{})));
|
||||
// restClientMap.put(mapKey, restClient);
|
||||
// } catch (Exception e) {
|
||||
// logger.error("创建es客户端失败", e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return restClient;
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,217 +1,217 @@
|
||||
package com.zyplayer.doc.data.service.elasticsearch.support;
|
||||
|
||||
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.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.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抽象类
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-07-07
|
||||
*/
|
||||
public abstract class EsAbstractService<T> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(EsAbstractService.class);
|
||||
|
||||
@Resource
|
||||
private ElasticSearchUtil elasticSearchUtil;
|
||||
@Resource
|
||||
private Mapper mapper;
|
||||
|
||||
public abstract Class<T> getObjClass();
|
||||
|
||||
public abstract String getPrimaryKey(T table);
|
||||
|
||||
private String getIndexName() {
|
||||
Document annotation = this.getObjClass().getAnnotation(Document.class);
|
||||
return annotation.indexName();
|
||||
}
|
||||
|
||||
private String getIndexType() {
|
||||
Document annotation = this.getObjClass().getAnnotation(Document.class);
|
||||
return annotation.indexType();
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return elasticSearchUtil.isOpen();
|
||||
}
|
||||
|
||||
public boolean upsert(T table) {
|
||||
String pk = getPrimaryKey(table);
|
||||
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);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条件 模糊查询,查询前100条
|
||||
*
|
||||
* @param condition 查询条件
|
||||
*/
|
||||
public List<T> getDataByCondition(List<EsQueryColumn> condition) {
|
||||
return getDataByCondition(condition, null, 0, 100).getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条件 模糊查询
|
||||
*
|
||||
* @param condition 查询条件
|
||||
* @param startIndex 开始行
|
||||
* @param pageSize 每页数量
|
||||
*/
|
||||
public EsPage<T> getDataByCondition(List<EsQueryColumn> condition, String[] fields, Integer startIndex, Integer pageSize) {
|
||||
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
||||
// 组装条件
|
||||
for (EsQueryColumn column : condition) {
|
||||
if (StringUtils.isBlank(column.getValue())) {
|
||||
if (CollectionUtils.isEmpty(column.getValues())) {
|
||||
continue;
|
||||
}
|
||||
for (Object value : column.getValues()) {
|
||||
if (column.getType() == 0) {
|
||||
boolQueryBuilder.must(QueryBuilders.wildcardQuery(column.getKey(), value.toString()));
|
||||
} else if (column.getType() == 1) {
|
||||
boolQueryBuilder.must(QueryBuilders.termQuery(column.getKey(), value));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (column.getType() == 0) {
|
||||
boolQueryBuilder.must(QueryBuilders.wildcardQuery(column.getKey(), column.getValue()));
|
||||
} else if (column.getType() == 1) {
|
||||
boolQueryBuilder.must(QueryBuilders.termQuery(column.getKey(), column.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
condition.forEach(val -> {
|
||||
if (StringUtils.isNotBlank(val.getValue())) {
|
||||
if (val.getType() == 0) {
|
||||
boolQueryBuilder.must(QueryBuilders.wildcardQuery(val.getKey(), val.getValue()));
|
||||
} else if (val.getType() == 1) {
|
||||
boolQueryBuilder.must(QueryBuilders.termQuery(val.getKey(), val.getValue()));
|
||||
}
|
||||
}
|
||||
});
|
||||
return this.getDataByQuery(boolQueryBuilder, fields, startIndex, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条件 模糊查询
|
||||
*
|
||||
* @param queryBuilders 查询条件
|
||||
* @param startIndex 开始行
|
||||
* @param pageSize 每页数量
|
||||
*/
|
||||
public EsPage<T> getDataByQuery(QueryBuilder queryBuilders, String[] fields, Integer startIndex, Integer pageSize) {
|
||||
// 设置高亮标签
|
||||
HighlightBuilder highlightBuilder = new HighlightBuilder();
|
||||
highlightBuilder.preTags("<span style=\"color:red\">");
|
||||
highlightBuilder.postTags("</span>");
|
||||
highlightBuilder.field("*");
|
||||
// 组装条件
|
||||
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) {
|
||||
sourceBuilder.fetchSource(fields, new String[]{});
|
||||
}
|
||||
// 组装请求
|
||||
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) {
|
||||
List<T> tableList = new LinkedList<>();
|
||||
for (SearchHit searchHit : response.getHits().getHits()) {
|
||||
// 获取表ID和表类型
|
||||
Map<String, Object> sourceMap = searchHit.getSourceAsMap();
|
||||
if (sourceMap == null) {
|
||||
sourceMap = new HashMap<>();
|
||||
}
|
||||
// 获取高亮文本
|
||||
Map<String, HighlightField> highlightFieldMap = searchHit.getHighlightFields();
|
||||
for (String key : highlightFieldMap.keySet()) {
|
||||
HighlightField hf = highlightFieldMap.get(key);
|
||||
StringBuilder fragments = new StringBuilder();
|
||||
for (Text text : hf.getFragments()) {
|
||||
fragments.append(text.toString());
|
||||
}
|
||||
sourceMap.put(key, fragments.toString());
|
||||
}
|
||||
T table = mapper.map(sourceMap, this.getObjClass());
|
||||
tableList.add(table);
|
||||
}
|
||||
EsPage<T> esPage = new EsPage<>();
|
||||
esPage.setTotal(response.getHits().getTotalHits().value);
|
||||
esPage.setData(tableList);
|
||||
return esPage;
|
||||
}
|
||||
|
||||
}
|
||||
//package com.zyplayer.doc.data.service.elasticsearch.support;
|
||||
//
|
||||
//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.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.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抽象类
|
||||
// *
|
||||
// * @author 暮光:城中城
|
||||
// * @since 2019-07-07
|
||||
// */
|
||||
//public abstract class EsAbstractService<T> {
|
||||
// private static final Logger logger = LoggerFactory.getLogger(EsAbstractService.class);
|
||||
//
|
||||
// @Resource
|
||||
// private ElasticSearchUtil elasticSearchUtil;
|
||||
// @Resource
|
||||
// private Mapper mapper;
|
||||
//
|
||||
// public abstract Class<T> getObjClass();
|
||||
//
|
||||
// public abstract String getPrimaryKey(T table);
|
||||
//
|
||||
// private String getIndexName() {
|
||||
// Document annotation = this.getObjClass().getAnnotation(Document.class);
|
||||
// return annotation.indexName();
|
||||
// }
|
||||
//
|
||||
// private String getIndexType() {
|
||||
// Document annotation = this.getObjClass().getAnnotation(Document.class);
|
||||
// return annotation.indexType();
|
||||
// }
|
||||
//
|
||||
// public boolean isOpen() {
|
||||
// return elasticSearchUtil.isOpen();
|
||||
// }
|
||||
//
|
||||
// public boolean upsert(T table) {
|
||||
// String pk = getPrimaryKey(table);
|
||||
// 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);
|
||||
// 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();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 多条件 模糊查询,查询前100条
|
||||
// *
|
||||
// * @param condition 查询条件
|
||||
// */
|
||||
// public List<T> getDataByCondition(List<EsQueryColumn> condition) {
|
||||
// return getDataByCondition(condition, null, 0, 100).getData();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 多条件 模糊查询
|
||||
// *
|
||||
// * @param condition 查询条件
|
||||
// * @param startIndex 开始行
|
||||
// * @param pageSize 每页数量
|
||||
// */
|
||||
// public EsPage<T> getDataByCondition(List<EsQueryColumn> condition, String[] fields, Integer startIndex, Integer pageSize) {
|
||||
// BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
||||
// // 组装条件
|
||||
// for (EsQueryColumn column : condition) {
|
||||
// if (StringUtils.isBlank(column.getValue())) {
|
||||
// if (CollectionUtils.isEmpty(column.getValues())) {
|
||||
// continue;
|
||||
// }
|
||||
// for (Object value : column.getValues()) {
|
||||
// if (column.getType() == 0) {
|
||||
// boolQueryBuilder.must(QueryBuilders.wildcardQuery(column.getKey(), value.toString()));
|
||||
// } else if (column.getType() == 1) {
|
||||
// boolQueryBuilder.must(QueryBuilders.termQuery(column.getKey(), value));
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (column.getType() == 0) {
|
||||
// boolQueryBuilder.must(QueryBuilders.wildcardQuery(column.getKey(), column.getValue()));
|
||||
// } else if (column.getType() == 1) {
|
||||
// boolQueryBuilder.must(QueryBuilders.termQuery(column.getKey(), column.getValue()));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// condition.forEach(val -> {
|
||||
// if (StringUtils.isNotBlank(val.getValue())) {
|
||||
// if (val.getType() == 0) {
|
||||
// boolQueryBuilder.must(QueryBuilders.wildcardQuery(val.getKey(), val.getValue()));
|
||||
// } else if (val.getType() == 1) {
|
||||
// boolQueryBuilder.must(QueryBuilders.termQuery(val.getKey(), val.getValue()));
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// return this.getDataByQuery(boolQueryBuilder, fields, startIndex, pageSize);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 多条件 模糊查询
|
||||
// *
|
||||
// * @param queryBuilders 查询条件
|
||||
// * @param startIndex 开始行
|
||||
// * @param pageSize 每页数量
|
||||
// */
|
||||
// public EsPage<T> getDataByQuery(QueryBuilder queryBuilders, String[] fields, Integer startIndex, Integer pageSize) {
|
||||
// // 设置高亮标签
|
||||
// HighlightBuilder highlightBuilder = new HighlightBuilder();
|
||||
// highlightBuilder.preTags("<span style=\"color:red\">");
|
||||
// highlightBuilder.postTags("</span>");
|
||||
// highlightBuilder.field("*");
|
||||
// // 组装条件
|
||||
// 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) {
|
||||
// sourceBuilder.fetchSource(fields, new String[]{});
|
||||
// }
|
||||
// // 组装请求
|
||||
// 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) {
|
||||
// List<T> tableList = new LinkedList<>();
|
||||
// for (SearchHit searchHit : response.getHits().getHits()) {
|
||||
// // 获取表ID和表类型
|
||||
// Map<String, Object> sourceMap = searchHit.getSourceAsMap();
|
||||
// if (sourceMap == null) {
|
||||
// sourceMap = new HashMap<>();
|
||||
// }
|
||||
// // 获取高亮文本
|
||||
// Map<String, HighlightField> highlightFieldMap = searchHit.getHighlightFields();
|
||||
// for (String key : highlightFieldMap.keySet()) {
|
||||
// HighlightField hf = highlightFieldMap.get(key);
|
||||
// StringBuilder fragments = new StringBuilder();
|
||||
// for (Text text : hf.getFragments()) {
|
||||
// fragments.append(text.toString());
|
||||
// }
|
||||
// sourceMap.put(key, fragments.toString());
|
||||
// }
|
||||
// T table = mapper.map(sourceMap, this.getObjClass());
|
||||
// tableList.add(table);
|
||||
// }
|
||||
// EsPage<T> esPage = new EsPage<>();
|
||||
// esPage.setTotal(response.getHits().getTotalHits().value);
|
||||
// esPage.setData(tableList);
|
||||
// return esPage;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zyplayer.doc.data.service.manage.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
@@ -11,7 +12,6 @@ import com.zyplayer.doc.data.repository.support.consts.UserMsgSysType;
|
||||
import com.zyplayer.doc.data.repository.support.consts.UserMsgType;
|
||||
import com.zyplayer.doc.data.service.manage.UserMessageService;
|
||||
import com.zyplayer.doc.data.service.manage.WikiPageService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -80,7 +80,7 @@ public class WikiPageServiceImpl extends ServiceImpl<WikiPageMapper, WikiPage> i
|
||||
wrapper.eq("del_flag", 0);
|
||||
wrapper.eq("parent_id", wikiPage.getId());
|
||||
List<WikiPage> wikiPageList = this.list(wrapper);
|
||||
if (CollectionUtils.isEmpty(wikiPageList)) {
|
||||
if (CollectionUtil.isEmpty(wikiPageList)) {
|
||||
return;
|
||||
}
|
||||
// 递归删除子页面
|
||||
|
||||
@@ -88,6 +88,7 @@ public class CacheUtil {
|
||||
* 获取缓存
|
||||
* @param key
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T get(String key) {
|
||||
if (StringUtils.isBlank(key)) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user