<?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.sf.system.mapper.UserMemberMapper">
    
    <resultMap type="UserMember" id="UserMemberResult">
        <result property="id"    column="id"    />
        <result property="memberLevel"    column="member_level"    />
        <result property="subscriptionStatus"    column="subscription_status"    />
        <result property="userId"    column="user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="integration"    column="integration"    />
        <result property="expirationTime"    column="expiration_time"    />
    </resultMap>

    <sql id="selectUserMemberVo">
        select id, member_level, subscription_status, user_id, create_time, update_time, integration, expiration_time from User_member
    </sql>

    <select id="selectUserMemberList" parameterType="UserMember" resultMap="UserMemberResult">
        <include refid="selectUserMemberVo"/>
        <where>  
            <if test="memberLevel != null "> and member_level = #{memberLevel}</if>
            <if test="subscriptionStatus != null "> and subscription_status = #{subscriptionStatus}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="integration != null "> and integration = #{integration}</if>
            <if test="expirationTime != null "> and expiration_time = #{expirationTime}</if>
        </where>
    </select>
    
    <select id="selectUserMemberById" parameterType="Long" resultMap="UserMemberResult">
        <include refid="selectUserMemberVo"/>
        where id = #{id}
    </select>

    <select id="selectUserMemberByUserId" resultMap="UserMemberResult">
        <include refid="selectUserMemberVo"/>
        where user_id = #{userId}
    </select>

    <insert id="insertUserMember" parameterType="UserMember" useGeneratedKeys="true" keyProperty="id">
        insert into User_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="memberLevel != null">member_level,</if>
            <if test="subscriptionStatus != null">subscription_status,</if>
            <if test="userId != null">user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="integration != null">integration,</if>
            <if test="expirationTime != null">expiration_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="memberLevel != null">#{memberLevel},</if>
            <if test="subscriptionStatus != null">#{subscriptionStatus},</if>
            <if test="userId != null">#{userId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="integration != null">#{integration},</if>
            <if test="expirationTime != null">#{expirationTime},</if>
         </trim>
    </insert>

    <update id="updateUserMember" parameterType="UserMember">
        update User_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="memberLevel != null">member_level = #{memberLevel},</if>
            <if test="subscriptionStatus != null">subscription_status = #{subscriptionStatus},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="integration != null">integration = #{integration},</if>
            <if test="expirationTime != null">expiration_time = #{expirationTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUserMemberById" parameterType="Long">
        delete from User_member where id = #{id}
    </delete>

    <delete id="deleteUserMemberByIds" parameterType="String">
        delete from User_member where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>