Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS into test
This commit is contained in:
@@ -28,12 +28,18 @@ public class PayPostcodeGroup extends BaseEntity
|
||||
/** ZONE 邮编分区,FEE 附加费 */
|
||||
private String configKind;
|
||||
|
||||
/** REACH 可达,UNREACH 不可达,REMOTE 偏远。普通分区为空 */
|
||||
/** REACH 可达,UNREACH 不可达,REMOTE 偏远,SURCHARGE 附加费。普通分区为空 */
|
||||
private String coverage;
|
||||
|
||||
/** 渠道名称,从表头识别,可在页面修改 */
|
||||
private String channelName;
|
||||
|
||||
/** 修改渠道名称前的原名称。分区维护按这个渠道收窄 */
|
||||
private String oldChannelName;
|
||||
|
||||
/** 为 true 时国家下的全部分区都查出来,不按渠道收窄 */
|
||||
private Boolean allChannels;
|
||||
|
||||
/** 目录里的服务类型,和报价产品对应 */
|
||||
private String serviceType;
|
||||
|
||||
|
||||
@@ -19,6 +19,12 @@ public class PayPostcodeLine implements Serializable
|
||||
|
||||
private String countryCode;
|
||||
|
||||
/** 查询条件:只看这个渠道下的邮编 */
|
||||
private String channelName;
|
||||
|
||||
/** 附加费邮编查询时带出这一组的费用名 */
|
||||
private String feeName;
|
||||
|
||||
private String regionName;
|
||||
|
||||
private String regionNameCn;
|
||||
|
||||
@@ -75,6 +75,12 @@ public class PaySurcharge
|
||||
/** 来自附加费配置的高,厘米。本表不保存 */
|
||||
private BigDecimal heightCm;
|
||||
|
||||
/** 来自附加费配置的超尺寸类型:SIDE 任一边,VOLUME 体积。本表不保存 */
|
||||
private String sizeType;
|
||||
|
||||
/** 来自附加费配置的体积阈值,立方米。本表不保存 */
|
||||
private BigDecimal volumeM3;
|
||||
|
||||
/** 来自附加费配置的超重阈值,公斤。本表不保存 */
|
||||
private BigDecimal overWeightKg;
|
||||
|
||||
@@ -84,6 +90,9 @@ public class PaySurcharge
|
||||
/** 来自附加费配置的命中邮编。本表不保存 */
|
||||
private String postcodeText;
|
||||
|
||||
/** 来自附加费配置的适用国家。本表不保存 */
|
||||
private String countryCode;
|
||||
|
||||
/** 适用重量下限,空表示不限。首重从 0 开始 */
|
||||
private BigDecimal weightMin;
|
||||
|
||||
|
||||
@@ -29,6 +29,12 @@ public class PayWeightBand
|
||||
/** 价格列名称,例如英国大陆、马德里高密度 */
|
||||
private String zoneName;
|
||||
|
||||
/** 计费条件类型。POSTCODE 邮编,SIZE 尺寸,WEIGHT 重量。空表示这一档只按分区 */
|
||||
private String calcRule;
|
||||
|
||||
/** 条件参数。邮编如 07 或 35,38;尺寸如 side:80;sum:180 或 box:60*40*30;重量如 30 表示超过 30kg */
|
||||
private String calcParam;
|
||||
|
||||
/** 重量段原文 */
|
||||
private String weightLabel;
|
||||
|
||||
|
||||
@@ -27,6 +27,10 @@ public class PrcSurcharge extends BaseEntity
|
||||
private BigDecimal widthCm;
|
||||
/** 超尺寸高,厘米 */
|
||||
private BigDecimal heightCm;
|
||||
/** 超尺寸类型,字典 bms_size_type:SIDE 任一边,VOLUME 体积 */
|
||||
private String sizeType;
|
||||
/** 超尺寸体积阈值,立方米。类型为体积时,订单体积超过该值才收取 */
|
||||
private BigDecimal volumeM3;
|
||||
/** 超重阈值,公斤 */
|
||||
private BigDecimal overWeightKg;
|
||||
/** 超重续收起始重量,公斤 */
|
||||
|
||||
@@ -50,6 +50,10 @@ public class PrcSurchargeBind
|
||||
|
||||
private String blockTitle;
|
||||
|
||||
private String countryCode;
|
||||
|
||||
private String feeType;
|
||||
|
||||
private String scNote;
|
||||
|
||||
private BigDecimal lengthCm;
|
||||
@@ -58,6 +62,12 @@ public class PrcSurchargeBind
|
||||
|
||||
private BigDecimal heightCm;
|
||||
|
||||
/** 超尺寸类型:SIDE 任一边,VOLUME 体积 */
|
||||
private String sizeType;
|
||||
|
||||
/** 超尺寸体积阈值,立方米 */
|
||||
private BigDecimal volumeM3;
|
||||
|
||||
private BigDecimal overWeightKg;
|
||||
|
||||
private BigDecimal extraWeightKg;
|
||||
|
||||
@@ -53,6 +53,12 @@ public class PrcSurchargeRel extends BaseEntity
|
||||
private String scNote;
|
||||
/** 命中邮编(来自 prc_surcharge.postcode_text) */
|
||||
private String postcodeText;
|
||||
/** 超尺寸类型:SIDE 任一边,VOLUME 体积 */
|
||||
private String sizeType;
|
||||
|
||||
/** 超尺寸体积阈值,立方米 */
|
||||
private BigDecimal volumeM3;
|
||||
|
||||
/** 超尺寸长/宽/高(厘米) */
|
||||
private BigDecimal lengthCm;
|
||||
private BigDecimal widthCm;
|
||||
|
||||
@@ -2,13 +2,21 @@ package com.bms.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.bms.common.core.domain.entity.SysUser;
|
||||
import com.bms.price.domain.PayOrderQuery;
|
||||
import com.bms.price.domain.PayOrderRow;
|
||||
|
||||
/** 应付列表。 */
|
||||
public interface PayOrderListMapper
|
||||
{
|
||||
List<PayOrderRow> selectList(PayOrderQuery query);
|
||||
/** 当前页的计费订单 ID,顺序就是列表顺序。 */
|
||||
List<Long> selectPageIds(PayOrderQuery query);
|
||||
|
||||
/** 按主键取出这一页的列表字段。 */
|
||||
List<PayOrderRow> selectByBillIds(@Param("billIds") List<Long> billIds);
|
||||
|
||||
/** 这一页更新人对应的账号和昵称。 */
|
||||
List<SysUser> selectUsers(@Param("userIds") List<Long> userIds, @Param("userNames") List<String> userNames);
|
||||
|
||||
PayOrderRow selectRow(@Param("billId") String billId);
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ public interface PayPostcodeMapper
|
||||
List<PayPostcodeGroup> selectRemoteGroupsByCountry(@Param("countryCode") String countryCode,
|
||||
@Param("countryName") String countryName);
|
||||
|
||||
/** 附加费邮编。compact 是去掉空格和符号后的订单邮编,用来按前几位缩小范围。 */
|
||||
List<PayPostcodeLine> selectSurchargeLines(@Param("countryCode") String countryCode,
|
||||
@Param("countryName") String countryName, @Param("compact") String compact);
|
||||
|
||||
List<PayPostcodeLine> selectRegionKeys(@Param("groupIds") List<Long> groupIds);
|
||||
|
||||
List<PayPostcodeLine> selectLinesByGroups(@Param("groupIds") List<Long> groupIds);
|
||||
|
||||
@@ -423,34 +423,7 @@ public final class LabelArCostCalculator
|
||||
result.getSkipped().add(name + ":价卡没有可计算的条件,暂不计费");
|
||||
}
|
||||
}
|
||||
result.getFees().addAll(keepHighestByName(sized));
|
||||
}
|
||||
|
||||
/** 同一费用名的尺寸档同时命中时,只收较高的一档,例如 70% 覆盖 35%。 */
|
||||
private static List<PayCostLine> keepHighestByName(List<PayCostLine> lines)
|
||||
{
|
||||
List<PayCostLine> kept = new ArrayList<>();
|
||||
for (PayCostLine line : lines)
|
||||
{
|
||||
PayCostLine same = null;
|
||||
for (PayCostLine exists : kept)
|
||||
{
|
||||
if (exists.getFeeName().equals(line.getFeeName()))
|
||||
{
|
||||
same = exists;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (same == null)
|
||||
{
|
||||
kept.add(line);
|
||||
}
|
||||
else if (line.getAmount().compareTo(same.getAmount()) > 0)
|
||||
{
|
||||
kept.set(kept.indexOf(same), line);
|
||||
}
|
||||
}
|
||||
return kept;
|
||||
result.getFees().addAll(sized);
|
||||
}
|
||||
|
||||
private static void addExtraKg(List<PayCostLine> fees, PaySurcharge fee, BigDecimal weight, String currency)
|
||||
@@ -473,13 +446,43 @@ public final class LabelArCostCalculator
|
||||
{
|
||||
return;
|
||||
}
|
||||
BigDecimal steps = PaySurchargeRules.extraSteps(fee, weight);
|
||||
if (steps.compareTo(BigDecimal.ZERO) <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
BigDecimal over = weight.subtract(threshold);
|
||||
BigDecimal amount = fee.getAmount().multiply(over).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal amount = fee.getAmount().multiply(steps).setScale(2, RoundingMode.HALF_UP);
|
||||
String billed = plain(steps.multiply(PaySurchargeRules.extraStepKg(fee)));
|
||||
PayCostLine freightLine = freightLine(fees);
|
||||
if (freightLine != null && "每公斤续重".equals(blank(fee.getFeeName())))
|
||||
{
|
||||
freightLine.setAmount(freightLine.getAmount().add(amount).setScale(2, RoundingMode.HALF_UP));
|
||||
String remark = blank(freightLine.getRemark());
|
||||
freightLine.setRemark((remark.isEmpty() ? "" : remark + ";") + "续重 " + billed + "kg × " + plain(fee.getAmount()));
|
||||
return;
|
||||
}
|
||||
long scId = fee.getSurchargeId() == null ? 0L : fee.getSurchargeId();
|
||||
String remark = "超出 " + plain(over) + "kg × " + plain(fee.getAmount()) + " " + blank(fee.getPriceUnit());
|
||||
String remark = "超出 " + plain(over) + "kg,按 " + billed + "kg × " + plain(fee.getAmount()) + " " + blank(fee.getPriceUnit());
|
||||
fees.add(line("SURCHARGE", blank(fee.getFeeName()), scId, amount, currency, remark));
|
||||
}
|
||||
|
||||
private static PayCostLine freightLine(List<PayCostLine> fees)
|
||||
{
|
||||
if (fees == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
for (PayCostLine row : fees)
|
||||
{
|
||||
if (row != null && "BASIC_FREIGHT".equals(row.getFeeType()))
|
||||
{
|
||||
return row;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 同一地区有多张服务表时,续重只跟本次首重所在的那一张表。 */
|
||||
private static boolean sameSection(String feeSection, String freightSection)
|
||||
{
|
||||
|
||||
@@ -103,7 +103,7 @@ public final class PayCostCalculator
|
||||
boolean postcodeOn, boolean zoneOn)
|
||||
{
|
||||
return calculate(product, weight, length, width, height, postcode, zoneName, bizDate, orderStatus, remoteHits,
|
||||
postcodeOn, zoneOn, null, null);
|
||||
postcodeOn, zoneOn, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,6 +112,17 @@ public final class PayCostCalculator
|
||||
public static PayOrderCostResult calculate(PayProduct product, BigDecimal weight, BigDecimal length, BigDecimal width,
|
||||
BigDecimal height, String postcode, String zoneName, Date bizDate, Integer orderStatus, List<PayRemoteBook.Hit> remoteHits,
|
||||
boolean postcodeOn, boolean zoneOn, String countryCode, String countryName)
|
||||
{
|
||||
return calculate(product, weight, length, width, height, postcode, zoneName, bizDate, orderStatus, remoteHits,
|
||||
postcodeOn, zoneOn, countryCode, countryName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* surchargeHits 是应付邮编配置里属性为附加费、并且前几位对上订单邮编的结果。
|
||||
*/
|
||||
public static PayOrderCostResult calculate(PayProduct product, BigDecimal weight, BigDecimal length, BigDecimal width,
|
||||
BigDecimal height, String postcode, String zoneName, Date bizDate, Integer orderStatus, List<PayRemoteBook.Hit> remoteHits,
|
||||
boolean postcodeOn, boolean zoneOn, String countryCode, String countryName, List<PayRemoteBook.Hit> surchargeHits)
|
||||
{
|
||||
PayOrderCostResult result = new PayOrderCostResult();
|
||||
result.setFees(new ArrayList<>());
|
||||
@@ -128,48 +139,64 @@ public final class PayCostCalculator
|
||||
result.setMessage(PaymentMesEnum.BMS_PAY_NO_WEIGHT.getCnMes());
|
||||
return result;
|
||||
}
|
||||
List<PayWeightBand> usable = usableBands(product.getWeightBands());
|
||||
List<PayWeightBand> bands = forZone(usable, zoneName);
|
||||
if (zoneName != null && !zoneName.isBlank() && bands.isEmpty() && hasZoneFee(product, zoneName))
|
||||
PayWeightBand remoteHit = conditionBand(product, postcode, countryCode, weight, length, width, height);
|
||||
PayWeightBand band;
|
||||
String pricedZone = zoneName;
|
||||
if (remoteHit != null)
|
||||
{
|
||||
bands = deliveryBands(usable, product);
|
||||
}
|
||||
if (zoneName != null && !zoneName.isBlank() && bands.isEmpty())
|
||||
{
|
||||
result.setMessage("邮编对应的地区「" + zoneName + "」不在价卡重量段里");
|
||||
return result;
|
||||
}
|
||||
Set<String> zones = zones(bands);
|
||||
if (zones.size() > 1)
|
||||
{
|
||||
result.setMessage("产品「" + product.getProductName() + "」有多个地区(" + String.join("、", zones)
|
||||
+ "),邮编没有对上其中的地区,无法确定运费");
|
||||
return result;
|
||||
}
|
||||
PayWeightBand band = matchBand(bands, weight);
|
||||
if (band == null)
|
||||
{
|
||||
PayWeightBand top = highestBand(bands);
|
||||
if (top == null || weight.compareTo(top.getWeightMax()) <= 0
|
||||
|| !hasExtraKg(product, zoneName, top.getWeightMax(), top.getSectionName()))
|
||||
band = remoteHit;
|
||||
if (!blank(remoteHit.getZoneName()).isEmpty())
|
||||
{
|
||||
result.setMessage(outOfRange(product, bands, weight));
|
||||
pricedZone = remoteHit.getZoneName();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
List<PayWeightBand> usable = usableBands(product.getWeightBands());
|
||||
List<PayWeightBand> bands = forZone(usable, zoneName);
|
||||
if (zoneName != null && !zoneName.isBlank() && bands.isEmpty()
|
||||
&& (hasZoneFee(product, zoneName) || hasRemoteWeightBand(product, zoneName)))
|
||||
{
|
||||
bands = deliveryBands(usable, product);
|
||||
}
|
||||
if (zoneName != null && !zoneName.isBlank() && bands.isEmpty())
|
||||
{
|
||||
result.setMessage("邮编对应的地区「" + zoneName + "」不在价卡重量段里");
|
||||
return result;
|
||||
}
|
||||
band = top;
|
||||
Set<String> zones = zones(bands);
|
||||
if (zones.size() > 1)
|
||||
{
|
||||
result.setMessage("产品「" + product.getProductName() + "」有多个地区(" + String.join("、", zones)
|
||||
+ "),邮编没有对上其中的地区,无法确定运费");
|
||||
return result;
|
||||
}
|
||||
band = matchBand(bands, weight);
|
||||
if (band == null)
|
||||
{
|
||||
PayWeightBand top = highestBand(bands);
|
||||
if (top == null || weight.compareTo(top.getWeightMax()) <= 0
|
||||
|| !hasExtraKg(product, zoneName, top.getWeightMax(), top.getSectionName()))
|
||||
{
|
||||
result.setMessage(outOfRange(product, bands, weight));
|
||||
return result;
|
||||
}
|
||||
band = top;
|
||||
}
|
||||
}
|
||||
String currency = currencyOf(product, band);
|
||||
BigDecimal freight = bandAmount(band, weight);
|
||||
String freightRemark = band.getWeightLabel() + " " + plain(band.getPrice()) + " " + blank(band.getPriceUnit());
|
||||
if (zoneName != null && !zoneName.isBlank())
|
||||
if (pricedZone != null && !pricedZone.isBlank())
|
||||
{
|
||||
freightRemark = freightRemark + ",地区 " + zoneName.replace('\n', ' ');
|
||||
freightRemark = freightRemark + ",地区 " + pricedZone.replace('\n', ' ');
|
||||
}
|
||||
PayCostLine freightLine = line("BASIC_FREIGHT", "基础运费", 0L, freight, currency, freightRemark);
|
||||
result.getFees().add(freightLine);
|
||||
result.setCurrency(currency);
|
||||
addSurcharges(product, weight, length, width, height, postcode, zoneName, bizDate, orderStatus, freight, currency,
|
||||
band.getSectionName(), remoteHits, postcodeOn, zoneOn, countryCode, countryName, result);
|
||||
addZoneFeeBands(result, product, band, weight, postcode, currency, zoneName);
|
||||
addSurcharges(product, weight, length, width, height, postcode, pricedZone, bizDate, orderStatus, freight, currency,
|
||||
band.getSectionName(), remoteHits, surchargeHits, postcodeOn, zoneOn, countryCode, countryName, result);
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
for (PayCostLine fee : result.getFees())
|
||||
{
|
||||
@@ -180,6 +207,24 @@ public final class PayCostCalculator
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 偏远费写在重量段里,和派送费按同一重量行对齐。分区对上时,运费仍用派送档。 */
|
||||
private static boolean hasRemoteWeightBand(PayProduct product, String zoneName)
|
||||
{
|
||||
if (product.getWeightBands() == null || zoneName == null || zoneName.isBlank())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (PayWeightBand band : product.getWeightBands())
|
||||
{
|
||||
if (band != null && zoneFeeBand(band) && blank(band.getCalcRule()).isEmpty()
|
||||
&& PayZoneMatcher.sameZone(band.getZoneName(), zoneName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 邮编落到偏远分区,而价卡重量段只有大陆派送费时,运费用大陆档。 */
|
||||
private static boolean hasZoneFee(PayProduct product, String zoneName)
|
||||
{
|
||||
@@ -289,7 +334,7 @@ public final class PayCostCalculator
|
||||
*/
|
||||
private static void addSurcharges(PayProduct product, BigDecimal weight, BigDecimal length, BigDecimal width,
|
||||
BigDecimal height, String postcode, String zoneName, Date bizDate, Integer orderStatus, BigDecimal freight, String currency,
|
||||
String freightSection, List<PayRemoteBook.Hit> remoteHits, boolean postcodeOn, boolean zoneOn,
|
||||
String freightSection, List<PayRemoteBook.Hit> remoteHits, List<PayRemoteBook.Hit> surchargeHits, boolean postcodeOn, boolean zoneOn,
|
||||
String countryCode, String countryName, PayOrderCostResult result)
|
||||
{
|
||||
if (product.getSurcharges() == null)
|
||||
@@ -305,9 +350,31 @@ 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 (PaySurchargeRules.FEE_POSTCODE.equals(rule))
|
||||
{
|
||||
String feePostName = blank(fee.getFeeName());
|
||||
if (postcode == null || postcode.isBlank())
|
||||
{
|
||||
result.getSkipped().add(feePostName + ":订单没有邮编");
|
||||
}
|
||||
else if (surchargeBookApplies(surchargeHits, fee))
|
||||
{
|
||||
addFlat(result.getFees(), fee, currency, "邮编 " + postcode.trim());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!countryAllows(fee, countryCode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<Map<String, Object>> postcodeRules = prefixRules(product, PaySurchargeRules.POSTCODE);
|
||||
List<Map<String, Object>> 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 +416,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;
|
||||
@@ -357,7 +424,11 @@ public final class PayCostCalculator
|
||||
String name = blank(fee.getFeeName());
|
||||
if (PaySurchargeRules.POSTCODE.equals(rule))
|
||||
{
|
||||
if (!postcodeRules.isEmpty())
|
||||
if (configFee && surchargeBookApplies(surchargeHits, fee))
|
||||
{
|
||||
addFlat(result.getFees(), fee, currency, "邮编 " + (postcode == null ? "" : postcode.trim()));
|
||||
}
|
||||
else if (!postcodeRules.isEmpty())
|
||||
{
|
||||
addConfiguredZoneFee(result, fee, weight, currency, postcode, countryCode, countryName, postcodeRules, "邮编 ");
|
||||
}
|
||||
@@ -472,37 +543,10 @@ public final class PayCostCalculator
|
||||
result.getSkipped().add(name + ":价卡没有可计算的条件,暂不计费");
|
||||
}
|
||||
}
|
||||
result.getFees().addAll(keepHighestByName(sized));
|
||||
result.getFees().addAll(sized);
|
||||
result.getFees().addAll(stepped);
|
||||
}
|
||||
|
||||
/** 同一费用名的按票尺寸档同时命中时,只收较高的一档,例如 70% 覆盖 35%。按超出单位计的不并进这一档。 */
|
||||
private static List<PayCostLine> keepHighestByName(List<PayCostLine> lines)
|
||||
{
|
||||
List<PayCostLine> kept = new ArrayList<>();
|
||||
for (PayCostLine line : lines)
|
||||
{
|
||||
PayCostLine same = null;
|
||||
for (PayCostLine exists : kept)
|
||||
{
|
||||
if (exists.getFeeName().equals(line.getFeeName()))
|
||||
{
|
||||
same = exists;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (same == null)
|
||||
{
|
||||
kept.add(line);
|
||||
}
|
||||
else if (line.getAmount().compareTo(same.getAmount()) > 0)
|
||||
{
|
||||
kept.set(kept.indexOf(same), line);
|
||||
}
|
||||
}
|
||||
return kept;
|
||||
}
|
||||
|
||||
private static void addExtraKg(List<PayCostLine> fees, PaySurcharge fee, BigDecimal weight, String currency)
|
||||
{
|
||||
if (fee.getAmount() == null || weight == null)
|
||||
@@ -523,13 +567,43 @@ public final class PayCostCalculator
|
||||
{
|
||||
return;
|
||||
}
|
||||
BigDecimal steps = PaySurchargeRules.extraSteps(fee, weight);
|
||||
if (steps.compareTo(BigDecimal.ZERO) <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
BigDecimal over = weight.subtract(threshold);
|
||||
BigDecimal amount = fee.getAmount().multiply(over).setScale(2, RoundingMode.HALF_UP);
|
||||
long scId = fee.getSurchargeId() == null ? 0L : fee.getSurchargeId();
|
||||
String remark = "超出 " + plain(over) + "kg × " + plain(fee.getAmount()) + " " + blank(fee.getPriceUnit());
|
||||
BigDecimal amount = fee.getAmount().multiply(steps).setScale(2, RoundingMode.HALF_UP);
|
||||
String billed = plain(steps.multiply(PaySurchargeRules.extraStepKg(fee)));
|
||||
PayCostLine freightLine = freightLine(fees);
|
||||
if (freightLine != null && "每公斤续重".equals(blank(fee.getFeeName())))
|
||||
{
|
||||
freightLine.setAmount(freightLine.getAmount().add(amount).setScale(2, RoundingMode.HALF_UP));
|
||||
String remark = blank(freightLine.getRemark());
|
||||
freightLine.setRemark((remark.isEmpty() ? "" : remark + ";") + "续重 " + billed + "kg × " + plain(fee.getAmount()));
|
||||
return;
|
||||
}
|
||||
long scId = feeRef(fee);
|
||||
String remark = "超出 " + plain(over) + "kg,按 " + billed + "kg × " + plain(fee.getAmount()) + " " + blank(fee.getPriceUnit());
|
||||
fees.add(line("SURCHARGE", blank(fee.getFeeName()), scId, amount, currency, remark));
|
||||
}
|
||||
|
||||
private static PayCostLine freightLine(List<PayCostLine> fees)
|
||||
{
|
||||
if (fees == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
for (PayCostLine row : fees)
|
||||
{
|
||||
if (row != null && "BASIC_FREIGHT".equals(row.getFeeType()))
|
||||
{
|
||||
return row;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 同一地区有多张服务表时,续重只跟本次首重所在的那一张表。 */
|
||||
private static boolean sameSection(String feeSection, String freightSection)
|
||||
{
|
||||
@@ -550,6 +624,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;
|
||||
@@ -588,6 +663,11 @@ public final class PayCostCalculator
|
||||
private static boolean sizeHit(PayProduct product, PaySurcharge fee, BigDecimal length, BigDecimal width, BigDecimal height,
|
||||
BigDecimal weight)
|
||||
{
|
||||
if (fee != null && (("VOLUME".equalsIgnoreCase(fee.getSizeType()) && fee.getVolumeM3() != null)
|
||||
|| (fee.getLengthCm() != null && fee.getWidthCm() != null && fee.getHeightCm() != null)))
|
||||
{
|
||||
return PaySurchargeRules.matchesFeeSize(fee, length, width, height);
|
||||
}
|
||||
List<Map<String, Object>> details = ruleDetails(product, PaySurchargeRules.SIZE);
|
||||
if (details.isEmpty())
|
||||
{
|
||||
@@ -653,12 +733,56 @@ 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);
|
||||
return name.contains("偏远") || name.contains("岛屿") || name.contains("remote") || name.contains("island");
|
||||
}
|
||||
|
||||
/** 附加费配置的费用名和邮编组上的费用名对得上,才收这一笔。邮编组没写费用名时,这一条附加费邮编都收。 */
|
||||
private static boolean surchargeBookApplies(List<PayRemoteBook.Hit> hits, PaySurcharge fee)
|
||||
{
|
||||
if (hits == null || hits.isEmpty() || fee == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
String name = blank(fee.getFeeName());
|
||||
for (PayRemoteBook.Hit hit : hits)
|
||||
{
|
||||
if (hit == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String book = blank(hit.getFeeName());
|
||||
if (book.isEmpty() || name.isEmpty() || sameFeeName(book, name) || sameFeeCore(book, name))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 邮编配置命中后,金额相同的那一档才收。命中写了地区时要对上分区;没写地区时用价卡上的邮编前缀选档。 */
|
||||
private static boolean bookApplies(List<PayRemoteBook.Hit> hits, PaySurcharge fee, String rule, String postcode)
|
||||
{
|
||||
@@ -720,6 +844,22 @@ public final class PayCostCalculator
|
||||
return fee.contains(book) || book.contains(fee);
|
||||
}
|
||||
|
||||
/** 去掉渠道和「附加费」这几个字后再比,空气减排费_Evri_48H 和空气减排附加费算同一笔。 */
|
||||
private static boolean sameFeeCore(String bookName, String feeName)
|
||||
{
|
||||
String book = feeCore(bookName);
|
||||
String fee = feeCore(feeName);
|
||||
return !book.isEmpty() && !fee.isEmpty() && (book.contains(fee) || fee.contains(book));
|
||||
}
|
||||
|
||||
private static String feeCore(String name)
|
||||
{
|
||||
String text = blank(name).toLowerCase(Locale.ROOT);
|
||||
text = text.replace("附加费", "").replace("附加", "").replace("费", "");
|
||||
text = text.replace("evri48h", "").replace("evri", "").replace("48h", "");
|
||||
return text.replaceAll("[^a-z0-9\\u4e00-\\u9fa5]", "");
|
||||
}
|
||||
|
||||
private static String feeKey(String name)
|
||||
{
|
||||
return blank(name).toLowerCase(Locale.ROOT).replace("地区", "").replace(" ", "");
|
||||
@@ -752,7 +892,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"));
|
||||
}
|
||||
|
||||
@@ -780,7 +920,20 @@ public final class PayCostCalculator
|
||||
return stepped;
|
||||
}
|
||||
}
|
||||
return matchedFee(fee, freight, currency, "尺寸命中");
|
||||
return matchedFee(fee, freight, currency, sizeRemark(fee));
|
||||
}
|
||||
|
||||
private static String sizeRemark(PaySurcharge fee)
|
||||
{
|
||||
if (fee != null && "VOLUME".equalsIgnoreCase(blank(fee.getSizeType())) && fee.getVolumeM3() != null)
|
||||
{
|
||||
return "体积超过 " + plain(fee.getVolumeM3()) + "m³";
|
||||
}
|
||||
if (fee == null || fee.getLengthCm() == null || fee.getWidthCm() == null || fee.getHeightCm() == null)
|
||||
{
|
||||
return "尺寸命中";
|
||||
}
|
||||
return "任一边超过 " + plain(fee.getLengthCm()) + "×" + plain(fee.getWidthCm()) + "×" + plain(fee.getHeightCm()) + "cm";
|
||||
}
|
||||
|
||||
/** 价卡写成每增加、每超出时,金额是一个步长的单价。 */
|
||||
@@ -832,10 +985,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;
|
||||
@@ -881,17 +1034,18 @@ public final class PayCostCalculator
|
||||
}
|
||||
amount = freight.multiply(fee.getAmount()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
|
||||
}
|
||||
else
|
||||
String lineCurrency = currency;
|
||||
if (!percent(fee))
|
||||
{
|
||||
amount = amount.setScale(2, RoundingMode.HALF_UP);
|
||||
String feeCurrency = normalize(fee.getCurrency());
|
||||
if (!feeCurrency.isEmpty() && !feeCurrency.equals(currency))
|
||||
if (!feeCurrency.isEmpty())
|
||||
{
|
||||
return null;
|
||||
lineCurrency = feeCurrency;
|
||||
}
|
||||
}
|
||||
long scId = fee.getSurchargeId() == null ? 0L : fee.getSurchargeId();
|
||||
return line("SURCHARGE", blank(fee.getFeeName()), scId, amount, currency, remark);
|
||||
long scId = feeRef(fee);
|
||||
return line("SURCHARGE", blank(fee.getFeeName()), scId, amount, lineCurrency, remark);
|
||||
}
|
||||
|
||||
private static boolean percent(PaySurcharge fee)
|
||||
@@ -918,6 +1072,226 @@ 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 PayWeightBand conditionBand(PayProduct product, String postcode, String countryCode, BigDecimal weight,
|
||||
BigDecimal length, BigDecimal width, BigDecimal height)
|
||||
{
|
||||
if (product.getWeightBands() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
PayWeightBand best = null;
|
||||
int bestRank = 0;
|
||||
int bestPrefix = 0;
|
||||
BigDecimal bestWeight = null;
|
||||
int bestIndex = -1;
|
||||
int index = 0;
|
||||
for (PayWeightBand band : product.getWeightBands())
|
||||
{
|
||||
int rank = conditionRank(band, postcode, countryCode, weight, length, width, height);
|
||||
if (rank > bestRank)
|
||||
{
|
||||
best = band;
|
||||
bestRank = rank;
|
||||
bestPrefix = prefixScore(band, postcode);
|
||||
bestWeight = weightGate(band);
|
||||
bestIndex = index;
|
||||
}
|
||||
else if (rank > 0 && rank == bestRank)
|
||||
{
|
||||
if (rank == 3 && prefixScore(band, postcode) > bestPrefix)
|
||||
{
|
||||
best = band;
|
||||
bestPrefix = prefixScore(band, postcode);
|
||||
bestIndex = index;
|
||||
}
|
||||
else if (rank == 1)
|
||||
{
|
||||
BigDecimal gate = weightGate(band);
|
||||
if (gate != null && (bestWeight == null || gate.compareTo(bestWeight) > 0))
|
||||
{
|
||||
best = band;
|
||||
bestWeight = gate;
|
||||
bestIndex = index;
|
||||
}
|
||||
}
|
||||
else if (rank == 2 && index > bestIndex)
|
||||
{
|
||||
best = band;
|
||||
bestIndex = index;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/** 邮编 3,尺寸 2,重量 1。没有命中返回 0。 */
|
||||
private static int conditionRank(PayWeightBand band, String postcode, String countryCode, BigDecimal weight,
|
||||
BigDecimal length, BigDecimal width, BigDecimal height)
|
||||
{
|
||||
if (band == null || band.getPrice() == null || !countryFits(band.getCountryCode(), countryCode))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
String rule = blank(band.getCalcRule()).toUpperCase(Locale.ROOT);
|
||||
String param = blank(band.getCalcParam());
|
||||
if (rule.isEmpty() || param.isEmpty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (PaySurchargeRules.POSTCODE.equals(rule) && PaySurchargeRules.matchesPostcode(param, postcode))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (PaySurchargeRules.SIZE.equals(rule) && PaySurchargeRules.matchesSize(param, length, width, height))
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
if (PaySurchargeRules.WEIGHT.equals(rule) && PaySurchargeRules.matchesWeight(param, weight))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int prefixScore(PayWeightBand band, String postcode)
|
||||
{
|
||||
int length = prefixLength(blank(band.getCalcParam()), postcode);
|
||||
return length == 0 ? 1 : length;
|
||||
}
|
||||
|
||||
private static BigDecimal weightGate(PayWeightBand band)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new BigDecimal(blank(band.getCalcParam()).trim());
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean countryFits(String bandCountry, String orderCountry)
|
||||
{
|
||||
if (bandCountry == null || bandCountry.isBlank() || orderCountry == null || orderCountry.isBlank())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return bandCountry.trim().equalsIgnoreCase(orderCountry.trim());
|
||||
}
|
||||
|
||||
private static int prefixLength(String prefixes, String postcode)
|
||||
{
|
||||
String digits = postcode.replaceAll("\\D", "");
|
||||
int best = 0;
|
||||
for (String token : prefixes.split(","))
|
||||
{
|
||||
String value = token.trim();
|
||||
if (value.matches("\\d{1,5}") && !digits.isEmpty() && digits.startsWith(value) && value.length() > best)
|
||||
{
|
||||
best = value.length();
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/** 没有邮编条件的分区费用仍按地区加在已选运费上。写了邮编条件的档已经当作运费本身。 */
|
||||
private static void addZoneFeeBands(PayOrderCostResult result, PayProduct product, PayWeightBand freight, BigDecimal weight,
|
||||
String postcode, String currency, String orderZone)
|
||||
{
|
||||
if (product.getWeightBands() == null || freight == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (PayWeightBand band : product.getWeightBands())
|
||||
{
|
||||
if (band == null || band.getPrice() == null || !zoneFeeBand(band) || !blank(band.getCalcRule()).isEmpty()
|
||||
|| !sameWeightRow(band, freight) || !zoneFeeHits(band, freight, postcode, orderZone))
|
||||
{
|
||||
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 sameWeightRow(PayWeightBand band, PayWeightBand freight)
|
||||
{
|
||||
if (band.getWeightMin() == null || band.getWeightMax() == null || freight.getWeightMin() == null || freight.getWeightMax() == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return band.getWeightMin().compareTo(freight.getWeightMin()) == 0
|
||||
&& band.getWeightMax().compareTo(freight.getWeightMax()) == 0;
|
||||
}
|
||||
|
||||
private static boolean zoneFeeHits(PayWeightBand band, PayWeightBand freight, String postcode, String orderZone)
|
||||
{
|
||||
String prefixes = PaySurchargeRules.remotePrefixes(band.getZoneName());
|
||||
if (!prefixes.isEmpty())
|
||||
{
|
||||
return PaySurchargeRules.matchesPostcode(prefixes, postcode);
|
||||
}
|
||||
String label = blank(band.getChargeName()) + " " + blank(band.getSectionName());
|
||||
if (label.contains("偏远"))
|
||||
{
|
||||
return orderZone != null && !orderZone.isBlank() && PayZoneMatcher.sameZone(band.getZoneName(), orderZone);
|
||||
}
|
||||
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 steps = PaySurchargeRules.extraSteps(fee, weight);
|
||||
if (steps.compareTo(BigDecimal.ZERO) <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
BigDecimal over = weight.subtract(band.getWeightMax());
|
||||
BigDecimal amount = fee.getAmount().multiply(steps).setScale(2, RoundingMode.HALF_UP);
|
||||
long scId = feeRef(fee);
|
||||
result.getFees().add(line("SURCHARGE", name, scId, amount, currency,
|
||||
"超出 " + plain(over) + "kg,按 " + plain(steps.multiply(PaySurchargeRules.extraStepKg(fee))) + "kg × "
|
||||
+ plain(fee.getAmount()) + " " + blank(fee.getPriceUnit())));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<PayWeightBand> usableBands(List<PayWeightBand> bands)
|
||||
{
|
||||
List<PayWeightBand> usable = new ArrayList<>();
|
||||
@@ -927,7 +1301,8 @@ 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) && blank(band.getCalcRule()).isEmpty())
|
||||
{
|
||||
usable.add(band);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -65,13 +66,14 @@ public class PayOrderFeeCalculator
|
||||
PayProduct product = payProductService.selectPriceForDate(channel.getId(), priceDate);
|
||||
BigDecimal weight = chargeWeight(bill);
|
||||
Integer orderStatus = orderStatus(bill, ext);
|
||||
List<PayPostcodeGroup> linked = linkedGroups(product);
|
||||
List<PayPostcodeGroup> linked = linkedGroups(product, channel);
|
||||
String zoneName = resolveZone(channel, product, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), linked);
|
||||
applyCurrentSurcharge(channel.getId(), product);
|
||||
List<PayRemoteBook.Hit> remoteHits = remoteHits(linked, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName());
|
||||
List<PayRemoteBook.Hit> remoteHits = remoteHits(linked, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), channel);
|
||||
List<PayRemoteBook.Hit> surchargeHits = surchargeHits(bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), channel, product);
|
||||
PayOrderCostResult result = PayCostCalculator.calculate(product, weight, bill.getPkgLength(), bill.getPkgWidth(),
|
||||
bill.getPkgHeight(), bill.getDestPostcode(), zoneName, priceDate, orderStatus, remoteHits, true, true,
|
||||
bill.getCountryCode(), bill.getCountryName());
|
||||
bill.getCountryCode(), bill.getCountryName(), surchargeHits);
|
||||
result.setBillId(bill.getBillId());
|
||||
result.setChannelId(channel.getId());
|
||||
result.setChannelName(channel.getChannelName());
|
||||
@@ -180,7 +182,7 @@ public class PayOrderFeeCalculator
|
||||
}
|
||||
|
||||
/**
|
||||
* 运费仍按订单日期取版本。附加费只取该价卡产品已绑定且启用的附加费配置。
|
||||
* 运费按订单日期的重量段。附加费取已绑定的配置,超重续收只用价卡上按分区写的续重单价。
|
||||
*
|
||||
* @param channelId 渠道 ID
|
||||
* @param priced 订单日期已经命中的价卡,方法会改写它的附加费
|
||||
@@ -200,7 +202,8 @@ public class PayOrderFeeCalculator
|
||||
{
|
||||
// 今天没有生效版本时,改查订单日期命中的那一版有没有绑定
|
||||
}
|
||||
priced.setSurcharges(payProductService.boundSurcharges(source));
|
||||
priced.setSurcharges(PaySurchargeRules.surchargesForCalc(priced.getSurcharges(),
|
||||
payProductService.boundSurcharges(source)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +212,7 @@ public class PayOrderFeeCalculator
|
||||
* @param product 当前价卡版本
|
||||
* @return 名称能对上的邮编组,没有时为空列表
|
||||
*/
|
||||
private List<PayPostcodeGroup> linkedGroups(PayProduct product)
|
||||
private List<PayPostcodeGroup> linkedGroups(PayProduct product, ServiceChannel channel)
|
||||
{
|
||||
List<String> names = new ArrayList<>();
|
||||
addName(names, product.getProductName());
|
||||
@@ -221,7 +224,7 @@ public class PayOrderFeeCalculator
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<PayPostcodeGroup> found = payPostcodeMapper.selectGroupsForProduct(names);
|
||||
return found == null ? new ArrayList<>() : found;
|
||||
return PayPostcodeBooks.ownChannel(found, channel.getChannelName(), channel.getChannelCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,7 +256,8 @@ public class PayOrderFeeCalculator
|
||||
* @param countryName 目的国名称
|
||||
* @return 命中的偏远分区;产品有名单但没命中时返回空列表
|
||||
*/
|
||||
private List<PayRemoteBook.Hit> remoteHits(List<PayPostcodeGroup> linked, String postcode, String countryCode, String countryName)
|
||||
private List<PayRemoteBook.Hit> remoteHits(List<PayPostcodeGroup> linked, String postcode, String countryCode, String countryName,
|
||||
ServiceChannel channel)
|
||||
{
|
||||
boolean productBook = false;
|
||||
for (PayPostcodeGroup group : linked)
|
||||
@@ -272,8 +276,10 @@ public class PayOrderFeeCalculator
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<PayPostcodeGroup> countryGroups = payPostcodeMapper.selectRemoteGroupsByCountry(countryCode, countryName);
|
||||
if (countryGroups == null || countryGroups.isEmpty())
|
||||
List<PayPostcodeGroup> countryGroups = PayPostcodeBooks.ownChannel(
|
||||
payPostcodeMapper.selectRemoteGroupsByCountry(countryCode, countryName),
|
||||
channel.getChannelName(), channel.getChannelCode());
|
||||
if (countryGroups.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -281,6 +287,32 @@ public class PayOrderFeeCalculator
|
||||
return hits == null || hits.isEmpty() ? null : hits;
|
||||
}
|
||||
|
||||
/** EVRI 渠道按应付邮编配置里的附加费邮编判断。前几位对上时,返回对应的费用名。 */
|
||||
private List<PayRemoteBook.Hit> surchargeHits(String postcode, String countryCode, String countryName, ServiceChannel channel,
|
||||
PayProduct product)
|
||||
{
|
||||
String productName = product == null ? "" : product.getProductName();
|
||||
if (channel == null || postcode == null || postcode.isBlank() || !evriChannel(channel, productName))
|
||||
{
|
||||
return new ArrayList<>();
|
||||
}
|
||||
String compact = postcode.toUpperCase(Locale.ROOT).replaceAll("[^A-Z0-9]", "");
|
||||
if (compact.length() < 2)
|
||||
{
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<PayPostcodeLine> lines = payPostcodeMapper.selectSurchargeLines(countryCode, countryName, compact);
|
||||
return PayRemoteBook.surchargeHits(lines, postcode, channel.getChannelName(), channel.getChannelCode(), productName);
|
||||
}
|
||||
|
||||
private static boolean evriChannel(ServiceChannel channel, String productName)
|
||||
{
|
||||
String blob = ((channel.getChannelName() == null ? "" : channel.getChannelName()) + " "
|
||||
+ (channel.getChannelCode() == null ? "" : channel.getChannelCode()) + " "
|
||||
+ (productName == null ? "" : productName)).toLowerCase(Locale.ROOT);
|
||||
return blob.contains("evri");
|
||||
}
|
||||
|
||||
/**
|
||||
* 在给定邮编组里做偏远匹配。没有偏远组时返回 null,有组但邮编没命中时返回空列表。
|
||||
*
|
||||
@@ -362,6 +394,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);
|
||||
@@ -463,7 +496,8 @@ public class PayOrderFeeCalculator
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ("UNREACH".equalsIgnoreCase(group.getCoverage() == null ? "" : group.getCoverage().trim()))
|
||||
String coverage = group.getCoverage() == null ? "" : group.getCoverage().trim();
|
||||
if ("UNREACH".equalsIgnoreCase(coverage) || "SURCHARGE".equalsIgnoreCase(coverage))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -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<PayPostcodeGroup> ownChannel(List<PayPostcodeGroup> groups, String channelName, String channelCode)
|
||||
{
|
||||
List<PayPostcodeGroup> found = groups == null ? new ArrayList<>() : groups;
|
||||
String name = norm(channelName);
|
||||
String code = norm(channelCode);
|
||||
if (found.isEmpty() || (name.isEmpty() && code.isEmpty()))
|
||||
{
|
||||
return found;
|
||||
}
|
||||
List<PayPostcodeGroup> matched = new ArrayList<>();
|
||||
List<PayPostcodeGroup> 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<PayPostcodeGroup> preferLonger(List<PayPostcodeGroup> 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<PayPostcodeGroup> 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]", "");
|
||||
}
|
||||
}
|
||||
@@ -415,6 +415,12 @@ public class PayPostcodeImporter
|
||||
series.startCol = bound(owner, i, start, end, true);
|
||||
series.endBound = bound(owner, i, start, end, false);
|
||||
series.channel = channelOf(channelSources(grid, header, owner, i, start, end, title, sheetName));
|
||||
if (airReduction(grid, header, series))
|
||||
{
|
||||
series.air = true;
|
||||
series.channel = "Evri 48H";
|
||||
series.coverage = "SURCHARGE";
|
||||
}
|
||||
list.add(series);
|
||||
}
|
||||
return list;
|
||||
@@ -620,6 +626,10 @@ public class PayPostcodeImporter
|
||||
String feeName = series.fee ? cut(series.feeName, 200) : "";
|
||||
String feeValue = series.fee ? cut(feeText, 200) : "";
|
||||
String channel = cut(series.channel, 100);
|
||||
if (series.air && (zone == null || zone.isBlank()))
|
||||
{
|
||||
zone = region;
|
||||
}
|
||||
String key = kind + "|" + sheetName + "|" + country.code + "|" + channel + "|" + feeName + "|" + feeValue + "|" + (series.fee ? "" : series.startCol);
|
||||
PayPostcodeGroup group = groups.get(key);
|
||||
if (group == null)
|
||||
@@ -630,7 +640,7 @@ public class PayPostcodeImporter
|
||||
group.setSheetName(sheetName);
|
||||
group.setBlockTitle(cut(series.title.isEmpty() ? sheetName : series.title, 200));
|
||||
group.setConfigKind(kind);
|
||||
group.setCoverage(coverageOf(sheetName, series.title, feeName));
|
||||
group.setCoverage(series.coverage.isEmpty() ? coverageOf(sheetName, series.title, feeName) : series.coverage);
|
||||
group.setChannelName(channel);
|
||||
group.setCountryName(country.name);
|
||||
group.setCountryCode(country.code);
|
||||
@@ -694,6 +704,10 @@ public class PayPostcodeImporter
|
||||
{
|
||||
return "REACH";
|
||||
}
|
||||
if (source.contains("空气减排"))
|
||||
{
|
||||
return "SURCHARGE";
|
||||
}
|
||||
if (source.contains("偏远") || source.contains("岛屿"))
|
||||
{
|
||||
return "REMOTE";
|
||||
@@ -701,6 +715,15 @@ public class PayPostcodeImporter
|
||||
return "";
|
||||
}
|
||||
|
||||
/** 空气减排地区、空气减排地区邮编这一组,属性记为附加费,渠道记为 Evri 48H。 */
|
||||
private static boolean airReduction(ExcelGrid grid, int header, Series series)
|
||||
{
|
||||
String feeHead = series.feeCol >= 0 ? flat(grid.text(header, series.feeCol)) : "";
|
||||
String postHead = flat(grid.text(header, series.postcodeCol));
|
||||
String regionHead = series.regionCol >= 0 ? flat(grid.text(header, series.regionCol)) : "";
|
||||
return feeHead.contains("空气减排") || postHead.contains("空气减排") || regionHead.contains("空气减排");
|
||||
}
|
||||
|
||||
/**
|
||||
* 一个格子里用逗号写了多条邮编时拆开。两端都是完整邮编的区间写成起止,KA27-28 这种短区间保持原文。
|
||||
*/
|
||||
@@ -1182,6 +1205,8 @@ public class PayPostcodeImporter
|
||||
private String title = "";
|
||||
private String feeName = "";
|
||||
private String channel = "";
|
||||
private String coverage = "";
|
||||
private boolean air;
|
||||
private String zoneAbove = "";
|
||||
private String countryHint = "";
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import com.bms.price.domain.PayPostcodeGroup;
|
||||
@@ -133,6 +134,63 @@ public final class PayRemoteBook
|
||||
return hits;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渠道对得上、邮编前几位命中的附加费邮编。同一费用名只留一条。
|
||||
*/
|
||||
public static List<Hit> surchargeHits(List<PayPostcodeLine> lines, String postcode, String channelName, String channelCode,
|
||||
String productName)
|
||||
{
|
||||
List<Hit> hits = new ArrayList<>();
|
||||
if (lines == null || lines.isEmpty() || postcode == null || postcode.isBlank())
|
||||
{
|
||||
return hits;
|
||||
}
|
||||
Set<String> seen = new java.util.LinkedHashSet<>();
|
||||
for (PayPostcodeLine line : lines)
|
||||
{
|
||||
if (line == null || !channelOwns(line.getChannelName(), channelName, channelCode, productName)
|
||||
|| !PaySurchargeRules.matchesFeePostcode(line.getPostcode(), postcode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String feeName = line.getFeeName() == null ? "" : line.getFeeName().trim();
|
||||
if (!seen.add(feeName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String region = first(line.getRegionName(), line.getRegionNameCn());
|
||||
hits.add(new Hit(feeName, null, line.getZoneName(), region));
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
/** 服务渠道或价卡产品名对上邮编组上的渠道即可。Evri 48H 价卡挂在「UBI英国EVRi普」这类渠道上时仍能用。 */
|
||||
private static boolean channelOwns(String bookChannel, String channelName, String channelCode, String productName)
|
||||
{
|
||||
if (owns(bookChannel, channelName, channelCode))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return owns(bookChannel, productName, "");
|
||||
}
|
||||
|
||||
private static boolean owns(String bookChannel, String channelName, String channelCode)
|
||||
{
|
||||
PayPostcodeGroup probe = new PayPostcodeGroup();
|
||||
probe.setChannelName(bookChannel);
|
||||
List<PayPostcodeGroup> kept = PayPostcodeBooks.ownChannel(List.of(probe), channelName, channelCode);
|
||||
String book = bookChannel == null ? "" : bookChannel.trim();
|
||||
for (PayPostcodeGroup group : kept)
|
||||
{
|
||||
String name = group.getChannelName() == null ? "" : group.getChannelName().trim();
|
||||
if (book.equals(name))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static BigDecimal amountOf(String feeText)
|
||||
{
|
||||
if (feeText == null || feeText.isBlank())
|
||||
|
||||
@@ -32,6 +32,9 @@ public final class PaySurchargeRules
|
||||
/** 邮编已经落到这个分区,再按重量区间收取,例如英国高地 */
|
||||
public static final String ZONE = "ZONE";
|
||||
|
||||
/** 邮编落在应付邮编配置的附加费邮编里才收取,前几位按正则前缀匹配。 */
|
||||
public static final String FEE_POSTCODE = "FEE_POSTCODE";
|
||||
|
||||
private static final Pattern REMOTE_PREFIX = Pattern.compile("(\\d{1,5}(?:\\s*[、,,]\\s*\\d{1,5})*)\\s*邮编");
|
||||
|
||||
private static final Pattern RANGE = Pattern.compile("([A-Z]{1,2})(\\d{1,2})\\s*-\\s*(\\d{1,2})");
|
||||
@@ -54,6 +57,8 @@ public final class PaySurchargeRules
|
||||
|
||||
private static final Pattern KG = Pattern.compile("(?i)(\\d+(?:\\.\\d+)?)\\s*(?:kg|公斤|千克)");
|
||||
|
||||
private static final Pattern EXTRA_STEP = Pattern.compile("(?i)(?:每增加|每超过|每超出)\\s*(\\d+(?:\\.\\d+)?)\\s*(?:kg|公斤|千克)");
|
||||
|
||||
private PaySurchargeRules()
|
||||
{
|
||||
}
|
||||
@@ -149,6 +154,39 @@ public final class PaySurchargeRules
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应付邮编配置里的附加费邮编。去掉空格后,配置邮编是订单邮编的前几位,或订单前几位对上配置邮编,都算命中。
|
||||
*/
|
||||
public static boolean matchesFeePostcode(String configured, String postcode)
|
||||
{
|
||||
String book = compactPostcode(configured);
|
||||
String order = compactPostcode(postcode);
|
||||
if (book.length() < 2 || order.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (leading(book, order))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return order.length() >= 3 && leading(order, book);
|
||||
}
|
||||
|
||||
/** 前缀正则。quote 掉邮编里的符号,只认开头连续的几位。 */
|
||||
private static boolean leading(String prefix, String text)
|
||||
{
|
||||
return Pattern.compile("^" + Pattern.quote(prefix)).matcher(text).find();
|
||||
}
|
||||
|
||||
private static String compactPostcode(String value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return value.toUpperCase(Locale.ROOT).replaceAll("[^A-Z0-9]", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 应收订单附加费邮编命中:去掉全部空白后按连续串计费。
|
||||
* 如 PA2 8HA → PA28HA,并尝试 PA2/PA28 等外向码前缀,便于命中 PA20-49。
|
||||
@@ -557,6 +595,14 @@ public final class PaySurchargeRules
|
||||
/** 配置了长宽高时按三边箱规判断,否则仍认导入价卡里的尺寸表达式。 */
|
||||
public static boolean matchesFeeSize(PaySurcharge fee, BigDecimal length, BigDecimal width, BigDecimal height)
|
||||
{
|
||||
if (fee != null && "VOLUME".equalsIgnoreCase(fee.getSizeType()) && fee.getVolumeM3() != null)
|
||||
{
|
||||
if (length == null || width == null || height == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return cubicMetres(length, width, height).compareTo(fee.getVolumeM3()) > 0;
|
||||
}
|
||||
if (fee != null && fee.getLengthCm() != null && fee.getWidthCm() != null && fee.getHeightCm() != null)
|
||||
{
|
||||
if (length == null || width == null || height == null)
|
||||
@@ -578,6 +624,63 @@ public final class PaySurchargeRules
|
||||
return matchesWeight(fee == null ? null : fee.getCalcParam(), weight);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计费时使用的附加费。价卡绑定的附加费配置都参与判断,超重续收仍只用价卡上的每公斤续重。
|
||||
*
|
||||
* @param cardFees 订单日期那一版价卡上的费用行
|
||||
* @param bound 价卡已绑定且启用的附加费配置
|
||||
* @return 绑定配置里除超重续收以外的费用,再加上价卡续重
|
||||
*/
|
||||
public static List<PaySurcharge> surchargesForCalc(List<PaySurcharge> cardFees, List<PaySurcharge> bound)
|
||||
{
|
||||
List<PaySurcharge> 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)
|
||||
{
|
||||
@@ -603,6 +706,45 @@ public final class PaySurchargeRules
|
||||
}
|
||||
}
|
||||
|
||||
/** 续重计费步长。价卡写了每增加若干公斤时用该步长,否则按 1kg。 */
|
||||
public static BigDecimal extraStepKg(PaySurcharge fee)
|
||||
{
|
||||
if (fee != null)
|
||||
{
|
||||
String blob = (fee.getChargeText() == null ? "" : fee.getChargeText()) + " "
|
||||
+ (fee.getFeeDesc() == null ? "" : fee.getFeeDesc());
|
||||
Matcher matcher = EXTRA_STEP.matcher(blob);
|
||||
if (matcher.find())
|
||||
{
|
||||
try
|
||||
{
|
||||
BigDecimal step = new BigDecimal(matcher.group(1));
|
||||
if (step.compareTo(BigDecimal.ZERO) > 0)
|
||||
{
|
||||
return step;
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
return BigDecimal.ONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return BigDecimal.ONE;
|
||||
}
|
||||
|
||||
/** 超出起重后的续重档数。不足一个计重单位也按一整档收取。 */
|
||||
public static BigDecimal extraSteps(PaySurcharge fee, BigDecimal weight)
|
||||
{
|
||||
BigDecimal threshold = extraStartKg(fee);
|
||||
if (threshold == null || weight == null || weight.compareTo(threshold) <= 0)
|
||||
{
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal step = extraStepKg(fee);
|
||||
return weight.subtract(threshold).divide(step, 0, RoundingMode.CEILING);
|
||||
}
|
||||
|
||||
/** 命中邮编。独立字段优先,其次是原来的邮编列和导入文本。 */
|
||||
public static String feePostcodes(PaySurcharge fee)
|
||||
{
|
||||
@@ -856,6 +998,11 @@ public final class PaySurchargeRules
|
||||
return null;
|
||||
}
|
||||
|
||||
private static BigDecimal cubicMetres(BigDecimal length, BigDecimal width, BigDecimal height)
|
||||
{
|
||||
return length.multiply(width).multiply(height).divide(new BigDecimal("1000000"), 6, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
private static boolean exceedsBox(BigDecimal[] parcel, BigDecimal a, BigDecimal b, BigDecimal c)
|
||||
{
|
||||
BigDecimal[] limit = desc(a, b, c);
|
||||
|
||||
@@ -428,6 +428,8 @@ public class PayWorkbookParser
|
||||
copy.setCountryName(band.getCountryName());
|
||||
copy.setCountryCode(band.getCountryCode());
|
||||
copy.setZoneName(band.getZoneName());
|
||||
copy.setCalcRule(band.getCalcRule());
|
||||
copy.setCalcParam(band.getCalcParam());
|
||||
copy.setWeightLabel(band.getWeightLabel());
|
||||
copy.setWeightMin(band.getWeightMin());
|
||||
copy.setWeightMax(band.getWeightMax());
|
||||
@@ -1151,7 +1153,7 @@ public class PayWorkbookParser
|
||||
}
|
||||
if (isFeeRateHeader(grid, row))
|
||||
{
|
||||
row = readFeeRateTable(grid, row, product);
|
||||
row = isLineHaulHeader(grid, row) ? skipRateTable(grid, row) : readFeeRateTable(grid, row, product);
|
||||
pending = "";
|
||||
continue;
|
||||
}
|
||||
@@ -1234,12 +1236,12 @@ public class PayWorkbookParser
|
||||
}
|
||||
|
||||
/**
|
||||
* 和派送费同一版式,但表头是偏远附加费、额外线路运输费这类费用。按地区和重量记附加费,不进重量段。
|
||||
* 和派送费同一版式,但表头是偏远附加费、额外线路运输费。首重记进重量段,每增加 1kg 记该费用的续重价。
|
||||
*/
|
||||
private int readFeeRateTable(ExcelGrid grid, int header, PayProduct product)
|
||||
{
|
||||
int data = header + 1;
|
||||
int subHeader = -1;
|
||||
List<Integer> labelRows = new ArrayList<>();
|
||||
while (data < grid.rows() && !grid.blankRow(data) && !isHardHeader(grid, data))
|
||||
{
|
||||
if (countNumbers(grid, data) > 0 || rowHasWeight(grid, data))
|
||||
@@ -1248,17 +1250,20 @@ public class PayWorkbookParser
|
||||
}
|
||||
if (countText(grid, data) >= 2)
|
||||
{
|
||||
subHeader = data;
|
||||
labelRows.add(data);
|
||||
}
|
||||
data++;
|
||||
}
|
||||
int[] heads = countryAndZoneRows(grid, labelRows);
|
||||
int countryRow = heads[0];
|
||||
int zoneRow = heads[1];
|
||||
int[] kind = new int[grid.cols()];
|
||||
String[] parent = new String[grid.cols()];
|
||||
String[] sub = new String[grid.cols()];
|
||||
String carry = "";
|
||||
for (int col = 0; col < grid.cols(); col++)
|
||||
{
|
||||
if (strayColumn(grid, header, col, subHeader))
|
||||
if (strayColumn(grid, header, col, zoneRow))
|
||||
{
|
||||
parent[col] = "";
|
||||
sub[col] = "";
|
||||
@@ -1275,7 +1280,7 @@ public class PayWorkbookParser
|
||||
head = carry;
|
||||
}
|
||||
parent[col] = head;
|
||||
sub[col] = subHeader < 0 ? "" : grid.text(subHeader, col);
|
||||
sub[col] = zoneRow < 0 ? "" : spanned(grid, zoneRow, col);
|
||||
kind[col] = columnKind(head, numericBelow(grid, col, data));
|
||||
}
|
||||
int added = product.getSurcharges().size();
|
||||
@@ -1322,6 +1327,21 @@ 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))
|
||||
{
|
||||
String grouped = countryRow < 0 ? "" : countryAt(grid, countryRow, col);
|
||||
String prefixes = PaySurchargeRules.remotePrefixes(zone);
|
||||
String place = prefixes.isEmpty() ? zone : zoneWithoutPostcode(zone);
|
||||
if (stepWeight(weight))
|
||||
{
|
||||
addExtraKg(product, feeName, place, weight, price, firstLimit(product, feeName, place));
|
||||
}
|
||||
else
|
||||
{
|
||||
addZoneFeeBand(product, feeName, place, weight, price, parent[col], countryLabel(grouped), countryCodeOf(grouped), prefixes);
|
||||
}
|
||||
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, ""))
|
||||
@@ -1366,8 +1386,8 @@ public class PayWorkbookParser
|
||||
private int readPriceTable(ExcelGrid grid, int header, String pending, PayProduct product, StringBuilder note)
|
||||
{
|
||||
int data = header + 1;
|
||||
int subHeader = -1;
|
||||
String section = cleanTitle(pending);
|
||||
List<Integer> labelRows = new ArrayList<>();
|
||||
while (data < grid.rows() && !grid.blankRow(data) && !isHardHeader(grid, data))
|
||||
{
|
||||
if (countNumbers(grid, data) > 0 || rowHasWeight(grid, data))
|
||||
@@ -1376,7 +1396,7 @@ public class PayWorkbookParser
|
||||
}
|
||||
if (countText(grid, data) >= 2)
|
||||
{
|
||||
subHeader = data;
|
||||
labelRows.add(data);
|
||||
}
|
||||
else if (section.isEmpty())
|
||||
{
|
||||
@@ -1384,13 +1404,16 @@ public class PayWorkbookParser
|
||||
}
|
||||
data++;
|
||||
}
|
||||
int[] heads = countryAndZoneRows(grid, labelRows);
|
||||
int countryRow = heads[0];
|
||||
int zoneRow = heads[1];
|
||||
int[] kind = new int[grid.cols()];
|
||||
String[] parent = new String[grid.cols()];
|
||||
String[] sub = new String[grid.cols()];
|
||||
String carry = "";
|
||||
for (int col = 0; col < grid.cols(); col++)
|
||||
{
|
||||
if (strayColumn(grid, header, col, subHeader))
|
||||
if (strayColumn(grid, header, col, zoneRow))
|
||||
{
|
||||
parent[col] = "";
|
||||
sub[col] = "";
|
||||
@@ -1407,7 +1430,7 @@ public class PayWorkbookParser
|
||||
head = carry;
|
||||
}
|
||||
parent[col] = head;
|
||||
sub[col] = subHeader < 0 ? "" : grid.text(subHeader, col);
|
||||
sub[col] = zoneRow < 0 ? "" : spanned(grid, zoneRow, col);
|
||||
kind[col] = columnKind(head, numericBelow(grid, col, data));
|
||||
}
|
||||
if (section.isEmpty())
|
||||
@@ -1495,14 +1518,52 @@ public class PayWorkbookParser
|
||||
priced = true;
|
||||
if (isSurchargePriceHead(parent[col]))
|
||||
{
|
||||
addPricedSurcharge(product, blankTo(section, "价格"), parent[col], zoneOf(sub[col], parent[col]), weight, price);
|
||||
String feeName = chargeTitle(parent[col]);
|
||||
if (zoneFeeName(feeName))
|
||||
{
|
||||
String remoteCountry = country;
|
||||
String remoteCode = countryCode;
|
||||
if (countryRow >= 0)
|
||||
{
|
||||
String grouped = countryAt(grid, countryRow, col);
|
||||
if (!grouped.isBlank())
|
||||
{
|
||||
remoteCountry = countryLabel(grouped);
|
||||
remoteCode = countryCodeOf(grouped);
|
||||
}
|
||||
}
|
||||
addZoneFeeBand(product, feeName, zoneOf(sub[col], parent[col]), weight, price, parent[col],
|
||||
remoteCountry, remoteCode, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
addPricedSurcharge(product, blankTo(section, "价格"), parent[col], zoneOf(sub[col], parent[col]), weight, price);
|
||||
}
|
||||
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;
|
||||
}
|
||||
String bandCountry = country;
|
||||
String bandCode = countryCode;
|
||||
if (countryRow >= 0)
|
||||
{
|
||||
String grouped = countryAt(grid, countryRow, col);
|
||||
if (!grouped.isBlank())
|
||||
{
|
||||
bandCountry = countryLabel(grouped);
|
||||
bandCode = countryCodeOf(grouped);
|
||||
}
|
||||
}
|
||||
PayWeightBand band = new PayWeightBand();
|
||||
band.setSectionName(blankTo(section, "价格"));
|
||||
band.setCountryName(country);
|
||||
band.setCountryCode(countryCode);
|
||||
band.setCountryName(bandCountry);
|
||||
band.setCountryCode(bandCode);
|
||||
band.setWeightLabel(weight);
|
||||
BigDecimal[] bounds = PayTexts.weightBounds(weight);
|
||||
band.setWeightMin(bounds[0]);
|
||||
@@ -2119,18 +2180,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 +2201,271 @@ public class PayWorkbookParser
|
||||
product.getSurcharges().add(fee);
|
||||
}
|
||||
|
||||
/** 分区里的“07邮编开头”“35、38邮编开头”拆出去,地区名单独留下。 */
|
||||
private static String zoneWithoutPostcode(String zone)
|
||||
{
|
||||
if (zone == null || zone.isBlank())
|
||||
{
|
||||
return zone;
|
||||
}
|
||||
String cleaned = zone.replaceAll("\\d+(?:[、,,\\s]+\\d+)*\\s*邮编开头", "");
|
||||
cleaned = cleaned.replaceAll("\\s+", " ").trim();
|
||||
return cleaned.isEmpty() ? zone : cleaned;
|
||||
}
|
||||
|
||||
/** 偏远附加费的首重记进重量段。邮编写成计费条件,分区只留地区名。 */
|
||||
private static void addZoneFeeBand(PayProduct product, String feeName, String zone, String weight, BigDecimal price, String head,
|
||||
String country, String countryCode, String postcodeParam)
|
||||
{
|
||||
PayWeightBand band = new PayWeightBand();
|
||||
band.setSectionName(feeName);
|
||||
band.setCountryName(country == null || country.isBlank() ? null : country);
|
||||
band.setCountryCode(countryCode == null || countryCode.isBlank() ? null : countryCode);
|
||||
band.setZoneName(zone);
|
||||
if (postcodeParam != null && !postcodeParam.isBlank())
|
||||
{
|
||||
band.setCalcRule(PaySurchargeRules.POSTCODE);
|
||||
band.setCalcParam(postcodeParam);
|
||||
}
|
||||
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)
|
||||
{
|
||||
return name != null && name.contains("偏远");
|
||||
}
|
||||
|
||||
/** 表头下先是国家、再是分区时两行都认。只有一行时当作分区。 */
|
||||
private static int[] countryAndZoneRows(ExcelGrid grid, List<Integer> labelRows)
|
||||
{
|
||||
int country = -1;
|
||||
int zone = labelRows == null || labelRows.isEmpty() ? -1 : labelRows.get(labelRows.size() - 1);
|
||||
if (labelRows != null && labelRows.size() >= 2 && countryGroupRow(grid, labelRows.get(0)))
|
||||
{
|
||||
country = labelRows.get(0);
|
||||
}
|
||||
return new int[] { country, zone };
|
||||
}
|
||||
|
||||
private static boolean countryGroupRow(ExcelGrid grid, int row)
|
||||
{
|
||||
int countries = 0;
|
||||
for (int col = 0; col < grid.cols(); col++)
|
||||
{
|
||||
String text = spanned(grid, row, col);
|
||||
if (text.isBlank())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (zoneMarker(text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (countryWord(text))
|
||||
{
|
||||
countries++;
|
||||
}
|
||||
}
|
||||
return countries >= 1;
|
||||
}
|
||||
|
||||
private static boolean countryWord(String text)
|
||||
{
|
||||
String lower = text.toLowerCase(Locale.ROOT);
|
||||
return text.contains("西班牙") || text.contains("葡萄牙") || text.contains("英国") || text.contains("法国")
|
||||
|| text.contains("德国") || text.contains("意大利") || text.contains("荷兰")
|
||||
|| lower.contains("spain") || lower.contains("portugal");
|
||||
}
|
||||
|
||||
private static boolean zoneMarker(String text)
|
||||
{
|
||||
String lower = text.toLowerCase(Locale.ROOT);
|
||||
return text.contains("地区") || text.contains("邮编") || text.contains("密度")
|
||||
|| lower.contains("density") || lower.contains("island") || lower.contains("mainland");
|
||||
}
|
||||
|
||||
private static String countryLabel(String country)
|
||||
{
|
||||
if (country == null || country.isBlank())
|
||||
{
|
||||
return country;
|
||||
}
|
||||
String code = countryCodeOf(country);
|
||||
if (code.isEmpty() || country.contains("("))
|
||||
{
|
||||
return country;
|
||||
}
|
||||
return country + "(" + code + ")";
|
||||
}
|
||||
|
||||
private static String countryCodeOf(String country)
|
||||
{
|
||||
if (country == null || country.isBlank())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if (country.contains("西班牙") || country.toLowerCase(Locale.ROOT).contains("spain"))
|
||||
{
|
||||
return "ES";
|
||||
}
|
||||
if (country.contains("葡萄牙") || country.toLowerCase(Locale.ROOT).contains("portugal"))
|
||||
{
|
||||
return "PT";
|
||||
}
|
||||
if (country.contains("英国"))
|
||||
{
|
||||
return "GB";
|
||||
}
|
||||
if (country.contains("法国"))
|
||||
{
|
||||
return "FR";
|
||||
}
|
||||
if (country.contains("德国"))
|
||||
{
|
||||
return "DE";
|
||||
}
|
||||
if (country.contains("意大利"))
|
||||
{
|
||||
return "IT";
|
||||
}
|
||||
if (country.contains("荷兰"))
|
||||
{
|
||||
return "NL";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/** 国家表头按列向左找到这一列所属国家。合并格和只写在左上角的国家都能认到。 */
|
||||
private static String countryAt(ExcelGrid grid, int row, int col)
|
||||
{
|
||||
if (row < 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
String own = spanned(grid, row, col);
|
||||
if (!own.isBlank())
|
||||
{
|
||||
return own;
|
||||
}
|
||||
for (int left = col - 1; left >= 0; left--)
|
||||
{
|
||||
String text = spanned(grid, row, left);
|
||||
if (text.isBlank())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return countryWord(text) ? text : "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/** 合并单元格只在左上角有字,右侧列沿用这一格。 */
|
||||
private static String spanned(ExcelGrid grid, int row, int col)
|
||||
{
|
||||
String text = grid.text(row, col).replace('\n', ' ').replaceAll("\\s+", " ").trim();
|
||||
if (!text.isBlank())
|
||||
{
|
||||
return text;
|
||||
}
|
||||
for (int left = col - 1; left >= 0; left--)
|
||||
{
|
||||
if (grid.colSpan(row, left) > 1 && left + grid.colSpan(row, left) - 1 >= col)
|
||||
{
|
||||
return grid.text(row, left).replace('\n', ' ').replaceAll("\\s+", " ").trim();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static boolean isLineHaulHeader(ExcelGrid grid, int row)
|
||||
{
|
||||
for (int col = 0; col < grid.cols(); col++)
|
||||
{
|
||||
String text = grid.text(row, col).toLowerCase(Locale.ROOT);
|
||||
if (text.contains("line-haul") || text.contains("linehaul") || text.contains("额外线路") || text.contains("额外路线"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 额外线路运输费整表跳过,留到下一块表头。 */
|
||||
private int skipRateTable(ExcelGrid grid, int header)
|
||||
{
|
||||
int data = header + 1;
|
||||
while (data < grid.rows() && !grid.blankRow(data) && !isHardHeader(grid, data))
|
||||
{
|
||||
if (countNumbers(grid, data) > 0 || rowHasWeight(grid, data))
|
||||
{
|
||||
break;
|
||||
}
|
||||
data++;
|
||||
}
|
||||
while (data < grid.rows() && !grid.blankRow(data) && !isHardHeader(grid, data))
|
||||
{
|
||||
data++;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -4288,7 +4615,7 @@ public class PayWorkbookParser
|
||||
}
|
||||
}
|
||||
|
||||
/** 价格表里和派送费并排的偏远列,按分区和重量区间记附加费,不进重量段。 */
|
||||
/** 价格表里和派送费并排、又不是偏远的费用列,按分区和重量区间记附加费。偏远列记进重量段。 */
|
||||
private void addPricedSurcharge(PayProduct product, String section, String head, String zone, String weight, BigDecimal price)
|
||||
{
|
||||
String feeName = shortCharge(head);
|
||||
|
||||
@@ -10,7 +10,7 @@ public interface IPayPostcodeService
|
||||
{
|
||||
List<PayPostcodeGroup> selectGroupList(PayPostcodeGroup query);
|
||||
|
||||
/** 每个国家一行:邮编属性、服务类型、销售产品、渠道、分区数、邮编总数、导入时间 */
|
||||
/** 每个国家一行:渠道多个时用顿号分隔。分区在抽屉里按渠道分开 */
|
||||
List<PayPostcodeGroup> selectCountryList(PayPostcodeGroup query);
|
||||
|
||||
/** 一个国家下面的分区,同一分区名只出现一行 */
|
||||
|
||||
+47
-11
@@ -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,13 +134,14 @@ 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<PayPostcodeGroup> linked = linkedGroups(product);
|
||||
List<PayPostcodeGroup> linked = linkedGroups(product, channel);
|
||||
String zoneName = resolveZone(channel, product, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), linked);
|
||||
applyCurrentSurcharge(channel.getId(), product);
|
||||
List<PayRemoteBook.Hit> remoteHits = remoteHits(linked, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName());
|
||||
List<PayRemoteBook.Hit> remoteHits = remoteHits(linked, bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), channel);
|
||||
List<PayRemoteBook.Hit> surchargeHits = surchargeHits(bill.getDestPostcode(), bill.getCountryCode(), bill.getCountryName(), channel, product);
|
||||
PayOrderCostResult result = PayCostCalculator.calculate(product, weight, bill.getPkgLength(), bill.getPkgWidth(),
|
||||
bill.getPkgHeight(), bill.getDestPostcode(), zoneName, bizDate, orderStatus, remoteHits, true, true,
|
||||
bill.getCountryCode(), bill.getCountryName());
|
||||
bill.getCountryCode(), bill.getCountryName(), surchargeHits);
|
||||
result.setBillId(bill.getBillId());
|
||||
result.setChannelId(channel.getId());
|
||||
result.setChannelName(channel.getChannelName());
|
||||
@@ -216,7 +218,7 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
|
||||
* @param product 当前价卡版本
|
||||
* @return 名称能对上的邮编组,没有时为空列表
|
||||
*/
|
||||
/** 运费仍按订单日期取版本。附加费只取该价卡产品已绑定且启用的附加费配置。 */
|
||||
/** 运费按订单日期的重量段。附加费取已绑定的配置,超重续收只用价卡上按分区写的续重单价。 */
|
||||
private void applyCurrentSurcharge(String channelId, PayProduct priced)
|
||||
{
|
||||
PayProduct source = priced;
|
||||
@@ -232,10 +234,11 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
|
||||
{
|
||||
// 今天没有生效版本时,改查订单日期命中的那一版有没有绑定
|
||||
}
|
||||
priced.setSurcharges(payProductService.boundSurcharges(source));
|
||||
priced.setSurcharges(PaySurchargeRules.surchargesForCalc(priced.getSurcharges(),
|
||||
payProductService.boundSurcharges(source)));
|
||||
}
|
||||
|
||||
private List<PayPostcodeGroup> linkedGroups(PayProduct product)
|
||||
private List<PayPostcodeGroup> linkedGroups(PayProduct product, ServiceChannel channel)
|
||||
{
|
||||
List<String> names = new ArrayList<>();
|
||||
addName(names, product.getProductName());
|
||||
@@ -247,7 +250,7 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<PayPostcodeGroup> found = payPostcodeMapper.selectGroupsForProduct(names);
|
||||
return found == null ? new ArrayList<>() : found;
|
||||
return PayPostcodeBooks.ownChannel(found, channel.getChannelName(), channel.getChannelCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,7 +282,8 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
|
||||
* @param countryName 目的国名称
|
||||
* @return 命中的偏远分区;产品有名单但没命中时返回空列表
|
||||
*/
|
||||
private List<PayRemoteBook.Hit> remoteHits(List<PayPostcodeGroup> linked, String postcode, String countryCode, String countryName)
|
||||
private List<PayRemoteBook.Hit> remoteHits(List<PayPostcodeGroup> linked, String postcode, String countryCode, String countryName,
|
||||
ServiceChannel channel)
|
||||
{
|
||||
boolean productBook = false;
|
||||
for (PayPostcodeGroup group : linked)
|
||||
@@ -298,8 +302,10 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<PayPostcodeGroup> countryGroups = payPostcodeMapper.selectRemoteGroupsByCountry(countryCode, countryName);
|
||||
if (countryGroups == null || countryGroups.isEmpty())
|
||||
List<PayPostcodeGroup> countryGroups = PayPostcodeBooks.ownChannel(
|
||||
payPostcodeMapper.selectRemoteGroupsByCountry(countryCode, countryName),
|
||||
channel.getChannelName(), channel.getChannelCode());
|
||||
if (countryGroups.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -307,6 +313,34 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
|
||||
return hits == null || hits.isEmpty() ? null : hits;
|
||||
}
|
||||
|
||||
/**
|
||||
* EVRI 渠道按应付邮编配置里的附加费邮编判断。前几位对上时,返回对应的费用名。
|
||||
*/
|
||||
private List<PayRemoteBook.Hit> surchargeHits(String postcode, String countryCode, String countryName, ServiceChannel channel,
|
||||
PayProduct product)
|
||||
{
|
||||
String productName = product == null ? "" : product.getProductName();
|
||||
if (channel == null || postcode == null || postcode.isBlank() || !evriChannel(channel, productName))
|
||||
{
|
||||
return new ArrayList<>();
|
||||
}
|
||||
String compact = postcode.toUpperCase(Locale.ROOT).replaceAll("[^A-Z0-9]", "");
|
||||
if (compact.length() < 2)
|
||||
{
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<PayPostcodeLine> lines = payPostcodeMapper.selectSurchargeLines(countryCode, countryName, compact);
|
||||
return PayRemoteBook.surchargeHits(lines, postcode, channel.getChannelName(), channel.getChannelCode(), productName);
|
||||
}
|
||||
|
||||
private static boolean evriChannel(ServiceChannel channel, String productName)
|
||||
{
|
||||
String blob = ((channel.getChannelName() == null ? "" : channel.getChannelName()) + " "
|
||||
+ (channel.getChannelCode() == null ? "" : channel.getChannelCode()) + " "
|
||||
+ (productName == null ? "" : productName)).toLowerCase(Locale.ROOT);
|
||||
return blob.contains("evri");
|
||||
}
|
||||
|
||||
/** 在给定邮编组里做偏远匹配。没有偏远组时返回 null,有组但邮编没命中时返回空列表。 */
|
||||
private List<PayRemoteBook.Hit> hitsOf(List<PayPostcodeGroup> groups, String postcode, String countryCode, String countryName)
|
||||
{
|
||||
@@ -380,6 +414,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);
|
||||
@@ -481,7 +516,8 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ("UNREACH".equalsIgnoreCase(group.getCoverage() == null ? "" : group.getCoverage().trim()))
|
||||
String coverage = group.getCoverage() == null ? "" : group.getCoverage().trim();
|
||||
if ("UNREACH".equalsIgnoreCase(coverage) || "SURCHARGE".equalsIgnoreCase(coverage))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
+132
-1
@@ -3,9 +3,11 @@ package com.bms.price.service.impl;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -13,10 +15,13 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.bms.common.core.domain.entity.SysUser;
|
||||
import com.bms.common.enums.PaymentMesEnum;
|
||||
import com.bms.common.exception.ServiceException;
|
||||
import com.bms.common.utils.SecurityUtils;
|
||||
import com.bms.common.utils.uuid.IdUtils;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.bms.price.domain.PayOrderCostResult;
|
||||
import com.bms.price.domain.PayOrderFeeBoard;
|
||||
import com.bms.price.domain.PrcPayBill;
|
||||
@@ -97,7 +102,133 @@ public class PayOrderListServiceImpl implements IPayOrderListService
|
||||
safe.setOrderNos(null);
|
||||
safe.setOrderNo(orderNos.isEmpty() ? null : orderNos.get(0));
|
||||
}
|
||||
return payOrderListMapper.selectList(safe);
|
||||
List<Long> billIds = payOrderListMapper.selectPageIds(safe);
|
||||
PageHelper.clearPage();
|
||||
Page<PayOrderRow> page = new Page<>();
|
||||
if (billIds instanceof Page<?> source)
|
||||
{
|
||||
page.setTotal(source.getTotal());
|
||||
page.setPageNum(source.getPageNum());
|
||||
page.setPageSize(source.getPageSize());
|
||||
}
|
||||
if (billIds == null || billIds.isEmpty())
|
||||
{
|
||||
return page;
|
||||
}
|
||||
Map<String, PayOrderRow> byId = new HashMap<>();
|
||||
for (PayOrderRow row : payOrderListMapper.selectByBillIds(billIds))
|
||||
{
|
||||
if (row != null && row.getBillId() != null)
|
||||
{
|
||||
byId.put(row.getBillId().trim(), row);
|
||||
}
|
||||
}
|
||||
for (Long billId : billIds)
|
||||
{
|
||||
PayOrderRow row = byId.get(String.valueOf(billId));
|
||||
if (row != null)
|
||||
{
|
||||
page.add(row);
|
||||
}
|
||||
}
|
||||
fillOperators(page);
|
||||
return page;
|
||||
}
|
||||
|
||||
/** 只给当前页解析更新人。system 显示系统自动,数字主键取昵称,其余按账号取昵称。 */
|
||||
private void fillOperators(List<PayOrderRow> rows)
|
||||
{
|
||||
List<Long> userIds = new ArrayList<>();
|
||||
List<String> userNames = new ArrayList<>();
|
||||
for (PayOrderRow row : rows)
|
||||
{
|
||||
String raw = row.getUpdateBy();
|
||||
if (raw == null || raw.isBlank())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ("system".equalsIgnoreCase(raw.trim()))
|
||||
{
|
||||
row.setUpdateBy("系统自动");
|
||||
continue;
|
||||
}
|
||||
if (raw.matches("^[0-9]+$"))
|
||||
{
|
||||
try
|
||||
{
|
||||
userIds.add(Long.parseLong(raw));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
userNames.add(raw);
|
||||
}
|
||||
}
|
||||
if (userIds.isEmpty() && userNames.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Map<Long, String> byUserId = new HashMap<>();
|
||||
Map<String, String> byUserName = new HashMap<>();
|
||||
for (SysUser user : payOrderListMapper.selectUsers(userIds, userNames))
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String label = operatorLabel(user);
|
||||
if (user.getUserId() != null && !byUserId.containsKey(user.getUserId()))
|
||||
{
|
||||
byUserId.put(user.getUserId(), label);
|
||||
}
|
||||
if (user.getUserName() != null && !user.getUserName().isBlank())
|
||||
{
|
||||
byUserName.putIfAbsent(user.getUserName().toLowerCase(Locale.ROOT), label);
|
||||
}
|
||||
}
|
||||
for (PayOrderRow row : rows)
|
||||
{
|
||||
String raw = row.getUpdateBy();
|
||||
if (raw == null || raw.isBlank() || "系统自动".equals(raw))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String label = null;
|
||||
if (raw.matches("^[0-9]+$"))
|
||||
{
|
||||
try
|
||||
{
|
||||
label = byUserId.get(Long.parseLong(raw));
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
label = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
label = byUserName.get(raw.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
if (label != null && !label.isBlank())
|
||||
{
|
||||
row.setUpdateBy(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 有昵称用昵称,没有就用账号。和原来列表里的更新人显示一致。 */
|
||||
private static String operatorLabel(SysUser user)
|
||||
{
|
||||
String nick = user.getNickName() == null ? "" : user.getNickName().trim();
|
||||
if (!nick.isEmpty())
|
||||
{
|
||||
return user.getNickName();
|
||||
}
|
||||
return user.getUserName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
-3
@@ -46,6 +46,7 @@ public class PayPostcodeServiceImpl implements IPayPostcodeService
|
||||
public List<PayPostcodeGroup> 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<Long> ids = payPostcodeMapper.selectGroupIdsByCountry(country);
|
||||
if (ids == null || ids.isEmpty())
|
||||
{
|
||||
@@ -397,7 +399,7 @@ public class PayPostcodeServiceImpl implements IPayPostcodeService
|
||||
private static String normalizeCoverage(String value)
|
||||
{
|
||||
String coverage = trimToEmpty(value).toUpperCase(java.util.Locale.ROOT);
|
||||
if (coverage.isEmpty() || "REACH".equals(coverage) || "UNREACH".equals(coverage) || "REMOTE".equals(coverage))
|
||||
if (coverage.isEmpty() || "REACH".equals(coverage) || "UNREACH".equals(coverage) || "REMOTE".equals(coverage) || "SURCHARGE".equals(coverage))
|
||||
{
|
||||
return coverage;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+44
-7
@@ -51,6 +51,7 @@ import com.bms.price.mapper.PrcPriceSetMapper;
|
||||
import com.bms.price.mapper.PrcSurchargeBindMapper;
|
||||
import com.bms.price.mapper.PrcSurchargeMapper;
|
||||
import com.bms.price.pay.PayParseProgressListener;
|
||||
import com.bms.price.pay.PaySurchargeRules;
|
||||
import com.bms.price.pay.PayChargeMode;
|
||||
import com.bms.price.pay.PayTemplateWorkbook;
|
||||
import com.bms.price.pay.PayWorkbookParser;
|
||||
@@ -1045,13 +1046,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<PaySurcharge> enabledBinds(Long productId, String type, String currency)
|
||||
{
|
||||
List<PaySurcharge> 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;
|
||||
}
|
||||
@@ -1119,10 +1134,18 @@ public class PayProductServiceImpl implements IPayProductService
|
||||
String currency = isBlank(fee.getCurrency()) ? DEFAULT_CURRENCY : fee.getCurrency();
|
||||
if ("SIZE".equals(rule))
|
||||
{
|
||||
BigDecimal length = positive(config.getLengthCm(), fee.getFeeName() + "的长");
|
||||
BigDecimal width = positive(config.getWidthCm(), fee.getFeeName() + "的宽");
|
||||
BigDecimal height = positive(config.getHeightCm(), fee.getFeeName() + "的高");
|
||||
fee.setChargeText("超过 " + plain(length) + "×" + plain(width) + "×" + plain(height) + "cm");
|
||||
if ("VOLUME".equalsIgnoreCase(config.getSizeType()))
|
||||
{
|
||||
BigDecimal volume = positive(config.getVolumeM3(), fee.getFeeName() + "的体积");
|
||||
fee.setChargeText("体积超过 " + plain(volume) + "m³");
|
||||
}
|
||||
else
|
||||
{
|
||||
BigDecimal length = positive(config.getLengthCm(), fee.getFeeName() + "的长");
|
||||
BigDecimal width = positive(config.getWidthCm(), fee.getFeeName() + "的宽");
|
||||
BigDecimal height = positive(config.getHeightCm(), fee.getFeeName() + "的高");
|
||||
fee.setChargeText("任一边超过 " + plain(length) + "×" + plain(width) + "×" + plain(height) + "cm");
|
||||
}
|
||||
fee.setPriceUnit(currency + "/ITEM");
|
||||
return;
|
||||
}
|
||||
@@ -1151,6 +1174,12 @@ public class PayProductServiceImpl implements IPayProductService
|
||||
fee.setPriceUnit(currency + "/ITEM");
|
||||
return;
|
||||
}
|
||||
if (PaySurchargeRules.FEE_POSTCODE.equals(rule))
|
||||
{
|
||||
fee.setChargeText("邮编命中应付邮编配置中的附加费");
|
||||
fee.setPriceUnit(currency + "/ITEM");
|
||||
return;
|
||||
}
|
||||
fee.setPriceUnit(currency + "/ITEM");
|
||||
fee.setChargeText(isBlank(fee.getFeeDesc()) ? "" : cut(fee.getFeeDesc(), 500));
|
||||
}
|
||||
@@ -1195,14 +1224,19 @@ public class PayProductServiceImpl implements IPayProductService
|
||||
fee.setLengthCm(bind.getLengthCm());
|
||||
fee.setWidthCm(bind.getWidthCm());
|
||||
fee.setHeightCm(bind.getHeightCm());
|
||||
fee.setSizeType(bind.getSizeType());
|
||||
fee.setVolumeM3(bind.getVolumeM3());
|
||||
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());
|
||||
config.setWidthCm(bind.getWidthCm());
|
||||
config.setHeightCm(bind.getHeightCm());
|
||||
config.setSizeType(bind.getSizeType());
|
||||
config.setVolumeM3(bind.getVolumeM3());
|
||||
config.setOverWeightKg(bind.getOverWeightKg());
|
||||
config.setExtraWeightKg(bind.getExtraWeightKg());
|
||||
config.setPostcodeText(bind.getPostcodeText());
|
||||
@@ -1250,7 +1284,8 @@ public class PayProductServiceImpl implements IPayProductService
|
||||
return "MANUAL";
|
||||
}
|
||||
if ("ALWAYS".equals(code) || "POSTCODE".equals(code) || "ZONE".equals(code) || "EXTRA_KG".equals(code)
|
||||
|| "WEIGHT".equals(code) || "SIZE".equals(code) || "RETURN".equals(code) || "MANUAL".equals(code))
|
||||
|| "WEIGHT".equals(code) || "SIZE".equals(code) || "RETURN".equals(code) || "MANUAL".equals(code)
|
||||
|| PaySurchargeRules.FEE_POSTCODE.equals(code))
|
||||
{
|
||||
return code;
|
||||
}
|
||||
@@ -2173,6 +2208,8 @@ public class PayProductServiceImpl implements IPayProductService
|
||||
band.setCountryName(cut(band.getCountryName(), 200));
|
||||
band.setCountryCode(cut(band.getCountryCode(), 32));
|
||||
band.setZoneName(cut(band.getZoneName(), 200));
|
||||
band.setCalcRule(cut(band.getCalcRule(), 32));
|
||||
band.setCalcParam(cut(band.getCalcParam(), 1000));
|
||||
band.setWeightLabel(cut(band.getWeightLabel(), 100));
|
||||
band.setVolumeText(cut(band.getVolumeText(), 40));
|
||||
band.setChargeName(cut(band.getChargeName(), 200));
|
||||
|
||||
+7
-1
@@ -490,8 +490,14 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.bill.notFound"));
|
||||
}
|
||||
return toResult(bill, incomeBillFeeMapper.selectByBillId(bill.getBillId()),
|
||||
TmsPriceQuoteResult result = toResult(bill, incomeBillFeeMapper.selectByBillId(bill.getBillId()),
|
||||
payBillFeeMapper.selectByBillId(bill.getBillId()));
|
||||
PrcPayBill payBill = payBillMapper.selectByBillId(bill.getBillId());
|
||||
if (payBill != null && payBill.getPayTotal() != null)
|
||||
{
|
||||
result.setPayTotal(payBill.getPayTotal());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+44
-4
@@ -10,6 +10,7 @@ import com.bms.common.exception.ServiceException;
|
||||
import com.bms.common.utils.MessageUtils;
|
||||
import com.bms.common.utils.StringUtils;
|
||||
import com.bms.price.domain.PrcSurcharge;
|
||||
import com.bms.price.pay.PaySurchargeRules;
|
||||
import com.bms.price.mapper.PrcSurchargeBindMapper;
|
||||
import com.bms.price.mapper.PrcSurchargeMapper;
|
||||
import com.bms.price.mapper.PrcSurchargeRelMapper;
|
||||
@@ -96,6 +97,8 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
|
||||
fresh.setLengthCm(surcharge.getLengthCm());
|
||||
fresh.setWidthCm(surcharge.getWidthCm());
|
||||
fresh.setHeightCm(surcharge.getHeightCm());
|
||||
fresh.setSizeType(surcharge.getSizeType());
|
||||
fresh.setVolumeM3(surcharge.getVolumeM3());
|
||||
fresh.setOverWeightKg(surcharge.getOverWeightKg());
|
||||
fresh.setExtraWeightKg(surcharge.getExtraWeightKg());
|
||||
fresh.setPostcodeText(surcharge.getPostcodeText());
|
||||
@@ -125,6 +128,8 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
|
||||
&& eqDecimal(old.getLengthCm(), updated.getLengthCm())
|
||||
&& eqDecimal(old.getWidthCm(), updated.getWidthCm())
|
||||
&& eqDecimal(old.getHeightCm(), updated.getHeightCm())
|
||||
&& eq(old.getSizeType(), updated.getSizeType())
|
||||
&& eqDecimal(old.getVolumeM3(), updated.getVolumeM3())
|
||||
&& eqDecimal(old.getOverWeightKg(), updated.getOverWeightKg())
|
||||
&& eqDecimal(old.getExtraWeightKg(), updated.getExtraWeightKg())
|
||||
&& eq(old.getPostcodeText(), updated.getPostcodeText())
|
||||
@@ -226,11 +231,21 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
|
||||
BigDecimal overWeight = null;
|
||||
BigDecimal extraWeight = null;
|
||||
String postcodes = null;
|
||||
String sizeType = null;
|
||||
BigDecimal volume = null;
|
||||
if ("SIZE".equals(type))
|
||||
{
|
||||
length = requiredSize(row.getLengthCm(), "长");
|
||||
width = requiredSize(row.getWidthCm(), "宽");
|
||||
height = requiredSize(row.getHeightCm(), "高");
|
||||
sizeType = requiredSizeType(row.getSizeType());
|
||||
if ("VOLUME".equals(sizeType))
|
||||
{
|
||||
volume = requiredSize(row.getVolumeM3(), "体积");
|
||||
}
|
||||
else
|
||||
{
|
||||
length = requiredSize(row.getLengthCm(), "长");
|
||||
width = requiredSize(row.getWidthCm(), "宽");
|
||||
height = requiredSize(row.getHeightCm(), "高");
|
||||
}
|
||||
row.setBlockTitle(null);
|
||||
}
|
||||
else if ("WEIGHT".equals(type))
|
||||
@@ -259,11 +274,32 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
|
||||
row.setLengthCm(length);
|
||||
row.setWidthCm(width);
|
||||
row.setHeightCm(height);
|
||||
row.setSizeType(sizeType);
|
||||
row.setVolumeM3(volume);
|
||||
row.setOverWeightKg(overWeight);
|
||||
row.setExtraWeightKg(extraWeight);
|
||||
row.setPostcodeText(postcodes);
|
||||
}
|
||||
|
||||
private static String requiredSizeType(String raw)
|
||||
{
|
||||
String code = raw == null ? "" : raw.trim().toUpperCase();
|
||||
if (!"SIDE".equals(code) && !"VOLUME".equals(code))
|
||||
{
|
||||
throw new ServiceException("请选择超尺寸类型");
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
private static String sizeChargeText(String sizeType, BigDecimal length, BigDecimal width, BigDecimal height, BigDecimal volume)
|
||||
{
|
||||
if ("VOLUME".equals(sizeType))
|
||||
{
|
||||
return "体积超过 " + plain(volume) + "m³";
|
||||
}
|
||||
return "任一边超过 " + plain(length) + "×" + plain(width) + "×" + plain(height) + "cm";
|
||||
}
|
||||
|
||||
private static BigDecimal requiredSize(BigDecimal value, String label)
|
||||
{
|
||||
if (value == null || value.compareTo(BigDecimal.ZERO) <= 0)
|
||||
@@ -321,7 +357,7 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
|
||||
String text;
|
||||
if ("SIZE".equals(rule))
|
||||
{
|
||||
text = "超过 " + plain(row.getLengthCm()) + "×" + plain(row.getWidthCm()) + "×" + plain(row.getHeightCm()) + "cm";
|
||||
text = sizeChargeText(row.getSizeType(), row.getLengthCm(), row.getWidthCm(), row.getHeightCm(), row.getVolumeM3());
|
||||
}
|
||||
else if ("WEIGHT".equals(rule))
|
||||
{
|
||||
@@ -335,6 +371,10 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
|
||||
{
|
||||
text = "邮编 " + (row.getPostcodeText() == null ? "" : row.getPostcodeText());
|
||||
}
|
||||
else if (PaySurchargeRules.FEE_POSTCODE.equals(rule))
|
||||
{
|
||||
text = "邮编命中应付邮编配置中的附加费";
|
||||
}
|
||||
else
|
||||
{
|
||||
text = row.getScNote() == null ? "" : row.getScNote();
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class ArBillWorkbookWriters {
|
||||
public static final String SUMMARY_TEMPLATE_CODE = "AR_BILL_SUMMARY";
|
||||
public static final String GUANGZHOU_TEMPLATE_CODE = "AR_BILL_GZ";
|
||||
public static final String JIYUN_TEMPLATE_CODE = "AR_BILL_JY";
|
||||
private final DefaultArBillWorkbookWriter defaultWriter;
|
||||
private final SummaryArBillWorkbookWriter summaryWriter;
|
||||
|
||||
|
||||
+55
-24
@@ -31,7 +31,7 @@ import com.bms.receivable.domain.ArBillDetail;
|
||||
import com.bms.receivable.domain.ArBillDetailFee;
|
||||
import com.bms.receivable.domain.ArExportTemplate;
|
||||
|
||||
/** 默认应收账单模板的 21 列明细及银行页脚排版。 */
|
||||
/** 默认、广州及集运应收账单模板共用的 21 列明细和银行页脚排版。 */
|
||||
@Component
|
||||
public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
private static final int TEMPLATE_DATA_START_ROW = 5;
|
||||
@@ -49,7 +49,6 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
private static final double MIN_TRACKING_NO_COLUMN_WIDTH = MIN_CUSTOMER_ORDER_NO_COLUMN_WIDTH;
|
||||
private static final double MIN_FORMULA_COLUMN_WIDTH = 17.0;
|
||||
private static final double MIN_FEE_TYPE_COLUMN_WIDTH = 10.0;
|
||||
private static final int TEMPLATE_DETAIL_STYLE_INDEX = 31;
|
||||
private static final String TEMPLATE_SHEET_XML = "xl/worksheets/sheet1.xml";
|
||||
private static final String TEMPLATE_SHEET_RELATIONSHIPS_XML = "xl/worksheets/_rels/sheet1.xml.rels";
|
||||
private static final String TEMPLATE_STYLES_XML = "xl/styles.xml";
|
||||
@@ -68,7 +67,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
private static final Pattern MERGE_REF_PATTERN = Pattern.compile(
|
||||
"(<mergeCell\\b[^>]*\\bref=\")([A-Z]+)(\\d+)(?::([A-Z]+)(\\d+))?(\")");
|
||||
|
||||
private record ExportStyleIndexes(int failedDetail, int detailNo, int failedDetailNo,
|
||||
private record ExportStyleIndexes(int detail, int failedDetail, int detailNo, int failedDetailNo,
|
||||
int customerOrderNo, int failedCustomerOrderNo,
|
||||
int trackingNo, int failedTrackingNo,
|
||||
int generalNumber, int failedGeneralNumber,
|
||||
@@ -79,18 +78,25 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
public void write(ArBill bill, ArExportTemplate template, Path target) throws IOException {
|
||||
// 样式表单独读取;不加载整张工作簿,且不依赖 styles.xml 和 sheet1.xml 在 ZIP 中的先后顺序。
|
||||
StylesTable styles = readExportStyles(template);
|
||||
boolean preserveTemplatePayee = ArBillWorkbookWriters.GUANGZHOU_TEMPLATE_CODE.equals(template.getTemplateCode())
|
||||
|| ArBillWorkbookWriters.JIYUN_TEMPLATE_CODE.equals(template.getTemplateCode());
|
||||
// 所有模板都从实际单元格读取样式,兼容新增 Sheet 或重新保存后变化的样式编号。
|
||||
int detailStyleIndex = readTemplateDetailStyleIndex(template);
|
||||
if (detailStyleIndex >= styles.getNumCellStyles()) {
|
||||
throw new IOException("应收账单导出模板明细样式不存在: " + detailStyleIndex);
|
||||
}
|
||||
String drawingPartPath = readTemplateDrawingPartPath(template);
|
||||
XSSFCellStyle detailNoStyle = styles.createCellStyle();
|
||||
detailNoStyle.cloneStyleFrom(styles.getStyleAt(TEMPLATE_DETAIL_STYLE_INDEX));
|
||||
detailNoStyle.cloneStyleFrom(styles.getStyleAt(detailStyleIndex));
|
||||
detailNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("0"));
|
||||
int detailNoStyleIndex = Short.toUnsignedInt(detailNoStyle.getIndex());
|
||||
XSSFCellStyle failedDetailStyle = styles.createCellStyle();
|
||||
failedDetailStyle.cloneStyleFrom(styles.getStyleAt(TEMPLATE_DETAIL_STYLE_INDEX));
|
||||
failedDetailStyle.cloneStyleFrom(styles.getStyleAt(detailStyleIndex));
|
||||
failedDetailStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
|
||||
failedDetailStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
int failedDetailStyleIndex = Short.toUnsignedInt(failedDetailStyle.getIndex());
|
||||
XSSFCellStyle customerOrderNoStyle = styles.createCellStyle();
|
||||
customerOrderNoStyle.cloneStyleFrom(styles.getStyleAt(TEMPLATE_DETAIL_STYLE_INDEX));
|
||||
customerOrderNoStyle.cloneStyleFrom(styles.getStyleAt(detailStyleIndex));
|
||||
customerOrderNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("@"));
|
||||
int customerOrderNoStyleIndex = Short.toUnsignedInt(customerOrderNoStyle.getIndex());
|
||||
XSSFCellStyle failedCustomerOrderNoStyle = styles.createCellStyle();
|
||||
@@ -98,7 +104,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
failedCustomerOrderNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("@"));
|
||||
int failedCustomerOrderNoStyleIndex = Short.toUnsignedInt(failedCustomerOrderNoStyle.getIndex());
|
||||
XSSFCellStyle trackingNoStyle = styles.createCellStyle();
|
||||
trackingNoStyle.cloneStyleFrom(styles.getStyleAt(TEMPLATE_DETAIL_STYLE_INDEX));
|
||||
trackingNoStyle.cloneStyleFrom(styles.getStyleAt(detailStyleIndex));
|
||||
trackingNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("@"));
|
||||
int trackingNoStyleIndex = Short.toUnsignedInt(trackingNoStyle.getIndex());
|
||||
XSSFCellStyle failedTrackingNoStyle = styles.createCellStyle();
|
||||
@@ -106,7 +112,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
failedTrackingNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("@"));
|
||||
int failedTrackingNoStyleIndex = Short.toUnsignedInt(failedTrackingNoStyle.getIndex());
|
||||
XSSFCellStyle generalNumberStyle = styles.createCellStyle();
|
||||
generalNumberStyle.cloneStyleFrom(styles.getStyleAt(TEMPLATE_DETAIL_STYLE_INDEX));
|
||||
generalNumberStyle.cloneStyleFrom(styles.getStyleAt(detailStyleIndex));
|
||||
generalNumberStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("General"));
|
||||
int generalNumberStyleIndex = Short.toUnsignedInt(generalNumberStyle.getIndex());
|
||||
XSSFCellStyle failedGeneralNumberStyle = styles.createCellStyle();
|
||||
@@ -118,7 +124,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
failedDetailNoStyle.setDataFormat(BuiltinFormats.getBuiltinFormat("0"));
|
||||
int failedDetailNoStyleIndex = Short.toUnsignedInt(failedDetailNoStyle.getIndex());
|
||||
XSSFCellStyle formulaStyle = styles.createCellStyle();
|
||||
formulaStyle.cloneStyleFrom(styles.getStyleAt(TEMPLATE_DETAIL_STYLE_INDEX));
|
||||
formulaStyle.cloneStyleFrom(styles.getStyleAt(detailStyleIndex));
|
||||
formulaStyle.setShrinkToFit(true);
|
||||
int formulaStyleIndex = Short.toUnsignedInt(formulaStyle.getIndex());
|
||||
XSSFCellStyle failedFormulaStyle = styles.createCellStyle();
|
||||
@@ -126,7 +132,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
failedFormulaStyle.setShrinkToFit(true);
|
||||
int failedFormulaStyleIndex = Short.toUnsignedInt(failedFormulaStyle.getIndex());
|
||||
ExportStyleIndexes exportStyleIndexes = new ExportStyleIndexes(
|
||||
failedDetailStyleIndex, detailNoStyleIndex, failedDetailNoStyleIndex,
|
||||
detailStyleIndex, failedDetailStyleIndex, detailNoStyleIndex, failedDetailNoStyleIndex,
|
||||
customerOrderNoStyleIndex, failedCustomerOrderNoStyleIndex,
|
||||
trackingNoStyleIndex, failedTrackingNoStyleIndex,
|
||||
generalNumberStyleIndex, failedGeneralNumberStyleIndex,
|
||||
@@ -151,7 +157,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
}
|
||||
if (TEMPLATE_SHEET_XML.equals(entry.getName())) {
|
||||
output.putNextEntry(new ZipEntry(entryName));
|
||||
int rowOffset = writeOoxmlSheet(readUtf8(templateZip), bill, output, exportStyleIndexes);
|
||||
int rowOffset = writeOoxmlSheet(readUtf8(templateZip), bill, output, exportStyleIndexes, preserveTemplatePayee);
|
||||
output.closeEntry();
|
||||
replaced = true;
|
||||
drawingRowOffset = Integer.valueOf(rowOffset);
|
||||
@@ -178,6 +184,29 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private int readTemplateDetailStyleIndex(ArExportTemplate template) throws IOException {
|
||||
try (InputStream input = openTemplateStream(template); ZipInputStream zip = new ZipInputStream(input)) {
|
||||
for (ZipEntry entry; (entry = zip.getNextEntry()) != null; ) {
|
||||
if (TEMPLATE_SHEET_XML.equals(entry.getName())) {
|
||||
String row = extractTemplateRows(readUtf8(zip)).get(6);
|
||||
if (row != null) {
|
||||
Matcher cells = CELL_PATTERN.matcher(row);
|
||||
while (cells.find()) {
|
||||
Matcher reference = CELL_REF_PATTERN.matcher(cells.group(1));
|
||||
Matcher style = CELL_STYLE_PATTERN.matcher(cells.group(1));
|
||||
if (reference.find() && "S6".equalsIgnoreCase(reference.group(1)) && style.find()) {
|
||||
return Integer.parseInt(style.group(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IOException("应收账单模板缺少 S6 合计单元格样式: " + template.getTemplateCode());
|
||||
}
|
||||
zip.closeEntry();
|
||||
}
|
||||
}
|
||||
throw new IOException("应收账单模板缺少运费工作表: " + template.getTemplateCode());
|
||||
}
|
||||
|
||||
private String readTemplateDrawingPartPath(ArExportTemplate template) throws IOException {
|
||||
try (InputStream input = openTemplateStream(template); ZipInputStream templateZip = new ZipInputStream(input)) {
|
||||
for (ZipEntry entry; (entry = templateZip.getNextEntry()) != null; ) {
|
||||
@@ -236,11 +265,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
try (InputStream input = openTemplateStream(template); ZipInputStream templateZip = new ZipInputStream(input)) {
|
||||
for (ZipEntry entry; (entry = templateZip.getNextEntry()) != null; ) {
|
||||
if (TEMPLATE_STYLES_XML.equals(entry.getName())) {
|
||||
StylesTable styles = new StylesTable(templateZip);
|
||||
if (styles.getNumCellStyles() <= TEMPLATE_DETAIL_STYLE_INDEX) {
|
||||
throw new IOException("应收账单导出模板缺少明细样式: " + TEMPLATE_DETAIL_STYLE_INDEX);
|
||||
}
|
||||
return styles;
|
||||
return new StylesTable(templateZip);
|
||||
}
|
||||
templateZip.closeEntry();
|
||||
}
|
||||
@@ -249,7 +274,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
}
|
||||
|
||||
private int writeOoxmlSheet(String templateXml, ArBill bill, OutputStream output,
|
||||
ExportStyleIndexes styleIndexes) throws IOException {
|
||||
ExportStyleIndexes styleIndexes, boolean preserveTemplatePayee) throws IOException {
|
||||
int sheetDataStart = templateXml.indexOf("<sheetData");
|
||||
int sheetDataOpenEnd = templateXml.indexOf('>', sheetDataStart);
|
||||
int sheetDataEnd = templateXml.indexOf("</sheetData>", sheetDataOpenEnd);
|
||||
@@ -263,7 +288,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
removeSheetDimension(templateXml.substring(0, sheetDataOpenEnd + 1)));
|
||||
writeUtf8(output, prefix);
|
||||
|
||||
String headerRow = replaceCellXml(templateRows.get(1), "A1",
|
||||
String headerRow = preserveTemplatePayee ? templateRows.get(1) : replaceCellXml(templateRows.get(1), "A1",
|
||||
StringUtils.isEmpty(bill.getBankAccountName()) ? "威狮国际供应链(深圳)有限公司" : bill.getBankAccountName(), false);
|
||||
writeUtf8(output, headerRow);
|
||||
writeUtf8(output, templateRows.get(2));
|
||||
@@ -291,7 +316,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
int rowOffset = lastDetailRow - TEMPLATE_LAST_DETAIL_ROW + EXPORT_FOOTER_GAP_ROWS;
|
||||
writeUtf8(output, "<row r=\"" + (lastDetailRow + 1) + "\" ht=\""
|
||||
+ EXPORT_DETAIL_ROW_HEIGHT + "\" customHeight=\"true\"/>");
|
||||
writeOoxmlFooter(output, templateRows, rowOffset, bill, styleIndexes.generalNumber());
|
||||
writeOoxmlFooter(output, templateRows, rowOffset, bill, styleIndexes.generalNumber(), preserveTemplatePayee);
|
||||
String suffix = shiftFooterMerges(templateXml.substring(sheetDataEnd), rowOffset);
|
||||
writeUtf8(output, suffix);
|
||||
return rowOffset;
|
||||
@@ -394,7 +419,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
}
|
||||
|
||||
private void writeOoxmlFooter(OutputStream output, Map<Integer, String> templateRows, int rowOffset,
|
||||
ArBill bill, int generalNumberStyleIndex) throws IOException {
|
||||
ArBill bill, int generalNumberStyleIndex, boolean preserveTemplatePayee) throws IOException {
|
||||
String totalAmountFormula = "SUM(S" + TEMPLATE_DATA_START_ROW + ":INDEX(S:S,ROW()-1))";
|
||||
for (int offset = 0; offset < 4; offset++) {
|
||||
int sourceRowNumber = TEMPLATE_LAST_DETAIL_ROW + offset + 1;
|
||||
@@ -407,20 +432,26 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
nvl(bill.getTotalAmount()), generalNumberStyleIndex);
|
||||
} else if (offset == 1) {
|
||||
row = replaceCellXml(row, "B" + targetRowNumber, "开户名", false);
|
||||
row = replaceCellXml(row, "C" + targetRowNumber, bill.getBankAccountName(), false);
|
||||
if (!preserveTemplatePayee) {
|
||||
row = replaceCellXml(row, "C" + targetRowNumber, bill.getBankAccountName(), false);
|
||||
}
|
||||
row = replaceCellXml(row, "P" + targetRowNumber, "本期已核销金额", false);
|
||||
row = replaceCellXml(row, "S" + targetRowNumber, bill.getWrittenOffAmount(), true,
|
||||
generalNumberStyleIndex);
|
||||
} else if (offset == 2) {
|
||||
row = replaceCellXml(row, "B" + targetRowNumber, "账号", false);
|
||||
row = replaceCellXml(row, "C" + targetRowNumber, exportBankAccountNo(bill.getBankAccountNo()), false);
|
||||
if (!preserveTemplatePayee) {
|
||||
row = replaceCellXml(row, "C" + targetRowNumber, exportBankAccountNo(bill.getBankAccountNo()), false);
|
||||
}
|
||||
row = replaceCellXml(row, "P" + targetRowNumber, "本期未核销金额", false);
|
||||
String unwrittenAmountFormula = "S" + (targetRowNumber - 2) + "-S" + (targetRowNumber - 1);
|
||||
row = replaceFormulaCellXml(row, "S" + targetRowNumber, unwrittenAmountFormula,
|
||||
nvl(bill.getUnwrittenAmount()), generalNumberStyleIndex);
|
||||
} else {
|
||||
row = replaceCellXml(row, "B" + targetRowNumber, "开户行", false);
|
||||
row = replaceCellXml(row, "C" + targetRowNumber, bill.getBankName(), false);
|
||||
if (!preserveTemplatePayee) {
|
||||
row = replaceCellXml(row, "C" + targetRowNumber, bill.getBankName(), false);
|
||||
}
|
||||
}
|
||||
writeUtf8(output, row);
|
||||
}
|
||||
@@ -430,7 +461,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
ExportStyleIndexes styleIndexes) throws IOException {
|
||||
String failureDescription = exportBillingFailDescription(detail.getBillingFailStatus());
|
||||
boolean failedDetail = !failureDescription.isEmpty();
|
||||
int styleIndex = failedDetail ? styleIndexes.failedDetail() : TEMPLATE_DETAIL_STYLE_INDEX;
|
||||
int styleIndex = failedDetail ? styleIndexes.failedDetail() : styleIndexes.detail();
|
||||
int sequenceStyleIndex = failedDetail ? styleIndexes.failedDetailNo() : styleIndexes.detailNo();
|
||||
Object[] values = {
|
||||
detail.getDetailNo(),
|
||||
|
||||
+87
-37
@@ -23,6 +23,7 @@ import java.util.zip.ZipOutputStream;
|
||||
import com.bms.common.utils.StringUtils;
|
||||
import com.bms.receivable.domain.ArBill;
|
||||
import com.bms.receivable.domain.ArBillDetail;
|
||||
import com.bms.receivable.domain.ArBillDetailFee;
|
||||
import com.bms.receivable.domain.ArExportTemplate;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
@@ -39,9 +40,13 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
private static final int DETAIL_START_ROW = 5;
|
||||
private static final int DETAIL_COLUMN_COUNT = 20;
|
||||
private static final int DETAIL_COLUMN_COUNT = 21;
|
||||
private static final int SUMMARY_START_ROW = 4;
|
||||
private static final String SUMMARY_REMARK = "国际货物运输代理服务费";
|
||||
private static final String REMOTE_FEE_TYPE = "REMOTE";
|
||||
private static final String SURCHARGE_FEE_TYPE = "SURCHARGE";
|
||||
private static final String ROMANIA_FEE_TYPE = "REGISTRATION";
|
||||
private static final String ROMANIA_FEE_NAME = "罗马尼亚费用";
|
||||
private static final Pattern MERGE = Pattern.compile("(<mergeCell\\b[^>]*\\bref=\")([A-Z]+)(\\d+):([A-Z]+)(\\d+)(\")");
|
||||
private static final Pattern FILTER = Pattern.compile("(<autoFilter\\b[^>]*\\bref=\")[^\"]*(\")");
|
||||
|
||||
@@ -110,9 +115,15 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
requireRow(workbook.getSheetAt(0), 5);
|
||||
requireRow(workbook.getSheetAt(1), 4);
|
||||
requireRow(workbook.getSheetAt(1), 5);
|
||||
XSSFCell explanationHeader = requireRow(workbook.getSheetAt(1), 3).getCell(DETAIL_COLUMN_COUNT - 1);
|
||||
if (explanationHeader == null || !"说明".equals(explanationHeader.toString().trim())) {
|
||||
throw new IOException("汇总模板运费明细缺少 T 列说明,请使用最新模板");
|
||||
requireDetailHeader(workbook.getSheetAt(1), 14, "附加费");
|
||||
requireDetailHeader(workbook.getSheetAt(1), 19, "备注");
|
||||
requireDetailHeader(workbook.getSheetAt(1), 20, "说明");
|
||||
}
|
||||
|
||||
private void requireDetailHeader(XSSFSheet sheet, int column, String label) throws IOException {
|
||||
XSSFCell header = requireRow(sheet, 3).getCell(column);
|
||||
if (header == null || !label.equals(header.toString().trim())) {
|
||||
throw new IOException("汇总模板运费明细缺少 " + (char) ('A' + column) + " 列" + label + ",请使用最新模板");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,33 +146,28 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
textCell(summary, 11, 1, exportBankAccountNo(bill.getBankAccountNo()));
|
||||
textCell(summary, 12, 1, bill.getBankName());
|
||||
textCell(detail, 2, 1, bill.getCustomerName());
|
||||
textCell(detail, 2, 17, billPeriod(bill));
|
||||
for (int column : new int[]{11, 12, 13, 14, 15}) {
|
||||
textCell(detail, 2, 18, billPeriod(bill));
|
||||
for (int column : new int[]{11, 12, 13, 15, 16}) {
|
||||
XSSFCell header = detail.getRow(3).getCell(column);
|
||||
header.setCellValue(header.getStringCellValue().replace("CNY", currency));
|
||||
}
|
||||
for (int column = 0; column < DETAIL_COLUMN_COUNT; column++) {
|
||||
XSSFCell cell = detail.getRow(4).getCell(column, XSSFRow.MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
||||
boolean identifier = column == 0 || column == 2 || column == 3 || column == 6;
|
||||
boolean money = column == 10 || column == 13 || column == 14 || column == 15 || column == 16;
|
||||
if (!identifier && !money) continue;
|
||||
XSSFCellStyle style = workbook.createCellStyle();
|
||||
style.cloneStyleFrom(cell.getCellStyle());
|
||||
boolean identifier = column == 0 || column == 2 || column == 3 || column == 6;
|
||||
String format = identifier ? "@" : (column == 13 || column == 15 ? "0.00" : "General");
|
||||
String format = identifier ? "@" : "0.00";
|
||||
style.setDataFormat(workbook.createDataFormat().getFormat(format));
|
||||
cell.setCellStyle(style);
|
||||
}
|
||||
XSSFRow summaryRow = requireRow(summary, 3);
|
||||
for (int column = 0; column < 7; column++) {
|
||||
XSSFCell cell = summaryRow.getCell(column, XSSFRow.MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
||||
XSSFCellStyle style = workbook.createCellStyle();
|
||||
style.cloneStyleFrom(cell.getCellStyle());
|
||||
style.setDataFormat(workbook.createDataFormat().getFormat(column == 4 ? "0.00" : "General"));
|
||||
cell.setCellStyle(style);
|
||||
}
|
||||
detail.getRow(4).setHeightInPoints(20);
|
||||
summaryRow.setHeightInPoints(20);
|
||||
// 订单号按文本输出并提供可读列宽;其他版式沿用用户模板。
|
||||
detail.setColumnWidth(2, Math.max(detail.getColumnWidth(2), 20 * 256));
|
||||
detail.setColumnWidth(3, Math.max(detail.getColumnWidth(3), 20 * 256));
|
||||
XSSFCell summaryAmount = requireRow(summary, 3).getCell(4, XSSFRow.MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
||||
XSSFCellStyle summaryAmountStyle = workbook.createCellStyle();
|
||||
summaryAmountStyle.cloneStyleFrom(summaryAmount.getCellStyle());
|
||||
summaryAmountStyle.setDataFormat(workbook.createDataFormat().getFormat("0.00"));
|
||||
summaryAmount.setCellStyle(summaryAmountStyle);
|
||||
// 行高、列宽、字体和配色沿用用户模板。
|
||||
workbook.setForceFormulaRecalculation(true);
|
||||
}
|
||||
|
||||
@@ -184,7 +190,7 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
failed[column] = Short.toUnsignedInt(style.getIndex());
|
||||
}
|
||||
return new DetailStyles(normal, failed);
|
||||
return new DetailStyles(normal, failed, workbook.getSheetAt(1).getRow(4).getHeightInPoints());
|
||||
}
|
||||
|
||||
private DetailResult writeDetails(SheetXml sheet, ArBill bill, OutputStream output,
|
||||
@@ -197,6 +203,7 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
while (true) {
|
||||
List<ArBillDetail> details = detailMapper.selectExportPage(bill.getArBillId(), lastDetailNo, EXPORT_PAGE_SIZE);
|
||||
if (details.isEmpty()) break;
|
||||
attachFees(details);
|
||||
for (ArBillDetail detail : details) {
|
||||
if (rowNumber + 2 > SpreadsheetVersion.EXCEL2007.getMaxRows()) {
|
||||
throw new IOException("账单订单数超过 Excel 单个工作表容量,请拆分账单后导出");
|
||||
@@ -204,8 +211,9 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
if (!StringUtils.isEmpty(detail.getCurrency()) && !detail.getCurrency().equals(bill.getCurrency())) {
|
||||
throw new IOException("账单明细币种与账单币种不一致,请检查账单");
|
||||
}
|
||||
writeUtf8(output, detailRow(rowNumber++, bill, detail, styles));
|
||||
BigDecimal amount = nvl(detail.getTotalAmount());
|
||||
DetailAmounts amounts = calculateDetailAmounts(detail);
|
||||
writeUtf8(output, detailRow(rowNumber++, bill, detail, amounts, styles));
|
||||
BigDecimal amount = amounts.total();
|
||||
total = total.add(amount);
|
||||
String key = StringUtils.isEmpty(detail.getProductCode())
|
||||
? "NAME:" + detail.getProductName() : "CODE:" + detail.getProductCode();
|
||||
@@ -220,13 +228,14 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
if (count == 0) writeUtf8(output, "<row r=\"5\"/>");
|
||||
writeUtf8(output, "<row r=\"" + (lastRow + 1) + "\"/>");
|
||||
String footer = shiftRowXml(sheet.rows().get(6), lastRow + 2);
|
||||
footer = replaceFormulaCellXml(footer, "P" + (lastRow + 2), "SUM(P5:P" + lastRow + ")", total);
|
||||
footer = replaceFormulaCellXml(footer, "Q" + (lastRow + 2), "SUM(Q5:Q" + lastRow + ")", total);
|
||||
writeUtf8(output, footer);
|
||||
writeUtf8(output, withFilter(sheet.suffix(), "A4:T" + lastRow));
|
||||
writeUtf8(output, withFilter(sheet.suffix(), "A4:U" + lastRow));
|
||||
return new DetailResult(count, lastRow, total);
|
||||
}
|
||||
|
||||
private String detailRow(int rowNumber, ArBill bill, ArBillDetail detail, DetailStyles styles) {
|
||||
private String detailRow(int rowNumber, ArBill bill, ArBillDetail detail,
|
||||
DetailAmounts amounts, DetailStyles styles) {
|
||||
String failure = exportBillingFailDescription(detail.getBillingFailStatus());
|
||||
Object[] values = {
|
||||
bill.getCustomerCode(),
|
||||
@@ -234,21 +243,27 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
detail.getTransferNo(), detail.getTrackingNo(),
|
||||
StringUtils.isEmpty(detail.getProductName()) ? detail.getProductCode() : detail.getProductName(),
|
||||
StringUtils.isEmpty(detail.getCountryName()) ? detail.getCountryCode() : detail.getCountryName(),
|
||||
detail.getDestPostcode(), null, detail.getReceiveWeight(), detail.getChargeWeight(), null,
|
||||
exportUnitPrice(detail), exportProcessingFee(detail), null, null, detail.getTotalAmount(), null, null,
|
||||
exportRemark(detail), failure
|
||||
detail.getDestPostcode(), null, detail.getReceiveWeight(), nvl(detail.getChargeWeight()),
|
||||
amounts.remote(), nvl(exportUnitPrice(detail)), amounts.processing(), amounts.freight(),
|
||||
amounts.surcharge(), amounts.romania(), amounts.total(), null, null,
|
||||
null, failure // 客户版汇总模板的 T 列备注固定留空,不输出内部备注或品名描述。
|
||||
};
|
||||
StringBuilder row = new StringBuilder(2048).append("<row r=\"").append(rowNumber)
|
||||
.append("\" ht=\"20\" customHeight=\"true\" spans=\"1:").append(DETAIL_COLUMN_COUNT).append("\">");
|
||||
.append("\" ht=\"").append(numberText(styles.rowHeight()))
|
||||
.append("\" customHeight=\"true\" spans=\"1:").append(DETAIL_COLUMN_COUNT).append("\">");
|
||||
for (int index = 0; index < values.length; index++) {
|
||||
String reference = (char) ('A' + index) + String.valueOf(rowNumber);
|
||||
int style = failure.isEmpty() ? styles.normal()[index] : styles.failed()[index];
|
||||
if (index == 13) {
|
||||
BigDecimal amount = nvl(detail.getChargeWeight()).multiply(nvl(exportUnitPrice(detail)))
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
String formula = switch (index) {
|
||||
case 13 -> "ROUND(J" + rowNumber + "*L" + rowNumber + ",2)";
|
||||
case 16 -> "N" + rowNumber + "+K" + rowNumber + "+M" + rowNumber
|
||||
+ "+P" + rowNumber + "+O" + rowNumber;
|
||||
default -> null;
|
||||
};
|
||||
if (formula != null) {
|
||||
row.append("<c r=\"").append(reference).append("\" s=\"").append(style)
|
||||
.append("\" t=\"n\"><f>ROUND(J").append(rowNumber).append("*L").append(rowNumber)
|
||||
.append(",2)</f><v>").append(numberText(amount)).append("</v></c>");
|
||||
.append("\" t=\"n\"><f>").append(xmlEscape(formula)).append("</f><v>")
|
||||
.append(numberText((Number) values[index])).append("</v></c>");
|
||||
} else {
|
||||
appendOoxmlCell(row, reference, values[index], style);
|
||||
}
|
||||
@@ -256,6 +271,39 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
return row.append("</row>").toString();
|
||||
}
|
||||
|
||||
/** 与工作表 N、Q 列的公式使用相同数值,缓存和产品汇总均复用本次计算结果。 */
|
||||
private DetailAmounts calculateDetailAmounts(ArBillDetail detail) throws IOException {
|
||||
BigDecimal freight = nvl(detail.getChargeWeight()).multiply(nvl(exportUnitPrice(detail)))
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal processing = nvl(exportProcessingFee(detail));
|
||||
BigDecimal remote = exportFeeAmount(detail, REMOTE_FEE_TYPE, null);
|
||||
BigDecimal surcharge = exportFeeAmount(detail, SURCHARGE_FEE_TYPE, null);
|
||||
BigDecimal romania = exportFeeAmount(detail, ROMANIA_FEE_TYPE, ROMANIA_FEE_NAME);
|
||||
BigDecimal total = freight.add(remote).add(processing).add(romania).add(surcharge);
|
||||
BigDecimal snapshot = nvl(detail.getTotalAmount());
|
||||
if (total.compareTo(snapshot) != 0) {
|
||||
String order = StringUtils.isEmpty(detail.getOrderNo()) ? detail.getTransferNo() : detail.getOrderNo();
|
||||
if (StringUtils.isEmpty(order)) order = "明细" + detail.getDetailNo();
|
||||
throw new IOException("订单 " + order + " 总金额与账单快照不一致:公式金额 " + numberText(total)
|
||||
+ ",账单金额 " + numberText(snapshot) + ",差额 " + numberText(total.subtract(snapshot))
|
||||
+ ",请检查其他费用、退费或计费快照");
|
||||
}
|
||||
return new DetailAmounts(freight, processing, remote, surcharge, romania, total);
|
||||
}
|
||||
|
||||
/** 从当前账单的费用快照汇总应收金额;无匹配项输出零,负金额照常输出。 */
|
||||
private BigDecimal exportFeeAmount(ArBillDetail detail, String feeType, String feeName) {
|
||||
if (detail.getFees() == null) return BigDecimal.ZERO;
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
for (ArBillDetailFee fee : detail.getFees()) {
|
||||
if (fee == null || !feeType.equalsIgnoreCase(StringUtils.trim(fee.getFeeType()))) continue;
|
||||
// REGISTRATION 也用于其他处理费,罗马尼亚费用必须同时精确匹配名称。
|
||||
if (feeName != null && !feeName.equals(StringUtils.trim(fee.getFeeName()))) continue;
|
||||
amount = amount.add(nvl(fee.getAmount()));
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
private void writeSummary(SheetXml sheet, ArBill bill, Map<String, ProductSummary> groups,
|
||||
BigDecimal total, OutputStream output) throws IOException {
|
||||
writeUtf8(output, sheet.prefix());
|
||||
@@ -342,7 +390,9 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
|
||||
|
||||
private record SheetXml(String prefix, Map<Integer, String> rows, String suffix) { }
|
||||
private record DetailResult(int count, int lastRow, BigDecimal amount) { }
|
||||
private record DetailStyles(int[] normal, int[] failed) { }
|
||||
private record DetailStyles(int[] normal, int[] failed, float rowHeight) { }
|
||||
private record DetailAmounts(BigDecimal freight, BigDecimal processing, BigDecimal remote,
|
||||
BigDecimal surcharge, BigDecimal romania, BigDecimal total) { }
|
||||
|
||||
private static class ProductSummary {
|
||||
private final String name;
|
||||
|
||||
@@ -17,22 +17,7 @@
|
||||
ifnull(nullif(trim(b.currency), ''), 'CNY') as currency,
|
||||
b.pay_calc_status as payCalcStatus,
|
||||
b.pay_calc_msg as payCalcMsg,
|
||||
case
|
||||
when lower(trim(b.update_by)) = 'system' then '系统自动'
|
||||
else ifnull((
|
||||
select case
|
||||
when nullif(trim(u.nick_name), '') is not null then u.nick_name
|
||||
else u.user_name
|
||||
end
|
||||
from sys_user u
|
||||
where u.del_flag = '0'
|
||||
and (
|
||||
(b.update_by regexp '^[0-9]+$' and u.user_id = cast(b.update_by as unsigned))
|
||||
or (ifnull(b.update_by, '') not regexp '^[0-9]+$' and u.user_name = b.update_by COLLATE utf8mb4_general_ci)
|
||||
)
|
||||
limit 1
|
||||
), b.update_by)
|
||||
end as updateBy,
|
||||
b.update_by as updateBy,
|
||||
b.update_time as updateTime,
|
||||
p.biz_date as bizDate
|
||||
from prc_order_bill p
|
||||
@@ -40,25 +25,69 @@
|
||||
left join prc_pay_bill b on b.bill_id = p.bill_id
|
||||
</sql>
|
||||
|
||||
<select id="selectList" resultType="com.bms.price.domain.PayOrderRow">
|
||||
<sql id="pageFilters">
|
||||
<if test="orderNos != null and orderNos.size() > 0">
|
||||
and p.order_no in
|
||||
<foreach collection="orderNos" item="no" open="(" separator="," close=")">#{no}</foreach>
|
||||
</if>
|
||||
<if test="(orderNos == null or orderNos.size() == 0) and orderNo != null and orderNo != ''">
|
||||
and p.order_no like concat('%', #{orderNo}, '%')
|
||||
</if>
|
||||
<if test="customerName != null and customerName != ''">
|
||||
and (p.customer_name like concat('%', #{customerName}, '%')
|
||||
or p.customer_code like concat('%', #{customerName}, '%'))
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<!-- 先只取这一页的订单主键。计数和排序都不带应付表,也不逐行查用户。 -->
|
||||
<select id="selectPageIds" resultType="java.lang.Long">
|
||||
<choose>
|
||||
<when test="ladingNo != null and ladingNo != ''">
|
||||
select p.bill_id
|
||||
from prc_order_bill p
|
||||
inner join (
|
||||
select e.bill_id
|
||||
from prc_order_bill_ext e
|
||||
where e.air_no_old like concat('%', #{ladingNo}, '%')
|
||||
) hit on hit.bill_id = p.bill_id
|
||||
<where>
|
||||
<include refid="pageFilters"/>
|
||||
</where>
|
||||
order by p.create_time desc, p.bill_id desc
|
||||
</when>
|
||||
<otherwise>
|
||||
select p.bill_id
|
||||
from prc_order_bill p
|
||||
<where>
|
||||
<include refid="pageFilters"/>
|
||||
</where>
|
||||
order by p.create_time desc, p.bill_id desc
|
||||
</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
|
||||
<select id="selectByBillIds" resultType="com.bms.price.domain.PayOrderRow">
|
||||
<include refid="orderColumns"/>
|
||||
<where>
|
||||
<if test="orderNos != null and orderNos.size() > 0">
|
||||
and p.order_no in
|
||||
<foreach collection="orderNos" item="no" open="(" separator="," close=")">#{no}</foreach>
|
||||
</if>
|
||||
<if test="(orderNos == null or orderNos.size() == 0) and orderNo != null and orderNo != ''">
|
||||
and p.order_no like concat('%', #{orderNo}, '%')
|
||||
</if>
|
||||
<if test="ladingNo != null and ladingNo != ''">
|
||||
and trim(e.air_no_old) like concat('%', #{ladingNo}, '%')
|
||||
</if>
|
||||
<if test="customerName != null and customerName != ''">
|
||||
and (p.customer_name like concat('%', #{customerName}, '%')
|
||||
or p.customer_code like concat('%', #{customerName}, '%'))
|
||||
</if>
|
||||
</where>
|
||||
order by p.create_time desc, p.bill_id desc
|
||||
where p.bill_id in
|
||||
<foreach collection="billIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectUsers" resultType="com.bms.common.core.domain.entity.SysUser">
|
||||
select u.user_id as userId, u.user_name as userName, u.nick_name as nickName
|
||||
from sys_user u
|
||||
where u.del_flag = '0'
|
||||
and (
|
||||
<trim prefixOverrides="or">
|
||||
<if test="userIds != null and userIds.size() > 0">
|
||||
u.user_id in
|
||||
<foreach collection="userIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</if>
|
||||
<if test="userNames != null and userNames.size() > 0">
|
||||
or u.user_name in
|
||||
<foreach collection="userNames" item="name" open="(" separator="," close=")">#{name} collate utf8mb4_general_ci</foreach>
|
||||
</if>
|
||||
</trim>
|
||||
)
|
||||
</select>
|
||||
|
||||
<select id="selectRow" resultType="com.bms.price.domain.PayOrderRow">
|
||||
@@ -80,9 +109,9 @@
|
||||
select p.bill_id as billId,
|
||||
p.order_no as orderNo,
|
||||
nullif(trim(e.air_no_old), '') as ladingNo
|
||||
from prc_order_bill p
|
||||
left join prc_order_bill_ext e on e.bill_id = p.bill_id
|
||||
where trim(e.air_no_old) in
|
||||
from prc_order_bill_ext e
|
||||
inner join prc_order_bill p on p.bill_id = e.bill_id
|
||||
where e.air_no_old in
|
||||
<foreach collection="ladingNos" item="no" open="(" separator="," close=")">#{no}</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -60,6 +60,31 @@
|
||||
and g.country_name = #{countryName}
|
||||
</otherwise>
|
||||
</choose>
|
||||
<include refid="channelMatch"/>
|
||||
</sql>
|
||||
|
||||
<sql id="lineChannelMatch">
|
||||
<choose>
|
||||
<when test="channelName != null and channelName != ''">
|
||||
and lower(trim(g.channel_name)) = lower(trim(#{channelName}))
|
||||
</when>
|
||||
<otherwise>
|
||||
and (g.channel_name is null or trim(g.channel_name) = '')
|
||||
</otherwise>
|
||||
</choose>
|
||||
</sql>
|
||||
|
||||
<sql id="channelMatch">
|
||||
<if test="allChannels == null or !allChannels">
|
||||
<choose>
|
||||
<when test="channelName != null and channelName != ''">
|
||||
and lower(trim(g.channel_name)) = lower(trim(#{channelName}))
|
||||
</when>
|
||||
<otherwise>
|
||||
and (g.channel_name is null or trim(g.channel_name) = '')
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="zoneExpr">
|
||||
@@ -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 @@
|
||||
</where>
|
||||
) 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
|
||||
</select>
|
||||
|
||||
<select id="selectSampleGroup" parameterType="com.bms.price.domain.PayPostcodeGroup" resultType="com.bms.price.domain.PayPostcodeGroup">
|
||||
@@ -196,10 +230,17 @@
|
||||
<update id="updateCountryProfile" parameterType="com.bms.price.domain.PayPostcodeGroup">
|
||||
update pay_postcode_group g
|
||||
set g.service_type = #{serviceType},
|
||||
g.product_name = #{productName},
|
||||
g.channel_name = #{channelName}
|
||||
g.product_name = #{productName}
|
||||
<where>
|
||||
<include refid="countryMatch"/>
|
||||
<choose>
|
||||
<when test="countryCode != null and countryCode != ''">
|
||||
and upper(trim(g.country_code)) = upper(trim(#{countryCode}))
|
||||
</when>
|
||||
<otherwise>
|
||||
and (g.country_code is null or trim(g.country_code) = '')
|
||||
and g.country_name = #{countryName}
|
||||
</otherwise>
|
||||
</choose>
|
||||
</where>
|
||||
</update>
|
||||
|
||||
@@ -325,13 +366,16 @@
|
||||
</if>
|
||||
<if test="countryCode != null and countryCode != ''">
|
||||
and l.group_id in (
|
||||
select g.group_id from pay_postcode_group g where upper(trim(g.country_code)) = upper(trim(#{countryCode}))
|
||||
select g.group_id from pay_postcode_group g
|
||||
where upper(trim(g.country_code)) = upper(trim(#{countryCode}))
|
||||
<include refid="lineChannelMatch"/>
|
||||
)
|
||||
</if>
|
||||
<if test="(countryCode == null or countryCode == '') and countryName != null and countryName != ''">
|
||||
and l.group_id in (
|
||||
select g.group_id from pay_postcode_group g
|
||||
where (g.country_code is null or trim(g.country_code) = '') and g.country_name = #{countryName}
|
||||
<include refid="lineChannelMatch"/>
|
||||
)
|
||||
</if>
|
||||
</where>
|
||||
@@ -432,6 +476,29 @@
|
||||
</choose>
|
||||
</select>
|
||||
|
||||
<select id="selectSurchargeLines" resultType="com.bms.price.domain.PayPostcodeLine">
|
||||
select l.line_id as lineId, l.group_id as groupId, g.channel_name as channelName, g.fee_name as feeName,
|
||||
g.country_name as countryName, g.country_code as countryCode,
|
||||
l.region_name as regionName, l.zone_name as zoneName, l.postcode
|
||||
from pay_postcode_group g
|
||||
inner join pay_postcode_line l on l.group_id = g.group_id
|
||||
where upper(trim(ifnull(g.coverage, ''))) = 'SURCHARGE'
|
||||
<if test="countryCode != null and countryCode != ''">
|
||||
and upper(trim(g.country_code)) = upper(trim(#{countryCode}))
|
||||
</if>
|
||||
<if test="(countryCode == null or countryCode == '') and countryName != null and countryName != ''">
|
||||
and trim(g.country_name) = trim(#{countryName})
|
||||
</if>
|
||||
and (
|
||||
replace(replace(replace(upper(ifnull(l.postcode, '')), ' ', ''), '-', ''), '*', '') = #{compact}
|
||||
or #{compact} like concat(replace(replace(replace(upper(ifnull(l.postcode, '')), ' ', ''), '-', ''), '*', ''), '%')
|
||||
or (
|
||||
char_length(#{compact}) >= 3
|
||||
and replace(replace(replace(upper(ifnull(l.postcode, '')), ' ', ''), '-', ''), '*', '') like concat(#{compact}, '%')
|
||||
)
|
||||
)
|
||||
</select>
|
||||
|
||||
<select id="selectGroupsByTokens" resultType="com.bms.price.domain.PayPostcodeGroup">
|
||||
select group_id as groupId, block_title as blockTitle, channel_name as channelName,
|
||||
product_name as productName, quote_sheet as quoteSheet, sheet_name as sheetName,
|
||||
|
||||
@@ -109,6 +109,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
and (b.weight_label like concat('%', #{weightKeyword}, '%')
|
||||
or b.charge_name like concat('%', #{weightKeyword}, '%')
|
||||
or b.zone_name like concat('%', #{weightKeyword}, '%')
|
||||
or b.calc_param like concat('%', #{weightKeyword}, '%')
|
||||
or b.country_name like concat('%', #{weightKeyword}, '%')
|
||||
or b.section_name like concat('%', #{weightKeyword}, '%')
|
||||
or b.volume_text like concat('%', #{weightKeyword}, '%'))
|
||||
@@ -320,12 +321,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<insert id="insertWeightBands">
|
||||
insert into pay_weight_band (
|
||||
product_id, term_id, version_no, section_name, country_name, country_code, zone_name, weight_label, weight_min, weight_max,
|
||||
product_id, term_id, version_no, section_name, country_name, country_code, zone_name, calc_rule, calc_param, weight_label, weight_min, weight_max,
|
||||
volume_text, charge_name, price, price_unit, sort_no
|
||||
) values
|
||||
<foreach collection="list" item="row" separator=",">
|
||||
(#{row.productId}, #{row.termId}, ifnull(#{row.versionNo}, 1), #{row.sectionName}, #{row.countryName}, #{row.countryCode}, #{row.zoneName},
|
||||
#{row.weightLabel}, #{row.weightMin}, #{row.weightMax}, #{row.volumeText}, #{row.chargeName}, #{row.price},
|
||||
#{row.calcRule}, #{row.calcParam}, #{row.weightLabel}, #{row.weightMin}, #{row.weightMax}, #{row.volumeText}, #{row.chargeName}, #{row.price},
|
||||
#{row.priceUnit}, #{row.sortNo})
|
||||
</foreach>
|
||||
</insert>
|
||||
@@ -352,7 +353,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectWeightBands" resultType="com.bms.price.domain.PayWeightBand">
|
||||
select band_id as bandId, product_id as productId, term_id as termId, version_no as versionNo, section_name as sectionName, country_name as countryName,
|
||||
country_code as countryCode, zone_name as zoneName, weight_label as weightLabel, weight_min as weightMin,
|
||||
country_code as countryCode, zone_name as zoneName, calc_rule as calcRule, calc_param as calcParam, weight_label as weightLabel, weight_min as weightMin,
|
||||
weight_max as weightMax, volume_text as volumeText, charge_name as chargeName, price, price_unit as priceUnit, sort_no as sortNo
|
||||
from pay_weight_band
|
||||
where product_id in
|
||||
@@ -362,7 +363,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectWeightBandsByTerm" resultType="com.bms.price.domain.PayWeightBand">
|
||||
select band_id as bandId, product_id as productId, term_id as termId, version_no as versionNo, section_name as sectionName, country_name as countryName,
|
||||
country_code as countryCode, zone_name as zoneName, weight_label as weightLabel, weight_min as weightMin,
|
||||
country_code as countryCode, zone_name as zoneName, calc_rule as calcRule, calc_param as calcParam, weight_label as weightLabel, weight_min as weightMin,
|
||||
weight_max as weightMax, volume_text as volumeText, charge_name as chargeName, price, price_unit as priceUnit, sort_no as sortNo
|
||||
from pay_weight_band
|
||||
where term_id in
|
||||
|
||||
@@ -39,14 +39,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</insert>
|
||||
|
||||
<select id="selectByBillId" resultMap="PrcPayBillFeeLogResult">
|
||||
select log_id, fee_id, bill_id, fee_name, amount, currency,
|
||||
before_fee_name, before_amount, before_currency,
|
||||
after_fee_name, after_amount, after_currency,
|
||||
operation_type, remark,
|
||||
case when lower(trim(create_by)) = 'system' then '系统自动' else create_by end as create_by,
|
||||
create_time
|
||||
from prc_pay_bill_fee_log
|
||||
where bill_id = #{billId}
|
||||
order by log_id desc
|
||||
select l.log_id, l.fee_id, l.bill_id, l.fee_name, l.amount, l.currency,
|
||||
l.before_fee_name, l.before_amount, l.before_currency,
|
||||
l.after_fee_name, l.after_amount, l.after_currency,
|
||||
l.operation_type, l.remark,
|
||||
case
|
||||
when lower(trim(l.create_by)) = 'system' then '系统自动'
|
||||
else ifnull((
|
||||
select case
|
||||
when nullif(trim(u.nick_name), '') is not null then u.nick_name
|
||||
else u.user_name
|
||||
end
|
||||
from sys_user u
|
||||
where u.del_flag = '0'
|
||||
and (
|
||||
(l.create_by regexp '^[0-9]+$' and u.user_id = cast(l.create_by as unsigned))
|
||||
or (ifnull(l.create_by, '') not regexp '^[0-9]+$' and u.user_name = l.create_by COLLATE utf8mb4_general_ci)
|
||||
)
|
||||
limit 1
|
||||
), l.create_by)
|
||||
end as create_by,
|
||||
l.create_time
|
||||
from prc_pay_bill_fee_log l
|
||||
where l.bill_id = #{billId}
|
||||
order by l.log_id desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -8,8 +8,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
b.bind_id as bindId, b.product_id as productId, b.product_type as productType, b.sc_id as scId, b.sort_no as sortNo,
|
||||
b.created_by as createdBy, b.create_time as createTime, b.updated_by as updatedBy, b.update_time as updateTime,
|
||||
c.sc_name as scName, c.charge_type as chargeType, c.charge_value as chargeValue, c.currency, c.ss_code as ssCode,
|
||||
c.block_title as blockTitle, c.sc_note as scNote,
|
||||
c.length_cm as lengthCm, c.width_cm as widthCm, c.height_cm as heightCm,
|
||||
c.block_title as blockTitle, c.sc_note as scNote, c.country_code as countryCode, c.fee_type as feeType,
|
||||
c.length_cm as lengthCm, c.width_cm as widthCm, c.height_cm as heightCm, c.size_type as sizeType, c.volume_m3 as volumeM3,
|
||||
c.over_weight_kg as overWeightKg, c.extra_weight_kg as extraWeightKg, c.postcode_text as postcodeText
|
||||
</sql>
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="lengthCm" column="length_cm" />
|
||||
<result property="widthCm" column="width_cm" />
|
||||
<result property="heightCm" column="height_cm" />
|
||||
<result property="sizeType" column="size_type" />
|
||||
<result property="volumeM3" column="volume_m3" />
|
||||
<result property="overWeightKg" column="over_weight_kg" />
|
||||
<result property="extraWeightKg" column="extra_weight_kg" />
|
||||
<result property="postcodeText" column="postcode_text" />
|
||||
@@ -33,7 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<sql id="selectPrcSurchargeVo">
|
||||
select sc_id, sc_name, fee_type, charge_type, dict_value, charge_value,
|
||||
length_cm, width_cm, height_cm, over_weight_kg, extra_weight_kg, postcode_text, currency, round_mode,
|
||||
length_cm, width_cm, height_cm, size_type, volume_m3, over_weight_kg, extra_weight_kg, postcode_text, currency, round_mode,
|
||||
ss_code, is_del, country_code, block_title, sc_note, tms_id, created_by, create_time, updated_by, update_time
|
||||
from prc_surcharge
|
||||
</sql>
|
||||
@@ -102,6 +104,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="lengthCm != null">length_cm,</if>
|
||||
<if test="widthCm != null">width_cm,</if>
|
||||
<if test="heightCm != null">height_cm,</if>
|
||||
<if test="sizeType != null and sizeType != ''">size_type,</if>
|
||||
<if test="volumeM3 != null">volume_m3,</if>
|
||||
<if test="overWeightKg != null">over_weight_kg,</if>
|
||||
<if test="extraWeightKg != null">extra_weight_kg,</if>
|
||||
<if test="postcodeText != null">postcode_text,</if>
|
||||
@@ -124,6 +128,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="lengthCm != null">#{lengthCm},</if>
|
||||
<if test="widthCm != null">#{widthCm},</if>
|
||||
<if test="heightCm != null">#{heightCm},</if>
|
||||
<if test="sizeType != null and sizeType != ''">#{sizeType},</if>
|
||||
<if test="volumeM3 != null">#{volumeM3},</if>
|
||||
<if test="overWeightKg != null">#{overWeightKg},</if>
|
||||
<if test="extraWeightKg != null">#{extraWeightKg},</if>
|
||||
<if test="postcodeText != null">#{postcodeText},</if>
|
||||
|
||||
@@ -25,6 +25,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="lengthCm" column="length_cm" />
|
||||
<result property="widthCm" column="width_cm" />
|
||||
<result property="heightCm" column="height_cm" />
|
||||
<result property="sizeType" column="size_type" />
|
||||
<result property="volumeM3" column="volume_m3" />
|
||||
<result property="overWeightKg" column="over_weight_kg" />
|
||||
<result property="extraWeightKg" column="extra_weight_kg" />
|
||||
<result property="blockTitle" column="block_title" />
|
||||
@@ -43,7 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
r.created_by, r.create_time, r.updated_by, r.update_time,
|
||||
s.sc_name, s.fee_type, s.charge_type, s.charge_value, s.currency,
|
||||
s.round_mode, s.ss_code, s.sc_note,
|
||||
s.postcode_text, s.length_cm, s.width_cm, s.height_cm,
|
||||
s.postcode_text, s.length_cm, s.width_cm, s.height_cm, s.size_type, s.volume_m3,
|
||||
s.over_weight_kg, s.extra_weight_kg, s.block_title,
|
||||
ifnull(c.country_name, rc.country_name) as country_name, ifnull(c.weight_min, rc.weight_min) as weight_min, ifnull(c.weight_max, rc.weight_max) as weight_max
|
||||
from prc_surcharge_rel r
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Reference in New Issue
Block a user