package com.cyksj.service.giftcard.impl; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.cyksj.common.exception.BusinessRuntimeException; import com.cyksj.mapper.GiftCardGoodsSkuMapper; import com.cyksj.mapper.GoodsDonMapper; import com.cyksj.mapper.GoodsDonSkuMapper; import com.cyksj.model.entity.GiftCardGoodsSku; import com.cyksj.model.entity.GoodsDon; import com.cyksj.model.entity.GoodsDonSku; import com.cyksj.model.request.GiftCardGoodsSkuReq; import com.cyksj.service.giftcard.GiftCardGoodsSkuService; import lombok.RequiredArgsConstructor; import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.List; /* *项目名: netflix *文件名: GiftCardGoodsSkuServiceImpl *创建者: JavaZou *创建时间:2023/8/29 18:19 */ @Service @RequiredArgsConstructor public class GiftCardGoodsSkuServiceImpl extends ServiceImpl implements GiftCardGoodsSkuService { private final GoodsDonSkuMapper goodsDonSkuMapper; private final GoodsDonMapper goodsDonMapper; @Override public void setOrUpdateGiftCardSku(GiftCardGoodsSku data) { if (data.getGoodsId() == null) { throw BusinessRuntimeException.getInstance("请选择对应的礼品卡平台"); } GoodsDon goodsDon = goodsDonMapper.selectById(data.getGoodsId()); if (goodsDon == null) { throw BusinessRuntimeException.getInstance("请选择对应的礼品卡平台"); } if (goodsDon.getSpecialType() == null || goodsDon.getSpecialType() != GoodsDon.SpecialType.giftCard) { throw BusinessRuntimeException.getInstance("该{0}平台不是礼品卡特殊类型", goodsDon.getTitle()); } BigDecimal cash = data.getCash(); Integer gcType = data.getGcType(); BigDecimal price = data.getPrice(); if (price == null || price.compareTo(BigDecimal.ZERO) == 0) { throw BusinessRuntimeException.getInstance("请输入正确的礼品卡配置价格"); } Long gcSkuId = data.getGcSkuId(); if (gcSkuId == null && cash == null) { throw BusinessRuntimeException.getInstance("请选择对应的礼品卡类型"); } if (gcSkuId != null && cash != null) { throw BusinessRuntimeException.getInstance("只能选择一种礼品卡类型"); } //虚拟卡 if (cash != null) { if (cash.compareTo(BigDecimal.ZERO) == 0) { throw BusinessRuntimeException.getInstance("请输入正确的礼品卡现金类型金额"); } gcType = 1; } if (gcSkuId != null) { GoodsDonSku sku = goodsDonSkuMapper.selectById(gcSkuId); if (sku == null) { throw BusinessRuntimeException.getInstance("存在未有的虚拟卡规格,请重新选择"); } if (!sku.getStatus()) { throw BusinessRuntimeException.getInstance("存在下架的虚拟卡规格,请重新选择"); } gcType = 2; data.setGcGoodsId(sku.getGoodsId()); } data.setGcType(gcType); try { this.saveOrUpdate(data); } catch (DuplicateKeyException e) { } } @Override public void setGiftCardSku(GiftCardGoodsSkuReq req) { List giftCardGoodsSkus = req.getConfigs(); if (CollUtil.isEmpty(giftCardGoodsSkus)) { throw BusinessRuntimeException.getInstance("请输入对应数据"); } giftCardGoodsSkus.forEach(giftCardSku -> { giftCardSku.setGoodsId(req.getGoodsId()); setOrUpdateGiftCardSku(giftCardSku); }); } }