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

    <resultMap type=".entity.TurnMembershipCardMx" id="TurnMembershipCardMxMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="turnMembershipCardId" column="turn_membership_card_id" jdbcType="INTEGER"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
        <result property="accountId" column="account_id" jdbcType="INTEGER"/>
        <result property="cardRestMoney" column="card_rest_money" jdbcType="NUMERIC"/>
        <result property="cardConsumeMoney" column="card_consume_money" jdbcType="NUMERIC"/>
        <result property="giftConsumeMoney" column="gift_consume_money" jdbcType="NUMERIC"/>
        <result property="rechargeOrProjectId" column="recharge_or_project_id" jdbcType="INTEGER"/>
        <result property="rechargeOrProjectName" column="recharge_or_project_name" jdbcType="VARCHAR"/>
        <result property="rechargeOrProjectNum" column="recharge_or_project_num" jdbcType="VARCHAR"/>
        <result property="courseRestCount" column="course_rest_count" jdbcType="INTEGER"/>
        <result property="courseConsumeCount" column="course_consume_count" jdbcType="INTEGER"/>
        <result property="courseRestPrice" column="course_rest_price" jdbcType="NUMERIC"/>
        <result property="courseConsumePrice" column="course_consume_price" jdbcType="NUMERIC"/>
        <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="TurnMembershipCardMxMap">
        select
          id, turn_membership_card_id, type, account_id, card_rest_money, card_consume_money, gift_consume_money, recharge_or_project_id, recharge_or_project_name, recharge_or_project_num, course_rest_count, course_consume_count, course_rest_price, course_consume_price, 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 turn_membership_card_mx
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="TurnMembershipCardMxMap">
        select
          id, turn_membership_card_id, type, account_id, card_rest_money, card_consume_money, gift_consume_money, recharge_or_project_id, recharge_or_project_name, recharge_or_project_num, course_rest_count, course_consume_count, course_rest_price, course_consume_price, 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 turn_membership_card_mx
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="turnMembershipCardId != null">
                and turn_membership_card_id = #{turnMembershipCardId}
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
            <if test="accountId != null">
                and account_id = #{accountId}
            </if>
            <if test="cardRestMoney != null">
                and card_rest_money = #{cardRestMoney}
            </if>
            <if test="cardConsumeMoney != null">
                and card_consume_money = #{cardConsumeMoney}
            </if>
            <if test="giftConsumeMoney != null">
                and gift_consume_money = #{giftConsumeMoney}
            </if>
            <if test="rechargeOrProjectId != null">
                and recharge_or_project_id = #{rechargeOrProjectId}
            </if>
            <if test="rechargeOrProjectName != null and rechargeOrProjectName != ''">
                and recharge_or_project_name = #{rechargeOrProjectName}
            </if>
            <if test="rechargeOrProjectNum != null and rechargeOrProjectNum != ''">
                and recharge_or_project_num = #{rechargeOrProjectNum}
            </if>
            <if test="courseRestCount != null">
                and course_rest_count = #{courseRestCount}
            </if>
            <if test="courseConsumeCount != null">
                and course_consume_count = #{courseConsumeCount}
            </if>
            <if test="courseRestPrice != null">
                and course_rest_price = #{courseRestPrice}
            </if>
            <if test="courseConsumePrice != null">
                and course_consume_price = #{courseConsumePrice}
            </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 turn_membership_card_mx
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="turnMembershipCardId != null">
                and turn_membership_card_id = #{turnMembershipCardId}
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
            <if test="accountId != null">
                and account_id = #{accountId}
            </if>
            <if test="cardRestMoney != null">
                and card_rest_money = #{cardRestMoney}
            </if>
            <if test="cardConsumeMoney != null">
                and card_consume_money = #{cardConsumeMoney}
            </if>
            <if test="giftConsumeMoney != null">
                and gift_consume_money = #{giftConsumeMoney}
            </if>
            <if test="rechargeOrProjectId != null">
                and recharge_or_project_id = #{rechargeOrProjectId}
            </if>
            <if test="rechargeOrProjectName != null and rechargeOrProjectName != ''">
                and recharge_or_project_name = #{rechargeOrProjectName}
            </if>
            <if test="rechargeOrProjectNum != null and rechargeOrProjectNum != ''">
                and recharge_or_project_num = #{rechargeOrProjectNum}
            </if>
            <if test="courseRestCount != null">
                and course_rest_count = #{courseRestCount}
            </if>
            <if test="courseConsumeCount != null">
                and course_consume_count = #{courseConsumeCount}
            </if>
            <if test="courseRestPrice != null">
                and course_rest_price = #{courseRestPrice}
            </if>
            <if test="courseConsumePrice != null">
                and course_consume_price = #{courseConsumePrice}
            </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="id" useGeneratedKeys="true">
        insert into turn_membership_card_mx(turn_membership_card_id, type, account_id, card_rest_money, card_consume_money, gift_consume_money, recharge_or_project_id, recharge_or_project_name, recharge_or_project_num, course_rest_count, course_consume_count, course_rest_price, course_consume_price, 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 (#{turnMembershipCardId}, #{type}, #{accountId}, #{cardRestMoney}, #{cardConsumeMoney}, #{giftConsumeMoney}, #{rechargeOrProjectId}, #{rechargeOrProjectName}, #{rechargeOrProjectNum}, #{courseRestCount}, #{courseConsumeCount}, #{courseRestPrice}, #{courseConsumePrice}, #{beforePrice}, #{beforeRestMoney}, #{beforeConsumeMoney}, #{beforeRestCount}, #{beforeConsumeCount}, #{backPrice}, #{backRestMoney}, #{backConsumeMoney}, #{backRestCount}, #{backConsumeCount}, #{beforeGiftRestMoney}, #{beforeGiftConsumeMoney}, #{backGiftRestMoney}, #{backGiftConsumeMoney})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into turn_membership_card_mx(turn_membership_card_id, type, account_id, card_rest_money, card_consume_money, gift_consume_money, recharge_or_project_id, recharge_or_project_name, recharge_or_project_num, course_rest_count, course_consume_count, course_rest_price, course_consume_price, 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.turnMembershipCardId}, #{entity.type}, #{entity.accountId}, #{entity.cardRestMoney}, #{entity.cardConsumeMoney}, #{entity.giftConsumeMoney}, #{entity.rechargeOrProjectId}, #{entity.rechargeOrProjectName}, #{entity.rechargeOrProjectNum}, #{entity.courseRestCount}, #{entity.courseConsumeCount}, #{entity.courseRestPrice}, #{entity.courseConsumePrice}, #{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="id" useGeneratedKeys="true">
        insert into turn_membership_card_mx(turn_membership_card_id, type, account_id, card_rest_money, card_consume_money, gift_consume_money, recharge_or_project_id, recharge_or_project_name, recharge_or_project_num, course_rest_count, course_consume_count, course_rest_price, course_consume_price, 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.turnMembershipCardId}, #{entity.type}, #{entity.accountId}, #{entity.cardRestMoney}, #{entity.cardConsumeMoney}, #{entity.giftConsumeMoney}, #{entity.rechargeOrProjectId}, #{entity.rechargeOrProjectName}, #{entity.rechargeOrProjectNum}, #{entity.courseRestCount}, #{entity.courseConsumeCount}, #{entity.courseRestPrice}, #{entity.courseConsumePrice}, #{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
        turn_membership_card_id = values(turn_membership_card_id),
        type = values(type),
        account_id = values(account_id),
        card_rest_money = values(card_rest_money),
        card_consume_money = values(card_consume_money),
        gift_consume_money = values(gift_consume_money),
        recharge_or_project_id = values(recharge_or_project_id),
        recharge_or_project_name = values(recharge_or_project_name),
        recharge_or_project_num = values(recharge_or_project_num),
        course_rest_count = values(course_rest_count),
        course_consume_count = values(course_consume_count),
        course_rest_price = values(course_rest_price),
        course_consume_price = values(course_consume_price),
        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 turn_membership_card_mx
        <set>
            <if test="turnMembershipCardId != null">
                turn_membership_card_id = #{turnMembershipCardId},
            </if>
            <if test="type != null">
                type = #{type},
            </if>
            <if test="accountId != null">
                account_id = #{accountId},
            </if>
            <if test="cardRestMoney != null">
                card_rest_money = #{cardRestMoney},
            </if>
            <if test="cardConsumeMoney != null">
                card_consume_money = #{cardConsumeMoney},
            </if>
            <if test="giftConsumeMoney != null">
                gift_consume_money = #{giftConsumeMoney},
            </if>
            <if test="rechargeOrProjectId != null">
                recharge_or_project_id = #{rechargeOrProjectId},
            </if>
            <if test="rechargeOrProjectName != null and rechargeOrProjectName != ''">
                recharge_or_project_name = #{rechargeOrProjectName},
            </if>
            <if test="rechargeOrProjectNum != null and rechargeOrProjectNum != ''">
                recharge_or_project_num = #{rechargeOrProjectNum},
            </if>
            <if test="courseRestCount != null">
                course_rest_count = #{courseRestCount},
            </if>
            <if test="courseConsumeCount != null">
                course_consume_count = #{courseConsumeCount},
            </if>
            <if test="courseRestPrice != null">
                course_rest_price = #{courseRestPrice},
            </if>
            <if test="courseConsumePrice != null">
                course_consume_price = #{courseConsumePrice},
            </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 id = #{id}
    </update>

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

</mapper>

