|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.qs.serve.common.exception.Assert; |
|
|
|
import com.qs.serve.common.utils.CopierUtil; |
|
|
|
import com.qs.serve.common.utils.StringUtils; |
|
|
|
import com.qs.serve.framework.base.model.ResultFlag; |
|
|
|
import com.qs.serve.framework.base.util.CollectionUtil; |
|
|
|
import com.qs.serve.framework.redis.utils.CodeGenUtil; |
|
|
@ -192,9 +193,6 @@ public class TzcRebateApplicationServiceImpl implements TzcRebateApplicationServ |
|
|
|
// 返利的商品
|
|
|
|
List<TzcRebateGoods> tzcRebateGoodsList = this.buildRebateGoodsList(param.getGoodsType(),param.getGoodsList()); |
|
|
|
|
|
|
|
// 期间及补偿参数保存
|
|
|
|
List<TzcRebatePeriod> periodList = this.savePeriodList(param.getPeriodList(), rebateId); |
|
|
|
|
|
|
|
// 保存坎级和设置参数
|
|
|
|
List<TzcRebateLevelsArgument> argumentList = new ArrayList<>(); |
|
|
|
List<TzcRebateLevels> levelsList = this.saveLevelListAndArgs(param.getLevelsList(), rebateId,argumentList); |
|
|
@ -218,8 +216,27 @@ public class TzcRebateApplicationServiceImpl implements TzcRebateApplicationServ |
|
|
|
configList.add(config); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取最高坎级返回的金额
|
|
|
|
// 获取最高坎级返回的金额(叠加金额)
|
|
|
|
BigDecimal maxAmount = tzcRebateApplication4CostService.getMaxLevelsAmount(levelsList, argumentList, configList); |
|
|
|
BigDecimal totalAllAmount = maxAmount.multiply(new BigDecimal(param.getPeriodList().size())); |
|
|
|
String periodMsg = "坎级叠加最高金额为:"+maxAmount; |
|
|
|
// 判断是否超预算
|
|
|
|
if (param.getRebateAmount()!=null){ |
|
|
|
if(totalAllAmount.compareTo(param.getRebateAmount())>0){ |
|
|
|
Assert.throwEx("返利金额超预算"); |
|
|
|
} |
|
|
|
// 计算需要增加的金额
|
|
|
|
BigDecimal needAddAmt = param.getRebateAmount().subtract(totalAllAmount); |
|
|
|
BigDecimal needAddAvgAmt = needAddAmt.divide(new BigDecimal(param.getPeriodList().size()),2,BigDecimal.ROUND_DOWN); |
|
|
|
// 添加补偿金额
|
|
|
|
maxAmount = maxAmount.add(needAddAvgAmt); |
|
|
|
totalAllAmount = param.getRebateAmount(); |
|
|
|
periodMsg = periodMsg+";设置最高返利金额:"+param.getRebateAmount()+",补充活动金额:"+needAddAvgAmt+"。活动合计金额:"+maxAmount; |
|
|
|
} |
|
|
|
|
|
|
|
// 期间及补偿参数保存
|
|
|
|
List<TzcRebatePeriod> periodList = this.savePeriodList(param.getPeriodList(), rebateId, periodMsg); |
|
|
|
|
|
|
|
// 计算和平摊到科目和成本中心(不再读取前端的金额)
|
|
|
|
List<TzcRebateSubjectParam> subjectParamList = param.getSubjectList(); |
|
|
|
this.calculateSubjectAndCenter(subjectParamList, maxAmount); |
|
|
@ -231,6 +248,7 @@ public class TzcRebateApplicationServiceImpl implements TzcRebateApplicationServ |
|
|
|
|
|
|
|
// 建立费用
|
|
|
|
Long costApplyId = tzcRebateApplication4CostService.buildCostAndActivity( |
|
|
|
maxAmount, |
|
|
|
rebate, |
|
|
|
argumentList, |
|
|
|
tzcRebateSubjectList, |
|
|
@ -243,10 +261,12 @@ public class TzcRebateApplicationServiceImpl implements TzcRebateApplicationServ |
|
|
|
|
|
|
|
// 绑定费用id
|
|
|
|
rebate.setCostApplyId(costApplyId); |
|
|
|
rebate.setRebateAmount(totalAllAmount); |
|
|
|
tzcRebateService.update( |
|
|
|
new LambdaUpdateWrapper<TzcRebate>() |
|
|
|
.eq(TzcRebate::getId,rebateId) |
|
|
|
.set(TzcRebate::getCostApplyId,costApplyId) |
|
|
|
.set(TzcRebate::getRebateAmount,totalAllAmount) |
|
|
|
); |
|
|
|
return rebate; |
|
|
|
} |
|
|
@ -445,7 +465,7 @@ public class TzcRebateApplicationServiceImpl implements TzcRebateApplicationServ |
|
|
|
* @param periodParamList |
|
|
|
* @param rebateId |
|
|
|
*/ |
|
|
|
private List<TzcRebatePeriod> savePeriodList(List<TzcRebatePeriodParam> periodParamList, Long rebateId) { |
|
|
|
private List<TzcRebatePeriod> savePeriodList(List<TzcRebatePeriodParam> periodParamList, Long rebateId,String msg) { |
|
|
|
List<TzcRebatePeriod> periodList = new ArrayList<>(); |
|
|
|
for (TzcRebatePeriodParam periodParam : periodParamList) { |
|
|
|
TzcRebatePeriod period = new TzcRebatePeriod(); |
|
|
@ -456,7 +476,11 @@ public class TzcRebateApplicationServiceImpl implements TzcRebateApplicationServ |
|
|
|
period.setPeriodAmount(periodParam.getPeriodAmount()); |
|
|
|
period.setSamePeriodAmount(periodParam.getSamePeriodAmount()); |
|
|
|
period.setCompensationFlag(periodParam.getCompensationFlag()); |
|
|
|
period.setRemark(periodParam.getRemark()); |
|
|
|
if (StringUtils.isNotEmpty(periodParam.getRemark())){ |
|
|
|
period.setRemark(periodParam.getRemark()+";"+msg); |
|
|
|
}else { |
|
|
|
period.setRemark(msg); |
|
|
|
} |
|
|
|
period.setExtRemark(periodParam.getExtRemark()); |
|
|
|
period.setTmpUk(periodParam.getTmpUk()); |
|
|
|
tzcRebatePeriodService.save(period); |
|
|
|