应付邮编调整和订单应付计费的附加费调整
This commit is contained in:
@@ -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邮编开头"));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user