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

    <select id="selectCheckHistoryDetail" parameterType="java.util.Map"
            resultType="com.dxhy.core.entity.TDxCheckInvoiceDetail" databaseId="mysql">
        SELECT t.id,t.FPDM,t.FPHM,date_format(t.KPRQ,'%Y-%m-%d')
        KPRQ,t.GFMC,t.XFMC,t.GFSH,t.XFSH,t.JE,t.SE,t.JSHJ,t.JYM,t.CYJG_TIP,t.FPZL,t.CYJG_CODE
        ,t.BZ,t.GFDZDH,t.GFYHZH,t.XFDZDH,t.XFYHZH,d.GOODS_NAME,d.MODEL,d.UNIT,d.NUM,d.UNIT_PRICE,d.TAX_RATE,date_format(t.create_date,'%Y-%m-%d')
        createDate,t.ZFBZ,t.check_user checkUser,d.cph,d.lx,d.txrqq,d.txrqz,d.detail_amount,d.tax_amount detailTaxAmount
        FROM t_dx_check_record_invoice t
        left join t_dx_check_invoice_detail d on t.uuid = d. uuid

        WHERE t.CYJG_CODE = '0001'
        <if test="gfsh != null and gfsh.size()>0 ">

            and t.GFSH in
            <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="company != null and company != '' and company != 'null' ">
            AND t.company = #{company}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            AND t.FPHM = #{invoiceNo}
        </if>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99'">
            AND t.FPZL = #{invoiceType}
        </if>
        <if test="userid != null and userid != '' and userid != 'null' and userid != '99'">
            and t.check_user=#{userid}
        </if>
        <if test="(kprqq != null and kprqq != '' and kprqq != 'null') and (kprqz != null and kprqz != '' and kprqz != 'null') ">
            AND date_format(t.KPRQ,'%Y-%m-%d %H:%i:%s') BETWEEN #{kprqq} AND #{kprqz}
        </if>
        AND t.create_date BETWEEN #{cyrqq} AND #{cyrqz}
        <if test="company !=null and company!=''">
            and t.company = #{company}
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="0"'>
            and t.FPZL in('01','03','04','10','11','14','08','15')
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="1"'>
            and t.FPZL in ('31','32')
        </if>
        ORDER BY t.create_date DESC

    </select>

    <select id="selectCheckHistoryDetail" parameterType="java.util.Map"
            resultType="com.dxhy.core.entity.TDxCheckInvoiceDetail" databaseId="oracle">
        SELECT t.id,t.FPDM,t.FPHM,to_date(KPRQ,'yyyy-mm-dd') KPRQ
        ,t.GFMC,t.XFMC,t.GFSH,t.XFSH,t.JE,t.SE,t.JSHJ,t.JYM,t.CYJG_TIP,t.FPZL,t.CYJG_CODE
        ,t.BZ,t.GFDZDH,t.GFYHZH,t.XFDZDH,t.XFYHZH,d.GOODS_NAME,d.MODEL,d.UNIT,d.NUM,d.UNIT_PRICE,d.TAX_RATE,
        to_char(t.create_date,'yyyy-mm-dd') createDate,t.ZFBZ,t.check_user
        checkUser,d.cph,d.lx,d.txrqq,d.txrqz,d.detail_amount,d.tax_amount detailTaxAmount
        FROM t_dx_check_record_invoice t
        left join t_dx_check_invoice_detail d on t.uuid = d. uuid
        WHERE t.CYJG_CODE = '0001'
        <if test="gfsh != null and gfsh.size()>0 ">

            and t.GFSH in
            <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="company != null and company != '' and company != 'null' ">
            AND t.company = #{company}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            AND t.FPHM = #{invoiceNo}
        </if>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99'">
            AND t.FPHM = #{invoiceType}
        </if>
        <if test="userid != null and userid != '' and userid != 'null' and userid != '99'">
            and t.check_user=#{userid}
        </if>
        <if test="(kprqq != null and kprqq != '' and kprqq != 'null') and (kprqz != null and kprqz != '' and kprqz != 'null') ">
            AND TO_CHAR(TO_DATE(t.KPRQ, 'yyyy-MM-dd'),'yyyy-MM-dd HH24:mm:dd' ) BETWEEN #{kprqq} AND #{kprqz}
        </if>
        AND TO_CHAR(t.create_date, 'yyyy-MM-dd HH24:mm:dd') between #{cyrqq} and #{cyrqz}
        <if test="company !=null and company!=''">
            and t.company = #{company}
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="0"'>
            and t.FPZL in('01','03','04','10','11','14','08','15')
        </if>
        <if test='invoiceSource!=null and invoiceSource!="" and invoiceSource!="null" and invoiceSource=="1"'>
            and t.FPZL in ('31','32')
        </if>
        ORDER BY t.create_date DESC
    </select>

</mapper>
