<?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=".dao.RepayTradeCourseDao">

    <resultMap type=".entity.RepayTradeCourse" id="RepayTradeCourseMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="courseId" column="course_id" jdbcType="INTEGER"/>
        <result property="repayTradeId" column="repay_trade_id" jdbcType="INTEGER"/>
        <result property="money" column="money" jdbcType="NUMERIC"/>
        <result property="coumMoney" column="coum_money" jdbcType="NUMERIC"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="RepayTradeCourseMap">
        select
          id, course_id, repay_trade_id, money, coum_money
        from repay_trade_course
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="RepayTradeCourseMap">
        select
          id, course_id, repay_trade_id, money, coum_money
        from repay_trade_course
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="courseId != null">
                and course_id = #{courseId}
            </if>
            <if test="repayTradeId != null">
                and repay_trade_id = #{repayTradeId}
            </if>
            <if test="money != null">
                and money = #{money}
            </if>
            <if test="coumMoney != null">
                and coum_money = #{coumMoney}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from repay_trade_course
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="courseId != null">
                and course_id = #{courseId}
            </if>
            <if test="repayTradeId != null">
                and repay_trade_id = #{repayTradeId}
            </if>
            <if test="money != null">
                and money = #{money}
            </if>
            <if test="coumMoney != null">
                and coum_money = #{coumMoney}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into repay_trade_course(course_id, repay_trade_id, money, coum_money)
        values (#{courseId}, #{repayTradeId}, #{money}, #{coumMoney})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into repay_trade_course(course_id, repay_trade_id, money, coum_money)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.courseId}, #{entity.repayTradeId}, #{entity.money}, #{entity.coumMoney})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into repay_trade_course(course_id, repay_trade_id, money, coum_money)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.courseId}, #{entity.repayTradeId}, #{entity.money}, #{entity.coumMoney})
        </foreach>
        on duplicate key update
        course_id = values(course_id),
        repay_trade_id = values(repay_trade_id),
        money = values(money),
        coum_money = values(coum_money)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update repay_trade_course
        <set>
            <if test="courseId != null">
                course_id = #{courseId},
            </if>
            <if test="repayTradeId != null">
                repay_trade_id = #{repayTradeId},
            </if>
            <if test="money != null">
                money = #{money},
            </if>
            <if test="coumMoney != null">
                coum_money = #{coumMoney},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from repay_trade_course where id = #{id}
    </delete>

</mapper>

