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'
insert into prc_surcharge_rel (
sc_id, product_id, product_code, detail_id, price_type, country_code, is_del,
created_by,
create_time
) values (
#{scId}, #{productId}, #{productCode}, #{detailId},
#{priceType}, #{countryCode}, ifnull(#{isDel}, '0'),
#{createBy},
sysdate()
)
update prc_surcharge_rel
set is_del = '1', update_time = sysdate()
where ifnull(is_del, '0') = '0'
and rel_id in
#{relId}
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
#{code}
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
#{id}
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
#{id}
delete from prc_surcharge_rel
where price_type = #{priceType}
and detail_id in
#{id}
delete from prc_surcharge_rel
where price_type = #{priceType}
and product_id in
#{id}
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}
)
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 prc_surcharge_rel
set sc_id = #{newScId}, updated_by = #{operator}, update_time = sysdate()
where ifnull(is_del, '0') = '0'
and sc_id = #{oldScId}