mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
【修复】商城系统:优惠活动中的限时活动,添加活动报错系统异常
This commit is contained in:
parent
3f7e99c938
commit
b7554e935c
@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
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.DiscountActivityBaseVO;
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.discount.vo.DiscountActivityCreateReqVO;
|
import cn.iocoder.yudao.module.promotion.controller.admin.discount.vo.DiscountActivityCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.discount.vo.DiscountActivityPageReqVO;
|
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 cn.iocoder.yudao.module.promotion.util.PromotionUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -48,31 +50,30 @@ public class DiscountActivityServiceImpl implements DiscountActivityService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DiscountProductDO> getMatchDiscountProductList(Collection<Long> skuIds) {
|
public List<DiscountProductDO> getMatchDiscountProductList(Collection<Long> skuIds) {
|
||||||
// TODO @zhangshuai:这里是不是可以直接 return discountProductMapper.getMatchDiscountProductList(skuIds); 一般来说,如果 idea 报“黄色”的警告,尽量都处理下哈;原则是,一切警告,皆为异常(错误),这样可以写出更好的代码。
|
return discountProductMapper.getMatchDiscountProductList(skuIds);
|
||||||
List<DiscountProductDO> matchDiscountProductList = discountProductMapper.getMatchDiscountProductList(skuIds);
|
|
||||||
return matchDiscountProductList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long createDiscountActivity(DiscountActivityCreateReqVO createReqVO) {
|
public Long createDiscountActivity(DiscountActivityCreateReqVO createReqVO) {
|
||||||
// 校验商品是否冲突
|
// 校验商品是否冲突
|
||||||
validateDiscountActivityProductConflicts(null, createReqVO.getProducts());
|
validateDiscountActivityProductConflicts(null, createReqVO.getProducts());
|
||||||
|
|
||||||
// 插入活动
|
// 插入活动
|
||||||
DiscountActivityDO discountActivity = DiscountActivityConvert.INSTANCE.convert(createReqVO)
|
DiscountActivityDO discountActivity = DiscountActivityConvert.INSTANCE.convert(createReqVO)
|
||||||
// TODO @zhangshuai:这里的调用去掉哈,强制就是开启的;
|
.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
.setStatus(PromotionUtils.calculateActivityStatus(createReqVO.getEndTime()));
|
|
||||||
discountActivityMapper.insert(discountActivity);
|
discountActivityMapper.insert(discountActivity);
|
||||||
// 插入商品
|
// 插入商品
|
||||||
// TODO @zhangshuai:activityStatus 最好代码里,也做下设置噢。
|
List<DiscountProductDO> discountProducts = BeanUtils.toBean(createReqVO.getProducts(), DiscountProductDO.class,
|
||||||
List<DiscountProductDO> discountProducts = convertList(createReqVO.getProducts(),
|
product -> product.setActivityId(discountActivity.getId()).setActivityStatus(discountActivity.getStatus())
|
||||||
product -> DiscountActivityConvert.INSTANCE.convert(product).setActivityId(discountActivity.getId()));
|
.setActivityStartTime(createReqVO.getStartTime()).setActivityEndTime(createReqVO.getEndTime()));
|
||||||
discountProductMapper.insertBatch(discountProducts);
|
discountProductMapper.insertBatch(discountProducts);
|
||||||
// 返回
|
// 返回
|
||||||
return discountActivity.getId();
|
return discountActivity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateDiscountActivity(DiscountActivityUpdateReqVO updateReqVO) {
|
public void updateDiscountActivity(DiscountActivityUpdateReqVO updateReqVO) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
DiscountActivityDO discountActivity = validateDiscountActivityExists(updateReqVO.getId());
|
DiscountActivityDO discountActivity = validateDiscountActivityExists(updateReqVO.getId());
|
||||||
|
Loading…
Reference in New Issue
Block a user