整合es、rabbitmq、redis完成上下架修改es
This commit is contained in:
		@@ -15,6 +15,7 @@
 | 
			
		||||
        <module>service-acl</module>
 | 
			
		||||
        <module>service-sys</module>
 | 
			
		||||
        <module>service-product</module>
 | 
			
		||||
        <module>service-search</module>
 | 
			
		||||
    </modules>
 | 
			
		||||
 | 
			
		||||
    <dependencies>
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,12 @@
 | 
			
		||||
            <artifactId>joda-time</artifactId>
 | 
			
		||||
            <version>2.10.1</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.atguigu</groupId>
 | 
			
		||||
            <artifactId>rabbit_util</artifactId>
 | 
			
		||||
            <version>1.0-SNAPSHOT</version>
 | 
			
		||||
            <scope>compile</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
    </dependencies>
 | 
			
		||||
    <properties>
 | 
			
		||||
        <maven.compiler.source>8</maven.compiler.source>
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,43 @@
 | 
			
		||||
package com.atguigu.ssyx.product.api;
 | 
			
		||||
 | 
			
		||||
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.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;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: ProductInnnerController
 | 
			
		||||
 * Package: com.atguigu.ssyx.product.api
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/16 17:28
 | 
			
		||||
 */
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("api/product")
 | 
			
		||||
