| | |
| | | } |
| | | @Log(title = "邀请码导入", businessType = BusinessType.IMPORT) |
| | | @ApiOperation(value = "邀请码导入") |
| | | @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW) |
| | | @PostMapping("/importExcel") |
| | | public R<String> importExcel(@RequestPart("file") MultipartFile file) { |
| | | ImportParams params = new ImportParams(); |
| | |
| | | area.setArea(area.getArea()); |
| | | area.setCityCode(dto.getCityCode()); |
| | | xpElectronicFenceAreaMapper.insert(area); |
| | | |
| | | } |
| | | |
| | | }else{ |
| | | // 设置电子围栏ID并保存区域数据 |
| | | for (XpElectronicFenceArea area : newElectronicFenceAreas) { |
| | | area.setElectronicId(xpElectronicFence.getId()); |
| | | area.setAreaStatus(2); |
| | | area.setArea(area.getArea()); |
| | | area.setCityCode(dto.getCityCode()); |
| | | xpElectronicFenceAreaMapper.insert(area); |
| | | |
| | | } |
| | | } |
| | | |
| | | if (dto.getStatus() == 2) { |
| | |
| | | gpsPoints.add(point); |
| | | } |
| | | TaxiPricingDemoService.PricingConfig config = new TaxiPricingDemoService.PricingConfig(); |
| | | config.peak = new TaxiPricingDemoService.PricingRule("高峰期", "14:40", "14:46", 15.0, 3.0, 5.0, 3.0, 0.8); |
| | | config.peaks.add(new TaxiPricingDemoService.PricingRule("高峰期", "14:40", "14:46", 15.0, 3.0, 5.0, 3.0, 0.8)); |
| | | config.peaks.add(new TaxiPricingDemoService.PricingRule("高峰期", "18:40", "19:46", 15.0, 3.0, 5.0, 3.0, 0.8)); |
| | | config.night = new TaxiPricingDemoService.PricingRule("夜间行驶", "14:47", "14:48", 18.0, 3.0, 5.0, 3.5, 1.0); |
| | | config.holiday = new TaxiPricingDemoService.PricingRule("节假日", "18:47", "18:48", 18.0, 3.0, 5.0, 4, 2.0); |
| | | config.normals.add(new TaxiPricingDemoService.PricingRule("普通时段", "14:46", "14:47", 10.0, 3.0, 5.0, 2.4, 0.5)); |
| | |
| | | System.err.println("--------------------------"); |
| | | System.err.println("应付总额: " + totalAmount + " 元"); |
| | | // 封装费用明细数据 |
| | | for (Map.Entry<String, BigDecimal> stringBigDecimalEntry : bill.entrySet()) { |
| | | FareBreakdownDetailVo startDetail = new FareBreakdownDetailVo(); |
| | | |
| | | String key = stringBigDecimalEntry.getKey(); |
| | | if (key.contains("起步价")){ |
| | | |
| | | startDetail.setTime(key.split("\\|")[1]); |
| | | // startDetail.setMileage(); |
| | | // startDetail.setDuration(); |
| | | startDetail.setMoney(stringBigDecimalEntry.getValue()); |
| | | if (key.contains("普通时段")){ |
| | | startDetail.setType(1); |
| | | }else if (key.contains("夜间")){ |
| | | startDetail.setType(2); |
| | | }else if (key.contains("高峰")){ |
| | | startDetail.setType(3); |
| | | }else if (key.contains("节假")){ |
| | | startDetail.setType(4); |
| | | } |
| | | } |
| | | } |
| | | // // 计算实际价格 |
| | | |
| | | // // 查询订单轨迹 |
| | |
| | | BigDecimal totalMileage = BigDecimal.valueOf(totalMileageKm); |
| | | |
| | | PricingRule baseRule = config.findMatchedRule(orderTime); |
| | | result.put("起步价(" + baseRule.ruleName + ")"+"-"+baseRule.start+"-"+baseRule.end, baseRule.baseFare); |
| | | result.put("起步价(" + baseRule.ruleName + ")"+"|"+baseRule.start+"-"+baseRule.end, baseRule.baseFare); |
| | | |
| | | if (totalMileage.compareTo(baseRule.baseKm) <= 0) { |
| | | return formatMap(result); |
| | |
| | | // BigDecimal totalSeg = distFee.add(timeFee).add(longExtra); |
| | | // 超出里程 |
| | | if (isOverBaseM) { |
| | | bill.put(activeRule.ruleName + "-"+activeRule.start + "-" + activeRule.end + "_Ml", bill.getOrDefault(activeRule.ruleName + activeRule.start + "-" + activeRule.end + "_Ml", BigDecimal.ZERO).add(segM)); |
| | | bill.put(activeRule.ruleName + "|"+activeRule.start + "-" + activeRule.end + "_Ml", bill.getOrDefault(activeRule.ruleName + activeRule.start + "-" + activeRule.end + "_Ml", BigDecimal.ZERO).add(segM)); |
| | | } |
| | | // 超出时间 |
| | | if (isOverBaseMs) { |
| | | bill.put(activeRule.ruleName + "-"+activeRule.start + "-" + activeRule.end + "_Ms", bill.getOrDefault(activeRule.ruleName + activeRule.start + "-" + activeRule.end + "_Ms", BigDecimal.ZERO).add(segMs)); |
| | | bill.put(activeRule.ruleName + "|"+activeRule.start + "-" + activeRule.end + "_Ms", bill.getOrDefault(activeRule.ruleName + activeRule.start + "-" + activeRule.end + "_Ms", BigDecimal.ZERO).add(segMs)); |
| | | } |
| | | |
| | | // 若不存在规则名称,则添加 |
| | | activeRuleNameRate.computeIfAbsent(activeRule.ruleName + "-"+activeRule.start + "-" + activeRule.end + "_Ml", k -> activeRule.perKmRate); // 超出里程的加价 |
| | | activeRuleNameRate.computeIfAbsent(activeRule.ruleName + "-"+activeRule.start + "-" + activeRule.end + "_Ms",k ->activeRule.perMinRate); // 超出时间的加价 |
| | | activeRuleNameRate.computeIfAbsent(activeRule.ruleName + "|"+activeRule.start + "-" + activeRule.end + "_Ml", k -> activeRule.perKmRate); // 超出里程的加价 |
| | | activeRuleNameRate.computeIfAbsent(activeRule.ruleName + "|"+activeRule.start + "-" + activeRule.end + "_Ms",k ->activeRule.perMinRate); // 超出时间的加价 |
| | | |
| | | activeRuleNameList.add(activeRule.ruleName + "-"+activeRule.start + "-" + activeRule.end + "_Ml"); |
| | | activeRuleNameList.add(activeRule.ruleName + "-"+activeRule.start + "-" + activeRule.end + "_Ms"); |
| | | activeRuleNameList.add(activeRule.ruleName + "|"+activeRule.start + "-" + activeRule.end + "_Ml"); |
| | | activeRuleNameList.add(activeRule.ruleName + "|"+activeRule.start + "-" + activeRule.end + "_Ms"); |
| | | // result.put(activeRule.ruleName, result.getOrDefault(activeRule.ruleName, BigDecimal.ZERO).add(totalSeg)); |
| | | } |
| | | // 1. 基础费率计算 |
| | |
| | | if(ruleName.endsWith("_Ml")){ |
| | | BigDecimal exceedValue = bill.get(ruleName); |
| | | if(Objects.nonNull(exceedValue)){ |
| | | result.put("distance"+split[0], result.getOrDefault(split[0], BigDecimal.ZERO).add(exceedValue)); |
| | | exceedValue = exceedValue.divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP); |
| | | }else{ |
| | | exceedValue = BigDecimal.ZERO; |
| | |
| | | }else{ |
| | | BigDecimal exceedValue = bill.get(ruleName); |
| | | if(Objects.nonNull(exceedValue)){ |
| | | result.put("time"+split[0], result.getOrDefault(split[0], BigDecimal.ZERO).add(exceedValue)); |
| | | exceedValue = exceedValue.divide(new BigDecimal(60000), 2, RoundingMode.HALF_UP); |
| | | }else{ |
| | | exceedValue = BigDecimal.ZERO; |
| | |
| | | } |
| | | // 2. 远途加价计算 (基于区间判定) |
| | | BigDecimal longExtra = calculateLongDistExtra(BigDecimal.valueOf(totalMileageKm), config.longSteps); |
| | | result.put("远途费", longExtra); |
| | | result.put("远途费|", longExtra); |
| | | return formatMap(result); |
| | | } |
| | | |
| | |
| | | |
| | | public static class PricingConfig { |
| | | public PricingRule holiday; |
| | | public PricingRule peak; |
| | | public List<PricingRule> peaks = new ArrayList<>(); |
| | | public PricingRule night; |
| | | public List<PricingRule> normals = new ArrayList<>(); |
| | | public List<LongRangeStep> longSteps = new ArrayList<>(); // 修改为区间列表 |
| | |
| | | public PricingRule findMatchedRule(Date date) { |
| | | LocalTime t = date.toInstant().atZone(ZoneId.systemDefault()).toLocalTime(); |
| | | if (holiday.isMatch(t)) return holiday; |
| | | if (peak.isMatch(t)) return peak; |
| | | for (PricingRule r : peaks) if (r.isMatch(t)) return r; |
| | | if (night.isMatch(t)) return night; |
| | | for (PricingRule r : normals) if (r.isMatch(t)) return r; |
| | | return normals.get(0); |
| | |
| | | |
| | | private static PricingConfig setupMockConfig() { |
| | | PricingConfig config = new PricingConfig(); |
| | | config.peak = new PricingRule("高峰期", "14:40", "14:46", 15.0, 3.0, 5.0, 3.0, 0.8); |
| | | config.peaks.add(new PricingRule("高峰期", "14:40", "14:46", 15.0, 3.0, 5.0, 3.0, 0.8)); |
| | | config.peaks.add(new PricingRule("高峰期", "19:40", "20:46", 15.0, 3.0, 5.0, 3.0, 0.8)); |
| | | config.night = new PricingRule("夜间行驶", "14:47", "14:48", 18.0, 3.0, 5.0, 3.5, 1.0); |
| | | config.holiday = new PricingRule("节假日", "18:47", "18:48", 18.0, 3.0, 5.0, 4, 2.0); |
| | | config.normals.add(new PricingRule("普通时段", "14:46", "14:47", 10.0, 3.0, 5.0, 2.4, 0.5)); |