New file |
| | |
| | | package com.ruoyi.cwgl.service.impl; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.cwgl.domain.ReceivableLineTruckPriceRule; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 精确运费规则匹配服务 |
| | | */ |
| | | public class ExactPricingRuleMatcher { |
| | | |
| | | /** |
| | | * 查找匹配的运费规则 |
| | | * @param rules 所有运费规则列表 |
| | | * @param customerName 客户名称 |
| | | * @param departureLocation 出发地完整地址 |
| | | * @param arrivalLocation 目的地完整地址 |
| | | * @param vehicleType 车型 |
| | | * @return 匹配的运费规则,没有则返回null |
| | | */ |
| | | public static ReceivableLineTruckPriceRule findExactMatchingRule( |
| | | List<ReceivableLineTruckPriceRule> rules, |
| | | String customerName, |
| | | String departureLocation, |
| | | String arrivalLocation, |
| | | String vehicleType) { |
| | | |
| | | |
| | | |
| | | for (ReceivableLineTruckPriceRule rule : rules) { |
| | | // 客户名称必须完全匹配 |
| | | if (!isFieldMatch(rule.getCustomerName(), customerName)) { |
| | | continue; |
| | | } |
| | | |
| | | // 车型必须完全匹配 |
| | | if (!isFieldMatch(rule.getVehicleType(), vehicleType)) { |
| | | continue; |
| | | } |
| | | |
| | | // 发货地匹配:规则中的发货市和区必须都包含在实际发货地址中 |
| | | if (!isAddressMatch(rule.getDepartureCity(), rule.getDepartureDistrict(), |
| | | departureLocation)) { |
| | | continue; |
| | | } |
| | | |
| | | // 收货地匹配:规则中的收货市和区必须都包含在实际收货地址中 |
| | | if (!isAddressMatch(rule.getArrivalCity(), rule.getArrivalDistrict(), |
| | | arrivalLocation)) { |
| | | continue; |
| | | } |
| | | |
| | | // 所有条件都满足,返回匹配的规则 |
| | | return rule; |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 地址匹配逻辑 |
| | | */ |
| | | private static boolean isAddressMatch(String ruleCity, String ruleDistrict, |
| | | String location) { |
| | | boolean cityFlag = true; |
| | | boolean districtFlag = true; |
| | | if(StringUtils.isNotEmpty(ruleCity) && !location.contains(ruleCity)){ |
| | | cityFlag = false; |
| | | } |
| | | |
| | | if(StringUtils.isNotEmpty(ruleDistrict) && !location.contains(ruleDistrict)){ |
| | | districtFlag = false; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | return (cityFlag&&districtFlag); |
| | | } |
| | | |
| | | /** |
| | | * 普通字段匹配逻辑 |
| | | */ |
| | | private static boolean isFieldMatch(String ruleValue, String actualValue) { |
| | | // 如果规则中定义了值,则必须完全匹配 |
| | | return ruleValue == null || ruleValue.isEmpty() || ruleValue.equals(actualValue); |
| | | } |
| | | |
| | | |
| | | } |