527 lines
23 KiB
XML
527 lines
23 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<!DOCTYPE mapper
|
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
<mapper namespace="com.bms.price.mapper.PrcPriceSetDetailMapper">
|
|
|
|
<resultMap type="PrcPriceSetDetail" id="PrcPriceSetDetailResult">
|
|
<id property="psdId" column="psd_id" />
|
|
<result property="priceSetId" column="price_set_id" />
|
|
<result property="psvId" column="psv_id" />
|
|
<result property="pspId" column="psp_id" />
|
|
<result property="productCode" column="product_code" />
|
|
<result property="productName" column="product_name" />
|
|
<result property="countryCode" column="country_code" />
|
|
<result property="countryName" column="country_name" />
|
|
<result property="zoneId" column="zone_id" />
|
|
<result property="zoneCode" column="zone_code" />
|
|
<result property="zoneName" column="zone_name" />
|
|
<result property="zdId" column="zd_id" />
|
|
<result property="wsdId" column="wsd_id" />
|
|
<result property="weightLabel" column="weight_label" />
|
|
<result property="weightMin" column="weight_min" />
|
|
<result property="weightMax" column="weight_max" />
|
|
<result property="productCountryId" column="product_country_id" />
|
|
<result property="fvValue" column="fv_value" />
|
|
<result property="fvRegistrationFee" column="fv_registration_fee" />
|
|
<result property="baseFreightPrice" column="base_freight_price" />
|
|
<result property="baseRegistrationFee" column="base_registration_fee" />
|
|
<result property="discountValue" column="discount_value" />
|
|
<result property="roundMode" column="round_mode" />
|
|
<result property="prId" column="pr_id" />
|
|
<result property="effectiveDate" column="effective_date" />
|
|
<result property="expireDate" column="expire_date" />
|
|
<result property="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,
|
|
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
|
|
from prc_price_set_detail
|
|
</sql>
|
|
|
|
<select id="selectPrcPriceSetDetailById" parameterType="Long" resultMap="PrcPriceSetDetailResult">
|
|
<include refid="selectPrcPriceSetDetailVo"/>
|
|
where psd_id = #{psdId}
|
|
</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,
|
|
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
|
|
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'
|
|
<where>
|
|
<if test="priceSetId != null">
|
|
AND d.price_set_id = #{priceSetId}
|
|
</if>
|
|
<if test="psvId != null">
|
|
AND d.psv_id = #{psvId}
|
|
</if>
|
|
<if test="productCode != null and productCode != ''">
|
|
AND d.product_code = #{productCode}
|
|
</if>
|
|
<if test="countryCode != null and countryCode != ''">
|
|
AND d.country_code = #{countryCode}
|
|
</if>
|
|
<if test="zoneCode != null and zoneCode != ''">
|
|
AND d.zone_code = #{zoneCode}
|
|
</if>
|
|
<if test="productKeyword != null and productKeyword != ''">
|
|
AND (
|
|
d.product_code like concat('%', #{productKeyword}, '%')
|
|
or d.product_name like concat('%', #{productKeyword}, '%')
|
|
)
|
|
</if>
|
|
<if test="countryKeyword != null and countryKeyword != ''">
|
|
AND (
|
|
d.country_code like concat('%', #{countryKeyword}, '%')
|
|
or d.country_name like concat('%', #{countryKeyword}, '%')
|
|
)
|
|
</if>
|
|
<if test="zoneKeyword != null and zoneKeyword != ''">
|
|
AND (
|
|
d.zone_code like concat('%', #{zoneKeyword}, '%')
|
|
or d.zone_name like concat('%', #{zoneKeyword}, '%')
|
|
)
|
|
</if>
|
|
<if test="keyword != null and keyword != ''">
|
|
AND (
|
|
d.product_code like concat('%', #{keyword}, '%')
|
|
or d.product_name like concat('%', #{keyword}, '%')
|
|
or d.country_code like concat('%', #{keyword}, '%')
|
|
or d.country_name like concat('%', #{keyword}, '%')
|
|
or d.zone_code like concat('%', #{keyword}, '%')
|
|
or d.zone_name like concat('%', #{keyword}, '%')
|
|
or d.weight_label like concat('%', #{keyword}, '%')
|
|
)
|
|
</if>
|
|
</where>
|
|
order by d.psd_id asc
|
|
</select>
|
|
|
|
<select id="countProductByPriceSetId" parameterType="Long" resultType="int">
|
|
select count(distinct product_code) from prc_price_set_detail where price_set_id = #{priceSetId}
|
|
</select>
|
|
|
|
<select id="countByPriceSetId" parameterType="Long" resultType="int">
|
|
select count(1) from prc_price_set_detail where price_set_id = #{priceSetId}
|
|
</select>
|
|
|
|
<select id="countByPsvId" parameterType="Long" resultType="int">
|
|
select count(1) from prc_price_set_detail where psv_id = #{psvId}
|
|
</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}
|
|
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,
|
|
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
|
|
)
|
|
select
|
|
#{priceSetId},
|
|
#{psvId},
|
|
p.product_code,
|
|
p.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))), ''),
|
|
'<W≤',
|
|
ifnull(trim(trailing '0' from trim(trailing '.' from cast(c.weight_max as char))), '')
|
|
)
|
|
end,
|
|
c.weight_min,
|
|
c.weight_max,
|
|
c.detail_id,
|
|
c.freight_price,
|
|
c.registration_fee,
|
|
'HALF_UP',
|
|
c.effective_date,
|
|
c.expire_date,
|
|
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') <> '2'
|
|
<choose>
|
|
<when test="openOnly">
|
|
and (c.effective_date is null or date(c.effective_date) <= curdate())
|
|
and (c.expire_date is null or date(c.expire_date) > curdate())
|
|
</when>
|
|
<otherwise>
|
|
and date(c.effective_date) <= date(#{asOf})
|
|
and (c.expire_date is null or date(c.expire_date) > 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
|
|
</insert>
|
|
|
|
<select id="selectFixedDetailsFromLibrary" resultMap="PrcPriceSetDetailResult">
|
|
select
|
|
null as psd_id,
|
|
null as price_set_id,
|
|
null as psv_id,
|
|
null as psp_id,
|
|
p.product_code,
|
|
p.product_name,
|
|
c.country_code,
|
|
c.country_name,
|
|
c.zone_id,
|
|
c.zone_code,
|
|
c.zone_name,
|
|
null as zd_id,
|
|
null as wsd_id,
|
|
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))), ''),
|
|
'<W≤',
|
|
ifnull(trim(trailing '0' from trim(trailing '.' from cast(c.weight_max as char))), '')
|
|
)
|
|
end as 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,
|
|
null as base_freight_price,
|
|
null as base_registration_fee,
|
|
null as discount_value,
|
|
'HALF_UP' as round_mode,
|
|
null as pr_id,
|
|
c.effective_date,
|
|
c.expire_date,
|
|
null as create_time,
|
|
null as update_time
|
|
from 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') <> '2'
|
|
<choose>
|
|
<when test="openOnly">
|
|
and (c.effective_date is null or date(c.effective_date) <= curdate())
|
|
and (c.expire_date is null or date(c.expire_date) > curdate())
|
|
</when>
|
|
<otherwise>
|
|
and date(c.effective_date) <= date(#{asOf})
|
|
and (c.expire_date is null or date(c.expire_date) > 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
|
|
</select>
|
|
|
|
<insert id="insertDiscountDetailsFromLibrary">
|
|
insert ignore into prc_price_set_detail (
|
|
price_set_id, psv_id, product_code, product_name, round_mode, create_time
|
|
)
|
|
select
|
|
#{priceSetId},
|
|
#{psvId},
|
|
p.product_code,
|
|
p.product_name,
|
|
'HALF_UP',
|
|
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>
|
|
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="psvId != null">psv_id,</if>
|
|
<if test="pspId != null">psp_id,</if>
|
|
<if test="productCode != null and productCode != ''">product_code,</if>
|
|
<if test="productName != null">product_name,</if>
|
|
<if test="countryCode != null">country_code,</if>
|
|
<if test="countryName != null">country_name,</if>
|
|
<if test="zoneId != null">zone_id,</if>
|
|
<if test="zoneCode != null">zone_code,</if>
|
|
<if test="zoneName != null">zone_name,</if>
|
|
<if test="zdId != null">zd_id,</if>
|
|
<if test="wsdId != null">wsd_id,</if>
|
|
<if test="weightLabel != null">weight_label,</if>
|
|
<if test="weightMin != null">weight_min,</if>
|
|
<if test="weightMax != null">weight_max,</if>
|
|
<if test="productCountryId != null">product_country_id,</if>
|
|
<if test="fvValue != null">fv_value,</if>
|
|
<if test="fvRegistrationFee != null">fv_registration_fee,</if>
|
|
<if test="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,
|
|
create_time
|
|
) values (
|
|
<if test="priceSetId != null">#{priceSetId},</if>
|
|
<if test="psvId != null">#{psvId},</if>
|
|
<if test="pspId != null">#{pspId},</if>
|
|
<if test="productCode != null and productCode != ''">#{productCode},</if>
|
|
<if test="productName != null">#{productName},</if>
|
|
<if test="countryCode != null">#{countryCode},</if>
|
|
<if test="countryName != null">#{countryName},</if>
|
|
<if test="zoneId != null">#{zoneId},</if>
|
|
<if test="zoneCode != null">#{zoneCode},</if>
|
|
<if test="zoneName != null">#{zoneName},</if>
|
|
<if test="zdId != null">#{zdId},</if>
|
|
<if test="wsdId != null">#{wsdId},</if>
|
|
<if test="weightLabel != null">#{weightLabel},</if>
|
|
<if test="weightMin != null">#{weightMin},</if>
|
|
<if test="weightMax != null">#{weightMax},</if>
|
|
<if test="productCountryId != null">#{productCountryId},</if>
|
|
<if test="fvValue != null">#{fvValue},</if>
|
|
<if test="fvRegistrationFee != null">#{fvRegistrationFee},</if>
|
|
<if test="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},
|
|
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,
|
|
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
|
|
) values
|
|
<foreach collection="list" item="item" separator=",">
|
|
(
|
|
#{item.priceSetId}, #{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},
|
|
ifnull(#{item.roundMode}, 'HALF_UP'), #{item.prId},
|
|
#{item.effectiveDate}, #{item.expireDate}, sysdate()
|
|
)
|
|
</foreach>
|
|
</insert>
|
|
|
|
<!-- Null means keep existing value (import empty freight/registration skips overwrite). -->
|
|
<update id="updateDetailPrices">
|
|
update prc_price_set_detail
|
|
<set>
|
|
<if test="fvValue != null">fv_value = #{fvValue},</if>
|
|
<if test="fvRegistrationFee != null">fv_registration_fee = #{fvRegistrationFee},</if>
|
|
update_time = sysdate()
|
|
</set>
|
|
where psd_id = #{psdId}
|
|
</update>
|
|
|
|
<update id="updatePrcPriceSetDetail" parameterType="PrcPriceSetDetail">
|
|
update prc_price_set_detail
|
|
<set>
|
|
<if test="psvId != null">psv_id = #{psvId},</if>
|
|
<if test="pspId != null">psp_id = #{pspId},</if>
|
|
<if test="productCode != null and productCode != ''">product_code = #{productCode},</if>
|
|
<if test="productName != null">product_name = #{productName},</if>
|
|
country_code = #{countryCode},
|
|
country_name = #{countryName},
|
|
zone_id = #{zoneId},
|
|
zone_code = #{zoneCode},
|
|
zone_name = #{zoneName},
|
|
zd_id = #{zdId},
|
|
wsd_id = #{wsdId},
|
|
weight_label = #{weightLabel},
|
|
weight_min = #{weightMin},
|
|
weight_max = #{weightMax},
|
|
product_country_id = #{productCountryId},
|
|
fv_value = #{fvValue},
|
|
fv_registration_fee = #{fvRegistrationFee},
|
|
discount_value = #{discountValue},
|
|
<if test="roundMode != null and roundMode != ''">round_mode = #{roundMode},</if>
|
|
pr_id = #{prId},
|
|
effective_date = #{effectiveDate},
|
|
expire_date = #{expireDate},
|
|
update_time = sysdate()
|
|
</set>
|
|
where psd_id = #{psdId}
|
|
</update>
|
|
|
|
<delete id="deletePrcPriceSetDetailByIds" parameterType="Long">
|
|
delete from prc_price_set_detail where psd_id in
|
|
<foreach item="psdId" collection="array" open="(" separator="," close=")">
|
|
#{psdId}
|
|
</foreach>
|
|
</delete>
|
|
|
|
<delete id="deletePrcPriceSetDetailByPriceSetId" parameterType="Long">
|
|
delete from prc_price_set_detail where price_set_id = #{priceSetId}
|
|
</delete>
|
|
|
|
<delete id="deletePrcPriceSetDetailByPsvId" parameterType="Long">
|
|
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>
|
|
|
|
<select id="selectFixedMatch" resultMap="PrcPriceSetDetailResult">
|
|
<include refid="selectPrcPriceSetDetailVo"/>
|
|
where price_set_id = #{priceSetId}
|
|
<if test="psvId != null">
|
|
and psv_id = #{psvId}
|
|
</if>
|
|
and product_code = #{productCode}
|
|
<choose>
|
|
<when test="countryCode != null and countryCode != ''">
|
|
and upper(ifnull(country_code,'')) = upper(#{countryCode})
|
|
</when>
|
|
<when test="countryName != null and countryName != ''">
|
|
and country_name = #{countryName}
|
|
</when>
|
|
<otherwise>
|
|
and 1 = 0
|
|
</otherwise>
|
|
</choose>
|
|
<choose>
|
|
<when test="zoneCode != null and zoneCode != ''">
|
|
and upper(ifnull(zone_code,'')) = upper(#{zoneCode})
|
|
</when>
|
|
<otherwise>
|
|
and (zone_code is null or zone_code = '')
|
|
</otherwise>
|
|
</choose>
|
|
and weight_min <= #{weight}
|
|
and weight_max >= #{weight}
|
|
order by
|
|
weight_min asc,
|
|
psd_id asc
|
|
limit 1
|
|
</select>
|
|
|
|
<select id="countZonedByPsvProductCountry" resultType="int">
|
|
select count(1)
|
|
from prc_price_set_detail
|
|
where psv_id = #{psvId}
|
|
and product_code = #{productCode}
|
|
and zone_code is not null and zone_code <> ''
|
|
<choose>
|
|
<when test="countryCode != null and countryCode != ''">
|
|
and upper(ifnull(country_code,'')) = upper(#{countryCode})
|
|
</when>
|
|
<when test="countryName != null and countryName != ''">
|
|
and country_name = #{countryName}
|
|
</when>
|
|
<otherwise>
|
|
and 1 = 0
|
|
</otherwise>
|
|
</choose>
|
|
</select>
|
|
|
|
<select id="countByPsvProduct" resultType="int">
|
|
select count(1)
|
|
from prc_price_set_detail
|
|
where psv_id = #{psvId}
|
|
and product_code = #{productCode}
|
|
</select>
|
|
|
|
<select id="countByPsvProductCountryZone" resultType="int">
|
|
select count(1)
|
|
from prc_price_set_detail
|
|
where psv_id = #{psvId}
|
|
and product_code = #{productCode}
|
|
<choose>
|
|
<when test="countryCode != null and countryCode != ''">
|
|
and upper(ifnull(country_code,'')) = upper(#{countryCode})
|
|
</when>
|
|
<when test="countryName != null and countryName != ''">
|
|
and country_name = #{countryName}
|
|
</when>
|
|
<otherwise>
|
|
and 1 = 0
|
|
</otherwise>
|
|
</choose>
|
|
<choose>
|
|
<when test="zoneCode != null and zoneCode != ''">
|
|
and upper(ifnull(zone_code,'')) = upper(#{zoneCode})
|
|
</when>
|
|
<otherwise>
|
|
and (zone_code is null or zone_code = '')
|
|
</otherwise>
|
|
</choose>
|
|
</select>
|
|
|
|
<select id="selectDiscountMatch" resultMap="PrcPriceSetDetailResult">
|
|
<include refid="selectPrcPriceSetDetailVo"/>
|
|
where price_set_id = #{priceSetId}
|
|
<if test="psvId != null">
|
|
and psv_id = #{psvId}
|
|
</if>
|
|
and product_code = #{productCode}
|
|
order by psd_id asc
|
|
limit 1
|
|
</select>
|
|
|
|
<insert id="copyDetailsFromVersion">
|
|
insert into prc_price_set_detail (
|
|
price_set_id, 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
|
|
)
|
|
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
|
|
</insert>
|
|
|
|
</mapper>
|