<?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.RepayPromotionMxDao">

    <resultMap type=".entity.RepayPromotionMx" id="RepayPromotionMxMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="repayTradeId" column="repay_trade_id" jdbcType="INTEGER"/>
        <result property="accountId" column="account_id" jdbcType="INTEGER"/>
        <result property="beforePrice" column="before_price" jdbcType="NUMERIC"/>
        <result property="beforeRestMoney" column="before_rest_money" jdbcType="NUMERIC"/>
        <result property="beforeConsumeMoney" column="before_consume_money" jdbcType="NUMERIC"/>
        <result property="beforeRestCount" column="before_rest_count" jdbcType="INTEGER"/>
        <result property="beforeConsumeCount" column="before_consume_count" jdbcType="INTEGER"/>
        <result property="backPrice" column="back_price" jdbcType="NUMERIC"/>
        <result property="backRestMoney" column="back_rest_money" jdbcType="NUMERIC"/>
        <result property="backConsumeMoney" column="back_consume_money" jdbcType="NUMERIC"/>
        <result property="backRestCount" column="back_rest_count" jdbcType="INTEGER"/>
        <result property="backConsumeCount" column="back_consume_count" jdbcType="INTEGER"/>
        <result property="beforeGiftRestMoney" column="before_gift_rest_money" jdbcType="NUMERIC"/>
        <result property="beforeGiftConsumeMoney" column="before_gift_consume_money" jdbcType="NUMERIC"/>
        <result property="backGiftRestMoney" column="back_gift_rest_money" jdbcType="NUMERIC"/>
        <result property="backGiftConsumeMoney" column="back_gift_consume_money" jdbcType="NUMERIC"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="RepayPromotionMxMap">
        select
          id, repay_trade_id, account_id, before_price, before_rest_money, before_consume_money, before_rest_count, before_consume_count, back_price, back_rest_money, back_consume_money, back_rest_count, back_consume_count, before_gift_rest_money, before_gift_consume_money, back_gift_rest_money, back_gift_consume_money
        from repay_promotion_mx
        where  = #{}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="RepayPromotionMxMap">
        select
          id, repay_trade_id, account_id, before_price, before_rest_money, before_consume_money, before_rest_count, before_consume_count, back_price, back_rest_money, back_consume_money, back_rest_count, back_consume_count, before_gift_rest_money, before_gift_consume_money, back_gift_rest_money, back_gift_consume_money
        from repay_promotion_mx
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="repayTradeId != null">
                and repay_trade_id = #{repayTradeId}
            </if>
            <if test="accountId != null">
                and account_id = #{accountId}
            </if>
            <if test="beforePrice != null">
                and before_price = #{beforePrice}
            </if>
            <if test="beforeRestMoney != null">
                and before_rest_money = #{beforeRestMoney}
            </if>
            <if test="beforeConsumeMoney != null">
                and before_consume_money = #{beforeConsumeMoney}
            </if>
            <if test="beforeRestCount != null">
                and before_rest_count = #{beforeRestCount}
            </if>
            <if test="beforeConsumeCount != null">
                and before_consume_count = #{beforeConsumeCount}
            </if>
            <if test="backPrice != null">
                and back_price = #{backPrice}
            </if>
            <if test="backRestMoney != null">
                and back_rest_money = #{backRestMoney}
            </if>
            <if test="backConsumeMoney != null">
                and back_consume_money = #{backConsumeMoney}
            </if>
            <if test="backRestCount != null">
                and back_rest_count = #{backRestCount}
            </if>
            <if test="backConsumeCount != null">
                and back_consume_count = #{backConsumeCount}
            </if>
            <if test="beforeGiftRestMoney != null">
                and before_gift_rest_money = #{beforeGiftRestMoney}
            </if>
            <if test="beforeGiftConsumeMoney != null">
                and before_gift_consume_money = #{beforeGiftConsumeMoney}
            </if>
            <if test="backGiftRestMoney != null">
                and back_gift_rest_money = #{backGiftRestMoney}
            </if>
            <if test="backGiftConsumeMoney != null">
                and back_gift_consume_money = #{backGiftConsumeMoney}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from repay_promotion_mx
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="repayTradeId != null">
                and repay_trade_id = #{repayTradeId}
            </if>
            <if test="accountId != null">
                and account_id = #{accountId}
            </if>
            <if test="beforePrice != null">
                and before_price = #{beforePrice}
            </if>
            <if test="beforeRestMoney != null">
                and before_rest_money = #{beforeRestMoney}
            </if>
            <if test="beforeConsumeMoney != null">
                and before_consume_money = #{beforeConsumeMoney}
            </if>
            <if test="beforeRestCount != null">
                and before_rest_count = #{beforeRestCount}
            </if>
            <if test="beforeConsumeCount != null">
                and before_consume_count = #{beforeConsumeCount}
            </if>
            <if test="backPrice != null">
                and back_price = #{backPrice}
            </if>
            <if test="backRestMoney != null">
                and back_rest_money = #{backRestMoney}
            </if>
            <if test="backConsumeMoney != null">
                and back_consume_money = #{backConsumeMoney}
            </if>
            <if test="backRestCount != null">
                and back_rest_count = #{backRestCount}
            </if>
            <if test="backConsumeCount != null">
                and back_consume_count = #{backConsumeCount}
            </if>
            <if test="beforeGiftRestMoney != null">
                and before_gift_rest_money = #{beforeGiftRestMoney}
            </if>
            <if test="beforeGiftConsumeMoney != null">
                and before_gift_consume_money = #{beforeGiftConsumeMoney}
            </if>
            <if test="backGiftRestMoney != null">
                and back_gift_rest_money = #{backGiftRestMoney}
            </if>
            <if test="backGiftConsumeMoney != null">
                and back_gift_consume_money = #{backGiftConsumeMoney}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="" useGeneratedKeys="true">
        insert into repay_promotion_mx(id, repay_trade_id, account_id, before_price, before_rest_money, before_consume_money, before_rest_count, before_consume_count, back_price, back_rest_money, back_consume_money, back_rest_count, back_consume_count, before_gift_rest_money, before_gift_consume_money, back_gift_rest_money, back_gift_consume_money)
        values (#{id}, #{repayTradeId}, #{accountId}, #{beforePrice}, #{beforeRestMoney}, #{beforeConsumeMoney}, #{beforeRestCount}, #{beforeConsumeCount}, #{backPrice}, #{backRestMoney}, #{backConsumeMoney}, #{backRestCount}, #{backConsumeCount}, #{beforeGiftRestMoney}, #{beforeGiftConsumeMoney}, #{backGiftRestMoney}, #{backGiftConsumeMoney})
    </insert>

    <insert id="insertBatch" keyProperty="" useGeneratedKeys="true">
        insert into repay_promotion_mx(id, repay_trade_id, account_id, before_price, before_rest_money, before_consume_money, before_rest_count, before_consume_count, back_price, back_rest_money, back_consume_money, back_rest_count, back_consume_count, before_gift_rest_money, before_gift_consume_money, back_gift_rest_money, back_gift_consume_money)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.id}, #{entity.repayTradeId}, #{entity.accountId}, #{entity.beforePrice}, #{entity.beforeRestMoney}, #{entity.beforeConsumeMoney}, #{entity.beforeRestCount}, #{entity.beforeConsumeCount}, #{entity.backPrice}, #{entity.backRestMoney}, #{entity.backConsumeMoney}, #{entity.backRestCount}, #{entity.backConsumeCount}, #{entity.beforeGiftRestMoney}, #{entity.beforeGiftConsumeMoney}, #{entity.backGiftRestMoney}, #{entity.backGiftConsumeMoney})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="" useGeneratedKeys="true">
        insert into repay_promotion_mx(id, repay_trade_id, account_id, before_price, before_rest_money, before_consume_money, before_rest_count, before_consume_count, back_price, back_rest_money, back_consume_money, back_rest_count, back_consume_count, before_gift_rest_money, before_gift_consume_money, back_gift_rest_money, back_gift_consume_money)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}, #{entity.repayTradeId}, #{entity.accountId}, #{entity.beforePrice}, #{entity.beforeRestMoney}, #{entity.beforeConsumeMoney}, #{entity.beforeRestCount}, #{entity.beforeConsumeCount}, #{entity.backPrice}, #{entity.backRestMoney}, #{entity.backConsumeMoney}, #{entity.backRestCount}, #{entity.backConsumeCount}, #{entity.beforeGiftRestMoney}, #{entity.beforeGiftConsumeMoney}, #{entity.backGiftRestMoney}, #{entity.backGiftConsumeMoney})
        </foreach>
        on duplicate key update
        id = values(id),
        repay_trade_id = values(repay_trade_id),
        account_id = values(account_id),
        before_price = values(before_price),
        before_rest_money = values(before_rest_money),
        before_consume_money = values(before_consume_money),
        before_rest_count = values(before_rest_count),
        before_consume_count = values(before_consume_count),
        back_price = values(back_price),
        back_rest_money = values(back_rest_money),
        back_consume_money = values(back_consume_money),
        back_rest_count = values(back_rest_count),
        back_consume_count = values(back_consume_count),
        before_gift_rest_money = values(before_gift_rest_money),
        before_gift_consume_money = values(before_gift_consume_money),
        back_gift_rest_money = values(back_gift_rest_money),
        back_gift_consume_money = values(back_gift_consume_money)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update repay_promotion_mx
        <set>
            <if test="id != null">
                id = #{id},
            </if>
            <if test="repayTradeId != null">
                repay_trade_id = #{repayTradeId},
            </if>
            <if test="accountId != null">
                account_id = #{accountId},
            </if>
            <if test="beforePrice != null">
                before_price = #{beforePrice},
            </if>
            <if test="beforeRestMoney != null">
                before_rest_money = #{beforeRestMoney},
            </if>
            <if test="beforeConsumeMoney != null">
                before_consume_money = #{beforeConsumeMoney},
            </if>
            <if test="beforeRestCount != null">
                before_rest_count = #{beforeRestCount},
            </if>
            <if test="beforeConsumeCount != null">
                before_consume_count = #{beforeConsumeCount},
            </if>
            <if test="backPrice != null">
                back_price = #{backPrice},
            </if>
            <if test="backRestMoney != null">
                back_rest_money = #{backRestMoney},
            </if>
            <if test="backConsumeMoney != null">
                back_consume_money = #{backConsumeMoney},
            </if>
            <if test="backRestCount != null">
                back_rest_count = #{backRestCount},
            </if>
            <if test="backConsumeCount != null">
                back_consume_count = #{backConsumeCount},
            </if>
            <if test="beforeGiftRestMoney != null">
                before_gift_rest_money = #{beforeGiftRestMoney},
            </if>
            <if test="beforeGiftConsumeMoney != null">
                before_gift_consume_money = #{beforeGiftConsumeMoney},
            </if>
            <if test="backGiftRestMoney != null">
                back_gift_rest_money = #{backGiftRestMoney},
            </if>
            <if test="backGiftConsumeMoney != null">
                back_gift_consume_money = #{backGiftConsumeMoney},
            </if>
        </set>
        where  = #{}
    </update>

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

</mapper>

