diff --git a/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/PayProductController.java b/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/PayProductController.java index 5bd2a189..2a63c77a 100644 --- a/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/PayProductController.java +++ b/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/PayProductController.java @@ -29,6 +29,7 @@ import com.bms.price.domain.ChannelProductMap; import com.bms.price.domain.PayProduct; import com.bms.price.domain.PayProductTerm; import com.bms.price.domain.PaySaveCommand; +import com.bms.price.domain.PaySurcharge; import com.bms.price.pay.PayDetailExporter; import com.bms.price.pay.PayChargeMode; import com.bms.price.pay.PayTemplateWorkbook; @@ -136,6 +137,24 @@ public class PayProductController extends BaseController return success(payProductService.saveManual(product)); } + /** 这一版从附加费配置勾选的费用 */ + @PreAuthorize("@ss.hasPermi('price:pay:surcharge')") + @GetMapping("/term/{termId}/config-surcharges") + public AjaxResult configSurcharges(@PathVariable Long termId) + { + return success(payProductService.listConfigSurcharges(termId)); + } + + /** 保存这一版勾选的附加费和计费参数 */ + @PreAuthorize("@ss.hasPermi('price:pay:surcharge')") + @Log(title = "应付价卡附加费", businessType = BusinessType.UPDATE) + @PutMapping("/term/{termId}/config-surcharges") + public AjaxResult saveConfigSurcharges(@PathVariable Long termId, @RequestBody List rows) + { + payProductService.saveConfigSurcharges(termId, rows); + return success(); + } + @PreAuthorize("@ss.hasPermi('price:pay:query')") @GetMapping("/{productId}") public AjaxResult getInfo(@PathVariable Long productId) diff --git a/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/SurchargeController.java b/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/SurchargeController.java index fd1a7493..30f3726f 100644 --- a/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/SurchargeController.java +++ b/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/SurchargeController.java @@ -87,6 +87,7 @@ public class SurchargeController extends BaseController + " or @ss.hasPermi('price:set:query') or @ss.hasPermi('price:set:add') or @ss.hasPermi('price:set:edit')" + " or @ss.hasPermi('price:billing:bill')" + " or @ss.hasPermi('price:pay:query') or @ss.hasPermi('price:pay:edit') or @ss.hasPermi('price:pay:import')" + + " or @ss.hasPermi('price:pay:surcharge')" + " or @ss.hasPermi('price:airBill:fee')") @GetMapping("/options") public AjaxResult listOptions(PrcSurcharge surcharge) diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PaySurcharge.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PaySurcharge.java index c44a1167..ae7c2d56 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/domain/PaySurcharge.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PaySurcharge.java @@ -63,9 +63,27 @@ public class PaySurcharge /** 邮编列表、重量阈值或尺寸表达式。续重时这里是公斤阈值 */ private String calcParam; - /** 偏远邮编规则。续重行的阈值在 calcParam,邮编放这里,避免互相覆盖 */ + /** 偏远邮编规则。导入价卡仍可能把邮编写在这里 */ private String postcodeParam; + /** 来自附加费配置的长,厘米。本表不保存 */ + private BigDecimal lengthCm; + + /** 来自附加费配置的宽,厘米。本表不保存 */ + private BigDecimal widthCm; + + /** 来自附加费配置的高,厘米。本表不保存 */ + private BigDecimal heightCm; + + /** 来自附加费配置的超重阈值,公斤。本表不保存 */ + private BigDecimal overWeightKg; + + /** 来自附加费配置的续重起始重量,公斤。本表不保存 */ + private BigDecimal extraWeightKg; + + /** 来自附加费配置的命中邮编。本表不保存 */ + private String postcodeText; + /** 适用重量下限,空表示不限。首重从 0 开始 */ private BigDecimal weightMin; diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurcharge.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurcharge.java index 99266a8a..9e8c4fd7 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurcharge.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurcharge.java @@ -21,6 +21,18 @@ public class PrcSurcharge extends BaseEntity /** 渠道产品(字典 payment_product_type.dict_value) */ private String dictValue; private BigDecimal chargeValue; + /** 超尺寸长,厘米 */ + private BigDecimal lengthCm; + /** 超尺寸宽,厘米 */ + private BigDecimal widthCm; + /** 超尺寸高,厘米 */ + private BigDecimal heightCm; + /** 超重阈值,公斤 */ + private BigDecimal overWeightKg; + /** 超重续收起始重量,公斤 */ + private BigDecimal extraWeightKg; + /** 命中邮编,多个用逗号分隔 */ + private String postcodeText; private String currency; /** 字典 bms_round_mode:UP / DOWN / HALF_UP */ private String roundMode; diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurchargeBind.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurchargeBind.java new file mode 100644 index 00000000..cbb9998f --- /dev/null +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcSurchargeBind.java @@ -0,0 +1,66 @@ +package com.bms.price.domain; + +import java.math.BigDecimal; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +/** + * 产品与附加费配置的关联。应付、应收以及后续类型都按产品编号和类型查询。 + */ +@Data +public class PrcSurchargeBind +{ + public static final String TYPE_AP = "AP"; + + public static final String TYPE_AR = "AR"; + + private Long bindId; + + private Long productId; + + /** AP 应付,AR 应收,以及后续其它类型 */ + private String productType; + + private Long scId; + + private Integer sortNo; + + private String createdBy; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + + private String updatedBy; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date updateTime; + + /** 关联查询带出的附加费配置 */ + private String scName; + + private String chargeType; + + private BigDecimal chargeValue; + + private String currency; + + /** on 启用,of 停用,vd 作废 */ + private String ssCode; + + private String blockTitle; + + private String scNote; + + private BigDecimal lengthCm; + + private BigDecimal widthCm; + + private BigDecimal heightCm; + + private BigDecimal overWeightKg; + + private BigDecimal extraWeightKg; + + private String postcodeText; +} diff --git a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PayProductMapper.java b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PayProductMapper.java index 07a7f1fa..018e01d0 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PayProductMapper.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PayProductMapper.java @@ -58,6 +58,10 @@ public interface PayProductMapper int deleteSurchargesByTerm(@Param("termIds") List termIds); + int deleteSurchargesByTermSection(@Param("termId") Long termId, @Param("sectionName") String sectionName); + + int refreshSurchargeCount(@Param("productId") Long productId); + int deleteExtraLinesByTerm(@Param("termIds") List termIds); Long selectTemplateIdByType(@Param("dictValue") String dictValue, @Param("productType") String productType); diff --git a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcSurchargeBindMapper.java b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcSurchargeBindMapper.java new file mode 100644 index 00000000..05ae34af --- /dev/null +++ b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcSurchargeBindMapper.java @@ -0,0 +1,23 @@ +package com.bms.price.mapper; + +import java.util.List; +import org.apache.ibatis.annotations.Param; +import com.bms.price.domain.PrcSurchargeBind; + +/** + * 产品与附加费配置的关联。 + */ +public interface PrcSurchargeBindMapper +{ + List selectByProduct(@Param("productId") Long productId, @Param("productType") String productType); + + List selectByProductIds(@Param("productIds") List productIds); + + int deleteByProduct(@Param("productId") Long productId, @Param("productType") String productType); + + int deleteByProductIds(@Param("productIds") List productIds); + + int insertBinds(@Param("list") List list); + + int rebindScId(@Param("oldScId") Long oldScId, @Param("newScId") Long newScId); +} diff --git a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcSurchargeMapper.java b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcSurchargeMapper.java index 98e65abe..251193e9 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcSurchargeMapper.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcSurchargeMapper.java @@ -24,4 +24,10 @@ public interface PrcSurchargeMapper /** 状态原地更新(不新增数据):停用置 of,版本化作废旧记录置 vd */ public int updateSsCodeByIds(@Param("scIds") Long[] scIds, @Param("ssCode") String ssCode, @Param("operator") String operator); + + /** 附加费改版后,应付价卡上的选择改指向新记录,并带上新的金额和说明。 */ + public int rebindPayConfig(@Param("oldScId") Long oldScId, @Param("newScId") Long newScId, + @Param("feeName") String feeName, @Param("zoneName") String zoneName, @Param("amount") java.math.BigDecimal amount, + @Param("currency") String currency, @Param("feeDesc") String feeDesc, @Param("calcRule") String calcRule, + @Param("chargeText") String chargeText, @Param("priceUnit") String priceUnit); } diff --git a/bms-back/bms-system/src/main/java/com/bms/price/pay/LabelArCostCalculator.java b/bms-back/bms-system/src/main/java/com/bms/price/pay/LabelArCostCalculator.java index 0957cc2b..20192704 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/pay/LabelArCostCalculator.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/pay/LabelArCostCalculator.java @@ -338,7 +338,7 @@ public final class LabelArCostCalculator String name = blank(fee.getFeeName()); if (PaySurchargeRules.POSTCODE.equals(rule)) { - String param = blank(fee.getPostcodeParam()).isEmpty() ? fee.getCalcParam() : fee.getPostcodeParam(); + String param = PaySurchargeRules.feePostcodes(fee); if (postcode == null || postcode.isBlank()) { result.getSkipped().add(name + ":订单没有邮编"); @@ -358,9 +358,9 @@ public final class LabelArCostCalculator } else if (PaySurchargeRules.WEIGHT.equals(rule)) { - if (PaySurchargeRules.matchesWeight(fee.getCalcParam(), weight)) + if (PaySurchargeRules.matchesFeeWeight(fee, weight)) { - addFlat(result.getFees(), fee, currency, "计费重超过 " + fee.getCalcParam() + "kg"); + addFlat(result.getFees(), fee, currency, "计费重超过 " + PaySurchargeRules.weightText(fee) + "kg"); } } // 超出尺寸费用 @@ -370,7 +370,7 @@ public final class LabelArCostCalculator { result.getSkipped().add(name + ":订单没有长宽高"); } - else if (PaySurchargeRules.matchesSize(fee.getCalcParam(), length, width, height)) + else if (PaySurchargeRules.matchesFeeSize(fee, length, width, height)) { PayCostLine matched = matchedFee(fee, freight, currency, "尺寸命中 " + fee.getCalcParam()); if (matched != null) @@ -459,12 +459,8 @@ public final class LabelArCostCalculator { return; } - BigDecimal threshold; - try - { - threshold = new BigDecimal(fee.getCalcParam() == null ? "" : fee.getCalcParam().trim()); - } - catch (NumberFormatException ex) + BigDecimal threshold = PaySurchargeRules.extraStartKg(fee); + if (threshold == null) { return; } @@ -517,16 +513,10 @@ public final class LabelArCostCalculator { continue; } - try + BigDecimal start = PaySurchargeRules.extraStartKg(fee); + if (start != null && start.compareTo(threshold) == 0) { - if (fee.getCalcParam() != null && new BigDecimal(fee.getCalcParam().trim()).compareTo(threshold) == 0) - { - return true; - } - } - catch (NumberFormatException ex) - { - continue; + return true; } } return false; @@ -593,11 +583,7 @@ public final class LabelArCostCalculator /** 价卡这一档写了邮编时,订单邮编必须落在里面。续重的重量门槛不算邮编。 */ private static boolean feePostcodeMatches(PaySurcharge fee, String rule, String postcode) { - String param = blank(fee.getPostcodeParam()); - if (param.isEmpty() && !PaySurchargeRules.EXTRA_KG.equals(rule)) - { - param = blank(fee.getCalcParam()); - } + String param = PaySurchargeRules.EXTRA_KG.equals(rule) ? blank(fee.getPostcodeParam()) : PaySurchargeRules.feePostcodes(fee); if (param.isEmpty()) { return false; diff --git a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayCostCalculator.java b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayCostCalculator.java index 435304ac..e606d027 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayCostCalculator.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayCostCalculator.java @@ -363,7 +363,7 @@ public final class PayCostCalculator } else { - String param = blank(fee.getPostcodeParam()).isEmpty() ? fee.getCalcParam() : fee.getPostcodeParam(); + String param = PaySurchargeRules.feePostcodes(fee); if (postcode == null || postcode.isBlank()) { result.getSkipped().add(name + ":订单没有邮编"); @@ -400,9 +400,9 @@ public final class PayCostCalculator } else if (PaySurchargeRules.WEIGHT.equals(rule)) { - if (PaySurchargeRules.matchesWeight(fee.getCalcParam(), weight)) + if (PaySurchargeRules.matchesFeeWeight(fee, weight)) { - addFlat(result.getFees(), fee, currency, "计费重超过 " + fee.getCalcParam() + "kg"); + addFlat(result.getFees(), fee, currency, "计费重超过 " + PaySurchargeRules.weightText(fee) + "kg"); } } // 超出尺寸费用 @@ -509,12 +509,8 @@ public final class PayCostCalculator { return; } - BigDecimal threshold; - try - { - threshold = new BigDecimal(fee.getCalcParam() == null ? "" : fee.getCalcParam().trim()); - } - catch (NumberFormatException ex) + BigDecimal threshold = PaySurchargeRules.extraStartKg(fee); + if (threshold == null) { return; } @@ -567,16 +563,10 @@ public final class PayCostCalculator { continue; } - try + BigDecimal start = PaySurchargeRules.extraStartKg(fee); + if (start != null && start.compareTo(threshold) == 0) { - if (fee.getCalcParam() != null && new BigDecimal(fee.getCalcParam().trim()).compareTo(threshold) == 0) - { - return true; - } - } - catch (NumberFormatException ex) - { - continue; + return true; } } return false; @@ -601,7 +591,7 @@ public final class PayCostCalculator List> details = ruleDetails(product, PaySurchargeRules.SIZE); if (details.isEmpty()) { - return PaySurchargeRules.matchesSize(fee.getCalcParam(), length, width, height); + return PaySurchargeRules.matchesFeeSize(fee, length, width, height); } for (Map detail : details) { @@ -711,11 +701,7 @@ public final class PayCostCalculator /** 价卡这一档写了邮编时,订单邮编必须落在里面。续重的重量门槛不算邮编。 */ private static boolean feePostcodeMatches(PaySurcharge fee, String rule, String postcode) { - String param = blank(fee.getPostcodeParam()); - if (param.isEmpty() && !PaySurchargeRules.EXTRA_KG.equals(rule)) - { - param = blank(fee.getCalcParam()); - } + String param = PaySurchargeRules.EXTRA_KG.equals(rule) ? blank(fee.getPostcodeParam()) : PaySurchargeRules.feePostcodes(fee); if (param.isEmpty()) { return false; diff --git a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayOrderFeeCalculator.java b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayOrderFeeCalculator.java index 431f09da..b5b7c345 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/pay/PayOrderFeeCalculator.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/pay/PayOrderFeeCalculator.java @@ -180,25 +180,27 @@ public class PayOrderFeeCalculator } /** - * 运费仍按订单日期取版本。附加费明细改用这个产品今天生效的版本。 + * 运费仍按订单日期取版本。附加费只取该价卡产品已绑定且启用的附加费配置。 * * @param channelId 渠道 ID * @param priced 订单日期已经命中的价卡,方法会改写它的附加费 */ private void applyCurrentSurcharge(String channelId, PayProduct priced) { + PayProduct source = priced; try { PayProduct current = payProductService.selectPriceForDate(channelId, new Date()); - if (current != null && current.getSurcharges() != null) + if (current != null) { - priced.setSurcharges(current.getSurcharges()); + source = current; } } catch (ServiceException ignored) { - // 今天没有生效版本时,附加费明细仍用订单日期命中的那一版 + // 今天没有生效版本时,改查订单日期命中的那一版有没有绑定 } + priced.setSurcharges(payProductService.boundSurcharges(source)); } /** diff --git a/bms-back/bms-system/src/main/java/com/bms/price/pay/PaySurchargeRules.java b/bms-back/bms-system/src/main/java/com/bms/price/pay/PaySurchargeRules.java index f09193da..fc5537d0 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/pay/PaySurchargeRules.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/pay/PaySurchargeRules.java @@ -505,6 +505,82 @@ public final class PaySurchargeRules } } + /** 配置了长宽高时按三边箱规判断,否则仍认导入价卡里的尺寸表达式。 */ + public static boolean matchesFeeSize(PaySurcharge fee, BigDecimal length, BigDecimal width, BigDecimal height) + { + if (fee != null && fee.getLengthCm() != null && fee.getWidthCm() != null && fee.getHeightCm() != null) + { + if (length == null || width == null || height == null) + { + return false; + } + return exceedsBox(desc(length, width, height), fee.getLengthCm(), fee.getWidthCm(), fee.getHeightCm()); + } + return matchesSize(fee == null ? null : fee.getCalcParam(), length, width, height); + } + + /** 配置了超重公斤时按该值判断,否则仍认导入价卡里的重量文本。 */ + public static boolean matchesFeeWeight(PaySurcharge fee, BigDecimal weight) + { + if (fee != null && fee.getOverWeightKg() != null) + { + return weight != null && weight.compareTo(fee.getOverWeightKg()) > 0; + } + return matchesWeight(fee == null ? null : fee.getCalcParam(), weight); + } + + /** 续重起始公斤。配置列优先,导入价卡仍从原条件文本读取。 */ + public static BigDecimal extraStartKg(PaySurcharge fee) + { + if (fee == null) + { + return null; + } + if (fee.getExtraWeightKg() != null) + { + return fee.getExtraWeightKg(); + } + if (fee.getCalcParam() == null || fee.getCalcParam().isBlank()) + { + return null; + } + try + { + return new BigDecimal(fee.getCalcParam().trim()); + } + catch (NumberFormatException ex) + { + return null; + } + } + + /** 命中邮编。独立字段优先,其次是原来的邮编列和导入文本。 */ + public static String feePostcodes(PaySurcharge fee) + { + if (fee == null) + { + return ""; + } + if (fee.getPostcodeText() != null && !fee.getPostcodeText().isBlank()) + { + return fee.getPostcodeText().trim(); + } + if (fee.getPostcodeParam() != null && !fee.getPostcodeParam().isBlank()) + { + return fee.getPostcodeParam().trim(); + } + return fee.getCalcParam() == null ? "" : fee.getCalcParam().trim(); + } + + public static String weightText(PaySurcharge fee) + { + if (fee != null && fee.getOverWeightKg() != null) + { + return fee.getOverWeightKg().stripTrailingZeros().toPlainString(); + } + return fee == null || fee.getCalcParam() == null ? "" : fee.getCalcParam(); + } + public static boolean matchesWeight(String param, BigDecimal weight) { if (param == null || param.isBlank() || weight == null) diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/IPayProductService.java b/bms-back/bms-system/src/main/java/com/bms/price/service/IPayProductService.java index 6717f8fe..e8f49a62 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/IPayProductService.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/IPayProductService.java @@ -11,6 +11,7 @@ import com.bms.price.domain.ChannelProductMap; import com.bms.price.domain.PayProduct; import com.bms.price.domain.PayProductTerm; import com.bms.price.domain.PaySaveCommand; +import com.bms.price.domain.PaySurcharge; /** * 应付价卡配置:预览后保存,列表查询和导出。 @@ -136,6 +137,18 @@ public interface IPayProductService /** 产品及其重量段、附加费、邮编配置 */ PayProduct selectPayProductDetail(Long productId); + /** 这一版价卡上,从附加费配置勾选进来的费用 */ + List listConfigSurcharges(Long termId); + + /** + * 应付计费用的附加费。只取这个产品在关联表里绑定、并且仍在启用的附加费配置。 + * 没有绑定时返回空列表,价卡里导入的附加费不参与计算。 + */ + List boundSurcharges(PayProduct product); + + /** 按附加费配置重写这一版勾选的费用,导入进来的附加费不动 */ + void saveConfigSurcharges(Long termId, List rows); + /** 确认这一版有源文件,返回原始文件名 */ String sourceFileName(Long productId); diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java index 4c2d2dba..40082036 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java @@ -229,21 +229,23 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService * @param product 当前价卡版本 * @return 名称能对上的邮编组,没有时为空列表 */ - /** 运费仍按订单日期取版本。附加费条件和附加费明细改用产品当前生效版本。 */ + /** 运费仍按订单日期取版本。附加费只取该价卡产品已绑定且启用的附加费配置。 */ private void applyCurrentSurcharge(String channelId, PayProduct priced) { + PayProduct source = priced; try { PayProduct current = payProductService.selectPriceForDate(channelId, new Date()); - if (current != null && current.getSurcharges() != null) + if (current != null) { - priced.setSurcharges(current.getSurcharges()); + source = current; } } catch (ServiceException ignored) { - // 今天没有生效版本时,附加费明细仍用订单日期命中的那一版 + // 今天没有生效版本时,改查订单日期命中的那一版有没有绑定 } + priced.setSurcharges(payProductService.boundSurcharges(source)); } private List linkedGroups(PayProduct product) diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayProductServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayProductServiceImpl.java index 1aea910e..b0616b92 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayProductServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayProductServiceImpl.java @@ -41,12 +41,14 @@ import com.bms.price.domain.PaySurcharge; import com.bms.price.domain.PayWeightBand; import com.bms.price.domain.PrcPriceSet; import com.bms.price.domain.PrcSurcharge; +import com.bms.price.domain.PrcSurchargeBind; import com.bms.masterdata.domain.ServiceChannel; import com.bms.masterdata.mapper.ServiceChannelMapper; import com.bms.price.mapper.ChannelProductMapMapper; import com.bms.price.mapper.PayProductMapper; import com.bms.price.mapper.PayProductTermMapper; 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.PayChargeMode; @@ -84,6 +86,9 @@ public class PayProductServiceImpl implements IPayProductService @Autowired private PrcSurchargeMapper prcSurchargeMapper; + @Autowired + private PrcSurchargeBindMapper surchargeBindMapper; + @Autowired private ChannelProductMapMapper channelProductMapMapper; @@ -1002,15 +1007,302 @@ public class PayProductServiceImpl implements IPayProductService product.setWeightBands(payProductMapper.selectWeightBandsByTerm(termIds)); product.setSurcharges(payProductMapper.selectSurchargesByTerm(termIds)); product.setExtraLines(payProductMapper.selectExtraLinesByTerm(termIds)); + appendBoundSurcharges(product); return product; } List ids = Collections.singletonList(productId); product.setWeightBands(payProductMapper.selectWeightBands(ids)); product.setSurcharges(payProductMapper.selectSurcharges(ids)); product.setExtraLines(payProductMapper.selectExtraLines(ids)); + appendBoundSurcharges(product); return product; } + private static final String CONFIG_SECTION = "附加费配置"; + + @Override + public List listConfigSurcharges(Long termId) + { + PayProductTerm term = requireTerm(termId); + PayProduct product = payProductMapper.selectPayProductById(term.getProductId()); + if (product == null) + { + throw new ServiceException("价卡不存在"); + } + List picked = new ArrayList<>(); + for (PrcSurchargeBind bind : surchargeBindMapper.selectByProduct(product.getProductId(), bindType(product))) + { + picked.add(toBoundFee(bind)); + } + return picked; + } + + @Override + public List boundSurcharges(PayProduct product) + { + List fees = new ArrayList<>(); + if (product == null || product.getProductId() == null) + { + return fees; + } + for (PrcSurchargeBind bind : surchargeBindMapper.selectByProduct(product.getProductId(), bindType(product))) + { + if (bind == null || bind.getSsCode() == null || !"on".equalsIgnoreCase(bind.getSsCode())) + { + continue; + } + fees.add(toBoundFee(bind, product.getCurrency())); + } + return fees; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveConfigSurcharges(Long termId, List rows) + { + PayProductTerm term = requireTerm(termId); + PayProduct product = payProductMapper.selectPayProductById(term.getProductId()); + if (product == null) + { + throw new ServiceException("价卡不存在"); + } + List saving = new ArrayList<>(); + Set seen = new LinkedHashSet<>(); + int sort = 1; + String type = bindType(product); + for (PaySurcharge input : rows == null ? List.of() : rows) + { + if (input == null || input.getScId() == null) + { + throw new ServiceException("请选择附加费"); + } + if (!seen.add(input.getScId())) + { + throw new ServiceException("同一附加费不能重复添加"); + } + PrcSurcharge config = prcSurchargeMapper.selectPrcSurchargeById(input.getScId()); + if (config == null || !"on".equalsIgnoreCase(config.getSsCode())) + { + throw new ServiceException("附加费不存在或已停用"); + } + if (config.getChargeValue() == null) + { + throw new ServiceException(config.getScName() + "还没有计费数值,请先到附加费配置里填写"); + } + PaySurcharge check = new PaySurcharge(); + check.setFeeName(config.getScName()); + check.setCurrency(isBlank(config.getCurrency()) ? product.getCurrency() : config.getCurrency()); + check.setCalcRule(calcRuleOf(config.getChargeType())); + check.setFeeDesc(config.getScNote()); + applyConfigParam(check, config); + PrcSurchargeBind bind = new PrcSurchargeBind(); + bind.setProductId(product.getProductId()); + bind.setProductType(type); + bind.setScId(config.getScId()); + bind.setSortNo(sort++); + bind.setCreatedBy(SecurityUtils.getUsername()); + saving.add(bind); + } + surchargeBindMapper.deleteByProduct(product.getProductId(), type); + if (!saving.isEmpty()) + { + surchargeBindMapper.insertBinds(saving); + } + payProductMapper.deleteSurchargesByTermSection(termId, CONFIG_SECTION); + payProductMapper.refreshSurchargeCount(product.getProductId()); + } + + /** 条件只认附加费配置上的字段,价卡行只记下说明文字。 */ + private void applyConfigParam(PaySurcharge fee, PrcSurcharge config) + { + String rule = fee.getCalcRule(); + 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"); + fee.setPriceUnit(currency + "/ITEM"); + return; + } + if ("WEIGHT".equals(rule)) + { + BigDecimal threshold = positiveOrZero(config.getOverWeightKg(), fee.getFeeName() + "的超重重量"); + fee.setChargeText("超过 " + plain(threshold) + "kg"); + fee.setPriceUnit(currency + "/ITEM"); + return; + } + if ("EXTRA_KG".equals(rule)) + { + BigDecimal threshold = positiveOrZero(config.getExtraWeightKg(), fee.getFeeName() + "的续重起始重量"); + fee.setChargeText("超出 " + plain(threshold) + "kg 后续收"); + fee.setPriceUnit(currency + "/KG"); + return; + } + if ("POSTCODE".equals(rule)) + { + String postcodes = joinPostcodes(config.getPostcodeText()); + if (postcodes.isEmpty()) + { + throw new ServiceException(fee.getFeeName() + "请先到附加费配置里填写邮编"); + } + fee.setChargeText(cut("邮编 " + postcodes, 500)); + fee.setPriceUnit(currency + "/ITEM"); + return; + } + fee.setPriceUnit(currency + "/ITEM"); + fee.setChargeText(isBlank(fee.getFeeDesc()) ? "" : cut(fee.getFeeDesc(), 500)); + } + + private void appendBoundSurcharges(PayProduct product) + { + if (product == null || product.getProductId() == null) + { + return; + } + List fees = product.getSurcharges(); + if (fees == null) + { + fees = new ArrayList<>(); + product.setSurcharges(fees); + } + fees.removeIf(fee -> fee != null && CONFIG_SECTION.equals(fee.getSectionName())); + for (PrcSurchargeBind bind : surchargeBindMapper.selectByProduct(product.getProductId(), bindType(product))) + { + fees.add(toBoundFee(bind, product.getCurrency())); + } + } + + private PaySurcharge toBoundFee(PrcSurchargeBind bind) + { + return toBoundFee(bind, null); + } + + private PaySurcharge toBoundFee(PrcSurchargeBind bind, String productCurrency) + { + PaySurcharge fee = new PaySurcharge(); + fee.setProductId(bind.getProductId()); + fee.setSectionName(CONFIG_SECTION); + fee.setFeeName(bind.getScName()); + fee.setScId(bind.getScId()); + fee.setZoneName(blankTo(bind.getBlockTitle(), "")); + fee.setAmount(bind.getChargeValue()); + fee.setCurrency(isBlank(bind.getCurrency()) ? productCurrency : bind.getCurrency().trim().toUpperCase(Locale.ROOT)); + fee.setFeeDesc(bind.getScNote()); + fee.setCalcRule(calcRuleOf(bind.getChargeType())); + fee.setSortNo(bind.getSortNo()); + fee.setLengthCm(bind.getLengthCm()); + fee.setWidthCm(bind.getWidthCm()); + fee.setHeightCm(bind.getHeightCm()); + fee.setOverWeightKg(bind.getOverWeightKg()); + fee.setExtraWeightKg(bind.getExtraWeightKg()); + fee.setPostcodeText(bind.getPostcodeText()); + PrcSurcharge config = new PrcSurcharge(); + config.setChargeType(bind.getChargeType()); + config.setLengthCm(bind.getLengthCm()); + config.setWidthCm(bind.getWidthCm()); + config.setHeightCm(bind.getHeightCm()); + config.setOverWeightKg(bind.getOverWeightKg()); + config.setExtraWeightKg(bind.getExtraWeightKg()); + config.setPostcodeText(bind.getPostcodeText()); + config.setScNote(bind.getScNote()); + applyConfigParam(fee, config); + return fee; + } + + private static String bindType(PayProduct product) + { + if (product == null || isBlank(product.getProductType())) + { + return PAY_TYPE_AP; + } + return product.getProductType().trim().toUpperCase(Locale.ROOT); + } + + private PayProductTerm requireTerm(Long termId) + { + if (termId == null) + { + throw new ServiceException("请先为价卡设置有效期"); + } + PayProductTerm term = payProductTermMapper.selectById(termId); + if (term == null || term.getPriceSetId() != null) + { + throw new ServiceException("价卡版本不存在"); + } + return term; + } + + private static String calcRuleOf(String chargeType) + { + if (chargeType == null) + { + return "MANUAL"; + } + String code = chargeType.trim().toUpperCase(Locale.ROOT); + if ("FIXED".equals(code)) + { + return "ALWAYS"; + } + if ("RATE".equals(code)) + { + 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)) + { + return code; + } + return "MANUAL"; + } + + private static BigDecimal positive(BigDecimal value, String label) + { + if (value == null || value.compareTo(BigDecimal.ZERO) <= 0) + { + throw new ServiceException(label + "要大于 0,请先到附加费配置里填写"); + } + return value; + } + + private static BigDecimal positiveOrZero(BigDecimal value, String label) + { + if (value == null) + { + throw new ServiceException("请先到附加费配置里填写" + label); + } + if (value.compareTo(BigDecimal.ZERO) < 0) + { + throw new ServiceException(label + "不能小于 0"); + } + return value; + } + + private static String joinPostcodes(String raw) + { + if (raw == null) + { + return ""; + } + String normalized = raw.replace(',', ',').replace('、', ',').replace(';', ',').replace(';', ',').replace('\n', ',').replace('\r', ','); + LinkedHashSet tokens = new LinkedHashSet<>(); + for (String part : normalized.split(",")) + { + String value = part.trim(); + if (!value.isEmpty()) + { + tokens.add(value); + } + } + return String.join(",", tokens); + } + + private static String plain(BigDecimal value) + { + return value.stripTrailingZeros().toPlainString(); + } + @Override public PayProduct selectPayProductDetailByTerm(Long termId) { @@ -1041,6 +1333,7 @@ public class PayProductServiceImpl implements IPayProductService product.setWeightBands(payProductMapper.selectWeightBandsByTerm(termIds)); product.setSurcharges(payProductMapper.selectSurchargesByTerm(termIds)); product.setExtraLines(payProductMapper.selectExtraLinesByTerm(termIds)); + appendBoundSurcharges(product); return product; } @@ -1626,6 +1919,7 @@ public class PayProductServiceImpl implements IPayProductService payProductTermMapper.deleteByProductIds(ids); payProductMapper.deleteWeightBands(ids); payProductMapper.deleteSurcharges(ids); + surchargeBindMapper.deleteByProductIds(ids); payProductMapper.deleteExtraLines(ids); return payProductMapper.deletePayProducts(ids); } @@ -1658,11 +1952,19 @@ public class PayProductServiceImpl implements IPayProductService for (PaySurcharge fee : payProductMapper.selectSurcharges(ids)) { PayProduct owner = map.get(fee.getProductId()); - if (owner != null) + if (owner != null && (fee == null || !CONFIG_SECTION.equals(fee.getSectionName()))) { owner.getSurcharges().add(fee); } } + for (PrcSurchargeBind bind : surchargeBindMapper.selectByProductIds(ids)) + { + PayProduct owner = map.get(bind.getProductId()); + if (owner != null && bindType(owner).equals(bind.getProductType())) + { + owner.getSurcharges().add(toBoundFee(bind, owner.getCurrency())); + } + } for (PayExtraLine line : payProductMapper.selectExtraLines(ids)) { PayProduct owner = map.get(line.getProductId()); diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcSurchargeServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcSurchargeServiceImpl.java index ccc06c97..e27d717d 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcSurchargeServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcSurchargeServiceImpl.java @@ -1,5 +1,7 @@ package com.bms.price.service.impl; +import java.math.BigDecimal; +import java.util.LinkedHashSet; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -8,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.mapper.PrcSurchargeBindMapper; import com.bms.price.mapper.PrcSurchargeMapper; import com.bms.price.mapper.PrcSurchargeRelMapper; import com.bms.price.service.IPrcSurchargeService; @@ -33,6 +36,9 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService @Autowired private PrcSurchargeRelMapper surchargeRelMapper; + @Autowired + private PrcSurchargeBindMapper surchargeBindMapper; + @Override public PrcSurcharge selectPrcSurchargeById(Long scId) { @@ -48,6 +54,7 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService @Override public int insertPrcSurcharge(PrcSurcharge surcharge) { + applyCalcParam(surcharge); validate(surcharge); applyInsertDefaults(surcharge); return surchargeMapper.insertPrcSurcharge(surcharge); @@ -60,12 +67,17 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService @Transactional public int updatePrcSurcharge(PrcSurcharge surcharge) { + applyCalcParam(surcharge); validate(surcharge); PrcSurcharge old = surchargeMapper.selectPrcSurchargeById(surcharge.getScId()); if (old == null) { throw new ServiceException("附加费不存在或已被作废,无法修改"); } + if (StringUtils.isEmpty(surcharge.getDictValue())) + { + surcharge.setDictValue(old.getDictValue()); + } // 无实际变化:不置作废、不插新记录,返回 -1 由 Controller 提示"未修改" if (isUnchanged(old, surcharge)) { @@ -81,6 +93,12 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService fresh.setChargeType(surcharge.getChargeType()); fresh.setDictValue(surcharge.getDictValue()); fresh.setChargeValue(surcharge.getChargeValue()); + fresh.setLengthCm(surcharge.getLengthCm()); + fresh.setWidthCm(surcharge.getWidthCm()); + fresh.setHeightCm(surcharge.getHeightCm()); + fresh.setOverWeightKg(surcharge.getOverWeightKg()); + fresh.setExtraWeightKg(surcharge.getExtraWeightKg()); + fresh.setPostcodeText(surcharge.getPostcodeText()); fresh.setCurrency(surcharge.getCurrency()); fresh.setRoundMode(surcharge.getRoundMode()); fresh.setSsCode(old.getSsCode()); @@ -92,6 +110,7 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService int rows = surchargeMapper.insertPrcSurcharge(fresh); // 3. 产品关联重指向新记录,保持产品附加费配置不失效 surchargeRelMapper.rebindRelScId(surcharge.getScId(), fresh.getScId(), operator); + syncPayCards(surcharge.getScId(), fresh); return rows; } @@ -103,6 +122,12 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService && eq(old.getChargeType(), updated.getChargeType()) && eq(old.getDictValue(), updated.getDictValue()) && eqDecimal(old.getChargeValue(), updated.getChargeValue()) + && eqDecimal(old.getLengthCm(), updated.getLengthCm()) + && eqDecimal(old.getWidthCm(), updated.getWidthCm()) + && eqDecimal(old.getHeightCm(), updated.getHeightCm()) + && eqDecimal(old.getOverWeightKg(), updated.getOverWeightKg()) + && eqDecimal(old.getExtraWeightKg(), updated.getExtraWeightKg()) + && eq(old.getPostcodeText(), updated.getPostcodeText()) && eq(old.getCurrency(), updated.getCurrency()) && eq(old.getRoundMode(), updated.getRoundMode()) && eq(old.getCountryCode(), updated.getCountryCode()) @@ -190,4 +215,154 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService throw new ServiceException(MessageUtils.message("price.surcharge.chargeValue.negative")); } } + + /** 只保留当前计费方式用到的字段,其余条件清空。 */ + private void applyCalcParam(PrcSurcharge row) + { + String type = row.getChargeType() == null ? "" : row.getChargeType().trim().toUpperCase(); + BigDecimal length = null; + BigDecimal width = null; + BigDecimal height = null; + BigDecimal overWeight = null; + BigDecimal extraWeight = null; + String postcodes = null; + if ("SIZE".equals(type)) + { + length = requiredSize(row.getLengthCm(), "长"); + width = requiredSize(row.getWidthCm(), "宽"); + height = requiredSize(row.getHeightCm(), "高"); + row.setBlockTitle(null); + } + else if ("WEIGHT".equals(type)) + { + overWeight = requiredWeight(row.getOverWeightKg(), "超过重量"); + row.setBlockTitle(null); + } + else if ("EXTRA_KG".equals(type)) + { + extraWeight = requiredWeight(row.getExtraWeightKg(), "续重起始重量"); + row.setBlockTitle(null); + } + else if ("POSTCODE".equals(type)) + { + postcodes = joinPostcodes(row.getPostcodeText()); + if (postcodes.isEmpty()) + { + throw new ServiceException("请填写邮编,多个用逗号分隔"); + } + row.setBlockTitle(null); + } + else if (!"ZONE".equals(type)) + { + row.setBlockTitle(null); + } + row.setLengthCm(length); + row.setWidthCm(width); + row.setHeightCm(height); + row.setOverWeightKg(overWeight); + row.setExtraWeightKg(extraWeight); + row.setPostcodeText(postcodes); + } + + private static BigDecimal requiredSize(BigDecimal value, String label) + { + if (value == null || value.compareTo(BigDecimal.ZERO) <= 0) + { + throw new ServiceException(label + "要大于 0"); + } + return value; + } + + private static BigDecimal requiredWeight(BigDecimal value, String label) + { + if (value == null) + { + throw new ServiceException("请填写" + label); + } + if (value.compareTo(BigDecimal.ZERO) < 0) + { + throw new ServiceException(label + "不能小于 0"); + } + return value; + } + + /** 价卡上的附加费改指向新配置,金额和条件说明跟着新记录走。 */ + private void syncPayCards(Long oldScId, PrcSurcharge fresh) + { + String rule = calcRule(fresh.getChargeType()); + String currency = StringUtils.isEmpty(fresh.getCurrency()) ? null : fresh.getCurrency().trim().toUpperCase(); + String priceUnit = currency == null ? null : ("EXTRA_KG".equals(rule) ? currency + "/KG" : currency + "/ITEM"); + surchargeMapper.rebindPayConfig(oldScId, fresh.getScId(), fresh.getScName(), + fresh.getBlockTitle() == null ? "" : fresh.getBlockTitle(), fresh.getChargeValue(), currency, + fresh.getScNote(), rule, chargeText(fresh, rule), priceUnit); + surchargeBindMapper.rebindScId(oldScId, fresh.getScId()); + } + + private static String calcRule(String chargeType) + { + if (chargeType == null) + { + return "MANUAL"; + } + String code = chargeType.trim().toUpperCase(); + if ("FIXED".equals(code)) + { + return "ALWAYS"; + } + if ("RATE".equals(code)) + { + return "MANUAL"; + } + return code; + } + + private static String chargeText(PrcSurcharge row, String rule) + { + String text; + if ("SIZE".equals(rule)) + { + text = "超过 " + plain(row.getLengthCm()) + "×" + plain(row.getWidthCm()) + "×" + plain(row.getHeightCm()) + "cm"; + } + else if ("WEIGHT".equals(rule)) + { + text = "超过 " + plain(row.getOverWeightKg()) + "kg"; + } + else if ("EXTRA_KG".equals(rule)) + { + text = "超出 " + plain(row.getExtraWeightKg()) + "kg 后续收"; + } + else if ("POSTCODE".equals(rule)) + { + text = "邮编 " + (row.getPostcodeText() == null ? "" : row.getPostcodeText()); + } + else + { + text = row.getScNote() == null ? "" : row.getScNote(); + } + return text.length() > 500 ? text.substring(0, 500) : text; + } + + private static String plain(BigDecimal value) + { + return value == null ? "" : value.stripTrailingZeros().toPlainString(); + } + + private static String joinPostcodes(String raw) + { + if (raw == null) + { + return ""; + } + LinkedHashSet tokens = new LinkedHashSet<>(); + String normalized = raw.replace(',', ',').replace('、', ',').replace(';', ',').replace(';', ',').replace('\n', ',').replace('\r', ','); + for (String part : normalized.split(",")) + { + String value = part.trim(); + if (!value.isEmpty()) + { + tokens.add(value); + } + } + return String.join(",", tokens); + } } diff --git a/bms-back/bms-system/src/main/resources/mapper/price/PayProductMapper.xml b/bms-back/bms-system/src/main/resources/mapper/price/PayProductMapper.xml index e9b88077..04abc5e2 100644 --- a/bms-back/bms-system/src/main/resources/mapper/price/PayProductMapper.xml +++ b/bms-back/bms-system/src/main/resources/mapper/price/PayProductMapper.xml @@ -370,28 +370,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by product_id, sort_no, band_id + + s.surcharge_id as surchargeId, s.product_id as productId, s.term_id as termId, s.version_no as versionNo, + s.section_name as sectionName, s.fee_name as feeName, s.sc_id as scId, s.zone_name as zoneName, + s.charge_text as chargeText, s.amount, s.currency, s.price_unit as priceUnit, s.fee_desc as feeDesc, + s.period_text as periodText, s.effective_start as effectiveStart, s.effective_end as effectiveEnd, + s.charge_timing as chargeTiming, s.calc_rule as calcRule, s.calc_param as calcParam, + s.weight_min as weightMin, s.weight_max as weightMax, s.postcode_param as postcodeParam, + cfg.length_cm as lengthCm, cfg.width_cm as widthCm, cfg.height_cm as heightCm, + cfg.over_weight_kg as overWeightKg, cfg.extra_weight_kg as extraWeightKg, cfg.postcode_text as postcodeText, + s.sort_no as sortNo + + + select + from prc_surcharge_bind b + inner join prc_surcharge c on c.sc_id = b.sc_id and ifnull(c.is_del, '0') = '0' + where b.product_id = #{productId} + and b.product_type = #{productType} + order by b.sort_no, b.bind_id + + + + + + delete from prc_surcharge_bind + where product_id = #{productId} + and product_type = #{productType} + + + + delete from prc_surcharge_bind + where product_id in + #{id} + + + + insert into prc_surcharge_bind (product_id, product_type, sc_id, sort_no, created_by, create_time) + values + + (#{row.productId}, #{row.productType}, #{row.scId}, ifnull(#{row.sortNo}, 0), #{row.createdBy}, sysdate()) + + + + + update prc_surcharge_bind + set sc_id = #{newScId}, update_time = sysdate() + where sc_id = #{oldScId} + + + diff --git a/bms-back/bms-system/src/main/resources/mapper/price/PrcSurchargeMapper.xml b/bms-back/bms-system/src/main/resources/mapper/price/PrcSurchargeMapper.xml index 348319a8..1f2e3fb8 100644 --- a/bms-back/bms-system/src/main/resources/mapper/price/PrcSurchargeMapper.xml +++ b/bms-back/bms-system/src/main/resources/mapper/price/PrcSurchargeMapper.xml @@ -11,6 +11,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + @@ -26,7 +32,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select sc_id, sc_name, fee_type, charge_type, dict_value, charge_value, currency, round_mode, + 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, ss_code, is_del, country_code, block_title, sc_note, tms_id, created_by, create_time, updated_by, update_time from prc_surcharge @@ -92,6 +99,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" charge_type, dict_value, charge_value, + length_cm, + width_cm, + height_cm, + over_weight_kg, + extra_weight_kg, + postcode_text, currency, round_mode, ss_code, @@ -108,6 +121,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{chargeType}, #{dictValue}, #{chargeValue}, + #{lengthCm}, + #{widthCm}, + #{heightCm}, + #{overWeightKg}, + #{extraWeightKg}, + #{postcodeText}, #{currency}, #{roundMode}, #{ssCode}, @@ -132,4 +151,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + update pay_surcharge + set sc_id = #{newScId}, + fee_name = #{feeName}, + zone_name = #{zoneName}, + amount = #{amount}, + currency = ifnull(#{currency}, currency), + fee_desc = #{feeDesc}, + calc_rule = #{calcRule}, + charge_text = #{chargeText}, + price_unit = ifnull(#{priceUnit}, price_unit) + where sc_id = #{oldScId} + and section_name = '附加费配置' + + diff --git a/bms-back/sql/price/pay_card_surcharge_menu.sql b/bms-back/sql/price/pay_card_surcharge_menu.sql new file mode 100644 index 00000000..870715dc --- /dev/null +++ b/bms-back/sql/price/pay_card_surcharge_menu.sql @@ -0,0 +1,18 @@ +-- 应付配置增加附加费按钮 +INSERT INTO `bms`.`sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`) +SELECT 2678, '附加费', 2508, 8, '', '', 1, 0, 'F', '0', '0', 'price:pay:surcharge', '#', 'admin', sysdate() +FROM DUAL +WHERE NOT EXISTS (SELECT 1 FROM `bms`.`sys_menu` WHERE `menu_id` = 2678 OR `perms` = 'price:pay:surcharge'); + +-- 管理员拥有应付配置附加费按钮 +INSERT INTO `bms`.`sys_role_menu` (`role_id`, `menu_id`) +SELECT 1, 2678 +FROM DUAL +WHERE NOT EXISTS (SELECT 1 FROM `bms`.`sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2678); + +-- 能看应付配置的角色同时拥有附加费按钮 +INSERT INTO `bms`.`sys_role_menu` (`role_id`, `menu_id`) +SELECT DISTINCT rm.`role_id`, 2678 +FROM `bms`.`sys_role_menu` rm +WHERE rm.`menu_id` = 2508 + AND NOT EXISTS (SELECT 1 FROM `bms`.`sys_role_menu` x WHERE x.`role_id` = rm.`role_id` AND x.`menu_id` = 2678); diff --git a/bms-back/sql/price/pay_surcharge_condition_drop.sql b/bms-back/sql/price/pay_surcharge_condition_drop.sql new file mode 100644 index 00000000..b45df5ab --- /dev/null +++ b/bms-back/sql/price/pay_surcharge_condition_drop.sql @@ -0,0 +1,17 @@ +-- `pay_surcharge` 表中删除重复的`length_cm` 属性 +ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `length_cm`; + +-- `pay_surcharge` 表中删除重复的`width_cm` 属性 +ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `width_cm`; + +-- `pay_surcharge` 表中删除重复的`height_cm` 属性 +ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `height_cm`; + +-- `pay_surcharge` 表中删除重复的`over_weight_kg` 属性 +ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `over_weight_kg`; + +-- `pay_surcharge` 表中删除重复的`extra_weight_kg` 属性 +ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `extra_weight_kg`; + +-- `pay_surcharge` 表中删除重复的`postcode_text` 属性 +ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `postcode_text`; diff --git a/bms-back/sql/price/prc_surcharge_bind.sql b/bms-back/sql/price/prc_surcharge_bind.sql new file mode 100644 index 00000000..0746cfc6 --- /dev/null +++ b/bms-back/sql/price/prc_surcharge_bind.sql @@ -0,0 +1,25 @@ +-- 新建产品与附加费配置的关联表,按产品编号和类型查询 +CREATE TABLE `bms`.`prc_surcharge_bind` ( + `bind_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '关联ID', + `product_id` bigint(20) NOT NULL COMMENT '产品ID,对应 pay_product.product_id', + `product_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '产品类型:AP应付、AR应收,以及后续其它类型', + `sc_id` bigint(20) NOT NULL COMMENT '附加费配置ID,对应 prc_surcharge.sc_id', + `sort_no` int(11) NOT NULL DEFAULT 0 COMMENT '排序', + `created_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '创建人', + `create_time` datetime NULL COMMENT '创建时间', + `updated_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '更新人', + `update_time` datetime NULL COMMENT '更新时间', + PRIMARY KEY (`bind_id`), + UNIQUE KEY `uk_surcharge_bind_product` (`product_id`, `product_type`, `sc_id`), + KEY `idx_surcharge_bind_sc` (`sc_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='产品附加费关联,应付应收及其它类型按产品编号和类型匹配'; + +-- 把价卡上已经绑定的附加费配置迁入关联表 +INSERT INTO `bms`.`prc_surcharge_bind` (`product_id`, `product_type`, `sc_id`, `sort_no`, `created_by`, `create_time`) +SELECT s.`product_id`, ifnull(p.`product_type`, 'AP'), s.`sc_id`, ifnull(s.`sort_no`, 0), 'admin', sysdate() +FROM `bms`.`pay_surcharge` s +INNER JOIN `bms`.`pay_product` p ON p.`product_id` = s.`product_id` +WHERE s.`section_name` = '附加费配置' AND s.`sc_id` IS NOT NULL; + +-- 删除已经迁入关联表的价卡附加费明细 +DELETE FROM `bms`.`pay_surcharge` WHERE `section_name` = '附加费配置'; diff --git a/bms-back/sql/price/prc_surcharge_calc_param.sql b/bms-back/sql/price/prc_surcharge_calc_param.sql new file mode 100644 index 00000000..6d9f05e2 --- /dev/null +++ b/bms-back/sql/price/prc_surcharge_calc_param.sql @@ -0,0 +1,17 @@ +-- `prc_surcharge` 表中添加`length_cm` 属性 +ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `length_cm` decimal(10,2) NULL COMMENT '超尺寸长,厘米' AFTER `charge_value`; + +-- `prc_surcharge` 表中添加`width_cm` 属性 +ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `width_cm` decimal(10,2) NULL COMMENT '超尺寸宽,厘米' AFTER `length_cm`; + +-- `prc_surcharge` 表中添加`height_cm` 属性 +ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `height_cm` decimal(10,2) NULL COMMENT '超尺寸高,厘米' AFTER `width_cm`; + +-- `prc_surcharge` 表中添加`over_weight_kg` 属性 +ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `over_weight_kg` decimal(12,3) NULL COMMENT '超重阈值,公斤,超过才收取' AFTER `height_cm`; + +-- `prc_surcharge` 表中添加`extra_weight_kg` 属性 +ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `extra_weight_kg` decimal(12,3) NULL COMMENT '超重续收起始重量,公斤' AFTER `over_weight_kg`; + +-- `prc_surcharge` 表中添加`postcode_text` 属性 +ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `postcode_text` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '命中邮编,多个用逗号分隔' AFTER `extra_weight_kg`; diff --git a/bms-front/src/api/price/pay.js b/bms-front/src/api/price/pay.js index 7eb9ef32..b2cb2201 100644 --- a/bms-front/src/api/price/pay.js +++ b/bms-front/src/api/price/pay.js @@ -60,6 +60,23 @@ export function previewPayTemplate(file, chargeType) { }) } +/** 这一版价卡已勾选的附加费配置 */ +export function listPayConfigSurcharges(termId) { + return request({ + url: '/price/pay/term/' + termId + '/config-surcharges', + method: 'get' + }) +} + +/** 保存这一版勾选的附加费和计费条件 */ +export function savePayConfigSurcharges(termId, data) { + return request({ + url: '/price/pay/term/' + termId + '/config-surcharges', + method: 'put', + data + }) +} + /** 按所选计费模式手工新增一条价卡 */ export function savePayManual(data) { return request({ diff --git a/bms-front/src/views/price/basic/pay/components/PayCardSurchargeDialog.vue b/bms-front/src/views/price/basic/pay/components/PayCardSurchargeDialog.vue new file mode 100644 index 00000000..b5ee0e62 --- /dev/null +++ b/bms-front/src/views/price/basic/pay/components/PayCardSurchargeDialog.vue @@ -0,0 +1,252 @@ + + + + + diff --git a/bms-front/src/views/price/basic/pay/components/PayConfigDetail.vue b/bms-front/src/views/price/basic/pay/components/PayConfigDetail.vue index 5cebdb0c..0cc452d4 100644 --- a/bms-front/src/views/price/basic/pay/components/PayConfigDetail.vue +++ b/bms-front/src/views/price/basic/pay/components/PayConfigDetail.vue @@ -75,7 +75,7 @@ /> - +
@@ -274,6 +274,8 @@ import PaySurchargePickerDialog from './PaySurchargePickerDialog.vue' const { order_charge_type } = useDict('order_charge_type') +const showFees = false + function chargeTypeText(value) { const hit = (order_charge_type.value || []).find(item => item.value === value) if (hit) return hit.label diff --git a/bms-front/src/views/price/basic/pay/components/PayImportDialog.vue b/bms-front/src/views/price/basic/pay/components/PayImportDialog.vue index d36deff7..5b4dc2c0 100644 --- a/bms-front/src/views/price/basic/pay/components/PayImportDialog.vue +++ b/bms-front/src/views/price/basic/pay/components/PayImportDialog.vue @@ -76,7 +76,6 @@ -