package lingtao.net.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lingtao.net.bean.Product; import lingtao.net.vo.PricingListVo; import lingtao.net.vo.ProductVo; import lingtao.net.vo.ProvidePrice; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @Service public class PriceService { public PricingListVo getAddressPrice(Product product, List proList) { Province province = parseAddress(product.getAddress()); if (province == null) { return new PricingListVo(100, "无效地址。"); } String plantName = product.getPlantName(); if ("领鸿".equals(plantName) || "欣海信".equals(plantName)) { List lyst = JSONObject.parseArray(ly_st, ProvincePriceVo.class); List lyyt = JSONObject.parseArray(ly_yt, ProvincePriceVo.class); List prices = getProvincePrice(lyst, province.province); if (prices != null && prices.size() > 0) { double firstPrice = StringtoDouble(prices.get(4).toString()); double secPrice = StringtoDouble(prices.get(5).toString()); for (ProductVo productVo : proList) { double weight = StringtoDouble(productVo.getWeight()); double finalePrice = 0; if (weight <= 0.5) { finalePrice = StringtoDouble(prices.get(0).toString()); } else if (weight <= 1) { finalePrice = StringtoDouble(prices.get(1).toString()); } else if (weight <= 2) { finalePrice = StringtoDouble(prices.get(2).toString()); } else if (weight <= 3) { finalePrice = StringtoDouble(prices.get(3).toString()); } else { finalePrice = firstPrice + Math.ceil(weight - 1.0) * secPrice; } productVo.getProvidePrices().add(new ProvidePrice("申通快递", finalePrice)); } } prices = getProvincePrice(lyyt, province.province); if (prices != null && prices.size() > 0) { double firstPrice = StringtoDouble(prices.get(5).toString()); double secPrice = StringtoDouble(prices.get(6).toString()); for (ProductVo productVo : proList) { double weight = StringtoDouble(productVo.getWeight()); double finalePrice = 0; if (weight <= 0.3 && StringtoDouble(prices.get(0).toString()) != 0) { finalePrice = StringtoDouble(prices.get(0).toString()); } else if (weight <= 0.5 && StringtoDouble(prices.get(1).toString()) != 0) { finalePrice = StringtoDouble(prices.get(1).toString()); } else if (weight <= 1 && StringtoDouble(prices.get(2).toString()) != 0) { finalePrice = StringtoDouble(prices.get(2).toString()); } else if (weight <= 2 && StringtoDouble(prices.get(3).toString()) != 0) { finalePrice = StringtoDouble(prices.get(3).toString()); } else if (weight <= 3 && StringtoDouble(prices.get(4).toString()) != 0) { finalePrice = StringtoDouble(prices.get(4).toString()); } else { finalePrice = firstPrice + Math.ceil(weight - 1.0) * secPrice; } productVo.getProvidePrices().add(new ProvidePrice("圆通快递", finalePrice)); } } } if ("艾印".equals(plantName) || "即客".equals(plantName)) { List list17 = Arrays.asList("新疆", "西藏", "甘肃", "宁夏", "青海"); List list8 = Arrays.asList("内蒙古"); double price = 0; if (isInAddress(list17, province.getProvince())) { price = 17; } else if (isInAddress(list8, province.getProvince())) { price = 8; } else { price = 3.5; if ("即客".equals(plantName)) { price = 4; } } for (ProductVo productVo : proList) { productVo.getProvidePrices().add(new ProvidePrice("EMS", price)); } } if ("彩印通".equals(plantName)) { List cytzt = JSONObject.parseArray(cyt_zt, ProvincePriceVo.class); List cytyt = JSONObject.parseArray(cyt_yt, ProvincePriceVo.class); List sfsome = JSONObject.parseArray(cyt_sf_some, ProvincePriceVo2.class); List sfmorning = JSONObject.parseArray(cyt_sf_morning, ProvincePriceVo2.class); List sfnextDay = JSONObject.parseArray(cyt_sf_nextDay, ProvincePriceVo2.class); List sftowDay = JSONObject.parseArray(cyt_sf_towDay, ProvincePriceVo2.class); calculateAndAddPrices(cytzt, "中通速递", province, proList, false); calculateAndAddPrices(cytyt, "圆通速递", province, proList, false); calculateAndAddPrices2(sfsome, "顺丰今日达", province, proList, false); calculateAndAddPrices2(sfmorning, "顺丰次晨达", province, proList, false); calculateAndAddPrices2(sfnextDay, "顺丰次日达", province, proList, false); calculateAndAddPrices2(sftowDay, "顺丰隔日达", province, proList, true); } if ("鸿晟".equals(plantName)) { for (ProductVo productVo : proList) { productVo.getProvidePrices().add(new ProvidePrice("Other", 3.5)); } double price = 0; List list12 = Arrays.asList("浙江", "江苏", "上海", "安徽"); List list16 = Arrays.asList("福建"); if (isInAddress(list12, province.getProvince())) { price = 12; } else if (isInAddress(list16, province.getProvince())) { price = 16; } else { price = 23; } for (ProductVo productVo : proList) { productVo.getProvidePrices().add(new ProvidePrice("SF", price)); } } if ("驰远".equals(plantName)) { Map>> sf_bk = (Map>>) JSON.parse(cy_sf_bk); Map>> sf_tk = (Map>>) JSON.parse(cy_sf_tk); List yt_xiao = JSONObject.parseArray(cy_yt_xiao, ProvincePriceVo.class); List yt_sd = JSONObject.parseArray(cy_yt_sd, ProvincePriceVo.class); List ems = JSONObject.parseArray(cy_ems, ProvincePriceVo.class); String priceString = priceKey(sf_bk, province); if (!StringUtils.isEmpty(priceString)) { double firstPrice = StringtoDouble(priceString.split("_")[1]); double secPrice = StringtoDouble(priceString.split("_")[2]); for (ProductVo productVo : proList) { double weight = StringtoDouble(productVo.getWeight()); double secWeightPrice = 0.0; if (weight > 1) { secWeightPrice = Math.ceil(weight - 1.0) * secPrice; } productVo.getProvidePrices().add(new ProvidePrice("顺丰标快", firstPrice + secWeightPrice)); } } priceString = priceKey(sf_tk, province); if (!StringUtils.isEmpty(priceString)) { double firstPrice = StringtoDouble(priceString.split("_")[1]); double secPrice = StringtoDouble(priceString.split("_")[2]); for (ProductVo productVo : proList) { double weight = StringtoDouble(productVo.getWeight()); double secWeightPrice = 0.0; if (weight > 1) { secWeightPrice = Math.ceil(weight - 1.0) * secPrice; } productVo.getProvidePrices().add(new ProvidePrice("顺丰特快", firstPrice + secWeightPrice)); } } List prices = getProvincePrice(yt_xiao, province.province); if (prices != null && prices.size() > 0) { double firstPrice = StringtoDouble(prices.get(4).toString()); double secPrice = StringtoDouble(prices.get(5).toString()); for (ProductVo productVo : proList) { double weight = StringtoDouble(productVo.getWeight()); double finalePrice = 0; if (weight <= 0.5) { finalePrice = StringtoDouble(prices.get(0).toString()); } else if (weight <= 1) { finalePrice = StringtoDouble(prices.get(1).toString()); } else if (weight <= 2) { finalePrice = StringtoDouble(prices.get(2).toString()); } else if (weight <= 3) { finalePrice = StringtoDouble(prices.get(3).toString()); } else { finalePrice = firstPrice + Math.ceil(weight - 1.0) * secPrice; } productVo.getProvidePrices().add(new ProvidePrice("圆通快递", finalePrice)); } } prices = getProvincePrice(yt_sd, province.province); if (prices != null && prices.size() > 0) { double firstPrice = StringtoDouble(prices.get(0).toString()); double secPrice = StringtoDouble(prices.get(1).toString()); for (ProductVo productVo : proList) { double weight = StringtoDouble(productVo.getWeight()); double finalePrice = 0; finalePrice = firstPrice + Math.ceil(weight - 1.0) * secPrice; productVo.getProvidePrices().add(new ProvidePrice("圆通速递", finalePrice)); } } prices = getProvincePrice(ems, province.province); if (prices != null && prices.size() > 0) { double firstPrice = StringtoDouble(prices.get(4).toString()); double secPrice = StringtoDouble(prices.get(5).toString()); for (ProductVo productVo : proList) { double weight = StringtoDouble(productVo.getWeight()); double finalePrice = 0; if (weight <= 0.5 && StringtoDouble(prices.get(0).toString()) != 0) { finalePrice = StringtoDouble(prices.get(0).toString()); } else if (weight <= 1 && StringtoDouble(prices.get(1).toString()) != 0) { finalePrice = StringtoDouble(prices.get(1).toString()); } else if (weight <= 2 && StringtoDouble(prices.get(2).toString()) != 0) { finalePrice = StringtoDouble(prices.get(2).toString()); } else if (weight <= 3 && StringtoDouble(prices.get(3).toString()) != 0) { finalePrice = StringtoDouble(prices.get(3).toString()); } else { finalePrice = firstPrice + Math.ceil(weight - 1.0) * secPrice; } productVo.getProvidePrices().add(new ProvidePrice("邮政快递", finalePrice)); } } } return new PricingListVo(proList); } private static Double StringtoDouble(String str) { try { return new BigDecimal(str).doubleValue(); } catch (Exception e) { return 0.0; } } // 定义一个通用方法来处理价格计算逻辑 private void calculateAndAddPrices(List priceData, String courierName, Province province, List proList, boolean hasThirdPrice) { List prices = getProvincePrice(priceData, province.province); List nofirst = Arrays.asList("内蒙古", "西藏", "新疆", "香港", "澳门", "台湾"); if (prices == null || prices.size() < (hasThirdPrice ? 3 : 2)) { return; // 如果价格数据不足,则直接返回 } try { double firstPrice = StringtoDouble(prices.get(0).toString()); double secPrice = StringtoDouble(prices.get(1).toString()); double thrPrice = hasThirdPrice && prices.size() > 2 ? StringtoDouble(prices.get(2).toString()) : 0; for (ProductVo productVo : proList) { double weight = StringtoDouble(productVo.getWeight()); double finalePrice = 0; if (courierName.equals("中通速递") || courierName.equals("圆通速递")) { if (weight <= 3 && !isInAddress(nofirst, province.getProvince())) { finalePrice = firstPrice; } else { finalePrice = firstPrice + Math.ceil(weight - 1.0) * secPrice; } } else { if (hasThirdPrice && weight > 30) { finalePrice = firstPrice + Math.ceil(weight - 1.0) * thrPrice; } else { finalePrice = firstPrice + Math.ceil(weight - 1.0) * secPrice; } } productVo.getProvidePrices().add(new ProvidePrice(courierName, finalePrice)); } } catch (Exception e) { // 记录日志或采取其他措施处理异常 System.err.println("Error parsing price data: " + e.getMessage()); } } private void calculateAndAddPrices2(List priceData, String courierName, Province province, List proList, boolean hasThirdPrice) { List prices = getProvincePrice2(priceData, province); List nofirst = Arrays.asList("内蒙古", "西藏", "新疆", "香港", "澳门", "台湾"); if (prices == null || prices.size() < (hasThirdPrice ? 3 : 2)) { return; // 如果价格数据不足,则直接返回 } try { double firstPrice = StringtoDouble(prices.get(0).toString()); double secPrice = StringtoDouble(prices.get(1).toString()); double thrPrice = hasThirdPrice && prices.size() > 2 ? StringtoDouble(prices.get(2).toString()) : 0; for (ProductVo productVo : proList) { double weight = StringtoDouble(productVo.getWeight()); double finalePrice = 0; if (courierName.equals("中通速递") || courierName.equals("圆通速递")) { if (weight <= 3 && !isInAddress(nofirst, province.getProvince())) { finalePrice = firstPrice; } else { finalePrice = firstPrice + Math.ceil(weight - 1.0) * secPrice; } } else { if (hasThirdPrice && weight > 30) { finalePrice = firstPrice + Math.ceil(weight - 1.0) * thrPrice; } else { finalePrice = firstPrice + Math.ceil(weight - 1.0) * secPrice; } } productVo.getProvidePrices().add(new ProvidePrice(courierName, finalePrice)); } } catch (Exception e) { // 记录日志或采取其他措施处理异常 System.err.println("Error parsing price data: " + e.getMessage()); } } private static List getProvincePrice2(List list, Province province) { List prices = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { if (isInAddress(Arrays.asList(list.get(i).getProvince()), province.getProvince())) { List cities = list.get(i).getCities(); if (cities.size() == 0 || isInAddress(cities, province.getCity())) { prices = list.get(i).getPrices(); } else if (list.get(i).getOtherPrices().size() > 0) { prices = list.get(i).getOtherPrices(); } } } return prices; } private static List getProvincePrice(List list, String provinceName) { List prices = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { if (isInAddress(list.get(i).getRegions(), provinceName)) { prices = list.get(i).getPrice(); } } return prices; } /** * 根据省份信息查找价格键 * 该方法通过遍历一个复杂的映射结构来查找与给定省份信息相对应的价格键 * 它首先遍历外层映射,然后遍历内层映射中的每个省份列表,检查是否有匹配的省份和城市 * * @param map 一个映射,其键是价格键,值是另一个映射;内层映射的键是省份名称,值是城市列表 * @param province 省份对象,包含需要查找的省份和城市信息 * @return 如果找到匹配的省份和城市,则返回对应的价格键;否则返回空字符串 */ private static String priceKey(Map>> map, Province province) { // 初始化结果字符串 String result = ""; // 获取外层映射的条目迭代器 Iterator>>> iterator = map.entrySet().iterator(); // 遍历外层映射 while (iterator.hasNext()) { // 获取当前外层映射条目 Map.Entry>> entry = iterator.next(); // 获取内层映射 Map> value = entry.getValue(); // 获取内层映射的条目迭代器 Iterator>> iteratorValue = value.entrySet().iterator(); // 遍历内层映射 while (iteratorValue.hasNext()) { // 获取当前内层映射条目 Map.Entry> provinces = iteratorValue.next(); // 获取省份名称 String provincesName = provinces.getKey(); // 检查省份名称是否与给定的省份信息匹配 if (isInAddress(Arrays.asList(provincesName), province.getProvince())) { // 获取城市列表 List citys = provinces.getValue(); // 如果城市列表为空,则直接返回当前的价格键 if (citys.size() == 0) { result = entry.getKey(); return result; } else { // 如果城市列表不为空,进一步检查城市是否匹配 if (isInAddress(citys, province.getCity())) { result = entry.getKey(); return result; } } } } } // 如果没有找到匹配的省份和城市,返回空字符串 return result; } //驰远顺丰标快 private static String cy_sf_bk = "{\"price_12_1\":{\"福建省\":[\"龙岩\"]},\"price_13_2\":{\"福建省\":[\"南平\",\"莆田\",\"福州\",\"泉州\",\"漳州\",\"厦门\",\"三明\",\"宁德\"]},\"price_16_6\":{\"广东省\":[\"河源\",\"韶关\",\"汕头\",\"清远\",\"深圳\",\"广州\",\"中山\",\"惠州\",\"揭阳\",\"东莞\",\"佛山\",\"汕尾\",\"潮州\",\"梅州\"],\"浙江省\":[\"台州\",\"温州\"]},\"price_18_5\":{\"北京市\":[],\"上海市\":[],\"天津市\":[],\"河北省\":[],\"河南省\":[],\"山东省\":[],\"浙江省\":[\"湖州\",\"宁波\",\"舟山\",\"丽水\",\"金华\",\"嘉兴\",\"衢州\",\"绍兴\",\"杭州\"],\"江西省\":[]},\"price_18_6\":{\"广西壮族自治区\":[\"河池\",\"防城港\",\"百色\",\"梧州/贺州\",\"钦州\",\"北海\",\"柳州\",\"来宾\",\"桂林\",\"玉林\",\"崇左\",\"贵港\",\"南宁\"],\"海南省\":[],\"重庆市\":[],\"辽宁省\":[],\"江苏省\":[],\"湖北省\":[],\"四川省\":[],\"陕西省\":[],\"贵州省\":[],\"云南省\":[],\"山西省\":[],\"内蒙古自治区\":[\"包头\",\"通辽\",\"呼和浩特\",\"乌海\",\"锡林郭勒盟\",\"赤峰\",\"鄂尔多斯\",\"乌兰察布\",\"阿拉善盟\",\"巴彦淖尔\"],\"安徽省\":[],\"广东省\":[\"江门\",\"茂名\",\"云浮\",\"湛江\",\"阳江\",\"珠海\",\"肇庆\"],\"湖南省\":[],\"甘肃省\":[],\"宁夏回族自治区\":[],\"青海省\":[\"海南藏族自治州\",\"果洛藏族自治州\",\"海东\",\"黄南藏族自治州\",\"海西蒙古族藏族自治州\",\"格尔木\",\"海北藏族自治州\",\"西宁\"]},\"price_18_9\":{\"吉林省\":[],\"黑龙江省\":[],\"内蒙古自治区\":[\"呼伦贝尔\",\"兴安盟\"]},\"price_20_10\":{\"新疆维吾尔自治区\":[]},\"price_21_12\":{\"青海省\":[\"玉树藏族自治州\"]},\"price_25_19\":{\"西藏自治区\":[\"拉萨\",\"日喀则\",\"那曲\",\"山南\",\"林芝\"]},\"price_26_21\":{\"西藏自治区\":[\"昌都\"]}}"; //驰远顺丰特快 private static String cy_sf_tk = "{\"price_18_8\":{\"广东省\":[\"汕头\",\"揭阳\",\"汕尾\",\"潮州\"]},\"price_20_8\":{\"广东省\":[\"河源\",\"茂名\",\"韶关\",\"清远\",\"深圳\",\"珠海\",\"广州\",\"肇庆\",\"中山\",\"江门\",\"云浮\",\"惠州\",\"湛江\",\"东莞\",\"阳江\",\"佛山\"],\"浙江省\":[\"宁波\",\"舟山\"]},\"price_22_10\":{\"上海市\":[],\"江苏省\":[],\"浙江省\":[\"湖州\",\"丽水\",\"金华\",\"嘉兴\",\"衢州\",\"绍兴\",\"杭州\"]},\"price_22_8\":{\"江西省\":[]},\"price_23_10\":{\"北京市\":[],\"天津市\":[],\"湖北省\":[],\"河北省\":[],\"河南省\":[],\"山东省\":[],\"安徽省\":[],\"湖南省\":[],\"广西壮族自治区\":[],\"海南省\":[]},\"price_23_13\":{\"重庆市\":[],\"辽宁省\":[],\"四川省\":[],\"陕西省\":[],\"贵州省\":[],\"云南省\":[],\"山西省\":[],\"甘肃省\":[],\"宁夏回族自治区\":[]},\"price_23_14\":{\"内蒙古自治区\":[\"包头\",\"通辽\",\"呼和浩特\",\"乌海\",\"锡林郭勒盟\",\"赤峰\",\"鄂尔多斯\",\"乌兰察布\",\"阿拉善盟\",\"巴彦淖尔\"],\"青海省\":[\"海南藏族自治州\",\"果洛藏族自治州\",\"海东\",\"黄南藏族自治州\",\"海西蒙古族藏族自治州\",\"格尔木\",\"玉树藏族自治州\",\"海北藏族自治州\",\"西宁\"]},\"price_23_18\":{\"吉林省\":[],\"黑龙江省\":[],\"内蒙古自治区\":[\"呼伦贝尔\",\"兴安盟\"]},\"price_26_21\":{\"西藏自治区\":[\"拉萨\",\"日喀则\",\"那曲\",\"山南\",\"林芝\",\"昌都\"],\"新疆维吾尔自治区\":[\"阿勒泰地区\",\"克孜勒苏柯尔克孜自治州\",\"哈密地区\",\"铁门关\",\"双河\",\"巴音郭楞蒙古自治州\",\"博尔塔拉蒙古自治州\",\"阿克苏地区\",\"昌吉回族自治州\",\"克拉玛依\",\"乌鲁木齐\",\"石河子\",\"喀什地区\",\"奎屯\",\"吐鲁番地区\",\"伊犁哈萨克自治州\",\"塔城地区\",\"和田地区\"]},\"price_20_10\":{\"新疆维吾尔自治区\":[\"乌鲁木齐\",\"石河子\",\"喀什地区\",\"奎屯\",\"吐鲁番地区\",\"伊犁哈萨克自治州\",\"塔城地区\",\"和田地区\"]},\"price_21_12\":{\"青海省\":[\"玉树藏族自治州\"]},\"price_25_19\":{\"西藏自治区\":[\"拉萨\",\"日喀则\",\"那曲\",\"山南\",\"林芝\"]}}"; //驰远圆通快递 private static String cy_yt_xiao = "[{\"price\":[2.7,3.2,3.7,4.7,4.5,0.8],\"regions\":[\"省内\"]},{\"price\":[2.7,3.2,3.7,4.7,5.0,1.2],\"regions\":[\"江苏\",\"浙江\",\"安徽\",\"广东\",\"江西\",\"湖南\"]},{\"price\":[3.7,4.2,4.7,5.7,7.0,1.4],\"regions\":[\"上海\"]},{\"price\":[2.7,3.2,3.7,4.7,5.5,1.8],\"regions\":[\"广西\",\"湖北\",\"河南省\",\"河北省\",\"天津市\",\"山西\"]},{\"price\":[2.7,3.2,3.7,4.7,6.0,2.3],\"regions\":[\"四川省\",\"重庆市\",\"云南\",\"贵州\"]},{\"price\":[2.7,3.2,3.7,4.7,6.0,1.8],\"regions\":[\"山东\"]},{\"price\":[2.7,3.2,3.7,4.7,6.0,2.1],\"regions\":[\"陕西省\"]},{\"price\":[4.2,4.7,5.2,6.2,8.0,2.0],\"regions\":[\"北京\"]},{\"price\":[8.3,8.3,14.3,20.3,8.0,6.0],\"regions\":[\"甘肃省\",\"宁夏\"]},{\"price\":[8.3,8.3,16.3,24.3,8.0,8.0],\"regions\":[\"青海省\"]},{\"price\":[10.3,10.3,18.3,26.3,10.0,8.0],\"regions\":[\"内蒙古\"]},{\"price\":[18.3,18.3,33.3,48.3,18.0,15.0],\"regions\":[\"新疆\"]},{\"price\":[22.3,22.3,40.3,58.3,22.0,18.0],\"regions\":[\"西藏\"]},{\"price\":[2.7,3.2,3.7,4.7,7.0,3.2],\"regions\":[\"黑龙江\",\"吉林\",\"辽宁\"]}]"; //驰远邮政快递 private static String cy_ems = "[{\"price\":[2.8,3.4,4.0,6.0,6.0,2.0],\"regions\":[\"福建\"]},{\"price\":[2.8,3.4,4.0,6.0,8.0,2.0],\"regions\":[\"江西省\",\"浙江省\",\"湖北省\",\"湖南省\",\"上海市\",\"广东省\",\"江苏省\",\"安徽省\"]},{\"price\":[2.8,3.4,6.0,8.0,10.0,3.0],\"regions\":[\"河南省\",\"贵州省\",\"山东省\",\"广西\",\"河北省\",\"陕西省\",\"海南省\",\"山西省\",\"天津市\",\"重庆市\",\"四川省\"]},{\"price\":[3.5,5.0,7.0,20.0,14.0,4.0],\"regions\":[\"云南省\",\"甘肃省\",\"内蒙\",\"辽宁省\",\"吉林省\",\"宁夏\",\"黑龙江省\"]},{\"price\":[8.0,0,0,0,10.0,3.0],\"regions\":[\"北京\"]},{\"price\":[12.0,0,0,0,16.0,12.0],\"regions\":[\"青海省\",\"新疆\",\"西藏\"]}]"; //驰远圆通速递(重货) private static String cy_yt_sd = "[{\"price\":[4.0,0.8],\"regions\":[\"福建\"]},{\"price\":[4.0,1.0],\"regions\":[\"广东\"]},{\"price\":[5.0,1.3],\"regions\":[\"上海\"]},{\"price\":[4.5,1.1],\"regions\":[\"浙江\",\"江西\",\"江苏\",\"安徽\",\"湖南\"]},{\"price\":[4.5,1.4],\"regions\":[\"湖北\",\"山东\",\"河南\",\"河北\",\"天津\"]},{\"price\":[5.5,1.7],\"regions\":[\"北京\"]},{\"price\":[5.5,1.6],\"regions\":[\"陕西\"]},{\"price\":[5.5,1.4],\"regions\":[\"广西\",\"山西\"]},{\"price\":[5.5,1.9],\"regions\":[\"贵州\",\"重庆\",\"云南\",\"四川\",\"海南\"]},{\"price\":[5.5,2.5],\"regions\":[\"辽宁\",\"黑龙江\",\"吉林\"]},{\"price\":[12.0,6.6],\"regions\":[\"甘肃\",\"宁夏\",\"青海\"]},{\"price\":[13.0,7.6],\"regions\":[\"内蒙古\"]},{\"price\":[20.0,15.6],\"regions\":[\"西藏\",\"新疆\"]}]"; //彩印通中通 private static String cyt_zt = "[{\"price\":[3.5,1],\"regions\":[\"广东\"]},{\"price\":[3.5,2],\"regions\":[\"浙江\",\"湖南\",\"福建\",\"江苏\",\"湖北\",\"广西\",\"江西\",\"安徽\"]},{\"price\":[3.5,3],\"regions\":[\"天津\",\"河南\",\"河北\",\"山东\",\"四川\",\"重庆\",\"贵州\",\"海南\",\"云南\"]},{\"price\":[3.5,4],\"regions\":[\"山西\",\"陕西\",\"黑龙江\",\"吉林\",\"辽宁\"]},{\"price\":[6,2],\"regions\":[\"上海\"]},{\"price\":[4.5,3],\"regions\":[\"北京\"]},{\"price\":[6,6],\"regions\":[\"甘肃\",\"宁夏\",\"青海\",\"内蒙古\"]},{\"price\":[20,20],\"regions\":[\"澳门\",\"香港\",\"台湾\"]},{\"price\":[10,8],\"regions\":[\"新疆\",\"西藏\"]}]"; //彩印通圆通 private static String cyt_yt = "[{\"price\":[2.6,1],\"regions\":[\"广东\"]},{\"price\":[2.6,2],\"regions\":[\"江苏省\",\"浙江省\",\"安徽省\",\"上海\",\"广西壮族自治区\",\"福建省\",\"江西省\",\"湖南省\",\"湖北省\"]},{\"price\":[2.6,3],\"regions\":[\"贵州省\",\"云南省\",\"海南省\",\"河南省\",\"山东省\",\"四川省\",\"重庆市\",\"北京市\",\"河北省\",\"天津市\"]},{\"price\":[2.6,4],\"regions\":[\"黑龙江省\",\"辽宁省\",\"吉林省\",\"山西省\",\"陕西省\"]},{\"price\":[2.6,5],\"regions\":[\"宁夏回族自治区\",\"青海省\",\"甘肃省\"]},{\"price\":[6,6],\"regions\":[\"内蒙古自治区\"]},{\"price\":[10,8],\"regions\":[\"新疆维吾尔自治区\",\"西藏自治区\"]},{\"price\":[30,15],\"regions\":[\"台湾\",\"香港\",\"澳门\"]}]\n"; //彩印通顺丰今日达 private static String cyt_sf_some = "[{\"province\":\"广东\",\"cities\":[\"佛山\"],\"price\":[11,1]},{\"province\":\"广东\",\"cities\":[\"广州\",\"深圳\"],\"price\":[16,2]},{\"province\":\"广东\",\"cities\":[\"江门\",\"中山\",\"东莞\"],\"price\":[15,2]}]"; //彩印通顺丰次晨达 private static String cyt_sf_morning = "[{\"province\":\"广东\",\"cities\":[\"佛山\",\"肇庆\",\"云浮\"],\"price\":[11,1]},{\"province\":\"广东\",\"cities\":[\"广州\",\"深圳\"],\"price\":[13,2]},{\"province\":\"广东\",\"cities\":[\"江门\",\"中山\",\"东莞\",\"惠州\",\"珠海\",\"肇庆\",\"清远\",\"云浮\",\"阳江\",\"揭阳\",\"茂名\",\"韶关\",\"梅州\",\"汕头\",\"湛江\",\"河源\",\"潮州\",\"汕尾\"],\"price\":[12,2]},{\"province\":\"广西\",\"cities\":[\"贺州\",\"梧州\"],\"price\":[16,6]},{\"province\":\"福建\",\"cities\":[\"泉州\"],\"price\":[20,8]},{\"province\":\"江苏\",\"cities\":[\"南京\",\"无锡\",\"镇江\",\"苏州\",\"常州\"],\"price\":[25,13]},{\"province\":\"上海\",\"cities\":[\"上海\"],\"price\":[25,13]},{\"province\":\"浙江\",\"cities\":[\"杭州\",\"湖州\",\"嘉兴\",\"宁波\",\"绍兴\",\"台州\",\"温州\"],\"price\":[25,13]},{\"province\":\"北京\",\"cities\":[\"北京\"],\"price\":[25,14]}]"; //彩印通次日达 private static String cyt_sf_nextDay = "[{\"province\":\"广东\",\"cities\":[\"阳江\",\"揭阳\",\"茂名\",\"韶关\",\"梅州\",\"汕头\",\"湛江\",\"河源\",\"潮州\",\"汕尾\"],\"prices\":[22,8],\"otherPrices\":[0,0]},{\"province\":\"福建\",\"cities\":[],\"prices\":[20,8],\"otherPrices\":[0,0]},{\"province\":\"广西\",\"cities\":[\"贺州\",\"梧州\"],\"prices\":[16,6],\"otherPrices\":[22,8]},{\"province\":\"江西\",\"cities\":[],\"prices\":[22,8],\"otherPrices\":[0,0]},{\"province\":\"湖南\",\"cities\":[],\"prices\":[22,8],\"otherPrices\":[0,0]},{\"province\":\"海南\",\"cities\":[],\"prices\":[22,8],\"otherPrices\":[0,0]},{\"province\":\"贵州\",\"cities\":[],\"prices\":[23,12],\"otherPrices\":[0,0]},{\"province\":\"安徽\",\"cities\":[],\"prices\":[23,12],\"otherPrices\":[0,0]},{\"province\":\"湖北\",\"cities\":[],\"prices\":[23,12],\"otherPrices\":[0,0]},{\"province\":\"江苏\",\"cities\":[],\"prices\":[23,13],\"otherPrices\":[0,0]},{\"province\":\"上海\",\"cities\":[],\"prices\":[23,13],\"otherPrices\":[0,0]},{\"province\":\"浙江\",\"cities\":[],\"prices\":[23,13],\"otherPrices\":[0,0]},{\"province\":\"重庆\",\"cities\":[],\"prices\":[23,13],\"otherPrices\":[0,0]},{\"province\":\"四川\",\"cities\":[],\"prices\":[23,13],\"otherPrices\":[0,0]},{\"province\":\"云南\",\"cities\":[],\"prices\":[23,13],\"otherPrices\":[0,0]},{\"province\":\"河南\",\"cities\":[],\"prices\":[23,13],\"otherPrices\":[0,0]},{\"province\":\"北京\",\"cities\":[],\"prices\":[23,14],\"otherPrices\":[0,0]},{\"province\":\"天津\",\"cities\":[],\"prices\":[23,14],\"otherPrices\":[0,0]},{\"province\":\"辽宁\",\"cities\":[],\"prices\":[23,14],\"otherPrices\":[0,0]},{\"province\":\"陕西\",\"cities\":[],\"prices\":[23,14],\"otherPrices\":[0,0]},{\"province\":\"河北\",\"cities\":[],\"prices\":[23,14],\"otherPrices\":[0,0]},{\"province\":\"山东\",\"cities\":[],\"prices\":[23,14],\"otherPrices\":[0,0]},{\"province\":\"甘肃\",\"cities\":[],\"prices\":[23,18],\"otherPrices\":[0,0]},{\"province\":\"宁夏\",\"cities\":[],\"prices\":[23,18],\"otherPrices\":[0,0]},{\"province\":\"青海\",\"cities\":[],\"prices\":[23,18],\"otherPrices\":[0,0]},{\"province\":\"内蒙古\",\"cities\":[\"呼伦贝尔\",\"兴安盟\"],\"prices\":[25,20],\"otherPrices\":[23,18]},{\"province\":\"吉林\",\"cities\":[],\"prices\":[25,20],\"otherPrices\":[0,0]},{\"province\":\"黑龙江\",\"cities\":[],\"prices\":[25,20],\"otherPrices\":[0,0]},{\"province\":\"新疆\",\"cities\":[],\"prices\":[28,25],\"otherPrices\":[0,0]},{\"province\":\"西藏\",\"cities\":[],\"prices\":[28,25],\"otherPrices\":[0,0]}]"; //彩印通隔日达 private static String cyt_sf_towDay = "[{\"province\":\"江西\",\"cities\":[],\"prices\":[18,6,6],\"otherPrices\":[0,0,0]},{\"province\":\"湖南\",\"cities\":[],\"prices\":[18,6,6],\"otherPrices\":[0,0,0]},{\"province\":\"海南\",\"cities\":[],\"prices\":[18,6,6],\"otherPrices\":[0,0,0]},{\"province\":\"贵州\",\"cities\":[],\"prices\":[18,6,6],\"otherPrices\":[0,0,0]},{\"province\":\"安徽\",\"cities\":[],\"prices\":[18,6,6],\"otherPrices\":[0,0,0]},{\"province\":\"湖北\",\"cities\":[],\"prices\":[18,8,8],\"otherPrices\":[0,0,0]},{\"province\":\"江苏\",\"cities\":[],\"prices\":[18,9,9],\"otherPrices\":[0,0,0]},{\"province\":\"上海\",\"cities\":[],\"prices\":[18,9,9],\"otherPrices\":[0,0,0]},{\"province\":\"浙江\",\"cities\":[],\"prices\":[18,9,9],\"otherPrices\":[0,0,0]},{\"province\":\"重庆\",\"cities\":[],\"prices\":[18,6,6],\"otherPrices\":[0,0,0]},{\"province\":\"四川\",\"cities\":[],\"prices\":[18,6,6],\"otherPrices\":[0,0,0]},{\"province\":\"云南\",\"cities\":[],\"prices\":[18,6,6],\"otherPrices\":[0,0,0]},{\"province\":\"河南\",\"cities\":[],\"prices\":[18,6,6],\"otherPrices\":[0,0,0]},{\"province\":\"北京\",\"cities\":[],\"prices\":[18,7,7],\"otherPrices\":[0,0,0]},{\"province\":\"天津\",\"cities\":[],\"prices\":[18,7,7],\"otherPrices\":[0,0,0]},{\"province\":\"辽宁\",\"cities\":[],\"prices\":[18,7,7],\"otherPrices\":[0,0,0]},{\"province\":\"陕西\",\"cities\":[],\"prices\":[18,7,7],\"otherPrices\":[0,0,0]},{\"province\":\"河北\",\"cities\":[],\"prices\":[18,7,7],\"otherPrices\":[0,0,0]},{\"province\":\"山东\",\"cities\":[],\"prices\":[18,7,7],\"otherPrices\":[0,0,0]},{\"province\":\"甘肃\",\"cities\":[],\"prices\":[18,9,9],\"otherPrices\":[0,0,0]},{\"province\":\"宁夏\",\"cities\":[],\"prices\":[18,9,9],\"otherPrices\":[0,0,0]},{\"province\":\"青海\",\"cities\":[],\"prices\":[18,9,9],\"otherPrices\":[0,0,0]},{\"province\":\"内蒙古\",\"cities\":[\"呼伦贝尔\",\"兴安盟\"],\"prices\":[20,10,10],\"otherPrices\":[18,9,9]},{\"province\":\"吉林\",\"cities\":[],\"prices\":[20,10,10],\"otherPrices\":[0,0,0]},{\"province\":\"黑龙江\",\"cities\":[],\"prices\":[20,10,10],\"otherPrices\":[0,0,0]},{\"province\":\"新疆\",\"cities\":[],\"prices\":[22,12,12],\"otherPrices\":[0,0,0]},{\"province\":\"西藏\",\"cities\":[],\"prices\":[0,0,0],\"otherPrices\":[0,0,0]}]"; //龙岩圆通 private static String ly_yt = "[{\"price\":[1.9,2.2,2.9,3.5,4.5,4.9,0.6],\"regions\":[\"福建\"]},{\"price\":[1.9,2.2,2.9,3.5,4.5,4.9,1.2],\"regions\":[\"广东\",\"安徽\",\"浙江\",\"江苏\",\"江西\",\"湖北\",\"湖南\"]},{\"price\":[1.9,2.2,2.9,3.5,4.5,4.9,1.4],\"regions\":[\"上海\"]},{\"price\":[1.9,2.2,2.9,3.5,4.5,4.9,1.9],\"regions\":[\"北京\"]},{\"price\":[1.9,2.2,2.9,3.5,4.5,4.9,1.6],\"regions\":[\"河南\"]},{\"price\":[1.9,2.2,2.9,3.5,4.5,5.9,1.6],\"regions\":[\"山东\",\"天津\",\"河北\",\"陕西\",\"广西\",\"山西\"]},{\"price\":[1.9,2.2,2.9,3.5,4.5,5.9,2.1],\"regions\":[\"海南\"]},{\"price\":[1.9,2.2,2.9,3.5,4.5,5.9,2.0],\"regions\":[\"四川\",\"贵州\",\"云南\",\"重庆\"]},{\"price\":[1.9,2.2,2.9,3.5,4.5,6.9,2.5],\"regions\":[\"黑龙江\",\"吉林\",\"辽宁\"]},{\"price\":[0,0,0,0,0,8.4,6.0],\"regions\":[\"甘肃\",\"宁夏\",\"青海\"]},{\"price\":[0,0,0,0,0,9.4,7.0],\"regions\":[\"内蒙古\"]},{\"price\":[0,0,0,0,0,15.4,12.0],\"regions\":[\"新疆\"]},{\"price\":[0,0,0,0,0,19.4,17.0],\"regions\":[\"西藏\"]}]"; //龙岩申通 private static String ly_st = "[{\"price\":[2.4,3.2,3.5,4.5,4.5,0.8],\"regions\":[\"福建\"]},{\"price\":[2.4,3.2,3.5,4.5,4.5,1.2],\"regions\":[\"广东\",\"安徽\",\"浙江\",\"江苏\",\"上海\",\"江西\",\"湖北\",\"湖南\"]},{\"price\":[2.4,3.2,3.5,4.5,5.0,2.0],\"regions\":[\"北京\"]},{\"price\":[2.4,3.2,3.5,4.5,5.0,2.5],\"regions\":[\"河南\",\"山东\",\"陕西\",\"四川\",\"广西\",\"山西\",\"贵州\",\"云南\",\"重庆\"]},{\"price\":[2.4,3.2,3.5,4.5,5.0,2.0],\"regions\":[\"天津\",\"河北\",\"海南\"]},{\"price\":[2.4,3.2,3.5,4.5,5.5,4.0],\"regions\":[\"黑龙江\",\"吉林\",\"辽宁\"]},{\"price\":[10.0,10.0,20.0,30.0,10.0,10.0],\"regions\":[\"甘肃\",\"宁夏\",\"青海\",\"内蒙古\"]},{\"price\":[15.0,16.0,30.0,45.0,18.0,16.0],\"regions\":[\"新疆\",\"西藏\"]}]"; private static Boolean isInAddress(List list, String address) { Boolean result = false; for (int i = 0; i < list.size(); i++) { if (address.contains(list.get(i))) { result = true; break; } } return result; } private static class ProvincePriceVo2 { private List prices = new ArrayList<>(); private List cities = new ArrayList<>(); private List otherPrices = new ArrayList<>(); private String province = ""; public List getPrices() { return prices; } public List getCities() { return cities; } public List getOtherPrices() { return otherPrices; } public String getProvince() { return province; } public void setPrices(List prices) { this.prices = prices; } public void setCities(List cities) { this.cities = cities; } public void setOtherPrices(List otherPrices) { this.otherPrices = otherPrices; } public void setProvince(String province) { this.province = province; } } private static class ProvincePriceVo { private List price = new ArrayList<>(); private List regions = new ArrayList<>(); private List otherPrices = new ArrayList<>(); public List getPrice() { return price; } public List getRegions() { return regions; } public List getOtherPrices() { return otherPrices; } public void setPrice(List price) { this.price = price; } public void setRegions(List regions) { this.regions = regions; } public void setOtherPrices(List otherPrices) { this.otherPrices = otherPrices; } } private static class Province { private String province; private String city; private String district; private String detailAddress; public Province(String province, String city, String district, String detailAddress) { this.province = province; this.city = city; this.district = district; this.detailAddress = detailAddress; } public String getProvince() { return province; } public void setProvince(String province) { this.province = province; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getDistrict() { return district; } public void setDistrict(String district) { this.district = district; } public String getDetailAddress() { return detailAddress; } public void setDetailAddress(String detailAddress) { this.detailAddress = detailAddress; } } private static Province parseAddress(String address) { if (StringUtils.isEmpty(address)) { return null; } String province = ""; String city = ""; String district = ""; String detailAddress = ""; // 匹配省级(省、自治区、直辖市) String provinceRegex = "(?[^省]+省|.+自治区|北京市|上海市|天津市|重庆市)"; Matcher provinceMatcher = Pattern.compile(provinceRegex).matcher(address); if (provinceMatcher.find()) { province = provinceMatcher.group("province"); String remaining = address.substring(province.length()); // 匹配市级(市、自治州、地区、盟) String cityRegex = "(?[^市]+市|.+自治州|.+地区|.+盟|市辖区)"; Matcher cityMatcher = Pattern.compile(cityRegex).matcher(remaining); if (cityMatcher.find()) { city = cityMatcher.group("city"); String districtPart = remaining.substring(city.length()); // 匹配区级(区、县、市、旗) String districtRegex = "(?[^区]+区|.+县|.+市|.+旗)"; Matcher districtMatcher = Pattern.compile(districtRegex).matcher(districtPart); if (districtMatcher.find()) { district = districtMatcher.group("district"); detailAddress = districtPart.substring(district.length()); } } } return new Province(province, city, district, detailAddress); } }