diff --git a/.idea/deployment.xml b/.idea/deployment.xml
deleted file mode 100644
index 0ebb202..0000000
--- a/.idea/deployment.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index b85319c..7556275 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -13,6 +13,9 @@
+
+
+
diff --git a/pom.xml b/pom.xml
index df6b8c1..999a7f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,6 +18,7 @@
common
model
service
+ service-client
diff --git a/service-client/pom.xml b/service-client/pom.xml
new file mode 100644
index 0000000..b6ad079
--- /dev/null
+++ b/service-client/pom.xml
@@ -0,0 +1,53 @@
+
+ 4.0.0
+
+ com.atguigu
+ guigu-ssyx-parent
+ 1.0-SNAPSHOT
+
+
+ service-client
+ pom
+
+ service-client
+ https://maven.apache.org
+
+ service-product-client
+
+
+
+ UTF-8
+
+
+
+
+ com.atguigu
+ service-util
+ 1.0-SNAPSHOT
+
+
+
+ com.atguigu
+ model
+ 1.0-SNAPSHOT
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-loadbalancer
+
+
+
diff --git a/service-client/service-product-client/pom.xml b/service-client/service-product-client/pom.xml
new file mode 100644
index 0000000..f56182b
--- /dev/null
+++ b/service-client/service-product-client/pom.xml
@@ -0,0 +1,23 @@
+
+ 4.0.0
+
+ com.atguigu
+ service-client
+ 1.0-SNAPSHOT
+
+
+ service-product-client
+ jar
+
+ service-product-client
+ https://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+
+
diff --git a/service-client/service-product-client/src/main/java/com/atguigu/ssyx/client/product/ProductFeignClient.java b/service-client/service-product-client/src/main/java/com/atguigu/ssyx/client/product/ProductFeignClient.java
new file mode 100644
index 0000000..fb684ca
--- /dev/null
+++ b/service-client/service-product-client/src/main/java/com/atguigu/ssyx/client/product/ProductFeignClient.java
@@ -0,0 +1,17 @@
+package com.atguigu.ssyx.client.product;
+
+import com.atguigu.ssyx.common.result.Result;
+import com.atguigu.ssyx.model.product.Category;
+import com.atguigu.ssyx.model.product.SkuInfo;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+
+@FeignClient(value = "service-product", path = "/api/product")
+public interface ProductFeignClient {
+ @GetMapping("inner/getCategory/{categoryId}")
+ Result getCategory(@PathVariable Long categoryId);
+
+ @GetMapping("inner/getSkuInfo/{skuId}")
+ Result getSkuInfo(@PathVariable Long skuId);
+}
diff --git a/service/pom.xml b/service/pom.xml
index c36e6ba..8091cd0 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -72,12 +72,5 @@
com.alibaba.cloud
spring-cloud-starter-alibaba-sentinel
-
-
-
- org.springframework.boot
- spring-boot-devtools
- true
-
diff --git a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/ServiceAclApplication.java b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/ServiceAclApplication.java
index f38d0d9..dad9e58 100644
--- a/service/service-acl/src/main/java/com/atguigu/ssyx/acl/ServiceAclApplication.java
+++ b/service/service-acl/src/main/java/com/atguigu/ssyx/acl/ServiceAclApplication.java
@@ -6,7 +6,7 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
-@ComponentScan(basePackages = {"com.atguigu.ssyx"})
+@ComponentScan(basePackages = {"com.atguigu.ssyx.common"})
@EnableTransactionManagement
public class ServiceAclApplication {
public static void main(String[] args) {
diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/ServiceProductApplication.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/ServiceProductApplication.java
index e3b8ff3..9fdb154 100644
--- a/service/service-product/src/main/java/com/atguigu/ssyx/product/ServiceProductApplication.java
+++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/ServiceProductApplication.java
@@ -6,7 +6,7 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
-@ComponentScan(basePackages = {"com.atguigu.ssyx"})
+@ComponentScan(basePackages = {"com.atguigu.ssyx.common"})
@EnableTransactionManagement
public class ServiceProductApplication {
public static void main(String[] args) {
diff --git a/service/service-product/src/main/java/com/atguigu/ssyx/product/api/ProductInnerController.java b/service/service-product/src/main/java/com/atguigu/ssyx/product/api/ProductInnerController.java
new file mode 100644
index 0000000..11f852b
--- /dev/null
+++ b/service/service-product/src/main/java/com/atguigu/ssyx/product/api/ProductInnerController.java
@@ -0,0 +1,38 @@
+package com.atguigu.ssyx.product.api;
+
+import com.atguigu.ssyx.common.result.Result;
+import com.atguigu.ssyx.model.product.Category;
+import com.atguigu.ssyx.model.product.SkuInfo;
+import com.atguigu.ssyx.product.service.CategoryService;
+import com.atguigu.ssyx.product.service.SkuInfoService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(value = "远程调用接口", tags = "远程调用接口")
+@RestController
+@RequestMapping("/api/product")
+public class ProductInnerController {
+ @Autowired
+ private CategoryService categoryService;
+ @Autowired
+ private SkuInfoService skuInfoService;
+
+ @ApiOperation(value = "根据分类id获取分类信息")
+ @GetMapping("inner/getCategory/{categoryId}")
+ public Result getCategory(@PathVariable Long categoryId) {
+ Category category = categoryService.getById(categoryId);
+ return Result.success(category);
+ }
+
+ @ApiOperation(value = "根据skuId获取sku信息")
+ @GetMapping("inner/getSkuInfo/{skuId}")
+ public Result getSkuInfo(@PathVariable Long skuId) {
+ SkuInfo skuInfo = skuInfoService.getById(skuId);
+ return Result.success(skuInfo);
+ }
+}
diff --git a/service/service-search/pom.xml b/service/service-search/pom.xml
index 3748cb6..a7554ea 100644
--- a/service/service-search/pom.xml
+++ b/service/service-search/pom.xml
@@ -1,4 +1,4 @@
-
4.0.0
@@ -18,6 +18,12 @@
+
+ com.atguigu
+ service-product-client
+ 1.0-SNAPSHOT
+
+
org.springframework.boot
spring-boot-starter-data-elasticsearch
@@ -27,10 +33,5 @@
org.springframework.boot
spring-boot-starter-data-redis
-
-
-
-
-
diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/ServiceSearchApplication.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/ServiceSearchApplication.java
index ef6e58d..eada2c8 100644
--- a/service/service-search/src/main/java/com/atguigu/ssyx/search/ServiceSearchApplication.java
+++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/ServiceSearchApplication.java
@@ -6,12 +6,11 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
-import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
-@ComponentScan(basePackages = {"com.atguigu.ssyx"})
+@ComponentScan(basePackages = {"com.atguigu.ssyx.common"})
+@EnableFeignClients(basePackages = {"com.atguigu.ssyx.client"})
@EnableDiscoveryClient
-@EnableFeignClients
public class ServiceSearchApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceSearchApplication.class, args);
diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/controller/SkuApiController.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/controller/SkuApiController.java
index b1d7d32..9e5155c 100644
--- a/service/service-search/src/main/java/com/atguigu/ssyx/search/controller/SkuApiController.java
+++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/controller/SkuApiController.java
@@ -1,9 +1,34 @@
package com.atguigu.ssyx.search.controller;
+import com.atguigu.ssyx.common.result.Result;
+import com.atguigu.ssyx.model.product.SkuInfo;
+import com.atguigu.ssyx.search.service.SkuService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
+@Api(tags = "商品添加到ES")
@RestController
@RequestMapping("/api/search/sku")
public class SkuApiController {
+ @Autowired
+ private SkuService skuService;
+
+ @ApiOperation(value = "上架商品")
+ @GetMapping("inner/upperSku/{skuId}")
+ public Result upperGoods(@PathVariable Long skuId) {
+ skuService.upperSku(skuId);
+ return Result.success();
+ }
+
+ @ApiOperation(value = "下架商品")
+ @GetMapping("inner/lowerSku/{skuId}")
+ public Result lowerGoods(@PathVariable Long skuId) {
+ skuService.lowerGoods(skuId);
+ return Result.success();
+ }
}
diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/service/SkuService.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/service/SkuService.java
index 529a69b..d16d006 100644
--- a/service/service-search/src/main/java/com/atguigu/ssyx/search/service/SkuService.java
+++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/service/SkuService.java
@@ -1,4 +1,17 @@
package com.atguigu.ssyx.search.service;
public interface SkuService {
+ /**
+ * 上架商品
+ *
+ * @param skuId 商品ID
+ */
+ void upperSku(Long skuId);
+
+ /**
+ * 下架商品
+ *
+ * @param skuId 商品ID
+ */
+ void lowerGoods(Long skuId);
}
diff --git a/service/service-search/src/main/java/com/atguigu/ssyx/search/service/impl/SkuServiceImpl.java b/service/service-search/src/main/java/com/atguigu/ssyx/search/service/impl/SkuServiceImpl.java
index c883203..8cdd3c6 100644
--- a/service/service-search/src/main/java/com/atguigu/ssyx/search/service/impl/SkuServiceImpl.java
+++ b/service/service-search/src/main/java/com/atguigu/ssyx/search/service/impl/SkuServiceImpl.java
@@ -1,8 +1,64 @@
package com.atguigu.ssyx.search.service.impl;
+import com.atguigu.ssyx.client.product.ProductFeignClient;
+import com.atguigu.ssyx.enums.SkuType;
+import com.atguigu.ssyx.model.product.Category;
+import com.atguigu.ssyx.model.product.SkuInfo;
+import com.atguigu.ssyx.model.search.SkuEs;
+import com.atguigu.ssyx.search.repository.SkuRepository;
import com.atguigu.ssyx.search.service.SkuService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.util.Objects;
+
@Service
public class SkuServiceImpl implements SkuService {
+ @Autowired
+ private SkuRepository skuRepository;
+ @Autowired
+ private ProductFeignClient productFeignClient;
+
+ /**
+ * 上架商品
+ *
+ * @param skuId 商品ID
+ */
+ @Override
+ public void upperSku(Long skuId) {
+ SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId).getData();
+ Category category = productFeignClient.getCategory(skuId).getData();
+ // 获取数据封装SkuEs
+ SkuEs skuEs = new SkuEs();
+ if (category != null) {
+ skuEs.setCategoryId(category.getId());
+ skuEs.setCategoryName(category.getName());
+ }
+ if (skuInfo != null) {
+ skuEs.setId(skuInfo.getId());
+ skuEs.setKeyword(skuInfo.getSkuName() + "," + skuEs.getCategoryName());
+ skuEs.setWareId(skuInfo.getWareId());
+ skuEs.setIsNewPerson(skuInfo.getIsNewPerson());
+ skuEs.setImgUrl(skuInfo.getImgUrl());
+ skuEs.setTitle(skuInfo.getSkuName());
+ if (Objects.equals(skuInfo.getSkuType(), SkuType.COMMON.getCode())) {
+ skuEs.setSkuType(0);
+ skuEs.setPrice(skuInfo.getPrice().doubleValue());
+ skuEs.setStock(skuInfo.getStock());
+ skuEs.setSale(skuInfo.getSale());
+ skuEs.setPerLimit(skuInfo.getPerLimit());
+ }
+ skuRepository.save(skuEs);
+ }
+ }
+
+ /**
+ * 下架商品
+ *
+ * @param skuId 商品ID
+ */
+ @Override
+ public void lowerGoods(Long skuId) {
+ skuRepository.deleteById(skuId);
+ }
}
diff --git a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/ServiceSysApplication.java b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/ServiceSysApplication.java
index 5f5c71b..d7734eb 100644
--- a/service/service-sys/src/main/java/com/atguigu/ssyx/sys/ServiceSysApplication.java
+++ b/service/service-sys/src/main/java/com/atguigu/ssyx/sys/ServiceSysApplication.java
@@ -7,7 +7,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableTransactionManagement
-@ComponentScan(basePackages = {"com.atguigu.ssyx"})
+@ComponentScan(basePackages = {"com.atguigu.ssyx.common"})
public class ServiceSysApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceSysApplication.class, args);