diff --git a/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/ZoneController.java b/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/ZoneController.java index d78ab3dc..538c822f 100644 --- a/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/ZoneController.java +++ b/bms-back/bms-admin/src/main/java/com/bms/web/controller/price/ZoneController.java @@ -20,11 +20,12 @@ import com.bms.common.core.page.TableDataInfo; import com.bms.common.enums.BusinessType; import com.bms.price.domain.PrcZone; import com.bms.price.domain.PrcZoneDetail; +import com.bms.price.domain.PrcZoneLabelProduct; import com.bms.price.domain.PrcZoneRegion; import com.bms.price.service.IPrcZoneService; /** - * 分区管理:国家(region) -> 分区 -> 邮编明细 + * 分区管理:常规按国家;打单按产品。 */ @RestController @RequestMapping("/price/zone") @@ -59,12 +60,36 @@ public class ZoneController extends BaseController return toAjax(zoneService.deleteZonesByRegionIds(regionIds)); } + + // ========== label product zones ========== + + @PreAuthorize("@ss.hasPermi('price:zone:list')") + @GetMapping("/label/product/list") + public TableDataInfo labelProductList(PrcZoneLabelProduct query) + { + startPage(); + List list = zoneService.selectLabelProductZoneList(query); + return getDataTable(list); + } + + @PreAuthorize("@ss.hasPermi('price:zone:remove')") + @Log(title = "LabelZoneProduct", businessType = BusinessType.DELETE) + @DeleteMapping("/label/product/{productId}") + public AjaxResult removeLabelProductZones(@PathVariable Long productId) + { + return toAjax(zoneService.deleteZonesByProductId(productId)); + } + // ========== zone ========== @PreAuthorize("@ss.hasPermi('price:zone:list')") @GetMapping("/item/list") public TableDataInfo zoneList(PrcZone zone) { + if (zone.getZoneType() == null || zone.getZoneType().isEmpty()) + { + zone.setZoneType(PrcZone.TYPE_REGULAR); + } startPage(); List list = zoneService.selectPrcZoneList(zone); return getDataTable(list); diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/LblProduct.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/LblProduct.java index 6e4d0766..d053ce99 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/domain/LblProduct.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/LblProduct.java @@ -105,7 +105,7 @@ public class LblProduct extends BaseEntity private List extraLines; - /** 邮编→分区(保存时同步到 prc_zone,不落产品子表) */ + /** 邮编→分区(保存时按产品同步到 prc_zone LABEL,不落产品子表) */ private Map> zonePostcodes; /** 编辑保存删除标记(不落库) */ diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcZone.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcZone.java index 6617df13..47b83567 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcZone.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcZone.java @@ -5,14 +5,23 @@ import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; -/** 国家下的分区:prc_zone */ +/** 国家/打单产品下的分区:prc_zone */ @Data public class PrcZone implements Serializable { private static final long serialVersionUID = 1L; + /** 常规计费(按国家) */ + public static final String TYPE_REGULAR = "REGULAR"; + /** 打单计费(按产品) */ + public static final String TYPE_LABEL = "LABEL"; + private Long zoneId; + /** REGULAR / LABEL */ + private String zoneType; private Long regionId; + /** 打单分区关联 prc_label_product.product_id;常规为 null */ + private Long productId; /** 存储在 prc_zone 上的 ISO2 国家代码 */ private String countryCode; private String zoneCode; @@ -27,4 +36,6 @@ public class PrcZone implements Serializable private Integer detailCount; /** 列表展示,来源于 region */ private String countryNameCn; + /** 打单产品名,非表字段 */ + private String productName; } diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcZoneLabelProduct.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcZoneLabelProduct.java new file mode 100644 index 00000000..028cd0c7 --- /dev/null +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcZoneLabelProduct.java @@ -0,0 +1,17 @@ +package com.bms.price.domain; + +import java.io.Serializable; +import lombok.Data; + +/** 打单计费分区:产品汇总行 */ +@Data +public class PrcZoneLabelProduct implements Serializable +{ + private static final long serialVersionUID = 1L; + + private Long productId; + private String productName; + private String dictValue; + private Integer zoneCount; + private Integer detailCount; +} diff --git a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcZoneDetailMapper.java b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcZoneDetailMapper.java index fb0a548e..4e2c3d75 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcZoneDetailMapper.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcZoneDetailMapper.java @@ -27,10 +27,16 @@ public interface PrcZoneDetailMapper public int deletePrcZoneDetailByRegionId(Long regionId); - /** - * 按国家 ISO2 + 邮编解析分区(先精确匹配,再取最长前缀)。 - */ + public int deletePrcZoneDetailByProductId(Long productId); + + /** 按国家 ISO2 + 邮编解析常规分区(先精确再最长前缀) */ public PrcZone selectZoneByCountryPostcode( @Param("countryCode") String countryCode, @Param("postcode") String postcode); + + /** 按打单产品 + 邮编解析 LABEL 分区(先精确再最长前缀) */ + public PrcZone selectZoneByProductPostcode( + @Param("productId") Long productId, + @Param("postcode") String postcode); } + diff --git a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcZoneMapper.java b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcZoneMapper.java index ee118d12..7e1027d2 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcZoneMapper.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcZoneMapper.java @@ -2,6 +2,7 @@ package com.bms.price.mapper; import java.util.List; import com.bms.price.domain.PrcZone; +import com.bms.price.domain.PrcZoneLabelProduct; import com.bms.price.domain.PrcZoneRegion; public interface PrcZoneMapper @@ -12,10 +13,14 @@ public interface PrcZoneMapper public List selectPrcZoneListByRegionId(Long regionId); + public List selectPrcZoneListByProductId(Long productId); + public List selectZoneRegionList(PrcZoneRegion query); public PrcZoneRegion selectZoneRegionById(Long regionId); + public List selectLabelProductZoneList(PrcZoneLabelProduct query); + public int countByRegionId(Long regionId); public int insertPrcZone(PrcZone zone); @@ -27,4 +32,6 @@ public interface PrcZoneMapper public int deletePrcZoneByRegionId(Long regionId); public int deletePrcZoneByRegionIds(Long[] regionIds); + + public int deletePrcZoneByProductId(Long productId); } diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/IPrcZoneService.java b/bms-back/bms-system/src/main/java/com/bms/price/service/IPrcZoneService.java index 23288735..c6a24faa 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/IPrcZoneService.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/IPrcZoneService.java @@ -5,6 +5,7 @@ import java.util.Map; import org.springframework.web.multipart.MultipartFile; import com.bms.price.domain.PrcZone; import com.bms.price.domain.PrcZoneDetail; +import com.bms.price.domain.PrcZoneLabelProduct; import com.bms.price.domain.PrcZoneRegion; public interface IPrcZoneService @@ -13,9 +14,14 @@ public interface IPrcZoneService public List selectZoneRegionList(PrcZoneRegion query); - /** 删除指定区域 ID 下的所有分区(及其明细) */ + /** 删除指定区域 ID 下的所有常规分区(及其明细) */ public int deleteZonesByRegionIds(Long[] regionIds); + public List selectLabelProductZoneList(PrcZoneLabelProduct query); + + /** 清空打单产品下全部 LABEL 分区与邮编 */ + public int deleteZonesByProductId(Long productId); + public PrcZone selectPrcZoneById(Long zoneId); public List selectPrcZoneList(PrcZone zone); @@ -39,10 +45,15 @@ public interface IPrcZoneService public String importZoneExcel(MultipartFile file, String operName) throws Exception; /** - * 按国家同步邮编分区:仅覆盖本次出现的 zone,不清空该国其他分区。 + * 按国家同步常规邮编分区:仅覆盖本次出现的 zone,不清空该国其他分区。 * @param countryCode2 ISO2 * @param zonePostcodes zoneLabel -> postcodes * @return 摘要文案 */ public String syncCountryZones(String countryCode2, Map> zonePostcodes); + + /** + * 按打单产品同步 LABEL 邮编分区:仅覆盖本次出现的 zone,不碰其他产品/常规分区。 + */ + public String syncLabelProductZones(Long productId, String countryCode2, Map> zonePostcodes); } diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/LblProductServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/LblProductServiceImpl.java index d333beeb..e9e83190 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/LblProductServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/LblProductServiceImpl.java @@ -233,7 +233,7 @@ public class LblProductServiceImpl implements ILblProductService int removed = 0; List products = command.getProducts(); int total = products.size(); - Map>> zoneSyncByCountry = new LinkedHashMap>>(); + List zoneSyncProducts = new ArrayList(); for (int i = 0; i < products.size(); i++) { LblProduct product = products.get(i); @@ -317,12 +317,21 @@ public class LblProductServiceImpl implements ILblProductService } } saved++; - collectZoneSync(zoneSyncByCountry, product); + if (product.getZonePostcodes() != null && !product.getZonePostcodes().isEmpty()) + { + zoneSyncProducts.add(product); + } } report(listener, 88, "正在同步邮编分区"); - for (Map.Entry>> e : zoneSyncByCountry.entrySet()) + for (LblProduct zp : zoneSyncProducts) { - prcZoneService.syncCountryZones(e.getKey(), e.getValue()); + if (zp == null || zp.getProductId() == null) + { + continue; + } + assertLabelZoneCountry(zp); + String country = LblZonePostcodeAttach.countryCodeOf(zp); + prcZoneService.syncLabelProductZones(zp.getProductId(), country, zp.getZonePostcodes()); } report(listener, 98, "保存完成,正在收尾"); return editVersion @@ -1193,7 +1202,7 @@ public class LblProductServiceImpl implements ILblProductService return false; } - private void collectZoneSync(Map>> byCountry, LblProduct product) + private void assertLabelZoneCountry(LblProduct product) { if (product == null || product.getZonePostcodes() == null || product.getZonePostcodes().isEmpty()) { @@ -1204,22 +1213,6 @@ public class LblProductServiceImpl implements ILblProductService { throw new ServiceException("产品「" + product.getProductName() + "」有邮编分区表,但无法识别国家代码"); } - Map> bucket = byCountry.computeIfAbsent(country, k -> new LinkedHashMap>()); - for (Map.Entry> e : product.getZonePostcodes().entrySet()) - { - if (e.getKey() == null || e.getValue() == null) - { - continue; - } - List list = bucket.computeIfAbsent(e.getKey(), k -> new ArrayList()); - for (String pc : e.getValue()) - { - if (pc != null && !pc.isBlank() && !list.contains(pc)) - { - list.add(pc); - } - } - } } private void prepareCounts(LblProduct product) diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcZoneServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcZoneServiceImpl.java index e2a7ce43..0e9461df 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcZoneServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcZoneServiceImpl.java @@ -27,6 +27,7 @@ import com.bms.common.utils.MessageUtils; import com.bms.common.utils.StringUtils; import com.bms.price.domain.PrcZone; import com.bms.price.domain.PrcZoneDetail; +import com.bms.price.domain.PrcZoneLabelProduct; import com.bms.price.domain.PrcZoneRegion; import com.bms.price.mapper.PrcZoneDetailMapper; import com.bms.price.mapper.PrcZoneMapper; @@ -69,6 +70,24 @@ public class PrcZoneServiceImpl implements IPrcZoneService return zoneMapper.selectZoneRegionList(query); } + @Override + public List selectLabelProductZoneList(PrcZoneLabelProduct query) + { + return zoneMapper.selectLabelProductZoneList(query); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public int deleteZonesByProductId(Long productId) + { + if (productId == null) + { + return 0; + } + detailMapper.deletePrcZoneDetailByProductId(productId); + return zoneMapper.deletePrcZoneByProductId(productId); + } + @Override @Transactional(rollbackFor = Exception.class) public int deleteZonesByRegionIds(Long[] regionIds) @@ -125,6 +144,18 @@ public class PrcZoneServiceImpl implements IPrcZoneService { throw new ServiceException(MessageUtils.message("price.zone.countryCode.empty")); } + if (StringUtils.isEmpty(zone.getZoneType())) + { + zone.setZoneType(PrcZone.TYPE_REGULAR); + } + if (PrcZone.TYPE_REGULAR.equals(zone.getZoneType())) + { + zone.setProductId(null); + } + else if (PrcZone.TYPE_LABEL.equals(zone.getZoneType()) && zone.getProductId() == null) + { + throw new ServiceException("打单分区必须关联产品"); + } if (zone.getZoneSort() == null) { zone.setZoneSort(extractZoneSort(zone.getZoneCode())); @@ -333,6 +364,8 @@ public class PrcZoneServiceImpl implements IPrcZoneService if (zone == null) { zone = new PrcZone(); + zone.setZoneType(PrcZone.TYPE_REGULAR); + zone.setProductId(null); zone.setRegionId(region.getRegionId()); zone.setCountryCode(code); zone.setZoneCode(zoneCode); @@ -343,6 +376,8 @@ public class PrcZoneServiceImpl implements IPrcZoneService } else { + zone.setZoneType(PrcZone.TYPE_REGULAR); + zone.setProductId(null); zone.setZoneName(label.length() > 100 ? label.substring(0, 100) : label); zoneMapper.updatePrcZone(zone); detailMapper.deletePrcZoneDetailByZoneId(zone.getZoneId()); @@ -380,6 +415,124 @@ public class PrcZoneServiceImpl implements IPrcZoneService return "已同步 " + code + " 分区" + zoneUpsert + "个、邮编" + detailInserted + "条"; } + + @Override + @Transactional(rollbackFor = Exception.class) + public String syncLabelProductZones(Long productId, String countryCode2, Map> zonePostcodes) + { + if (productId == null) + { + throw new ServiceException("打单产品ID不能为空"); + } + if (zonePostcodes == null || zonePostcodes.isEmpty()) + { + return "无邮编分区需同步"; + } + String code = StringUtils.isEmpty(countryCode2) ? "" : countryCode2.trim().toUpperCase(Locale.ROOT); + Long regionId = null; + if (StringUtils.isNotEmpty(code)) + { + BmsRegion region = regionMapper.selectRegionByCode2(code); + if (region != null) + { + regionId = region.getRegionId(); + } + } + if (regionId == null) + { + throw new ServiceException("分区管理未找到国家 " + (StringUtils.isEmpty(code) ? "(empty)" : code)); + } + List existing = zoneMapper.selectPrcZoneListByProductId(productId); + Map byCode = new HashMap(); + if (existing != null) + { + for (PrcZone z : existing) + { + if (z != null && StringUtils.isNotEmpty(z.getZoneCode())) + { + byCode.put(z.getZoneCode().trim().toUpperCase(Locale.ROOT), z); + } + } + } + int zoneUpsert = 0; + int detailInserted = 0; + List>> entries = new ArrayList<>(zonePostcodes.entrySet()); + entries.sort(Comparator.comparingInt(e -> extractZoneSort(e.getKey()))); + for (Map.Entry> entry : entries) + { + String label = StringUtils.trim(entry.getKey()); + if (StringUtils.isEmpty(label)) + { + continue; + } + label = label.replace('\r', ' ').replace('\n', ' ').replaceAll("\\s+", " ").trim(); + String zoneCode = ZoneCodeAbbrevs.toAbbrev(label); + if (StringUtils.isEmpty(zoneCode)) + { + continue; + } + if (zoneCode.length() > 50) + { + zoneCode = zoneCode.substring(0, 50); + } + String key = zoneCode.trim().toUpperCase(Locale.ROOT); + PrcZone zone = byCode.get(key); + if (zone == null) + { + zone = new PrcZone(); + zone.setZoneType(PrcZone.TYPE_LABEL); + zone.setProductId(productId); + zone.setRegionId(regionId); + zone.setCountryCode(code); + zone.setZoneCode(zoneCode); + zone.setZoneName(label.length() > 100 ? label.substring(0, 100) : label); + zone.setZoneSort(extractZoneSort(label)); + zoneMapper.insertPrcZone(zone); + byCode.put(key, zone); + } + else + { + zone.setZoneType(PrcZone.TYPE_LABEL); + zone.setProductId(productId); + zone.setRegionId(regionId); + zone.setCountryCode(code); + zone.setZoneName(label.length() > 100 ? label.substring(0, 100) : label); + zoneMapper.updatePrcZone(zone); + detailMapper.deletePrcZoneDetailByZoneId(zone.getZoneId()); + } + zoneUpsert++; + Set uniquePostcodes = new LinkedHashSet(); + if (entry.getValue() != null) + { + uniquePostcodes.addAll(entry.getValue()); + } + List batch = new ArrayList<>(BATCH_SIZE); + for (String postcode : uniquePostcodes) + { + if (StringUtils.isEmpty(postcode)) + { + continue; + } + PrcZoneDetail detail = new PrcZoneDetail(); + detail.setZoneId(zone.getZoneId()); + detail.setPostcode(postcode.trim()); + batch.add(detail); + if (batch.size() >= BATCH_SIZE) + { + detailMapper.insertPrcZoneDetailBatch(batch); + detailInserted += batch.size(); + batch = new ArrayList<>(BATCH_SIZE); + } + } + if (!batch.isEmpty()) + { + detailMapper.insertPrcZoneDetailBatch(batch); + detailInserted += batch.size(); + } + } + return "已同步产品" + productId + "分区" + zoneUpsert + "个、邮编" + detailInserted + "条"; + } + private int[] replaceRegionZones(BmsRegion region, Map> zonePostcodes) { if (StringUtils.isEmpty(region.getCountryCode2())) @@ -400,6 +553,8 @@ public class PrcZoneServiceImpl implements IPrcZoneService { String zoneCode = ZoneCodeAbbrevs.toAbbrev(entry.getKey()); PrcZone zone = new PrcZone(); + zone.setZoneType(PrcZone.TYPE_REGULAR); + zone.setProductId(null); zone.setRegionId(regionId); zone.setCountryCode(region.getCountryCode2()); zone.setZoneCode(zoneCode); diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/TmsPriceQuoteServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/TmsPriceQuoteServiceImpl.java index c9362069..8972ff88 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/TmsPriceQuoteServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/TmsPriceQuoteServiceImpl.java @@ -758,8 +758,8 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService /** * 打单多分区价卡:先按国家收窄运费分区; - * 该国只有 1 个运费分区(如 PT Mainland)直接用,不强依分区管理; - * 多分区(如 ES 密度)再用 prc_zone 按邮编解析。 + * 该国只有 1 个运费分区直接用; + * 多分区则按打单产品 + 邮编在 LABEL prc_zone 中解析。 */ private String resolveLabelFreightZone(LblProduct product, String countryCode, String destPostcode) { @@ -779,14 +779,15 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService return countryFreight.get(0); } List candidates = countryFreight.isEmpty() ? zoneNames : countryFreight; - if (StringUtils.isEmpty(cc)) + if (product == null || product.getProductId() == null) { - throw new ServiceException("邮编未匹配到分区"); + throw new ServiceException("邮编未匹配到产品分区"); } - PrcZone resolved = zoneDetailMapper.selectZoneByCountryPostcode(cc, normalizePostcode(destPostcode)); + PrcZone resolved = zoneDetailMapper.selectZoneByProductPostcode( + product.getProductId(), normalizePostcode(destPostcode)); if (resolved == null) { - throw new ServiceException("邮编未匹配到分区"); + throw new ServiceException("邮编未匹配到产品分区"); } String mapped = PayZoneMatcher.mapRegion(candidates, resolved.getZoneCode()); if (mapped == null) diff --git a/bms-back/bms-system/src/main/resources/mapper/price/PrcZoneDetailMapper.xml b/bms-back/bms-system/src/main/resources/mapper/price/PrcZoneDetailMapper.xml index dfc24ae5..38c99951 100644 --- a/bms-back/bms-system/src/main/resources/mapper/price/PrcZoneDetailMapper.xml +++ b/bms-back/bms-system/src/main/resources/mapper/price/PrcZoneDetailMapper.xml @@ -43,6 +43,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(1) from prc_zone_detail d inner join prc_zone z on z.zone_id = d.zone_id where z.region_id = #{regionId} + and z.zone_type = 'REGULAR' + and z.product_id is null @@ -89,11 +91,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete d from prc_zone_detail d inner join prc_zone z on z.zone_id = d.zone_id where z.region_id = #{regionId} + and z.zone_type = 'REGULAR' + and z.product_id is null + + + + delete d from prc_zone_detail d + inner join prc_zone z on z.zone_id = d.zone_id + where z.product_id = #{productId} + and z.zone_type = 'LABEL' + + + + select r.region_id, r.country_name_cn, r.country_name_en, r.country_code_2, r.status, - (select count(1) from prc_zone z where z.region_id = r.region_id) as zone_count, + (select count(1) from prc_zone z where z.region_id = r.region_id and z.zone_type = 'REGULAR' and z.product_id is null) as zone_count, (select count(1) from prc_zone_detail d inner join prc_zone z on z.zone_id = d.zone_id - where z.region_id = r.region_id) as detail_count + where z.region_id = r.region_id and z.zone_type = 'REGULAR' and z.product_id is null) as detail_count from region r where r.region_id = #{regionId} + + insert into prc_zone ( + zone_type, region_id, + product_id, country_code, zone_code, zone_name, @@ -117,7 +183,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" remark, create_time ) values ( + #{zoneType}, #{regionId}, + #{productId}, #{countryCode}, #{zoneCode}, #{zoneName}, @@ -130,7 +198,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update prc_zone + zone_type = #{zoneType}, region_id = #{regionId}, + product_id = #{productId}, country_code = #{countryCode}, zone_code = #{zoneCode}, zone_name = #{zoneName}, @@ -149,7 +219,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from prc_zone where region_id = #{regionId} + delete from prc_zone + where region_id = #{regionId} + and zone_type = 'REGULAR' + and product_id is null @@ -157,6 +230,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{regionId} + and zone_type = 'REGULAR' + and product_id is null + + + + delete from prc_zone + where product_id = #{productId} + and zone_type = 'LABEL' diff --git a/bms-back/sql/price/prc_zone_label_es_cleanup_optional.sql b/bms-back/sql/price/prc_zone_label_es_cleanup_optional.sql new file mode 100644 index 00000000..dfa87570 --- /dev/null +++ b/bms-back/sql/price/prc_zone_label_es_cleanup_optional.sql @@ -0,0 +1,22 @@ + -- Optional: after label price cards are re-imported into LABEL product zones, + -- remove ES REGULAR zones that came from label density sheets and collide with + -- product-scoped LABEL data. Review before running in production. + +DELETE d FROM prc_zone_detail d +INNER JOIN prc_zone z ON z.zone_id = d.zone_id +WHERE z.zone_type = 'REGULAR' +AND z.product_id IS NULL +AND upper(z.country_code) = 'ES' +AND z.zone_code IN ( + 'DENSO_RESTO','RURAL_RESTO','MAD-BCN_DENSE','MAD-BCN_NON_DENSE','MAD-BCN_RURAL', + 'HIGH','LOW','MEDIUM','MAD_HIGH_DENSITY' +); + + DELETE FROM prc_zone + WHERE zone_type = 'REGULAR' +AND product_id IS NULL +AND upper(country_code) = 'ES' +AND zone_code IN ( + 'DENSO_RESTO','RURAL_RESTO','MAD-BCN_DENSE','MAD-BCN_NON_DENSE','MAD-BCN_RURAL', + 'HIGH','LOW','MEDIUM','MAD_HIGH_DENSITY' +); diff --git a/bms-back/sql/price/prc_zone_type_product_alter.sql b/bms-back/sql/price/prc_zone_type_product_alter.sql new file mode 100644 index 00000000..953185bd --- /dev/null +++ b/bms-back/sql/price/prc_zone_type_product_alter.sql @@ -0,0 +1,62 @@ +-- prc_zone: REGULAR (country) vs LABEL (product) +-- Idempotent: safe to re-run. + +SET @db := DATABASE(); + +SELECT COUNT(*) INTO @col_zone_type +FROM information_schema.COLUMNS +WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'prc_zone' AND COLUMN_NAME = 'zone_type'; +SET @sql := IF(@col_zone_type = 0, + 'ALTER TABLE prc_zone ADD COLUMN zone_type varchar(16) NOT NULL DEFAULT ''REGULAR'' COMMENT ''REGULAR regular billing / LABEL label product billing'' AFTER zone_id', + 'SELECT 1'); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; + +SELECT COUNT(*) INTO @col_product_id +FROM information_schema.COLUMNS +WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'prc_zone' AND COLUMN_NAME = 'product_id'; +SET @sql := IF(@col_product_id = 0, + 'ALTER TABLE prc_zone ADD COLUMN product_id bigint(20) DEFAULT NULL COMMENT ''prc_label_product.product_id when zone_type=LABEL'' AFTER region_id', + 'SELECT 1'); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; + +UPDATE prc_zone SET zone_type = 'REGULAR' WHERE zone_type IS NULL OR zone_type = ''; + +SELECT COUNT(*) INTO @col_uk_key +FROM information_schema.COLUMNS +WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'prc_zone' AND COLUMN_NAME = 'zone_uk_key'; +SET @sql := IF(@col_uk_key = 0, + 'ALTER TABLE prc_zone ADD COLUMN zone_uk_key varchar(160) AS (CONCAT(zone_type, '':'', IFNULL(product_id, 0), '':'', IFNULL(region_id, 0), '':'', UPPER(zone_code))) STORED COMMENT ''unique scope key''', + 'SELECT 1'); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; + +SELECT COUNT(*) INTO @idx_old +FROM information_schema.STATISTICS +WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'prc_zone' AND INDEX_NAME = 'uk_zone_region_code'; +SET @sql := IF(@idx_old > 0, + 'ALTER TABLE prc_zone DROP INDEX uk_zone_region_code', + 'SELECT 1'); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; + +SELECT COUNT(*) INTO @idx_scope +FROM information_schema.STATISTICS +WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'prc_zone' AND INDEX_NAME = 'uk_zone_scope'; +SET @sql := IF(@idx_scope = 0, + 'ALTER TABLE prc_zone ADD UNIQUE KEY uk_zone_scope (zone_uk_key)', + 'SELECT 1'); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; + +SELECT COUNT(*) INTO @idx_type +FROM information_schema.STATISTICS +WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'prc_zone' AND INDEX_NAME = 'idx_zone_type'; +SET @sql := IF(@idx_type = 0, + 'ALTER TABLE prc_zone ADD KEY idx_zone_type (zone_type)', + 'SELECT 1'); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; + +SELECT COUNT(*) INTO @idx_product +FROM information_schema.STATISTICS +WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'prc_zone' AND INDEX_NAME = 'idx_zone_product_id'; +SET @sql := IF(@idx_product = 0, + 'ALTER TABLE prc_zone ADD KEY idx_zone_product_id (product_id)', + 'SELECT 1'); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; diff --git a/bms-front/src/api/price/zone.js b/bms-front/src/api/price/zone.js index 2bc52ac6..d9adc80d 100644 --- a/bms-front/src/api/price/zone.js +++ b/bms-front/src/api/price/zone.js @@ -17,7 +17,7 @@ export function getCountry(regionId) { }) } -/** Delete all zones + postcodes for region(s); does not delete region */ +/** Delete all REGULAR zones + postcodes for region(s); does not delete region */ export function delCountryZones(regionIds) { return request({ url: '/price/zone/country/' + regionIds, @@ -25,6 +25,23 @@ export function delCountryZones(regionIds) { }) } +// ========== label product zones ========== + +export function listLabelProduct(query) { + return request({ + url: '/price/zone/label/product/list', + method: 'get', + params: query + }) +} + +export function delLabelProductZones(productId) { + return request({ + url: '/price/zone/label/product/' + productId, + method: 'delete' + }) +} + // ========== zone item ========== export function listZone(query) { diff --git a/bms-front/src/views/price/basic/zone/components/LabelZoneDrawer.vue b/bms-front/src/views/price/basic/zone/components/LabelZoneDrawer.vue new file mode 100644 index 00000000..f60f9d49 --- /dev/null +++ b/bms-front/src/views/price/basic/zone/components/LabelZoneDrawer.vue @@ -0,0 +1,198 @@ + + + + + diff --git a/bms-front/src/views/price/basic/zone/components/ZoneDrawer.vue b/bms-front/src/views/price/basic/zone/components/ZoneDrawer.vue index c1453832..06e686eb 100644 --- a/bms-front/src/views/price/basic/zone/components/ZoneDrawer.vue +++ b/bms-front/src/views/price/basic/zone/components/ZoneDrawer.vue @@ -138,7 +138,7 @@ function loadZoneList(regionId) { return } zoneLoading.value = true - listZone({ regionId, pageNum: 1, pageSize: 200 }).then(res => { + listZone({ zoneType: 'REGULAR', regionId, pageNum: 1, pageSize: 200 }).then(res => { zoneList.value = res.rows || [] }).catch(() => { zoneList.value = [] diff --git a/bms-front/src/views/price/basic/zone/components/ZoneFormDialog.vue b/bms-front/src/views/price/basic/zone/components/ZoneFormDialog.vue index 5650b6be..feac728c 100644 --- a/bms-front/src/views/price/basic/zone/components/ZoneFormDialog.vue +++ b/bms-front/src/views/price/basic/zone/components/ZoneFormDialog.vue @@ -39,6 +39,16 @@ const props = defineProps({ country: { type: Object, default: null + }, + /** REGULAR / LABEL,默认常规 */ + zoneType: { + type: String, + default: 'REGULAR' + }, + /** 打单产品 ID(LABEL 时必填) */ + productId: { + type: [Number, String], + default: null } }) @@ -59,6 +69,8 @@ function open2(row) { ? { ...row } : { zoneId: undefined, + zoneType: props.zoneType || 'REGULAR', + productId: props.productId || undefined, regionId: props.country?.regionId, countryCode: props.country?.countryCode2 || undefined, zoneCode: undefined, @@ -80,6 +92,8 @@ function submitForm() { .toString().trim().toUpperCase() const payload = { ...form.value, + zoneType: form.value.zoneType || props.zoneType || 'REGULAR', + productId: props.zoneType === 'LABEL' ? (props.productId || form.value.productId) : null, regionId: region?.regionId, countryCode: code, zoneName: form.value.zoneName || (cn ? (cn + '(' + form.value.zoneCode + ')') : form.value.zoneCode) diff --git a/bms-front/src/views/price/basic/zone/index.vue b/bms-front/src/views/price/basic/zone/index.vue index 9a1459eb..bed8b4e0 100644 --- a/bms-front/src/views/price/basic/zone/index.vue +++ b/bms-front/src/views/price/basic/zone/index.vue @@ -1,14 +1,29 @@