Files
BMS/bms-back/bms-system/src/main/resources/mapper/price/PayPostcodeMapper.xml
T
2026-11-13 18:26:21 +08:00

473 lines
24 KiB
XML

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.price.mapper.PayPostcodeMapper">
<select id="selectGroupList" parameterType="com.bms.price.domain.PayPostcodeGroup" resultType="com.bms.price.domain.PayPostcodeGroup">
select group_id as groupId, source_file as sourceFile, file_md5 as fileMd5, sheet_name as sheetName,
block_title as blockTitle, config_kind as configKind, coverage, channel_name as channelName,
country_name as countryName, country_code as countryCode,
service_type as serviceType, catalog_country as catalogCountry, product_name as productName, quote_sheet as quoteSheet,
fee_name as feeName, fee_text as feeText, line_count as lineCount, create_by as createBy, create_time as createTime, remark
from pay_postcode_group
<where>
<if test="sourceFile != null and sourceFile != ''">and source_file like concat('%', #{sourceFile}, '%')</if>
<if test="sheetName != null and sheetName != ''">and sheet_name like concat('%', #{sheetName}, '%')</if>
<if test="countryName != null and countryName != ''">and (country_name like concat('%', #{countryName}, '%') or country_code like concat('%', #{countryName}, '%') or catalog_country like concat('%', #{countryName}, '%'))</if>
<if test="serviceType != null and serviceType != ''">and service_type like concat('%', #{serviceType}, '%')</if>
<if test="productName != null and productName != ''">and product_name like concat('%', #{productName}, '%')</if>
<if test="quoteSheet != null and quoteSheet != ''">and quote_sheet like concat('%', #{quoteSheet}, '%')</if>
<if test="configKind != null and configKind != ''">and config_kind = #{configKind}</if>
<if test="coverage != null and coverage != ''">and coverage = #{coverage}</if>
<if test="channelName != null and channelName != ''">and channel_name like concat('%', #{channelName}, '%')</if>
<if test="feeName != null and feeName != ''">and fee_name like concat('%', #{feeName}, '%')</if>
<if test="postcode != null and postcode != ''">
and exists (
select 1 from pay_postcode_line l
where l.group_id = pay_postcode_group.group_id and l.postcode like concat('%', #{postcode}, '%')
)
</if>
</where>
order by group_id desc
</select>
<select id="selectBlockTitlesByCountry" resultType="string">
select distinct block_title
from pay_postcode_group
where block_title is not null
and block_title &lt;&gt; ''
<if test="countryCode != null and countryCode != ''">
and (
upper(ifnull(country_code, '')) = upper(#{countryCode})
or upper(ifnull(catalog_country, '')) = upper(#{countryCode})
)
</if>
<if test="countryName != null and countryName != ''">
and (
country_name like concat('%', #{countryName}, '%')
or catalog_country like concat('%', #{countryName}, '%')
)
</if>
order by block_title asc
</select>
<sql id="countryMatch">
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(trim(g.country_code)) = upper(trim(#{countryCode}))
</when>
<otherwise>
and (g.country_code is null or trim(g.country_code) = '')
and g.country_name = #{countryName}
</otherwise>
</choose>
</sql>
<sql id="zoneExpr">
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
</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,
max(g.country_code) as countryCode,
group_concat(distinct nullif(trim(g.coverage), '') order by g.coverage separator '、') as coverage,
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 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
when nullif(trim(g.block_title), '') is not null then trim(g.block_title)
else null
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>
</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
order by max(g.create_time) desc
</select>
<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,
group_concat(distinct nullif(trim(t.coverage), '') order by t.coverage separator '、') as coverage,
count(t.line_id) as lineCount,
max(t.country_name) as countryName,
max(t.country_code) as countryCode
from (
select g.group_id, g.coverage, g.country_name, g.country_code, l.line_id,
case
when l.line_id is null then nullif(trim(g.block_title), '')
else
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
end as zone_name
from pay_postcode_group g
left join pay_postcode_line l on l.group_id = g.group_id
<where>
<include refid="countryMatch"/>
</where>
) t
where t.zone_name is not null and t.zone_name &lt;&gt; ''
group by t.zone_name
order by t.zone_name asc
</select>
<select id="selectSampleGroup" parameterType="com.bms.price.domain.PayPostcodeGroup" resultType="com.bms.price.domain.PayPostcodeGroup">
select group_id as groupId, source_file as sourceFile, file_md5 as fileMd5, sheet_name as sheetName,
block_title as blockTitle, config_kind as configKind, coverage, channel_name as channelName,
country_name as countryName, country_code as countryCode,
service_type as serviceType, catalog_country as catalogCountry, product_name as productName, quote_sheet as quoteSheet
from pay_postcode_group g
<where>
<include refid="countryMatch"/>
</where>
order by g.group_id asc
limit 1
</select>
<select id="countZoneName" parameterType="com.bms.price.domain.PayPostcodeGroup" resultType="int">
select count(*) from (
select 1
from pay_postcode_group g
left join pay_postcode_line l on l.group_id = g.group_id
<where>
<include refid="countryMatch"/>
and (
(l.line_id is null and trim(g.block_title) = #{zoneName})
or (l.line_id is not null and <include refid="zoneExpr"/> = #{zoneName})
)
</where>
limit 1
) hit
</select>
<select id="selectZoneGroupId" parameterType="com.bms.price.domain.PayPostcodeGroup" resultType="long">
select g.group_id
from pay_postcode_group g
left join pay_postcode_line l on l.group_id = g.group_id
<where>
<include refid="countryMatch"/>
and (
(g.source_file = '手工新增' and trim(g.block_title) = #{zoneName})
or (l.line_id is not null and <include refid="zoneExpr"/> = #{zoneName})
)
</where>
order by case when g.source_file = '手工新增' and trim(g.block_title) = #{zoneName} then 0 else 1 end, g.group_id asc
limit 1
</select>
<update id="updateCountryProfile" parameterType="com.bms.price.domain.PayPostcodeGroup">
update pay_postcode_group g
set g.service_type = #{serviceType},
g.product_name = #{productName},
g.channel_name = #{channelName}
<where>
<include refid="countryMatch"/>
</where>
</update>
<select id="selectGroupIdsByCountry" parameterType="com.bms.price.domain.PayPostcodeGroup" resultType="long">
select g.group_id from pay_postcode_group g
<where>
<include refid="countryMatch"/>
</where>
</select>
<update id="renameZoneLines" parameterType="com.bms.price.domain.PayPostcodeGroup">
update pay_postcode_line l
inner join pay_postcode_group g on g.group_id = l.group_id
set l.zone_name = #{zoneName}
<where>
<include refid="countryMatch"/>
and <include refid="zoneExpr"/> = #{oldZoneName}
</where>
</update>
<update id="updateExclusiveZone" parameterType="com.bms.price.domain.PayPostcodeGroup">
update pay_postcode_group g
set g.block_title = case
when trim(g.block_title) = #{oldZoneName} or g.source_file = '手工新增' then #{zoneName}
else g.block_title
end,
g.coverage = #{coverage},
g.fee_name = case
when #{coverage} = 'REMOTE' and (g.fee_name is null or trim(g.fee_name) = '') then '偏远'
else g.fee_name
end
<where>
<include refid="countryMatch"/>
and (
trim(g.block_title) = #{oldZoneName}
or (
exists (
select 1 from pay_postcode_line l
where l.group_id = g.group_id and <include refid="zoneExpr"/> = #{zoneName}
)
and not exists (
select 1 from pay_postcode_line l
where l.group_id = g.group_id and <include refid="zoneExpr"/> &lt;&gt; #{zoneName}
)
)
)
</where>
</update>
<insert id="insertLine" parameterType="com.bms.price.domain.PayPostcodeLine" useGeneratedKeys="true" keyProperty="lineId">
insert into pay_postcode_line (
group_id, country_name, country_code, region_name, region_name_cn, city_name, region_code,
zone_name, postcode, postcode_raw, postcode_end, extra_text, sort_no
) values (
#{groupId}, #{countryName}, #{countryCode}, #{regionName}, #{regionNameCn}, #{cityName}, #{regionCode},
#{zoneName}, #{postcode}, #{postcodeRaw}, #{postcodeEnd}, #{extraText}, ifnull(#{sortNo}, 0)
)
</insert>
<update id="updateLine" parameterType="com.bms.price.domain.PayPostcodeLine">
update pay_postcode_line
set city_name = #{cityName},
zone_name = #{zoneName},
postcode = #{postcode},
postcode_raw = #{postcodeRaw},
postcode_end = #{postcodeEnd}
where line_id = #{lineId}
</update>
<select id="selectLineById" resultType="com.bms.price.domain.PayPostcodeLine">
select line_id as lineId, group_id as groupId, country_name as countryName, country_code as countryCode,
city_name as cityName, zone_name as zoneName, postcode, postcode_raw as postcodeRaw, postcode_end as postcodeEnd
from pay_postcode_line
where line_id = #{lineId}
</select>
<select id="selectGroupIdsByLineIds" resultType="long">
select distinct group_id from pay_postcode_line
where line_id in
<foreach collection="lineIds" item="id" open="(" separator="," close=")">#{id}</foreach>
</select>
<delete id="deleteLineByIds">
delete from pay_postcode_line where line_id in
<foreach collection="lineIds" item="id" open="(" separator="," close=")">#{id}</foreach>
</delete>
<delete id="deleteLinesByZone" parameterType="com.bms.price.domain.PayPostcodeGroup">
delete l from pay_postcode_line l
inner join pay_postcode_group g on g.group_id = l.group_id
<where>
<include refid="countryMatch"/>
and <include refid="zoneExpr"/> = #{zoneName}
</where>
</delete>
<update id="refreshLineCount">
update pay_postcode_group g
set g.line_count = (select count(*) from pay_postcode_line l where l.group_id = g.group_id)
where g.group_id = #{groupId}
</update>
<select id="selectLineList" parameterType="com.bms.price.domain.PayPostcodeLine" resultType="com.bms.price.domain.PayPostcodeLine">
select l.line_id as lineId, l.group_id as groupId, l.country_name as countryName, l.country_code as countryCode,
l.region_name as regionName, l.region_name_cn as regionNameCn, l.city_name as cityName, l.region_code as regionCode,
l.zone_name as zoneName, l.postcode, l.postcode_raw as postcodeRaw, l.postcode_end as postcodeEnd,
l.extra_text as extraText, l.sort_no as sortNo
from pay_postcode_line l
<where>
<if test="groupId != null">and l.group_id = #{groupId}</if>
<if test="postcode != null and postcode != ''">and l.postcode like concat('%', #{postcode}, '%')</if>
<if test="regionName != null and regionName != ''">and (l.region_name like concat('%', #{regionName}, '%') or l.region_name_cn like concat('%', #{regionName}, '%') or l.zone_name like concat('%', #{regionName}, '%') or l.city_name like concat('%', #{regionName}, '%'))</if>
<if test="zoneName != null and zoneName != ''">
and (
trim(l.zone_name) = #{zoneName}
or ((l.zone_name is null or trim(l.zone_name) = '') and trim(l.region_name) = #{zoneName})
or (
(l.zone_name is null or trim(l.zone_name) = '')
and (l.region_name is null or trim(l.region_name) = '')
and l.group_id in (select g.group_id from pay_postcode_group g where trim(g.block_title) = #{zoneName})
)
)
</if>
<if test="countryCode != null and countryCode != ''">
and l.group_id in (
select g.group_id from pay_postcode_group g where upper(trim(g.country_code)) = upper(trim(#{countryCode}))
)
</if>
<if test="(countryCode == null or countryCode == '') and countryName != null and countryName != ''">
and l.group_id in (
select g.group_id from pay_postcode_group g
where (g.country_code is null or trim(g.country_code) = '') and g.country_name = #{countryName}
)
</if>
</where>
order by l.sort_no asc, l.line_id asc
</select>
<insert id="insertGroup" parameterType="com.bms.price.domain.PayPostcodeGroup" useGeneratedKeys="true" keyProperty="groupId">
insert into pay_postcode_group (
source_file, file_md5, sheet_name, block_title, config_kind, coverage, channel_name, country_name, country_code,
service_type, catalog_country, product_name, quote_sheet,
fee_name, fee_text, line_count, create_by, create_time, remark
) values (
#{sourceFile}, #{fileMd5}, #{sheetName}, #{blockTitle}, #{configKind}, #{coverage}, #{channelName}, #{countryName}, #{countryCode},
#{serviceType}, #{catalogCountry}, #{productName}, #{quoteSheet},
#{feeName}, #{feeText}, #{lineCount}, #{createBy}, sysdate(), #{remark}
)
</insert>
<insert id="insertLines">
insert into pay_postcode_line (
group_id, country_name, country_code, region_name, region_name_cn, city_name, region_code,
zone_name, postcode, postcode_raw, postcode_end, extra_text, sort_no
) values
<foreach collection="list" item="item" separator=",">
(#{item.groupId}, #{item.countryName}, #{item.countryCode}, #{item.regionName}, #{item.regionNameCn},
#{item.cityName}, #{item.regionCode}, #{item.zoneName}, #{item.postcode}, #{item.postcodeRaw},
#{item.postcodeEnd}, #{item.extraText}, #{item.sortNo})
</foreach>
</insert>
<select id="selectGroupById" resultType="com.bms.price.domain.PayPostcodeGroup">
select group_id as groupId, source_file as sourceFile, file_md5 as fileMd5, sheet_name as sheetName,
block_title as blockTitle, config_kind as configKind, coverage, channel_name as channelName,
country_name as countryName, country_code as countryCode,
service_type as serviceType, catalog_country as catalogCountry, product_name as productName, quote_sheet as quoteSheet,
fee_name as feeName, fee_text as feeText, line_count as lineCount, create_by as createBy, create_time as createTime, remark
from pay_postcode_group
where group_id = #{groupId}
</select>
<update id="updateGroup" parameterType="com.bms.price.domain.PayPostcodeGroup">
update pay_postcode_group
set coverage = #{coverage},
channel_name = #{channelName},
country_name = #{countryName},
country_code = #{countryCode},
service_type = #{serviceType},
catalog_country = #{catalogCountry},
product_name = #{productName},
quote_sheet = #{quoteSheet},
config_kind = #{configKind},
fee_name = #{feeName},
fee_text = #{feeText},
block_title = #{blockTitle},
remark = #{remark}
where group_id = #{groupId}
</update>
<select id="selectGroupIds" resultType="long">
select group_id from pay_postcode_group where file_md5 = #{fileMd5} and sheet_name = #{sheetName}
</select>
<select id="selectGroupsForProduct" resultType="com.bms.price.domain.PayPostcodeGroup">
select group_id as groupId, block_title as blockTitle, channel_name as channelName,
product_name as productName, quote_sheet as quoteSheet, sheet_name as sheetName,
config_kind as configKind, coverage, fee_name as feeName, fee_text as feeText,
country_name as countryName, country_code as countryCode
from pay_postcode_group
where
<foreach collection="names" item="name" separator=" or ">
lower(quote_sheet) = lower(#{name})
or lower(product_name) = lower(#{name})
or lower(sheet_name) = lower(#{name})
</foreach>
</select>
<select id="selectRemoteGroupsByCountry" resultType="com.bms.price.domain.PayPostcodeGroup">
select group_id as groupId, block_title as blockTitle, channel_name as channelName,
product_name as productName, quote_sheet as quoteSheet, sheet_name as sheetName,
config_kind as configKind, coverage, fee_name as feeName, fee_text as feeText,
country_name as countryName, country_code as countryCode
from pay_postcode_group
where (
upper(ifnull(coverage, '')) = 'REMOTE'
or ifnull(fee_name, '') like '%偏远%'
or lower(ifnull(fee_name, '')) like '%remote%'
)
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(trim(country_code)) = upper(trim(#{countryCode}))
</when>
<when test="countryName != null and countryName != ''">
and trim(country_name) = trim(#{countryName})
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
</select>
<select id="selectGroupsByTokens" resultType="com.bms.price.domain.PayPostcodeGroup">
select group_id as groupId, block_title as blockTitle, channel_name as channelName,
product_name as productName, quote_sheet as quoteSheet, sheet_name as sheetName,
config_kind as configKind, fee_name as feeName, country_name as countryName, country_code as countryCode
from pay_postcode_group
where
<foreach collection="tokens" item="token" separator=" or ">
lower(concat_ws(' ', ifnull(channel_name, ''), ifnull(block_title, ''), ifnull(product_name, ''),
ifnull(quote_sheet, ''), ifnull(sheet_name, ''))) like concat('%', #{token}, '%')
</foreach>
</select>
<select id="selectRegionKeys" resultType="com.bms.price.domain.PayPostcodeLine">
select group_id as groupId, region_name as regionName, zone_name as zoneName
from pay_postcode_line
where group_id in
<foreach collection="groupIds" item="id" open="(" separator="," close=")">#{id}</foreach>
group by group_id, region_name, zone_name
</select>
<select id="selectLinesByGroups" resultType="com.bms.price.domain.PayPostcodeLine">
select line_id as lineId, group_id as groupId, country_name as countryName, country_code as countryCode,
region_name as regionName, zone_name as zoneName, postcode, postcode_end as postcodeEnd
from pay_postcode_line
where group_id in
<foreach collection="groupIds" item="id" open="(" separator="," close=")">#{id}</foreach>
</select>
<delete id="deleteLines">
delete from pay_postcode_line where group_id in
<foreach collection="groupIds" item="id" open="(" separator="," close=")">#{id}</foreach>
</delete>
<delete id="deleteGroups">
delete from pay_postcode_group where group_id in
<foreach collection="groupIds" item="id" open="(" separator="," close=")">#{id}</foreach>
</delete>
</mapper>