From e6e5579c77978fb46d056b6a35dba2c21b51ab64 Mon Sep 17 00:00:00 2001 From: Tankaikai Date: Mon, 10 Mar 2025 10:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=BB=84=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=88=B7=E6=96=B0=E5=95=86=E5=93=81=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E7=BC=93=E5=AD=98=EF=BC=8C=E5=B9=B6=E5=8F=91=E9=80=81mq?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/ProdGroupController.java | 55 ++++++++++++++----- .../czg/product/service/ProdGroupService.java | 6 +- .../service/impl/ProdGroupServiceImpl.java | 16 ++++-- 3 files changed, 54 insertions(+), 23 deletions(-) diff --git a/cash-api/product-server/src/main/java/com/czg/controller/admin/ProdGroupController.java b/cash-api/product-server/src/main/java/com/czg/controller/admin/ProdGroupController.java index 79de3704..c98f7c32 100644 --- a/cash-api/product-server/src/main/java/com/czg/controller/admin/ProdGroupController.java +++ b/cash-api/product-server/src/main/java/com/czg/controller/admin/ProdGroupController.java @@ -1,9 +1,13 @@ package com.czg.controller.admin; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.thread.ThreadUtil; +import com.czg.config.RabbitPublisher; import com.czg.log.annotation.OperationLog; import com.czg.product.dto.ProdGroupDTO; import com.czg.product.service.ProdGroupService; import com.czg.resp.CzgResult; +import com.czg.sa.StpKit; import com.czg.utils.AssertUtil; import com.czg.validator.group.DefaultGroup; import com.czg.validator.group.InsertGroup; @@ -17,16 +21,17 @@ import java.util.List; /** -* 商品分组 -* -* @author Tankaikai tankaikai@aliyun.com -* @since 1.0 2025-02-17 -*/ + * 商品分组 + * + * @author Tankaikai tankaikai@aliyun.com + * @since 1.0 2025-02-17 + */ @AllArgsConstructor @RestController @RequestMapping("/admin/prod/group") public class ProdGroupController { private final ProdGroupService prodGroupService; + private final RabbitPublisher rabbitPublisher; /** * 分页 @@ -34,7 +39,7 @@ public class ProdGroupController { @GetMapping("page") @OperationLog("商品分组-分页") //@SaAdminCheckPermission("prodGroup:page") - public CzgResult> getProdGroupPage(ProdGroupDTO param){ + public CzgResult> getProdGroupPage(ProdGroupDTO param) { Page data = prodGroupService.getProdGroupPage(param); return CzgResult.success(data); } @@ -45,7 +50,7 @@ public class ProdGroupController { @GetMapping("list") @OperationLog("商品分组-列表") //@SaAdminCheckPermission("prodGroup:list") - public CzgResult> getProdGroupList(ProdGroupDTO param){ + public CzgResult> getProdGroupList(ProdGroupDTO param) { List data = prodGroupService.getProdGroupList(param); return CzgResult.success(data); } @@ -58,7 +63,7 @@ public class ProdGroupController { @GetMapping("{id}") @OperationLog("商品分组-详情") //@SaAdminCheckPermission("prodGroup:info") - public CzgResult getProdGroupById(@PathVariable("id") Long id){ + public CzgResult getProdGroupById(@PathVariable("id") Long id) { AssertUtil.isNull(id, "{}不能为空", "id"); ProdGroupDTO data = prodGroupService.getProdGroupById(id); return CzgResult.success(data); @@ -70,8 +75,13 @@ public class ProdGroupController { @PostMapping @OperationLog("商品分组-新增") //@SaAdminCheckPermission("prodGroup:add") - public CzgResult addProdGroup(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ProdGroupDTO dto){ + public CzgResult addProdGroup(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ProdGroupDTO dto) { + Long shopId = StpKit.USER.getShopId(0L); + dto.setShopId(shopId); prodGroupService.addProdGroup(dto); + ThreadUtil.execAsync(() -> { + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); + }); return CzgResult.success(); } @@ -81,8 +91,13 @@ public class ProdGroupController { @PutMapping @OperationLog("商品分组-修改") //@SaAdminCheckPermission("prodGroup:update") - public CzgResult updateProdGroup(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ProdGroupDTO dto){ + public CzgResult updateProdGroup(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ProdGroupDTO dto) { + Long shopId = StpKit.USER.getShopId(0L); + dto.setShopId(shopId); prodGroupService.updateProdGroup(dto); + ThreadUtil.execAsync(() -> { + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); + }); return CzgResult.success(); } @@ -92,10 +107,14 @@ public class ProdGroupController { @DeleteMapping("{id}") @OperationLog("商品分组-删除") //@SaAdminCheckPermission("prodGroup:delete") - public CzgResult deleteProdGroup(@PathVariable("id") Long id){ + public CzgResult deleteProdGroup(@PathVariable("id") Long id) { //效验数据 AssertUtil.isNull(id, "{}不能为空", "id"); - prodGroupService.deleteProdGroup(id); + Long shopId = StpKit.USER.getShopId(0L); + prodGroupService.deleteProdGroup(shopId, id); + ThreadUtil.execAsync(() -> { + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); + }); return CzgResult.success(); } @@ -108,7 +127,11 @@ public class ProdGroupController { public CzgResult disableProdGroup(@PathVariable("id") Long id) { //效验数据 AssertUtil.isNull(id, "{}不能为空", "id"); - prodGroupService.disableProdGroup(id); + Long shopId = StpKit.USER.getShopId(0L); + prodGroupService.disableProdGroup(shopId, id); + ThreadUtil.execAsync(() -> { + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); + }); return CzgResult.success(); } @@ -121,7 +144,11 @@ public class ProdGroupController { public CzgResult enableProdGroup(@PathVariable("id") Long id) { //效验数据 AssertUtil.isNull(id, "{}不能为空", "id"); - prodGroupService.enableProdGroup(id); + Long shopId = StpKit.USER.getShopId(0L); + prodGroupService.enableProdGroup(shopId, id); + ThreadUtil.execAsync(() -> { + rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); + }); return CzgResult.success(); } } \ No newline at end of file diff --git a/cash-common/cash-common-service/src/main/java/com/czg/product/service/ProdGroupService.java b/cash-common/cash-common-service/src/main/java/com/czg/product/service/ProdGroupService.java index 530a0a7f..a723fc4b 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/product/service/ProdGroupService.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/product/service/ProdGroupService.java @@ -50,7 +50,7 @@ public interface ProdGroupService extends IService { * * @param id 商品分组ID */ - void deleteProdGroup(Long id); + void deleteProdGroup(Long shopId, Long id); /** * 更新商品分组 @@ -64,13 +64,13 @@ public interface ProdGroupService extends IService { * * @param id 商品分组ID */ - void disableProdGroup(Long id); + void disableProdGroup(Long shopId, Long id); /** * 启用商品分组 * * @param id 商品分组ID */ - void enableProdGroup(Long id); + void enableProdGroup(Long shopId, Long id); } \ No newline at end of file diff --git a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProdGroupServiceImpl.java b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProdGroupServiceImpl.java index e26e3322..36c8f233 100644 --- a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProdGroupServiceImpl.java +++ b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProdGroupServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; +import com.czg.constant.CacheConstant; import com.czg.enums.StatusEnum; import com.czg.exception.CzgException; import com.czg.product.dto.ProdGroupDTO; @@ -22,6 +23,7 @@ import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.update.UpdateChain; import com.mybatisflex.spring.service.impl.ServiceImpl; import lombok.AllArgsConstructor; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -82,6 +84,7 @@ public class ProdGroupServiceImpl extends ServiceImpl