<?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.MixedSignatureDao">

    <select id="selectQsfpList" parameterType="java.util.Map"
            resultType="com.dxhy.core.model.SmyqsWqsfpVO">
        select * from (
        select
        t.id,
        t.invoice_type invoiceType,
        t.invoice_code invoiceCode,
        t.invoice_no invoiceNo,
        date_format(t.invoice_date,'%Y-%m-%d') invoiceDate,
        r.ticket_number ticketNumber,
        r.passenger,
        t.invoice_amount invoiceAmount,
        t.tax_amount taxAmount,
        t.total_amount totalAmount,
        t.invoice_status invoiceStatus,
        r.dqskssq,
        r.source_system sourceSystem,
        r.departure_city departureCity,
        r.reaching_city reachingCity,
        r.related_business_documents relatedBusinessDocumes,
        r.business_document_maker businessDocumentMaker,
        r.business_document_number businessDocumentNumber,
        r.reimbursement_time reimbursementTime,
        r.reimbursement_status reimbursementStatus,
        r.train_number trainNumber,
        r.ticket_departure_time ticketDepartureTime,
        r.ticket_arrival_time ticketArrivalTime,
        r.passenger_s_f_z_h passengerSfzh,
        t.uuid,
        t.gf_tax_no gfTaxNo,
        r.gf_address_and_phone gfAddressAndPhone,
        r.gf_bank_and_no gfBankAndNo,
        r.xf_address_and_phone xfAddressAndPhone,
        r.xf_bank_and_no xfBankAndNo,
        t.gf_name gfName,
        t.xf_tax_no xfTaxNo,
        t.xf_name xfName,
        r.tax_rate taxRate,
        date_format(t.create_date,'%Y-%m-%d') createDate,
        r.rzh_yesorno rzhYesorno,
        r.tag,
        r.is_deduction isDeduction,
        r.is_domestic isDomestic,
        r.select_id selectId,
        t.qs_date qsDate,
        t.qs_type qsType,
        t.qs_name qsName,
        t.qs_status qsStatus,
        t.scan_id scanId,
        t.invoice_remark remark,
        '1' fileType,
        t.check_code checkCode,
        r.qz_status qzStatus,
        r.ewm,
        r.orientation,
        r.region,
        r.fuel_surcharge fuelSurcharge,
        r.caac_development_fund caacDevelopmentFund,
        t.update_date updateDate,
        r.fare,
        t.notes,
        t.dept_name businessName,
        '0'isHunsao
        from t_dx_invoice t left join t_dx_invoice_reimburse r on t.uuid = r.uuid
        where t.user_name=#{param.userName} and ((t.qs_status='0' and r.id is null) or (t.qs_status='1' and
        (r.qs_status!='1' or r.qs_status is null)))
        <if test="param.invoiceType != '99' and param.invoiceType != null and param.invoiceType != '' and param.invoiceType != 'null'">
            and t.invoice_type = #{param.invoiceType}
        </if>
        <if test="param.fileType != '99' and param.fileType != null and param.fileType != '' and param.fileType != 'null'">
            and r.file_type = #{param.fileType}
        </if>
        <if test="param.businessCode != '99' and param.businessCode != null and param.businessCode != '' and param.businessCode != 'null'">
            and t.dept_id = #{param.businessCode}
        </if>
        <if test="param.businessCode == ''">
            and (t.dept_id is null or t.dept_id='' or t.dept_id='99')
        </if>
        <if test="param.createDateBegin != null and param.createDateBegin != '' and param.createDateBegin != 'null' ">
            <![CDATA[ AND t.create_date >= #{param.createDateBegin} ]]>
        </if>
        <if test="param.createDateEnd != null and param.createDateEnd != '' and param.createDateEnd != 'null' ">
            <![CDATA[ AND t.create_date <= #{param.createDateEnd} ]]>
        </if>
        <if test="param.xfName != null and param.xfName != ''">
            and t.xf_name LIKE concat(#{param.xfName},'%')
        </if>
        <if test="param.ewm != null and param.ewm != ''">
            and r.ewm LIKE concat(#{param.ewm},'%')
        </if>
        <if test="param.qzStatus != null and param.qzStatus != '' and param.qzStatus != '99'">
            and r.qz_status = #{param.qzStatus}
        </if>
        <if test="param.gfsh != null and param.gfsh != '' and param.gfshFlag != '99'">
            and t.gf_tax_no = #{param.gfsh}
        </if>
        <if test="param.qsStatus != null and param.qsStatus != '' and param.qsStatus != '99'">
            and t.qs_status = #{param.qsStatus}
        </if>
        union all
        select
        r.id,
        r.invoice_type invoiceType,
        r.invoice_code invoiceCode,
        r.invoice_no invoiceNo,
        date_format(r.invoice_date,'%Y-%m-%d') invoiceDate,
        r.ticket_number ticketNumber,
        r.passenger,
        r.invoice_amount invoiceAmount,
        r.tax_amount taxAmount,
        r.total_amount totalAmount,
        r.invoice_status invoiceStatus,
        r.dqskssq,
        r.source_system sourceSystem,
        r.departure_city departureCity,
        r.reaching_city reachingCity,
        r.related_business_documents relatedBusinessDocumes,
        r.business_document_maker businessDocumentMaker,
        r.business_document_number businessDocumentNumber,
        r.reimbursement_time reimbursementTime,
        r.reimbursement_status reimbursementStatus,
        r.train_number trainNumber,
        r.ticket_departure_time ticketDepartureTime,
        r.ticket_arrival_time ticketArrivalTime,
        r.passenger_s_f_z_h passengerSfzh,
        r.uuid,
        r.gf_tax_no gfTaxNo,
        r.gf_address_and_phone gfAddressAndPhone,
        r.gf_bank_and_no gfBankAndNo,
        r.xf_address_and_phone xfAddressAndPhone,
        r.xf_bank_and_no xfBankAndNo,
        r.gf_name gfName,
        r.xf_tax_no xfTaxNo,
        r.xf_name xfName,
        r.tax_rate taxRate,
        date_format(r.create_date,'%Y-%m-%d') createDate,
        r.rzh_yesorno rzhYesorno,
        r.tag,
        r.is_deduction isDeduction,
        r.is_domestic isDomestic,
        r.select_id selectId,
        r.qs_date qsDate,
        r.qs_type qsType,
        r.qs_name qsName,
        r.qs_status qsStatus,
        r.scan_id scanId,
        r.remark,
        r.file_type fileType,
        r.check_code checkCode,
        r.qz_status qzStatus,
        r.ewm,
        r.orientation,
        r.region,
        r.fuel_surcharge,
        r.caac_development_fund caacDevelopmentFund,
        r.update_date,
        r.fare,
        r.notes,
        r.dept_name businessName,
        '1' isHunsao
        from t_dx_invoice_reimburse r left join t_dx_invoice t on r.uuid = t.uuid
        where r.qs_name = #{param.userName} and (r.qs_status='1' or (r.qs_status='0' and (t.qs_status ='0' or
        t.qs_status is null)))
        <if test="param.invoiceType != '99' and param.invoiceType != null and param.invoiceType != '' and param.invoiceType != 'null'">
            and r.invoice_type = #{param.invoiceType}
        </if>
        <if test="param.fileType != '99' and param.fileType != null and param.fileType != '' and param.fileType != 'null'">
            and r.file_type = #{param.fileType}
        </if>
        <if test="param.businessCode != '99' and param.businessCode != null and param.businessCode != '' and param.businessCode != 'null'">
            and r.dept_id = #{param.businessCode}
        </if>
        <if test="param.businessCode == ''">
            and (r.dept_id is null or r.dept_id='' or r.dept_id='99')
        </if>
        <if test="param.createDateBegin != null and param.createDateBegin != '' and param.createDateBegin != 'null' ">
            <![CDATA[ AND r.create_date >= #{param.createDateBegin} ]]>
        </if>
        <if test="param.createDateEnd != null and param.createDateEnd != '' and param.createDateEnd != 'null' ">
            <![CDATA[ AND r.create_date <= #{param.createDateEnd} ]]>
        </if>
        <if test="param.xfName != null and param.xfName != ''">
            and r.xf_name LIKE concat(#{param.xfName},'%')
        </if>
        <if test="param.ewm != null and param.ewm != ''">
            and r.ewm LIKE concat(#{param.ewm},'%')
        </if>
        <if test="param.qzStatus != null and param.qzStatus != '' and param.qzStatus != '99'">
            and r.qz_status = #{param.qzStatus}
        </if>
        <if test="param.gfsh != null and param.gfsh != '' and param.gfshFlag != '99'">
            and r.gf_tax_no = #{param.gfsh}
        </if>
        <if test="param.qsStatus != null and param.qsStatus != '' and param.qsStatus != '99'">
            and r.qs_status = #{param.qsStatus}
        </if>
        ) t order by t.createDate desc

    </select>
</mapper>
