<?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="cn.superdesk.uniorder.dao.mapper.invoice.customer.fundrestream.InvoiceBankStatementMapperEx">

	<!-- 自定义部分 -->

	<resultMap id="InvoiceBankMap" type="cn.superdesk.uniorder.dto.vo.invoice.common.InvoiceBankVo">
		<id column="id" jdbcType="BIGINT" property="id"/>
		<result column="bank_name" jdbcType="VARCHAR" property="bankName"/>
		<result column="count" jdbcType="DECIMAL" property="count"/>
		<result column="no_check_count" jdbcType="DECIMAL" property="noCheckCount"/>
		<result column="enable" jdbcType="TINYINT" property="enable"/>
		<result column="status" jdbcType="TINYINT" property="status"/>
		<result column="payee" jdbcType="VARCHAR" property="payee"/>
		<result column="payee_account" jdbcType="VARCHAR" property="payeeAccount"/>
		<result column="pay_time" jdbcType="DATE" property="payTime"/>
		<result column="remark" jdbcType="VARCHAR" property="remark"/>
		<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
		<result column="back_time" jdbcType="TIMESTAMP" property="backTime"/>
	</resultMap>

	<resultMap id="InvOrderCountResultMap" type="cn.superdesk.uniorder.dto.vo.unified.UnifiedInvOrderCount">
		<result column="dz_order_id" property="dzOrderId" jdbcType="BIGINT"/>
		<result column="goods_num" property="goodNums" jdbcType="INTEGER"/>
		<result column="status_nums" property="statusNums" jdbcType="INTEGER"/>
	</resultMap>

	<select id="findAll" resultMap="cn.superdesk.uniorder.dao.mapper.invoice.customer.fundrestream.InvoiceBankStatementMapper.BaseResultMap">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.invoice.customer.fundrestream.InvoiceBankStatementMapper.Base_Column_List"/>
		from invoice_bank_statement where 1=1

		<if test="id != null ">
			and id = #{id,jdbcType=BIGINT}
		</if>
		<if test="noCheckCount != null and noCheckCount == 1">
			and no_check_count &gt; 0
		</if>
		<if test="enable != null and enable != ''">
			and `enable` = #{enable}
		</if>
		<if test="payee != null and payee != ''">
			and payee like CONCAT('%',#{payee},'%')
		</if>
		order by create_time
	</select>


	<select id="getInvOrderCount" resultMap="InvOrderCountResultMap">
select tb.dz_order_id,tc.status_nums,ta.goods_num from
(
	SELECT dz_order_id
		from invoice_apply_x_goods WHERE invoice_apply_id=#{id} GROUP BY dz_order_id
) tb
LEFT JOIN (
	SELECT count(id) as goods_num,dz_order_id from dz_order_good a GROUP BY dz_order_id
) ta on ta.dz_order_id = tb.dz_order_id
LEFT JOIN
(
	SELECT dz_order_id,sum(back_status) as  status_nums
		from invoice_apply_x_goods  GROUP BY dz_order_id
) tc on tc.dz_order_id = tb.dz_order_id
 where tc.status_nums>0

  </select>




	<select id="getBankByApplyId" resultMap="InvoiceBankMap">
    SELECT
        t2.*,t1.back_time
    FROM
        invoice_apply_x_goods t1
    RIGHT JOIN invoice_bank t2 ON t1.bank_id = t2.id
    WHERE
        t1.invoice_apply_id = #{id,jdbcType=BIGINT}
    GROUP BY
	    t2.id
  </select>

</mapper>
