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, 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 and v.price_type = #{priceType} and v.price_set_id is null and v.effective_time is not null and v.effective_time <= #{bizDate} and (v.expire_time is null or v.expire_time > #{bizDate}) insert ignore into prc_price_set_detail ( 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, size_limit, last_mile, lead_time, round_mode, effective_date, expire_date, is_del, create_time ) select 'SALES', #{psvId}, c.product_code, c.product_name, c.country_code, c.country_name, c.zone_id, c.zone_code, c.zone_name, c.weight_label, c.weight_min, c.weight_max, 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 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 ignore into prc_price_set_detail ( price_type, psv_id, product_code, product_name, round_mode, is_del, create_time ) select 'SALES', #{psvId}, p.product_code, p.product_name, 'HALF_UP', '0', sysdate() 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 into prc_price_set_detail ( 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, size_limit, last_mile, lead_time, discount_value, round_mode, pr_id, effective_date, expire_date, is_del, create_time ) values ( #{priceType}, #{psvId}, #{pspId}, #{productCode}, #{productName}, #{countryCode}, #{countryName}, #{zoneId}, #{zoneCode}, #{zoneName}, #{zdId}, #{wsdId}, #{weightLabel}, #{weightMin}, #{weightMax}, #{productCountryId}, #{fvValue}, #{fvRegistrationFee}, #{sizeLimit}, #{lastMile}, #{leadTime}, #{discountValue}, #{roundMode}, #{prId}, #{effectiveDate}, #{expireDate}, ifnull(#{isDel}, '0'), sysdate() ) insert into prc_price_set_detail ( 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, size_limit, last_mile, lead_time, discount_value, round_mode, pr_id, effective_date, expire_date, is_del, create_time ) values ( 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.sizeLimit}, #{item.lastMile}, #{item.leadTime}, #{item.discountValue}, ifnull(#{item.roundMode}, 'HALF_UP'), #{item.prId}, #{item.effectiveDate}, #{item.expireDate}, ifnull(#{item.isDel}, '0'), sysdate() ) update prc_price_set_detail fv_value = #{fvValue}, fv_registration_fee = #{fvRegistrationFee}, update_time = sysdate() where psd_id = #{psdId} update prc_price_set_detail price_type = #{priceType}, psv_id = #{psvId}, psp_id = #{pspId}, product_code = #{productCode}, product_name = #{productName}, 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}, size_limit = #{sizeLimit}, last_mile = #{lastMile}, lead_time = #{leadTime}, discount_value = #{discountValue}, round_mode = #{roundMode}, pr_id = #{prId}, effective_date = #{effectiveDate}, expire_date = #{expireDate}, update_time = sysdate() where psd_id = #{psdId} update prc_price_set_detail set is_del = '1', update_time = sysdate() where ifnull(is_del, '0') = '0' and psd_id in #{psdId} delete from prc_price_set_detail where psd_id in #{psdId} 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 prc_price_set_detail set is_del = '1', update_time = sysdate() where psv_id = #{psvId} and ifnull(is_del, '0') = '0' delete from prc_price_set_detail where psv_id = #{psvId} update prc_price_set_detail set is_del = '1', update_time = sysdate() where psv_id is null and ifnull(is_del, '0') = '0' insert into prc_price_set_detail ( 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, size_limit, last_mile, lead_time, discount_value, round_mode, pr_id, effective_date, expire_date, status, is_del, create_time ) select 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 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 <=> v.status) or not (d.effective_date <=> v.effective_time) or not (d.expire_date <=> v.expire_time) ) 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 v.price_set_id = #{priceSetId} and v.price_type = 'SALES' and d.price_type = 'SALES' and ( not (d.status <=> v.status) or not (d.effective_date <=> v.effective_time) or not (d.expire_date <=> v.expire_time) ) update prc_price_set_detail set price_type = #{priceType}, update_time = sysdate() where psv_id = #{psvId}