|
|
|
@@ -1,5 +1,7 @@ |
|
|
|
package com.xueyi.common.web.entity.service.impl; |
|
|
|
|
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient; |
|
|
|
import co.elastic.clients.elasticsearch.indices.CreateIndexResponse; |
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
|
|
|
import com.xueyi.common.core.constant.basic.BaseConstants; |
|
|
|
import com.xueyi.common.core.constant.basic.OperateConstants; |
|
|
|
@@ -11,7 +13,11 @@ import com.xueyi.common.redis.constant.RedisConstants; |
|
|
|
import com.xueyi.common.web.entity.manager.IBaseManager; |
|
|
|
import com.xueyi.common.web.entity.service.IBaseService; |
|
|
|
import com.xueyi.common.web.entity.service.impl.handle.BaseHandleServiceImpl; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.Serializable; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
@@ -27,6 +33,7 @@ import java.util.stream.Collectors; |
|
|
|
*/ |
|
|
|
public class BaseServiceImpl<Q extends BaseEntity, D extends BaseEntity, IDG extends IBaseManager<Q, D>> extends BaseHandleServiceImpl<Q, D, IDG> implements IBaseService<Q, D> { |
|
|
|
|
|
|
|
private Logger log = LoggerFactory.getLogger(BaseServiceImpl.class); |
|
|
|
/** |
|
|
|
* 查询数据对象列表 |
|
|
|
* |
|
|
|
@@ -214,4 +221,37 @@ public class BaseServiceImpl<Q extends BaseEntity, D extends BaseEntity, IDG ext |
|
|
|
throw new UtilException("未正常配置缓存,无法使用!"); |
|
|
|
refreshCache(null, RedisConstants.OperateType.REFRESH_ALL, null, null); |
|
|
|
} |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ElasticsearchClient client; |
|
|
|
@Override |
|
|
|
public void createEsIndex(D dto) { |
|
|
|
boolean exists = false; |
|
|
|
try { |
|
|
|
exists = client.indices().exists(query -> query.index(dto.getClass().getSimpleName())).value(); |
|
|
|
System.out.println(exists); |
|
|
|
if (exists) { |
|
|
|
log.info("索引已存在"); |
|
|
|
} else { |
|
|
|
final CreateIndexResponse products = client.indices().create(builder -> builder.index(dto.getClass().getSimpleName())); |
|
|
|
log.info(products.acknowledged()?"索引创建成功" : "索引创建失败"); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void saveToEs(BaseEntity dto) { |
|
|
|
try { |
|
|
|
createEsIndex((D)dto); |
|
|
|
client.index(i -> i |
|
|
|
.index(dto.getClass().getSimpleName()) |
|
|
|
.id(dto.getId().toString()) |
|
|
|
.document(dto)); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |