<?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.system.mapper.LoanScheduleMapper">
    
    <resultMap type="LoanSchedule" id="LoanScheduleResult">
        <result property="loanScheduleId"    column="loan_schedule_id"    />
        <result property="loanApplicationId"    column="loan_application_id"    />
        <result property="loanApplicationNumber"    column="loan_application_number"    />
        <result property="loanScheduleName"    column="loan_schedule_name"    />
        <result property="loanScheduleValue"    column="loan_schedule_value"    />
        <result property="loanScheduleScore"    column="loan_schedule_score"    />
        <result property="loanScheduleTime"    column="loan_schedule_time"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectLoanScheduleVo">
        select loan_schedule_id, loan_application_id, loan_application_number, loan_schedule_name, loan_schedule_value, loan_schedule_score, loan_schedule_time, create_by, create_time, update_by, update_time, remark from loan_schedule
    </sql>

    <select id="selectLoanScheduleList" parameterType="LoanSchedule" resultMap="LoanScheduleResult">
        <include refid="selectLoanScheduleVo"/>
        <where>  
            <if test="loanApplicationId != null "> and loan_application_id = #{loanApplicationId}</if>
            <if test="loanApplicationNumber != null  and loanApplicationNumber != ''"> and loan_application_number = #{loanApplicationNumber}</if>
            <if test="loanScheduleName != null  and loanScheduleName != ''"> and loan_schedule_name like concat('%', #{loanScheduleName}, '%')</if>
            <if test="loanScheduleValue != null  and loanScheduleValue != ''"> and loan_schedule_value = #{loanScheduleValue}</if>
            <if test="loanScheduleScore != null  and loanScheduleScore != ''"> and loan_schedule_score = #{loanScheduleScore}</if>
            <if test="loanScheduleTime != null "> and loan_schedule_time = #{loanScheduleTime}</if>
        </where>
        order by create_time
    </select>
    
    <select id="selectLoanScheduleByLoanScheduleId" parameterType="Long" resultMap="LoanScheduleResult">
        <include refid="selectLoanScheduleVo"/>
        where loan_schedule_id = #{loanScheduleId}
    </select>
        
    <insert id="insertLoanSchedule" parameterType="LoanSchedule" useGeneratedKeys="true" keyProperty="loanScheduleId">
        insert into loan_schedule
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="loanApplicationId != null">loan_application_id,</if>
            <if test="loanApplicationNumber != null and loanApplicationNumber != ''">loan_application_number,</if>
            <if test="loanScheduleName != null and loanScheduleName != ''">loan_schedule_name,</if>
            <if test="loanScheduleValue != null and loanScheduleValue != ''">loan_schedule_value,</if>
            <if test="loanScheduleScore != null">loan_schedule_score,</if>
            <if test="loanScheduleTime != null">loan_schedule_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            create_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="loanApplicationId != null">#{loanApplicationId},</if>
            <if test="loanApplicationNumber != null and loanApplicationNumber != ''">#{loanApplicationNumber},</if>
            <if test="loanScheduleName != null and loanScheduleName != ''">#{loanScheduleName},</if>
            <if test="loanScheduleValue != null and loanScheduleValue != ''">#{loanScheduleValue},</if>
            <if test="loanScheduleScore != null">#{loanScheduleScore},</if>
            <if test="loanScheduleTime != null">#{loanScheduleTime},</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="remark != null">#{remark},</if>
            sysdate()
         </trim>
    </insert>

    <update id="updateLoanSchedule" parameterType="LoanSchedule">
        update loan_schedule
        <trim prefix="SET" suffixOverrides=",">
            <if test="loanApplicationId != null">loan_application_id = #{loanApplicationId},</if>
            <if test="loanApplicationNumber != null and loanApplicationNumber != ''">loan_application_number = #{loanApplicationNumber},</if>
            <if test="loanScheduleName != null and loanScheduleName != ''">loan_schedule_name = #{loanScheduleName},</if>
            <if test="loanScheduleValue != null and loanScheduleValue != ''">loan_schedule_value = #{loanScheduleValue},</if>
            <if test="loanScheduleScore != null">loan_schedule_score = #{loanScheduleScore},</if>
            <if test="loanScheduleTime != null">loan_schedule_time = #{loanScheduleTime},</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="remark != null">remark = #{remark},</if>
        </trim>
        where loan_schedule_id = #{loanScheduleId}
    </update>

    <delete id="deleteLoanScheduleByLoanScheduleId" parameterType="Long">
        delete from loan_schedule where loan_schedule_id = #{loanScheduleId}
    </delete>

    <delete id="deleteLoanScheduleByLoanScheduleIds" parameterType="String">
        delete from loan_schedule where loan_schedule_id in 
        <foreach item="loanScheduleId" collection="array" open="(" separator="," close=")">
            #{loanScheduleId}
        </foreach>
    </delete>
    <delete id="deleteLoanScheduleByLoanApplicationIdAndValue" parameterType="LoanSchedule">
        delete from loan_schedule where loan_application_id = #{loanApplicationId} and loan_schedule_value = #{value}
    </delete>
</mapper>