public class ProductInnnerController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    CategoryService categoryService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    SkuInfoService skuInfoService;
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "根据分类id获取分类信息")
 | 
			
		||||
    @GetMapping("inner/getCategory/{categoryId}")
 | 
			
		||||
    public Category getCategory(@PathVariable Long categoryId) {
 | 
			
		||||
        return categoryService.getById(categoryId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "根据skuId获取sku信息")
 | 
			
		||||
    @GetMapping("inner/getSkuInfo/{skuId}")
 | 
			
		||||
    public SkuInfo getSkuInfo(@PathVariable("skuId") Long skuId) {
 | 
			
		||||
        return skuInfoService.getById(skuId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -83,6 +83,7 @@ public class SkuInfoController {
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "删除商品sku信息")
 | 
			
		||||
    @DeleteMapping("remove/{id}")
 | 
			
		||||
    //TODO 删除es
 | 
			
		||||
    public Result remove(@PathVariable Long id) {
 | 
			
		||||
        try {
 | 
			
		||||
            skuInfoService.removeById(id);
 | 
			
		||||
@@ -94,6 +95,7 @@ public class SkuInfoController {
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "根据id列表删除商品sku信息")
 | 
			
		||||
    @DeleteMapping("batchRemove")
 | 
			
		||||
    //TODO 删除es
 | 
			
		||||
    public Result batchRemove(@RequestBody List<Long> idList) {
 | 
			
		||||
        try {
 | 
			
		||||
            skuInfoService.removeByIds(idList);
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
 | 
			
		||||
 * @since 2023-09-15
 | 
			
		||||
 */
 | 
			
		||||
public interface SkuInfoService extends IService<SkuInfo> {
 | 
			
		||||
 | 
			
		||||
    IPage<SkuInfo> selectPage(Page<SkuInfo> pageParam, SkuInfoQueryVo skuInfoQueryVo);
 | 
			
		||||
 | 
			
		||||
    void saveSkuInfo(SkuInfoVo skuInfoVo);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,8 @@ import com.atguigu.ssyx.model.product.SkuAttrValue;
 | 
			
		||||
import com.atguigu.ssyx.model.product.SkuImage;
 | 
			
		||||
import com.atguigu.ssyx.model.product.SkuInfo;
 | 
			
		||||
import com.atguigu.ssyx.model.product.SkuPoster;
 | 
			
		||||
import com.atguigu.ssyx.mq.constant.MqConst;
 | 
			
		||||
import com.atguigu.ssyx.mq.service.RabbitService;
 | 
			
		||||
import com.atguigu.ssyx.product.mapper.SkuInfoMapper;
 | 
			
		||||
import com.atguigu.ssyx.product.service.SkuAttrValueService;
 | 
			
		||||
import com.atguigu.ssyx.product.service.SkuImageService;
 | 
			
		||||
@@ -41,6 +43,8 @@ public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoMapper, SkuInfo> impl
 | 
			
		||||
    private SkuImageService skuImagesService;
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private SkuAttrValueService skuAttrValueService;
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private RabbitService rabbitService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取sku分页列表
 | 
			
		||||
@@ -205,12 +209,16 @@ public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoMapper, SkuInfo> impl
 | 
			
		||||
            SkuInfo skuInfo = baseMapper.selectById(skuId);
 | 
			
		||||
            skuInfo.setPublishStatus(status);
 | 
			
		||||
            baseMapper.updateById(skuInfo);
 | 
			
		||||
            //TODO 商品上架 后续会完善:发送mq消息更新es数据
 | 
			
		||||
 | 
			
		||||
            //商品上架:发送mq消息同步es
 | 
			
		||||
            rabbitService.sendMessage(MqConst.EXCHANGE_GOODS_DIRECT, MqConst.ROUTING_GOODS_UPPER, skuId);
 | 
			
		||||
        } else {
 | 
			
		||||
            SkuInfo skuInfo = baseMapper.selectById(skuId);
 | 
			
		||||
            skuInfo.setPublishStatus(status);
 | 
			
		||||
            baseMapper.updateById(skuInfo);
 | 
			
		||||
            //TODO 商品下架 后续会完善:发送mq消息更新es数据
 | 
			
		||||
 | 
			
		||||
            //商品下架:发送mq消息同步es
 | 
			
		||||
            rabbitService.sendMessage(MqConst.EXCHANGE_GOODS_DIRECT, MqConst.ROUTING_GOODS_LOWER, skuId);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,18 @@ spring:
 | 
			
		||||
    url: jdbc:mysql://82.157.68.223:3306/shequ-product?characterEncoding=utf-8&useSSL=false
 | 
			
		||||
    username: shequ-product
 | 
			
		||||
    password: shequ-product
 | 
			
		||||
  rabbitmq:
 | 
			
		||||
    host: 43.143.164.194
 | 
			
		||||
    port: 5672
 | 
			
		||||
    username: guest
 | 
			
		||||
    password: guest
 | 
			
		||||
    publisher-confirm-type: CORRELATED  #发布确认模式,消息是否被成功发送到交换机
 | 
			
		||||
    publisher-returns: true
 | 
			
		||||
    listener:
 | 
			
		||||
      simple:
 | 
			
		||||
        prefetch: 1
 | 
			
		||||
        concurrency: 3
 | 
			
		||||
        acknowledge-mode: manual   #消费端手动确认
 | 
			
		||||
 | 
			
		||||
  jackson:
 | 
			
		||||
    date-format: yyyy-MM-dd HH:mm:ss
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										43
									
								
								guigu-ssyx-parent/service/service-search/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								guigu-ssyx-parent/service/service-search/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
         xmlns="http://maven.apache.org/POM/4.0.0"
 | 
			
		||||
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 | 
			
		||||
    <modelVersion>4.0.0</modelVersion>
 | 
			
		||||
    <parent>
 | 
			
		||||
        <groupId>com.atguigu</groupId>
 | 
			
		||||
        <artifactId>service</artifactId>
 | 
			
		||||
        <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </parent>
 | 
			
		||||
 | 
			
		||||
    <artifactId>service-search</artifactId>
 | 
			
		||||
    <dependencies>
 | 
			
		||||
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.boot</groupId>
 | 
			
		||||
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.atguigu</groupId>
 | 
			
		||||
            <artifactId>service-product-client</artifactId>
 | 
			
		||||
            <version>1.0-SNAPSHOT</version>
 | 
			
		||||
            <scope>compile</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.atguigu</groupId>
 | 
			
		||||
            <artifactId>rabbit_util</artifactId>
 | 
			
		||||
            <version>1.0-SNAPSHOT</version>
 | 
			
		||||
            <scope>compile</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <!--        <dependency>-->
 | 
			
		||||
        <!--            <groupId>com.atguigu</groupId>-->
 | 
			
		||||
        <!--            <artifactId>service-product-api</artifactId>-->
 | 
			
		||||
        <!--            <version>1.0-SNAPSHOT</version>-->
 | 
			
		||||
        <!--        </dependency>-->
 | 
			
		||||
    </dependencies>
 | 
			
		||||
    <properties>
 | 
			
		||||
        <maven.compiler.source>8</maven.compiler.source>
 | 
			
		||||
        <maven.compiler.target>8</maven.compiler.target>
 | 
			
		||||
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
			
		||||
    </properties>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
package com.atguigu.ssyx;
 | 
			
		||||
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 | 
			
		||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 | 
			
		||||
import org.springframework.cloud.openfeign.EnableFeignClients;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: ServiceSearchApplication
 | 
			
		||||
 * Package: com.atguigu.ssyx
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/16 17:20
 | 
			
		||||
 */
 | 
			
		||||
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)//取消数据源自动配置
 | 
			
		||||
@EnableDiscoveryClient
 | 
			
		||||
@EnableFeignClients
 | 
			
		||||
public class ServiceSearchApplication {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        SpringApplication.run(ServiceSearchApplication.class, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,39 @@
 | 
			
		||||
package com.atguigu.ssyx.search.controller;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.common.result.Result;
 | 
			
		||||
import com.atguigu.ssyx.search.service.SkuService;
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: SkuApiController
 | 
			
		||||
 * Package: com.atguigu.ssyx.search.controller
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/16 17:22
 | 
			
		||||
 */
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("api/search/sku")
 | 
			
		||||
public class SkuApiController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private SkuService skuService;
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "上架商品")
 | 
			
		||||
    @GetMapping("inner/upperSku/{skuId}")
 | 
			
		||||
    public Result upperGoods(@PathVariable("skuId") Long skuId) {
 | 
			
		||||
        skuService.upperSku(skuId);
 | 
			
		||||
        return Result.ok(null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiOperation(value = "下架商品")
 | 
			
		||||
    @GetMapping("inner/lowerSku/{skuId}")
 | 
			
		||||
    public Result lowerGoods(@PathVariable("skuId") Long skuId) {
 | 
			
		||||
        skuService.lowerSku(skuId);
 | 
			
		||||
        return Result.ok(null);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,73 @@
 | 
			
		||||
package com.atguigu.ssyx.search.receiver;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.mq.constant.MqConst;
 | 
			
		||||
import com.atguigu.ssyx.search.service.SkuService;
 | 
			
		||||
import com.rabbitmq.client.Channel;
 | 
			
		||||
import org.springframework.amqp.core.Message;
 | 
			
		||||
import org.springframework.amqp.rabbit.annotation.Exchange;
 | 
			
		||||
import org.springframework.amqp.rabbit.annotation.Queue;
 | 
			
		||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
 | 
			
		||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Component;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: SkuReceiver
 | 
			
		||||
 * Package: com.atguigu.ssyx.search.receiver
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/16 23:57
 | 
			
		||||
 */
 | 
			
		||||
@Component
 | 
			
		||||
public class SkuReceiver {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private SkuService skuService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 商品上架
 | 
			
		||||
     *
 | 
			
		||||
     * @param skuId
 | 
			
		||||
     * @param message
 | 
			
		||||
     * @param channel
 | 
			
		||||
     * @throws IOException
 | 
			
		||||
     */
 | 
			
		||||
    @RabbitListener(bindings = @QueueBinding(
 | 
			
		||||
            value = @Queue(value = MqConst.QUEUE_GOODS_UPPER, durable = "true"),
 | 
			
		||||
            exchange = @Exchange(value = MqConst.EXCHANGE_GOODS_DIRECT),
 | 
			
		||||
            key = {MqConst.ROUTING_GOODS_UPPER}
 | 
			
		||||
    ))
 | 
			
		||||
    public void upperSku(Long skuId, Message message, Channel channel) throws IOException {
 | 
			
		||||
        if (null != skuId) {
 | 
			
		||||
            skuService.upperSku(skuId);
 | 
			
		||||
        }
 | 
			
		||||
        //第一个参数:表示收到的消息的标号
 | 
			
		||||
        //第二个参数:如果为true表示可以签收多个消息
 | 
			
		||||
        channel.basicAck(message
 | 
			
		||||
                .getMessageProperties()
 | 
			
		||||
                .getDeliveryTag(), false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 商品下架
 | 
			
		||||
     *
 | 
			
		||||
     * @param skuId
 | 
			
		||||
     */
 | 
			
		||||
    @RabbitListener(bindings = @QueueBinding(
 | 
			
		||||
            value = @Queue(value = MqConst.QUEUE_GOODS_LOWER, durable = "true"),
 | 
			
		||||
            exchange = @Exchange(value = MqConst.EXCHANGE_GOODS_DIRECT),
 | 
			
		||||
            key = {MqConst.ROUTING_GOODS_LOWER}
 | 
			
		||||
    ))
 | 
			
		||||
    public void lowerSku(Long skuId, Message message, Channel channel) throws IOException {
 | 
			
		||||
        if (null != skuId) {
 | 
			
		||||
            skuService.lowerSku(skuId);
 | 
			
		||||
        }
 | 
			
		||||
        //第一个参数:表示收到的消息的标号
 | 
			
		||||
        //第二个参数:如果为true表示可以签收多个消息
 | 
			
		||||
        channel.basicAck(message
 | 
			
		||||
                .getMessageProperties()
 | 
			
		||||
                .getDeliveryTag(), false);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,14 @@
 | 
			
		||||
package com.atguigu.ssyx.search.repository;
 | 
			
		||||
 | 
			
		||||
import com.atguigu.ssyx.model.search.SkuEs;
 | 
			
		||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: SkuRepository
 | 
			
		||||
 * Package: com.atguigu.ssyx.search.repository
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/16 17:24
 | 
			
		||||
 */
 | 
			
		||||
public interface SkuRepository extends ElasticsearchRepository<SkuEs, Long> {
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,29 @@
 | 
			
		||||
package com.atguigu.ssyx.search.service;
 | 
			
		||||
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: SkuService
 | 
			
		||||
 * Package: com.atguigu.ssyx.search.service
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/16 17:23
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public interface SkuService {
 | 
			
		||||
    /**
 | 
			
		||||
     * 上架商品列表
 | 
			
		||||
     *
 | 
			
		||||
     * @param skuId
 | 
			
		||||
     */
 | 
			
		||||
    void upperSku(Long skuId);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 下架商品列表
 | 
			
		||||
     *
 | 
			
		||||
     * @param skuId
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    void lowerSku(Long skuId);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,87 @@
 | 
			
		||||
package com.atguigu.ssyx.search.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.alibaba.fastjson.JSON;
 | 
			
		||||
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 lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ClassName: SkuServiceImpl
 | 
			
		||||
 * Package: com.atguigu.ssyx.search.service.impl
 | 
			
		||||
 *
 | 
			
		||||
 * @author yovinchen
 | 
			
		||||
 * @Create 2023/9/16 17:23
 | 
			
		||||
 */
 | 
			
		||||
@Slf4j
 | 
			
		||||
@Service
 | 
			
		||||
public class SkuServiceImpl implements SkuService {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private ProductFeignClient productFeignClient;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private SkuRepository skuEsRepository;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 上架商品列表
 | 
			
		||||
     *
 | 
			
		||||
     * @param skuId
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void upperSku(Long skuId) {
 | 
			
		||||
        log.info("upperSku:" + skuId);
 | 
			
		||||
        //查询sku信息
 | 
			
		||||
        SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
 | 
			
		||||
        if (null == skuInfo) return;
 | 
			
		||||
 | 
			
		||||
        // 查询分类
 | 
			
		||||
        SkuEs skuEs = new SkuEs();
 | 
			
		||||
        Category category = productFeignClient.getCategory(skuInfo.getCategoryId());
 | 
			
		||||
        if (category != null) {
 | 
			
		||||
            skuEs.setCategoryId(category.getId());
 | 
			
		||||
            skuEs.setCategoryName(category.getName());
 | 
			
		||||
        }
 | 
			
		||||
        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());
 | 
			
		||||
        } else {
 | 
			
		||||
            //TODO 待完善-秒杀商品
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        SkuEs save = skuEsRepository.save(skuEs);
 | 
			
		||||
        log.info("upperSku:" + JSON.toJSONString(save));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * a下架商品列表
 | 
			
		||||
     *
 | 
			
		||||
     * @param skuId
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void lowerSku(Long skuId) {
 | 
			
		||||
        skuEsRepository.deleteById(skuId);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,41 @@
 | 
			
		||||
server:
 | 
			
		||||
  port: 8204
 | 
			
		||||
feign:
 | 
			
		||||
  sentinel:
 | 
			
		||||
    enabled: true
 | 
			
		||||
  client:
 | 
			
		||||
    config:
 | 
			
		||||
      default: #配置全局的feign的调用超时时间  如果 有指定的服务配置 默认的配置不会生效
 | 
			
		||||
        connectTimeout: 30000 # 指定的是 消费者 连接服务提供者的连接超时时间 是否能连接  单位是毫秒
 | 
			
		||||
        readTimeout: 50000  # 指定的是调用服务提供者的 服务 的超时时间()  单位是毫秒
 | 
			
		||||
spring:
 | 
			
		||||
  main:
 | 
			
		||||
    allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册
 | 
			
		||||
  elasticsearch:
 | 
			
		||||
    rest:
 | 
			
		||||
      uris: http://43.143.164.194:9200
 | 
			
		||||
  rabbitmq:
 | 
			
		||||
    host: 43.143.164.194
 | 
			
		||||
    port: 5672
 | 
			
		||||
    username: guest
 | 
			
		||||
    password: guest
 | 
			
		||||
    publisher-confirm-type: CORRELATED  #发布确认模式,消息是否被成功发送到交换机
 | 
			
		||||
    publisher-returns: true
 | 
			
		||||
    listener:
 | 
			
		||||
      simple:
 | 
			
		||||
        prefetch: 1
 | 
			
		||||
        concurrency: 3
 | 
			
		||||
        acknowledge-mode: manual   #消费端手动确认
 | 
			
		||||
 | 
			
		||||
  redis:
 | 
			
		||||
    host: localhost
 | 
			
		||||
    port: 6379
 | 
			
		||||
    database: 0
 | 
			
		||||
    timeout: 1800000
 | 
			
		||||
    password:
 | 
			
		||||
    lettuce:
 | 
			
		||||
      pool:
 | 
			
		||||
        max-active: 20 #最大连接数
 | 
			
		||||
        max-wait: -1    #最大阻塞等待时间(负数表示没限制)
 | 
			
		||||
        max-idle: 5    #最大空闲
 | 
			
		||||
        min-idle: 0     #最小空闲
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
spring:
 | 
			
		||||
  application:
 | 
			
		||||
    name: service-search
 | 
			
		||||
  profiles:
 | 
			
		||||
    active: dev
 | 
			
		||||
  cloud:
 | 
			
		||||
    nacos:
 | 
			
		||||
      discovery:
 | 
			
		||||
        server-addr: localhost:8848
 | 
			
		||||
      username: nacos
 | 
			
		||||
      password: nacos
 | 
			
		||||
		Reference in New Issue
	
	Block a user