整合es、rabbitmq、redis完成上下架修改es
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user