Files
BMS/bms-back/bms-system/src/main/resources/mapper/price/PrcPriceSetDetailMapper.xml
T
2026-11-02 09:00:38 +08:00

744 lines
32 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.PrcPriceSetDetailMapper">
<resultMap type="PrcPriceSetDetail" id="PrcPriceSetDetailResult">
<id property="psdId" column="psd_id" />
<result property="priceType" column="price_type" />
<result property="psvId" column="psv_id" />
<result property="pspId" column="psp_id" />
<result property="productCode" column="product_code" />
<result property="productName" column="product_name" />
<result property="countryCode" column="country_code" />
<result property="countryName" column="country_name" />
<result property="zoneId" column="zone_id" />
<result property="zoneCode" column="zone_code" />
<result property="zoneName" column="zone_name" />
<result property="zdId" column="zd_id" />
<result property="wsdId" column="wsd_id" />
<result property="weightLabel" column="weight_label" />
<result property="weightMin" column="weight_min" />
<result property="weightMax" column="weight_max" />
<result property="productCountryId" column="product_country_id" />
<result property="fvValue" column="fv_value" />
<result property="fvRegistrationFee" column="fv_registration_fee" />
<result property="sizeLimit" column="size_limit" />
<result property="lastMile" column="last_mile" />
<result property="leadTime" column="lead_time" />
<result property="baseFreightPrice" column="base_freight_price" />
<result property="baseRegistrationFee" column="base_registration_fee" />
<result property="discountValue" column="discount_value" />
<result property="roundMode" column="round_mode" />
<result property="prId" column="pr_id" />
<result property="effectiveDate" column="effective_date" />
<result property="expireDate" column="expire_date" />
<result property="isDel" column="is_del" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectPrcPriceSetDetailVo">
select psd_id, price_type, psv_id, psp_id, product_code, product_name, country_code, country_name,
zone_id, zone_code, zone_name,
zd_id, wsd_id, weight_label, weight_min, weight_max, product_country_id,
fv_value, fv_registration_fee, size_limit, last_mile, lead_time,
discount_value, round_mode, pr_id, effective_date, expire_date, is_del, create_time, update_time
from prc_price_set_detail
</sql>
<sql id="catalogVersionWindow">
and v.price_type = #{priceType}
and v.price_set_id is null
and v.effective_time is not null
and v.effective_time &lt;= #{bizDate}
and (v.expire_time is null or v.expire_time &gt; #{bizDate})
</sql>
<select id="selectPrcPriceSetDetailById" parameterType="Long" resultMap="PrcPriceSetDetailResult">
<include refid="selectPrcPriceSetDetailVo"/>
where psd_id = #{psdId}
and ifnull(is_del, '0') = '0'
</select>
<select id="selectPrcPriceSetDetailList" parameterType="PrcPriceSetDetail" resultMap="PrcPriceSetDetailResult">
select d.psd_id, d.price_type, d.psv_id, d.psp_id, d.product_code, d.product_name, d.country_code, d.country_name,
d.zone_id, d.zone_code, d.zone_name,
d.zd_id, d.wsd_id, d.weight_label, d.weight_min, d.weight_max, d.product_country_id,
d.fv_value, d.fv_registration_fee, d.size_limit, d.last_mile, d.lead_time,
bp.fv_value as base_freight_price,
bp.fv_registration_fee as base_registration_fee,
d.discount_value, d.round_mode, d.pr_id, d.effective_date, d.expire_date, d.is_del, d.create_time, d.update_time
from prc_price_set_detail d
left join prc_price_set_detail bp
on bp.price_type = 'PRODUCT'
and bp.product_code = d.product_code
and ifnull(bp.country_code,'') = ifnull(d.country_code,'')
and ifnull(bp.zone_code,'') = ifnull(d.zone_code,'')
and ifnull(bp.weight_min,-1) = ifnull(d.weight_min,-1)
and ifnull(bp.weight_max,-1) = ifnull(d.weight_max,-1)
and ifnull(bp.is_del, '0') = '0'
and bp.psv_id = (
select v.psv_id from prc_price_set_version v
where v.price_type = 'PRODUCT' and v.price_set_id is null and v.status = '1'
order by v.version_seq desc limit 1
)
<where>
and ifnull(d.is_del, '0') = '0'
<if test="priceType != null and priceType != ''">
AND d.price_type = #{priceType}
</if>
<if test="psvId != null">
AND d.psv_id = #{psvId}
</if>
<if test="pspId != null">
AND d.psp_id = #{pspId}
</if>
<if test="productCode != null and productCode != ''">
AND d.product_code = #{productCode}
</if>
<if test="countryCode != null and countryCode != ''">
AND d.country_code = #{countryCode}
</if>
<if test="zoneCode != null and zoneCode != ''">
AND d.zone_code = #{zoneCode}
</if>
<if test="productKeyword != null and productKeyword != ''">
AND (
d.product_code like concat('%', #{productKeyword}, '%')
or d.product_name like concat('%', #{productKeyword}, '%')
)
</if>
<if test="countryKeyword != null and countryKeyword != ''">
AND (
d.country_code like concat('%', #{countryKeyword}, '%')
or d.country_name like concat('%', #{countryKeyword}, '%')
)
</if>
<if test="zoneKeyword != null and zoneKeyword != ''">
AND (
d.zone_code like concat('%', #{zoneKeyword}, '%')
or d.zone_name like concat('%', #{zoneKeyword}, '%')
)
</if>
<if test="keyword != null and keyword != ''">
AND (
d.product_code like concat('%', #{keyword}, '%')
or d.product_name like concat('%', #{keyword}, '%')
or d.country_code like concat('%', #{keyword}, '%')
or d.country_name like concat('%', #{keyword}, '%')
or d.zone_code like concat('%', #{keyword}, '%')
or d.zone_name like concat('%', #{keyword}, '%')
or d.weight_label like concat('%', #{keyword}, '%')
)
</if>
</where>
order by d.psd_id asc
</select>
<select id="countProductByPriceSetId" parameterType="Long" resultType="int">
select count(distinct d.product_code)
from prc_price_set_detail d
inner join prc_price_set_version v on v.psv_id = d.psv_id
where v.price_set_id = #{priceSetId} and v.price_type = 'SALES'
and ifnull(d.is_del, '0') = '0'
</select>
<select id="countByPriceSetId" parameterType="Long" resultType="int">
select count(1)
from prc_price_set_detail d
inner join prc_price_set_version v on v.psv_id = d.psv_id
where v.price_set_id = #{priceSetId} and v.price_type = 'SALES'
and ifnull(d.is_del, '0') = '0'
</select>
<select id="countByPsvId" parameterType="Long" resultType="int">
select count(1) from prc_price_set_detail where psv_id = #{psvId} and ifnull(is_del, '0') = '0'
</select>
<select id="selectDetailOptionRows" resultMap="PrcPriceSetDetailResult">
select distinct product_code, product_name, country_code, country_name, zone_code, zone_name
from prc_price_set_detail
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
order by product_code, country_name, zone_code
</select>
<insert id="insertFixedDetailsFromLibrary">
insert ignore into prc_price_set_detail (
price_type, psv_id, product_code, product_name,
country_code, country_name, zone_id, zone_code, zone_name,
weight_label, weight_min, weight_max, product_country_id,
fv_value, fv_registration_fee, size_limit, last_mile, lead_time, round_mode,
effective_date, expire_date, is_del, create_time
)
select
'SALES',
#{psvId},
c.product_code,
c.product_name,
c.country_code,
c.country_name,
c.zone_id,
c.zone_code,
c.zone_name,
c.weight_label,
c.weight_min,
c.weight_max,
c.psd_id,
c.fv_value,
c.fv_registration_fee,
c.size_limit,
c.last_mile,
c.lead_time,
'HALF_UP',
c.effective_date,
c.expire_date,
'0',
sysdate()
from prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
where c.price_type = 'PRODUCT'
and ifnull(c.is_del, '0') = '0'
and v.price_type = 'PRODUCT'
and v.price_set_id is null
and v.status = '1'
and v.psv_id = (
select v2.psv_id from prc_price_set_version v2
where v2.price_type = 'PRODUCT' and v2.price_set_id is null and v2.status = '1'
order by v2.version_seq desc limit 1
)
order by c.product_code asc, c.country_name asc, c.zone_code asc, c.weight_min asc, c.psd_id asc
</insert>
<select id="selectFixedDetailsFromLibrary" resultMap="PrcPriceSetDetailResult">
select
null as psd_id,
'SALES' as price_type,
null as psv_id,
null as psp_id,
c.product_code,
c.product_name,
c.country_code,
c.country_name,
c.zone_id,
c.zone_code,
c.zone_name,
null as zd_id,
null as wsd_id,
c.weight_label,
c.weight_min,
c.weight_max,
c.psd_id as product_country_id,
c.fv_value,
c.fv_registration_fee,
c.size_limit,
c.last_mile,
c.lead_time,
null as base_freight_price,
null as base_registration_fee,
null as discount_value,
'HALF_UP' as round_mode,
null as pr_id,
c.effective_date,
c.expire_date,
null as create_time,
null as update_time
from prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
where c.price_type = 'PRODUCT'
and ifnull(c.is_del, '0') = '0'
and v.price_type = 'PRODUCT'
and v.price_set_id is null
and v.status = '1'
and v.psv_id = (
select v2.psv_id from prc_price_set_version v2
where v2.price_type = 'PRODUCT' and v2.price_set_id is null and v2.status = '1'
order by v2.version_seq desc limit 1
)
order by c.product_code asc, c.country_name asc, c.zone_code asc, c.weight_min asc, c.psd_id asc
</select>
<insert id="insertDiscountDetailsFromLibrary">
insert ignore into prc_price_set_detail (
price_type, psv_id, product_code, product_name, round_mode, is_del, create_time
)
select
'SALES',
#{psvId},
p.product_code,
p.product_name,
'HALF_UP',
'0',
sysdate()
from prc_price_set_product p
inner join prc_price_set_version v on v.psv_id = p.psv_id
where p.price_type = 'PRODUCT'
and ifnull(p.is_del, '0') = '0'
and v.price_type = 'PRODUCT'
and v.price_set_id is null
and v.status = '1'
and v.psv_id = (
select v2.psv_id from prc_price_set_version v2
where v2.price_type = 'PRODUCT' and v2.price_set_id is null and v2.status = '1'
order by v2.version_seq desc limit 1
)
order by p.product_code asc
</insert>
<insert id="insertPrcPriceSetDetail" parameterType="PrcPriceSetDetail" useGeneratedKeys="true" keyProperty="psdId">
insert into prc_price_set_detail (
<if test="priceType != null and priceType != ''">price_type,</if>
<if test="psvId != null">psv_id,</if>
<if test="pspId != null">psp_id,</if>
<if test="productCode != null and productCode != ''">product_code,</if>
<if test="productName != null">product_name,</if>
<if test="countryCode != null">country_code,</if>
<if test="countryName != null">country_name,</if>
<if test="zoneId != null">zone_id,</if>
<if test="zoneCode != null">zone_code,</if>
<if test="zoneName != null">zone_name,</if>
<if test="zdId != null">zd_id,</if>
<if test="wsdId != null">wsd_id,</if>
<if test="weightLabel != null">weight_label,</if>
<if test="weightMin != null">weight_min,</if>
<if test="weightMax != null">weight_max,</if>
<if test="productCountryId != null">product_country_id,</if>
<if test="fvValue != null">fv_value,</if>
<if test="fvRegistrationFee != null">fv_registration_fee,</if>
<if test="sizeLimit != null">size_limit,</if>
<if test="lastMile != null">last_mile,</if>
<if test="leadTime != null">lead_time,</if>
<if test="discountValue != null">discount_value,</if>
<if test="roundMode != null and roundMode != ''">round_mode,</if>
<if test="prId != null">pr_id,</if>
<if test="effectiveDate != null">effective_date,</if>
expire_date,
is_del,
create_time
) values (
<if test="priceType != null and priceType != ''">#{priceType},</if>
<if test="psvId != null">#{psvId},</if>
<if test="pspId != null">#{pspId},</if>
<if test="productCode != null and productCode != ''">#{productCode},</if>
<if test="productName != null">#{productName},</if>
<if test="countryCode != null">#{countryCode},</if>
<if test="countryName != null">#{countryName},</if>
<if test="zoneId != null">#{zoneId},</if>
<if test="zoneCode != null">#{zoneCode},</if>
<if test="zoneName != null">#{zoneName},</if>
<if test="zdId != null">#{zdId},</if>
<if test="wsdId != null">#{wsdId},</if>
<if test="weightLabel != null">#{weightLabel},</if>
<if test="weightMin != null">#{weightMin},</if>
<if test="weightMax != null">#{weightMax},</if>
<if test="productCountryId != null">#{productCountryId},</if>
<if test="fvValue != null">#{fvValue},</if>
<if test="fvRegistrationFee != null">#{fvRegistrationFee},</if>
<if test="sizeLimit != null">#{sizeLimit},</if>
<if test="lastMile != null">#{lastMile},</if>
<if test="leadTime != null">#{leadTime},</if>
<if test="discountValue != null">#{discountValue},</if>
<if test="roundMode != null and roundMode != ''">#{roundMode},</if>
<if test="prId != null">#{prId},</if>
<if test="effectiveDate != null">#{effectiveDate},</if>
#{expireDate},
ifnull(#{isDel}, '0'),
sysdate()
)
</insert>
<insert id="insertPrcPriceSetDetailBatch" useGeneratedKeys="true" keyProperty="psdId">
insert into prc_price_set_detail (
price_type, psv_id, psp_id, product_code, product_name,
country_code, country_name, zone_id, zone_code, zone_name,
zd_id, wsd_id, weight_label, weight_min, weight_max, product_country_id,
fv_value, fv_registration_fee, size_limit, last_mile, lead_time,
discount_value, round_mode, pr_id,
effective_date, expire_date, is_del, create_time
) values
<foreach collection="list" item="item" separator=",">
(
ifnull(#{item.priceType}, 'SALES'), #{item.psvId}, #{item.pspId}, #{item.productCode}, #{item.productName},
#{item.countryCode}, #{item.countryName}, #{item.zoneId}, #{item.zoneCode}, #{item.zoneName},
#{item.zdId}, #{item.wsdId}, #{item.weightLabel}, #{item.weightMin}, #{item.weightMax}, #{item.productCountryId},
#{item.fvValue}, #{item.fvRegistrationFee}, #{item.sizeLimit}, #{item.lastMile}, #{item.leadTime},
#{item.discountValue},
ifnull(#{item.roundMode}, 'HALF_UP'), #{item.prId},
#{item.effectiveDate}, #{item.expireDate}, ifnull(#{item.isDel}, '0'), sysdate()
)
</foreach>
</insert>
<update id="updateDetailPrices">
update prc_price_set_detail
<set>
<if test="fvValue != null">fv_value = #{fvValue},</if>
<if test="fvRegistrationFee != null">fv_registration_fee = #{fvRegistrationFee},</if>
update_time = sysdate()
</set>
where psd_id = #{psdId}
</update>
<update id="updatePrcPriceSetDetail" parameterType="PrcPriceSetDetail">
update prc_price_set_detail
<set>
<if test="priceType != null and priceType != ''">price_type = #{priceType},</if>
<if test="psvId != null">psv_id = #{psvId},</if>
<if test="pspId != null">psp_id = #{pspId},</if>
<if test="productCode != null and productCode != ''">product_code = #{productCode},</if>
<if test="productName != null">product_name = #{productName},</if>
country_code = #{countryCode},
country_name = #{countryName},
zone_id = #{zoneId},
zone_code = #{zoneCode},
zone_name = #{zoneName},
zd_id = #{zdId},
wsd_id = #{wsdId},
weight_label = #{weightLabel},
weight_min = #{weightMin},
weight_max = #{weightMax},
product_country_id = #{productCountryId},
fv_value = #{fvValue},
fv_registration_fee = #{fvRegistrationFee},
size_limit = #{sizeLimit},
last_mile = #{lastMile},
lead_time = #{leadTime},
discount_value = #{discountValue},
<if test="roundMode != null and roundMode != ''">round_mode = #{roundMode},</if>
pr_id = #{prId},
effective_date = #{effectiveDate},
expire_date = #{expireDate},
update_time = sysdate()
</set>
where psd_id = #{psdId}
</update>
<update id="deletePrcPriceSetDetailByIds" parameterType="Long">
update prc_price_set_detail
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and psd_id in
<foreach item="psdId" collection="array" open="(" separator="," close=")">
#{psdId}
</foreach>
</update>
<delete id="physicalDeleteByIds" parameterType="Long">
delete from prc_price_set_detail
where psd_id in
<foreach item="psdId" collection="array" open="(" separator="," close=")">
#{psdId}
</foreach>
</delete>
<update id="deletePrcPriceSetDetailByPriceSetId" parameterType="Long">
update prc_price_set_detail d
inner join prc_price_set_version v on v.psv_id = d.psv_id
set d.is_del = '1', d.update_time = sysdate()
where v.price_set_id = #{priceSetId} and v.price_type = 'SALES'
and ifnull(d.is_del, '0') = '0'
</update>
<update id="deletePrcPriceSetDetailByPsvId" parameterType="Long">
update prc_price_set_detail
set is_del = '1', update_time = sysdate()
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
</update>
<delete id="physicalDeleteByPsvId">
delete from prc_price_set_detail where psv_id = #{psvId}
</delete>
<update id="deleteOrphanDetailsByPriceSetId" parameterType="Long">
update prc_price_set_detail
set is_del = '1', update_time = sysdate()
where psv_id is null
and ifnull(is_del, '0') = '0'
</update>
<select id="selectFixedMatch" resultMap="PrcPriceSetDetailResult">
<include refid="selectPrcPriceSetDetailVo"/>
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
and product_code = #{productCode}
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(country_code,'')) = upper(#{countryCode})
</when>
<when test="countryName != null and countryName != ''">
and country_name = #{countryName}
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
<choose>
<when test="zoneCode != null and zoneCode != ''">
and upper(ifnull(zone_code,'')) = upper(#{zoneCode})
</when>
<otherwise>
and (zone_code is null or zone_code = '')
</otherwise>
</choose>
and weight_min &lt;= #{weight}
and weight_max &gt;= #{weight}
order by weight_min asc, psd_id asc
limit 1
</select>
<select id="selectFixedMinBand" resultMap="PrcPriceSetDetailResult">
<include refid="selectPrcPriceSetDetailVo"/>
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
and product_code = #{productCode}
and weight_min is not null
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(country_code,'')) = upper(#{countryCode})
</when>
<when test="countryName != null and countryName != ''">
and country_name = #{countryName}
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
<choose>
<when test="zoneCode != null and zoneCode != ''">
and upper(ifnull(zone_code,'')) = upper(#{zoneCode})
</when>
<otherwise>
and (zone_code is null or zone_code = '')
</otherwise>
</choose>
order by weight_min asc, psd_id asc
limit 1
</select>
<select id="countZonedByPsvProductCountry" resultType="int">
select count(1)
from prc_price_set_detail
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
and product_code = #{productCode}
and zone_code is not null and zone_code &lt;&gt; ''
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(country_code,'')) = upper(#{countryCode})
</when>
<when test="countryName != null and countryName != ''">
and country_name = #{countryName}
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
</select>
<select id="countByPsvProduct" resultType="int">
select count(1)
from prc_price_set_detail
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
and product_code = #{productCode}
</select>
<select id="countByPsvProductCountryZone" resultType="int">
select count(1)
from prc_price_set_detail
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
and product_code = #{productCode}
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(country_code,'')) = upper(#{countryCode})
</when>
<when test="countryName != null and countryName != ''">
and country_name = #{countryName}
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
<choose>
<when test="zoneCode != null and zoneCode != ''">
and upper(ifnull(zone_code,'')) = upper(#{zoneCode})
</when>
<otherwise>
and (zone_code is null or zone_code = '')
</otherwise>
</choose>
</select>
<select id="selectDiscountMatch" resultMap="PrcPriceSetDetailResult">
<include refid="selectPrcPriceSetDetailVo"/>
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
and product_code = #{productCode}
order by psd_id asc
limit 1
</select>
<insert id="copyDetailsFromVersion">
insert into prc_price_set_detail (
price_type, psv_id, product_code, product_name, country_code, country_name,
zone_id, zone_code, zone_name, zd_id, wsd_id, weight_label, weight_min, weight_max,
product_country_id, fv_value, fv_registration_fee, size_limit, last_mile, lead_time,
discount_value, round_mode, pr_id, effective_date, expire_date, status, is_del, create_time
)
select
d.price_type, #{newPsvId}, d.product_code, d.product_name, d.country_code, d.country_name,
d.zone_id, d.zone_code, d.zone_name, d.zd_id, d.wsd_id, d.weight_label, d.weight_min, d.weight_max,
d.product_country_id, d.fv_value, d.fv_registration_fee, d.size_limit, d.last_mile, d.lead_time,
d.discount_value, d.round_mode, d.pr_id, v.effective_time, v.expire_time, ifnull(v.status, '0'), '0', sysdate()
from prc_price_set_detail d
left join prc_price_set_version v on v.psv_id = #{newPsvId}
where d.psv_id = #{srcPsvId}
and ifnull(d.is_del, '0') = '0'
order by d.psd_id asc
</insert>
<update id="syncEffectByPriceType">
update prc_price_set_detail d
inner join prc_price_set_version v on v.psv_id = d.psv_id
set d.effective_date = v.effective_time,
d.expire_date = v.expire_time,
d.status = v.status,
d.update_time = sysdate()
where d.price_type = #{priceType}
and v.price_set_id is null
and (
not (d.status &lt;=&gt; v.status)
or not (d.effective_date &lt;=&gt; v.effective_time)
or not (d.expire_date &lt;=&gt; v.expire_time)
)
</update>
<update id="syncEffectByPriceSetId">
update prc_price_set_detail d
inner join prc_price_set_version v on v.psv_id = d.psv_id
set d.effective_date = v.effective_time,
d.expire_date = v.expire_time,
d.status = v.status,
d.update_time = sysdate()
where v.price_set_id = #{priceSetId}
and v.price_type = 'SALES'
and d.price_type = 'SALES'
and (
not (d.status &lt;=&gt; v.status)
or not (d.effective_date &lt;=&gt; v.effective_time)
or not (d.expire_date &lt;=&gt; v.expire_time)
)
</update>
<update id="updatePriceTypeByPsvId">
update prc_price_set_detail
set price_type = #{priceType}, update_time = sysdate()
where psv_id = #{psvId}
</update>
<select id="selectCatalogMatch" resultMap="PrcPriceSetDetailResult">
select d.psd_id, d.price_type, d.psv_id, d.psp_id, d.product_code, d.product_name,
d.country_code, d.country_name, d.zone_id, d.zone_code, d.zone_name,
d.zd_id, d.wsd_id, d.weight_label, d.weight_min, d.weight_max, d.product_country_id,
d.fv_value, d.fv_registration_fee, d.size_limit, d.last_mile, d.lead_time,
d.discount_value, d.round_mode, d.pr_id, d.effective_date, d.expire_date,
d.create_time, d.update_time
from prc_price_set_detail d
inner join prc_price_set_version v on v.psv_id = d.psv_id
where d.price_type = #{priceType}
and ifnull(d.is_del, '0') = '0'
and d.product_code = #{productCode}
<include refid="catalogVersionWindow"/>
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(d.country_code,'')) = upper(#{countryCode})
</when>
<when test="countryName != null and countryName != ''">
and d.country_name = #{countryName}
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
<choose>
<when test="zoneCode != null and zoneCode != ''">
and upper(ifnull(d.zone_code,'')) = upper(#{zoneCode})
</when>
<otherwise>
and (d.zone_code is null or d.zone_code = '')
</otherwise>
</choose>
and d.weight_min &lt;= #{weight}
and d.weight_max &gt;= #{weight}
order by v.effective_time desc, d.weight_min asc, d.psd_id asc
limit 1
</select>
<select id="countCatalogByProduct" resultType="int">
select count(1)
from prc_price_set_detail d
inner join prc_price_set_version v on v.psv_id = d.psv_id
where d.price_type = #{priceType}
and ifnull(d.is_del, '0') = '0'
and d.product_code = #{productCode}
<include refid="catalogVersionWindow"/>
</select>
<select id="countCatalogZonedByProductCountry" resultType="int">
select count(1)
from prc_price_set_detail d
inner join prc_price_set_version v on v.psv_id = d.psv_id
where d.price_type = #{priceType}
and ifnull(d.is_del, '0') = '0'
and d.product_code = #{productCode}
and d.zone_code is not null and d.zone_code &lt;&gt; ''
<include refid="catalogVersionWindow"/>
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(d.country_code,'')) = upper(#{countryCode})
</when>
<when test="countryName != null and countryName != ''">
and d.country_name = #{countryName}
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
</select>
<select id="countCatalogByProductCountryZone" resultType="int">
select count(1)
from prc_price_set_detail d
inner join prc_price_set_version v on v.psv_id = d.psv_id
where d.price_type = #{priceType}
and ifnull(d.is_del, '0') = '0'
and d.product_code = #{productCode}
<include refid="catalogVersionWindow"/>
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(d.country_code,'')) = upper(#{countryCode})
</when>
<when test="countryName != null and countryName != ''">
and d.country_name = #{countryName}
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
<choose>
<when test="zoneCode != null and zoneCode != ''">
and upper(ifnull(d.zone_code,'')) = upper(#{zoneCode})
</when>
<otherwise>
and (d.zone_code is null or d.zone_code = '')
</otherwise>
</choose>
</select>
</mapper>