应付邮编优化和应付列表去除多余字段

This commit is contained in:
liuminghui
2026-11-20 18:01:43 +08:00
parent 5c2d4a23c2
commit 817545059e
9 changed files with 166 additions and 65 deletions
@@ -12,6 +12,9 @@ public interface PayPostcodeMapper
List<PayPostcodeGroup> selectCountryList(PayPostcodeGroup query);
/** 当前页国家的分区数和邮编数。 */
List<PayPostcodeGroup> selectCountryZoneStats(PayPostcodeGroup query);
List<PayPostcodeGroup> selectZoneList(PayPostcodeGroup query);
PayPostcodeGroup selectSampleGroup(PayPostcodeGroup query);
@@ -1,8 +1,10 @@
package com.bms.price.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import com.bms.common.exception.ServiceException;
@@ -39,7 +41,57 @@ public class PayPostcodeServiceImpl implements IPayPostcodeService
@Override
public List<PayPostcodeGroup> selectCountryList(PayPostcodeGroup query)
{
return payPostcodeMapper.selectCountryList(query);
List<PayPostcodeGroup> countries = payPostcodeMapper.selectCountryList(query);
if (countries == null || countries.isEmpty())
{
return countries;
}
List<Long> groupIds = new ArrayList<Long>();
for (PayPostcodeGroup row : countries)
{
row.setZoneCount(0);
row.setLineCount(0);
if (row.getGroupId() != null)
{
groupIds.add(row.getGroupId());
}
}
if (groupIds.isEmpty())
{
return countries;
}
query.getParams().put("groupIds", groupIds);
try
{
List<PayPostcodeGroup> stats = payPostcodeMapper.selectCountryZoneStats(query);
if (stats == null || stats.isEmpty())
{
return countries;
}
Map<Long, PayPostcodeGroup> byId = new HashMap<Long, PayPostcodeGroup>();
for (PayPostcodeGroup stat : stats)
{
if (stat.getGroupId() != null)
{
byId.put(stat.getGroupId(), stat);
}
}
for (PayPostcodeGroup row : countries)
{
PayPostcodeGroup stat = byId.get(row.getGroupId());
if (stat == null)
{
continue;
}
row.setZoneCount(stat.getZoneCount() == null ? 0 : stat.getZoneCount());
row.setLineCount(stat.getLineCount() == null ? 0 : stat.getLineCount());
}
return countries;
}
finally
{
query.getParams().remove("groupIds");
}
}
@Override
@@ -96,6 +96,31 @@
end
</sql>
<sql id="countryBucket">
case
when nullif(trim(g.country_code), '') is not null then upper(trim(g.country_code))
when nullif(trim(g.country_name), '') is not null then trim(g.country_name)
else '未填写国家'
end
</sql>
<sql id="countryListFilter">
<if test="countryName != null and countryName != ''">
and (g.country_name like concat('%', #{countryName}, '%') or g.country_code like concat('%', #{countryName}, '%') or g.catalog_country like concat('%', #{countryName}, '%'))
</if>
<if test="serviceType != null and serviceType != ''">and g.service_type like concat('%', #{serviceType}, '%')</if>
<if test="productName != null and productName != ''">and g.product_name like concat('%', #{productName}, '%')</if>
<if test="channelName != null and channelName != ''">and g.channel_name like concat('%', #{channelName}, '%')</if>
<if test="coverage != null and coverage != ''">and g.coverage = #{coverage}</if>
<if test="postcode != null and postcode != ''">
and exists (
select 1 from pay_postcode_line lp
where lp.group_id = g.group_id and lp.postcode like concat('%', #{postcode}, '%')
)
</if>
</sql>
<!-- 国家列表只汇总配置表。分区数和邮编数另查当前页,避免整表邮编先放大再聚合。 -->
<select id="selectCountryList" parameterType="com.bms.price.domain.PayPostcodeGroup" resultType="com.bms.price.domain.PayPostcodeGroup">
select min(g.group_id) as groupId,
max(g.country_name) as countryName,
@@ -104,50 +129,65 @@
group_concat(distinct nullif(trim(g.service_type), '') order by g.service_type separator '、') as serviceType,
group_concat(distinct nullif(trim(g.product_name), '') order by g.product_name separator '、') as productName,
group_concat(distinct nullif(trim(g.channel_name), '') order by g.channel_name separator '、') as channelName,
count(distinct case
when l.line_id is null and nullif(trim(g.block_title), '') is null then null
else concat(
case
when l.line_id is not null then
case
when nullif(trim(l.zone_name), '') is not null then trim(l.zone_name)
when nullif(trim(l.region_name), '') is not null then trim(l.region_name)
when nullif(trim(g.block_title), '') is not null then trim(g.block_title)
else '未分区'
end
else trim(g.block_title)
end,
'||',
lower(ifnull(trim(g.channel_name), ''))
)
end) as zoneCount,
count(l.line_id) as lineCount,
max(g.create_time) as createTime
from pay_postcode_group g
left join pay_postcode_line l on l.group_id = g.group_id
<where>
<if test="countryName != null and countryName != ''">
and (g.country_name like concat('%', #{countryName}, '%') or g.country_code like concat('%', #{countryName}, '%') or g.catalog_country like concat('%', #{countryName}, '%'))
</if>
<if test="serviceType != null and serviceType != ''">and g.service_type like concat('%', #{serviceType}, '%')</if>
<if test="productName != null and productName != ''">and g.product_name like concat('%', #{productName}, '%')</if>
<if test="channelName != null and channelName != ''">and g.channel_name like concat('%', #{channelName}, '%')</if>
<if test="coverage != null and coverage != ''">and g.coverage = #{coverage}</if>
<if test="postcode != null and postcode != ''">
and exists (
select 1 from pay_postcode_line lp
where lp.group_id = g.group_id and lp.postcode like concat('%', #{postcode}, '%')
)
</if>
<include refid="countryListFilter"/>
</where>
group by case
when nullif(trim(g.country_code), '') is not null then upper(trim(g.country_code))
when nullif(trim(g.country_name), '') is not null then trim(g.country_name)
else '未填写国家'
end
group by <include refid="countryBucket"/>
order by max(g.create_time) desc
</select>
<!-- 当前页国家的分区数、邮编数。有邮编的按分区名加渠道去重;没有邮编但有区块标题的算一个分区。 -->
<select id="selectCountryZoneStats" parameterType="com.bms.price.domain.PayPostcodeGroup" resultType="com.bms.price.domain.PayPostcodeGroup">
select min(t.group_id) as groupId,
count(distinct t.zone_key) as zoneCount,
count(case when t.line_flag = 1 then 1 end) as lineCount
from (
select g.group_id,
<include refid="countryBucket"/> as country_key,
concat(<include refid="zoneExpr"/>, '||', lower(ifnull(trim(g.channel_name), ''))) as zone_key,
1 as line_flag
from (
select g.group_id, g.block_title, g.channel_name, g.country_code, g.country_name
from pay_postcode_group g
<where>
<include refid="countryListFilter"/>
<include refid="pageCountryScope"/>
</where>
) g
inner join pay_postcode_line l on l.group_id = g.group_id
union all
select g.group_id,
<include refid="countryBucket"/> as country_key,
concat(trim(g.block_title), '||', lower(ifnull(trim(g.channel_name), ''))) as zone_key,
0 as line_flag
from pay_postcode_group g
<where>
<include refid="countryListFilter"/>
<include refid="pageCountryScope"/>
and nullif(trim(g.block_title), '') is not null
and not exists (select 1 from pay_postcode_line l where l.group_id = g.group_id)
</where>
) t
group by t.country_key
</select>
<sql id="pageCountryScope">
<if test="params != null and params.groupIds != null and params.groupIds.size() > 0">
and <include refid="countryBucket"/> in (
select case
when nullif(trim(src.country_code), '') is not null then upper(trim(src.country_code))
when nullif(trim(src.country_name), '') is not null then trim(src.country_name)
else '未填写国家'
end
from pay_postcode_group src
where src.group_id in
<foreach collection="params.groupIds" item="id" open="(" separator="," close=")">#{id}</foreach>
)
</if>
</sql>
<select id="selectZoneList" parameterType="com.bms.price.domain.PayPostcodeGroup" resultType="com.bms.price.domain.PayPostcodeGroup">
select t.zone_name as zoneName,
min(t.group_id) as groupId,
@@ -148,7 +148,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
)
left join pay_product cur on cur.product_id = t.product_id
<include refid="payProductWhere"/>
order by ifnull(t.effective_start, pay_product.effective_date) desc, pay_product.product_id desc
order by pay_product.create_time desc, pay_product.product_id desc
</select>
<select id="selectPayProductById" parameterType="long" resultMap="PayProductResult">