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