evri渠道附加费计算调整,应付列表查询性能优化
This commit is contained in:
@@ -169,6 +169,20 @@ class PayCostCalculatorTest
|
||||
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())));
|
||||
|
||||
PaySurcharge volume = fee(17L, "体积附加费", "6", "EUR", "SIZE", null);
|
||||
volume.setSectionName("附加费配置");
|
||||
volume.setSizeType("VOLUME");
|
||||
volume.setVolumeM3(new BigDecimal("0.01"));
|
||||
product.setSurcharges(List.of(fuel, volume));
|
||||
PayOrderCostResult underVolume = PayCostCalculator.calculate(product, new BigDecimal("1"),
|
||||
new BigDecimal("20"), new BigDecimal("20"), new BigDecimal("5"), "28001", "马德里", null, 1);
|
||||
assertTrue(underVolume.getFees().stream().noneMatch(row -> "体积附加费".equals(row.getFeeName())));
|
||||
PayOrderCostResult overVolume = PayCostCalculator.calculate(product, new BigDecimal("1"),
|
||||
new BigDecimal("50"), new BigDecimal("40"), new BigDecimal("20"), "28001", "马德里", null, 1);
|
||||
assertTrue(hasFee(overVolume, "体积附加费", "6"));
|
||||
assertTrue(overVolume.getFees().stream().anyMatch(row -> "体积附加费".equals(row.getFeeName())
|
||||
&& row.getRemark() != null && row.getRemark().contains("体积超过")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -211,13 +225,15 @@ class PayCostCalculatorTest
|
||||
}
|
||||
|
||||
@Test
|
||||
void oversizeUsesTheHigherPercentWhenBothTiersMatch()
|
||||
void oversizeAddsEveryMatchingTierOfTheSameName()
|
||||
{
|
||||
PayOrderCostResult result = PayCostCalculator.calculate(spainOneZone(), new BigDecimal("1"),
|
||||
new BigDecimal("130"), new BigDecimal("50"), new BigDecimal("40"), "28001", null, 1);
|
||||
assertTrue(hasFee(result, "基础运费", "2.27"));
|
||||
assertTrue(hasFee(result, "特大包裹收费", "0.79"));
|
||||
assertTrue(hasFee(result, "特大包裹收费", "1.59"));
|
||||
assertEquals(1, result.getFees().stream().filter(fee -> "特大包裹收费".equals(fee.getFeeName())).count());
|
||||
assertEquals(2, result.getFees().stream().filter(fee -> "特大包裹收费".equals(fee.getFeeName())).count());
|
||||
assertEquals(new BigDecimal("4.65"), result.getPayTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -510,6 +526,59 @@ class PayCostCalculatorTest
|
||||
assertTrue(PayRemoteBook.hits(List.of(delivery), List.of(line(42L, "28001")), "28001", "ES", "西班牙") == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void evriFeePostcodeAddsTheMatchingSurcharge()
|
||||
{
|
||||
assertTrue(PaySurchargeRules.matchesFeePostcode("BS1 1BT", "BS1 1BT"));
|
||||
assertTrue(PaySurchargeRules.matchesFeePostcode("BS1 1BT", "bs11bt"));
|
||||
assertTrue(PaySurchargeRules.matchesFeePostcode("BS1", "BS1 1BT"));
|
||||
assertTrue(PaySurchargeRules.matchesFeePostcode("BS1 1BT", "BS1"));
|
||||
assertFalse(PaySurchargeRules.matchesFeePostcode("BS1 1BT", "SW1A 1AA"));
|
||||
assertFalse(PaySurchargeRules.matchesFeePostcode("B", "BS1 1BT"));
|
||||
|
||||
PayProduct product = new PayProduct();
|
||||
product.setProductName("Evri 48H");
|
||||
product.setCurrency("GBP");
|
||||
product.setWeightBands(new ArrayList<>(List.of(band("0", "1", "1.51", "UK Mainland"))));
|
||||
PaySurcharge air = fee(9L, "空气减排附加费", "0.45", "GBP", "FEE_POSTCODE", null);
|
||||
air.setSectionName("附加费配置");
|
||||
air.setScId(9L);
|
||||
product.setSurcharges(List.of(air));
|
||||
List<PayRemoteBook.Hit> hits = List.of(new PayRemoteBook.Hit("空气减排附加费", null, "Bristol", "Bristol"));
|
||||
PayOrderCostResult hit = PayCostCalculator.calculate(product, new BigDecimal("0.5"),
|
||||
null, null, null, "BS1 1BT", "UK Mainland", null, 1, null, true, true, "GB", "英国", hits);
|
||||
assertTrue(hasFee(hit, "基础运费", "1.51"));
|
||||
assertTrue(hasFee(hit, "空气减排附加费", "0.45"));
|
||||
assertEquals(new BigDecimal("1.96"), hit.getPayTotal());
|
||||
|
||||
PayOrderCostResult miss = PayCostCalculator.calculate(product, new BigDecimal("0.5"),
|
||||
null, null, null, "SW1A 1AA", "UK Mainland", null, 1, null, true, true, "GB", "英国", List.of());
|
||||
assertTrue(miss.getFees().stream().noneMatch(row -> "空气减排附加费".equals(row.getFeeName())));
|
||||
|
||||
List<PayRemoteBook.Hit> other = List.of(new PayRemoteBook.Hit("燃油附加费", null, "", ""));
|
||||
PayOrderCostResult named = PayCostCalculator.calculate(product, new BigDecimal("0.5"),
|
||||
null, null, null, "BS1 1BT", "UK Mainland", null, 1, null, true, true, "GB", "英国", other);
|
||||
assertTrue(named.getFees().stream().noneMatch(row -> "空气减排附加费".equals(row.getFeeName())));
|
||||
|
||||
PayPostcodeLine stored = new PayPostcodeLine();
|
||||
stored.setChannelName("Evri 48H");
|
||||
stored.setFeeName("空气减排附加费");
|
||||
stored.setPostcode("BS1 3LT");
|
||||
List<PayRemoteBook.Hit> channelHits = PayRemoteBook.surchargeHits(List.of(stored), "BS1 3LT", "UBI英国EVRi普", "UBI_GBPEVRI", "Evri 48H");
|
||||
assertEquals(1, channelHits.size());
|
||||
assertEquals("空气减排附加费", channelHits.get(0).getFeeName());
|
||||
|
||||
PaySurcharge configured = fee(203L, "空气减排费_Evri_48H", "0.45", "EUR", "POSTCODE", null);
|
||||
configured.setSectionName("附加费配置");
|
||||
configured.setScId(203L);
|
||||
configured.setPostcodeText("BS1");
|
||||
product.setSurcharges(List.of(configured));
|
||||
PayOrderCostResult order = PayCostCalculator.calculate(product, new BigDecimal("0.5"),
|
||||
null, null, null, "BS1 3LT", "UK Mainland", null, 1, null, true, true, "GB", "英国", channelHits);
|
||||
assertTrue(order.getFees().stream().anyMatch(row -> "空气减排费_Evri_48H".equals(row.getFeeName())
|
||||
&& row.getAmount().compareTo(new BigDecimal("0.45")) == 0 && "EUR".equals(row.getCurrency())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void severalZonesCannotBePricedFromTheOrder()
|
||||
{
|
||||
|
||||
@@ -2,11 +2,13 @@ package com.bms.price.pay;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import com.bms.price.domain.PayPostcodeGroup;
|
||||
@@ -32,7 +34,7 @@ class PayPostcodeImporterTest
|
||||
assertEquals("Royal Mail", remote195.getChannelName());
|
||||
assertEquals("Royal Mail", remote115.getChannelName());
|
||||
assertEquals("EVRI", evri.getChannelName());
|
||||
assertEquals("EVRI", air.getChannelName());
|
||||
assertEquals("Evri 48H", air.getChannelName());
|
||||
assertEquals(15, remote195.getLineCount());
|
||||
assertTrue(remote195.getLines().stream().anyMatch(line -> "PA60-78".equals(line.getPostcode())));
|
||||
assertTrue(remote195.getLines().stream().anyMatch(line -> "PA80".equals(line.getPostcode())));
|
||||
@@ -47,7 +49,8 @@ class PayPostcodeImporterTest
|
||||
assertEquals("REMOTE", remote195.getCoverage());
|
||||
assertEquals("REMOTE", remote115.getCoverage());
|
||||
assertEquals("REMOTE", evri.getCoverage());
|
||||
assertEquals("", air.getCoverage());
|
||||
assertEquals("SURCHARGE", air.getCoverage());
|
||||
assertTrue(air.getLines().stream().anyMatch(line -> "BS1 1BT".equals(line.getPostcode()) && "Bristol".equals(line.getZoneName())));
|
||||
assertTrue(groups.stream().noneMatch(item -> "Evri 48H".equals(item.getSheetName())));
|
||||
|
||||
PayPostcodeGroup italy = groups.stream().filter(item -> "iMile邮编分区".equals(item.getSheetName()) && "IT".equals(item.getCountryCode())).findFirst().orElseThrow();
|
||||
@@ -80,7 +83,7 @@ class PayPostcodeImporterTest
|
||||
assertEquals("REACH", PayPostcodeImporter.coverageOf("法国GOFO可达邮编", "", ""));
|
||||
assertEquals("UNREACH", PayPostcodeImporter.coverageOf("德国DPD挂号(DEDPD)不可达邮编", "", ""));
|
||||
assertEquals("REMOTE", PayPostcodeImporter.coverageOf("evri 偏远", "", ""));
|
||||
assertEquals("", PayPostcodeImporter.coverageOf("英国附加费", "EVRI偏远&空气减排地区附加费", "空气减排附加费"));
|
||||
assertEquals("SURCHARGE", PayPostcodeImporter.coverageOf("英国附加费", "EVRI偏远&空气减排地区附加费", "空气减排附加费"));
|
||||
List<PayPostcodeImporter.PostcodeToken> kept = PayPostcodeImporter.expandPostcode("KA27-28");
|
||||
assertEquals("KA27-28", kept.get(0).postcode);
|
||||
assertEquals("", kept.get(0).end);
|
||||
@@ -89,6 +92,75 @@ class PayPostcodeImporterTest
|
||||
assertEquals("57039", range.get(0).end);
|
||||
}
|
||||
|
||||
@Test
|
||||
void evriAirReductionReadsAsSurchargeOnEvri48h() throws Exception
|
||||
{
|
||||
List<PayPostcodeGroup> groups = importer.parse(ukFeeBook(), "英国附加费.xlsx");
|
||||
PayPostcodeGroup royal = one(groups.stream().filter(item -> "FEE".equals(item.getConfigKind())).toList(), "偏远附加费", "1.95GBP/票");
|
||||
assertEquals("Royal Mail", royal.getChannelName());
|
||||
assertEquals("REMOTE", royal.getCoverage());
|
||||
assertTrue(royal.getLines().stream().anyMatch(line -> "IV".equals(line.getPostcode())));
|
||||
assertTrue(royal.getLines().stream().anyMatch(line -> "HS".equals(line.getPostcode())));
|
||||
|
||||
PayPostcodeGroup evri = one(groups.stream().filter(item -> "FEE".equals(item.getConfigKind())).toList(), "偏远附加费", "5.95GBP/票");
|
||||
assertEquals("EVRI", evri.getChannelName());
|
||||
assertEquals("REMOTE", evri.getCoverage());
|
||||
assertTrue(evri.getLines().stream().anyMatch(line -> "GY".equals(line.getPostcode()) && "GY*".equals(line.getPostcodeRaw())));
|
||||
assertTrue(evri.getLines().stream().noneMatch(line -> "BS1 1BT".equals(line.getPostcode())));
|
||||
|
||||
PayPostcodeGroup air = one(groups.stream().filter(item -> "FEE".equals(item.getConfigKind())).toList(), "空气减排附加费", "0.45GBP/票");
|
||||
assertEquals("Evri 48H", air.getChannelName());
|
||||
assertEquals("SURCHARGE", air.getCoverage());
|
||||
assertEquals("英国", air.getCountryName());
|
||||
assertEquals(2, air.getLineCount());
|
||||
assertTrue(air.getLines().stream().anyMatch(line -> "BS1 1BT".equals(line.getPostcode()) && "Bristol".equals(line.getZoneName()) && "Bristol".equals(line.getRegionName())));
|
||||
assertTrue(air.getLines().stream().anyMatch(line -> "BS1 1BU".equals(line.getPostcode()) && "Bristol".equals(line.getZoneName())));
|
||||
}
|
||||
|
||||
private static byte[] ukFeeBook() throws Exception
|
||||
{
|
||||
try (XSSFWorkbook book = new XSSFWorkbook(); ByteArrayOutputStream out = new ByteArrayOutputStream())
|
||||
{
|
||||
var sheet = book.createSheet("英国附加费");
|
||||
var title = sheet.createRow(0);
|
||||
title.createCell(0).setCellValue("Royal Mail偏远地区附加费");
|
||||
title.createCell(4).setCellValue("EVRI偏远&空气减排地区附加费");
|
||||
var head = sheet.createRow(1);
|
||||
String[] headers = {
|
||||
"偏远地区(英文)", "邮编开头", "偏远附加费", "",
|
||||
"偏远地区(英文)", "偏远地区(中文)", "邮编开头", "偏远附加费",
|
||||
"空气减排地区", "空气减排地区邮编", "空气减排附加费"
|
||||
};
|
||||
for (int i = 0; i < headers.length; i++)
|
||||
{
|
||||
if (!headers[i].isEmpty())
|
||||
{
|
||||
head.createCell(i).setCellValue(headers[i]);
|
||||
}
|
||||
}
|
||||
var first = sheet.createRow(2);
|
||||
first.createCell(0).setCellValue("The Highlands");
|
||||
first.createCell(1).setCellValue("IV");
|
||||
first.createCell(2).setCellValue("1.95GBP/票");
|
||||
first.createCell(4).setCellValue("Channel Islands");
|
||||
first.createCell(5).setCellValue("海峡群岛(含锡利岛)");
|
||||
first.createCell(6).setCellValue("GY*");
|
||||
first.createCell(7).setCellValue("5.95GBP/票");
|
||||
first.createCell(8).setCellValue("Bristol");
|
||||
first.createCell(9).setCellValue("BS1 1BT");
|
||||
first.createCell(10).setCellValue("0.45GBP/票");
|
||||
var second = sheet.createRow(3);
|
||||
second.createCell(1).setCellValue("HS");
|
||||
second.createCell(2).setCellValue("1.95GBP/票");
|
||||
second.createCell(6).setCellValue("JE*");
|
||||
second.createCell(7).setCellValue("5.95GBP/票");
|
||||
second.createCell(9).setCellValue("BS1 1BU");
|
||||
second.createCell(10).setCellValue("0.45GBP/票");
|
||||
book.write(out);
|
||||
return out.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("依赖开发机 D:/应付供应商 下的价卡文件,未随项目提供")
|
||||
void reachableUnreachableAndRemoteKeepTheirOwnCountry() throws Exception
|
||||
|
||||
Reference in New Issue
Block a user