<?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.jxpt.baseService.ncpInvoice.dao.NcpJjkcRecordInvoiceDao" >
	<!--底账和ncp表字段合集-->
	<resultMap id="BaseResultMap"
			   type="com.dxhy.api.model.ncp.ncpInvoice.TDxRecordInvoiceNcpVo">
		<result column="invoice_code" property="invoiceCode"/>
		<result column="invoice_no" property="invoiceNo"/>
		<result column="eleInvoiceNo" property="eleInvoiceNo"/>
		<result column="kprq" property="invoiceDate"/>
		<result column="invoice_type" property="invoiceType"/>
		<result column="gfsh" property="gfsh"/>
		<result column="gfmc" property="gfmc"/>
		<result column="xf_tax_no" property="xfsh"/>
		<result column="xf_name" property="xfmc"/>
		<result column="invoice_amount" property="invoiceAmount"/>
		<result column="tax_amount" property="taxAmount"/>
		<result column="dk_tax_amount" property="dkTaxAmount"/>
		<result column="invoice_status" property="invoiceStatus"/>
		<result column="rzh_date" property="rzsj"/>
		<result column="qs_date" property="qsrq"/>
		<result column="dqskssq" property="skssq"/>
		<result column="auth_status" property="rzclzt"/>
		<result column="qs_type" property="qsfs"/>
		<result column="qs_status" property="qszt"/>
		<result column="qs_name" property="qsr"/>
		<result column="rzh_yesorno" property="rzzt"/>
		<result column="deptId" property="deptId"/>
		<result column="deptName" property="businessName"/>
		<result column="confirm_user" property="rzhr"/>
		<result column="glzt" property="glzt"/>
		<result column="uuid" property="uuid"/>
		<result column="bdk_status" property="bdkStatus"/>
		<result column="export_mark" property="exportMark"/>
		<result column="scan_id" property="scanId"/>
		<result column="in_account_status" property="inAccountStatus"/>
		<result column="settle_source" property="settleSource"/>
		<result column="settlement_no" property="settlementNo"/>
		<result column="settlement_status" property="settlementStatus"/>
		<result column="voucher_number" property="voucherNumber"/>
		<result column="total_amount" property="totalAmount"/>

		<result column="ncpfpcllx" property="ncpfpcllx" jdbcType="VARCHAR" />
		<result column="dqsqqrclzt" property="dqsqqrclzt" jdbcType="VARCHAR" />
		<result column="jdqrzt" property="jdqrzt" jdbcType="VARCHAR" />
		<result column="jdqrlx" property="jdqrlx" jdbcType="VARCHAR" />
		<result column="ncpbfje" property="ncpbfje" jdbcType="VARCHAR" />
		<result column="ncpbfse" property="ncpbfse" jdbcType="VARCHAR" />
		<result column="yxdkse" property="yxdkse" jdbcType="VARCHAR" />
		<result column="kjjkcse" property="kjjkcse" jdbcType="VARCHAR" />
		<result column="sykjjkcse" property="sykjjkcse" jdbcType="VARCHAR" />
		<result column="qrsbyy" property="qrsbyy" jdbcType="VARCHAR" />
		<result column="qrsj" property="qrsj" jdbcType="VARCHAR" />
		<result column="qrr" property="qrr" jdbcType="VARCHAR" />
	</resultMap>

    <resultMap id="JjkcHjMap"
               type="com.dxhy.api.model.ncp.ncpInvoice.TDxRecordInvoiceNcpVo">
        <result column="hjsl" property="id"/>
        <result column="hjje" property="invoiceAmount"/>
        <result column="sykjjkcse" property="sykjjkcse"/>
    </resultMap>

	<!--ncp和ncp_jjkc字段合集-->
	<resultMap id="BaseJjkcResultMap" type="com.dxhy.api.model.ncp.ncpJjkcInvoice.TDxRecordInvoiceNcpJjkcVo" >
		<id column="id" property="id"/>
		<result column="invoice_code" property="invoiceCode"/>
		<result column="invoice_no" property="invoiceNo"/>
		<result column="ele_invoice_no" property="eleInvoiceNo"/>
		<result column="gf_tax_no" property="gfTaxNo"/>
		<result column="uuid" property="uuid"/>
		<result column="jjssq" property="jjssq"/>
		<result column="bcjjkcse" property="bcjjkcse" />
		<result column="sqlx" property="sqlx"/>
		<result column="clzt" property="clzt"/>
		<result column="sbyy" property="sbyy"/>
		<result column="czsj" property="czsj" />
		<result column="gxsj" property="gxsj" />
		<result column="czr" property="czr"/>
		<result column="update_time" property="updateTime" />
		<result column="create_time" property="createTime" />

		<result column="invoice_amount" property="invoiceAmount"/>
		<result column="kjjkcse" property="kjjkcse"/>
		<result column="sykjjkcse" property="sykjjkcse"/>
		<result column="invoice_type" property="invoiceType"/>
		<result column="invoice_date" property="invoiceDate"/>
		<result column="xf_name" property="xfName"/>
		<result column="xf_tax_no" property="xfTaxNo"/>
		<result column="gf_name" property="gfName"/>
		<result column="lqTdyslxDm" property="lqTdyslxDm"/>
		<result column="invoice_status" property="invoiceStatus"/>
		<result column="glzt" property="glzt"/>
		<result column="lq_hzsdbs" property="lqHzsdbs"/>
		<result column="lq_cpyycbs" property="lqCpyycbs"/>
		<result column="lq_jdcycbs" property="lqJdcycbs"/>

	</resultMap>

	<resultMap id="BbfpzhcxhjResultMap"
			   type="com.dxhy.api.model.ncp.ncpJjkcInvoice.TDxRecordInvoiceNcpJjkcVo">
		<result column="hjsl" property="id"/>
		<result column="hjje" property="invoiceAmount"/>
		<result column="bcjjkcse" property="bcjjkcse"/>
	</resultMap>

	<select databaseId="mysql" id="selectNcpJjkcInvoiceHj" resultType="com.dxhy.api.model.ncp.ncpInvoice.TDxRecordInvoiceNcpVo" resultMap="JjkcHjMap" >
		select
		count(1) hjsl,sum(t.invoice_amount) hjje,sum(t.tax_amount) hjse,sum(ncp.sykjjkcse) sykjjkcse
		from t_dx_invoice_ncp ncp left join t_dx_record_invoice t on t.uuid = ncp.uuid
		WHERE t.company = #{company} and ncp.invoice_date between #{kpksrq} and #{kpjsrq}
		and t.gf_tax_no in
		<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>

		<if test="invoiceCode != null and invoiceCode != '' and invoiceCode != 'null' ">
			and ncp.invoice_code = #{invoiceCode}
		</if>
		<if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
			and ncp.invoice_no = #{invoiceNo}
		</if>
		<if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
			and t.ele_invoice_no = #{eleInvoiceNo}
		</if>

		<if test="invoiceSource != null and invoiceSource != '' and invoiceSource != 'null' and invoiceSource != '99' ">
			and t.invoice_source = #{invoiceSource}
		</if>
		<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99'">
			and t.invoice_type = #{invoiceType}
		</if>

		<if test="uuids != null and uuids.size() > 0">
			and ncp.uuid in
			<foreach collection="uuids" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<if test="notInFphmList != null and notInFphmList.size() > 0">
			and ncp.invoice_no not in
			<foreach collection="notInFphmList" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		and ncp.sfqsqbbjj = '0' and ncp.sykjjkcse &gt; 0 and t.invoice_status in ('0','7') and t.lq_hzsdbs = 'N' and t.glzt in ('0','2')
		<!--认证条件，必须是认证的，且没撤销申请-->
		and rzh_yesorno = '1' and auth_status = 4 and rzlx = 1  and cxrz_status in (0,5)
	</select>

	<select databaseId="oracle" id="selectNcpJjkcInvoiceHj" resultType="com.dxhy.api.model.ncp.ncpInvoice.TDxRecordInvoiceNcpVo" resultMap="JjkcHjMap" >
		select
		count(1) hjsl,sum(t.invoice_amount) hjje,sum(t.tax_amount) hjse,sum(ncp.sykjjkcse) sykjjkcse
		from t_dx_invoice_ncp ncp left join t_dx_record_invoice t on t.uuid = ncp.uuid
		WHERE t.company = #{company} and ncp.invoice_date between to_date(#{kpksrq},'yyyy-mm-dd hh24:mi:ss') and to_date(#{kpjsrq},'yyyy-mm-dd hh24:mi:ss')
		and t.gf_tax_no in
		<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>

		<if test="invoiceCode != null and invoiceCode != '' and invoiceCode != 'null' ">
			and ncp.invoice_code = #{invoiceCode}
		</if>
		<if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
			and ncp.invoice_no = #{invoiceNo}
		</if>
		<if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
			and t.ele_invoice_no = #{eleInvoiceNo}
		</if>

		<if test="invoiceSource != null and invoiceSource != '' and invoiceSource != 'null' and invoiceSource != '99' ">
			and t.invoice_source = #{invoiceSource}
		</if>
		<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99'">
			and t.invoice_type = #{invoiceType}
		</if>

		<if test="uuids != null and uuids.size() > 0">
			and ncp.uuid in
			<foreach collection="uuids" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<if test="notInFphmList != null and notInFphmList.size() > 0">
			and ncp.invoice_no not in
			<foreach collection="notInFphmList" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		and ncp.sfqsqbbjj = '0' and ncp.sykjjkcse &gt; 0 and t.invoice_status in ('0','7') and t.lq_hzsdbs = 'N' and t.glzt in ('0','2')
		<!--认证条件，必须是认证的，且没撤销申请-->
		and rzh_yesorno = '1' and auth_status = 4 and rzlx = 1  and cxrz_status in (0,5)
	</select>

	<select databaseId="mysql" id="selectNcpJjkcInvoiceList"  parameterType="java.util.Map"
			resultMap="BaseResultMap">
			select
		t.invoice_code,t.invoice_no,t.ele_invoice_no eleInvoiceNo,DATE_FORMAT(t.invoice_date,'%Y-%m-%d') kprq,t.gf_tax_no
		gfsh,t.gf_name gfmc,
		t.xf_tax_no,t.xf_name,t.tax_amount,t.dk_tax_amount,t.invoice_status,t.invoice_amount,DATE_FORMAT(t.rzh_date,'%Y-%m-%d')
		rzh_date ,DATE_FORMAT(t.qs_date,'%Y-%m-%d') qs_date,t.rzh_type,t.dept_id deptId,
		t.gx_user_name,t.rzh_belong_date
		dqskssq,t.auth_status,t.qs_type,t.qs_status,t.confirm_user,t.qs_name,t.rzh_yesorno,
		t.invoice_type , t.dept_name deptName,t.glzt
		glzt,t.uuid,t.bdk_status,t.scan_id,t.in_account_status,t.settle_source,
		t.settlement_no,
		t.settlement_status,t.voucher_number,t.total_amount,

		ncp.ncpfpcllx,ncp.dqsqqrclzt,ncp.jdqrzt,ncp.jdqrlx,ncp.kjjkcse,ncp.sykjjkcse,
		ncp.ncpbfje,ncp.ncpbfse,ncp.yxdkse,ncp.qrsbyy,DATE_FORMAT(ncp.qrsj,'%Y-%m-%d %H:%i:%s') qrsj,qrr
		from t_dx_invoice_ncp ncp left join t_dx_record_invoice t on t.uuid = ncp.uuid
		WHERE t.company = #{company} and ncp.invoice_date between #{kpksrq} and #{kpjsrq}
		and t.gf_tax_no in
		<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>

		<if test="invoiceCode != null and invoiceCode != '' and invoiceCode != 'null' ">
			and ncp.invoice_code = #{invoiceCode}
		</if>
		<if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
			and ncp.invoice_no = #{invoiceNo}
		</if>
		<if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
			and t.ele_invoice_no = #{eleInvoiceNo}
		</if>

		<if test="invoiceSource != null and invoiceSource != '' and invoiceSource != 'null' and invoiceSource != '99' ">
			and t.invoice_source = #{invoiceSource}
		</if>
		<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99'">
			and t.invoice_type = #{invoiceType}
		</if>

		<if test="uuids != null and uuids.size() > 0">
			and ncp.uuid in
			<foreach collection="uuids" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<if test="notInFphmList != null and notInFphmList.size() > 0">
			and ncp.invoice_no not in
			<foreach collection="notInFphmList" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		and ncp.sfqsqbbjj = '0' and ncp.sykjjkcse &gt; 0 and t.invoice_status in ('0','7') and t.lq_hzsdbs = 'N' and t.glzt in ('0','2')
		<!--认证条件，必须是认证的，且没撤销申请-->
		and rzh_yesorno = '1' and auth_status = 4 and rzlx = 1  and cxrz_status in (0,5)

		order by t.invoice_date desc
	</select>

	<select databaseId="oracle" id="selectNcpJjkcInvoiceList"  parameterType="java.util.Map"
			resultMap="BaseResultMap">
		select
		t.invoice_code,t.invoice_no,t.ele_invoice_no eleInvoiceNo,TO_CHAR(t.invoice_date, 'yyyy-MM-dd') kprq,t.gf_tax_no
		gfsh,t.gf_name gfmc,
		t.xf_tax_no,t.xf_name,t.tax_amount,t.dk_tax_amount,t.invoice_status,t.invoice_amount,TO_CHAR(t.rzh_date, 'yyyy-MM-dd')
		rzh_date ,TO_CHAR(t.qs_date, 'yyyy-MM-dd') qs_date,t.rzh_type,t.dept_id deptId,
		t.gx_user_name,t.rzh_belong_date
		dqskssq,t.auth_status,t.qs_type,t.qs_status,t.confirm_user,t.qs_name,t.rzh_yesorno,
		t.invoice_type , t.dept_name deptName,t.glzt
		glzt,t.uuid,t.bdk_status,t.scan_id,t.in_account_status,t.settle_source,
		t.settlement_no,
		t.settlement_status,t.voucher_number,t.total_amount,

		ncp.ncpfpcllx,ncp.dqsqqrclzt,ncp.jdqrzt,ncp.jdqrlx,ncp.kjjkcse,ncp.sykjjkcse,
		ncp.ncpbfje,ncp.ncpbfse,ncp.yxdkse,ncp.qrsbyy,TO_CHAR(ncp.qrsj, 'yyyy-MM-dd') qrsj,qrr
		from t_dx_invoice_ncp ncp left join t_dx_record_invoice t on t.uuid = ncp.uuid
		WHERE t.company = #{company} and ncp.invoice_date between to_date(#{kpksrq},'yyyy-mm-dd hh24:mi:ss') and to_date(#{kpjsrq},'yyyy-mm-dd hh24:mi:ss')
		and t.gf_tax_no in
		<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>

		<if test="invoiceCode != null and invoiceCode != '' and invoiceCode != 'null' ">
			and ncp.invoice_code = #{invoiceCode}
		</if>
		<if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
			and ncp.invoice_no = #{invoiceNo}
		</if>
		<if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
			and t.ele_invoice_no = #{eleInvoiceNo}
		</if>

		<if test="invoiceSource != null and invoiceSource != '' and invoiceSource != 'null' and invoiceSource != '99' ">
			and t.invoice_source = #{invoiceSource}
		</if>
		<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99'">
			and t.invoice_type = #{invoiceType}
		</if>

		<if test="uuids != null and uuids.size() > 0">
			and ncp.uuid in
			<foreach collection="uuids" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<if test="notInFphmList != null and notInFphmList.size() > 0">
			and ncp.invoice_no not in
			<foreach collection="notInFphmList" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		and ncp.sfqsqbbjj = '0' and ncp.sykjjkcse &gt; 0 and t.invoice_status in ('0','7') and t.lq_hzsdbs = 'N' and t.glzt in ('0','2')
		<!--认证条件，必须是认证的，且没撤销申请-->
		and rzh_yesorno = '1' and auth_status = 4 and rzlx = 1  and cxrz_status in (0,5)

		order by t.invoice_date desc
	</select>

	<!--查找发票信息，通过uuid-->
    <select id="selectNcpXsInvoiceByUuid"
			resultMap="BaseResultMap">
			select
		t.invoice_code,t.invoice_no,t.ele_invoice_no eleInvoiceNo,DATE_FORMAT(t.invoice_date,'%Y-%m-%d') kprq,t.gf_tax_no
		gfsh,t.gf_name gfmc,
		t.xf_tax_no,t.xf_name,t.tax_amount,t.dk_tax_amount,t.invoice_status,t.invoice_amount,DATE_FORMAT(t.rzh_date,'%Y-%m-%d')
		rzh_date ,DATE_FORMAT(t.qs_date,'%Y-%m-%d') qs_date,t.rzh_type,t.dept_id deptId,
		t.gx_user_name,t.rzh_belong_date
		dqskssq,t.auth_status,t.qs_type,t.qs_status,t.confirm_user,t.qs_name,t.rzh_yesorno,
		t.invoice_type , t.dept_name deptName,t.glzt
		glzt,t.uuid,t.bdk_status,t.scan_id,t.in_account_status,t.settle_source,
		t.settlement_no,
		t.settlement_status,t.voucher_number,t.total_amount,
		ncp.ncpfpcllx,ncp.dqsqqrclzt,ncp.ncpbfje,ncp.yxdkse,ncp.qrsbyy,DATE_FORMAT(ncp.qrsj,'%Y-%m-%d %H:%i:%s') qrsj,qrr
		from t_dx_invoice_ncp ncp left join t_dx_record_invoice t on t.uuid = ncp.uuid
		where ncp.uuid = #{uuid}
	</select>

	<!--通过uuid批量查找-->
	<select id="selectNcpXsInvoiceByUuids"
			resultMap="BaseResultMap">
			select
		t.invoice_code,t.invoice_no,t.ele_invoice_no eleInvoiceNo,DATE_FORMAT(t.invoice_date,'%Y-%m-%d') kprq,t.gf_tax_no
		gfsh,t.gf_name gfmc,
		t.xf_tax_no,t.xf_name,t.tax_amount,t.dk_tax_amount,t.invoice_status,t.invoice_amount,DATE_FORMAT(t.rzh_date,'%Y-%m-%d')
		rzh_date ,DATE_FORMAT(t.qs_date,'%Y-%m-%d') qs_date,t.rzh_type,t.dept_id deptId,
		t.gx_user_name,t.rzh_belong_date
		dqskssq,t.auth_status,t.qs_type,t.qs_status,t.confirm_user,t.qs_name,t.rzh_yesorno,
		t.invoice_type , t.dept_name deptName,t.glzt
		glzt,t.uuid,t.bdk_status,t.scan_id,t.in_account_status,t.settle_source,
		t.settlement_no,
		t.settlement_status,t.voucher_number,t.total_amount,
		ncp.ncpfpcllx,ncp.dqsqqrclzt,ncp.ncpbfje,ncp.yxdkse,ncp.qrsbyy,DATE_FORMAT(ncp.qrsj,'%Y-%m-%d %H:%i:%s') qrsj,qrr
		from t_dx_invoice_ncp ncp left join t_dx_record_invoice t on t.uuid = ncp.uuid
		where 1=1
		<if test="uuids != null and uuids.size() > 0">
			and t.uuid in
			<foreach collection="uuids" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
	</select>


	<!--农产品加计扣除结果-->
	<select databaseId="mysql" id="selectNcpJjkcResultHj" resultType="com.dxhy.api.model.ncp.ncpJjkcInvoice.TDxRecordInvoiceNcpJjkcVo" resultMap="BbfpzhcxhjResultMap" >
		select
		count(1) hjsl,sum(ncp.invoice_amount) hjje,sum(ncp.tax_amount) hjse,sum(t.bcjjkcse) bcjjkcse
		from t_dx_invoice_ncp_jjkc t left join t_dx_invoice_ncp ncp on t.uuid = ncp.uuid
		left join t_dx_record_invoice record on t.uuid=record.uuid
		WHERE ncp.invoice_date between #{kpksrq} and #{kpjsrq}
		and t.gf_tax_no in
		<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>

		<if test="invoiceCode != null and invoiceCode != '' and invoiceCode != 'null' ">
			and ncp.invoice_code = #{invoiceCode}
		</if>
		<if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
			and ncp.invoice_no = #{invoiceNo}
		</if>
		<if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
			and t.ele_invoice_no = #{eleInvoiceNo}
		</if>
		<if test="invoiceSource != null and invoiceSource != '' and invoiceSource != 'null' and invoiceSource != '99' ">
			and t.invoice_source = #{invoiceSource}
		</if>
		<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99'">
			and record.invoice_type = #{invoiceType}
		</if>

		<if test="uuids != null and uuids.size() > 0">
			and t.uuid in
			<foreach collection="uuids" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<if test="notInFphmList != null and notInFphmList.size() > 0">
			and invoice_no not in
			<foreach collection="notInFphmList" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<!--加计处理状态-->
		<if test="clzt != null and clzt != '' and clzt != 'null' and clzt != '99'">
			and t.clzt = #{clzt}
		</if>

		<!--申请类型-->
		<if test="sqlx != null and sqlx != '' and sqlx != 'null' and sqlx != '99'">
			and t.sqlx = #{sqlx}
		</if>

		<!--加计所属期-->
		<if test="jjssq != null and jjssq != '' and jjssq != 'null' and jjssq != '99'">
			and t.jjssq = #{jjssq}
		</if>
	</select>

	<select databaseId="oracle" id="selectNcpJjkcResultHj" resultType="com.dxhy.api.model.ncp.ncpJjkcInvoice.TDxRecordInvoiceNcpJjkcVo" resultMap="BbfpzhcxhjResultMap" >
		select
		count(1) hjsl,sum(ncp.invoice_amount) hjje,sum(ncp.tax_amount) hjse,sum(t.bcjjkcse) bcjjkcse
		from t_dx_invoice_ncp_jjkc t left join t_dx_invoice_ncp ncp on t.uuid = ncp.uuid
		left join t_dx_record_invoice record on t.uuid=record.uuid
		WHERE ncp.invoice_date between  to_date(#{kpksrq},'yyyy-mm-dd hh24:mi:ss') and to_date(#{kpjsrq},'yyyy-mm-dd hh24:mi:ss')
		and t.gf_tax_no in
		<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>

		<if test="invoiceCode != null and invoiceCode != '' and invoiceCode != 'null' ">
			and ncp.invoice_code = #{invoiceCode}
		</if>
		<if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
			and ncp.invoice_no = #{invoiceNo}
		</if>
		<if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
			and t.ele_invoice_no = #{eleInvoiceNo}
		</if>
		<if test="invoiceSource != null and invoiceSource != '' and invoiceSource != 'null' and invoiceSource != '99' ">
			and t.invoice_source = #{invoiceSource}
		</if>
		<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99'">
			and record.invoice_type = #{invoiceType}
		</if>

		<if test="uuids != null and uuids.size() > 0">
			and t.uuid in
			<foreach collection="uuids" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<if test="notInFphmList != null and notInFphmList.size() > 0">
			and invoice_no not in
			<foreach collection="notInFphmList" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<!--加计处理状态-->
		<if test="clzt != null and clzt != '' and clzt != 'null' and clzt != '99'">
			and t.clzt = #{clzt}
		</if>

		<!--申请类型-->
		<if test="sqlx != null and sqlx != '' and sqlx != 'null' and sqlx != '99'">
			and t.sqlx = #{sqlx}
		</if>

		<!--加计所属期-->
		<if test="jjssq != null and jjssq != '' and jjssq != 'null' and jjssq != '99'">
			and t.jjssq = #{jjssq}
		</if>
	</select>


	<select databaseId="mysql" id="selectNcpJjkcResultList"  parameterType="java.util.Map"
			resultMap="BaseJjkcResultMap">
		select
		t.id,t.invoice_code,t.invoice_no,t.ele_invoice_no,t.gf_tax_no,t.uuid,t.jjssq,t.bcjjkcse,t.sqlx,t.clzt,t.sbyy,DATE_FORMAT(t.czsj,'%Y-%m-%d') czsj,DATE_FORMAT(t.gxsj,'%Y-%m-%d') gxsj,t.czr,t.update_time,t.create_time,
		ncp.invoice_amount,ncp.kjjkcse,ncp.sykjjkcse,ncp.invoice_type,DATE_FORMAT(ncp.invoice_date,'%Y-%m-%d') invoice_date,ncp.gf_name,ncp.xf_name,ncp.xf_tax_no,
		record.lq_tdyslxDm lqTdyslxDm,record.invoice_status,record.glzt,record.lq_hzsdbs,record.lq_cpyycbs,record.lq_jdcycbs
		from t_dx_invoice_ncp_jjkc t left join t_dx_invoice_ncp ncp on t.uuid = ncp.uuid
		left join t_dx_record_invoice record on t.uuid=record.uuid
		WHERE
		t.gf_tax_no in
		<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>
		<if test="kpksrq!=null and kpksrq!='' ">
			and ncp.invoice_date &gt;= #{kpksrq}
		</if>
		<if test="kpjsrq!=null and kpjsrq!='' ">
			and ncp.invoice_date &lt;= #{kpjsrq}
		</if>

		<if test="invoiceCode != null and invoiceCode != '' and invoiceCode != 'null' ">
			and ncp.invoice_code = #{invoiceCode}
		</if>
		<if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
			and ncp.invoice_no = #{invoiceNo}
		</if>
		<if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
			and t.ele_invoice_no = #{eleInvoiceNo}
		</if>
		<if test="invoiceSource != null and invoiceSource != '' and invoiceSource != 'null' and invoiceSource != '99' ">
			and t.invoice_source = #{invoiceSource}
		</if>
		<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99'">
			and record.invoice_type = #{invoiceType}
		</if>

		<if test="uuids != null and uuids.size() > 0">
			and t.uuid in
			<foreach collection="uuids" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<if test="notInFphmList != null and notInFphmList.size() > 0">
			and invoice_no not in
			<foreach collection="notInFphmList" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<!--加计处理状态-->
		<if test="clzt != null and clzt != '' and clzt != 'null' and clzt != '99'">
			and t.clzt = #{clzt}
		</if>

		<!--申请类型-->
		<if test="sqlx != null and sqlx != '' and sqlx != 'null' and sqlx != '99'">
			and t.sqlx = #{sqlx}
		</if>

		<!--加计所属期-->
		<if test="jjssq != null and jjssq != '' and jjssq != 'null' and jjssq != '99'">
			and t.jjssq = #{jjssq}
		</if>

		<!--税款所属期-->
		<if test="skssq != null and skssq != '' and skssq != 'null' ">
			and record.rzh_belong_date = #{skssq}
		</if>
		<!--认证类型-->
		<if test="rzlx != null and rzlx != '' and rzlx != 'null' and rzlx != '99'">
			and record.rzlx = #{rzlx}
		</if>
		<!--认证状态-->
		<if test="authStatus != null and authStatus != '' and authStatus != 'null'  and authStatus != '99'">
			and record.auth_status = #{authStatus}
		</if>

		order by ncp.invoice_date desc
	</select>

	<select databaseId="oracle" id="selectNcpJjkcResultList"  parameterType="java.util.Map"
			resultMap="BaseJjkcResultMap">
		select
		t.id,t.invoice_code,t.invoice_no,t.ele_invoice_no,t.gf_tax_no,t.uuid,t.jjssq,t.bcjjkcse,t.sqlx,t.clzt,t.sbyy,TO_CHAR(t.czsj, 'yyyy-MM-dd') czsj,
		TO_CHAR(t.gxsj, 'yyyy-MM-dd') gxsj,t.czr,t.update_time,t.create_time,
		ncp.invoice_amount,ncp.kjjkcse,ncp.sykjjkcse,ncp.invoice_type,TO_CHAR(ncp.invoice_date, 'yyyy-MM-dd') invoice_date,ncp.gf_name,ncp.xf_name,ncp.xf_tax_no,
		record.lq_tdyslxDm lqTdyslxDm,record.invoice_status,record.glzt,record.lq_hzsdbs,record.lq_cpyycbs,record.lq_jdcycbs
		from t_dx_invoice_ncp_jjkc t left join t_dx_invoice_ncp ncp on t.uuid = ncp.uuid
		left join t_dx_record_invoice record on t.uuid=record.uuid
		WHERE
		t.gf_tax_no in
		<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>

		<if test="kpksrq!=null and kpksrq!='' ">
			and ncp.invoice_date &gt;= to_date(#{kpksrq},'yyyy-mm-dd hh24:mi:ss')
		</if>
		<if test="kpjsrq!=null and kpjsrq!='' ">
			and ncp.invoice_date &lt;= to_date(#{kpjsrq},'yyyy-mm-dd hh24:mi:ss')
		</if>

		<if test="invoiceCode != null and invoiceCode != '' and invoiceCode != 'null' ">
			and ncp.invoice_code = #{invoiceCode}
		</if>
		<if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
			and ncp.invoice_no = #{invoiceNo}
		</if>
		<if test="eleInvoiceNo!=null and eleInvoiceNo!='' and eleInvoiceNo!='null'">
			and t.ele_invoice_no = #{eleInvoiceNo}
		</if>
		<if test="invoiceSource != null and invoiceSource != '' and invoiceSource != 'null' and invoiceSource != '99' ">
			and t.invoice_source = #{invoiceSource}
		</if>
		<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99'">
			and record.invoice_type = #{invoiceType}
		</if>

		<if test="uuids != null and uuids.size() > 0">
			and t.uuid in
			<foreach collection="uuids" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<if test="notInFphmList != null and notInFphmList.size() > 0">
			and invoice_no not in
			<foreach collection="notInFphmList" index="index" item="item"
					 open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>

		<!--加计处理状态-->
		<if test="clzt != null and clzt != '' and clzt != 'null' and clzt != '99'">
			and t.clzt = #{clzt}
		</if>

		<!--申请类型-->
		<if test="sqlx != null and sqlx != '' and sqlx != 'null' and sqlx != '99'">
			and t.sqlx = #{sqlx}
		</if>

		<!--加计所属期-->
		<if test="jjssq != null and jjssq != '' and jjssq != 'null' and jjssq != '99'">
			and t.jjssq = #{jjssq}
		</if>

		<!--税款所属期-->
		<if test="skssq != null and skssq != '' and skssq != 'null' ">
			and record.rzh_belong_date = #{skssq}
		</if>
		<!--认证类型-->
		<if test="rzlx != null and rzlx != '' and rzlx != 'null' and rzlx != '99'">
			and record.rzlx = #{rzlx}
		</if>
		<!--认证状态-->
		<if test="authStatus != null and authStatus != '' and authStatus != 'null'  and authStatus != '99'">
			and record.auth_status = #{authStatus}
		</if>

		order by ncp.invoice_date desc
	</select>


</mapper>