12 changed files with 28 additions and 264 deletions
@ -1,28 +0,0 @@ |
|||||
package com.qs.serve.modules.tzc.service; |
|
||||
|
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
|
||||
import com.qs.serve.modules.tzc.entity.TzcRebate; |
|
||||
import com.qs.serve.modules.tzc.entity.bo.TzcRebateParam; |
|
||||
|
|
||||
/** |
|
||||
* 返利信息 服务接口 |
|
||||
* @author YenHex |
|
||||
* @date 2025-04-15 |
|
||||
*/ |
|
||||
public interface TzcRebateApplicationService { |
|
||||
|
|
||||
/** |
|
||||
* 编辑返利实体类 |
|
||||
* @param param |
|
||||
* @return |
|
||||
*/ |
|
||||
Object modifyRebate(TzcRebateParam param); |
|
||||
|
|
||||
/** |
|
||||
* 提交返利到OA |
|
||||
* @param id |
|
||||
*/ |
|
||||
void commitRebate(Long id); |
|
||||
|
|
||||
} |
|
||||
|
|
@ -1,224 +0,0 @@ |
|||||
package com.qs.serve.modules.tzc.service.impl; |
|
||||
|
|
||||
import cn.hutool.core.collection.CollUtil; |
|
||||
import com.qs.serve.common.exception.Assert; |
|
||||
import com.qs.serve.common.utils.CopierUtil; |
|
||||
import com.qs.serve.framework.base.model.ResultFlag; |
|
||||
import com.qs.serve.framework.redis.utils.CodeGenUtil; |
|
||||
import com.qs.serve.modules.basic.entity.BmsSubject; |
|
||||
import com.qs.serve.modules.basic.entity.BmsSupplier; |
|
||||
import com.qs.serve.modules.basic.entity.dto.GoodsTargetInfo; |
|
||||
import com.qs.serve.modules.basic.mapper.BmsCostCenterMapper; |
|
||||
import com.qs.serve.modules.basic.mapper.BmsSubjectMapper; |
|
||||
import com.qs.serve.modules.basic.mapper.BmsSupplierMapper; |
|
||||
import com.qs.serve.modules.basic.service.GoodsApplicationService; |
|
||||
import com.qs.serve.modules.tzc.entity.TzcRebate; |
|
||||
import com.qs.serve.modules.tzc.entity.TzcRebateGoods; |
|
||||
import com.qs.serve.modules.tzc.entity.TzcRebateSubject; |
|
||||
import com.qs.serve.modules.tzc.entity.bo.*; |
|
||||
import com.qs.serve.modules.tzc.enums.TzcRebateStatus; |
|
||||
import com.qs.serve.modules.tzc.service.TzcRebateApplicationService; |
|
||||
import com.qs.serve.modules.tzc.service.TzcRebateService; |
|
||||
import lombok.AllArgsConstructor; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.jetbrains.annotations.NotNull; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
|
|
||||
import java.math.BigDecimal; |
|
||||
import java.util.ArrayList; |
|
||||
import java.util.HashMap; |
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
import java.util.stream.Collectors; |
|
||||
|
|
||||
/** |
|
||||
* @author YenHex |
|
||||
* @since 2025/4/16 |
|
||||
*/ |
|
||||
@Slf4j |
|
||||
@Service |
|
||||
@AllArgsConstructor |
|
||||
public class TzcRebateApplicationServiceImpl implements TzcRebateApplicationService { |
|
||||
|
|
||||
private final TzcRebateService tzcRebateService; |
|
||||
|
|
||||
private final BmsCostCenterMapper bmsCostCenterMapper; |
|
||||
private final BmsSupplierMapper bmsSupplierMapper; |
|
||||
private final BmsSubjectMapper bmsSubjectMapper; |
|
||||
private final GoodsApplicationService goodsApplicationService; |
|
||||
|
|
||||
@Override |
|
||||
public Object modifyRebate(TzcRebateParam param) { |
|
||||
|
|
||||
Long rebateId = param.getId(); |
|
||||
String rebateCode = null; |
|
||||
|
|
||||
if(rebateId!=null){ |
|
||||
TzcRebate rebate = tzcRebateService.getById(rebateId); |
|
||||
if(TzcRebateStatus.DRAFT.isEqual(rebate.getRebateStatus())){ |
|
||||
Assert.throwEx("返利状态为初始化,不能修改"); |
|
||||
} |
|
||||
rebateCode = rebate.getRebateCode(); |
|
||||
}else { |
|
||||
rebateCode = "FL"+CodeGenUtil.generate(CodeGenUtil.SourceKey.TZC_REBATE); |
|
||||
} |
|
||||
|
|
||||
// 校验返利参数
|
|
||||
this.validRebateParam(param); |
|
||||
|
|
||||
BmsSupplier supplier = bmsSupplierMapper.selectById(param.getSupplierId()); |
|
||||
if(supplier==null){ |
|
||||
Assert.throwEx("客户不存在"); |
|
||||
} |
|
||||
|
|
||||
TzcRebate rebate = new TzcRebate(); |
|
||||
rebate.setId(rebateId); |
|
||||
rebate.setRebateCode(rebateCode); |
|
||||
// rebate.setTemplateId();
|
|
||||
// rebate.setTemplateName();
|
|
||||
rebate.setRebateName(param.getRebateName()); |
|
||||
rebate.setRebateStatus(TzcRebateStatus.DRAFT.getStatus()); |
|
||||
rebate.setActivityStartTime(param.getActivityStartTime()); |
|
||||
rebate.setActivityEndTime(param.getActivityEndTime()); |
|
||||
rebate.setCheckModel(param.getCheckModel()); |
|
||||
rebate.setCheckMaxAmount(param.getCheckMaxAmount()); |
|
||||
rebate.setCheckAutoDateType(param.getCheckAutoDateType()); |
|
||||
rebate.setCheckStartDate(param.getCheckStartDate()); |
|
||||
rebate.setCheckEndDate(param.getCheckEndDate()); |
|
||||
rebate.setSupplierId(param.getSupplierId()); |
|
||||
rebate.setSupplierCode(supplier.getCode()); |
|
||||
rebate.setSupplierName(supplier.getName()); |
|
||||
rebate.setRebateAmount(param.getRebateAmount()); |
|
||||
rebate.setRemark(param.getRemark()); |
|
||||
|
|
||||
// 返利的商品
|
|
||||
List<TzcRebateGoods> tzcRebateGoodsList = this.buildRebateGoodsList(param.getGoodsType(),param.getGoodsList()); |
|
||||
// 返利的商品,关联主表id和code
|
|
||||
for (TzcRebateGoods rebateGoods : tzcRebateGoodsList) { |
|
||||
rebateGoods.setRebateId(rebate.getId()); |
|
||||
rebateGoods.setRebateCode(rebate.getRebateCode()); |
|
||||
} |
|
||||
|
|
||||
// 返利的科目
|
|
||||
List<TzcRebateSubject> tzcRebateSubjectList = this.buildRebateSubjectList(param.getSubjectList()); |
|
||||
|
|
||||
|
|
||||
return null; |
|
||||
} |
|
||||
|
|
||||
@NotNull |
|
||||
private List<TzcRebateSubject> buildRebateSubjectList(List<TzcRebateSubjectParam> subjectList) { |
|
||||
List<TzcRebateSubject> rebateSubjectList = new ArrayList<>(); |
|
||||
for (TzcRebateSubjectParam subjectParam : subjectList) { |
|
||||
TzcRebateSubject rebateSubject = new TzcRebateSubject(); |
|
||||
BmsSubject subject = bmsSubjectMapper.selectById(subjectParam.getSubjectId()); |
|
||||
rebateSubject.setSubjectId(subject.getId()); |
|
||||
rebateSubject.setSubjectCode(subject.getSubjectCode()); |
|
||||
rebateSubject.setSubjectName(subject.getSubjectName()); |
|
||||
rebateSubject.setSubjectRate(subjectParam.getSubjectRate()); |
|
||||
rebateSubject.setSubjectAmount(subjectParam.getSubjectAmount()); |
|
||||
rebateSubject.setRemark(subjectParam.getRemark()); |
|
||||
rebateSubject.setTmpUk(subjectParam.getTmpUk()); |
|
||||
|
|
||||
List<TzcRebateCenterParam> centerParamList= subjectParam.getCenterList(); |
|
||||
} |
|
||||
return rebateSubjectList; |
|
||||
} |
|
||||
|
|
||||
@NotNull |
|
||||
private List<TzcRebateGoods> buildRebateGoodsList(String goodsTypeAll, List<TzcRebateGoodsParam> goodsList) { |
|
||||
List<TzcRebateGoods> tzcRebateGoodsList = new ArrayList<>(); |
|
||||
// 方式一:支持多种
|
|
||||
// Map<String,List<TzcRebateGoodsParam>> goodsListMap = goodsList.stream()
|
|
||||
// .collect(Collectors.groupingBy(TzcRebateGoodsParam::getGoodsType));
|
|
||||
// 方式二:只支持一种,兼容旧活动接口参数
|
|
||||
Map<String,List<TzcRebateGoodsParam>> goodsListMap = new HashMap<>(); |
|
||||
goodsListMap.put(goodsTypeAll,goodsList); |
|
||||
|
|
||||
for (Map.Entry<String, List<TzcRebateGoodsParam>> entry : goodsListMap.entrySet()) { |
|
||||
String goodsType = entry.getKey(); |
|
||||
List<TzcRebateGoodsParam> goodsParamList = entry.getValue(); |
|
||||
List<GoodsTargetInfo> goodsTargetList = goodsApplicationService.getGoodsTargetInfo(goodsType,goodsParamList.stream() |
|
||||
.map(TzcRebateGoodsParam::getGoodsId).collect(Collectors.toList())); |
|
||||
for (GoodsTargetInfo targetInfo : goodsTargetList) { |
|
||||
TzcRebateGoods rebateGoods = CopierUtil.copy(targetInfo,new TzcRebateGoods()); |
|
||||
for (TzcRebateGoodsParam goodsParam : goodsParamList) { |
|
||||
if(goodsParam.getGoodsId().equals(targetInfo.getTargetId())){ |
|
||||
rebateGoods.setTmpUk(goodsParam.getTmpUk()); |
|
||||
rebateGoods.setRemark(goodsParam.getRemark()); |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
tzcRebateGoodsList.add(rebateGoods); |
|
||||
} |
|
||||
} |
|
||||
return tzcRebateGoodsList; |
|
||||
} |
|
||||
|
|
||||
private void validRebateParam(TzcRebateParam param) { |
|
||||
BigDecimal oneHundred = new BigDecimal(100); |
|
||||
List<TzcRebateSubjectParam> subjectParamList = param.getSubjectList(); |
|
||||
BigDecimal totalRate = BigDecimal.ZERO; |
|
||||
BigDecimal totalAmount = BigDecimal.ZERO; |
|
||||
for (TzcRebateSubjectParam subjectParam : subjectParamList) { |
|
||||
|
|
||||
List<TzcRebateCenterParam> centerParamList = subjectParam.getCenterList(); |
|
||||
BigDecimal totalCenterRate = BigDecimal.ZERO; |
|
||||
BigDecimal totalCenterAmount = BigDecimal.ZERO; |
|
||||
for (TzcRebateCenterParam centerParam : centerParamList) { |
|
||||
if(centerParam.getCenterRate().compareTo(BigDecimal.ZERO)<0){ |
|
||||
Assert.throwEx("成本中心占比不能小于0"); |
|
||||
} |
|
||||
if(centerParam.getCenterAmount().compareTo(BigDecimal.ZERO)<0){ |
|
||||
Assert.throwEx("成本中心额度不能小于0"); |
|
||||
} |
|
||||
totalCenterRate = totalCenterRate.add(centerParam.getCenterRate()); |
|
||||
totalCenterAmount = totalCenterAmount.add(centerParam.getCenterAmount()); |
|
||||
} |
|
||||
if(totalCenterRate.compareTo(oneHundred)!=0){ |
|
||||
Assert.throwEx("科目的成本中心合计占比异常,当前:"+totalCenterRate+"%"); |
|
||||
} |
|
||||
if(totalCenterAmount.compareTo(subjectParam.getSubjectAmount())!=0){ |
|
||||
Assert.throwEx("科目的成本中心合计计必须为返利科目额度"+totalCenterAmount+"元"); |
|
||||
} |
|
||||
if(subjectParam.getSubjectRate().compareTo(BigDecimal.ZERO)<0){ |
|
||||
Assert.throwEx("科目占比不能小于0"); |
|
||||
} |
|
||||
if(subjectParam.getSubjectAmount().compareTo(BigDecimal.ZERO)<0){ |
|
||||
Assert.throwEx("科目额度不能小于0"); |
|
||||
} |
|
||||
totalRate = totalRate.add(subjectParam.getSubjectRate()); |
|
||||
totalAmount = totalAmount.add(subjectParam.getSubjectAmount()); |
|
||||
|
|
||||
} |
|
||||
if(totalRate.compareTo(oneHundred)!=0){ |
|
||||
Assert.throwEx("科目占比合计["+totalRate+"%]不为100%"); |
|
||||
} |
|
||||
if(totalAmount.compareTo(param.getRebateAmount())!=0){ |
|
||||
Assert.throwEx("科目额度合计异常金额:"+totalAmount+"元"); |
|
||||
} |
|
||||
|
|
||||
List<TzcRebatePeriodParam> periodList = param.getPeriodList(); |
|
||||
for (int i = 0; i < periodList.size(); i++) { |
|
||||
TzcRebatePeriodParam period = periodList.get(i); |
|
||||
for (int j = i + 1; j < periodList.size(); j++) { |
|
||||
TzcRebatePeriodParam period2 = periodList.get(j); |
|
||||
if (period.getPeriodEndDate().compareTo(period2.getPeriodStartDate()) >= 0 |
|
||||
&& period.getPeriodStartDate().compareTo(period2.getPeriodEndDate()) <= 0) { |
|
||||
Assert.throwEx("["+period.getPeriodTitle()+"]与["+period2.getPeriodTitle()+"],时间段存在交集"); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// 校验坎级叠加
|
|
||||
if(CollUtil.isEmpty(param.getConfigList())){ |
|
||||
Assert.throwEx("坎级叠加标识为1时,坎级配置不能为空"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void commitRebate(Long id) { |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
Loading…
Reference in new issue