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 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 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' and (c.effective_date is null or date(c.effective_date) <= curdate()) and (c.expire_date is null or date(c.expire_date) > curdate()) and date(c.effective_date) <= date(#{asOf}) and (c.expire_date is null or date(c.expire_date) > date(#{asOf})) order by p.product_code asc, c.country_name asc, c.zone_code asc, c.weight_min asc, c.detail_id asc 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 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' ) order by p.product_code asc 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 ( #{priceSetId}, #{psvId}, #{pspId}, #{productCode}, #{productName}, #{countryCode}, #{countryName}, #{zoneId}, #{zoneCode}, #{zoneName}, #{zdId}, #{wsdId}, #{weightLabel}, #{weightMin}, #{weightMax}, #{productCountryId}, #{fvValue}, #{fvRegistrationFee}, #{discountValue}, #{roundMode}, #{prId}, #{effectiveDate}, #{expireDate}, sysdate() ) 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 ( #{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() ) update prc_price_set_detail fv_value = #{fvValue}, fv_registration_fee = #{fvRegistrationFee}, update_time = sysdate() where psd_id = #{psdId} update prc_price_set_detail 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}, discount_value = #{discountValue}, round_mode = #{roundMode}, pr_id = #{prId}, effective_date = #{effectiveDate}, expire_date = #{expireDate}, update_time = sysdate() where psd_id = #{psdId} delete from prc_price_set_detail where psd_id in #{psdId} delete from prc_price_set_detail where price_set_id = #{priceSetId} delete from prc_price_set_detail where psv_id = #{psvId} delete from prc_price_set_detail where price_set_id = #{priceSetId} and psv_id is null 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