新增打单产品分区管理功能,优化常规分区逻辑

This commit is contained in:
wuweihua
2026-11-18 19:01:40 +08:00
parent 4b766184b5
commit 0445c4fa21
19 changed files with 787 additions and 50 deletions
@@ -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);
}
@@ -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);
@@ -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>