select export_id, dimension, file_name, storage_key, row_count, export_status, export_user_id, export_by, export_time, remark from prc_profit_report_export insert into prc_profit_report_export ( dimension, file_name, storage_key, row_count, export_status, export_user_id, export_by, export_time, remark ) values ( #{dimension}, #{fileName}, #{storageKey}, #{rowCount}, #{exportStatus}, #{exportUserId}, #{exportBy}, sysdate(), #{remark} ) update prc_profit_report_export set file_name = #{fileName}, storage_key = #{storageKey}, row_count = #{rowCount}, export_status = 'SUCCESS', remark = null where export_id = #{exportId} and export_status = 'PROCESSING' update prc_profit_report_export set export_status = 'FAILED', remark = #{remark} where export_id = #{exportId} and export_status = 'PROCESSING' from prc_income_bill i inner join prc_order_bill p on p.bill_id = i.bill_id and (p.billing_fail_status is null or p.billing_fail_status not in (1, 2, 3)) and p.biz_date >= #{beginBizDate} and p.biz_date <= #{endBizDate} and ( p.order_no like concat('%', #{orderValue}, '%') ) and p.order_no like concat('%', #{orderNo}, '%') and p.customer_code in #{customerValue} and p.customer_code = #{customerCode} and ( p.customer_name like concat('%', #{customerValue}, '%') ) and p.customer_name like concat('%', #{customerName}, '%') and p.product_code <=> #{productCode} and p.country_code <=> #{countryCode} and i.currency <=> #{currency} and i.belong_saler_code = #{belongSalerCode} and i.belong_saler_code = #{belongSalerCode} and p.product_code = #{productCode} and p.country_code = #{countryCode} and i.currency = #{currency} and (i.product_amount is null or i.redline_amount is null or i.sales_amount is null) i.product_amount as cost_amount, i.redline_amount, case when i.product_amount is not null and i.redline_amount is not null then i.product_amount - i.redline_amount else null end as redline_gross_profit, case when i.product_amount is not null and i.redline_amount is not null and i.redline_amount != 0 then round((i.product_amount - i.redline_amount) * 100 / i.redline_amount, 4) else null end as redline_gross_margin_rate, i.sales_amount, case when i.product_amount is not null and i.sales_amount is not null then i.sales_amount - i.product_amount else null end as sales_gross_profit, case when i.product_amount is not null and i.sales_amount is not null and i.sales_amount != 0 then round((i.sales_amount - i.product_amount) * 100 / i.sales_amount, 4) else null end as sales_gross_margin_rate