重构产品价和红线价功能

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
@@ -29,21 +29,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="effectStatus" column="status" />
</resultMap>
<!-- Catalog country rows over prc_price_set_detail (price_type=PRODUCT); dates/status from version -->
<sql id="selectVo">
select c.detail_id, c.product_id, c.product_code, c.country_name, c.country_code,
select c.psd_id as detail_id, c.psp_id as product_id, c.product_code, c.country_name, c.country_code,
c.zone_id, c.zone_code, c.zone_name,
c.weight_min, c.weight_max,
c.freight_price, c.registration_fee, c.size_limit, c.last_mile, c.lead_time,
c.effective_date, c.expire_date, c.status, c.is_del, c.create_time, c.update_time
from product_country c
c.fv_value as freight_price, c.fv_registration_fee as registration_fee,
c.size_limit, c.last_mile, c.lead_time,
c.effective_date, c.expire_date, c.status,
ifnull(c.is_del, '0') as is_del, c.create_time, c.update_time
from prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
</sql>
<sql id="catalogBizWindow">
and v.price_set_id is null
<if test="bizDate != null">
and v.effective_time &lt;= #{bizDate}
and (v.expire_time is null or v.expire_time &gt; #{bizDate})
</if>
<if test="bizDate == null">
and v.expire_time is null
</if>
</sql>
<select id="selectBmsProductCountryList" parameterType="BmsProductCountry" resultMap="BmsProductCountryResult">
<include refid="selectVo"/>
<where>
and c.price_type = 'PRODUCT'
and ifnull(c.is_del, '0') = '0'
<if test="productId != null">
AND c.product_id = #{productId}
AND c.psp_id = #{productId}
</if>
<if test="productCode != null and productCode != ''">
AND c.product_code = #{productCode}
@@ -67,91 +83,118 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND c.weight_max = #{weightMax}
</if>
<if test="effectiveDate != null">
AND c.effective_date = #{effectiveDate}
AND v.effective_time = #{effectiveDate}
</if>
<if test="openOnly != null and openOnly">
AND c.expire_date is null
AND v.expire_time is null
</if>
<if test="status != null and status != ''">
AND c.status = #{status}
AND v.status = #{status}
</if>
<if test="effectStatus != null and effectStatus != ''">
AND c.status = #{effectStatus}
AND v.status = #{effectStatus}
</if>
</where>
order by c.effective_date desc, c.country_name asc, c.zone_code asc, c.weight_min asc, c.detail_id asc
order by v.effective_time desc, c.country_name asc, c.zone_code asc, c.weight_min asc, c.psd_id asc
</select>
<insert id="insertBmsProductCountry" parameterType="BmsProductCountry" useGeneratedKeys="true" keyProperty="detailId">
insert into product_country (
product_id, product_code, country_name, country_code, zone_id, zone_code, zone_name,
insert into prc_price_set_detail (
price_type, psv_id, psp_id, product_code, product_name,
country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max,
freight_price, registration_fee, size_limit, last_mile, lead_time,
fv_value, fv_registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, status, is_del, create_time
) values (
#{productId}, #{productCode}, #{countryName}, #{countryCode}, #{zoneId}, #{zoneCode}, #{zoneName},
'PRODUCT',
IFNULL(#{psvId}, (select psv_id from prc_price_set_product where psp_id = #{productId} and ifnull(is_del, '0') = '0')),
#{productId}, #{productCode}, #{productName},
#{countryName}, #{countryCode}, #{zoneId}, #{zoneCode}, #{zoneName},
#{weightMin}, #{weightMax},
#{freightPrice}, #{registrationFee}, #{sizeLimit}, #{lastMile}, #{leadTime},
#{effectiveDate}, #{expireDate}, IFNULL(#{status}, '0'), IFNULL(#{isDel}, '0'), sysdate()
#{effectiveDate}, #{expireDate}, ifnull(#{status}, '0'), ifnull(#{isDel}, '0'), sysdate()
)
</insert>
<insert id="insertBmsProductCountryBatch">
insert into prc_price_set_detail (
price_type, psv_id, psp_id, product_code, product_name,
country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max,
fv_value, fv_registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, status, is_del, create_time
) values
<foreach collection="list" item="item" separator=",">
(
'PRODUCT', #{item.psvId}, #{item.productId}, #{item.productCode}, #{item.productName},
#{item.countryName}, #{item.countryCode}, #{item.zoneId}, #{item.zoneCode}, #{item.zoneName},
#{item.weightMin}, #{item.weightMax},
#{item.freightPrice}, #{item.registrationFee}, #{item.sizeLimit}, #{item.lastMile}, #{item.leadTime},
#{item.effectiveDate}, #{item.expireDate}, ifnull(#{item.status}, '0'), ifnull(#{item.isDel}, '0'), sysdate()
)
</foreach>
</insert>
<!-- Detail edit dialog: frontend submits full editable fields;
weight_max / expire_date may be null (= open-ended) -->
weight_max may be null (= open-ended). Version dates are source of truth for list. -->
<update id="updateBmsProductCountry" parameterType="BmsProductCountry">
update product_country
set weight_min = #{weightMin},
weight_max = #{weightMax},
freight_price = #{freightPrice},
registration_fee = #{registrationFee},
size_limit = #{sizeLimit},
last_mile = #{lastMile},
lead_time = #{leadTime},
effective_date = #{effectiveDate},
expire_date = #{expireDate},
update_time = sysdate()
where detail_id = #{detailId}
update prc_price_set_detail
set weight_min = #{weightMin},
weight_max = #{weightMax},
fv_value = #{freightPrice},
fv_registration_fee = #{registrationFee},
size_limit = #{sizeLimit},
last_mile = #{lastMile},
lead_time = #{leadTime},
effective_date = #{effectiveDate},
expire_date = #{expireDate},
update_time = sysdate()
where psd_id = #{detailId}
and price_type = 'PRODUCT'
</update>
<update id="updateBmsProductCountryImport" parameterType="BmsProductCountry">
update product_country
set product_id = #{productId},
country_code = #{countryCode},
zone_id = #{zoneId},
zone_code = #{zoneCode},
zone_name = #{zoneName},
weight_min = #{weightMin},
weight_max = #{weightMax},
freight_price = #{freightPrice},
registration_fee = #{registrationFee},
size_limit = #{sizeLimit},
last_mile = #{lastMile},
lead_time = #{leadTime},
effective_date = #{effectiveDate},
expire_date = #{expireDate},
status = IFNULL(#{status}, status),
update_time = sysdate()
where detail_id = #{detailId}
update prc_price_set_detail
set psp_id = #{productId},
country_code = #{countryCode},
zone_id = #{zoneId},
zone_code = #{zoneCode},
zone_name = #{zoneName},
weight_min = #{weightMin},
weight_max = #{weightMax},
fv_value = #{freightPrice},
fv_registration_fee = #{registrationFee},
size_limit = #{sizeLimit},
last_mile = #{lastMile},
lead_time = #{leadTime},
effective_date = #{effectiveDate},
expire_date = #{expireDate},
update_time = sysdate()
where psd_id = #{detailId}
and price_type = 'PRODUCT'
</update>
<update id="deleteByProductId" parameterType="Long">
update product_country
<delete id="deleteByProductId" parameterType="Long">
update prc_price_set_detail
set is_del = '1', update_time = sysdate()
where product_id = #{productId}
where psp_id = #{productId}
and price_type = 'PRODUCT'
and ifnull(is_del, '0') = '0'
</update>
</delete>
<update id="deleteByProductCode" parameterType="String">
update product_country
<delete id="deleteByProductCode" parameterType="String">
update prc_price_set_detail
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and price_type = 'PRODUCT'
and ifnull(is_del, '0') = '0'
</update>
</delete>
<update id="deleteByProductCodes">
update product_country
update prc_price_set_detail
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
where price_type = 'PRODUCT'
and ifnull(is_del, '0') = '0'
and product_code in
<foreach item="code" collection="array" open="(" separator="," close=")">
#{code}
@@ -159,92 +202,78 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<update id="deleteByProductCodeAndEffectiveDate">
update product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
update prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
set c.is_del = '1', c.update_time = sysdate()
where c.product_code = #{productCode}
and c.price_type = 'PRODUCT'
and ifnull(c.is_del, '0') = '0'
and (
(#{effectiveDate} is null and effective_date is null)
or effective_date = #{effectiveDate}
(#{effectiveDate} is null and v.effective_time is null)
or v.effective_time = #{effectiveDate}
)
</update>
<select id="selectMaxOpenEffectiveDate" resultType="java.util.Date">
select max(effective_date) from product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
select max(v.effective_time)
from prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
where c.product_code = #{productCode}
and c.price_type = 'PRODUCT'
and ifnull(c.is_del, '0') = '0'
and v.price_set_id is null
and v.expire_time is null
</select>
<!-- Version-level expire is handled by BmsProductMapper; keep no-op for call sites -->
<update id="expireOpenByProductCode">
update product_country
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
update prc_price_set_version
set update_time = update_time
where 1 = 0
</update>
<update id="reopenExpiredByProductCodeAndExpireDate">
update product_country
set expire_date = null,
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date = #{expireDate}
update prc_price_set_version
set update_time = update_time
where 1 = 0
</update>
<update id="expireOpenByProductCodeAndCountry">
update product_country
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(country_code,'')) = upper(#{countryCode})
</when>
<otherwise>
and country_name = #{countryName}
</otherwise>
</choose>
update prc_price_set_version
set update_time = update_time
where 1 = 0
</update>
<update id="refreshStatusByDates">
update product_country
set status = case
when expire_date is not null and expire_date &lt;= now() then '2'
when effective_date is null or effective_date &gt; now() then '0'
else '1'
end
where ifnull(is_del, '0') = '0'
update prc_price_set_version
set update_time = update_time
where 1 = 0
</update>
<update id="deleteOpenByProductCodeAndEffectiveDate">
update product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
update prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
set c.is_del = '1', c.update_time = sysdate()
where c.product_code = #{productCode}
and c.price_type = 'PRODUCT'
and ifnull(c.is_del, '0') = '0'
and v.expire_time is null
and (
(#{effectiveDate} is null and effective_date is null)
or effective_date = #{effectiveDate}
(#{effectiveDate} is null and v.effective_time is null)
or v.effective_time = #{effectiveDate}
)
</update>
<update id="deleteOpenByProductCodeAndCountryOnDate">
update product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (
(#{effectiveDate} is null and effective_date is null)
or effective_date = #{effectiveDate}
)
<delete id="physicalDeleteByPspId">
delete from prc_price_set_detail
where psp_id = #{productId}
and price_type = 'PRODUCT'
</delete>
<delete id="physicalDeleteByPspIdAndCountry">
delete from prc_price_set_detail
where psp_id = #{productId}
and price_type = 'PRODUCT'
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(country_code,'')) = upper(#{countryCode})
@@ -253,14 +282,58 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and country_name = #{countryName}
</otherwise>
</choose>
</update>
</delete>
<!-- Draft/pending (status 0/3): hard-delete old details for product+country before re-import -->
<delete id="deleteOpenByProductCodeAndCountryOnDate">
delete c from prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
where c.product_code = #{productCode}
and c.price_type = 'PRODUCT'
and v.status in ('0', '3')
and (
(#{effectiveDate} is null and v.effective_time is null)
or v.effective_time = #{effectiveDate}
)
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(c.country_code,'')) = upper(#{countryCode})
</when>
<otherwise>
and c.country_name = #{countryName}
</otherwise>
</choose>
</delete>
<delete id="deleteSurchargeRelByProductCodeAndCountryOnDate">
delete r from prc_surcharge_rel r
inner join prc_price_set_detail c on c.psd_id = r.detail_id
inner join prc_price_set_version v on v.psv_id = c.psv_id
where c.product_code = #{productCode}
and c.price_type = 'PRODUCT'
and v.status in ('0', '3')
and (
(#{effectiveDate} is null and v.effective_time is null)
or v.effective_time = #{effectiveDate}
)
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(c.country_code,'')) = upper(#{countryCode})
</when>
<otherwise>
and c.country_name = #{countryName}
</otherwise>
</choose>
</delete>
<select id="selectMatchByProductCountryWeight" resultMap="BmsProductCountryResult">
<include refid="selectVo"/>
where c.product_code = #{productCode}
where c.price_type = 'PRODUCT'
and ifnull(c.is_del, '0') = '0'
and c.product_code = #{productCode}
and c.weight_min &lt;= #{weight}
and c.weight_max &gt;= #{weight}
<include refid="catalogBizWindow"/>
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(c.country_code) = upper(#{countryCode})
@@ -280,68 +353,56 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and (c.zone_code is null or c.zone_code = '')
</otherwise>
</choose>
<if test="bizDate != null">
and (c.effective_date is null or c.effective_date &lt;= #{bizDate})
and (c.expire_date is null or c.expire_date &gt; #{bizDate})
</if>
<if test="bizDate == null">
and c.expire_date is null
</if>
order by c.effective_date desc, c.weight_min asc, c.detail_id asc
order by v.effective_time desc, c.weight_min asc, c.psd_id asc
limit 1
</select>
<select id="countZonedByProductCountry" resultType="int">
select count(1)
from product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and zone_code is not null and zone_code &lt;&gt; ''
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 c.product_code = #{productCode}
and c.zone_code is not null and c.zone_code &lt;&gt; ''
<include refid="catalogBizWindow"/>
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(country_code) = upper(#{countryCode})
and upper(c.country_code) = upper(#{countryCode})
</when>
<when test="countryName != null and countryName != ''">
and country_name = #{countryName}
and c.country_name = #{countryName}
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
<if test="bizDate != null">
and (effective_date is null or effective_date &lt;= #{bizDate})
and (expire_date is null or expire_date &gt; #{bizDate})
</if>
<if test="bizDate == null">
and expire_date is null
</if>
</select>
<select id="countByProduct" resultType="int">
select count(1)
from product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
<if test="bizDate != null">
and (effective_date is null or effective_date &lt;= #{bizDate})
and (expire_date is null or expire_date &gt; #{bizDate})
</if>
<if test="bizDate == null">
and expire_date is null
</if>
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 c.product_code = #{productCode}
<include refid="catalogBizWindow"/>
</select>
<select id="countByProductCountryZone" resultType="int">
select count(1)
from product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
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 c.product_code = #{productCode}
<include refid="catalogBizWindow"/>
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(country_code) = upper(#{countryCode})
and upper(c.country_code) = upper(#{countryCode})
</when>
<when test="countryName != null and countryName != ''">
and country_name = #{countryName}
and c.country_name = #{countryName}
</when>
<otherwise>
and 1 = 0
@@ -349,45 +410,56 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</choose>
<choose>
<when test="zoneCode != null and zoneCode != ''">
and upper(ifnull(zone_code,'')) = upper(#{zoneCode})
and upper(ifnull(c.zone_code,'')) = upper(#{zoneCode})
</when>
<otherwise>
and (zone_code is null or zone_code = '')
and (c.zone_code is null or c.zone_code = '')
</otherwise>
</choose>
<if test="bizDate != null">
and (effective_date is null or effective_date &lt;= #{bizDate})
and (expire_date is null or expire_date &gt; #{bizDate})
</if>
<if test="bizDate == null">
and expire_date is null
</if>
</select>
<select id="selectOpenByProductCode" resultMap="BmsProductCountryResult">
<include refid="selectVo"/>
where c.product_code = #{productCode}
where c.price_type = 'PRODUCT'
and ifnull(c.is_del, '0') = '0'
and c.expire_date is null
order by c.country_name asc, c.zone_code asc, c.weight_min asc, c.detail_id asc
and c.product_code = #{productCode}
and v.price_set_id is null
and v.expire_time is null
order by c.country_name asc, c.zone_code asc, c.weight_min asc, c.psd_id asc
</select>
<!-- Copy from latest EFFECT PRODUCT version into target product (psp_id/psv_id) -->
<insert id="copyOpenCountries">
insert into product_country (
product_id, product_code, country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max, freight_price, registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, status, is_del, create_time
insert into prc_price_set_detail (
price_type, psv_id, psp_id, product_code, product_name,
country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max, fv_value, fv_registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, is_del, create_time
)
select
#{productId}, product_code, country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max, freight_price, registration_fee, size_limit, last_mile, lead_time,
#{effectiveDate}, null, IFNULL(#{status}, '0'), '0', sysdate()
from product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{effectiveDate})
order by detail_id asc
'PRODUCT',
(select psv_id from prc_price_set_product where psp_id = #{productId} and ifnull(is_del, '0') = '0'),
#{productId},
c.product_code, c.product_name,
c.country_name, c.country_code, c.zone_id, c.zone_code, c.zone_name,
c.weight_min, c.weight_max, c.fv_value, c.fv_registration_fee, c.size_limit, c.last_mile, c.lead_time,
#{effectiveDate}, null, '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 c.product_code = #{productCode}
and v.price_set_id is null
and v.status = '1'
and c.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, v2.psv_id desc
limit 1
)
and c.psv_id &lt;&gt; ifnull((select psv_id from prc_price_set_product where psp_id = #{productId} and ifnull(is_del, '0') = '0'), -1)
and (v.effective_time is null or v.effective_time &lt; #{effectiveDate})
order by c.psd_id asc
</insert>
</mapper>
@@ -6,6 +6,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="BmsProduct" id="BmsProductResult">
<id property="productId" column="product_id" />
<result property="psvId" column="psv_id" />
<result property="priceType" column="price_type" />
<result property="productCode" column="product_code" />
<result property="productName" column="product_name" />
<result property="serviceLevel" column="service_level" />
@@ -18,9 +20,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="status" column="status" />
<result property="isDel" column="is_del" />
<result property="sourceSheet" column="source_sheet" />
<result property="pefId" column="pef_id" />
<result property="remark" column="remark" />
<result property="tmsId" column="tms_id" />
<result property="createBy" column="created_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="updated_by" />
@@ -29,69 +28,110 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="surchargeCount" column="surcharge_count" />
</resultMap>
<sql id="latestProductPsv">
(
select v2.psv_id from prc_price_set_version v2
where v2.price_type = 'PRODUCT' and v2.price_set_id is null
order by case when v2.status = '1' then 0 when v2.status = '0' then 1 else 2 end,
v2.version_seq desc, v2.psv_id desc
limit 1
)
</sql>
<sql id="selectBmsProductVo">
select p.product_id, p.product_code, p.product_name, p.service_level, p.cargo_attr,
p.dest_region, p.update_note, p.tax_mode, p.effective_date, p.expire_date, p.status, p.is_del,
p.source_sheet, p.pef_id, p.remark, p.tms_id, p.created_by, p.create_time, p.updated_by, p.update_time,
(select count(distinct c.country_name) from product_country c
select p.psp_id as product_id, p.psv_id, p.price_type, p.product_code, p.product_name, p.service_level, p.cargo_attr,
p.dest_region, p.update_note, p.tax_mode,
p.effective_time as effective_date, p.expire_time as expire_date, p.status,
ifnull(p.is_del, '0') as is_del,
p.source_sheet, null as remark, null as tms_id,
v.created_by, p.create_time, v.updated_by, p.update_time,
(select count(distinct ifnull(c.country_code, c.country_name)) from prc_price_set_detail c
where ifnull(c.is_del, '0') = '0'
and (c.product_id = p.product_id
or (c.product_id is null and c.product_code = p.product_code
and (
(p.effective_date is null and c.effective_date is null)
or c.effective_date = p.effective_date
)))
and (c.psp_id = p.psp_id or (c.psv_id = p.psv_id and c.product_code = p.product_code))
) as country_count,
(select count(*) from prc_surcharge_rel r
inner join prc_surcharge s on s.sc_id = r.sc_id and ifnull(s.is_del, '0') = '0'
where ifnull(r.is_del, '0') = '0'
and r.product_id = p.product_id and r.price_type = 'PRODUCT') as surcharge_count
from product p
and r.product_id = p.psp_id and r.price_type = 'PRODUCT') as surcharge_count
from prc_price_set_product p
inner join prc_price_set_version v on v.psv_id = p.psv_id
</sql>
<select id="selectBmsProductById" parameterType="Long" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
where p.product_id = #{productId}
where p.psp_id = #{productId}
and p.price_type = 'PRODUCT'
and ifnull(p.is_del, '0') = '0'
</select>
<select id="selectBmsProductByCode" parameterType="String" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
where p.product_code = #{productCode}
and p.price_type = 'PRODUCT'
and ifnull(p.is_del, '0') = '0'
order by p.effective_date desc, p.product_id desc
and p.psv_id = <include refid="latestProductPsv"/>
limit 1
</select>
<select id="selectBmsProductByCodeAndDate" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
where p.product_code = #{productCode}
and p.price_type = 'PRODUCT'
and ifnull(p.is_del, '0') = '0'
<choose>
<when test="effectiveDate != null">
AND p.effective_date = #{effectiveDate}
AND v.effective_time = #{effectiveDate}
</when>
<otherwise>
AND p.effective_date is null
AND v.effective_time is null
</otherwise>
</choose>
limit 1
</select>
<select id="selectByCodeAndPsvId" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
where p.product_code = #{productCode}
and p.psv_id = #{psvId}
and p.price_type = 'PRODUCT'
and ifnull(p.is_del, '0') = '0'
limit 1
</select>
<select id="selectEffectiveBmsProductByCode" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
where p.product_code = #{productCode}
and p.price_type = 'PRODUCT'
and ifnull(p.is_del, '0') = '0'
and (p.effective_date is null or #{bizDate} is null or p.effective_date &lt;= #{bizDate})
and (p.expire_date is null or #{bizDate} is null or p.expire_date &gt; #{bizDate})
order by p.effective_date desc, p.product_id desc
and v.price_set_id is null
and (v.effective_time is null or #{bizDate} is null or v.effective_time &lt;= #{bizDate})
and (v.expire_time is null or #{bizDate} is null or v.expire_time &gt; #{bizDate})
order by v.effective_time desc, p.psp_id desc
limit 1
</select>
<select id="selectBmsProductList" parameterType="BmsProduct" resultMap="BmsProductResult">
<include refid="selectBmsProductVo"/>
<where>
and ifnull(p.is_del, '0') = '0'
and p.price_type = 'PRODUCT'
and ifnull(p.is_del, '0') = '0'
<choose>
<when test="psvId != null">
AND p.psv_id = #{psvId}
</when>
<when test="statusGroup != null and statusGroup == 'effect'">
AND v.price_set_id is null AND v.status = '1'
</when>
<when test="statusGroup != null and statusGroup == 'pending'">
AND v.price_set_id is null AND v.status in ('0', '3')
</when>
<when test="statusGroup != null and statusGroup == 'expired'">
AND v.status = '2'
</when>
<otherwise>
AND p.psv_id = <include refid="latestProductPsv"/>
</otherwise>
</choose>
<if test="productCode != null and productCode != ''">
AND p.product_code like concat('%', #{productCode}, '%')
</if>
@@ -102,21 +142,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND p.tax_mode = #{taxMode}
</if>
<if test="status != null and status != ''">
AND p.status = #{status}
AND v.status = #{status}
</if>
<if test="effectStatus != null and effectStatus != ''">
AND p.status = #{effectStatus}
AND v.status = #{effectStatus}
</if>
<if test="statusGroup != null and statusGroup == 'active'">
AND p.status in ('0', '1')
AND v.status in ('0', '1')
</if>
<if test="statusGroup != null and statusGroup == 'expired'">
AND p.status = '2'
<if test="params != null and params.beginTime != null and params.beginTime != ''">
AND p.expire_date &gt;= #{params.beginTime}
AND v.expire_time &gt;= #{params.beginTime}
</if>
<if test="params != null and params.endTime != null and params.endTime != ''">
AND p.expire_date &lt;= #{params.endTime}
AND v.expire_time &lt;= #{params.endTime}
</if>
</if>
<if test="cargoAttr != null and cargoAttr != ''">
@@ -129,56 +168,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
<choose>
<when test="statusGroup != null and statusGroup == 'expired'">
order by p.expire_date desc, p.product_code asc, p.product_id desc
order by v.expire_time desc, p.product_code asc, p.psp_id desc
</when>
<otherwise>
order by p.product_code asc, p.effective_date desc, p.product_id desc
order by p.product_code asc, p.psp_id desc
</otherwise>
</choose>
</select>
<insert id="insertBmsProduct" parameterType="BmsProduct" useGeneratedKeys="true" keyProperty="productId">
insert into product (
<if test="productCode != null and productCode != ''">product_code,</if>
<if test="productName != null and productName != ''">product_name,</if>
<if test="serviceLevel != null">service_level,</if>
<if test="cargoAttr != null">cargo_attr,</if>
<if test="destRegion != null">dest_region,</if>
<if test="updateNote != null">update_note,</if>
<if test="taxMode != null and taxMode != ''">tax_mode,</if>
<if test="effectiveDate != null">effective_date,</if>
<if test="expireDate != null">expire_date,</if>
<if test="status != null and status != ''">status,</if>
is_del,
<if test="sourceSheet != null">source_sheet,</if>
<if test="pefId != null">pef_id,</if>
<if test="remark != null">remark,</if>
<if test="tmsId != null">tms_id,</if>
<if test="createBy != null and createBy != ''">created_by,</if>
create_time
insert into prc_price_set_product (
price_type, psv_id, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, effective_time, expire_time, status, source_sheet, is_del, create_time
) values (
<if test="productCode != null and productCode != ''">#{productCode},</if>
<if test="productName != null and productName != ''">#{productName},</if>
<if test="serviceLevel != null">#{serviceLevel},</if>
<if test="cargoAttr != null">#{cargoAttr},</if>
<if test="destRegion != null">#{destRegion},</if>
<if test="updateNote != null">#{updateNote},</if>
<if test="taxMode != null and taxMode != ''">#{taxMode},</if>
<if test="effectiveDate != null">#{effectiveDate},</if>
<if test="expireDate != null">#{expireDate},</if>
<if test="status != null and status != ''">#{status},</if>
ifnull(#{isDel}, '0'),
<if test="sourceSheet != null">#{sourceSheet},</if>
<if test="pefId != null">#{pefId},</if>
<if test="remark != null">#{remark},</if>
<if test="tmsId != null">#{tmsId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
ifnull(#{priceType}, 'PRODUCT'), #{psvId}, #{productCode}, #{productName}, #{serviceLevel}, #{cargoAttr},
#{destRegion}, #{updateNote}, ifnull(#{taxMode}, 'TAX_INCLUDED'), #{effectiveDate}, #{expireDate},
ifnull(#{status}, '0'), #{sourceSheet},
ifnull(#{isDel}, '0'), sysdate()
)
</insert>
<update id="updateBmsProduct" parameterType="BmsProduct">
update product
update prc_price_set_product
<set>
<if test="productCode != null and productCode != ''">product_code = #{productCode},</if>
<if test="productName != null and productName != ''">product_name = #{productName},</if>
@@ -187,60 +198,57 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="destRegion != null">dest_region = #{destRegion},</if>
<if test="updateNote != null">update_note = #{updateNote},</if>
<if test="taxMode != null and taxMode != ''">tax_mode = #{taxMode},</if>
<if test="effectiveDate != null">effective_date = #{effectiveDate},</if>
expire_date = #{expireDate},
<if test="status != null and status != ''">effective_time = #{effectiveDate},</if>
<if test="status != null and status != ''">expire_time = #{expireDate},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="sourceSheet != null">source_sheet = #{sourceSheet},</if>
<if test="pefId != null">pef_id = #{pefId},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="tmsId != null">tms_id = #{tmsId},</if>
<if test="updateBy != null and updateBy != ''">updated_by = #{updateBy},</if>
update_time = sysdate()
</set>
where product_id = #{productId}
where psp_id = #{productId}
</update>
<update id="deleteBmsProductByIds" parameterType="Long">
update product
set is_del = '1',
update_time = sysdate()
where ifnull(is_del, '0') = '0'
and product_id in
update prc_price_set_product
set is_del = '1', update_time = sysdate()
where price_type = 'PRODUCT'
and ifnull(is_del, '0') = '0'
and psp_id in
<foreach item="productId" collection="array" open="(" separator="," close=")">
#{productId}
</foreach>
</update>
<!-- Version-level expire handled in CatalogVersionSupport; keep no-op updates for call sites -->
<update id="expireOpenByProductCode">
update product
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
<if test="excludeId != null">
and product_id &lt;&gt; #{excludeId}
</if>
update prc_price_set_version
set expire_time = #{newEffectiveDate}, status = '2', update_time = sysdate()
where price_type = 'PRODUCT'
and price_set_id is null
and status = '1'
and (expire_time is null)
and (effective_time is null or effective_time &lt; #{newEffectiveDate})
</update>
<update id="reopenExpiredByProductCodeAndExpireDate">
update product
set expire_date = null,
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date = #{expireDate}
update prc_price_set_version
set expire_time = null, status = '1', update_time = sysdate()
where price_type = 'PRODUCT'
and price_set_id is null
and expire_time = #{expireDate}
</update>
<update id="refreshStatusByDates">
update product
update prc_price_set_version
set status = case
when expire_date is not null and expire_date &lt;= now() then '2'
when effective_date is null or effective_date &gt; now() then '0'
when expire_time is not null and expire_time &lt;= now() then '2'
when effective_time is not null and effective_time &gt; now() then '3'
when effective_time is null then '0'
else '1'
end
where ifnull(is_del, '0') = '0'
end,
update_time = sysdate()
where price_type = 'PRODUCT'
and price_set_id is null
and status in ('0','1','2','3')
</update>
</mapper>
@@ -29,21 +29,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="effectStatus" column="status" />
</resultMap>
<!-- Catalog country rows over prc_price_set_detail (price_type=REDLINE); dates/status from version -->
<sql id="selectVo">
select c.detail_id, c.product_id, c.product_code, c.country_name, c.country_code,
select c.psd_id as detail_id, c.psp_id as product_id, c.product_code, c.country_name, c.country_code,
c.zone_id, c.zone_code, c.zone_name,
c.weight_min, c.weight_max,
c.freight_price, c.registration_fee, c.size_limit, c.last_mile, c.lead_time,
c.effective_date, c.expire_date, c.status, c.is_del, c.create_time, c.update_time
from redline_product_country c
c.fv_value as freight_price, c.fv_registration_fee as registration_fee,
c.size_limit, c.last_mile, c.lead_time,
c.effective_date, c.expire_date, c.status,
ifnull(c.is_del, '0') as is_del, c.create_time, c.update_time
from prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
</sql>
<sql id="catalogBizWindow">
and v.price_set_id is null
<if test="bizDate != null">
and v.effective_time &lt;= #{bizDate}
and (v.expire_time is null or v.expire_time &gt; #{bizDate})
</if>
<if test="bizDate == null">
and v.expire_time is null
</if>
</sql>
<select id="selectBmsRedlineProductCountryList" parameterType="BmsRedlineProductCountry" resultMap="BmsRedlineProductCountryResult">
<include refid="selectVo"/>
<where>
and c.price_type = 'REDLINE'
and ifnull(c.is_del, '0') = '0'
<if test="productId != null">
AND c.product_id = #{productId}
AND c.psp_id = #{productId}
</if>
<if test="productCode != null and productCode != ''">
AND c.product_code = #{productCode}
@@ -67,91 +83,118 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND c.weight_max = #{weightMax}
</if>
<if test="effectiveDate != null">
AND c.effective_date = #{effectiveDate}
AND v.effective_time = #{effectiveDate}
</if>
<if test="openOnly != null and openOnly">
AND c.expire_date is null
AND v.expire_time is null
</if>
<if test="status != null and status != ''">
AND c.status = #{status}
AND v.status = #{status}
</if>
<if test="effectStatus != null and effectStatus != ''">
AND c.status = #{effectStatus}
AND v.status = #{effectStatus}
</if>
</where>
order by c.effective_date desc, c.country_name asc, c.zone_code asc, c.weight_min asc, c.detail_id asc
order by v.effective_time desc, c.country_name asc, c.zone_code asc, c.weight_min asc, c.psd_id asc
</select>
<insert id="insertBmsRedlineProductCountry" parameterType="BmsRedlineProductCountry" useGeneratedKeys="true" keyProperty="detailId">
insert into redline_product_country (
product_id, product_code, country_name, country_code, zone_id, zone_code, zone_name,
insert into prc_price_set_detail (
price_type, psv_id, psp_id, product_code, product_name,
country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max,
freight_price, registration_fee, size_limit, last_mile, lead_time,
fv_value, fv_registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, status, is_del, create_time
) values (
#{productId}, #{productCode}, #{countryName}, #{countryCode}, #{zoneId}, #{zoneCode}, #{zoneName},
'REDLINE',
IFNULL(#{psvId}, (select psv_id from prc_price_set_product where psp_id = #{productId} and ifnull(is_del, '0') = '0')),
#{productId}, #{productCode}, #{productName},
#{countryName}, #{countryCode}, #{zoneId}, #{zoneCode}, #{zoneName},
#{weightMin}, #{weightMax},
#{freightPrice}, #{registrationFee}, #{sizeLimit}, #{lastMile}, #{leadTime},
#{effectiveDate}, #{expireDate}, IFNULL(#{status}, '0'), IFNULL(#{isDel}, '0'), sysdate()
#{effectiveDate}, #{expireDate}, ifnull(#{status}, '0'), ifnull(#{isDel}, '0'), sysdate()
)
</insert>
<insert id="insertBmsRedlineProductCountryBatch">
insert into prc_price_set_detail (
price_type, psv_id, psp_id, product_code, product_name,
country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max,
fv_value, fv_registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, status, is_del, create_time
) values
<foreach collection="list" item="item" separator=",">
(
'REDLINE', #{item.psvId}, #{item.productId}, #{item.productCode}, #{item.productName},
#{item.countryName}, #{item.countryCode}, #{item.zoneId}, #{item.zoneCode}, #{item.zoneName},
#{item.weightMin}, #{item.weightMax},
#{item.freightPrice}, #{item.registrationFee}, #{item.sizeLimit}, #{item.lastMile}, #{item.leadTime},
#{item.effectiveDate}, #{item.expireDate}, ifnull(#{item.status}, '0'), ifnull(#{item.isDel}, '0'), sysdate()
)
</foreach>
</insert>
<!-- Detail edit dialog: frontend submits full editable fields;
weight_max / expire_date may be null (= open-ended) -->
weight_max may be null (= open-ended). Version dates are source of truth for list. -->
<update id="updateBmsRedlineProductCountry" parameterType="BmsRedlineProductCountry">
update redline_product_country
set weight_min = #{weightMin},
weight_max = #{weightMax},
freight_price = #{freightPrice},
registration_fee = #{registrationFee},
size_limit = #{sizeLimit},
last_mile = #{lastMile},
lead_time = #{leadTime},
effective_date = #{effectiveDate},
expire_date = #{expireDate},
update_time = sysdate()
where detail_id = #{detailId}
update prc_price_set_detail
set weight_min = #{weightMin},
weight_max = #{weightMax},
fv_value = #{freightPrice},
fv_registration_fee = #{registrationFee},
size_limit = #{sizeLimit},
last_mile = #{lastMile},
lead_time = #{leadTime},
effective_date = #{effectiveDate},
expire_date = #{expireDate},
update_time = sysdate()
where psd_id = #{detailId}
and price_type = 'REDLINE'
</update>
<update id="updateBmsRedlineProductCountryImport" parameterType="BmsRedlineProductCountry">
update redline_product_country
set product_id = #{productId},
country_code = #{countryCode},
zone_id = #{zoneId},
zone_code = #{zoneCode},
zone_name = #{zoneName},
weight_min = #{weightMin},
weight_max = #{weightMax},
freight_price = #{freightPrice},
registration_fee = #{registrationFee},
size_limit = #{sizeLimit},
last_mile = #{lastMile},
lead_time = #{leadTime},
effective_date = #{effectiveDate},
expire_date = #{expireDate},
status = IFNULL(#{status}, status),
update_time = sysdate()
where detail_id = #{detailId}
update prc_price_set_detail
set psp_id = #{productId},
country_code = #{countryCode},
zone_id = #{zoneId},
zone_code = #{zoneCode},
zone_name = #{zoneName},
weight_min = #{weightMin},
weight_max = #{weightMax},
fv_value = #{freightPrice},
fv_registration_fee = #{registrationFee},
size_limit = #{sizeLimit},
last_mile = #{lastMile},
lead_time = #{leadTime},
effective_date = #{effectiveDate},
expire_date = #{expireDate},
update_time = sysdate()
where psd_id = #{detailId}
and price_type = 'REDLINE'
</update>
<update id="deleteByProductId" parameterType="Long">
update redline_product_country
<delete id="deleteByProductId" parameterType="Long">
update prc_price_set_detail
set is_del = '1', update_time = sysdate()
where product_id = #{productId}
where psp_id = #{productId}
and price_type = 'REDLINE'
and ifnull(is_del, '0') = '0'
</update>
</delete>
<update id="deleteByProductCode" parameterType="String">
update redline_product_country
<delete id="deleteByProductCode" parameterType="String">
update prc_price_set_detail
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and price_type = 'REDLINE'
and ifnull(is_del, '0') = '0'
</update>
</delete>
<update id="deleteByProductCodes">
update redline_product_country
update prc_price_set_detail
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
where price_type = 'REDLINE'
and ifnull(is_del, '0') = '0'
and product_code in
<foreach item="code" collection="array" open="(" separator="," close=")">
#{code}
@@ -159,92 +202,78 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<update id="deleteByProductCodeAndEffectiveDate">
update redline_product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
update prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
set c.is_del = '1', c.update_time = sysdate()
where c.product_code = #{productCode}
and c.price_type = 'REDLINE'
and ifnull(c.is_del, '0') = '0'
and (
(#{effectiveDate} is null and effective_date is null)
or effective_date = #{effectiveDate}
(#{effectiveDate} is null and v.effective_time is null)
or v.effective_time = #{effectiveDate}
)
</update>
<select id="selectMaxOpenEffectiveDate" resultType="java.util.Date">
select max(effective_date) from redline_product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
select max(v.effective_time)
from prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
where c.product_code = #{productCode}
and c.price_type = 'REDLINE'
and ifnull(c.is_del, '0') = '0'
and v.price_set_id is null
and v.expire_time is null
</select>
<!-- Version-level expire is handled by BmsRedlineProductMapper; keep no-op for call sites -->
<update id="reopenExpiredByProductCodeAndExpireDate">
update redline_product_country
set expire_date = null,
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date = #{expireDate}
update prc_price_set_version
set update_time = update_time
where 1 = 0
</update>
<update id="expireOpenByProductCode">
update redline_product_country
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
update prc_price_set_version
set update_time = update_time
where 1 = 0
</update>
<update id="expireOpenByProductCodeAndCountry">
update redline_product_country
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(country_code,'')) = upper(#{countryCode})
</when>
<otherwise>
and country_name = #{countryName}
</otherwise>
</choose>
update prc_price_set_version
set update_time = update_time
where 1 = 0
</update>
<update id="refreshStatusByDates">
update redline_product_country
set status = case
when expire_date is not null and expire_date &lt;= now() then '2'
when effective_date is null or effective_date &gt; now() then '0'
else '1'
end
where ifnull(is_del, '0') = '0'
update prc_price_set_version
set update_time = update_time
where 1 = 0
</update>
<update id="deleteOpenByProductCodeAndEffectiveDate">
update redline_product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
update prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
set c.is_del = '1', c.update_time = sysdate()
where c.product_code = #{productCode}
and c.price_type = 'REDLINE'
and ifnull(c.is_del, '0') = '0'
and v.expire_time is null
and (
(#{effectiveDate} is null and effective_date is null)
or effective_date = #{effectiveDate}
(#{effectiveDate} is null and v.effective_time is null)
or v.effective_time = #{effectiveDate}
)
</update>
<update id="deleteOpenByProductCodeAndCountryOnDate">
update redline_product_country
set is_del = '1', update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (
(#{effectiveDate} is null and effective_date is null)
or effective_date = #{effectiveDate}
)
<delete id="physicalDeleteByPspId">
delete from prc_price_set_detail
where psp_id = #{productId}
and price_type = 'REDLINE'
</delete>
<delete id="physicalDeleteByPspIdAndCountry">
delete from prc_price_set_detail
where psp_id = #{productId}
and price_type = 'REDLINE'
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(country_code,'')) = upper(#{countryCode})
@@ -253,14 +282,58 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and country_name = #{countryName}
</otherwise>
</choose>
</update>
</delete>
<!-- Draft/pending (status 0/3): hard-delete old details for product+country before re-import -->
<delete id="deleteOpenByProductCodeAndCountryOnDate">
delete c from prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
where c.product_code = #{productCode}
and c.price_type = 'REDLINE'
and v.status in ('0', '3')
and (
(#{effectiveDate} is null and v.effective_time is null)
or v.effective_time = #{effectiveDate}
)
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(c.country_code,'')) = upper(#{countryCode})
</when>
<otherwise>
and c.country_name = #{countryName}
</otherwise>
</choose>
</delete>
<delete id="deleteSurchargeRelByProductCodeAndCountryOnDate">
delete r from prc_surcharge_rel r
inner join prc_price_set_detail c on c.psd_id = r.detail_id
inner join prc_price_set_version v on v.psv_id = c.psv_id
where c.product_code = #{productCode}
and c.price_type = 'REDLINE'
and v.status in ('0', '3')
and (
(#{effectiveDate} is null and v.effective_time is null)
or v.effective_time = #{effectiveDate}
)
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(ifnull(c.country_code,'')) = upper(#{countryCode})
</when>
<otherwise>
and c.country_name = #{countryName}
</otherwise>
</choose>
</delete>
<select id="selectMatchByProductCountryWeight" resultMap="BmsRedlineProductCountryResult">
<include refid="selectVo"/>
where c.product_code = #{productCode}
where c.price_type = 'REDLINE'
and ifnull(c.is_del, '0') = '0'
and c.product_code = #{productCode}
and c.weight_min &lt;= #{weight}
and c.weight_max &gt;= #{weight}
<include refid="catalogBizWindow"/>
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(c.country_code) = upper(#{countryCode})
@@ -280,67 +353,74 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and (c.zone_code is null or c.zone_code = '')
</otherwise>
</choose>
<if test="bizDate != null">
and (c.effective_date is null or c.effective_date &lt;= #{bizDate})
and (c.expire_date is null or c.expire_date &gt; #{bizDate})
</if>
<if test="bizDate == null">
and c.expire_date is null
</if>
order by c.effective_date desc, c.weight_min asc, c.detail_id asc
order by v.effective_time desc, c.weight_min asc, c.psd_id asc
limit 1
</select>
<select id="countZonedByProductCountry" resultType="int">
select count(1)
from redline_product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and zone_code is not null and zone_code &lt;&gt; ''
from prc_price_set_detail c
inner join prc_price_set_version v on v.psv_id = c.psv_id
where c.price_type = 'REDLINE'
and ifnull(c.is_del, '0') = '0'
and c.product_code = #{productCode}
and c.zone_code is not null and c.zone_code &lt;&gt; ''
<include refid="catalogBizWindow"/>
<choose>
<when test="countryCode != null and countryCode != ''">
and upper(country_code) = upper(#{countryCode})
and upper(c.country_code) = upper(#{countryCode})
</when>
<when test="countryName != null and countryName != ''">
and country_name = #{countryName}
and c.country_name = #{countryName}
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
<if test="bizDate != null">
and (effective_date is null or effective_date &lt;= #{bizDate})
and (expire_date is null or expire_date &gt; #{bizDate})
</if>
<if test="bizDate == null">
and expire_date is null
</if>
</select>
<select id="selectOpenByProductCode" resultMap="BmsRedlineProductCountryResult">
<include refid="selectVo"/>
where c.product_code = #{productCode}
where c.price_type = 'REDLINE'
and ifnull(c.is_del, '0') = '0'
and c.expire_date is null
order by c.country_name asc, c.zone_code asc, c.weight_min asc, c.detail_id asc
and c.product_code = #{productCode}
and v.price_set_id is null
and v.expire_time is null
order by c.country_name asc, c.zone_code asc, c.weight_min asc, c.psd_id asc
</select>
<!-- Copy from latest EFFECT REDLINE version into target product (psp_id/psv_id) -->
<insert id="copyOpenCountries">
insert into redline_product_country (
product_id, product_code, country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max, freight_price, registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, status, is_del, create_time
insert into prc_price_set_detail (
price_type, psv_id, psp_id, product_code, product_name,
country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max, fv_value, fv_registration_fee, size_limit, last_mile, lead_time,
effective_date, expire_date, is_del, create_time
)
select
#{productId}, product_code, country_name, country_code, zone_id, zone_code, zone_name,
weight_min, weight_max, freight_price, registration_fee, size_limit, last_mile, lead_time,
#{effectiveDate}, null, IFNULL(#{status}, '0'), '0', sysdate()
from redline_product_country
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{effectiveDate})
order by detail_id asc
'REDLINE',
(select psv_id from prc_price_set_product where psp_id = #{productId} and ifnull(is_del, '0') = '0'),
#{productId},
c.product_code, c.product_name,
c.country_name, c.country_code, c.zone_id, c.zone_code, c.zone_name,
c.weight_min, c.weight_max, c.fv_value, c.fv_registration_fee, c.size_limit, c.last_mile, c.lead_time,
#{effectiveDate}, null, '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 = 'REDLINE'
and ifnull(c.is_del, '0') = '0'
and c.product_code = #{productCode}
and v.price_set_id is null
and v.status = '1'
and c.psv_id = (
select v2.psv_id from prc_price_set_version v2
where v2.price_type = 'REDLINE' and v2.price_set_id is null and v2.status = '1'
order by v2.version_seq desc, v2.psv_id desc
limit 1
)
and c.psv_id &lt;&gt; ifnull((select psv_id from prc_price_set_product where psp_id = #{productId} and ifnull(is_del, '0') = '0'), -1)
and (v.effective_time is null or v.effective_time &lt; #{effectiveDate})
order by c.psd_id asc
</insert>
</mapper>
@@ -6,6 +6,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="BmsRedlineProduct" id="BmsRedlineProductResult">
<id property="productId" column="product_id" />
<result property="psvId" column="psv_id" />
<result property="priceType" column="price_type" />
<result property="productCode" column="product_code" />
<result property="productName" column="product_name" />
<result property="serviceLevel" column="service_level" />
@@ -18,9 +20,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="status" column="status" />
<result property="isDel" column="is_del" />
<result property="sourceSheet" column="source_sheet" />
<result property="pefId" column="pef_id" />
<result property="remark" column="remark" />
<result property="tmsId" column="tms_id" />
<result property="createBy" column="created_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="updated_by" />
@@ -29,69 +28,110 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="surchargeCount" column="surcharge_count" />
</resultMap>
<sql id="latestRedlinePsv">
(
select v2.psv_id from prc_price_set_version v2
where v2.price_type = 'REDLINE' and v2.price_set_id is null
order by case when v2.status = '1' then 0 when v2.status = '0' then 1 else 2 end,
v2.version_seq desc, v2.psv_id desc
limit 1
)
</sql>
<sql id="selectBmsRedlineProductVo">
select p.product_id, p.product_code, p.product_name, p.service_level, p.cargo_attr,
p.dest_region, p.update_note, p.tax_mode, p.effective_date, p.expire_date, p.status, p.is_del,
p.source_sheet, p.pef_id, p.remark, p.tms_id, p.created_by, p.create_time, p.updated_by, p.update_time,
(select count(distinct c.country_name) from redline_product_country c
select p.psp_id as product_id, p.psv_id, p.price_type, p.product_code, p.product_name, p.service_level, p.cargo_attr,
p.dest_region, p.update_note, p.tax_mode,
p.effective_time as effective_date, p.expire_time as expire_date, p.status,
ifnull(p.is_del, '0') as is_del,
p.source_sheet, null as remark, null as tms_id,
v.created_by, p.create_time, v.updated_by, p.update_time,
(select count(distinct ifnull(c.country_code, c.country_name)) from prc_price_set_detail c
where ifnull(c.is_del, '0') = '0'
and (c.product_id = p.product_id
or (c.product_id is null and c.product_code = p.product_code
and (
(p.effective_date is null and c.effective_date is null)
or c.effective_date = p.effective_date
)))
and (c.psp_id = p.psp_id or (c.psv_id = p.psv_id and c.product_code = p.product_code))
) as country_count,
(select count(*) from prc_surcharge_rel r
inner join prc_surcharge s on s.sc_id = r.sc_id and ifnull(s.is_del, '0') = '0'
where ifnull(r.is_del, '0') = '0'
and r.product_id = p.product_id and r.price_type = 'REDLINE') as surcharge_count
from redline_product p
and r.product_id = p.psp_id and r.price_type = 'REDLINE') as surcharge_count
from prc_price_set_product p
inner join prc_price_set_version v on v.psv_id = p.psv_id
</sql>
<select id="selectBmsRedlineProductById" parameterType="Long" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
where p.product_id = #{productId}
where p.psp_id = #{productId}
and p.price_type = 'REDLINE'
and ifnull(p.is_del, '0') = '0'
</select>
<select id="selectBmsRedlineProductByCode" parameterType="String" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
where p.product_code = #{productCode}
and p.price_type = 'REDLINE'
and ifnull(p.is_del, '0') = '0'
order by p.effective_date desc, p.product_id desc
and p.psv_id = <include refid="latestRedlinePsv"/>
limit 1
</select>
<select id="selectBmsRedlineProductByCodeAndDate" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
where p.product_code = #{productCode}
and p.price_type = 'REDLINE'
and ifnull(p.is_del, '0') = '0'
<choose>
<when test="effectiveDate != null">
AND p.effective_date = #{effectiveDate}
AND v.effective_time = #{effectiveDate}
</when>
<otherwise>
AND p.effective_date is null
AND v.effective_time is null
</otherwise>
</choose>
limit 1
</select>
<select id="selectByCodeAndPsvId" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
where p.product_code = #{productCode}
and p.psv_id = #{psvId}
and p.price_type = 'REDLINE'
and ifnull(p.is_del, '0') = '0'
limit 1
</select>
<select id="selectEffectiveBmsRedlineProductByCode" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
where p.product_code = #{productCode}
and p.price_type = 'REDLINE'
and ifnull(p.is_del, '0') = '0'
and (p.effective_date is null or #{bizDate} is null or p.effective_date &lt;= #{bizDate})
and (p.expire_date is null or #{bizDate} is null or p.expire_date &gt; #{bizDate})
order by p.effective_date desc, p.product_id desc
and v.price_set_id is null
and (v.effective_time is null or #{bizDate} is null or v.effective_time &lt;= #{bizDate})
and (v.expire_time is null or #{bizDate} is null or v.expire_time &gt; #{bizDate})
order by v.effective_time desc, p.psp_id desc
limit 1
</select>
<select id="selectBmsRedlineProductList" parameterType="BmsRedlineProduct" resultMap="BmsRedlineProductResult">
<include refid="selectBmsRedlineProductVo"/>
<where>
and ifnull(p.is_del, '0') = '0'
and p.price_type = 'REDLINE'
and ifnull(p.is_del, '0') = '0'
<choose>
<when test="psvId != null">
AND p.psv_id = #{psvId}
</when>
<when test="statusGroup != null and statusGroup == 'effect'">
AND v.price_set_id is null AND v.status = '1'
</when>
<when test="statusGroup != null and statusGroup == 'pending'">
AND v.price_set_id is null AND v.status in ('0', '3')
</when>
<when test="statusGroup != null and statusGroup == 'expired'">
AND v.status = '2'
</when>
<otherwise>
AND p.psv_id = <include refid="latestRedlinePsv"/>
</otherwise>
</choose>
<if test="productCode != null and productCode != ''">
AND p.product_code like concat('%', #{productCode}, '%')
</if>
@@ -102,21 +142,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND p.tax_mode = #{taxMode}
</if>
<if test="status != null and status != ''">
AND p.status = #{status}
AND v.status = #{status}
</if>
<if test="effectStatus != null and effectStatus != ''">
AND p.status = #{effectStatus}
AND v.status = #{effectStatus}
</if>
<if test="statusGroup != null and statusGroup == 'active'">
AND p.status in ('0', '1')
AND v.status in ('0', '1')
</if>
<if test="statusGroup != null and statusGroup == 'expired'">
AND p.status = '2'
<if test="params != null and params.beginTime != null and params.beginTime != ''">
AND p.expire_date &gt;= #{params.beginTime}
AND v.expire_time &gt;= #{params.beginTime}
</if>
<if test="params != null and params.endTime != null and params.endTime != ''">
AND p.expire_date &lt;= #{params.endTime}
AND v.expire_time &lt;= #{params.endTime}
</if>
</if>
<if test="cargoAttr != null and cargoAttr != ''">
@@ -129,56 +168,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
<choose>
<when test="statusGroup != null and statusGroup == 'expired'">
order by p.expire_date desc, p.product_code asc, p.product_id desc
order by v.expire_time desc, p.product_code asc, p.psp_id desc
</when>
<otherwise>
order by p.product_code asc, p.effective_date desc, p.product_id desc
order by p.product_code asc, p.psp_id desc
</otherwise>
</choose>
</select>
<insert id="insertBmsRedlineProduct" parameterType="BmsRedlineProduct" useGeneratedKeys="true" keyProperty="productId">
insert into redline_product (
<if test="productCode != null and productCode != ''">product_code,</if>
<if test="productName != null and productName != ''">product_name,</if>
<if test="serviceLevel != null">service_level,</if>
<if test="cargoAttr != null">cargo_attr,</if>
<if test="destRegion != null">dest_region,</if>
<if test="updateNote != null">update_note,</if>
<if test="taxMode != null and taxMode != ''">tax_mode,</if>
<if test="effectiveDate != null">effective_date,</if>
<if test="expireDate != null">expire_date,</if>
<if test="status != null and status != ''">status,</if>
is_del,
<if test="sourceSheet != null">source_sheet,</if>
<if test="pefId != null">pef_id,</if>
<if test="remark != null">remark,</if>
<if test="tmsId != null">tms_id,</if>
<if test="createBy != null and createBy != ''">created_by,</if>
create_time
insert into prc_price_set_product (
price_type, psv_id, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, effective_time, expire_time, status, source_sheet, is_del, create_time
) values (
<if test="productCode != null and productCode != ''">#{productCode},</if>
<if test="productName != null and productName != ''">#{productName},</if>
<if test="serviceLevel != null">#{serviceLevel},</if>
<if test="cargoAttr != null">#{cargoAttr},</if>
<if test="destRegion != null">#{destRegion},</if>
<if test="updateNote != null">#{updateNote},</if>
<if test="taxMode != null and taxMode != ''">#{taxMode},</if>
<if test="effectiveDate != null">#{effectiveDate},</if>
<if test="expireDate != null">#{expireDate},</if>
<if test="status != null and status != ''">#{status},</if>
ifnull(#{isDel}, '0'),
<if test="sourceSheet != null">#{sourceSheet},</if>
<if test="pefId != null">#{pefId},</if>
<if test="remark != null">#{remark},</if>
<if test="tmsId != null">#{tmsId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
ifnull(#{priceType}, 'REDLINE'), #{psvId}, #{productCode}, #{productName}, #{serviceLevel}, #{cargoAttr},
#{destRegion}, #{updateNote}, ifnull(#{taxMode}, 'TAX_INCLUDED'), #{effectiveDate}, #{expireDate},
ifnull(#{status}, '0'), #{sourceSheet},
ifnull(#{isDel}, '0'), sysdate()
)
</insert>
<update id="updateBmsRedlineProduct" parameterType="BmsRedlineProduct">
update redline_product
update prc_price_set_product
<set>
<if test="productCode != null and productCode != ''">product_code = #{productCode},</if>
<if test="productName != null and productName != ''">product_name = #{productName},</if>
@@ -187,60 +198,57 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="destRegion != null">dest_region = #{destRegion},</if>
<if test="updateNote != null">update_note = #{updateNote},</if>
<if test="taxMode != null and taxMode != ''">tax_mode = #{taxMode},</if>
<if test="effectiveDate != null">effective_date = #{effectiveDate},</if>
expire_date = #{expireDate},
<if test="status != null and status != ''">effective_time = #{effectiveDate},</if>
<if test="status != null and status != ''">expire_time = #{expireDate},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="sourceSheet != null">source_sheet = #{sourceSheet},</if>
<if test="pefId != null">pef_id = #{pefId},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="tmsId != null">tms_id = #{tmsId},</if>
<if test="updateBy != null and updateBy != ''">updated_by = #{updateBy},</if>
update_time = sysdate()
</set>
where product_id = #{productId}
where psp_id = #{productId}
</update>
<update id="deleteBmsRedlineProductByIds" parameterType="Long">
update redline_product
set is_del = '1',
update_time = sysdate()
where ifnull(is_del, '0') = '0'
and product_id in
update prc_price_set_product
set is_del = '1', update_time = sysdate()
where price_type = 'REDLINE'
and ifnull(is_del, '0') = '0'
and psp_id in
<foreach item="productId" collection="array" open="(" separator="," close=")">
#{productId}
</foreach>
</update>
<update id="reopenExpiredByProductCodeAndExpireDate">
update redline_product
set expire_date = null,
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date = #{expireDate}
<!-- Version-level expire handled in CatalogVersionSupport; keep no-op updates for call sites -->
<update id="expireOpenByProductCode">
update prc_price_set_version
set expire_time = #{newEffectiveDate}, status = '2', update_time = sysdate()
where price_type = 'REDLINE'
and price_set_id is null
and status = '1'
and (expire_time is null)
and (effective_time is null or effective_time &lt; #{newEffectiveDate})
</update>
<update id="expireOpenByProductCode">
update redline_product
set expire_date = #{newEffectiveDate},
update_time = sysdate()
where product_code = #{productCode}
and ifnull(is_del, '0') = '0'
and expire_date is null
and (effective_date is null or effective_date &lt; #{newEffectiveDate})
<if test="excludeId != null">
and product_id &lt;&gt; #{excludeId}
</if>
<update id="reopenExpiredByProductCodeAndExpireDate">
update prc_price_set_version
set expire_time = null, status = '1', update_time = sysdate()
where price_type = 'REDLINE'
and price_set_id is null
and expire_time = #{expireDate}
</update>
<update id="refreshStatusByDates">
update redline_product
update prc_price_set_version
set status = case
when expire_date is not null and expire_date &lt;= now() then '2'
when effective_date is null or effective_date &gt; now() then '0'
when expire_time is not null and expire_time &lt;= now() then '2'
when effective_time is not null and effective_time &gt; now() then '3'
when effective_time is null then '0'
else '1'
end
where ifnull(is_del, '0') = '0'
end,
update_time = sysdate()
where price_type = 'REDLINE'
and price_set_id is null
and status in ('0','1','2','3')
</update>
</mapper>
@@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="PrcPriceExcelFile" id="PrcPriceExcelFileResult">
<id property="pefId" column="pef_id" />
<result property="excelType" column="excel_type" />
<result property="psvId" column="psv_id" />
<result property="effectiveTime" column="effective_time" />
<result property="fileName" column="file_name" />
<result property="filePath" column="file_path" />
@@ -23,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectPrcPriceExcelFileVo">
select pef_id, excel_type, effective_time, file_name, file_path, file_size, content_type,
select pef_id, excel_type, psv_id, effective_time, file_name, file_path, file_size, content_type,
file_extension, oss_id, sheet_names, remark, created_by, create_time, updated_by, update_time
from prc_price_excel_file
</sql>
@@ -39,6 +40,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="excelType != null and excelType != ''">
AND excel_type = #{excelType}
</if>
<if test="psvId != null">
AND psv_id = #{psvId}
</if>
<if test="fileName != null and fileName != ''">
AND file_name like concat('%', #{fileName}, '%')
</if>
@@ -46,20 +50,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by pef_id desc
</select>
<select id="selectByProductCode" resultMap="PrcPriceExcelFileResult">
select distinct f.pef_id, f.excel_type, f.effective_time, f.file_name, f.file_path, f.file_size,
f.content_type, f.file_extension, f.oss_id, f.sheet_names, f.remark,
f.created_by, f.create_time, f.updated_by, f.update_time
from prc_price_excel_file f
inner join product p on p.pef_id = f.pef_id and ifnull(p.is_del, '0') = '0'
where p.product_code = #{productCode}
and p.pef_id is not null
order by f.effective_time desc, f.pef_id desc
<select id="selectByPsvId" resultMap="PrcPriceExcelFileResult">
<include refid="selectPrcPriceExcelFileVo"/>
where psv_id = #{psvId}
order by effective_time desc, pef_id desc
</select>
<insert id="insertPrcPriceExcelFile" parameterType="PrcPriceExcelFile" useGeneratedKeys="true" keyProperty="pefId">
insert into prc_price_excel_file (
<if test="excelType != null and excelType != ''">excel_type,</if>
<if test="psvId != null">psv_id,</if>
<if test="effectiveTime != null">effective_time,</if>
<if test="fileName != null and fileName != ''">file_name,</if>
<if test="filePath != null and filePath != ''">file_path,</if>
@@ -73,6 +73,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
create_time
) values (
<if test="excelType != null and excelType != ''">#{excelType},</if>
<if test="psvId != null">#{psvId},</if>
<if test="effectiveTime != null">#{effectiveTime},</if>
<if test="fileName != null and fileName != ''">#{fileName},</if>
<if test="filePath != null and filePath != ''">#{filePath},</if>
@@ -91,6 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update prc_price_excel_file
<set>
<if test="excelType != null and excelType != ''">excel_type = #{excelType},</if>
<if test="psvId != null">psv_id = #{psvId},</if>
<if test="effectiveTime != null">effective_time = #{effectiveTime},</if>
<if test="fileName != null and fileName != ''">file_name = #{fileName},</if>
<if test="filePath != null and filePath != ''">file_path = #{filePath},</if>
@@ -113,27 +115,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</delete>
<select id="selectByRedlineProductCode" resultMap="PrcPriceExcelFileResult">
select distinct f.pef_id, f.excel_type, f.effective_time, f.file_name, f.file_path, f.file_size,
f.content_type, f.file_extension, f.oss_id, f.sheet_names, f.remark,
f.created_by, f.create_time, f.updated_by, f.update_time
from prc_price_excel_file f
inner join redline_product p on p.pef_id = f.pef_id and ifnull(p.is_del, '0') = '0'
where p.product_code = #{productCode}
and p.pef_id is not null
order by f.effective_time desc, f.pef_id desc
</select>
<select id="selectByPsvId" resultMap="PrcPriceExcelFileResult">
select distinct f.pef_id, f.excel_type, f.effective_time, f.file_name, f.file_path, f.file_size,
f.content_type, f.file_extension, f.oss_id, f.sheet_names, f.remark,
f.created_by, f.create_time, f.updated_by, f.update_time
from prc_price_excel_file f
inner join prc_price_set_product psp on psp.pef_id = f.pef_id
where psp.psv_id = #{psvId}
and psp.pef_id is not null
order by f.effective_time desc, f.pef_id desc
</select>
<delete id="physicalDeleteByPsvId">
delete from prc_price_excel_file where psv_id = #{psvId}
</delete>
</mapper>
@@ -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>
@@ -28,7 +28,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
s.set_type, s.default_discount, s.default_type, s.calculate_sign,
s.status, s.tms_id,
s.created_by, s.create_time, s.updated_by, s.update_time,
(select count(distinct p.product_code) from prc_price_set_product p where p.price_set_id = s.price_set_id) as product_count,
(select count(distinct p.product_code)
from prc_price_set_product p
inner join prc_price_set_version v on v.psv_id = p.psv_id
where v.price_set_id = s.price_set_id
and ifnull(p.is_del, '0') = '0') as product_count,
(select count(1) from prc_customer_price_set c where c.price_set_id = s.price_set_id) as customer_count
from prc_price_set s
</sql>
@@ -6,7 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="PrcPriceSetProduct" id="PrcPriceSetProductResult">
<id property="pspId" column="psp_id" />
<result property="priceSetId" column="price_set_id" />
<result property="priceType" column="price_type" />
<result property="psvId" column="psv_id" />
<result property="productCode" column="product_code" />
<result property="productName" column="product_name" />
@@ -15,29 +15,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="destRegion" column="dest_region" />
<result property="updateNote" column="update_note" />
<result property="taxMode" column="tax_mode" />
<result property="effectiveTime" column="effective_time" />
<result property="expireTime" column="expire_time" />
<result property="status" column="status" />
<result property="sourceProductId" column="source_product_id" />
<result property="sourceSheet" column="source_sheet" />
<result property="pefId" column="pef_id" />
<result property="isDel" column="is_del" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectVo">
select psp_id, price_set_id, psv_id, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, source_product_id, source_sheet, pef_id,
create_time, update_time
select psp_id, price_type, psv_id, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, effective_time, expire_time, status,
source_product_id, source_sheet, is_del, create_time, update_time
from prc_price_set_product
</sql>
<select id="selectPrcPriceSetProductById" parameterType="Long" resultMap="PrcPriceSetProductResult">
<include refid="selectVo"/>
where psp_id = #{pspId}
and ifnull(is_del, '0') = '0'
</select>
<select id="selectPrcPriceSetProductList" parameterType="PrcPriceSetProduct" resultMap="PrcPriceSetProductResult">
<include refid="selectVo"/>
<where>
<if test="priceSetId != null">AND price_set_id = #{priceSetId}</if>
and ifnull(is_del, '0') = '0'
<if test="priceType != null and priceType != ''">AND price_type = #{priceType}</if>
<if test="psvId != null">AND psv_id = #{psvId}</if>
<if test="productCode != null and productCode != ''">AND product_code = #{productCode}</if>
</where>
@@ -48,22 +54,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectVo"/>
where psv_id = #{psvId}
and product_code = #{productCode}
and ifnull(is_del, '0') = '0'
limit 1
</select>
<insert id="insertPrcPriceSetProduct" parameterType="PrcPriceSetProduct" useGeneratedKeys="true" keyProperty="pspId">
insert into prc_price_set_product (
price_set_id, psv_id, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, source_product_id, source_sheet, pef_id, create_time
price_type, psv_id, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, source_product_id, source_sheet, is_del, create_time
) values (
#{priceSetId}, #{psvId}, #{productCode}, #{productName}, #{serviceLevel}, #{cargoAttr},
#{destRegion}, #{updateNote}, #{taxMode}, #{sourceProductId}, #{sourceSheet}, #{pefId}, sysdate()
#{priceType}, #{psvId}, #{productCode}, #{productName}, #{serviceLevel}, #{cargoAttr},
#{destRegion}, #{updateNote}, #{taxMode}, #{sourceProductId}, #{sourceSheet},
ifnull(#{isDel}, '0'), sysdate()
)
</insert>
<update id="updatePrcPriceSetProduct" parameterType="PrcPriceSetProduct">
update prc_price_set_product
<set>
<if test="priceType != null and priceType != ''">price_type = #{priceType},</if>
<if test="productName != null">product_name = #{productName},</if>
<if test="serviceLevel != null">service_level = #{serviceLevel},</if>
<if test="cargoAttr != null">cargo_attr = #{cargoAttr},</if>
@@ -72,42 +81,54 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="taxMode != null and taxMode != ''">tax_mode = #{taxMode},</if>
<if test="sourceProductId != null">source_product_id = #{sourceProductId},</if>
<if test="sourceSheet != null">source_sheet = #{sourceSheet},</if>
<if test="pefId != null">pef_id = #{pefId},</if>
update_time = sysdate()
</set>
where psp_id = #{pspId}
</update>
<delete id="deleteByPsvId">
<update id="deleteByPsvId">
update prc_price_set_product
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_product where psv_id = #{psvId}
</delete>
<delete id="deleteByPsvIdAndCode">
delete from prc_price_set_product
<update id="deleteByPsvIdAndCode">
update prc_price_set_product
set is_del = '1', update_time = sysdate()
where psv_id = #{psvId}
and product_code = #{productCode}
</delete>
and ifnull(is_del, '0') = '0'
</update>
<insert id="copyFromVersion">
insert into prc_price_set_product (
price_set_id, psv_id, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, source_product_id, source_sheet, pef_id, create_time
price_type, psv_id, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, effective_time, expire_time, status,
source_product_id, source_sheet, is_del, create_time
)
select
price_set_id, #{newPsvId}, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, source_product_id, source_sheet, pef_id, sysdate()
from prc_price_set_product
where psv_id = #{srcPsvId}
order by psp_id asc
p.price_type, #{newPsvId}, p.product_code, p.product_name, p.service_level, p.cargo_attr,
p.dest_region, p.update_note, p.tax_mode, v.effective_time, v.expire_time, v.status,
p.source_product_id, p.source_sheet, '0', sysdate()
from prc_price_set_product p
left join prc_price_set_version v on v.psv_id = #{newPsvId}
where p.psv_id = #{srcPsvId}
and ifnull(p.is_del, '0') = '0'
order by p.psp_id asc
</insert>
<insert id="insertFromLibrary">
insert ignore into prc_price_set_product (
price_set_id, psv_id, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, source_product_id, source_sheet, create_time
price_type, psv_id, product_code, product_name, service_level, cargo_attr,
dest_region, update_note, tax_mode, source_product_id, source_sheet, is_del, create_time
)
select
#{priceSetId},
'SALES',
#{psvId},
p.product_code,
p.product_name,
@@ -116,16 +137,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
p.dest_region,
p.update_note,
ifnull(p.tax_mode, 'TAX_INCLUDED'),
p.product_id,
p.psp_id,
p.source_sheet,
'0',
sysdate()
from product p
where p.status = '1'
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 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 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, v2.psv_id desc
limit 1
)
order by p.product_code asc
</insert>
@@ -133,7 +160,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectFromLibrary" resultMap="PrcPriceSetProductResult">
select
null as psp_id,
null as price_set_id,
'SALES' as price_type,
null as psv_id,
p.product_code,
p.product_name,
@@ -142,17 +169,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
p.dest_region,
p.update_note,
ifnull(p.tax_mode, 'TAX_INCLUDED') as tax_mode,
p.product_id as source_product_id,
p.psp_id as source_product_id,
p.source_sheet,
null as create_time,
null as update_time
from product p
where p.status = '1'
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 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 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, v2.psv_id desc
limit 1
)
order by p.product_code asc
</select>
@@ -163,19 +195,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
on sp.psv_id = d.psv_id and sp.product_code = d.product_code
set d.psp_id = sp.psp_id
where d.psv_id = #{psvId}
and ifnull(d.is_del, '0') = '0'
and ifnull(sp.is_del, '0') = '0'
and (d.psp_id is null or d.psp_id &lt;&gt; sp.psp_id)
</update>
<update id="updatePefIdByPsvId">
<update id="updatePriceTypeByPsvId">
update prc_price_set_product
set pef_id = #{pefId}, update_time = sysdate()
set price_type = #{priceType}, update_time = sysdate()
where psv_id = #{psvId}
<if test="productCodes != null and productCodes.size() &gt; 0">
and product_code in
<foreach item="code" collection="productCodes" open="(" separator="," close=")">
#{code}
</foreach>
</if>
</update>
<update id="syncEffectByPriceType">
update prc_price_set_product p
inner join prc_price_set_version v on v.psv_id = p.psv_id
set p.effective_time = v.effective_time,
p.expire_time = v.expire_time,
p.status = v.status,
p.update_time = sysdate()
where p.price_type = #{priceType}
and v.price_set_id is null
and (
not (p.status &lt;=&gt; v.status)
or not (p.effective_time &lt;=&gt; v.effective_time)
or not (p.expire_time &lt;=&gt; v.expire_time)
)
</update>
</mapper>
@@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="PrcPriceSetVersion" id="PrcPriceSetVersionResult">
<id property="psvId" column="psv_id" />
<result property="priceSetId" column="price_set_id" />
<result property="priceType" column="price_type" />
<result property="versionNo" column="version_no" />
<result property="versionSeq" column="version_seq" />
<result property="effectiveTime" column="effective_time" />
@@ -17,10 +18,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" />
<result property="updateBy" column="updated_by" />
<result property="updateTime" column="update_time" />
<result property="productCount" column="product_count" />
<result property="detailCount" column="detail_count" />
</resultMap>
<sql id="selectPrcPriceSetVersionVo">
select psv_id, price_set_id, version_no, version_seq, effective_time, expire_time, status,
select psv_id, price_set_id, price_type, version_no, version_seq, effective_time, expire_time, status,
price_build_mode, created_by, create_time, updated_by, update_time
from prc_price_set_version
</sql>
@@ -36,6 +39,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="priceSetId != null">
AND price_set_id = #{priceSetId}
</if>
<if test="priceSetId == null and priceType != null and priceType != '' and priceType != 'SALES'">
AND price_set_id is null
</if>
<if test="priceType != null and priceType != ''">
AND price_type = #{priceType}
</if>
<if test="versionNo != null and versionNo != ''">
AND version_no = #{versionNo}
</if>
@@ -46,13 +55,56 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by version_seq desc
</select>
<select id="selectCatalogVersionList" parameterType="PrcPriceSetVersion" resultMap="PrcPriceSetVersionResult">
select v.psv_id, v.price_set_id, v.price_type, v.version_no, v.version_seq,
v.effective_time, v.expire_time, v.status, v.price_build_mode,
v.created_by, v.create_time, v.updated_by, v.update_time,
(select count(1) from prc_price_set_product p
where p.psv_id = v.psv_id and ifnull(p.is_del, '0') = '0') as product_count,
(select count(1) from prc_price_set_detail d
where d.psv_id = v.psv_id and ifnull(d.is_del, '0') = '0') as detail_count
from prc_price_set_version v
where v.price_set_id is null
and v.price_type = #{priceType}
<choose>
<when test="statusGroup != null and statusGroup == 'pending'">
and v.status in ('0', '3')
</when>
<when test="statusGroup != null and statusGroup == 'expired'">
and v.status = '2'
</when>
<when test="statusGroup != null and statusGroup == 'effect'">
and v.status = '1'
</when>
<when test="status != null and status != ''">
and v.status = #{status}
</when>
</choose>
order by v.version_seq desc, v.psv_id desc
</select>
<select id="selectMaxVersionSeq" resultType="java.lang.Integer">
select max(version_seq) from prc_price_set_version where price_set_id = #{priceSetId}
select max(version_seq) from prc_price_set_version
where price_type = 'SALES' and price_set_id = #{priceSetId}
</select>
<select id="selectMaxVersionSeqByType" resultType="java.lang.Integer">
select max(version_seq) from prc_price_set_version
where price_type = #{priceType}
<choose>
<when test="priceSetId != null">
and price_set_id = #{priceSetId}
</when>
<otherwise>
and price_set_id is null
</otherwise>
</choose>
</select>
<insert id="insertPrcPriceSetVersion" parameterType="PrcPriceSetVersion" useGeneratedKeys="true" keyProperty="psvId">
insert into prc_price_set_version (
<if test="priceSetId != null">price_set_id,</if>
<if test="priceType != null and priceType != ''">price_type,</if>
<if test="versionNo != null and versionNo != ''">version_no,</if>
<if test="versionSeq != null">version_seq,</if>
<if test="effectiveTime != null">effective_time,</if>
@@ -63,6 +115,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
create_time
) values (
<if test="priceSetId != null">#{priceSetId},</if>
<if test="priceType != null and priceType != ''">#{priceType},</if>
<if test="versionNo != null and versionNo != ''">#{versionNo},</if>
<if test="versionSeq != null">#{versionSeq},</if>
<if test="effectiveTime != null">#{effectiveTime},</if>
@@ -77,6 +130,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updatePrcPriceSetVersion" parameterType="PrcPriceSetVersion">
update prc_price_set_version
<set>
<if test="priceType != null and priceType != ''">price_type = #{priceType},</if>
<if test="versionNo != null and versionNo != ''">version_no = #{versionNo},</if>
<if test="versionSeq != null">version_seq = #{versionSeq},</if>
<if test="effectiveTime != null">effective_time = #{effectiveTime},</if>
@@ -97,16 +151,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<delete id="deletePrcPriceSetVersionByPriceSetId" parameterType="Long">
delete from prc_price_set_version where price_set_id = #{priceSetId}
delete from prc_price_set_version where price_set_id = #{priceSetId} and price_type = 'SALES'
</delete>
<select id="selectPriceSetIds" resultType="Long">
select distinct price_set_id from prc_price_set_version
select distinct price_set_id from prc_price_set_version where price_set_id is not null
</select>
<select id="selectActiveByPriceSetAt" resultMap="PrcPriceSetVersionResult">
<include refid="selectPrcPriceSetVersionVo"/>
where price_set_id = #{priceSetId}
where price_type = 'SALES'
and price_set_id = #{priceSetId}
and effective_time is not null
and effective_time &lt;= #{asOf}
and (expire_time is null or expire_time &gt; #{asOf})
@@ -114,4 +169,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
limit 1
</select>
<select id="selectActiveByTypeAt" resultMap="PrcPriceSetVersionResult">
<include refid="selectPrcPriceSetVersionVo"/>
where price_type = #{priceType}
and price_set_id is null
and effective_time is not null
and effective_time &lt;= #{asOf}
and (expire_time is null or expire_time &gt; #{asOf})
order by effective_time desc, version_seq desc, psv_id desc
limit 1
</select>
<update id="refreshCatalogStatusByDates">
update prc_price_set_version
set status = case
when expire_time is not null and expire_time &lt;= now() then '2'
when effective_time is not null and effective_time &gt; now() then '3'
when effective_time is null then '0'
else '1'
end,
update_time = sysdate()
where price_type = #{priceType}
and price_set_id is null
and status in ('0','1','2','3')
</update>
</mapper>
@@ -39,8 +39,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ifnull(c.country_name, rc.country_name) as country_name, ifnull(c.weight_min, rc.weight_min) as weight_min, ifnull(c.weight_max, rc.weight_max) as weight_max
from prc_surcharge_rel r
join prc_surcharge s on s.sc_id = r.sc_id and ifnull(s.is_del, '0') = '0'
left join product_country c on c.detail_id = r.detail_id and r.price_type = 'PRODUCT' and ifnull(c.is_del, '0') = '0'
left join redline_product_country rc on rc.detail_id = r.detail_id and r.price_type = 'REDLINE' and ifnull(rc.is_del, '0') = '0'
left join prc_price_set_detail c on c.psd_id = r.detail_id and r.price_type = 'PRODUCT' and ifnull(c.is_del, '0') = '0'
left join prc_price_set_detail rc on rc.psd_id = r.detail_id and r.price_type = 'REDLINE' and ifnull(rc.is_del, '0') = '0'
</sql>
<select id="selectPrcSurchargeRelList" parameterType="PrcSurchargeRel" resultMap="PrcSurchargeRelResult">
@@ -136,6 +136,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</update>
<delete id="physicalDeleteByPsvId">
delete r from prc_surcharge_rel r
where exists (
select 1 from prc_price_set_product p
where p.psp_id = r.product_id and p.psv_id = #{psvId}
)
or exists (
select 1 from prc_price_set_detail d
where d.psd_id = r.detail_id and d.psv_id = #{psvId}
)
</delete>
<!-- 附加费版本化编辑后,产品关联重指向新记录 -->
<update id="rebindRelScId">
update prc_surcharge_rel