| | |
| | | exceedValue = BigDecimal.ZERO; |
| | | } |
| | | BigDecimal exceedRate = activeRuleNameRate.get(ruleName); |
| | | result.put("时长费"+split[0], result.getOrDefault(split[0], BigDecimal.ZERO).add(exceedValue.multiply(exceedRate))); |
| | | result.put("时长费"+split[0]+"&"+exceedValue, result.getOrDefault(split[0], BigDecimal.ZERO).add(exceedValue.multiply(exceedRate))); |
| | | } |
| | | } |
| | | // 2. 远途加价计算 (基于区间判定) |
| | | BigDecimal longExtra = calculateLongDistExtra(BigDecimal.valueOf(totalMileageKm), config.longSteps); |
| | | result.put("远途费|", longExtra); |
| | | // 计算远途里程 |
| | | BigDecimal longExtraValue = calculateLongDistExtra(BigDecimal.valueOf(totalMileageKm), config.longSteps); |
| | | result.put("远途费&"+longExtraValue, longExtra); |
| | | return formatMap(result); |
| | | } |
| | | |
| | |
| | | } |
| | | return billM.subtract(extraStart).multiply(extraRate); |
| | | } |
| | | /** |
| | | * 计算远途费的里程 |
| | | */ |
| | | private BigDecimal calculateLongDistExtraValue(BigDecimal billM, List<LongRangeStep> steps) { |
| | | if (billM.compareTo(BigDecimal.ZERO) <= 0) return BigDecimal.ZERO; |
| | | |
| | | // 当前点所在的公里数 |
| | | BigDecimal extraStart = BigDecimal.ZERO; |
| | | BigDecimal extraRate = BigDecimal.ZERO; |
| | | |
| | | // 匹配区间规则 |
| | | for (LongRangeStep step : steps) { |
| | | if (step.isMatch(billM)) { |
| | | extraRate = step.addPrice; |
| | | extraStart = step.numStart; |
| | | break; |
| | | } |
| | | } |
| | | return billM.subtract(extraStart); |
| | | } |
| | | |
| | | private Map<String, BigDecimal> formatMap(Map<String, BigDecimal> map) { |
| | | return map.entrySet().stream().collect(Collectors.toMap( |