Files
BMS/bms-back/bms-system/src/main/resources/mapper/price/PrcSurchargeRelMapper.xml
T
2026-10-28 18:10:10 +08:00

194 lines
7.9 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.PrcSurchargeRelMapper">
<resultMap type="PrcSurchargeRel" id="PrcSurchargeRelResult">
<id property="relId" column="rel_id" />
<result property="scId" column="sc_id" />
<result property="productId" column="product_id" />
<result property="productCode" column="product_code" />
<result property="detailId" column="detail_id" />
<result property="priceType" column="price_type" />
<result property="countryCode" column="country_code" />
<result property="isDel" column="is_del" />
<result property="scName" column="sc_name" />
<result property="feeType" column="fee_type" />
<result property="chargeType" column="charge_type" />
<result property="chargeValue" column="charge_value" />
<result property="currency" column="currency" />
<result property="roundMode" column="round_mode" />
<result property="ssCode" column="ss_code" />
<result property="scNote" column="sc_note" />
<result property="countryName" column="country_name" />
<result property="weightMin" column="weight_min" />
<result property="weightMax" column="weight_max" />
<result property="createBy" column="created_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="updated_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectPrcSurchargeRelVo">
select r.rel_id, r.sc_id, r.product_id, r.product_code, r.detail_id,
r.price_type, r.country_code, r.is_del,
r.created_by, r.create_time, r.updated_by, r.update_time,
s.sc_name, s.fee_type, s.charge_type, s.charge_value, s.currency,
s.round_mode, s.ss_code, s.sc_note,
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 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">
<include refid="selectPrcSurchargeRelVo"/>
<where>
and ifnull(r.is_del, '0') = '0'
<if test="productId != null">
AND r.product_id = #{productId}
</if>
<if test="productCode != null and productCode != ''">
AND r.product_code = #{productCode}
</if>
<if test="scId != null">
AND r.sc_id = #{scId}
</if>
<if test="detailId != null">
AND r.detail_id = #{detailId}
</if>
<if test="priceType != null and priceType != ''">
AND r.price_type = #{priceType}
</if>
<if test="countryCode != null and countryCode != ''">
AND r.country_code = #{countryCode}
</if>
</where>
order by r.detail_id is not null, r.rel_id asc
</select>
<select id="selectByDetailIdsAndPriceType" resultMap="PrcSurchargeRelResult">
<include refid="selectPrcSurchargeRelVo"/>
where ifnull(r.is_del, '0') = '0'
and r.price_type = #{priceType}
and r.detail_id in
<foreach item="id" collection="detailIds" open="(" separator="," close=")">
#{id}
</foreach>
order by r.rel_id asc
</select>
<insert id="insertPrcSurchargeRel" parameterType="PrcSurchargeRel" useGeneratedKeys="true" keyProperty="relId">
insert into prc_surcharge_rel (
sc_id, product_id, product_code, detail_id, price_type, country_code, is_del,
<if test="createBy != null and createBy != ''">created_by,</if>
create_time
) values (
#{scId}, #{productId}, #{productCode}, #{detailId},
#{priceType}, #{countryCode}, ifnull(#{isDel}, '0'),
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="deletePrcSurchargeRelByIds" parameterType="Long">
update prc_surcharge_rel
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and rel_id in
<foreach item="relId" collection="array" open="(" separator="," close=")">
#{relId}
</foreach>
</update>
<update id="deleteRelByProductCodes">
update prc_surcharge_rel
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and price_type = 'PRODUCT'
and product_code in
<foreach item="code" collection="array" open="(" separator="," close=")">
#{code}
</foreach>
</update>
<update id="deleteByDetailIdsAndPriceType">
update prc_surcharge_rel
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and price_type = #{priceType}
and detail_id in
<foreach item="id" collection="detailIds" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<update id="deleteByProductIdsAndPriceType">
update prc_surcharge_rel
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and price_type = #{priceType}
and product_id in
<foreach item="id" collection="productIds" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<delete id="physicalDeleteByDetailIdsAndPriceType">
delete from prc_surcharge_rel
where price_type = #{priceType}
and detail_id in
<foreach item="id" collection="detailIds" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="physicalDeleteByProductIdsAndPriceType">
delete from prc_surcharge_rel
where price_type = #{priceType}
and product_id in
<foreach item="id" collection="productIds" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<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="softDeleteByPsvId">
update prc_surcharge_rel r
set r.is_del = '1', r.update_time = sysdate()
where ifnull(r.is_del, '0') = '0'
and (
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}
)
)
</update>
<!-- 附加费版本化编辑后,产品关联重指向新记录 -->
<update id="rebindRelScId">
update prc_surcharge_rel
set sc_id = #{newScId}, updated_by = #{operator}, update_time = sysdate()
where ifnull(is_del, '0') = '0'
and sc_id = #{oldScId}
</update>
</mapper>