|
|
|
@ -109,7 +109,6 @@ public class BsSalaryUtil { |
|
|
|
if (!StringUtils.hasText(stepStr) || !StringUtils.hasText(stepPriceStr) || count == null || count.compareTo(BigDecimal.ZERO) <= 0) { |
|
|
|
if (!StringUtils.hasText(stepStr) || !StringUtils.hasText(stepPriceStr) || count == null || count.compareTo(BigDecimal.ZERO) <= 0) { |
|
|
|
return BigDecimal.ZERO; |
|
|
|
return BigDecimal.ZERO; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 解析阶梯区间
|
|
|
|
// 解析阶梯区间
|
|
|
|
List<BigDecimal> stepList = Arrays.stream(stepStr.split(" ")) |
|
|
|
List<BigDecimal> stepList = Arrays.stream(stepStr.split(" ")) |
|
|
|
.filter(StringUtils::hasText) |
|
|
|
.filter(StringUtils::hasText) |
|
|
|
@ -125,37 +124,24 @@ public class BsSalaryUtil { |
|
|
|
if (priceList.size() != stepList.size() + 1) { |
|
|
|
if (priceList.size() != stepList.size() + 1) { |
|
|
|
return BigDecimal.ZERO; |
|
|
|
return BigDecimal.ZERO; |
|
|
|
} |
|
|
|
} |
|
|
|
BigDecimal totalAmount = BigDecimal.ZERO; |
|
|
|
BigDecimal finalPrice = BigDecimal.ZERO; |
|
|
|
BigDecimal remain = count; |
|
|
|
for (int i = 0; i < stepList.size(); i++) { |
|
|
|
BigDecimal preStep = BigDecimal.ZERO; |
|
|
|
BigDecimal stepLimit = stepList.get(i); |
|
|
|
// 遍历每一档阶梯
|
|
|
|
if (count.compareTo(stepLimit) <= 0) { |
|
|
|
BigDecimal one = new BigDecimal(1); |
|
|
|
finalPrice = priceList.get(i); |
|
|
|
for (int i = 0; i < stepList.size() && remain.compareTo(BigDecimal.ZERO) > 0; i++) { |
|
|
|
break; |
|
|
|
BigDecimal currStep = stepList.get(i).subtract(one); |
|
|
|
|
|
|
|
BigDecimal stepDiff = currStep.subtract(preStep); |
|
|
|
|
|
|
|
// 当前区间实际耗用数量
|
|
|
|
|
|
|
|
BigDecimal useNum = remain.min(stepDiff); |
|
|
|
|
|
|
|
// 累加金额
|
|
|
|
|
|
|
|
if (BsSalaryStandardEnum.STEP_SETTLEMENT_UNIT_BATCH.getCode().equals(stepSettlementUnit)) { |
|
|
|
|
|
|
|
totalAmount = totalAmount.add(priceList.get(i)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (BsSalaryStandardEnum.STEP_SETTLEMENT_UNIT_MULTIPLE.getCode().equals(stepSettlementUnit)) { |
|
|
|
|
|
|
|
totalAmount = totalAmount.add(useNum.multiply(priceList.get(i)).multiply(settlementPrice)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// 剩余数量
|
|
|
|
if (finalPrice.compareTo(BigDecimal.ZERO) == 0) { |
|
|
|
remain = remain.subtract(useNum); |
|
|
|
finalPrice = priceList.get(priceList.size() - 1); |
|
|
|
// 记录上一档阶梯
|
|
|
|
|
|
|
|
preStep = currStep; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// 超出所有阶梯的部分,取最后一档价格
|
|
|
|
// 遍历每一档阶梯
|
|
|
|
if (remain.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
BigDecimal totalAmount = BigDecimal.ZERO; |
|
|
|
BigDecimal lastPrice = priceList.get(priceList.size() - 1); |
|
|
|
|
|
|
|
if (BsSalaryStandardEnum.STEP_SETTLEMENT_UNIT_BATCH.getCode().equals(stepSettlementUnit)) { |
|
|
|
if (BsSalaryStandardEnum.STEP_SETTLEMENT_UNIT_BATCH.getCode().equals(stepSettlementUnit)) { |
|
|
|
totalAmount = totalAmount.add(lastPrice); |
|
|
|
totalAmount = finalPrice; |
|
|
|
} |
|
|
|
} |
|
|
|
if (BsSalaryStandardEnum.STEP_SETTLEMENT_UNIT_MULTIPLE.getCode().equals(stepSettlementUnit)) { |
|
|
|
if (BsSalaryStandardEnum.STEP_SETTLEMENT_UNIT_MULTIPLE.getCode().equals(stepSettlementUnit)) { |
|
|
|
totalAmount = totalAmount.add(remain.multiply(lastPrice).multiply(settlementPrice)); |
|
|
|
totalAmount = count.multiply(finalPrice).multiply(settlementPrice); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return totalAmount; |
|
|
|
return totalAmount; |
|
|
|
} |
|
|
|
} |
|
|
|
|