From b7554e935c8af173f2c40a9610c39ce8c6f19681 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 2 May 2024 14:57:53 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E5=95=86?= =?UTF-8?q?=E5=9F=8E=E7=B3=BB=E7=BB=9F=EF=BC=9A=E4=BC=98=E6=83=A0=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E4=B8=AD=E7=9A=84=E9=99=90=E6=97=B6=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=B4=BB=E5=8A=A8=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discount/DiscountActivityServiceImpl.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityServiceImpl.java index f103cf5532..25872d8e8b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/discount/DiscountActivityServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.promotion.controller.admin.discount.vo.DiscountActivityBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.discount.vo.DiscountActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.discount.vo.DiscountActivityPageReqVO; @@ -18,6 +19,7 @@ import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnu import cn.iocoder.yudao.module.promotion.util.PromotionUtils; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import java.time.LocalDateTime; @@ -48,31 +50,30 @@ public class DiscountActivityServiceImpl implements DiscountActivityService { @Override public List getMatchDiscountProductList(Collection skuIds) { - // TODO @zhangshuai:这里是不是可以直接 return discountProductMapper.getMatchDiscountProductList(skuIds); 一般来说,如果 idea 报“黄色”的警告,尽量都处理下哈;原则是,一切警告,皆为异常(错误),这样可以写出更好的代码。 - List matchDiscountProductList = discountProductMapper.getMatchDiscountProductList(skuIds); - return matchDiscountProductList; + return discountProductMapper.getMatchDiscountProductList(skuIds); } @Override + @Transactional(rollbackFor = Exception.class) public Long createDiscountActivity(DiscountActivityCreateReqVO createReqVO) { // 校验商品是否冲突 validateDiscountActivityProductConflicts(null, createReqVO.getProducts()); // 插入活动 DiscountActivityDO discountActivity = DiscountActivityConvert.INSTANCE.convert(createReqVO) - // TODO @zhangshuai:这里的调用去掉哈,强制就是开启的; - .setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getEndTime())); + .setStatus(CommonStatusEnum.ENABLE.getStatus()); discountActivityMapper.insert(discountActivity); // 插入商品 - // TODO @zhangshuai:activityStatus 最好代码里,也做下设置噢。 - List discountProducts = convertList(createReqVO.getProducts(), - product -> DiscountActivityConvert.INSTANCE.convert(product).setActivityId(discountActivity.getId())); + List discountProducts = BeanUtils.toBean(createReqVO.getProducts(), DiscountProductDO.class, + product -> product.setActivityId(discountActivity.getId()).setActivityStatus(discountActivity.getStatus()) + .setActivityStartTime(createReqVO.getStartTime()).setActivityEndTime(createReqVO.getEndTime())); discountProductMapper.insertBatch(discountProducts); // 返回 return discountActivity.getId(); } @Override + @Transactional(rollbackFor = Exception.class) public void updateDiscountActivity(DiscountActivityUpdateReqVO updateReqVO) { // 校验存在 DiscountActivityDO discountActivity = validateDiscountActivityExists(updateReqVO.getId());