整合es、rabbitmq、redis完成上下架修改es
This commit is contained in:
parent
ca82fbe892
commit
3019bc5737
@ -14,6 +14,7 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>common-util</module>
|
<module>common-util</module>
|
||||||
<module>service-util</module>
|
<module>service-util</module>
|
||||||
|
<module>rabbit_util</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
26
guigu-ssyx-parent/common/rabbit_util/pom.xml
Normal file
26
guigu-ssyx-parent/common/rabbit_util/pom.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?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>common</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>rabbit_util</artifactId>
|
||||||
|
<dependencies>
|
||||||
|
<!--rabbitmq消息队列-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
|
||||||
|
</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,22 @@
|
|||||||
|
package com.atguigu.ssyx.mq.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||||
|
import org.springframework.amqp.support.converter.MessageConverter;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClassName: MQConfig
|
||||||
|
* Package: com.atguigu.ssyx.mq.config
|
||||||
|
*
|
||||||
|
* @author yovinchen
|
||||||
|
* @Create 2023/9/16 23:32
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class MQConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MessageConverter messageConverter() {
|
||||||
|
return new Jackson2JsonMessageConverter();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package com.atguigu.ssyx.mq.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.Message;
|
||||||
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClassName: MQProducerAckConfig
|
||||||
|
* Package: com.atguigu.ssyx.mq.config
|
||||||
|
*
|
||||||
|
* @author yovinchen
|
||||||
|
* @Create 2023/9/16 23:33
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class MQProducerAckConfig implements RabbitTemplate.ReturnCallback, RabbitTemplate.ConfirmCallback {
|
||||||
|
|
||||||
|
// 我们发送消息使用的是 private RabbitTemplate rabbitTemplate; 对象
|
||||||
|
// 如果不做设置的话 当前的rabbitTemplate 与当前的配置类没有任何关系!
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
// 设置 表示修饰一个非静态的void方法,在服务器加载Servlet的时候运行。并且只执行一次!
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
rabbitTemplate.setReturnCallback(this);
|
||||||
|
rabbitTemplate.setConfirmCallback(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表示消息是否正确发送到了交换机上
|
||||||
|
*
|
||||||
|
* @param correlationData 消息的载体
|
||||||
|
* @param ack 判断是否发送到交换机上
|
||||||
|
* @param cause 原因
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||||
|
if (ack) {
|
||||||
|
System.out.println("消息发送成功!");
|
||||||
|
} else {
|
||||||
|
System.out.println("消息发送失败!" + cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息如果没有正确发送到队列中,则会走这个方法!如果消息被正常处理,则这个方法不会走!
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
* @param replyCode
|
||||||
|
* @param replyText
|
||||||
|
* @param exchange
|
||||||
|
* @param routingKey
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
|
||||||
|
System.out.println("消息主体: " + new String(message.getBody()));
|
||||||
|
System.out.println("应答码: " + replyCode);
|
||||||
|
System.out.println("描述:" + replyText);
|
||||||
|
System.out.println("消息使用的交换器 exchange : " + exchange);
|
||||||
|
System.out.println("消息使用的路由键 routing : " + routingKey);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
package com.atguigu.ssyx.mq.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClassName: MqConst
|
||||||
|
* Package: com.atguigu.ssyx.mq.constant
|
||||||
|
*
|
||||||
|
* @author yovinchen
|
||||||
|
* @Create 2023/9/16 23:34
|
||||||
|
*/
|
||||||
|
public class MqConst {
|
||||||
|
/**
|
||||||
|
* 消息补偿
|
||||||
|
*/
|
||||||
|
public static final String MQ_KEY_PREFIX = "ssyx.mq:list";
|
||||||
|
public static final int RETRY_COUNT = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品上下架
|
||||||
|
*/
|
||||||
|
public static final String EXCHANGE_GOODS_DIRECT = "ssyx.goods.direct";
|
||||||
|
public static final String ROUTING_GOODS_UPPER = "ssyx.goods.upper";
|
||||||
|
public static final String ROUTING_GOODS_LOWER = "ssyx.goods.lower";
|
||||||
|
//队列
|
||||||
|
public static final String QUEUE_GOODS_UPPER = "ssyx.goods.upper";
|
||||||
|
public static final String QUEUE_GOODS_LOWER = "ssyx.goods.lower";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 团长上下线
|
||||||
|
*/
|
||||||
|
public static final String EXCHANGE_LEADER_DIRECT = "ssyx.leader.direct";
|
||||||
|
public static final String ROUTING_LEADER_UPPER = "ssyx.leader.upper";
|
||||||
|
public static final String ROUTING_LEADER_LOWER = "ssyx.leader.lower";
|
||||||
|
//队列
|
||||||
|
public static final String QUEUE_LEADER_UPPER = "ssyx.leader.upper";
|
||||||
|
public static final String QUEUE_LEADER_LOWER = "ssyx.leader.lower";
|
||||||
|
|
||||||
|
//订单
|
||||||
|
public static final String EXCHANGE_ORDER_DIRECT = "ssyx.order.direct";
|
||||||
|
public static final String ROUTING_ROLLBACK_STOCK = "ssyx.rollback.stock";
|
||||||
|
public static final String ROUTING_MINUS_STOCK = "ssyx.minus.stock";
|
||||||
|
|
||||||
|
public static final String ROUTING_DELETE_CART = "ssyx.delete.cart";
|
||||||
|
//解锁普通商品库存
|
||||||
|
public static final String QUEUE_ROLLBACK_STOCK = "ssyx.rollback.stock";
|
||||||
|
public static final String QUEUE_SECKILL_ROLLBACK_STOCK = "ssyx.seckill.rollback.stock";
|
||||||
|
public static final String QUEUE_MINUS_STOCK = "ssyx.minus.stock";
|
||||||
|
public static final String QUEUE_DELETE_CART = "ssyx.delete.cart";
|
||||||
|
|
||||||
|
//支付
|
||||||
|
public static final String EXCHANGE_PAY_DIRECT = "ssyx.pay.direct";
|
||||||
|
public static final String ROUTING_PAY_SUCCESS = "ssyx.pay.success";
|
||||||
|
public static final String QUEUE_ORDER_PAY = "ssyx.order.pay";
|
||||||
|
public static final String QUEUE_LEADER_BILL = "ssyx.leader.bill";
|
||||||
|
|
||||||
|
//取消订单
|
||||||
|
public static final String EXCHANGE_CANCEL_ORDER_DIRECT = "ssyx.cancel.order.direct";
|
||||||
|
public static final String ROUTING_CANCEL_ORDER = "ssyx.cancel.order";
|
||||||
|
//延迟取消订单队列
|
||||||
|
public static final String QUEUE_CANCEL_ORDER = "ssyx.cancel.order";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务
|
||||||
|
*/
|
||||||
|
public static final String EXCHANGE_DIRECT_TASK = "ssyx.exchange.direct.task";
|
||||||
|
public static final String ROUTING_TASK_23 = "ssyx.task.23";
|
||||||
|
//队列
|
||||||
|
public static final String QUEUE_TASK_23 = "ssyx.queue.task.23";
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
package com.atguigu.ssyx.mq.service;
|
||||||
|
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClassName: RabbitService
|
||||||
|
* Package: com.atguigu.ssyx.common.service
|
||||||
|
*
|
||||||
|
* @author yovinchen
|
||||||
|
* @Create 2023/9/16 18:12
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class RabbitService {
|
||||||
|
|
||||||
|
// 引入操作rabbitmq 的模板
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送消息
|
||||||
|
*
|
||||||
|
* @param exchange 交换机
|
||||||
|
* @param routingKey 路由键
|
||||||
|
* @param message 消息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean sendMessage(String exchange, String routingKey, Object message) {
|
||||||
|
// 调用发送数据的方法
|
||||||
|
rabbitTemplate.convertAndSend(exchange, routingKey, message);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送延迟消息的方法
|
||||||
|
*
|
||||||
|
* @param exchange 交换机
|
||||||
|
* @param routingKey 路由键
|
||||||
|
* @param message 消息内容
|
||||||
|
* @param delayTime 延迟时间
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean sendDelayMessage(String exchange, String routingKey, Object message, int delayTime) {
|
||||||
|
|
||||||
|
// 在发送消息的时候设置延迟时间
|
||||||
|
rabbitTemplate.convertAndSend(exchange, routingKey, message, message1 -> {
|
||||||
|
// 设置一个延迟时间
|
||||||
|
message1
|
||||||
|
.getMessageProperties()
|
||||||
|
.setDelay(delayTime * 1000);
|
||||||
|
return message1;
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@
|
|||||||
<module>common</module>
|
<module>common</module>
|
||||||
<module>model</module>
|
<module>model</module>
|
||||||
<module>service</module>
|
<module>service</module>
|
||||||
|
<module>service-client</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
51
guigu-ssyx-parent/service-client/pom.xml
Normal file
51
guigu-ssyx-parent/service-client/pom.xml
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?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>guigu-ssyx-parent</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>service-client</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>service-product-client</module>
|
||||||
|
</modules>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atguigu</groupId>
|
||||||
|
<artifactId>common-util</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atguigu</groupId>
|
||||||
|
<artifactId>model</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 服务调用feign -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</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,20 @@
|
|||||||
|
<?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-client</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>service-product-client</artifactId>
|
||||||
|
|
||||||
|
<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.client.product;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClassName: ProductFeignClient
|
||||||
|
* Package: com.atguigu.ssyx.client.product
|
||||||
|
*
|
||||||
|
* @author yovinchen
|
||||||
|
* @Create 2023/9/16 17:45
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "service-product")
|
||||||
|
public interface ProductFeignClient {
|
||||||
|
|
||||||
|
@GetMapping("/api/product/inner/getCategory/{categoryId}")
|
||||||
|
Category getCategory(@PathVariable("categoryId") Long categoryId);
|
||||||
|
|
||||||
|
@GetMapping("/api/product/inner/getSkuInfo/{skuId}")
|
||||||
|
SkuInfo getSkuInfo(@PathVariable("skuId") Long skuId);
|
||||||
|
}
|
@ -15,6 +15,7 @@
|
|||||||
<module>service-acl</module>
|
<module>service-acl</module>
|
||||||
<module>service-sys</module>
|
<module>service-sys</module>
|
||||||
<module>service-product</module>
|
<module>service-product</module>
|
||||||
|
<module>service-search</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -23,6 +23,12 @@
|
|||||||
<artifactId>joda-time</artifactId>
|
<artifactId>joda-time</artifactId>
|
||||||
<version>2.10.1</version>
|
<version>2.10.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atguigu</groupId>
|
||||||
|
<artifactId>rabbit_util</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<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信息")
|
@ApiOperation(value = "删除商品sku信息")
|
||||||
@DeleteMapping("remove/{id}")
|
@DeleteMapping("remove/{id}")
|
||||||
|
//TODO 删除es
|
||||||
public Result remove(@PathVariable Long id) {
|
public Result remove(@PathVariable Long id) {
|
||||||
try {
|
try {
|
||||||
skuInfoService.removeById(id);
|
skuInfoService.removeById(id);
|
||||||
@ -94,6 +95,7 @@ public class SkuInfoController {
|
|||||||
|
|
||||||
@ApiOperation(value = "根据id列表删除商品sku信息")
|
@ApiOperation(value = "根据id列表删除商品sku信息")
|
||||||
@DeleteMapping("batchRemove")
|
@DeleteMapping("batchRemove")
|
||||||
|
//TODO 删除es
|
||||||
public Result batchRemove(@RequestBody List<Long> idList) {
|
public Result batchRemove(@RequestBody List<Long> idList) {
|
||||||
try {
|
try {
|
||||||
skuInfoService.removeByIds(idList);
|
skuInfoService.removeByIds(idList);
|
||||||
|
@ -16,7 +16,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
* @since 2023-09-15
|
* @since 2023-09-15
|
||||||
*/
|
*/
|
||||||
public interface SkuInfoService extends IService<SkuInfo> {
|
public interface SkuInfoService extends IService<SkuInfo> {
|
||||||
|
|
||||||
IPage<SkuInfo> selectPage(Page<SkuInfo> pageParam, SkuInfoQueryVo skuInfoQueryVo);
|
IPage<SkuInfo> selectPage(Page<SkuInfo> pageParam, SkuInfoQueryVo skuInfoQueryVo);
|
||||||
|
|
||||||
void saveSkuInfo(SkuInfoVo skuInfoVo);
|
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.SkuImage;
|
||||||
import com.atguigu.ssyx.model.product.SkuInfo;
|
import com.atguigu.ssyx.model.product.SkuInfo;
|
||||||
import com.atguigu.ssyx.model.product.SkuPoster;
|
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.mapper.SkuInfoMapper;
|
||||||
import com.atguigu.ssyx.product.service.SkuAttrValueService;
|
import com.atguigu.ssyx.product.service.SkuAttrValueService;
|
||||||
import com.atguigu.ssyx.product.service.SkuImageService;
|
import com.atguigu.ssyx.product.service.SkuImageService;
|
||||||
@ -41,6 +43,8 @@ public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoMapper, SkuInfo> impl
|
|||||||
private SkuImageService skuImagesService;
|
private SkuImageService skuImagesService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SkuAttrValueService skuAttrValueService;
|
private SkuAttrValueService skuAttrValueService;
|
||||||
|
@Autowired
|
||||||
|
private RabbitService rabbitService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取sku分页列表
|
* 获取sku分页列表
|
||||||
@ -205,12 +209,16 @@ public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoMapper, SkuInfo> impl
|
|||||||
SkuInfo skuInfo = baseMapper.selectById(skuId);
|
SkuInfo skuInfo = baseMapper.selectById(skuId);
|
||||||
skuInfo.setPublishStatus(status);
|
skuInfo.setPublishStatus(status);
|
||||||
baseMapper.updateById(skuInfo);
|
baseMapper.updateById(skuInfo);
|
||||||
//TODO 商品上架 后续会完善:发送mq消息更新es数据
|
|
||||||
|
//商品上架:发送mq消息同步es
|
||||||
|
rabbitService.sendMessage(MqConst.EXCHANGE_GOODS_DIRECT, MqConst.ROUTING_GOODS_UPPER, skuId);
|
||||||
} else {
|
} else {
|
||||||
SkuInfo skuInfo = baseMapper.selectById(skuId);
|
SkuInfo skuInfo = baseMapper.selectById(skuId);
|
||||||
skuInfo.setPublishStatus(status);
|
skuInfo.setPublishStatus(status);
|
||||||
baseMapper.updateById(skuInfo);
|
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
|
url: jdbc:mysql://82.157.68.223:3306/shequ-product?characterEncoding=utf-8&useSSL=false
|
||||||
username: shequ-product
|
username: shequ-product
|
||||||
password: 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:
|
jackson:
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
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
|
Loading…
Reference in New Issue
Block a user