<?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.ruoyi.invest.mapper.DebitInforsMapper">

    <resultMap type="DebitInforsVo" id="DebitInforsResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="lenders"    column="lenders"    />
        <result property="applicableCustomerGroups"    column="applicable_customer_groups"    />
        <result property="requiredMaterials"    column="required_materials"    />
        <result property="creditConditions"    column="credit_conditions"    />
        <result property="lendingRate"    column="lending_rate"    />
        <result property="loanTerm"    column="loan_term"    />
        <result property="repaymentMethod"    column="repayment_method"    />
        <result property="loanLimit"    column="loan_limit"    />
        <result property="loanPurpose"    column="loan_purpose"    />
        <result property="applyMethod"    column="apply_method"    />
        <result property="creditQueryCount"    column="credit_query_count"    />
        <result property="debtCount"    column="debt_count"    />
        <result property="creditCardCount"    column="credit_card_count"    />
        <result property="creditCardUsageRate"    column="credit_card_usage_rate"    />
        <result property="loanBalance"    column="loan_balance"    />
        <result property="debtRequirements"    column="debt_requirements"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectDebitInforsVo">
        select a.id, a.name, a.type, a.lenders, a.applicable_customer_groups, a.required_materials, a.credit_conditions, a.lending_rate, a.loan_term, a.repayment_method, a.loan_limit, a.loan_purpose, a.apply_method, a.credit_query_count, a.debt_count, a.credit_card_count, a.credit_card_usage_rate, a.loan_balance, a.debt_requirements, a.create_by, a.create_time, a.update_by, a.update_time, a.del_flag, a.remark from debit_infors a
    </sql>

    <select id="selectDebitInforsList" parameterType="DebitInforsDto" resultMap="DebitInforsResult">
        <include refid="selectDebitInforsVo"/>
        <where>
            a.del_flag='0'
            <if test="name != null  and name != ''"> and a.name like '%'|| #{name}||'%'</if>
            <if test="type != null  and type != ''"> and a.type = #{type}</if>
            <if test="lenders != null  and lenders != ''"> and a.lenders = #{lenders}</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by a.create_time desc
    </select>

    <select id="selectDebitInforsById" parameterType="Long" resultMap="DebitInforsResult">
        <include refid="selectDebitInforsVo"/>
        where a.id = #{id}
    </select>

    <insert id="insertDebitInfors" parameterType="DebitInfors">
        insert into debit_infors
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="type != null">type,</if>
            <if test="lenders != null and lenders != ''">lenders,</if>
            <if test="applicableCustomerGroups != null">applicable_customer_groups,</if>
            <if test="requiredMaterials != null">required_materials,</if>
            <if test="creditConditions != null">credit_conditions,</if>
            <if test="lendingRate != null">lending_rate,</if>
            <if test="loanTerm != null">loan_term,</if>
            <if test="repaymentMethod != null">repayment_method,</if>
            <if test="loanLimit != null">loan_limit,</if>
            <if test="loanPurpose != null">loan_purpose,</if>
            <if test="applyMethod != null">apply_method,</if>
            <if test="creditQueryCount != null">credit_query_count,</if>
            <if test="debtCount != null">debt_count,</if>
            <if test="creditCardCount != null">credit_card_count,</if>
            <if test="creditCardUsageRate != null">credit_card_usage_rate,</if>
            <if test="loanBalance != null">loan_balance,</if>
            <if test="debtRequirements != null">debt_requirements,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="lenders != null and lenders != ''">#{lenders},</if>
            <if test="applicableCustomerGroups != null">#{applicableCustomerGroups},</if>
            <if test="requiredMaterials != null">#{requiredMaterials},</if>
            <if test="creditConditions != null">#{creditConditions},</if>
            <if test="lendingRate != null">#{lendingRate},</if>
            <if test="loanTerm != null">#{loanTerm},</if>
            <if test="repaymentMethod != null">#{repaymentMethod},</if>
            <if test="loanLimit != null">#{loanLimit},</if>
            <if test="loanPurpose != null">#{loanPurpose},</if>
            <if test="applyMethod != null">#{applyMethod},</if>
            <if test="creditQueryCount != null">#{creditQueryCount},</if>
            <if test="debtCount != null">#{debtCount},</if>
            <if test="creditCardCount != null">#{creditCardCount},</if>
            <if test="creditCardUsageRate != null">#{creditCardUsageRate},</if>
            <if test="loanBalance != null">#{loanBalance},</if>
            <if test="debtRequirements != null">#{debtRequirements},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateDebitInfors" parameterType="DebitInfors">
        update debit_infors
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="lenders != null and lenders != ''">lenders = #{lenders},</if>
            <if test="applicableCustomerGroups != null">applicable_customer_groups = #{applicableCustomerGroups},</if>
            <if test="requiredMaterials != null">required_materials = #{requiredMaterials},</if>
            <if test="creditConditions != null">credit_conditions = #{creditConditions},</if>
            <if test="lendingRate != null">lending_rate = #{lendingRate},</if>
            <if test="loanTerm != null">loan_term = #{loanTerm},</if>
            <if test="repaymentMethod != null">repayment_method = #{repaymentMethod},</if>
            <if test="loanLimit != null">loan_limit = #{loanLimit},</if>
            <if test="loanPurpose != null">loan_purpose = #{loanPurpose},</if>
            <if test="applyMethod != null">apply_method = #{applyMethod},</if>
            <if test="creditQueryCount != null">credit_query_count = #{creditQueryCount},</if>
            <if test="debtCount != null">debt_count = #{debtCount},</if>
            <if test="creditCardCount != null">credit_card_count = #{creditCardCount},</if>
            <if test="creditCardUsageRate != null">credit_card_usage_rate = #{creditCardUsageRate},</if>
            <if test="loanBalance != null">loan_balance = #{loanBalance},</if>
            <if test="debtRequirements != null">debt_requirements = #{debtRequirements},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDebitInforsById" parameterType="Long">
        delete from debit_infors where id = #{id}
    </delete>

    <delete id="deleteDebitInforsByIds" parameterType="String">
        delete from debit_infors where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <update id="removeDebitInforsById" parameterType="Long">
         update debit_infors set del_flag='1' where id = #{id}
    </update>

    <update id="removeDebitInforsByIds" parameterType="String">
        update debit_infors set del_flag='1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
