diff --git a/cash-api/product-server/src/main/java/com/czg/controller/admin/ProductController.java b/cash-api/product-server/src/main/java/com/czg/controller/admin/ProductController.java index ecfe1aca..2182e135 100644 --- a/cash-api/product-server/src/main/java/com/czg/controller/admin/ProductController.java +++ b/cash-api/product-server/src/main/java/com/czg/controller/admin/ProductController.java @@ -1,5 +1,7 @@ package com.czg.controller.admin; +import cn.hutool.core.convert.Convert; +import com.czg.config.RabbitPublisher; import com.czg.exception.CzgException; import com.czg.log.annotation.OperationLog; import com.czg.product.dto.ProdConsBindDTO; @@ -37,6 +39,7 @@ import java.util.List; public class ProductController { private final ProductService productService; private final ProdConsRelationService prodConsRelationService; + private final RabbitPublisher rabbitPublisher; @GetMapping("page") @OperationLog("商品-分页") @@ -74,6 +77,7 @@ public class ProductController { Long shopId = StpKit.USER.getShopId(0L); dto.setShopId(shopId); productService.addProduct(dto); + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); return CzgResult.success(); } @@ -84,6 +88,7 @@ public class ProductController { Long shopId = StpKit.USER.getShopId(0L); dto.setShopId(shopId); productService.updateProduct(dto); + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); return CzgResult.success(); } @@ -95,6 +100,7 @@ public class ProductController { AssertUtil.isNull(id, "{}不能为空", "id"); Long shopId = StpKit.USER.getShopId(0L); productService.deleteProduct(shopId, id); + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); return CzgResult.success(); } @@ -108,6 +114,7 @@ public class ProductController { Long shopId = StpKit.USER.getShopId(0L); param.setShopId(shopId); productService.onOffProduct(param); + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); return CzgResult.success(); } @@ -121,6 +128,7 @@ public class ProductController { Long shopId = StpKit.USER.getShopId(0L); param.setShopId(shopId); productService.markProductIsSoldOut(param); + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); return CzgResult.success(); } diff --git a/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConfig.java b/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConfig.java index 07a8421b..102dd235 100644 --- a/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConfig.java +++ b/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConfig.java @@ -1,6 +1,9 @@ package com.czg.config; -import org.springframework.amqp.core.*; +import org.springframework.amqp.core.Binding; +import org.springframework.amqp.core.BindingBuilder; +import org.springframework.amqp.core.DirectExchange; +import org.springframework.amqp.core.Queue; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -48,6 +51,11 @@ public class RabbitConfig { return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_STOCK_QUEUE, true); } + @Bean + public Queue productInfoChangeQueue() { + return new Queue(activeProfile + "-" + RabbitConstants.Queue.PRODUCT_INFO_CHANGE_QUEUE, true); + } + @Bean @Primary public DirectExchange directExchange() { @@ -69,4 +77,9 @@ public class RabbitConfig { public Binding bindingOrderStockExchange(Queue orderStockQueue, DirectExchange exchange) { return BindingBuilder.bind(orderStockQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.ORDER_STOCK_QUEUE); } + + @Bean + public Binding bindingProductInfoChange(Queue productInfoChangeQueue, DirectExchange exchange) { + return BindingBuilder.bind(productInfoChangeQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.PRODUCT_INFO_CHANGE_QUEUE); + } } diff --git a/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConstants.java b/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConstants.java index 80ab4167..480d384d 100644 --- a/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConstants.java +++ b/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConstants.java @@ -15,5 +15,6 @@ public interface RabbitConstants { public static final String ORDER_PRINT_QUEUE = "order.print.queue"; public static final String ORDER_MACHINE_PRINT_QUEUE = "order.machine.print.queue"; public static final String ORDER_HANDOVER_PRINT_QUEUE = "order.handover.print.queue"; + public static final String PRODUCT_INFO_CHANGE_QUEUE = "product.info.change.queue"; } } diff --git a/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitPublisher.java b/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitPublisher.java index ea4efa0e..32bb2644 100644 --- a/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitPublisher.java +++ b/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitPublisher.java @@ -23,7 +23,7 @@ public class RabbitPublisher { * @param orderId 订单id */ public void sendOrderCancelMsg(String orderId) { - sendMsg(RabbitConstants.Queue.ORDER_STOCK_QUEUE, orderId); + sendMsg(RabbitConstants.Queue.ORDER_CANCEL_QUEUE, orderId); } /** @@ -54,6 +54,15 @@ public class RabbitPublisher { sendMsg(RabbitConstants.Queue.ORDER_HANDOVER_PRINT_QUEUE, handoverRecordId); } + /** + * 商品信息变动消息 + * + * @param shopId 店铺id + */ + public void sendProductInfoChangeMsg(String shopId) { + sendMsg(RabbitConstants.Queue.PRODUCT_INFO_CHANGE_QUEUE, shopId); + } + private void sendMsg(String queue, String msg) { diff --git a/cash-common/cash-common-service/src/main/java/com/czg/product/dto/ProdConsRelationDTO.java b/cash-common/cash-common-service/src/main/java/com/czg/product/dto/ProdConsRelationDTO.java index 6c48e21f..e0aaa16e 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/product/dto/ProdConsRelationDTO.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/product/dto/ProdConsRelationDTO.java @@ -50,5 +50,9 @@ public class ProdConsRelationDTO implements Serializable { */ @JSONField(format = "yyyy-MM-dd HH:mm:ss") private LocalDateTime createTime; + /** + * 耗材单位 + */ + private String conUnit; } \ No newline at end of file diff --git a/cash-service/product-service/pom.xml b/cash-service/product-service/pom.xml index 1e11dfb6..758998b8 100644 --- a/cash-service/product-service/pom.xml +++ b/cash-service/product-service/pom.xml @@ -17,4 +17,11 @@ UTF-8 + + + com.czg + cash-common-mq + ${project.version} + + \ No newline at end of file diff --git a/cash-service/product-service/src/main/java/com/czg/service/product/mapper/ProdConsRelationMapper.java b/cash-service/product-service/src/main/java/com/czg/service/product/mapper/ProdConsRelationMapper.java index 3a9bcb8b..347b6f52 100644 --- a/cash-service/product-service/src/main/java/com/czg/service/product/mapper/ProdConsRelationMapper.java +++ b/cash-service/product-service/src/main/java/com/czg/service/product/mapper/ProdConsRelationMapper.java @@ -1,5 +1,6 @@ package com.czg.service.product.mapper; +import com.czg.product.dto.ProdConsRelationDTO; import com.czg.product.dto.ProductBriefDTO; import com.czg.product.entity.ProdConsRelation; import com.mybatisflex.core.BaseMapper; @@ -19,4 +20,5 @@ public interface ProdConsRelationMapper extends BaseMapper { List getProductListByConId(@Param("conId") Long conId); + List selectListByProdId(@Param("prodId") Long prodId); } \ No newline at end of file diff --git a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductRpcServiceImpl.java b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductRpcServiceImpl.java index 324e8f8a..2a4e4396 100644 --- a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductRpcServiceImpl.java +++ b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductRpcServiceImpl.java @@ -2,7 +2,9 @@ package com.czg.service.product.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; import cn.hutool.core.util.NumberUtil; +import com.czg.config.RabbitPublisher; import com.czg.constant.CacheConstant; import com.czg.product.dto.ProductStockSubtractDTO; import com.czg.product.entity.ConsInfo; @@ -49,6 +51,8 @@ public class ProductRpcServiceImpl implements ProductRpcService { @Resource private ConsStockFlowMapper consStockFlowMapper; + @Resource + private RabbitPublisher rabbitPublisher; @Override @Transactional(rollbackFor = Exception.class) @@ -107,6 +111,7 @@ public class ProductRpcServiceImpl implements ProductRpcService { consStockFlowMapper.insert(consStockFlow); } } + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); } @Override @@ -165,5 +170,6 @@ public class ProductRpcServiceImpl implements ProductRpcService { consStockFlowMapper.insert(consStockFlow); } } + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); } } diff --git a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java index 71a06460..49c2f794 100644 --- a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java +++ b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java @@ -131,7 +131,7 @@ public class ProductServiceImpl extends ServiceImpl impl lowMemberPriceIsPresent.ifPresent(record::setLowMemberPrice); } record.setSkuList(skuList); - List consList = prodConsRelationMapper.selectListByQueryAs(query().eq(ProdConsRelation::getProductId, record.getId()), ProdConsRelationDTO.class); + List consList = prodConsRelationMapper.selectListByProdId(record.getId()); record.setConsList(consList); if (CollUtil.isNotEmpty(consList)) { List consIds = consList.stream().map(ProdConsRelationDTO::getConsInfoId).distinct().toList(); diff --git a/cash-service/product-service/src/main/resources/mapper/ProdConsRelationMapper.xml b/cash-service/product-service/src/main/resources/mapper/ProdConsRelationMapper.xml index 7ea43063..c1b7fe62 100644 --- a/cash-service/product-service/src/main/resources/mapper/ProdConsRelationMapper.xml +++ b/cash-service/product-service/src/main/resources/mapper/ProdConsRelationMapper.xml @@ -11,4 +11,11 @@ inner join tb_product t2 on t1.product_id = t2.id where t1.cons_info_id = #{conId} + \ No newline at end of file