重构产品价和红线价功能

This commit is contained in:
wuweihua
2026-10-18 14:16:27 +08:00
parent db6f5e882a
commit 60d4614695
84 changed files with 6753 additions and 2843 deletions
@@ -6,7 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="PrcPriceSetDetail" id="PrcPriceSetDetailResult">
<id property="psdId" column="psd_id" />
<result property="priceSetId" column="price_set_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" />
@@ -24,6 +24,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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" />
@@ -31,40 +34,68 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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_set_id, psv_id, psp_id, product_code, product_name, country_code, country_name,
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,
discount_value, round_mode, pr_id, effective_date, expire_date, create_time, update_time
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_set_id, d.psv_id, d.psp_id, d.product_code, d.product_name, d.country_code, d.country_name,
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,
c.freight_price as base_freight_price,
c.registration_fee as base_registration_fee,
d.discount_value, d.round_mode, d.pr_id, d.effective_date, d.expire_date, d.create_time, d.update_time
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 product_country c on c.detail_id = d.product_country_id and ifnull(c.is_del, '0') = '0'
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>
<if test="priceSetId != null">
AND d.price_set_id = #{priceSetId}
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>
@@ -108,94 +139,88 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="countProductByPriceSetId" parameterType="Long" resultType="int">
select count(distinct product_code) from prc_price_set_detail where price_set_id = #{priceSetId}
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 where price_set_id = #{priceSetId}
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}
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>
<!-- FIXED: join active products + country by product_id only (avoid OR-join row explosion) -->
<insert id="insertFixedDetailsFromLibrary">
insert ignore into prc_price_set_detail (
price_set_id, psv_id, product_code, product_name,
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, round_mode,
effective_date, expire_date, create_time
fv_value, fv_registration_fee, size_limit, last_mile, lead_time, round_mode,
effective_date, expire_date, is_del, create_time
)
select
#{priceSetId},
'SALES',
#{psvId},
p.product_code,
p.product_name,
c.product_code,
c.product_name,
c.country_code,
c.country_name,
c.zone_id,
c.zone_code,
c.zone_name,
case
when c.weight_min is null and c.weight_max is null then null
else concat(
ifnull(trim(trailing '0' from trim(trailing '.' from cast(c.weight_min as char))), ''),
'&lt;W≤',
ifnull(trim(trailing '0' from trim(trailing '.' from cast(c.weight_max as char))), '')
)
end,
c.weight_label,
c.weight_min,
c.weight_max,
c.detail_id,
c.freight_price,
c.registration_fee,
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 product_country c
inner join product p on p.product_id = c.product_id
<where>
and p.status = '1'
and ifnull(p.is_del, '0') = '0'
and ifnull(c.is_del, '0') = '0'
and p.product_id = (
select max(p2.product_id) from product p2
where p2.product_code = p.product_code and p2.status = '1'
and ifnull(p2.is_del, '0') = '0'
)
and ifnull(c.status, '1') &lt;&gt; '2'
<choose>
<when test="openOnly">
and (c.effective_date is null or date(c.effective_date) &lt;= curdate())
and (c.expire_date is null or date(c.expire_date) &gt; curdate())
</when>
<otherwise>
and date(c.effective_date) &lt;= date(#{asOf})
and (c.expire_date is null or date(c.expire_date) &gt; date(#{asOf}))
</otherwise>
</choose>
</where>
order by p.product_code asc, c.country_name asc, c.zone_code asc, c.weight_min asc, c.detail_id asc
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,
null as price_set_id,
'SALES' as price_type,
null as psv_id,
null as psp_id,
p.product_code,
p.product_name,
c.product_code,
c.product_name,
c.country_code,
c.country_name,
c.zone_id,
@@ -203,19 +228,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
c.zone_name,
null as zd_id,
null as wsd_id,
case
when c.weight_min is null and c.weight_max is null then null
else concat(
ifnull(trim(trailing '0' from trim(trailing '.' from cast(c.weight_min as char))), ''),
'&lt;W≤',
ifnull(trim(trailing '0' from trim(trailing '.' from cast(c.weight_max as char))), '')
)
end as weight_label,
c.weight_label,
c.weight_min,
c.weight_max,
c.detail_id as product_country_id,
c.freight_price as fv_value,
c.registration_fee as fv_registration_fee,
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,
@@ -225,59 +246,51 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
c.expire_date,
null as create_time,
null as update_time
from product_country c
inner join product p on p.product_id = c.product_id
<where>
and p.status = '1'
and ifnull(p.is_del, '0') = '0'
and ifnull(c.is_del, '0') = '0'
and p.product_id = (
select max(p2.product_id) from product p2
where p2.product_code = p.product_code and p2.status = '1'
and ifnull(p2.is_del, '0') = '0'
)
and ifnull(c.status, '1') &lt;&gt; '2'
<choose>
<when test="openOnly">
and (c.effective_date is null or date(c.effective_date) &lt;= curdate())
and (c.expire_date is null or date(c.expire_date) &gt; curdate())
</when>
<otherwise>
and date(c.effective_date) &lt;= date(#{asOf})
and (c.expire_date is null or date(c.expire_date) &gt; date(#{asOf}))
</otherwise>
</choose>
</where>
order by p.product_code asc, c.country_name asc, c.zone_code asc, c.weight_min asc, c.detail_id asc
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_set_id, psv_id, product_code, product_name, round_mode, create_time
price_type, psv_id, product_code, product_name, round_mode, is_del, create_time
)
select
#{priceSetId},
'SALES',
#{psvId},
p.product_code,
p.product_name,
'HALF_UP',
'0',
sysdate()
from product p
<where>
and p.status = '1'
and ifnull(p.is_del, '0') = '0'
and p.product_id = (
select max(p2.product_id) from product p2
where p2.product_code = p.product_code and p2.status = '1'
and ifnull(p2.is_del, '0') = '0'
)
</where>
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="priceSetId != null">price_set_id,</if>
<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>
@@ -295,14 +308,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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="priceSetId != null">#{priceSetId},</if>
<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>
@@ -320,36 +337,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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_set_id, psv_id, psp_id, product_code, product_name,
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, discount_value, round_mode, pr_id,
effective_date, expire_date, create_time
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=",">
(
#{item.priceSetId}, #{item.psvId}, #{item.pspId}, #{item.productCode}, #{item.productName},
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.discountValue},
#{item.fvValue}, #{item.fvRegistrationFee}, #{item.sizeLimit}, #{item.lastMile}, #{item.leadTime},
#{item.discountValue},
ifnull(#{item.roundMode}, 'HALF_UP'), #{item.prId},
#{item.effectiveDate}, #{item.expireDate}, sysdate()
#{item.effectiveDate}, #{item.expireDate}, ifnull(#{item.isDel}, '0'), sysdate()
)
</foreach>
</insert>
<!-- Null means keep existing value (import empty freight/registration skips overwrite). -->
<update id="updateDetailPrices">
update prc_price_set_detail
<set>
@@ -363,6 +385,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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>
@@ -380,6 +403,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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},
@@ -390,31 +416,46 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where psd_id = #{psdId}
</update>
<delete id="deletePrcPriceSetDetailByIds" parameterType="Long">
delete from prc_price_set_detail where psd_id in
<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>
</delete>
</update>
<delete id="deletePrcPriceSetDetailByPriceSetId" parameterType="Long">
delete from prc_price_set_detail where price_set_id = #{priceSetId}
</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>
<delete id="deletePrcPriceSetDetailByPsvId" parameterType="Long">
<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>
<delete id="deleteOrphanDetailsByPriceSetId" parameterType="Long">
delete from prc_price_set_detail where price_set_id = #{priceSetId} and psv_id is null
</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 price_set_id = #{priceSetId}
<if test="psvId != null">
and psv_id = #{psvId}
</if>
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
and product_code = #{productCode}
<choose>
<when test="countryCode != null and countryCode != ''">
@@ -437,9 +478,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</choose>
and weight_min &lt;= #{weight}
and weight_max &gt;= #{weight}
order by
weight_min asc,
psd_id asc
order by weight_min asc, psd_id asc
limit 1
</select>
@@ -447,6 +486,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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>
@@ -466,6 +506,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select count(1)
from prc_price_set_detail
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
and product_code = #{productCode}
</select>
@@ -473,6 +514,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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 != ''">
@@ -497,10 +539,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectDiscountMatch" resultMap="PrcPriceSetDetailResult">
<include refid="selectPrcPriceSetDetailVo"/>
where price_set_id = #{priceSetId}
<if test="psvId != null">
and psv_id = #{psvId}
</if>
where psv_id = #{psvId}
and ifnull(is_del, '0') = '0'
and product_code = #{productCode}
order by psd_id asc
limit 1
@@ -508,19 +548,142 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="copyDetailsFromVersion">
insert into prc_price_set_detail (
price_set_id, psv_id, product_code, product_name, country_code, country_name,
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, discount_value, round_mode,
pr_id, effective_date, expire_date, create_time
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
price_set_id, #{newPsvId}, 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, discount_value, round_mode,
pr_id, effective_date, expire_date, sysdate()
from prc_price_set_detail
where psv_id = #{srcPsvId}
order by psd_id asc
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="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>