<?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.RepayPlanMapper">
    <select id="findByDrawCode" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Table_Base_Column_List"/>
        from t_repay_plan inner join t_repay on t_repay_plan.repay_code = t_repay.code
        where draw_code = #{drawCode}
    </select>
    <insert id="insertItems" parameterType="java.util.List">
        insert into t_repay_plan
        (
        code,
        repay_code,
        repay_date,
        should_repay_interest,
        should_repay_principal,
        should_repay_total,
        periods_number
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.code},
            #{item.repayCode},
            #{item.repayDate},
            #{item.shouldRepayInterest},
            #{item.shouldRepayPrincipal},
            #{item.shouldRepayTotal},
            #{item.periodsNumber}
            )
        </foreach>

    </insert>

    <insert id="insertAllSelective" parameterType="collection">
        <foreach collection="collection" item="item" index="index" separator=";">
            insert into t_repay_plan
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="item.code != null">
                    code,
                </if>
                <if test="item.repayCode != null">
                    repay_code,
                </if>
                <if test="item.repayDate != null">
                    repay_date,
                </if>
                <if test="item.shouldRepayInterest != null">
                    should_repay_interest,
                </if>
                <if test="item.shouldRepayPrincipal != null">
                    should_repay_principal,
                </if>
                <if test="item.shouldRepayTotal != null">
                    should_repay_total,
                </if>
                <if test="item.periodsNumber != null">
                    periods_number,
                </if>
                <if test="item.status != null">
                    status,
                </if>
            </trim>
            values
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="item.code != null">
                    #{item.code},
                </if>
                <if test="item.repayCode != null">
                    #{item.repayCode},
                </if>
                <if test="item.repayDate != null">
                    #{item.repayDate},
                </if>
                <if test="item.shouldRepayInterest != null">
                    #{item.shouldRepayInterest},
                </if>
                <if test="item.shouldRepayPrincipal != null">
                    #{item.shouldRepayPrincipal},
                </if>
                <if test="item.shouldRepayTotal != null">
                    #{item.shouldRepayTotal},
                </if>
                <if test="item.periodsNumber != null">
                    #{item.periodsNumber},
                </if>
                <if test="item.status != null">
                    #{item.status},
                </if>
            </trim>
        </foreach>
    </insert>

    <delete id="deleteAllByRepayCode">
        delete from t_repay_plan where 1=0
        <trim>
            <if test="repayCode != null">
                or repay_code = #{repayCode}
            </if>
        </trim>
    </delete>

    <select id="findByRepayCode" resultType="string" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_repay_plan where repay_code = #{repayCode}
    </select>
</mapper>