新增打单产品分区管理功能,优化常规分区逻辑
This commit is contained in:
@@ -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<PrcZoneLabelProduct> 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<PrcZone> list = zoneService.selectPrcZoneList(zone);
|
||||
return getDataTable(list);
|
||||
|
||||
@@ -105,7 +105,7 @@ public class LblProduct extends BaseEntity
|
||||
|
||||
private List<LblExtraLine> extraLines;
|
||||
|
||||
/** 邮编→分区(保存时同步到 prc_zone,不落产品子表) */
|
||||
/** 邮编→分区(保存时按产品同步到 prc_zone LABEL,不落产品子表) */
|
||||
private Map<String, List<String>> zonePostcodes;
|
||||
|
||||
/** 编辑保存删除标记(不落库) */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<PrcZone> selectPrcZoneListByRegionId(Long regionId);
|
||||
|
||||
public List<PrcZone> selectPrcZoneListByProductId(Long productId);
|
||||
|
||||
public List<PrcZoneRegion> selectZoneRegionList(PrcZoneRegion query);
|
||||
|
||||
public PrcZoneRegion selectZoneRegionById(Long regionId);
|
||||
|
||||
public List<PrcZoneLabelProduct> 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);
|
||||
}
|
||||
|
||||
@@ -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<PrcZoneRegion> selectZoneRegionList(PrcZoneRegion query);
|
||||
|
||||
/** 删除指定区域 ID 下的所有分区(及其明细) */
|
||||
/** 删除指定区域 ID 下的所有常规分区(及其明细) */
|
||||
public int deleteZonesByRegionIds(Long[] regionIds);
|
||||
|
||||
public List<PrcZoneLabelProduct> selectLabelProductZoneList(PrcZoneLabelProduct query);
|
||||
|
||||
/** 清空打单产品下全部 LABEL 分区与邮编 */
|
||||
public int deleteZonesByProductId(Long productId);
|
||||
|
||||
public PrcZone selectPrcZoneById(Long zoneId);
|
||||
|
||||
public List<PrcZone> 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<String, List<String>> zonePostcodes);
|
||||
|
||||
/**
|
||||
* 按打单产品同步 LABEL 邮编分区:仅覆盖本次出现的 zone,不碰其他产品/常规分区。
|
||||
*/
|
||||
public String syncLabelProductZones(Long productId, String countryCode2, Map<String, List<String>> zonePostcodes);
|
||||
}
|
||||
|
||||
+14
-21
@@ -233,7 +233,7 @@ public class LblProductServiceImpl implements ILblProductService
|
||||
int removed = 0;
|
||||
List<LblProduct> products = command.getProducts();
|
||||
int total = products.size();
|
||||
Map<String, Map<String, List<String>>> zoneSyncByCountry = new LinkedHashMap<String, Map<String, List<String>>>();
|
||||
List<LblProduct> zoneSyncProducts = new ArrayList<LblProduct>();
|
||||
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<String, Map<String, List<String>>> 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<String, Map<String, List<String>>> 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<String, List<String>> bucket = byCountry.computeIfAbsent(country, k -> new LinkedHashMap<String, List<String>>());
|
||||
for (Map.Entry<String, List<String>> e : product.getZonePostcodes().entrySet())
|
||||
{
|
||||
if (e.getKey() == null || e.getValue() == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<String> list = bucket.computeIfAbsent(e.getKey(), k -> new ArrayList<String>());
|
||||
for (String pc : e.getValue())
|
||||
{
|
||||
if (pc != null && !pc.isBlank() && !list.contains(pc))
|
||||
{
|
||||
list.add(pc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareCounts(LblProduct product)
|
||||
|
||||
@@ -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<PrcZoneLabelProduct> 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<String, List<String>> 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<PrcZone> existing = zoneMapper.selectPrcZoneListByProductId(productId);
|
||||
Map<String, PrcZone> byCode = new HashMap<String, PrcZone>();
|
||||
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<Map.Entry<String, List<String>>> entries = new ArrayList<>(zonePostcodes.entrySet());
|
||||
entries.sort(Comparator.comparingInt(e -> extractZoneSort(e.getKey())));
|
||||
for (Map.Entry<String, List<String>> 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<String> uniquePostcodes = new LinkedHashSet<String>();
|
||||
if (entry.getValue() != null)
|
||||
{
|
||||
uniquePostcodes.addAll(entry.getValue());
|
||||
}
|
||||
List<PrcZoneDetail> 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<String, List<String>> 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);
|
||||
|
||||
+7
-6
@@ -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<String> 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)
|
||||
|
||||
@@ -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
|
||||
</select>
|
||||
|
||||
<insert id="insertPrcZoneDetail" parameterType="PrcZoneDetail" useGeneratedKeys="true" keyProperty="detailId">
|
||||
@@ -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>
|
||||
|
||||
<delete id="deletePrcZoneDetailByProductId" parameterType="Long">
|
||||
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'
|
||||
</delete>
|
||||
|
||||
<select id="selectZoneByCountryPostcode" resultType="com.bms.price.domain.PrcZone">
|
||||
select z.zone_id as zoneId,
|
||||
z.zone_type as zoneType,
|
||||
z.region_id as regionId,
|
||||
z.product_id as productId,
|
||||
z.country_code as countryCode,
|
||||
z.zone_code as zoneCode,
|
||||
z.zone_name as zoneName,
|
||||
@@ -103,7 +116,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
z.update_time as updateTime
|
||||
from prc_zone_detail d
|
||||
inner join prc_zone z on z.zone_id = d.zone_id
|
||||
where upper(ifnull(z.country_code,'')) = upper(#{countryCode})
|
||||
where z.zone_type = 'REGULAR'
|
||||
and z.product_id is null
|
||||
and upper(ifnull(z.country_code,'')) = upper(#{countryCode})
|
||||
and (
|
||||
replace(upper(ifnull(d.postcode,'')), ' ', '') = replace(upper(#{postcode}), ' ', '')
|
||||
or replace(upper(#{postcode}), ' ', '') like concat(replace(upper(ifnull(d.postcode,'')), ' ', ''), '%')
|
||||
)
|
||||
order by
|
||||
case when replace(upper(ifnull(d.postcode,'')), ' ', '') = replace(upper(#{postcode}), ' ', '') then 0 else 1 end,
|
||||
char_length(replace(ifnull(d.postcode,''), ' ', '')) desc,
|
||||
d.detail_id asc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="selectZoneByProductPostcode" resultType="com.bms.price.domain.PrcZone">
|
||||
select z.zone_id as zoneId,
|
||||
z.zone_type as zoneType,
|
||||
z.region_id as regionId,
|
||||
z.product_id as productId,
|
||||
z.country_code as countryCode,
|
||||
z.zone_code as zoneCode,
|
||||
z.zone_name as zoneName,
|
||||
z.zone_sort as zoneSort,
|
||||
z.remark as remark,
|
||||
z.create_time as createTime,
|
||||
z.update_time as updateTime
|
||||
from prc_zone_detail d
|
||||
inner join prc_zone z on z.zone_id = d.zone_id
|
||||
where z.zone_type = 'LABEL'
|
||||
and z.product_id = #{productId}
|
||||
and (
|
||||
replace(upper(ifnull(d.postcode,'')), ' ', '') = replace(upper(#{postcode}), ' ', '')
|
||||
or replace(upper(#{postcode}), ' ', '') like concat(replace(upper(ifnull(d.postcode,'')), ' ', ''), '%')
|
||||
|
||||
@@ -6,7 +6,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<resultMap type="PrcZone" id="PrcZoneResult">
|
||||
<id property="zoneId" column="zone_id" />
|
||||
<result property="zoneType" column="zone_type" />
|
||||
<result property="regionId" column="region_id" />
|
||||
<result property="productId" column="product_id" />
|
||||
<result property="countryCode" column="country_code" />
|
||||
<result property="zoneCode" column="zone_code" />
|
||||
<result property="zoneName" column="zone_name" />
|
||||
@@ -16,6 +18,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="detailCount" column="detail_count" />
|
||||
<result property="countryNameCn" column="country_name_cn" />
|
||||
<result property="productName" column="product_name" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="PrcZoneRegion" id="PrcZoneRegionResult">
|
||||
@@ -28,8 +31,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="detailCount" column="detail_count" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="PrcZoneLabelProduct" id="PrcZoneLabelProductResult">
|
||||
<id property="productId" column="product_id" />
|
||||
<result property="productName" column="product_name" />
|
||||
<result property="dictValue" column="dict_value" />
|
||||
<result property="zoneCount" column="zone_count" />
|
||||
<result property="detailCount" column="detail_count" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectPrcZoneVo">
|
||||
select zone_id, region_id, country_code, zone_code, zone_name, zone_sort, remark, create_time, update_time
|
||||
select zone_id, zone_type, region_id, product_id, country_code, zone_code, zone_name, zone_sort, remark, create_time, update_time
|
||||
from prc_zone
|
||||
</sql>
|
||||
|
||||
@@ -39,25 +50,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</select>
|
||||
|
||||
<select id="selectPrcZoneListByRegionId" parameterType="Long" resultMap="PrcZoneResult">
|
||||
select z.zone_id, z.region_id, z.country_code, z.zone_code, z.zone_name, z.zone_sort, z.remark,
|
||||
select z.zone_id, z.zone_type, z.region_id, z.product_id, z.country_code, z.zone_code, z.zone_name, z.zone_sort, z.remark,
|
||||
z.create_time, z.update_time,
|
||||
(select count(1) from prc_zone_detail d where d.zone_id = z.zone_id) as detail_count
|
||||
from prc_zone z
|
||||
where z.region_id = #{regionId}
|
||||
and z.zone_type = 'REGULAR'
|
||||
and z.product_id is null
|
||||
order by z.zone_sort asc, z.zone_id asc
|
||||
</select>
|
||||
|
||||
<select id="selectPrcZoneListByProductId" parameterType="Long" resultMap="PrcZoneResult">
|
||||
select z.zone_id, z.zone_type, z.region_id, z.product_id, z.country_code, z.zone_code, z.zone_name, z.zone_sort, z.remark,
|
||||
z.create_time, z.update_time,
|
||||
(select count(1) from prc_zone_detail d where d.zone_id = z.zone_id) as detail_count
|
||||
from prc_zone z
|
||||
where z.product_id = #{productId}
|
||||
and z.zone_type = 'LABEL'
|
||||
order by z.zone_sort asc, z.zone_id asc
|
||||
</select>
|
||||
|
||||
<select id="selectPrcZoneList" parameterType="PrcZone" resultMap="PrcZoneResult">
|
||||
select z.zone_id, z.region_id, z.country_code, z.zone_code, z.zone_name, z.zone_sort, z.remark,
|
||||
select z.zone_id, z.zone_type, z.region_id, z.product_id, z.country_code, z.zone_code, z.zone_name, z.zone_sort, z.remark,
|
||||
z.create_time, z.update_time,
|
||||
r.country_name_cn,
|
||||
p.product_name,
|
||||
(select count(1) from prc_zone_detail d where d.zone_id = z.zone_id) as detail_count
|
||||
from prc_zone z
|
||||
left join region r on r.region_id = z.region_id
|
||||
left join prc_label_product p on p.product_id = z.product_id
|
||||
<where>
|
||||
<if test="zoneType != null and zoneType != ''">
|
||||
AND z.zone_type = #{zoneType}
|
||||
</if>
|
||||
<if test="zoneType == null or zoneType == ''">
|
||||
AND z.zone_type = 'REGULAR'
|
||||
</if>
|
||||
<if test="regionId != null">
|
||||
AND z.region_id = #{regionId}
|
||||
</if>
|
||||
<if test="productId != null">
|
||||
AND z.product_id = #{productId}
|
||||
</if>
|
||||
<if test="countryCode != null and countryCode != ''">
|
||||
AND z.country_code = #{countryCode}
|
||||
</if>
|
||||
@@ -79,6 +113,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
inner join region r on r.region_id = z.region_id
|
||||
left join prc_zone_detail d on d.zone_id = z.zone_id
|
||||
<where>
|
||||
AND z.zone_type = 'REGULAR'
|
||||
AND z.product_id is null
|
||||
<if test="countryNameCn != null and countryNameCn != ''">
|
||||
AND r.country_name_cn like concat('%', #{countryNameCn}, '%')
|
||||
</if>
|
||||
@@ -95,21 +131,51 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectZoneRegionById" parameterType="Long" resultMap="PrcZoneRegionResult">
|
||||
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}
|
||||
</select>
|
||||
|
||||
<select id="selectLabelProductZoneList" parameterType="PrcZoneLabelProduct" resultMap="PrcZoneLabelProductResult">
|
||||
select p.product_id, p.product_name, p.dict_value,
|
||||
count(distinct z.zone_id) as zone_count,
|
||||
count(d.detail_id) as detail_count
|
||||
from prc_zone z
|
||||
inner join prc_label_product p on p.product_id = z.product_id
|
||||
left join prc_zone_detail d on d.zone_id = z.zone_id
|
||||
<where>
|
||||
AND z.zone_type = 'LABEL'
|
||||
AND z.product_id is not null
|
||||
<if test="productName != null and productName != ''">
|
||||
AND (p.product_name like concat('%', #{productName}, '%')
|
||||
OR p.dict_value like concat('%', #{productName}, '%'))
|
||||
</if>
|
||||
<if test="dictValue != null and dictValue != ''">
|
||||
AND p.dict_value like concat('%', #{dictValue}, '%')
|
||||
</if>
|
||||
<if test="productId != null">
|
||||
AND p.product_id = #{productId}
|
||||
</if>
|
||||
</where>
|
||||
group by p.product_id, p.product_name, p.dict_value
|
||||
order by p.product_name asc, p.product_id asc
|
||||
</select>
|
||||
|
||||
<select id="countByRegionId" parameterType="Long" resultType="int">
|
||||
select count(1) from prc_zone where region_id = #{regionId}
|
||||
select count(1) from prc_zone
|
||||
where region_id = #{regionId}
|
||||
and zone_type = 'REGULAR'
|
||||
and product_id is null
|
||||
</select>
|
||||
|
||||
<insert id="insertPrcZone" parameterType="PrcZone" useGeneratedKeys="true" keyProperty="zoneId">
|
||||
insert into prc_zone (
|
||||
<if test="zoneType != null and zoneType != ''">zone_type,</if>
|
||||
<if test="regionId != null">region_id,</if>
|
||||
<if test="productId != null">product_id,</if>
|
||||
<if test="countryCode != null and countryCode != ''">country_code,</if>
|
||||
<if test="zoneCode != null and zoneCode != ''">zone_code,</if>
|
||||
<if test="zoneName != null">zone_name,</if>
|
||||
@@ -117,7 +183,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="remark != null">remark,</if>
|
||||
create_time
|
||||
) values (
|
||||
<if test="zoneType != null and zoneType != ''">#{zoneType},</if>
|
||||
<if test="regionId != null">#{regionId},</if>
|
||||
<if test="productId != null">#{productId},</if>
|
||||
<if test="countryCode != null and countryCode != ''">#{countryCode},</if>
|
||||
<if test="zoneCode != null and zoneCode != ''">#{zoneCode},</if>
|
||||
<if test="zoneName != null">#{zoneName},</if>
|
||||
@@ -130,7 +198,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<update id="updatePrcZone" parameterType="PrcZone">
|
||||
update prc_zone
|
||||
<set>
|
||||
<if test="zoneType != null and zoneType != ''">zone_type = #{zoneType},</if>
|
||||
<if test="regionId != null">region_id = #{regionId},</if>
|
||||
<if test="productId != null">product_id = #{productId},</if>
|
||||
<if test="countryCode != null and countryCode != ''">country_code = #{countryCode},</if>
|
||||
<if test="zoneCode != null and zoneCode != ''">zone_code = #{zoneCode},</if>
|
||||
<if test="zoneName != null">zone_name = #{zoneName},</if>
|
||||
@@ -149,7 +219,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</delete>
|
||||
|
||||
<delete id="deletePrcZoneByRegionId" parameterType="Long">
|
||||
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
|
||||
</delete>
|
||||
|
||||
<delete id="deletePrcZoneByRegionIds" parameterType="Long">
|
||||
@@ -157,6 +230,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<foreach item="regionId" collection="array" open="(" separator="," close=")">
|
||||
#{regionId}
|
||||
</foreach>
|
||||
and zone_type = 'REGULAR'
|
||||
and product_id is null
|
||||
</delete>
|
||||
|
||||
<delete id="deletePrcZoneByProductId" parameterType="Long">
|
||||
delete from prc_zone
|
||||
where product_id = #{productId}
|
||||
and zone_type = 'LABEL'
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -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'
|
||||
);
|
||||
@@ -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;
|
||||
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
<template>
|
||||
<el-drawer v-model="visible" size="860px" append-to-body>
|
||||
<template #header>
|
||||
<div class="drawer-head">
|
||||
<span class="drawer-title">打单产品分区</span>
|
||||
<span v-if="product" class="drawer-sub">
|
||||
当前:{{ product.productName || product.dictValue || product.productId }}
|
||||
<template v-if="product.dictValue">({{ product.dictValue }})</template>
|
||||
,共 {{ zoneList.length }} 个分区
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-loading="zoneLoading">
|
||||
<div class="zone-toolbar">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
icon="Plus"
|
||||
size="small"
|
||||
:disabled="!product"
|
||||
@click="handleZoneAdd"
|
||||
v-hasPermi="['price:zone:add']"
|
||||
>新增分区</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
icon="Delete"
|
||||
size="small"
|
||||
:disabled="!product"
|
||||
@click="handleClearZones"
|
||||
v-hasPermi="['price:zone:remove']"
|
||||
>清空分区</el-button>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
:data="zoneList"
|
||||
border
|
||||
highlight-current-row
|
||||
row-key="zoneId"
|
||||
:empty-text="product ? '该产品暂无分区,可导入打单价卡同步或点击「新增分区」' : '请先选择产品'"
|
||||
>
|
||||
<el-table-column label="分区名称" align="center" min-width="200">
|
||||
<template #default="{ row }">
|
||||
<div class="zone-country-cell">
|
||||
<div class="zone-title">{{ row.zoneName || row.zoneCode }}</div>
|
||||
<el-button link type="primary" class="zone-click" @click="openPostcodeDrawer(row)" v-hasPermi="['price:zone:query']">分区点击</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="国家编码" prop="countryCode" align="center" width="110" />
|
||||
<el-table-column label="分区代码" prop="zoneCode" align="center" width="140" />
|
||||
<el-table-column label="邮编数" prop="detailCount" align="center" width="100" />
|
||||
<el-table-column label="排序" prop="zoneSort" align="center" width="80" />
|
||||
<el-table-column label="操作" align="center" width="220" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" icon="View" @click="openPostcodeDrawer(row)" v-hasPermi="['price:zone:query']">明细</el-button>
|
||||
<el-button link type="primary" icon="Edit" @click="handleZoneUpdate(row)" v-hasPermi="['price:zone:edit']">编辑</el-button>
|
||||
<el-button link type="primary" icon="Delete" @click="handleZoneDelete(row.zoneId)" v-hasPermi="['price:zone:remove']">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<zone-form-dialog ref="zoneFormRef" :country="formCountry" zone-type="LABEL" :product-id="product?.productId" @success="onZoneChanged" />
|
||||
<postcode-drawer ref="postcodeDrawerRef" @changed="onZoneChanged" />
|
||||
</el-drawer>
|
||||
</template>
|
||||
|
||||
<script setup name="LabelZoneDrawer">
|
||||
import {
|
||||
delLabelProductZones,
|
||||
listZone, addZone, updateZone, delZone
|
||||
} from '@/api/price/zone'
|
||||
import ZoneFormDialog from './ZoneFormDialog.vue'
|
||||
import PostcodeDrawer from './PostcodeDrawer.vue'
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
const emit = defineEmits(['changed'])
|
||||
|
||||
const visible = ref(false)
|
||||
const product = ref(null)
|
||||
const zoneList = ref([])
|
||||
const zoneLoading = ref(false)
|
||||
const zoneFormRef = ref()
|
||||
const postcodeDrawerRef = ref()
|
||||
|
||||
const formCountry = computed(() => {
|
||||
if (!product.value) return null
|
||||
// ZoneFormDialog expects region fields; LABEL zones still carry regionId/countryCode from sync
|
||||
const first = zoneList.value[0]
|
||||
return {
|
||||
regionId: first?.regionId || null,
|
||||
countryCode2: first?.countryCode || '',
|
||||
countryNameCn: product.value.productName || product.value.dictValue || ''
|
||||
}
|
||||
})
|
||||
|
||||
function open(row) {
|
||||
product.value = row || null
|
||||
visible.value = true
|
||||
loadZoneList()
|
||||
}
|
||||
|
||||
function reload() {
|
||||
loadZoneList()
|
||||
}
|
||||
|
||||
function loadZoneList() {
|
||||
if (!product.value?.productId) {
|
||||
zoneList.value = []
|
||||
return
|
||||
}
|
||||
zoneLoading.value = true
|
||||
listZone({ zoneType: 'LABEL', productId: product.value.productId, pageNum: 1, pageSize: 200 }).then(res => {
|
||||
zoneList.value = res.rows || []
|
||||
}).catch(() => {
|
||||
zoneList.value = []
|
||||
}).finally(() => {
|
||||
zoneLoading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
function handleZoneAdd() {
|
||||
if (!formCountry.value?.regionId) {
|
||||
proxy.$modal.msgWarning('该产品尚无国家分区主数据,请先通过打单价卡导入同步')
|
||||
return
|
||||
}
|
||||
zoneFormRef.value.open()
|
||||
}
|
||||
|
||||
function handleZoneUpdate(row) {
|
||||
zoneFormRef.value.open(row)
|
||||
}
|
||||
|
||||
function onZoneChanged() {
|
||||
// ensure newly added zone is LABEL + product scoped
|
||||
loadZoneList()
|
||||
emit('changed')
|
||||
}
|
||||
|
||||
function handleZoneDelete(zoneIds) {
|
||||
proxy.$modal.confirm('是否确认删除分区编号为"' + zoneIds + '"的数据?将同时删除邮编明细。').then(() => {
|
||||
return delZone(zoneIds)
|
||||
}).then(() => {
|
||||
proxy.$modal.msgSuccess('删除成功')
|
||||
onZoneChanged()
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
function handleClearZones() {
|
||||
if (!product.value?.productId) return
|
||||
proxy.$modal.confirm('是否清空打单产品 productId="' + product.value.productId + '" 下的全部分区与邮编?').then(() => {
|
||||
return delLabelProductZones(product.value.productId)
|
||||
}).then(() => {
|
||||
zoneList.value = []
|
||||
proxy.$modal.msgSuccess('清空成功')
|
||||
emit('changed')
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
function onProductCleared(productId) {
|
||||
if (visible.value && String(product.value?.productId) === String(productId)) {
|
||||
zoneList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function openPostcodeDrawer(row) {
|
||||
postcodeDrawerRef.value.open(row)
|
||||
}
|
||||
|
||||
defineExpose({ open, reload, onProductCleared })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.drawer-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.drawer-title { font-size: 16px; font-weight: 600; }
|
||||
.drawer-sub { color: #909399; font-size: 13px; }
|
||||
.zone-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.zone-country-cell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
padding: 4px 0;
|
||||
}
|
||||
.zone-title { font-weight: 500; }
|
||||
.zone-click { padding: 0; height: auto; font-size: 12px; }
|
||||
</style>
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-tabs v-model="activeTab" class="mb16" @tab-change="onTabChange">
|
||||
<el-tab-pane label="常规计费分区" name="regular" />
|
||||
<el-tab-pane label="打单计费分区" name="label" />
|
||||
</el-tabs>
|
||||
|
||||
<el-alert
|
||||
v-if="activeTab === 'regular'"
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="mb16"
|
||||
title="国家来自 region;点击「分区」在抽屉中查看/维护国家分区,抽屉内点击「分区点击」查看邮编明细。导入 Excel 时需 sheet 名以「分区」结尾且能匹配国家表。"
|
||||
title="常规计费按国家维护分区;点击「分区」维护邮编。导入 Excel 时 sheet 名需以「分区」结尾且能匹配国家表。"
|
||||
/>
|
||||
<el-alert
|
||||
v-else
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="mb16"
|
||||
title="打单计费按产品维护分区;由打单价卡导入同步。计费时按渠道绑定产品 + 订单邮编匹配分区。"
|
||||
/>
|
||||
|
||||
<basic-table
|
||||
v-show="activeTab === 'regular'"
|
||||
ref="countryTableRef"
|
||||
:columns="countryColumns"
|
||||
:search-columns="countrySearchColumns"
|
||||
@@ -36,7 +51,22 @@
|
||||
</template>
|
||||
</basic-table>
|
||||
|
||||
<basic-table
|
||||
v-show="activeTab === 'label'"
|
||||
ref="labelTableRef"
|
||||
:columns="labelColumns"
|
||||
:search-columns="labelSearchColumns"
|
||||
:query="queryLabelProductList"
|
||||
row-key="productId"
|
||||
>
|
||||
<template #col-action="{ row }">
|
||||
<el-button link type="primary" icon="List" @click.stop="openLabelZoneDrawer(row)" v-hasPermi="['price:zone:query']">分区</el-button>
|
||||
<el-button link type="primary" icon="Delete" @click.stop="handleLabelDelete(row.productId)" v-hasPermi="['price:zone:remove']">清空</el-button>
|
||||
</template>
|
||||
</basic-table>
|
||||
|
||||
<zone-drawer ref="zoneDrawerRef" @changed="onZoneChanged" />
|
||||
<label-zone-drawer ref="labelZoneDrawerRef" @changed="onLabelZoneChanged" />
|
||||
|
||||
<excel-import-dialog
|
||||
ref="importRef"
|
||||
@@ -51,13 +81,17 @@
|
||||
|
||||
<script setup name="PriceZone">
|
||||
import ExcelImportDialog from '@/components/ExcelImportDialog'
|
||||
import { listCountry, delCountryZones } from '@/api/price/zone'
|
||||
import { listCountry, delCountryZones, listLabelProduct, delLabelProductZones } from '@/api/price/zone'
|
||||
import ZoneDrawer from './components/ZoneDrawer.vue'
|
||||
import LabelZoneDrawer from './components/LabelZoneDrawer.vue'
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
|
||||
const activeTab = ref('regular')
|
||||
const countryTableRef = ref()
|
||||
const labelTableRef = ref()
|
||||
const zoneDrawerRef = ref()
|
||||
const labelZoneDrawerRef = ref()
|
||||
const importRef = ref()
|
||||
|
||||
const countrySearchColumns = [
|
||||
@@ -75,11 +109,35 @@ const countryColumns = [
|
||||
{ label: '操作', prop: 'action', align: 'center', width: 160, showInToolbar: false }
|
||||
]
|
||||
|
||||
const labelSearchColumns = [
|
||||
{ label: '产品名称', prop: 'productName', component: 'input', placeholder: '产品名称 / 字典值', width: '260px' }
|
||||
]
|
||||
|
||||
const labelColumns = [
|
||||
{ label: '产品编号', prop: 'productId', align: 'center', width: 110 },
|
||||
{ label: '产品名称', prop: 'productName', align: 'center', minWidth: 180 },
|
||||
{ label: '字典值', prop: 'dictValue', align: 'center', minWidth: 160 },
|
||||
{ label: '分区数', prop: 'zoneCount', align: 'center', width: 90 },
|
||||
{ label: '邮编数', prop: 'detailCount', align: 'center', width: 100 },
|
||||
{ label: '操作', prop: 'action', align: 'center', width: 160, showInToolbar: false }
|
||||
]
|
||||
|
||||
function queryCountryList(params) {
|
||||
return listCountry(params)
|
||||
}
|
||||
|
||||
/** 工具栏「为国家新增分区」:不传国家,抽屉内自行选择 */
|
||||
function queryLabelProductList(params) {
|
||||
return listLabelProduct(params)
|
||||
}
|
||||
|
||||
function onTabChange() {
|
||||
if (activeTab.value === 'regular') {
|
||||
countryTableRef.value?.refresh?.()
|
||||
} else {
|
||||
labelTableRef.value?.refresh?.()
|
||||
}
|
||||
}
|
||||
|
||||
function handleAddZone() {
|
||||
zoneDrawerRef.value.open()
|
||||
}
|
||||
@@ -88,13 +146,20 @@ function openZoneDrawer(row) {
|
||||
zoneDrawerRef.value.open(row)
|
||||
}
|
||||
|
||||
/** 抽屉内分区/邮编有变动 → 刷新国家表格的分区数/邮编数统计 */
|
||||
function openLabelZoneDrawer(row) {
|
||||
labelZoneDrawerRef.value.open(row)
|
||||
}
|
||||
|
||||
function onZoneChanged() {
|
||||
countryTableRef.value.refresh()
|
||||
}
|
||||
|
||||
function onLabelZoneChanged() {
|
||||
labelTableRef.value.refresh()
|
||||
}
|
||||
|
||||
function handleCountryDelete(regionIds) {
|
||||
proxy.$modal.confirm('是否清空国家 regionId="' + regionIds + '" 下的全部分区与邮编?(不会删除 region 国家主数据)').then(() => {
|
||||
proxy.$modal.confirm('是否清空国家 regionId="' + regionIds + '" 下的全部常规分区与邮编?(不会删除 region 国家主数据)').then(() => {
|
||||
return delCountryZones(regionIds)
|
||||
}).then(() => {
|
||||
countryTableRef.value.refresh()
|
||||
@@ -103,6 +168,16 @@ function handleCountryDelete(regionIds) {
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
function handleLabelDelete(productId) {
|
||||
proxy.$modal.confirm('是否清空打单产品 productId="' + productId + '" 下的全部分区与邮编?').then(() => {
|
||||
return delLabelProductZones(productId)
|
||||
}).then(() => {
|
||||
labelTableRef.value.refresh()
|
||||
labelZoneDrawerRef.value.onProductCleared(productId)
|
||||
proxy.$modal.msgSuccess('清空成功')
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
function handleImport() {
|
||||
importRef.value.open()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user