From ad7cf3c18c8a004d98a88aa54a971ac102849f43 Mon Sep 17 00:00:00 2001 From: liuminghui <468701464@qq.com> Date: Thu, 19 Nov 2026 11:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E4=BB=98=E9=82=AE=E7=BC=96=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E5=92=8C=E8=AE=A2=E5=8D=95=E5=BA=94=E4=BB=98=E8=AE=A1?= =?UTF-8?q?=E8=B4=B9=E7=9A=84=E9=99=84=E5=8A=A0=E8=B4=B9=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bms/price/pay/PayCostCalculatorTest.java | 129 ++++++++++++++++++ .../bms/price/pay/PayWorkbookParserTest.java | 6 +- .../bms/price/domain/PayPostcodeGroup.java | 6 + .../com/bms/price/domain/PayPostcodeLine.java | 3 + .../com/bms/price/domain/PaySurcharge.java | 3 + .../bms/price/domain/PrcSurchargeBind.java | 4 + .../com/bms/price/pay/PayCostCalculator.java | 115 +++++++++++++++- .../bms/price/pay/PayOrderFeeCalculator.java | 23 ++-- .../com/bms/price/pay/PayPostcodeBooks.java | 108 +++++++++++++++ .../com/bms/price/pay/PaySurchargeRules.java | 57 ++++++++ .../com/bms/price/pay/PayWorkbookParser.java | 108 ++++++++++++++- .../price/service/IPayPostcodeService.java | 2 +- .../service/impl/PayOrderCostServiceImpl.java | 24 ++-- .../service/impl/PayPostcodeServiceImpl.java | 7 +- .../service/impl/PayProductServiceImpl.java | 19 ++- .../mapper/price/PayPostcodeMapper.xml | 86 +++++++++--- .../mapper/price/PrcSurchargeBindMapper.xml | 2 +- .../components/PayPostcodeDrawer.vue | 1 + .../components/PayPostcodeFormDialog.vue | 2 + .../payPostcode/components/PayZoneDrawer.vue | 21 ++- .../components/PayZoneFormDialog.vue | 6 + .../src/views/data/payPostcode/index.vue | 12 +- .../basic/pay/components/PayConfigDetail.vue | 78 ++++++++++- 23 files changed, 752 insertions(+), 70 deletions(-) create mode 100644 bms-back/bms-system/src/main/java/com/bms/price/pay/PayPostcodeBooks.java diff --git a/bms-back/bms-admin/src/test/java/com/bms/price/pay/PayCostCalculatorTest.java b/bms-back/bms-admin/src/test/java/com/bms/price/pay/PayCostCalculatorTest.java index ce8cd883..4823f732 100644 --- a/bms-back/bms-admin/src/test/java/com/bms/price/pay/PayCostCalculatorTest.java +++ b/bms-back/bms-admin/src/test/java/com/bms/price/pay/PayCostCalculatorTest.java @@ -55,6 +55,92 @@ class PayCostCalculatorTest assertEquals(new BigDecimal("3.72"), over.getPayTotal()); } + @Test + void boundSurchargesKeepTheCardContinuation() + { + PayWeightBand first = band("0", "1", "10", "UK Mainland"); + first.setSectionName("派送费"); + first.setPriceUnit("CNY/ITEM"); + first.setChargeName("首重"); + PaySurcharge extra = fee(1L, "每公斤续重", "2", "CNY", "EXTRA_KG", "1"); + extra.setSectionName("派送费"); + extra.setZoneName("UK Mainland"); + extra.setPriceUnit("CNY/KG"); + PaySurcharge imported = fee(2L, "偏远地区附加费", "8", "CNY", "POSTCODE", "BT"); + PaySurcharge bound = fee(3L, "燃油", "1", "CNY", "ALWAYS", null); + bound.setSectionName("附加费配置"); + PaySurcharge configExtra = fee(5L, "超重续收", "9", "CNY", "EXTRA_KG", "1"); + configExtra.setSectionName("附加费配置"); + configExtra.setExtraWeightKg(new BigDecimal("1")); + configExtra.setZoneName("UK Mainland"); + PayProduct product = new PayProduct(); + product.setProductName("续重价"); + product.setCurrency("CNY"); + product.setWeightBands(new ArrayList<>(List.of(first))); + product.setSurcharges(PaySurchargeRules.surchargesForCalc(List.of(extra, imported), List.of(bound, configExtra))); + + PayOrderCostResult over = PayCostCalculator.calculate(product, new BigDecimal("3"), + null, null, null, "KY4 0DN", "UK Mainland", null, 1); + assertTrue(hasFee(over, "基础运费", "10")); + assertTrue(hasFee(over, "每公斤续重", "4")); + assertTrue(hasFee(over, "燃油", "1")); + assertFalse(over.getFees().stream().anyMatch(fee -> fee.getFeeName().contains("偏远"))); + assertFalse(over.getFees().stream().anyMatch(fee -> "超重续收".equals(fee.getFeeName()))); + assertEquals(new BigDecimal("15.00"), over.getPayTotal()); + } + + @Test + void boundConfigFeesFollowTheirOwnChargeRule() + { + PayProduct product = new PayProduct(); + product.setProductName("CTT 48H"); + product.setCurrency("EUR"); + product.setWeightBands(new ArrayList<>(List.of(band("0", "5", "2.05", "马德里")))); + PaySurcharge fuel = fee(11L, "燃油附加费", "0.50", "EUR", "ALWAYS", null); + fuel.setSectionName("附加费配置"); + fuel.setScId(101L); + PaySurcharge heavy = fee(12L, "超重附加费", "3", "EUR", "WEIGHT", null); + heavy.setSectionName("附加费配置"); + heavy.setOverWeightKg(new BigDecimal("2")); + PaySurcharge bulky = fee(13L, "超尺寸附加费", "4", "EUR", "SIZE", null); + bulky.setSectionName("附加费配置"); + bulky.setLengthCm(new BigDecimal("60")); + bulky.setWidthCm(new BigDecimal("40")); + bulky.setHeightCm(new BigDecimal("30")); + PaySurcharge remote = fee(14L, "偏远附加费", "7.1", "EUR", "POSTCODE", null); + remote.setSectionName("附加费配置"); + remote.setPostcodeText("07"); + remote.setCountryCode("ES"); + PaySurcharge manual = fee(15L, "仓库操作费", "1", "EUR", "MANUAL", null); + manual.setSectionName("附加费配置"); + PaySurcharge returned = fee(16L, "退件费", "2", "EUR", "RETURN", null); + returned.setSectionName("附加费配置"); + product.setSurcharges(List.of(fuel, heavy, bulky, remote, manual, returned)); + + PayOrderCostResult light = PayCostCalculator.calculate(product, new BigDecimal("1"), + new BigDecimal("10"), new BigDecimal("10"), new BigDecimal("10"), "28001", "马德里", null, 1, + List.of(), true, true, "ES", "西班牙"); + assertTrue(hasFee(light, "燃油附加费", "0.50")); + assertEquals(101L, light.getFees().stream().filter(row -> "燃油附加费".equals(row.getFeeName())).findFirst().orElseThrow().getScId()); + assertTrue(light.getFees().stream().noneMatch(row -> "超重附加费".equals(row.getFeeName()) || "超尺寸附加费".equals(row.getFeeName()) + || "偏远附加费".equals(row.getFeeName()) || "仓库操作费".equals(row.getFeeName()) || "退件费".equals(row.getFeeName()))); + + PayOrderCostResult hit = PayCostCalculator.calculate(product, new BigDecimal("3"), + new BigDecimal("70"), new BigDecimal("50"), new BigDecimal("40"), "07008", "马德里", null, 9, + List.of(), true, true, "ES", "西班牙"); + assertTrue(hasFee(hit, "燃油附加费", "0.50")); + assertTrue(hasFee(hit, "超重附加费", "3")); + assertTrue(hasFee(hit, "超尺寸附加费", "4")); + assertTrue(hasFee(hit, "偏远附加费", "7.1")); + assertTrue(hasFee(hit, "退件费", "2")); + assertTrue(hit.getFees().stream().noneMatch(row -> "仓库操作费".equals(row.getFeeName()))); + + PayOrderCostResult france = PayCostCalculator.calculate(product, new BigDecimal("3"), + new BigDecimal("70"), new BigDecimal("50"), new BigDecimal("40"), "07008", "马德里", null, 9, + List.of(), true, true, "FR", "法国"); + assertTrue(france.getFees().stream().noneMatch(row -> "偏远附加费".equals(row.getFeeName()))); + } + @Test void extraKgFollowsTheSameServiceSection() { @@ -184,6 +270,49 @@ class PayCostCalculatorTest assertTrue(PaySurchargeRules.matchesPostcode("07,35,38,51,52,9", "9000")); assertFalse(PaySurchargeRules.matchesPostcode("07,35,38,51,52,9", "28001")); assertTrue(PaySurchargeRules.matchesPostcode("IV,HS,KA27-28", "KA27 8AA")); + } + + @Test + void zoneFeeBandsKeepDeliveryAndAddRemoteAndLineHaul() + { + PayProduct product = new PayProduct(); + product.setProductName("CTT 48H"); + product.setCurrency("EUR"); + PayWeightBand delivery = band("0", "1", "2.05", "Mad High Density 马德里高密度地区"); + delivery.setSectionName("派送费"); + delivery.setChargeName("派送费"); + PayWeightBand lineHaul = band("0", "1", "0.09", "Mad High Density 马德里高密度地区"); + lineHaul.setSectionName("额外线路运输费"); + lineHaul.setChargeName("额外线路运输费"); + PayWeightBand remote = band("0", "1", "7.1", "Balearic Islands 07邮编开头"); + remote.setSectionName("偏远附加费"); + remote.setChargeName("偏远附加费"); + product.setWeightBands(new ArrayList<>(List.of(delivery, lineHaul, remote))); + PaySurcharge deliveryExtra = fee(11L, "每公斤续重", "0.29", "EUR", "EXTRA_KG", "1"); + deliveryExtra.setSectionName("派送费"); + deliveryExtra.setZoneName("Mad High Density 马德里高密度地区"); + PaySurcharge lineExtra = fee(12L, "每公斤续重", "0.05", "EUR", "EXTRA_KG", "1"); + lineExtra.setSectionName("额外线路运输费"); + lineExtra.setZoneName("Mad High Density 马德里高密度地区"); + PaySurcharge remoteExtra = fee(13L, "每公斤续重", "4", "EUR", "EXTRA_KG", "1"); + remoteExtra.setSectionName("偏远附加费"); + remoteExtra.setZoneName("Balearic Islands 07邮编开头"); + product.setSurcharges(List.of(deliveryExtra, lineExtra, remoteExtra)); + + PayOrderCostResult island = PayCostCalculator.calculate(product, new BigDecimal("3"), + null, null, null, "07008", "Mad High Density 马德里高密度地区", null, 1); + assertTrue(hasFee(island, "基础运费", "2.05")); + assertTrue(hasFee(island, "每公斤续重", "0.58")); + assertTrue(hasFee(island, "额外线路运输费", "0.09")); + assertTrue(hasFee(island, "额外线路运输费", "0.10")); + assertTrue(hasFee(island, "偏远附加费", "7.1")); + assertTrue(hasFee(island, "偏远附加费", "8")); + + PayOrderCostResult mainland = PayCostCalculator.calculate(product, new BigDecimal("3"), + null, null, null, "28001", "Mad High Density 马德里高密度地区", null, 1); + assertTrue(hasFee(mainland, "基础运费", "2.05")); + assertTrue(hasFee(mainland, "额外线路运输费", "0.09")); + assertTrue(mainland.getFees().stream().noneMatch(fee -> "偏远附加费".equals(fee.getFeeName()))); assertEquals("07", PaySurchargeRules.remotePrefixes("Balearic Islands 07邮编开头")); assertEquals("35,38", PaySurchargeRules.remotePrefixes("Canary Islands 35、38邮编开头")); assertEquals("9", PaySurchargeRules.remotePrefixes("Portuguese Island 9邮编开头")); diff --git a/bms-back/bms-admin/src/test/java/com/bms/price/pay/PayWorkbookParserTest.java b/bms-back/bms-admin/src/test/java/com/bms/price/pay/PayWorkbookParserTest.java index f80affd1..e8f9459d 100644 --- a/bms-back/bms-admin/src/test/java/com/bms/price/pay/PayWorkbookParserTest.java +++ b/bms-back/bms-admin/src/test/java/com/bms/price/pay/PayWorkbookParserTest.java @@ -3,6 +3,7 @@ package com.bms.price.pay; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.math.BigDecimal; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -34,7 +35,10 @@ class PayWorkbookParserTest assertTrue(evri.getSurcharges().stream().anyMatch(fee -> "战争附加费".equals(fee.getFeeName()) && fee.getChargeText().contains("2.5"))); PayProduct ctt = product(preview, "CTT 48H"); assertTrue(ctt.getWeightBands().stream().anyMatch(band -> band.getWeightLabel() != null && band.getWeightLabel().contains("首重") && decimal(band, "2.05"))); - assertTrue(ctt.getWeightBands().stream().anyMatch(band -> "每增加 1Kg".equals(band.getWeightLabel()) || (band.getWeightLabel() != null && band.getWeightLabel().contains("每增加")))); + assertTrue(ctt.getWeightBands().stream().noneMatch(band -> band.getWeightLabel() != null && band.getWeightLabel().contains("每增加"))); + assertTrue(ctt.getSurcharges().stream().anyMatch(fee -> "每公斤续重".equals(fee.getFeeName()) && fee.getAmount() != null && fee.getAmount().compareTo(new BigDecimal("0.29")) == 0)); + assertTrue(ctt.getWeightBands().stream().anyMatch(band -> band.getChargeName() != null && band.getChargeName().contains("偏远") && decimal(band, "7.1"))); + assertTrue(ctt.getWeightBands().stream().anyMatch(band -> band.getChargeName() != null && (band.getChargeName().contains("额外") || band.getChargeName().toLowerCase().contains("line-haul")) && decimal(band, "0.09"))); } @Test diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PayPostcodeGroup.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PayPostcodeGroup.java index 792c577d..041d324e 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/domain/PayPostcodeGroup.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PayPostcodeGroup.java @@ -34,6 +34,12 @@ public class PayPostcodeGroup extends BaseEntity /** 渠道名称,从表头识别,可在页面修改 */ private String channelName; + /** 修改渠道名称前的原名称。分区维护按这个渠道收窄 */ + private String oldChannelName; + + /** 为 true 时国家下的全部分区都查出来,不按渠道收窄 */ + private Boolean allChannels; + /** 目录里的服务类型,和报价产品对应 */ private String serviceType; diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PayPostcodeLine.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PayPostcodeLine.java index 0f5e5fe9..7e50f1e2 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/domain/PayPostcodeLine.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PayPostcodeLine.java @@ -19,6 +19,9 @@ public class PayPostcodeLine implements Serializable private String countryCode; + /** 查询条件:只看这个渠道下的邮编 */ + private String channelName; + private String regionName; private String regionNameCn; diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PaySurcharge.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PaySurcharge.java index ae7c2d56..20c94321 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/domain/PaySurcharge.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PaySurcharge.java @@ -84,6 +84,9 @@ public class PaySurcharge /** 来自附加费配置的命中邮编。本表不保存 */ private String postcodeText; + /** 来自附加费配置的适用国家。本表不保存 */ + private String countryCode; + /** 适用重量下限,空表示不限。首重从 0 开始 */ private BigDecimal weightMin; diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurchargeBind.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurchargeBind.java index cbb9998f..38668aed 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurchargeBind.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurchargeBind.java @@ -50,6 +50,10 @@ public class PrcSurchargeBind private String blockTitle; + private String countryCode; + + private String feeType; + private String scNote; private BigDecimal lengthCm; diff --git a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayCostCalculator.java b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayCostCalculator.java index e606d027..ca5ef54d 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayCostCalculator.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayCostCalculator.java @@ -168,6 +168,7 @@ public final class PayCostCalculator PayCostLine freightLine = line("BASIC_FREIGHT", "基础运费", 0L, freight, currency, freightRemark); result.getFees().add(freightLine); result.setCurrency(currency); + addZoneFeeBands(result, product, band, weight, postcode, currency); addSurcharges(product, weight, length, width, height, postcode, zoneName, bizDate, orderStatus, freight, currency, band.getSectionName(), remoteHits, postcodeOn, zoneOn, countryCode, countryName, result); BigDecimal total = BigDecimal.ZERO; @@ -305,9 +306,18 @@ public final class PayCostCalculator continue; } String rule = fee.getCalcRule() == null || fee.getCalcRule().isBlank() ? PaySurchargeRules.MANUAL : fee.getCalcRule(); + boolean configFee = "附加费配置".equals(blank(fee.getSectionName())); + if (PaySurchargeRules.EXTRA_KG.equals(rule) && configFee) + { + continue; + } + if (!countryAllows(fee, countryCode)) + { + continue; + } List> postcodeRules = prefixRules(product, PaySurchargeRules.POSTCODE); List> zoneRules = prefixRules(product, PaySurchargeRules.ZONE); - if (remoteHits != null && remoteFee(fee) && postcodeRules.isEmpty()) + if (!configFee && remoteHits != null && remoteFee(fee) && postcodeRules.isEmpty()) { String name = blank(fee.getFeeName()); boolean added = false; @@ -349,7 +359,7 @@ public final class PayCostCalculator } boolean configuredZone = PaySurchargeRules.ZONE.equals(rule) && !zoneRules.isEmpty(); boolean postcodeDriven = PaySurchargeRules.POSTCODE.equals(rule) || !blank(fee.getPostcodeParam()).isEmpty(); - if (!configuredZone && !postcodeDriven && zoneName != null && !zoneName.isBlank() && fee.getZoneName() != null && !fee.getZoneName().isBlank() + if (!configFee && !configuredZone && !postcodeDriven && zoneName != null && !zoneName.isBlank() && fee.getZoneName() != null && !fee.getZoneName().isBlank() && !PayZoneMatcher.sameZone(fee.getZoneName(), zoneName)) { continue; @@ -525,7 +535,7 @@ public final class PayCostCalculator } BigDecimal over = weight.subtract(threshold); BigDecimal amount = fee.getAmount().multiply(over).setScale(2, RoundingMode.HALF_UP); - long scId = fee.getSurchargeId() == null ? 0L : fee.getSurchargeId(); + long scId = feeRef(fee); String remark = "超出 " + plain(over) + "kg × " + plain(fee.getAmount()) + " " + blank(fee.getPriceUnit()); fees.add(line("SURCHARGE", blank(fee.getFeeName()), scId, amount, currency, remark)); } @@ -550,6 +560,7 @@ public final class PayCostCalculator for (PaySurcharge fee : product.getSurcharges()) { if (fee == null || !PaySurchargeRules.EXTRA_KG.equals(fee.getCalcRule()) || fee.getAmount() == null + || "附加费配置".equals(blank(fee.getSectionName())) || !blank(fee.getPostcodeParam()).isEmpty()) { continue; @@ -653,6 +664,27 @@ public final class PayCostCalculator return details; } + /** 附加费配置写了国家时,只对这个国家的订单收取。 */ + private static boolean countryAllows(PaySurcharge fee, String orderCountry) + { + String limited = blank(fee.getCountryCode()); + if (limited.isEmpty() || orderCountry == null || orderCountry.isBlank()) + { + return true; + } + return limited.equalsIgnoreCase(orderCountry.trim()); + } + + /** 绑定的附加费用配置编号,导入价卡用自己的行号。 */ + private static long feeRef(PaySurcharge fee) + { + if (fee.getScId() != null) + { + return fee.getScId(); + } + return fee.getSurchargeId() == null ? 0L : fee.getSurchargeId(); + } + private static boolean remoteFee(PaySurcharge fee) { String name = blank(fee.getFeeName()).toLowerCase(Locale.ROOT); @@ -752,7 +784,7 @@ public final class PayCostCalculator return; } BigDecimal amount = fee.getAmount().multiply(weight).setScale(2, RoundingMode.HALF_UP); - long scId = fee.getSurchargeId() == null ? 0L : fee.getSurchargeId(); + long scId = feeRef(fee); fees.add(line("SURCHARGE", blank(fee.getFeeName()), scId, amount, currency, remark + " × " + plain(weight) + "kg")); } @@ -832,10 +864,10 @@ public final class PayCostCalculator { continue; } + long scId = feeRef(fee); BigDecimal amount = fee.getAmount().multiply(steps); String remark = "三边之和 " + plain(sum) + "cm,超出 " + plain(excess) + "cm,每 " + plain(step) + "cm " + plain(fee.getAmount()) + "," + plain(steps) + " 档"; - long scId = fee.getSurchargeId() == null ? 0L : fee.getSurchargeId(); return line("SURCHARGE", blank(fee.getFeeName()), scId, amount, currency, remark); } return null; @@ -890,7 +922,7 @@ public final class PayCostCalculator return null; } } - long scId = fee.getSurchargeId() == null ? 0L : fee.getSurchargeId(); + long scId = feeRef(fee); return line("SURCHARGE", blank(fee.getFeeName()), scId, amount, currency, remark); } @@ -918,6 +950,75 @@ public final class PayCostCalculator return true; } + /** 偏远附加费、额外线路运输费写在重量段里,不拿来当基础运费。 */ + private static boolean zoneFeeBand(PayWeightBand band) + { + String name = (blank(band.getChargeName()) + " " + blank(band.getSectionName())).toLowerCase(Locale.ROOT); + return name.contains("偏远") || name.contains("额外") || name.contains("line-haul") || name.contains("linehaul") || name.contains("运输费"); + } + + /** 和首重同一地区的线路费直接加;带邮编前缀的偏远费按邮编加。超出首重再加该费用自己的续重价。 */ + private static void addZoneFeeBands(PayOrderCostResult result, PayProduct product, PayWeightBand freight, BigDecimal weight, + String postcode, String currency) + { + if (product.getWeightBands() == null || freight == null) + { + return; + } + for (PayWeightBand band : product.getWeightBands()) + { + if (band == null || band.getPrice() == null || !zoneFeeBand(band) || !zoneFeeHits(band, freight, postcode)) + { + continue; + } + String name = blank(band.getChargeName()).isEmpty() ? blank(band.getSectionName()) : band.getChargeName(); + long bandId = band.getBandId() == null ? 0L : band.getBandId(); + result.getFees().add(line("SURCHARGE", name, bandId, band.getPrice(), currency, + blank(band.getZoneName()).replace('\n', ' ') + " " + blank(band.getWeightLabel()))); + addZoneFeeExtra(result, product, band, weight, currency, name); + } + } + + private static boolean zoneFeeHits(PayWeightBand band, PayWeightBand freight, String postcode) + { + String prefixes = PaySurchargeRules.remotePrefixes(band.getZoneName()); + if (!prefixes.isEmpty()) + { + return PaySurchargeRules.matchesPostcode(prefixes, postcode); + } + return PayZoneMatcher.sameZone(band.getZoneName(), freight.getZoneName()); + } + + private static void addZoneFeeExtra(PayOrderCostResult result, PayProduct product, PayWeightBand band, BigDecimal weight, + String currency, String name) + { + if (weight == null || band.getWeightMax() == null || weight.compareTo(band.getWeightMax()) <= 0 || product.getSurcharges() == null) + { + return; + } + for (PaySurcharge fee : product.getSurcharges()) + { + if (fee == null || fee.getAmount() == null || !PaySurchargeRules.EXTRA_KG.equals(fee.getCalcRule())) + { + continue; + } + if (!PayZoneMatcher.sameZone(fee.getZoneName(), band.getZoneName())) + { + continue; + } + if (!sameSection(fee.getSectionName(), band.getSectionName()) && !sameSection(fee.getSectionName(), band.getChargeName())) + { + continue; + } + BigDecimal over = weight.subtract(band.getWeightMax()); + BigDecimal amount = fee.getAmount().multiply(over).setScale(2, RoundingMode.HALF_UP); + long scId = feeRef(fee); + result.getFees().add(line("SURCHARGE", name, scId, amount, currency, + "超出 " + plain(over) + "kg × " + plain(fee.getAmount()) + " " + blank(fee.getPriceUnit()))); + return; + } + } + private static List usableBands(List bands) { List usable = new ArrayList<>(); @@ -927,7 +1028,7 @@ public final class PayCostCalculator } for (PayWeightBand band : bands) { - if (band != null && band.getPrice() != null && band.getWeightMin() != null && band.getWeightMax() != null) + if (band != null && band.getPrice() != null && band.getWeightMin() != null && band.getWeightMax() != null && !zoneFeeBand(band)) { usable.add(band); } diff --git a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayOrderFeeCalculator.java b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayOrderFeeCalculator.java index a24de46f..23d7b615 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayOrderFeeCalculator.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayOrderFeeCalculator.java @@ -65,10 +65,10 @@ public class PayOrderFeeCalculator PayProduct product = payProductService.selectPriceForDate(channel.getId(), priceDate); BigDecimal weight = chargeWeight(bill); Integer orderStatus = orderStatus(bill, ext); - List linked = linkedGroups(product); + List linked = linkedGroups(product, channel); String zoneName = resolveZone(channel, product, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), linked); applyCurrentSurcharge(channel.getId(), product); - List remoteHits = remoteHits(linked, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName()); + List remoteHits = remoteHits(linked, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), channel); PayOrderCostResult result = PayCostCalculator.calculate(product, weight, bill.getPkgLength(), bill.getPkgWidth(), bill.getPkgHeight(), bill.getDestPostcode(), zoneName, priceDate, orderStatus, remoteHits, true, true, bill.getCountryCode(), bill.getCountryName()); @@ -180,7 +180,7 @@ public class PayOrderFeeCalculator } /** - * 运费仍按订单日期取版本。附加费只取该价卡产品已绑定且启用的附加费配置。 + * 运费按订单日期的重量段。附加费取已绑定的配置,超重续收只用价卡上按分区写的续重单价。 * * @param channelId 渠道 ID * @param priced 订单日期已经命中的价卡,方法会改写它的附加费 @@ -200,7 +200,8 @@ public class PayOrderFeeCalculator { // 今天没有生效版本时,改查订单日期命中的那一版有没有绑定 } - priced.setSurcharges(payProductService.boundSurcharges(source)); + priced.setSurcharges(PaySurchargeRules.surchargesForCalc(priced.getSurcharges(), + payProductService.boundSurcharges(source))); } /** @@ -209,7 +210,7 @@ public class PayOrderFeeCalculator * @param product 当前价卡版本 * @return 名称能对上的邮编组,没有时为空列表 */ - private List linkedGroups(PayProduct product) + private List linkedGroups(PayProduct product, ServiceChannel channel) { List names = new ArrayList<>(); addName(names, product.getProductName()); @@ -221,7 +222,7 @@ public class PayOrderFeeCalculator return new ArrayList<>(); } List found = payPostcodeMapper.selectGroupsForProduct(names); - return found == null ? new ArrayList<>() : found; + return PayPostcodeBooks.ownChannel(found, channel.getChannelName(), channel.getChannelCode()); } /** @@ -253,7 +254,8 @@ public class PayOrderFeeCalculator * @param countryName 目的国名称 * @return 命中的偏远分区;产品有名单但没命中时返回空列表 */ - private List remoteHits(List linked, String postcode, String countryCode, String countryName) + private List remoteHits(List linked, String postcode, String countryCode, String countryName, + ServiceChannel channel) { boolean productBook = false; for (PayPostcodeGroup group : linked) @@ -272,8 +274,10 @@ public class PayOrderFeeCalculator { return null; } - List countryGroups = payPostcodeMapper.selectRemoteGroupsByCountry(countryCode, countryName); - if (countryGroups == null || countryGroups.isEmpty()) + List countryGroups = PayPostcodeBooks.ownChannel( + payPostcodeMapper.selectRemoteGroupsByCountry(countryCode, countryName), + channel.getChannelName(), channel.getChannelCode()); + if (countryGroups.isEmpty()) { return null; } @@ -362,6 +366,7 @@ public class PayOrderFeeCalculator groups.add(group); } } + groups = PayPostcodeBooks.ownChannel(groups, channel.getChannelName(), channel.getChannelCode()); if (groups.isEmpty()) { PayZoneMatcher.Decision mainland = PayZoneMatcher.resolve(zoneNames, new ArrayList<>(), postcode); diff --git a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayPostcodeBooks.java b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayPostcodeBooks.java new file mode 100644 index 00000000..5c9da2d9 --- /dev/null +++ b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayPostcodeBooks.java @@ -0,0 +1,108 @@ +package com.bms.price.pay; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import com.bms.price.domain.PayPostcodeGroup; + +/** 同一国家下,只保留和订单渠道对得上的邮编配置。 */ +public final class PayPostcodeBooks +{ + private PayPostcodeBooks() + { + } + + /** + * 渠道名称或编码对上的配置留下。没有写渠道的旧配置,只在没有任何对上的渠道时才使用。 + * + * @param groups 已经按产品或国家查出的邮编组 + * @param channelName 订单渠道名称 + * @param channelCode 订单渠道编码 + * @return 这个渠道自己的邮编组 + */ + public static List ownChannel(List groups, String channelName, String channelCode) + { + List found = groups == null ? new ArrayList<>() : groups; + String name = norm(channelName); + String code = norm(channelCode); + if (found.isEmpty() || (name.isEmpty() && code.isEmpty())) + { + return found; + } + List matched = new ArrayList<>(); + List blank = new ArrayList<>(); + for (PayPostcodeGroup group : found) + { + if (group == null) + { + continue; + } + String book = norm(group.getChannelName()); + if (book.isEmpty()) + { + blank.add(group); + continue; + } + if (hit(book, name) || hit(book, code)) + { + matched.add(group); + } + } + if (matched.isEmpty()) + { + return blank; + } + return preferLonger(matched, name, code); + } + + /** 订单渠道同时含「evri」和「evri48」时,只留更长的那一个,避免短名称把另一个渠道的分区也带上。 */ + private static List preferLonger(List matched, String name, String code) + { + int best = 0; + for (PayPostcodeGroup group : matched) + { + String book = norm(group.getChannelName()); + if (name.contains(book) || code.contains(book)) + { + best = Math.max(best, book.length()); + } + } + if (best == 0) + { + return matched; + } + List specific = new ArrayList<>(); + for (PayPostcodeGroup group : matched) + { + String book = norm(group.getChannelName()); + if (book.length() == best && (name.contains(book) || code.contains(book))) + { + specific.add(group); + } + } + return specific.isEmpty() ? matched : specific; + } + + private static boolean hit(String book, String channel) + { + if (book.isEmpty() || channel.isEmpty()) + { + return false; + } + if (book.equals(channel)) + { + return true; + } + int shorter = Math.min(book.length(), channel.length()); + return shorter >= 3 && (book.contains(channel) || channel.contains(book)); + } + + private static String norm(String value) + { + if (value == null) + { + return ""; + } + return value.toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9\\u4e00-\\u9fa5]", ""); + } +} diff --git a/bms-back/bms-system/src/main/java/com/bms/price/pay/PaySurchargeRules.java b/bms-back/bms-system/src/main/java/com/bms/price/pay/PaySurchargeRules.java index 307ee039..49fb3fee 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/pay/PaySurchargeRules.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/pay/PaySurchargeRules.java @@ -578,6 +578,63 @@ public final class PaySurchargeRules return matchesWeight(fee == null ? null : fee.getCalcParam(), weight); } + /** + * 计费时使用的附加费。价卡绑定的附加费配置都参与判断,超重续收仍只用价卡上的每公斤续重。 + * + * @param cardFees 订单日期那一版价卡上的费用行 + * @param bound 价卡已绑定且启用的附加费配置 + * @return 绑定配置里除超重续收以外的费用,再加上价卡续重 + */ + public static List surchargesForCalc(List cardFees, List bound) + { + List fees = new ArrayList<>(); + if (bound != null) + { + for (PaySurcharge fee : bound) + { + if (fee != null && EXTRA_KG.equals(fee.getCalcRule())) + { + continue; + } + fees.add(fee); + } + } + if (cardFees == null) + { + return fees; + } + for (PaySurcharge fee : cardFees) + { + if (freightContinuation(fee)) + { + fees.add(fee); + } + } + return fees; + } + + /** 价卡上的每公斤续重。带邮编的超重续收不拿来续运费。 */ + private static boolean freightContinuation(PaySurcharge fee) + { + if (fee == null || !EXTRA_KG.equals(fee.getCalcRule()) || fee.getAmount() == null) + { + return false; + } + if ("附加费配置".equals(fee.getSectionName())) + { + return false; + } + if (extraStartKg(fee) == null) + { + return false; + } + if (fee.getPostcodeParam() != null && !fee.getPostcodeParam().isBlank()) + { + return false; + } + return fee.getPostcodeText() == null || fee.getPostcodeText().isBlank(); + } + /** 续重起始公斤。配置列优先,导入价卡仍从原条件文本读取。 */ public static BigDecimal extraStartKg(PaySurcharge fee) { diff --git a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayWorkbookParser.java b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayWorkbookParser.java index 0097a018..5d94cad6 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayWorkbookParser.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayWorkbookParser.java @@ -1234,7 +1234,7 @@ public class PayWorkbookParser } /** - * 和派送费同一版式,但表头是偏远附加费、额外线路运输费这类费用。按地区和重量记附加费,不进重量段。 + * 和派送费同一版式,但表头是偏远附加费、额外线路运输费。首重记进重量段,每增加 1kg 记该费用的续重价。 */ private int readFeeRateTable(ExcelGrid grid, int header, PayProduct product) { @@ -1322,6 +1322,18 @@ public class PayWorkbookParser priced = true; String feeName = shortCharge(parent[col]); String zone = zoneOf(sub[col], parent[col]).replace('\n', ' ').replaceAll("\\s+", " ").trim(); + if (zoneFeeName(feeName)) + { + if (stepWeight(weight)) + { + addExtraKg(product, feeName, zone, weight, price, firstLimit(product, feeName, zone)); + } + else + { + addZoneFeeBand(product, feeName, zone, weight, price, parent[col]); + } + continue; + } String standard = price.stripTrailingZeros().toPlainString() + " " + feeUnit(parent[col], weight); String desc = country.isBlank() ? weight : country + ";" + weight; if (addSurcharge(product, feeName, feeName, zone, standard.trim(), desc, "")) @@ -1499,6 +1511,13 @@ public class PayWorkbookParser continue; } boolean feeHead = isPriceHead(parent[col]); + if (stepWeight(weight)) + { + String zone = feeHead ? zoneOf(sub[col], parent[col]) : (parent[col].isBlank() ? sub[col] : parent[col]); + String sectionName = blankTo(section, "价格"); + addExtraKg(product, sectionName, zone, weight, price, firstLimit(product, sectionName, zone)); + continue; + } PayWeightBand band = new PayWeightBand(); band.setSectionName(blankTo(section, "价格")); band.setCountryName(country); @@ -2119,18 +2138,19 @@ public class PayWorkbookParser return row; } - /** Kg.ad. 按地区各记一条每公斤续重,不进入重量段。 */ + /** 每增加 1kg、Kg.ad. 记到该重量段的续重价,不再单独占一行重量段。 */ private static void addExtraKg(PayProduct product, String section, String zone, String label, BigDecimal price, BigDecimal threshold) { - BigDecimal from = threshold == null ? BigDecimal.ZERO : threshold; + BigDecimal from = threshold == null ? BigDecimal.ONE : threshold; + String currency = product.getCurrency() == null || product.getCurrency().isBlank() ? "EUR" : product.getCurrency().trim(); PaySurcharge fee = new PaySurcharge(); fee.setSectionName(section); fee.setFeeName("每公斤续重"); fee.setZoneName(zone); - fee.setChargeText(label + " " + price.stripTrailingZeros().toPlainString() + " EUR/KG"); + fee.setChargeText(label + " " + price.stripTrailingZeros().toPlainString() + " " + currency + "/KG"); fee.setAmount(price); - fee.setCurrency("EUR"); - fee.setPriceUnit("EUR/KG"); + fee.setCurrency(currency); + fee.setPriceUnit(currency + "/KG"); fee.setFeeDesc("超过" + from.stripTrailingZeros().toPlainString() + "kg后,按超出的重量每公斤加收"); fee.setChargeTiming("产生时收取"); fee.setCalcRule(PaySurchargeRules.EXTRA_KG); @@ -2139,6 +2159,82 @@ public class PayWorkbookParser product.getSurcharges().add(fee); } + /** 偏远附加费、额外线路运输费的首重,作为重量段里的费用项。 */ + private static void addZoneFeeBand(PayProduct product, String feeName, String zone, String weight, BigDecimal price, String head) + { + PayWeightBand band = new PayWeightBand(); + band.setSectionName(feeName); + band.setZoneName(zone); + band.setWeightLabel(weight); + BigDecimal[] bounds = PayTexts.weightBounds(weight); + band.setWeightMin(bounds[0]); + band.setWeightMax(bounds[1]); + band.setChargeName(feeName); + band.setPrice(price); + band.setPriceUnit(feeUnit(head, weight)); + band.setSortNo(product.getWeightBands().size() + 1); + product.getWeightBands().add(band); + } + + /** 同一费用、同一地区里,续重从已读到的首重上限开始。 */ + private static BigDecimal firstLimit(PayProduct product, String section, String zone) + { + BigDecimal found = null; + if (product.getWeightBands() != null) + { + for (PayWeightBand band : product.getWeightBands()) + { + if (band == null || band.getWeightMax() == null || !sameSectionText(band.getSectionName(), section) || !sameZoneText(band.getZoneName(), zone)) + { + continue; + } + found = band.getWeightMax(); + } + } + return found == null ? BigDecimal.ONE : found; + } + + private static boolean stepWeight(String weight) + { + if (weight == null) + { + return false; + } + String compact = weight.replace(" ", "").toLowerCase(Locale.ROOT); + return compact.contains("每增加") || compact.contains("additionalkg") || compact.contains("kg.ad"); + } + + /** 偏远、额外线路这类和首重同表的费用,要进重量段。超重、超尺寸仍走附加费。 */ + private static boolean zoneFeeName(String name) + { + if (name == null) + { + return false; + } + String text = name.toLowerCase(Locale.ROOT); + return text.contains("偏远") || text.contains("额外") || text.contains("line-haul") || text.contains("linehaul") || text.contains("运输费"); + } + + private static boolean sameSectionText(String left, String right) + { + if (left == null || left.isBlank() || right == null || right.isBlank()) + { + return true; + } + return left.trim().equals(right.trim()); + } + + private static boolean sameZoneText(String left, String right) + { + boolean leftBlank = left == null || left.isBlank(); + boolean rightBlank = right == null || right.isBlank(); + if (leftBlank && rightBlank) + { + return true; + } + return PayZoneMatcher.sameZone(left, right); + } + private static boolean isKgStepHeader(ExcelGrid grid, int row) { int names = 0; diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/IPayPostcodeService.java b/bms-back/bms-system/src/main/java/com/bms/price/service/IPayPostcodeService.java index 56c72724..b5729135 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/IPayPostcodeService.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/IPayPostcodeService.java @@ -10,7 +10,7 @@ public interface IPayPostcodeService { List selectGroupList(PayPostcodeGroup query); - /** 每个国家一行:邮编属性、服务类型、销售产品、渠道、分区数、邮编总数、导入时间 */ + /** 每个国家一行:渠道多个时用顿号分隔。分区在抽屉里按渠道分开 */ List selectCountryList(PayPostcodeGroup query); /** 一个国家下面的分区,同一分区名只出现一行 */ diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java index 38a2df01..a487f52d 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java @@ -28,6 +28,7 @@ import com.bms.price.mapper.PrcOrderBillMapper; import com.bms.price.mapper.PrcPayBillFeeMapper; import com.bms.price.mapper.PrcPayBillMapper; import com.bms.price.pay.PayCostCalculator; +import com.bms.price.pay.PayPostcodeBooks; import com.bms.price.pay.PayFeeMoney; import com.bms.price.pay.PaySettleSupport; import com.bms.price.pay.PayRemoteBook; @@ -133,10 +134,10 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService PayProduct product = payProductService.selectPriceForDate(channel.getId(), bizDate); BigDecimal weight = firstPositive(bill.getChargeWeight(), bill.getWeight(), bill.getActualWeight(), bill.getReceiveWeight()); Integer orderStatus = bill.getOrderStatus() != null ? bill.getOrderStatus() : (ext == null ? null : ext.getOrderStatus()); - List linked = linkedGroups(product); + List linked = linkedGroups(product, channel); String zoneName = resolveZone(channel, product, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), linked); applyCurrentSurcharge(channel.getId(), product); - List remoteHits = remoteHits(linked, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName()); + List remoteHits = remoteHits(linked, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), channel); PayOrderCostResult result = PayCostCalculator.calculate(product, weight, bill.getPkgLength(), bill.getPkgWidth(), bill.getPkgHeight(), bill.getDestPostcode(), zoneName, bizDate, orderStatus, remoteHits, true, true, bill.getCountryCode(), bill.getCountryName()); @@ -216,7 +217,7 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService * @param product 当前价卡版本 * @return 名称能对上的邮编组,没有时为空列表 */ - /** 运费仍按订单日期取版本。附加费只取该价卡产品已绑定且启用的附加费配置。 */ + /** 运费按订单日期的重量段。附加费取已绑定的配置,超重续收只用价卡上按分区写的续重单价。 */ private void applyCurrentSurcharge(String channelId, PayProduct priced) { PayProduct source = priced; @@ -232,10 +233,11 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService { // 今天没有生效版本时,改查订单日期命中的那一版有没有绑定 } - priced.setSurcharges(payProductService.boundSurcharges(source)); + priced.setSurcharges(PaySurchargeRules.surchargesForCalc(priced.getSurcharges(), + payProductService.boundSurcharges(source))); } - private List linkedGroups(PayProduct product) + private List linkedGroups(PayProduct product, ServiceChannel channel) { List names = new ArrayList<>(); addName(names, product.getProductName()); @@ -247,7 +249,7 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService return new ArrayList<>(); } List found = payPostcodeMapper.selectGroupsForProduct(names); - return found == null ? new ArrayList<>() : found; + return PayPostcodeBooks.ownChannel(found, channel.getChannelName(), channel.getChannelCode()); } /** @@ -279,7 +281,8 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService * @param countryName 目的国名称 * @return 命中的偏远分区;产品有名单但没命中时返回空列表 */ - private List remoteHits(List linked, String postcode, String countryCode, String countryName) + private List remoteHits(List linked, String postcode, String countryCode, String countryName, + ServiceChannel channel) { boolean productBook = false; for (PayPostcodeGroup group : linked) @@ -298,8 +301,10 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService { return null; } - List countryGroups = payPostcodeMapper.selectRemoteGroupsByCountry(countryCode, countryName); - if (countryGroups == null || countryGroups.isEmpty()) + List countryGroups = PayPostcodeBooks.ownChannel( + payPostcodeMapper.selectRemoteGroupsByCountry(countryCode, countryName), + channel.getChannelName(), channel.getChannelCode()); + if (countryGroups.isEmpty()) { return null; } @@ -380,6 +385,7 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService groups.add(group); } } + groups = PayPostcodeBooks.ownChannel(groups, channel.getChannelName(), channel.getChannelCode()); if (groups.isEmpty()) { PayZoneMatcher.Decision mainland = PayZoneMatcher.resolve(zoneNames, new ArrayList<>(), postcode); diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayPostcodeServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayPostcodeServiceImpl.java index 86e0e59a..6e5f2621 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayPostcodeServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayPostcodeServiceImpl.java @@ -46,6 +46,7 @@ public class PayPostcodeServiceImpl implements IPayPostcodeService public List selectZoneList(PayPostcodeGroup query) { requireCountry(query); + query.setAllChannels(Boolean.TRUE); return payPostcodeMapper.selectZoneList(query); } @@ -74,7 +75,7 @@ public class PayPostcodeServiceImpl implements IPayPostcodeService if ("REMOTE".equals(row.getCoverage())) { row.setSheetName("手工偏远"); - row.setChannelName(""); + row.setChannelName(firstText(zone.getChannelName(), sample == null ? "" : sample.getChannelName())); row.setProductName(""); row.setQuoteSheet(""); row.setFeeName("偏远"); @@ -82,7 +83,7 @@ public class PayPostcodeServiceImpl implements IPayPostcodeService else { row.setSheetName(sample != null && !trimToEmpty(sample.getSheetName()).isEmpty() ? sample.getSheetName() : zoneName); - row.setChannelName(sample == null ? "" : trimToEmpty(sample.getChannelName())); + row.setChannelName(firstText(zone.getChannelName(), sample == null ? "" : sample.getChannelName())); row.setProductName(sample == null ? "" : trimToEmpty(sample.getProductName())); row.setQuoteSheet(sample == null ? "" : trimToEmpty(sample.getQuoteSheet())); row.setFeeName(""); @@ -152,6 +153,7 @@ public class PayPostcodeServiceImpl implements IPayPostcodeService public int deleteCountry(PayPostcodeGroup country) { requireCountry(country); + country.setAllChannels(Boolean.TRUE); List ids = payPostcodeMapper.selectGroupIdsByCountry(country); if (ids == null || ids.isEmpty()) { @@ -427,6 +429,7 @@ public class PayPostcodeServiceImpl implements IPayPostcodeService PayPostcodeGroup country = new PayPostcodeGroup(); country.setCountryCode(line.getCountryCode()); country.setCountryName(line.getCountryName()); + country.setChannelName(line.getChannelName()); requireCountry(country); return country; } diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayProductServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayProductServiceImpl.java index b0616b92..fb590c55 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayProductServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayProductServiceImpl.java @@ -1045,13 +1045,27 @@ public class PayProductServiceImpl implements IPayProductService { return fees; } - for (PrcSurchargeBind bind : surchargeBindMapper.selectByProduct(product.getProductId(), bindType(product))) + String type = bindType(product); + fees.addAll(enabledBinds(product.getProductId(), type, product.getCurrency())); + Long originId = product.getOriginId(); + if (fees.isEmpty() && originId != null && !originId.equals(product.getProductId())) + { + fees.addAll(enabledBinds(originId, type, product.getCurrency())); + } + return fees; + } + + /** 这一版价卡上已启用的附加费配置。计费方式不限,订单计算时再按各自条件判断。 */ + private List enabledBinds(Long productId, String type, String currency) + { + List fees = new ArrayList<>(); + for (PrcSurchargeBind bind : surchargeBindMapper.selectByProduct(productId, type)) { if (bind == null || bind.getSsCode() == null || !"on".equalsIgnoreCase(bind.getSsCode())) { continue; } - fees.add(toBoundFee(bind, product.getCurrency())); + fees.add(toBoundFee(bind, currency)); } return fees; } @@ -1198,6 +1212,7 @@ public class PayProductServiceImpl implements IPayProductService fee.setOverWeightKg(bind.getOverWeightKg()); fee.setExtraWeightKg(bind.getExtraWeightKg()); fee.setPostcodeText(bind.getPostcodeText()); + fee.setCountryCode(bind.getCountryCode()); PrcSurcharge config = new PrcSurcharge(); config.setChargeType(bind.getChargeType()); config.setLengthCm(bind.getLengthCm()); diff --git a/bms-back/bms-system/src/main/resources/mapper/price/PayPostcodeMapper.xml b/bms-back/bms-system/src/main/resources/mapper/price/PayPostcodeMapper.xml index caf87e39..106034a7 100644 --- a/bms-back/bms-system/src/main/resources/mapper/price/PayPostcodeMapper.xml +++ b/bms-back/bms-system/src/main/resources/mapper/price/PayPostcodeMapper.xml @@ -60,6 +60,31 @@ and g.country_name = #{countryName} + + + + + + + and lower(trim(g.channel_name)) = lower(trim(#{channelName})) + + + and (g.channel_name is null or trim(g.channel_name) = '') + + + + + + + + + and lower(trim(g.channel_name)) = lower(trim(#{channelName})) + + + and (g.channel_name is null or trim(g.channel_name) = '') + + + @@ -79,19 +104,23 @@ group_concat(distinct nullif(trim(g.service_type), '') order by g.service_type separator '、') as serviceType, group_concat(distinct nullif(trim(g.product_name), '') order by g.product_name separator '、') as productName, group_concat(distinct nullif(trim(g.channel_name), '') order by g.channel_name separator '、') as channelName, - count(distinct - case - when l.line_id is not null then - case - when nullif(trim(l.zone_name), '') is not null then trim(l.zone_name) - when nullif(trim(l.region_name), '') is not null then trim(l.region_name) - when nullif(trim(g.block_title), '') is not null then trim(g.block_title) - else '未分区' - end - when nullif(trim(g.block_title), '') is not null then trim(g.block_title) - else null - end - ) as zoneCount, + count(distinct case + when l.line_id is null and nullif(trim(g.block_title), '') is null then null + else concat( + case + when l.line_id is not null then + case + when nullif(trim(l.zone_name), '') is not null then trim(l.zone_name) + when nullif(trim(l.region_name), '') is not null then trim(l.region_name) + when nullif(trim(g.block_title), '') is not null then trim(g.block_title) + else '未分区' + end + else trim(g.block_title) + end, + '||', + lower(ifnull(trim(g.channel_name), '')) + ) + end) as zoneCount, count(l.line_id) as lineCount, max(g.create_time) as createTime from pay_postcode_group g @@ -125,9 +154,10 @@ group_concat(distinct nullif(trim(t.coverage), '') order by t.coverage separator '、') as coverage, count(t.line_id) as lineCount, max(t.country_name) as countryName, - max(t.country_code) as countryCode + max(t.country_code) as countryCode, + max(t.channel_name) as channelName from ( - select g.group_id, g.coverage, g.country_name, g.country_code, l.line_id, + select g.group_id, g.coverage, g.country_name, g.country_code, g.channel_name, l.line_id, case when l.line_id is null then nullif(trim(g.block_title), '') else @@ -145,8 +175,12 @@ ) t where t.zone_name is not null and t.zone_name <> '' - group by t.zone_name - order by t.zone_name asc + group by t.zone_name, + case + when nullif(trim(t.channel_name), '') is not null then lower(trim(t.channel_name)) + else '' + end + order by t.zone_name asc, max(t.channel_name) asc