28 changed files with 259 additions and 82 deletions
@ -0,0 +1,13 @@ |
|||||
|
package com.qs.serve.common.consts; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2025/6/6 |
||||
|
*/ |
||||
|
public interface CommonValue { |
||||
|
|
||||
|
BigDecimal N100 = new BigDecimal("100"); |
||||
|
|
||||
|
} |
@ -1,22 +0,0 @@ |
|||||
package com.qs.serve.modules.oms.service.impl; |
|
||||
|
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
||||
import lombok.AllArgsConstructor; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
import com.qs.serve.modules.oms.entity.OmsPromotionGift; |
|
||||
import com.qs.serve.modules.oms.service.OmsPromotionGiftService; |
|
||||
import com.qs.serve.modules.oms.mapper.OmsPromotionGiftMapper; |
|
||||
|
|
||||
/** |
|
||||
* 搭赠方案 服务实现类 |
|
||||
* @author YenHex |
|
||||
* @since 2025-06-05 |
|
||||
*/ |
|
||||
@Slf4j |
|
||||
@Service |
|
||||
@AllArgsConstructor |
|
||||
public class OmsPromotionGiftServiceImpl extends ServiceImpl<OmsPromotionGiftMapper,OmsPromotionGift> implements OmsPromotionGiftService { |
|
||||
|
|
||||
} |
|
||||
|
|
@ -0,0 +1,178 @@ |
|||||
|
package com.qs.serve.modules.oms.service.impl; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollUtil; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.qs.serve.common.consts.CommonValue; |
||||
|
import com.qs.serve.common.exception.Assert; |
||||
|
import com.qs.serve.common.utils.CopierUtil; |
||||
|
import com.qs.serve.modules.bms.entity.BmsSubject; |
||||
|
import com.qs.serve.modules.bms.mapper.BmsSubjectMapper; |
||||
|
import com.qs.serve.modules.goods.entity.dto.GoodsTargetInfo; |
||||
|
import com.qs.serve.modules.goods.entity.dto.TbsCenterDto; |
||||
|
import com.qs.serve.modules.goods.service.GoodsApplicationService; |
||||
|
import com.qs.serve.modules.oms.entity.*; |
||||
|
import com.qs.serve.modules.oms.entity.bo.*; |
||||
|
import com.qs.serve.modules.oms.mapper.*; |
||||
|
import com.qs.serve.modules.oms.service.OmsPromotionGiftService; |
||||
|
import com.qs.serve.modules.tbs.service.TbsCenterDtoService; |
||||
|
import com.qs.serve.modules.tzc.entity.bo.TzcRebateGoodsParam; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.List; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 搭赠方案 服务实现类 |
||||
|
* @author YenHex |
||||
|
* @since 2025-06-05 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class OmsPromotionGiftServiceImpl extends ServiceImpl<OmsPromotionGiftMapper,OmsPromotionGift> implements OmsPromotionGiftService { |
||||
|
|
||||
|
private BmsSubjectMapper bmsSubjectMapper; |
||||
|
private final TbsCenterDtoService tbsCenterDtoService; |
||||
|
private final GoodsApplicationService goodsApplicationService; |
||||
|
|
||||
|
private OmsPromotionGiftCenterMapper omsPromotionGiftCenterMapper; |
||||
|
private OmsPromotionGiftSubjectMapper omsPromotionGiftSubjectMapper; |
||||
|
private OmsPromotionGiftScopeMapper omsPromotionGiftScopeMapper; |
||||
|
private OmsPromotionGiftItemMapper omsPromotionGiftItemMapper; |
||||
|
private OmsPromotionGiftGoodsMapper omsPromotionGiftGoodsMapper; |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void modifyGift(OmsPromotionGiftBo giftBo) { |
||||
|
boolean isUpdate = false; |
||||
|
if (giftBo.getId() != null){ |
||||
|
isUpdate = true; |
||||
|
OmsPromotionGift entity = this.getById(giftBo.getId()); |
||||
|
Assert.throwEx(entity == null, "数据不存在"); |
||||
|
Assert.throwEx(entity.getGiftStatus() != 0,"搭赠案的状态已更新,请刷新后再试!"); |
||||
|
} |
||||
|
List<OmsPromotionGiftSubjectBo> subjectBoList = giftBo.getSubjectList(); |
||||
|
List<OmsPromotionGiftScopeBo> scopeBoList = giftBo.getScopeList(); |
||||
|
List<OmsPromotionGiftItemBo> itemBoList = giftBo.getItemList(); |
||||
|
if (CollUtil.isNotEmpty(subjectBoList)){ |
||||
|
BigDecimal totalRate = BigDecimal.ZERO; |
||||
|
for (OmsPromotionGiftSubjectBo subjectBo : subjectBoList) { |
||||
|
totalRate = totalRate.add(subjectBo.getSubjectRate()); |
||||
|
BigDecimal totalCenterRate = BigDecimal.ZERO; |
||||
|
for (OmsPromotionGiftCenterBo centerBo : subjectBo.getCenterList()) { |
||||
|
totalCenterRate = totalCenterRate.add(centerBo.getCenterRate()); |
||||
|
} |
||||
|
Assert.throwEx(totalCenterRate.compareTo(CommonValue.N100) != 0,"成本中心占比总和必须为100 %"); |
||||
|
} |
||||
|
Assert.throwEx(totalRate.compareTo(CommonValue.N100) != 0,"科目占比总和必须为100 %"); |
||||
|
} |
||||
|
|
||||
|
OmsPromotionGift gift = CopierUtil.copy(giftBo,new OmsPromotionGift()); |
||||
|
gift.setId(giftBo.getId()); |
||||
|
gift.setGiftStatus(null); |
||||
|
gift.setSubmitTime(null); |
||||
|
gift.setSyFormId(null); |
||||
|
gift.setSyFlowId(null); |
||||
|
gift.setPassingTime(null); |
||||
|
super.saveOrUpdate(gift); |
||||
|
|
||||
|
Long giftId = gift.getId(); |
||||
|
|
||||
|
// 删除历史记录
|
||||
|
if (isUpdate){ |
||||
|
QueryWrapper delQw = new QueryWrapper(); |
||||
|
delQw.eq("gift_id",giftId); |
||||
|
omsPromotionGiftCenterMapper.delete(delQw); |
||||
|
omsPromotionGiftSubjectMapper.delete(delQw); |
||||
|
omsPromotionGiftScopeMapper.delete(delQw); |
||||
|
omsPromotionGiftItemMapper.delete(delQw); |
||||
|
omsPromotionGiftGoodsMapper.delete(delQw); |
||||
|
} |
||||
|
|
||||
|
for (OmsPromotionGiftScopeBo scopeBo : scopeBoList) { |
||||
|
OmsPromotionGiftScope scope = new OmsPromotionGiftScope(); |
||||
|
scope.setGiftId(giftId); |
||||
|
scope.setRegionType(scopeBo.getRegionType()); |
||||
|
scope.setRegionId(scopeBo.getRegionId()); |
||||
|
TbsCenterDto centerDto = tbsCenterDtoService.getCenterDto(scopeBo.getRegionType(),scopeBo.getRegionId()); |
||||
|
scope.setRegionCode(centerDto.getCenterCode()); |
||||
|
scope.setRegionName(centerDto.getCenterName()); |
||||
|
scope.setRemark(scopeBo.getRemark()); |
||||
|
omsPromotionGiftScopeMapper.insert(scope); |
||||
|
} |
||||
|
|
||||
|
saveItemAndGoods(itemBoList, giftId); |
||||
|
|
||||
|
this.saveGifSubjectAndCenter(subjectBoList, giftId); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存规则和商品 |
||||
|
* @param itemBoList |
||||
|
* @param giftId |
||||
|
*/ |
||||
|
private void saveItemAndGoods(List<OmsPromotionGiftItemBo> itemBoList, Long giftId) { |
||||
|
for (OmsPromotionGiftItemBo itemBo : itemBoList) { |
||||
|
OmsPromotionGiftItem giftItem = CopierUtil.copy(itemBo,new OmsPromotionGiftItem()); |
||||
|
giftItem.setGiftId(giftId); |
||||
|
if (CollUtil.isNotEmpty(itemBo.getGoodsList())){ |
||||
|
giftItem.setGoodsFlag(1); |
||||
|
} |
||||
|
GoodsTargetInfo goodsTarget = goodsApplicationService.getGoodsTargetInfo(giftItem.getGoodsType(),giftItem.getGoodsId()); |
||||
|
giftItem.setGoodsCode(goodsTarget.getTargetCode()); |
||||
|
giftItem.setGoodsName(goodsTarget.getTargetName()); |
||||
|
omsPromotionGiftItemMapper.insert(giftItem); |
||||
|
if (CollUtil.isNotEmpty(itemBo.getGoodsList())){ |
||||
|
for (OmsPromotionGiftGoodsBo goodsBo : itemBo.getGoodsList()) { |
||||
|
OmsPromotionGiftGoods giftGoods = CopierUtil.copy(goodsBo,new OmsPromotionGiftGoods()); |
||||
|
giftGoods.setGiftId(giftId); |
||||
|
giftGoods.setGiftItemId(giftItem.getId()); |
||||
|
giftGoods.setGoodsType(goodsBo.getGoodsType()); |
||||
|
GoodsTargetInfo goodsTarget2 = goodsApplicationService.getGoodsTargetInfo(giftGoods.getGoodsType(),giftGoods.getGoodsId()); |
||||
|
giftGoods.setGoodsCode(goodsTarget2.getTargetCode()); |
||||
|
giftGoods.setGoodsName(goodsTarget2.getTargetName()); |
||||
|
omsPromotionGiftGoodsMapper.insert(giftGoods); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param subjectBoList |
||||
|
* @param giftId |
||||
|
*/ |
||||
|
private void saveGifSubjectAndCenter(List<OmsPromotionGiftSubjectBo> subjectBoList, Long giftId) { |
||||
|
for (OmsPromotionGiftSubjectBo subjectBo : subjectBoList) { |
||||
|
OmsPromotionGiftSubject giftSubject = CopierUtil.copy(subjectBo,new OmsPromotionGiftSubject()); |
||||
|
giftSubject.setGiftId(giftId); |
||||
|
BmsSubject subject1 = bmsSubjectMapper.selectById(giftSubject.getSubjectId()); |
||||
|
giftSubject.setSubjectCode(subject1.getSubjectCode()); |
||||
|
giftSubject.setSubjectName(subject1.getSubjectName()); |
||||
|
omsPromotionGiftSubjectMapper.insert(giftSubject); |
||||
|
|
||||
|
for (OmsPromotionGiftCenterBo centerBo : subjectBo.getCenterList()) { |
||||
|
OmsPromotionGiftCenter center = new OmsPromotionGiftCenter(); |
||||
|
center.setGiftId(giftId); |
||||
|
center.setGiftSubjectId(giftSubject.getId()); |
||||
|
center.setSubjectId(giftSubject.getSubjectId()); |
||||
|
center.setCenterRate(centerBo.getCenterRate()); |
||||
|
center.setCenterId(centerBo.getCenterId()); |
||||
|
TbsCenterDto centerDto = tbsCenterDtoService.getCenterDto(centerBo.getCenterType(),centerBo.getCenterId()); |
||||
|
center.setCenterType(centerBo.getCenterType()); |
||||
|
center.setCenterCode(centerDto.getCenterCode()); |
||||
|
center.setCenterName(centerDto.getCenterName()); |
||||
|
omsPromotionGiftCenterMapper.insert(center); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
Loading…
Reference in new issue