<?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.dxhy.core.dao.OtherInvoiceDetailDao">
    <select id="selectPassengerTheme"
            resultType="com.dxhy.core.entity.InvoiceMainBody">
        SELECT invoice_code,
               invoice_no,
               invoice_date,
               invoice_type,
               gf_name,
               gf_address_and_phone,
               gf_bank_and_no,
               gf_tax_no,
               xf_tax_no,
               xf_name,
               xf_address_and_phone,
               xf_bank_and_no,
               invoice_status,
               create_date,
               '' AS rzlx,
               source_system,
               qs_date,
               qs_name,
               qs_type,
               '' AS rzh_date,
               '' AS rzh_type,
               '' AS gx_user_name,
               '' AS dqskssq,
               related_business_documents,
               business_document_maker,
               business_document_number,
               reimbursement_time,
               reimbursement_status,
               ticket_number,
               passenger,
               is_deduction,
               uuid,
               departure_city,
               reaching_city,
               invoice_amount,
               tax_amount,
               total_amount,
               tax_rate,
               scan_id,
               train_number,
               ticket_arrival_time,
               ticket_departure_time,
               seat_level,
               traffic_type,
               currency
        FROM t_dx_invoice_reimburse
        where select_id = #{selectId}
    </select>
    <select id="selectInvoiceMainBody"
            resultType="com.dxhy.core.entity.InvoiceMainBody"
            databaseId="mysql">
        select d.*
        from (
                 SELECT a.*
                 FROM (
                          SELECT invoice_code,
                                 invoice_no,
                                 invoice_date,
                                 invoice_type,
                                 invoice_amount,
                                 tax_amount,
                                 total_amount,
                                 gf_name,
                                 gf_address_and_phone,
                                 gf_bank_and_no,
                                 gf_tax_no,
                                 xf_tax_no,
                                 xf_name,
                                 xf_address_and_phone,
                                 xf_bank_and_no,
                                 invoice_status,
                                 create_date,
                                 source_system,
                                 qs_date,
                                 qs_name,
                                 qs_type,
                                 rzh_date,
                                 rzh_type,
                                 confirm_user as gx_user_name,
                                 rzh_belong_date dqskssq,
                                 ''           AS related_business_documents,
                                 ''           AS business_document_maker,
                                 ''           AS business_document_number,
                                 ''           AS reimbursement_time,
                                 ''           AS reimbursement_status,
                                 ''           AS ticket_number,
                                 ''           AS passenger,
                                 ''           AS is_deduction,
                                 uuid,
                                 ''           AS departure_city,
                                 ''           AS reaching_city,
                                 ''           AS tax_rate,
                                 remark,
                                 scan_id
                          FROM t_dx_record_invoice
                          WHERE invoice_code = #{invoiceCode}
                            and invoice_no = #{invoiceNo}
                          UNION ALL
                          SELECT invoice_code,
                                 invoice_no,
                                 invoice_date,
                                 invoice_type,
                                 invoice_amount,
                                 tax_amount,
                                 total_amount,
                                 gf_name,
                                 gf_address_and_phone,
                                 gf_bank_and_no,
                                 gf_tax_no,
                                 xf_tax_no,
                                 xf_name,
                                 xf_address_and_phone,
                                 xf_bank_and_no,
                                 invoice_status,
                                 create_date,
                                 source_system,
                                 qs_date,
                                 qs_name,
                                 qs_type,
                                 '' AS rzh_date,
                                 '' AS rzh_type,
                                 '' AS gx_user_name,
                                 '' AS dqskssq,
                                 related_business_documents,
                                 business_document_maker,
                                 business_document_number,
                                 reimbursement_time,
                                 reimbursement_status,
                                 ticket_number,
                                 passenger,
                                 is_deduction,
                                 uuid,
                                 departure_city,
                                 reaching_city,
                                 tax_rate,
                                 '' as remark,
                                 scan_id
                          FROM t_dx_invoice_reimburse
                          where invoice_code = #{invoiceCode}
                            and invoice_no = #{invoiceNo}
                      ) AS a
                 ORDER BY a.create_date
                 limit 10
             ) AS d
        GROUP BY d.uuid
        having min(d.create_date)
    </select>
</mapper>
