From 2635487e21af79268eb99311d25a45763a8653f1 Mon Sep 17 00:00:00 2001
From: gyc <2649472510@qq.com>
Date: Sun, 28 Apr 2024 20:30:36 +0800
Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=95=86=E5=93=81=E9=87=8C=E5=BC=95?=
=?UTF-8?q?=E7=94=A8es=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
bawei-base/base-es/base-es-common/pom.xml | 4 +-
.../handler/GlobalExceptionHandler.java | 2 +-
bawei-base/base-es/base-es-remote/pom.xml | 4 +-
.../bawei/es/remote/EsDocRemoteService.java | 2 +-
.../bawei/es/remote/EsIndexRemoteService.java | 2 +-
bawei-base/base-es/base-es-server/pom.xml | 9 +---
.../main/java/com/bawei/es/EsApplication.java | 1 +
.../bawei/es/controller/EsDocController.java | 2 +-
.../src/main/resources/bootstrap.yml | 18 +++++--
bawei-base/base-es/pom.xml | 14 ++++-
.../src/main/resources/bootstrap.yml | 8 +++
.../base-gen/src/main/resources/bootstrap.yml | 8 +++
.../base-job/src/main/resources/bootstrap.yml | 8 +++
.../src/main/resources/bootstrap.yml | 8 +++
.../bawei-mall-product-server/pom.xml | 1 -
.../product/controller/TestController.java | 2 +-
.../mall/product/runer/EsRunnerImpl.java | 51 +++++++++++++++++++
.../impl/MallProductInfoServiceImpl.java | 18 ++++---
.../src/main/resources/bootstrap.yml | 8 +++
19 files changed, 141 insertions(+), 29 deletions(-)
rename bawei-base/base-es/{base-es-server/src/main/java/com/bawei/es => base-es-common/src/main/java/com/bawei/common}/handler/GlobalExceptionHandler.java (99%)
create mode 100644 bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/runer/EsRunnerImpl.java
diff --git a/bawei-base/base-es/base-es-common/pom.xml b/bawei-base/base-es/base-es-common/pom.xml
index 6c30fb9..eabe7e3 100644
--- a/bawei-base/base-es/base-es-common/pom.xml
+++ b/bawei-base/base-es/base-es-common/pom.xml
@@ -5,9 +5,9 @@
4.0.0
com.bawei
- bawei-base
+ base-es
3.6.0
- ../../pom.xml
+ ../pom.xml
base-es-common
diff --git a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/handler/GlobalExceptionHandler.java b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/handler/GlobalExceptionHandler.java
similarity index 99%
rename from bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/handler/GlobalExceptionHandler.java
rename to bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/handler/GlobalExceptionHandler.java
index a099b3d..57bde85 100644
--- a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/handler/GlobalExceptionHandler.java
+++ b/bawei-base/base-es/base-es-common/src/main/java/com/bawei/common/handler/GlobalExceptionHandler.java
@@ -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;
diff --git a/bawei-base/base-es/base-es-remote/pom.xml b/bawei-base/base-es/base-es-remote/pom.xml
index e92d62a..7854eac 100644
--- a/bawei-base/base-es/base-es-remote/pom.xml
+++ b/bawei-base/base-es/base-es-remote/pom.xml
@@ -5,9 +5,9 @@
4.0.0
com.bawei
- bawei-base
+ base-es
3.6.0
- ../../pom.xml
+ ../pom.xml
base-es-remote
diff --git a/bawei-base/base-es/base-es-remote/src/main/java/com/bawei/es/remote/EsDocRemoteService.java b/bawei-base/base-es/base-es-remote/src/main/java/com/bawei/es/remote/EsDocRemoteService.java
index c08796b..66236b9 100644
--- a/bawei-base/base-es/base-es-remote/src/main/java/com/bawei/es/remote/EsDocRemoteService.java
+++ b/bawei-base/base-es/base-es-remote/src/main/java/com/bawei/es/remote/EsDocRemoteService.java
@@ -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 {
diff --git a/bawei-base/base-es/base-es-remote/src/main/java/com/bawei/es/remote/EsIndexRemoteService.java b/bawei-base/base-es/base-es-remote/src/main/java/com/bawei/es/remote/EsIndexRemoteService.java
index 8c797b1..6a8fb0e 100644
--- a/bawei-base/base-es/base-es-remote/src/main/java/com/bawei/es/remote/EsIndexRemoteService.java
+++ b/bawei-base/base-es/base-es-remote/src/main/java/com/bawei/es/remote/EsIndexRemoteService.java
@@ -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 docMsg);
diff --git a/bawei-base/base-es/base-es-server/pom.xml b/bawei-base/base-es/base-es-server/pom.xml
index e3c097b..e1b2fe7 100644
--- a/bawei-base/base-es/base-es-server/pom.xml
+++ b/bawei-base/base-es/base-es-server/pom.xml
@@ -5,9 +5,9 @@
4.0.0
com.bawei
- bawei-base
+ base-es
3.6.0
- ../../pom.xml
+ ./pom.xml
base-es-server
@@ -53,11 +53,6 @@
bawei-common-swagger
-
- com.bawei
- bawei-common-core
-
-
org.hibernate.validator
hibernate-validator
diff --git a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/EsApplication.java b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/EsApplication.java
index 2a18888..2fcde4a 100644
--- a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/EsApplication.java
+++ b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/EsApplication.java
@@ -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服务模块启动成功 ლ(´ڡ`ლ)゙ ");
}
}
diff --git a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/controller/EsDocController.java b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/controller/EsDocController.java
index e5108aa..2443255 100644
--- a/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/controller/EsDocController.java
+++ b/bawei-base/base-es/base-es-server/src/main/java/com/bawei/es/controller/EsDocController.java
@@ -16,7 +16,7 @@ public class EsDocController {
private EsDocService esDocService;
@GetMapping("/queryList/{indexName}")
- public R queryList(@PathVariable String indexName, @RequestParam Map docMsg){
+ public R queryList(@PathVariable String indexName, @RequestBody Map docMsg){
return R.ok(esDocService.queryList(indexName,docMsg),"数据查询成功");
}
diff --git a/bawei-base/base-es/base-es-server/src/main/resources/bootstrap.yml b/bawei-base/base-es/base-es-server/src/main/resources/bootstrap.yml
index 90c9077..da77dc3 100644
--- a/bawei-base/base-es/base-es-server/src/main/resources/bootstrap.yml
+++ b/bawei-base/base-es/base-es-server/src/main/resources/bootstrap.yml
@@ -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
diff --git a/bawei-base/base-es/pom.xml b/bawei-base/base-es/pom.xml
index 42ff87a..40a6f8c 100644
--- a/bawei-base/base-es/pom.xml
+++ b/bawei-base/base-es/pom.xml
@@ -11,5 +11,17 @@
base-es
pom
-
+
+ 8
+ 8
+ UTF-8
+
+
+ base-es服务
+
+
+ base-es-common
+ base-es-remote
+ base-es-server
+
diff --git a/bawei-base/base-file/base-file-server/src/main/resources/bootstrap.yml b/bawei-base/base-file/base-file-server/src/main/resources/bootstrap.yml
index 93c36a8..d5b4f95 100644
--- a/bawei-base/base-file/base-file-server/src/main/resources/bootstrap.yml
+++ b/bawei-base/base-file/base-file-server/src/main/resources/bootstrap.yml
@@ -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
diff --git a/bawei-base/base-gen/src/main/resources/bootstrap.yml b/bawei-base/base-gen/src/main/resources/bootstrap.yml
index e76f3f0..7dceda7 100644
--- a/bawei-base/base-gen/src/main/resources/bootstrap.yml
+++ b/bawei-base/base-gen/src/main/resources/bootstrap.yml
@@ -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
diff --git a/bawei-base/base-job/src/main/resources/bootstrap.yml b/bawei-base/base-job/src/main/resources/bootstrap.yml
index 93dc9b9..4e37f1c 100644
--- a/bawei-base/base-job/src/main/resources/bootstrap.yml
+++ b/bawei-base/base-job/src/main/resources/bootstrap.yml
@@ -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
diff --git a/bawei-base/base-system/base-system-server/src/main/resources/bootstrap.yml b/bawei-base/base-system/base-system-server/src/main/resources/bootstrap.yml
index cc173aa..6d2f333 100644
--- a/bawei-base/base-system/base-system-server/src/main/resources/bootstrap.yml
+++ b/bawei-base/base-system/base-system-server/src/main/resources/bootstrap.yml
@@ -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
diff --git a/bawei-mall/bawei-mall-product/bawei-mall-product-server/pom.xml b/bawei-mall/bawei-mall-product/bawei-mall-product-server/pom.xml
index 302db47..cbcf94f 100644
--- a/bawei-mall/bawei-mall-product/bawei-mall-product-server/pom.xml
+++ b/bawei-mall/bawei-mall-product/bawei-mall-product-server/pom.xml
@@ -104,7 +104,6 @@
com.bawei
base-es-remote
-
diff --git a/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/controller/TestController.java b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/controller/TestController.java
index bccfc77..d1f8f97 100644
--- a/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/controller/TestController.java
+++ b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/controller/TestController.java
@@ -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;
diff --git a/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/runer/EsRunnerImpl.java b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/runer/EsRunnerImpl.java
new file mode 100644
index 0000000..5673469
--- /dev/null
+++ b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/runer/EsRunnerImpl.java
@@ -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 mallProductInfos = mallProductInfoMapper.selectMallProductInfoList(new MallProductInfo());
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map 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);
+
+
+ }
+
+}
diff --git a/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/service/impl/MallProductInfoServiceImpl.java b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/service/impl/MallProductInfoServiceImpl.java
index 5d909f8..4600e3b 100644
--- a/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/service/impl/MallProductInfoServiceImpl.java
+++ b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/java/com/bawei/mall/product/service/impl/MallProductInfoServiceImpl.java
@@ -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;
diff --git a/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/resources/bootstrap.yml b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/resources/bootstrap.yml
index 319d684..77b6fec 100644
--- a/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/resources/bootstrap.yml
+++ b/bawei-mall/bawei-mall-product/bawei-mall-product-server/src/main/resources/bootstrap.yml
@@ -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