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

    <resultMap id="BaseResultMap" type="com.dxhy.core.model.BbfpmxcxRespVO">
        <result column="invoice_code" property="invoiceCode"></result>
        <result column="invoice_no" property="invoiceNo"></result>
        <result column="kprq" property="invoiceDate"></result>
        <result column="gf_tax_no" property="gfTaxNo"></result>
        <result column="gf_name" property="gfName"></result>
        <result column="gf_address_and_phone" property="gfAddressAndPhone"></result>
        <result column="gf_bank_and_no" property="gfBankAndNo"></result>
        <result column="xf_tax_no" property="xfTaxNo"></result>
        <result column="xf_name" property="xfName"></result>
        <result column="xf_address_and_phone" property="xfAddressAndPhone"></result>
        <result column="xf_bank_and_no" property="xfBankAndNo"></result>
        <result column="remark" property="remark"></result>
        <result column="detail_no" property="detailNo"></result>
        <result column="unit" property="unit"></result>
        <result column="goods_name" property="goodsName"></result>
        <result column="model" property="model"></result>
        <result column="num" property="num"></result>
        <result column="unit_price" property="unitPrice"></result>
        <result column="detail_amount" property="detailAmount"></result>
        <result column="tax_rate" property="taxRate"></result>
        <result column="tax_amount" property="taxAmount"></result>
        <result column="invoice_type" property="invoiceType"></result>
    </resultMap>

  <select id="selectByPramsMap" parameterType="java.util.Map" resultMap="BaseResultMap" databaseId="mysql">
     select
     t.invoice_code,t.invoice_no,DATE_FORMAT(t.invoice_date,'%Y-%m-%d') kprq,
     t.gf_tax_no,t.gf_name,t.gf_address_and_phone,t.gf_bank_and_no,t.invoice_type,
     t.xf_tax_no,t.xf_name,t.xf_address_and_phone,t.xf_bank_and_no,t.remark,
     b.detail_no,b.unit,b.goods_name,b.model,b.num,b.unit_price,b.detail_amount,b.tax_rate,b.tax_amount,
      b.cph,b.lx,b.txrqq,b.txrqz
    FROM
    ${dxhyTertiary}.t_dx_record_invoice t
    left join ${dxhyDetail}.t_dx_record_invoice_detail b on t.uuid = b.uuid
    where t.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=" xfmc !=null and xfmc !='' and xfmc != 'null' ">
          and t.xf_name like CONCAT(#{xfmc},'%')
      </if>
      <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
          and t.invoice_type = #{invoiceType}
      </if>
      <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null'  ">
          and t.invoice_no = #{invoiceNo}
      </if>
      <if test=" goodsName !=null and goodsName !='' and goodsName != 'null' ">
          and b.goods_name like  CONCAT('%',CONCAT(#{goodsName},'%'))
      </if>
      <if test="company !=null and company !=''">
          and t.company = #{company}
      </if>
      <if test="invoiceSource != null and invoiceSource != '' and invoiceSource != 'null' and invoiceSource != '99' ">
          and t.invoice_source = #{invoiceSource}
      </if>
      order by t.invoice_date desc,b.id
  </select>

    <select id="selectByPramsMap" parameterType="java.util.Map" resultMap="BaseResultMap" databaseId="oracle">
        select
        t.invoice_code,t.invoice_no,to_char(t.invoice_date,'yyyy-mm-dd') kprq,
        t.gf_tax_no,t.gf_name,t.gf_address_and_phone,t.gf_bank_and_no,t.invoice_type,
        t.xf_tax_no,t.xf_name,t.xf_address_and_phone,t.xf_bank_and_no,t.remark,
        b.detail_no,b.unit,b.goods_name,b.model,b.num,b.unit_price,b.detail_amount,b.tax_rate,b.tax_amount,
        b.cph,b.lx,b.txrqq,b.txrqz
        FROM
        ${dxhyTertiary}.t_dx_record_invoice t
        left join ${dxhyDetail}.t_dx_record_invoice_detail b on t.uuid = b.uuid
        where  t.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=" xfmc !=null and xfmc !='' and xfmc != 'null' ">
            and t.xf_name like CONCAT(#{xfmc},'%')
        </if>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null'  ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test=" goodsName !=null and goodsName !='' and goodsName != 'null' ">
            and b.goods_name like  CONCAT('%',CONCAT(#{goodsName},'%'))
        </if>
        <if test="company !=null and company !=''">
            and t.company = #{company}
        </if>
        <if test="invoiceSource != null and invoiceSource != '' and invoiceSource != 'null' and invoiceSource != '99' ">
            and t.invoice_source = #{invoiceSource}
        </if>
        order by t.invoice_date desc,b.id
    </select>
</mapper>
