<?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.usoft.fin.grpc.dal.mapper.CreditMapper">

    <select id="findByEnuuAndProductCode" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_credit
        where product_code = #{productCode} and enuu = #{enuu}
    </select>
    <select id="findByEnuu" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_credit
        where enuu = #{enuu}
    </select>

    <resultMap id="CreditVOResultMap" type="com.usoft.fin.grpc.dal.entity.vo.CreditVO" extends="BaseResultMap">
        <result column="product_name" property="productName" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="findCreditVOByEnuu" resultMap="CreditVOResultMap">
        select
        <include refid="Table_Base_Column_List"/>, t_product.name as product_name
        from t_credit , t_product
        where t_credit.enuu = #{enuu} and t_credit.product_code = t_product.code
    </select>

    <update id="updateByCodeSelective" parameterType="com.usoft.fin.grpc.dal.entity.Credit">
        update t_credit
        <set>
            <if test="creditApplyCode != null">
                credit_apply_code = #{creditApplyCode,jdbcType=VARCHAR},
            </if>
            <if test="rate != null">
                rate = #{rate,jdbcType=DECIMAL},
            </if>
            <if test="replyAmount != null">
                reply_amount = #{replyAmount,jdbcType=DECIMAL},
            </if>
            <if test="usedAmount != null">
                used_amount = #{usedAmount,jdbcType=DECIMAL},
            </if>
            <if test="usableAmount != null">
                usable_amount = #{usableAmount,jdbcType=DECIMAL},
            </if>
            <if test="startDate != null">
                start_date = #{startDate,jdbc=VARCHAR},
            </if>
            <if test="endDate != null">
                end_date = #{endDate,jdbc=VARCHAR},
            </if>
        </set>
        where code = #{code,jdbcType=VARCHAR}
    </update>
    <select id="findByCode" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_credit
        where code = #{code}
    </select>


    <select id="findByCreditApplyCode" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_credit
        where credit_apply_code = #{creditApplyCode}
    </select>
</mapper>