|
|
@ -22,10 +22,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -100,6 +97,7 @@ public class TzcRebateApplication4CostServiceImpl implements TzcRebateApplicatio |
|
|
|
TbsCostApply costApply = new TbsCostApply(); |
|
|
|
costApply.setRebateId(rebateId); |
|
|
|
costApply.setCode(rebate.getRebateCode()); |
|
|
|
costApply.setTemplateId(rebate.getTemplateId()); |
|
|
|
// 标记为返利类型
|
|
|
|
costApply.setContractFlag(3); |
|
|
|
costApply.setMatchType(1); |
|
|
@ -294,42 +292,59 @@ public class TzcRebateApplication4CostServiceImpl implements TzcRebateApplicatio |
|
|
|
* @param configList |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public BigDecimal getMaxLevelsAmount(List<TzcRebateLevels> levelsList, |
|
|
|
List<TzcRebateLevelsArgument> argumentList, |
|
|
|
List<TzcRebateLevelsConfig> configList){ |
|
|
|
int level = 0; |
|
|
|
String[] configArr = null; |
|
|
|
for (TzcRebateLevelsConfig config: configList) { |
|
|
|
if(config.getLevelNum()>level){ |
|
|
|
level = config.getLevelNum(); |
|
|
|
configArr = config.getLevelConfigs(); |
|
|
|
BigDecimal maxAmount = BigDecimal.ZERO; |
|
|
|
for (TzcRebateLevelsConfig config : configList) { |
|
|
|
Set<String> levelNumSet = Arrays.stream(config.getLevelConfigs()).collect(Collectors.toSet()); |
|
|
|
// 默认包含当前坎级
|
|
|
|
levelNumSet.add(config.getLevelNum()+""); |
|
|
|
BigDecimal currentConfAmount = BigDecimal.ZERO; |
|
|
|
for (String levelNumStr : levelNumSet) { |
|
|
|
int levelNum = Integer.parseInt(levelNumStr); |
|
|
|
// 当前坎级最高返利金额
|
|
|
|
BigDecimal currentLevelMaxAmount = getCurrentLevelMaxAmount(levelsList, argumentList, levelNum); |
|
|
|
if (currentLevelMaxAmount.compareTo(BigDecimal.ZERO)>0){ |
|
|
|
currentConfAmount = currentConfAmount.add(currentLevelMaxAmount); |
|
|
|
} |
|
|
|
} |
|
|
|
if (currentConfAmount.compareTo(maxAmount)>0){ |
|
|
|
maxAmount = currentConfAmount; |
|
|
|
} |
|
|
|
} |
|
|
|
BigDecimal maxAmount = BigDecimal.ZERO; |
|
|
|
return maxAmount; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取当前坎级最高金额 |
|
|
|
* @param levelsList |
|
|
|
* @param argumentList |
|
|
|
* @param levelNum |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@NotNull |
|
|
|
private BigDecimal getCurrentLevelMaxAmount(List<TzcRebateLevels> levelsList, List<TzcRebateLevelsArgument> argumentList, int levelNum) { |
|
|
|
BigDecimal currentLevelMaxAmount = BigDecimal.ZERO; |
|
|
|
for (TzcRebateLevels levels : levelsList) { |
|
|
|
String lvNum = levels.getLevelNum()+""; |
|
|
|
for (String levelNum : configArr) { |
|
|
|
if(lvNum.equals(levelNum)){ |
|
|
|
BigDecimal amt1 = BigDecimal.ZERO; |
|
|
|
BigDecimal amt2 = BigDecimal.ZERO; |
|
|
|
for (TzcRebateLevelsArgument argument : argumentList) { |
|
|
|
if(argument.getLevelId().equals(levels.getId())){ |
|
|
|
if (argument.getBusinessType().equals(TzcArgTypes.LevelReturn.name())){ |
|
|
|
amt1 = argument.getMaxReturn(); |
|
|
|
}else if (argument.getBusinessType().equals(TzcArgTypes.LevelOverallReturn.name())){ |
|
|
|
amt2 = argument.getMaxReturn(); |
|
|
|
} |
|
|
|
if(levels.getLevelNum()== levelNum){ |
|
|
|
// 排除返利和补偿返利的最高金额
|
|
|
|
BigDecimal currentArgAmount = BigDecimal.ZERO; |
|
|
|
for (TzcRebateLevelsArgument argument : argumentList) { |
|
|
|
if(argument.getLevelId().equals(levels.getId())){ |
|
|
|
if (argument.getMaxReturn().compareTo(currentArgAmount)>0){ |
|
|
|
currentArgAmount = argument.getMaxReturn(); |
|
|
|
} |
|
|
|
} |
|
|
|
if(amt1.compareTo(amt2)>0){ |
|
|
|
maxAmount = amt1; |
|
|
|
}else { |
|
|
|
maxAmount = amt2; |
|
|
|
} |
|
|
|
} |
|
|
|
// 排除同坎级的有同期和无同期的最高金额
|
|
|
|
if (currentArgAmount.compareTo(currentLevelMaxAmount)>0){ |
|
|
|
currentLevelMaxAmount = currentArgAmount; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return maxAmount; |
|
|
|
return currentLevelMaxAmount; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -360,12 +375,12 @@ public class TzcRebateApplication4CostServiceImpl implements TzcRebateApplicatio |
|
|
|
String msg = ""; |
|
|
|
if (levels.getConditionType().equals(0)){ |
|
|
|
periodAmount = sameDispatchAmt; |
|
|
|
msg = "同期金额:"+periodAmount; |
|
|
|
msg = ";同期金额:"+periodAmount; |
|
|
|
}else if (levels.getConditionType().equals(1)){ |
|
|
|
periodAmount = tarPeriodAmount; |
|
|
|
msg = "目标金额:"+periodAmount; |
|
|
|
msg = ";目标金额:"+periodAmount; |
|
|
|
} |
|
|
|
msg = "("+msg+",占比:"+levels.getConditionRate()+"(含)-"+levels.getConditionRateEnd()+"%)"; |
|
|
|
msg = msg+";占比:"+levels.getConditionRate()+"(含)-"+levels.getConditionRateEnd()+"%"; |
|
|
|
BigDecimal targetAmt = periodAmount.multiply(levels.getConditionRate()) |
|
|
|
.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); |
|
|
|
BigDecimal targetAmtEnd = periodAmount.multiply(levels.getConditionRateEnd()) |
|
|
@ -374,10 +389,10 @@ public class TzcRebateApplication4CostServiceImpl implements TzcRebateApplicatio |
|
|
|
boolean ok1 = dispatchAmt.compareTo(targetAmt)>=0; // 包含
|
|
|
|
boolean ok2 = dispatchAmt.compareTo(targetAmtEnd)<0; // 不包含
|
|
|
|
if (!ok1 || !ok2){ |
|
|
|
dto.appendDebugMsg("跳过坎级:"+levels.getLevelNum()+",门槛金额:"+targetAmt+msg+",发货金额:"+dispatchAmt); |
|
|
|
dto.appendDebugMsg("跳过坎级:"+levels.getLevelNum()+",门槛金额:"+targetAmt+"-"+targetAmtEnd + msg+",发货金额:"+dispatchAmt); |
|
|
|
continue; |
|
|
|
} |
|
|
|
dto.appendDebugMsg("命中坎级:"+levels.getLevelNum()+",条件金额:"+targetAmt+msg+",发货金额:"+dispatchAmt); |
|
|
|
dto.appendDebugMsg("命中坎级:"+levels.getLevelNum()+",门槛金额:"+targetAmt+"-"+targetAmtEnd + msg+",发货金额:"+dispatchAmt); |
|
|
|
dto.setMaxLevels(levels); |
|
|
|
return dto; |
|
|
|
}else if (levels.getConditionSelect().equals(1)){ |
|
|
@ -464,7 +479,6 @@ public class TzcRebateApplication4CostServiceImpl implements TzcRebateApplicatio |
|
|
|
dto.appendDebugMsg("读取坎级("+rebateLevels.getLevelNum()+")配置 ,返利参数:"+currentArgument.getBusinessType()); |
|
|
|
TzcRebateLevelAmountDTO rebateLevelsDTO = CopierUtil.copy(rebateLevels,new TzcRebateLevelAmountDTO()); |
|
|
|
rebateLevelsDTO.setArgument(currentArgument); |
|
|
|
rebateLevelsDTO.setMaxReturn(currentArgument.getMaxReturn()); |
|
|
|
// 选择的策略:0-百分比;1-固定金额
|
|
|
|
if (currentArgument.getRateAmtFlag().equals(1)){ |
|
|
|
rebateLevelsDTO.setReturnAmt(currentArgument.getReturnFixed()); |
|
|
@ -474,8 +488,11 @@ public class TzcRebateApplication4CostServiceImpl implements TzcRebateApplicatio |
|
|
|
if (currentArgument.getSumAddFlag().equals(0)){ |
|
|
|
BigDecimal rs = dispatchAmt.multiply(currentArgument.getReturnRate()) |
|
|
|
.divide(BigDecimal.valueOf(100),2,RoundingMode.HALF_UP); |
|
|
|
if (rs.compareTo(currentArgument.getMaxReturn())>0){ |
|
|
|
rs = currentArgument.getMaxReturn(); |
|
|
|
} |
|
|
|
rebateLevelsDTO.setReturnAmt(rs); |
|
|
|
rebateLevelsDTO.setDebugMsg("基于总量("+rs+")=返货金额("+dispatchAmt+")*返利百分比("+currentArgument.getReturnRate()+"%)"); |
|
|
|
rebateLevelsDTO.setDebugMsg("基于总量("+rs+")=返货金额("+dispatchAmt+")*返利百分比("+currentArgument.getReturnRate()+"%);最高返利:"+currentArgument.getMaxReturn()); |
|
|
|
}else if (currentArgument.getSumAddFlag().equals(1)){ |
|
|
|
// 增量 = (发货金额 - 同比发货金额) * 返利比例 / 100
|
|
|
|
BigDecimal rs = dispatchAmt.subtract(sameDispatchAmt) |
|
|
@ -483,7 +500,10 @@ public class TzcRebateApplication4CostServiceImpl implements TzcRebateApplicatio |
|
|
|
.divide(BigDecimal.valueOf(100),2,RoundingMode.HALF_UP); |
|
|
|
if (rs.compareTo(BigDecimal.ZERO)>0){ |
|
|
|
rebateLevelsDTO.setDebugMsg("基于增量("+rs+") " + |
|
|
|
"= (发货金额["+dispatchAmt+"] - 同比发货金额["+sameDispatchAmt+"]) * 返利比例["+currentArgument.getReturnRate()+"%]"); |
|
|
|
"= (发货金额["+dispatchAmt+"] - 同比发货金额["+sameDispatchAmt+"]) * 返利比例["+currentArgument.getReturnRate()+"%];最高返利"+currentArgument.getMaxReturn()); |
|
|
|
if (rs.compareTo(currentArgument.getMaxReturn())>0){ |
|
|
|
rs = currentArgument.getMaxReturn(); |
|
|
|
} |
|
|
|
rebateLevelsDTO.setReturnAmt(rs); |
|
|
|
}else { |
|
|
|
rebateLevelsDTO.setReturnAmt(BigDecimal.ZERO); |
|
|
|