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

    <resultMap id="CheckRecordInvoiceMap" type="com.dxhy.core.model.CheckInvoiceVO">
        <result column="id" property="id"/>
        <result column="FPDM" property="invoiceCode"/>
        <result column="FPHM" property="invoiceNo"/>
        <result column="KPRQ" property="invoiceDate"/>
        <result column="GFMC" property="gfmc"/>
        <result column="XFMC" property="xfmc"/>
        <result column="JSHJ" property="totalAmount"/>
        <result column="SE" property="taxAmount"/>
        <result column="JE" property="invoiceAmount"/>
        <result column="CYJG_TIP" property="checkMassege"/>
        <result column="JYM" property="checkCode"/>
        <result column="FPZL" property="invoiceType"/>
        <result column="CYJG_CODE" property="handleCode"/>
    </resultMap>

    <select id="selectCheckHistory" parameterType="java.util.Map"
            resultMap="CheckRecordInvoiceMap" databaseId="mysql">
        SELECT t.id,t.FPDM,t.FPHM,date_format(t.KPRQ,'%Y-%m-%d')
        KPRQ,t.GFMC,t.XFMC,t.JE,t.SE,t.JSHJ,t.JYM,t.CYJG_TIP,t.FPZL,t.CYJG_CODE
        FROM t_dx_check_record_invoice t
        WHERE t.check_user = #{userid}
        <if test="invoiceCode != null and invoiceCode != '' and invoiceCode != 'null' ">
            AND t.FPDM = #{invoiceCode}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            AND t.FPHM = #{invoiceNo}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            AND t.FPHM = #{invoiceNo}
        </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>
        <if test="company!=null and company!=''">
            and t.company = #{company}
        </if>
        AND t.create_date BETWEEN #{cyrqq} AND #{cyrqz}
        ORDER BY t.PDF_MD5 DESC,t.create_date DESC
    </select>

    <select id="selectCheckHistory" parameterType="java.util.Map"
            resultMap="CheckRecordInvoiceMap" databaseId="oracle">
        SELECT t.id,t.FPDM,t.FPHM,to_char(to_date(KPRQ,'yyyymmdd'),'yyyy-mm-dd') KPRQ
        ,t.GFMC,t.XFMC,t.JE,t.SE,t.JSHJ,t.JYM,t.CYJG_TIP,t.FPZL,t.CYJG_CODE
        FROM t_dx_check_record_invoice t
        WHERE t.check_user = #{userid}
        <if test="invoiceCode != null and invoiceCode != '' and invoiceCode != 'null' ">
            AND t.FPDM = #{invoiceCode}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            AND t.FPHM = #{invoiceNo}
        </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>
        ORDER BY t.PDF_MD5 DESC,t.create_date DESC
    </select>

</mapper>