在商品里引用es查询接口
parent
770d7cc049
commit
2635487e21
|
@ -5,9 +5,9 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.bawei</groupId>
|
||||
<artifactId>bawei-base</artifactId>
|
||||
<artifactId>base-es</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>base-es-common</artifactId>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.bawei.es.handler;
|
||||
package com.bawei.common.handler;
|
||||
|
||||
import com.bawei.common.core.constant.HttpStatus;
|
||||
import com.bawei.common.core.exception.DemoModeException;
|
|
@ -5,9 +5,9 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.bawei</groupId>
|
||||
<artifactId>bawei-base</artifactId>
|
||||
<artifactId>base-es</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>base-es-remote</artifactId>
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@FeignClient(contextId = "EsDocRemoteService", value = ServiceNameConstants.BAWEI_BASE_ES,
|
||||
@FeignClient(contextId = "EsDocRemoteService", value = ServiceNameConstants.ES_SERVICE,
|
||||
fallbackFactory = EsDocRemoteFactory.class,
|
||||
path = "/doc")
|
||||
public interface EsDocRemoteService {
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.cloud.openfeign.FeignClient;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
@FeignClient(contextId = "EsIndexRemoteService",value = ServiceNameConstants.BAWEI_BASE_ES,fallbackFactory = EsIndexRemoteFactory.class,path = "/index")
|
||||
@FeignClient(contextId = "EsIndexRemoteService",value = ServiceNameConstants.ES_SERVICE,fallbackFactory = EsIndexRemoteFactory.class,path = "/index")
|
||||
public interface EsIndexRemoteService {
|
||||
@PostMapping("/createIndex/{indexName}")
|
||||
public R createIndex(@PathVariable("indexName") String indexName, @RequestBody Map<String,Object> docMsg);
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.bawei</groupId>
|
||||
<artifactId>bawei-base</artifactId>
|
||||
<artifactId>base-es</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
<relativePath>./pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>base-es-server</artifactId>
|
||||
|
@ -53,11 +53,6 @@
|
|||
<artifactId>bawei-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.bawei</groupId>
|
||||
<artifactId>bawei-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
|
|
|
@ -10,5 +10,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||
public class EsApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EsApplication.class, args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ es服务模块启动成功 ლ(´ڡ`ლ)゙ ");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public class EsDocController {
|
|||
private EsDocService esDocService;
|
||||
|
||||
@GetMapping("/queryList/{indexName}")
|
||||
public R queryList(@PathVariable String indexName, @RequestParam Map<String,Object> docMsg){
|
||||
public R queryList(@PathVariable String indexName, @RequestBody Map<String,Object> docMsg){
|
||||
return R.ok(esDocService.queryList(indexName,docMsg),"数据查询成功");
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ server:
|
|||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: bawei-base-es
|
||||
name: bawei-es
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
|
@ -14,10 +14,14 @@ spring:
|
|||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 124.222.99.46:8848
|
||||
server-addr: 127.0.0.1:8848
|
||||
# 命名空间
|
||||
namespace: 12345678
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 124.222.99.46:8848
|
||||
server-addr: 127.0.0.1:8848
|
||||
#命令空间
|
||||
namespace: 12345678
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
@ -47,3 +51,11 @@ feign:
|
|||
min-request-size: 8192
|
||||
response:
|
||||
enabled: true
|
||||
# feign 配置
|
||||
feign:
|
||||
compression:
|
||||
request:
|
||||
enabled: true
|
||||
min-request-size: 8192
|
||||
response:
|
||||
enabled: true
|
||||
|
|
|
@ -11,5 +11,17 @@
|
|||
|
||||
<artifactId>base-es</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<description>
|
||||
base-es服务
|
||||
</description>
|
||||
<modules>
|
||||
<module>base-es-common</module>
|
||||
<module>base-es-remote</module>
|
||||
<module>base-es-server</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
|
|
@ -36,3 +36,11 @@ knife4j:
|
|||
enable: true # 开启knife4j接口文档美化
|
||||
setting:
|
||||
language: zh_cn # 指定语言
|
||||
# feign 配置
|
||||
feign:
|
||||
compression:
|
||||
request:
|
||||
enabled: true
|
||||
min-request-size: 8192
|
||||
response:
|
||||
enabled: true
|
||||
|
|
|
@ -42,3 +42,11 @@ knife4j:
|
|||
enable: true # 开启knife4j接口文档美化
|
||||
setting:
|
||||
language: zh_cn # 指定语言
|
||||
# feign 配置
|
||||
feign:
|
||||
compression:
|
||||
request:
|
||||
enabled: true
|
||||
min-request-size: 8192
|
||||
response:
|
||||
enabled: true
|
||||
|
|
|
@ -36,3 +36,11 @@ knife4j:
|
|||
enable: true # 开启knife4j接口文档美化
|
||||
setting:
|
||||
language: zh_cn # 指定语言
|
||||
# feign 配置
|
||||
feign:
|
||||
compression:
|
||||
request:
|
||||
enabled: true
|
||||
min-request-size: 8192
|
||||
response:
|
||||
enabled: true
|
||||
|
|
|
@ -36,3 +36,11 @@ knife4j:
|
|||
enable: true # 开启knife4j接口文档美化
|
||||
setting:
|
||||
language: zh_cn # 指定语言
|
||||
# feign 配置
|
||||
feign:
|
||||
compression:
|
||||
request:
|
||||
enabled: true
|
||||
min-request-size: 8192
|
||||
response:
|
||||
enabled: true
|
||||
|
|
|
@ -104,7 +104,6 @@
|
|||
<groupId>com.bawei</groupId>
|
||||
<artifactId>base-es-remote</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.bawei.mall.product.controller;
|
|||
import com.bawei.common.core.domain.R;
|
||||
import com.bawei.common.rabbit.domain.Message;
|
||||
import com.bawei.common.rabbit.enums.QueueEnum;
|
||||
import com.bawei.es.remote.api.RemoteIndexService;
|
||||
|
||||
import com.bawei.mall.product.cache.ProductInfoCache;
|
||||
import com.bawei.mall.product.domain.reponse.ProductDetailsResponse;
|
||||
import com.bawei.mall.product.domain.reponse.ProductInfoResponse;
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package com.bawei.mall.product.runer;
|
||||
|
||||
import com.bawei.common.core.domain.R;
|
||||
import com.bawei.es.remote.EsDocRemoteService;
|
||||
import com.bawei.es.remote.EsIndexRemoteService;
|
||||
import com.bawei.mall.product.domain.MallProductInfo;
|
||||
import com.bawei.mall.product.mapper.MallProductInfoMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @program: mall_cloud
|
||||
* @ClassName: EsRunnerImpl
|
||||
* @author: Gyc
|
||||
* @create: 2024-04-27 15:36
|
||||
**/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class EsRunnerImpl implements ApplicationRunner {
|
||||
@Autowired
|
||||
private EsIndexRemoteService esIndexRemoteService;
|
||||
@Autowired
|
||||
private EsDocRemoteService esDocRemoteService;
|
||||
@Autowired
|
||||
private MallProductInfoMapper mallProductInfoMapper;
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
List<MallProductInfo> mallProductInfos = mallProductInfoMapper.selectMallProductInfoList(new MallProductInfo());
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Map<String, Object> productMap = mallProductInfos.stream()
|
||||
.collect(Collectors.toMap(
|
||||
productInfo -> String.valueOf(productInfo.getId()),
|
||||
productInfo -> objectMapper.convertValue(productInfo, Map.class)
|
||||
));
|
||||
|
||||
R shop = esDocRemoteService.batchAddDoc("shop", productMap);
|
||||
log.info(shop);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -19,8 +19,8 @@ import com.bawei.common.core.utils.bean.BeanUtils;
|
|||
import com.bawei.common.rabbit.domain.Message;
|
||||
import com.bawei.common.rabbit.enums.QueueEnum;
|
||||
import com.bawei.common.security.utils.SecurityUtils;
|
||||
import com.bawei.es.remote.api.RemoteDocumentService;
|
||||
import com.bawei.es.remote.api.RemoteIndexService;
|
||||
import com.bawei.es.remote.EsDocRemoteService;
|
||||
import com.bawei.es.remote.EsIndexRemoteService;
|
||||
import com.bawei.mall.product.cache.ProductInfoCache;
|
||||
import com.bawei.mall.product.domain.MallProductRuleInfo;
|
||||
import com.bawei.mall.product.domain.MallProductSkuInfo;
|
||||
|
@ -32,6 +32,7 @@ import com.bawei.mall.product.domain.request.ProductInfoRequest;
|
|||
import com.bawei.mall.product.service.IMallProductRuleInfoService;
|
||||
import com.bawei.mall.product.service.IMallProductSkuInfoService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Builder;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -47,6 +48,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* @date 2022-09-19
|
||||
*/
|
||||
@Service
|
||||
@Builder
|
||||
public class MallProductInfoServiceImpl implements IMallProductInfoService
|
||||
{
|
||||
@Autowired
|
||||
|
@ -66,10 +68,10 @@ public class MallProductInfoServiceImpl implements IMallProductInfoService
|
|||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Autowired
|
||||
private RemoteDocumentService remoteDocumentService;
|
||||
private EsDocRemoteService esDocRemoteService;
|
||||
|
||||
@Autowired
|
||||
private RemoteIndexService remoteIndexService;
|
||||
private EsIndexRemoteService esIndexRemoteService;
|
||||
|
||||
/**
|
||||
* 查询商品信息
|
||||
|
@ -260,9 +262,9 @@ public class MallProductInfoServiceImpl implements IMallProductInfoService
|
|||
}else if (mallProductInfo.getStatus().equals("1") && status.equals("1")){
|
||||
throw new RuntimeException("商品已下架");
|
||||
}
|
||||
R shop = remoteIndexService.exist("shop");
|
||||
R shop = esIndexRemoteService.findIndex("shop");
|
||||
if (shop.isSuccess()){
|
||||
R r = remoteIndexService.deleteIndex("shop");
|
||||
R r = esIndexRemoteService.deleteIndex("shop");
|
||||
if (r.isSuccess()){
|
||||
//删除该索引后,进行修改数据
|
||||
mallProductInfo.setStatus(status);
|
||||
|
@ -278,9 +280,9 @@ public class MallProductInfoServiceImpl implements IMallProductInfoService
|
|||
@Override
|
||||
public R esList() {
|
||||
//添加es列表查询
|
||||
if (remoteIndexService.exist("shop").isSuccess()){
|
||||
if (esIndexRemoteService.findIndex("shop").isSuccess()){
|
||||
//查询es列表
|
||||
R shop = remoteDocumentService.queryList("shop", null);
|
||||
R shop = esDocRemoteService.queryList("shop", null);
|
||||
return R.ok(shop.getData());
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -38,3 +38,11 @@ knife4j:
|
|||
enable: true # 开启knife4j接口文档美化
|
||||
setting:
|
||||
language: zh_cn # 指定语言
|
||||
# feign 配置
|
||||
feign:
|
||||
compression:
|
||||
request:
|
||||
enabled: true
|
||||
min-request-size: 8192
|
||||
response:
|
||||
enabled: true
|
||||
|
|
Loading…
Reference in New Issue