<?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.jkcredit.invoice.mapper.binvoce.HcInvoiceMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.jkcredit.invoice.model.entity.invoice.HcInvoice">
        <result column="sellerName" property="sellerName"/>
        <result column="sellerTaxpayerCode" property="sellerTaxpayerCode"/>
        <result column="buyerName" property="buyerName"/>
        <result column="buyerTaxpayerCode" property="buyerTaxpayerCode"/>
        <result column="amount" property="amount"/>
        <result column="rawInvoiceId" property="rawInvoiceId"/>
        <result column="rawInvoiceCode" property="rawInvoiceCode"/>
        <result column="rawInvoiceNum" property="rawInvoiceNum"/>
        <result column="invoiceCode" property="invoiceCode"/>
        <result column="invoiceNum" property="invoiceNum"/>
        <result column="invoiceUrl" property="invoiceUrl"/>
        <result column="yearMonth" property="yearMonth"/>
    </resultMap>

    <sql id="baseSql">
        sellerName,
        sellerTaxpayerCode,
        buyerName,
        buyerTaxpayerCode,
        amount,
        rawInvoiceId,
        rawInvoiceCode,
        rawInvoiceNum,
        invoiceCode,
        invoiceNum,
        invoiceUrl,
        yearMonth
    </sql>

    <select id="selectAllByPage" resultMap="BaseResultMap">
        select
        <include refid="baseSql" />
        from t_hcinvoice
        where yearMonth = #{hcInvoice.yearMonth,jdbcType=VARCHAR}
              and  buyerTaxpayerCode = BINARY #{hcInvoice.buyerTaxpayerCode,jdbcType=VARCHAR}
    </select>
    <select id="selectInvoiceByCondition" parameterType="com.jkcredit.invoice.model.entity.invoice.HcInvoice" resultMap="BaseResultMap">
        select
        <include refid="baseSql" />
        from t_hcinvoice
        where yearMonth = #{yearMonth,jdbcType=VARCHAR}
        <if test="buyerName != null and buyerName != ''">
            and  buyerName = BINARY #{buyerName,jdbcType=VARCHAR}
        </if>
        <if test="buyerTaxpayerCode != null and buyerTaxpayerCode != ''">
            and  buyerTaxpayerCode = BINARY #{buyerTaxpayerCode,jdbcType=VARCHAR}
        </if>
    </select>
    <insert id="insertHcInvoice" parameterType="com.jkcredit.invoice.model.entity.invoice.HcInvoice">
        INSERT INTO t_hcinvoice (<include refid="baseSql"></include>)
         VALUES (   #{sellerName,jdbcType=VARCHAR},
                    #{sellerTaxpayerCode,jdbcType=VARCHAR},
                    #{buyerName,jdbcType=VARCHAR},
                    #{buyerTaxpayerCode,jdbcType=VARCHAR},
                    #{amount,jdbcType=INTEGER},
                    #{rawInvoiceId,jdbcType=VARCHAR},
                    #{rawInvoiceCode,jdbcType=VARCHAR},
                    #{rawInvoiceNum,jdbcType=VARCHAR},
                    #{invoiceCode,jdbcType=VARCHAR},
                    #{invoiceNum,jdbcType=VARCHAR},
                    #{invoiceUrl,jdbcType=VARCHAR},
                    #{yearMonth,jdbcType=VARCHAR}
        )
    </insert>
    <delete id="deleteByMounth" parameterType="java.lang.String">
        DELETE  from t_hcinvoice where yearMonth = #{yearMonth,jdbcType=VARCHAR}
    </delete>
</mapper>
