<?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.ruoyi.system.mapper.VipMembershipMapper">
    
    <resultMap type="VipMembership" id="VipMembershipResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="shupm"    column="shupm"    />
        <result property="price"    column="price"    />
        <result property="duration"    column="duration"    />
        <result property="state"    column="state"    />
    </resultMap>

    <sql id="selectVipMembershipVo">
        select id, name, shupm, price, duration, state from vip_membership
    </sql>

    <select id="selectVipMembershipList" parameterType="VipMembership" resultMap="VipMembershipResult">
        <include refid="selectVipMembershipVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="state != null "> and state = #{state}</if>
        </where>
        order by id desc
    </select>
    
    <select id="selectVipMembershipById" parameterType="Long" resultMap="VipMembershipResult">
        <include refid="selectVipMembershipVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertVipMembership" parameterType="VipMembership" useGeneratedKeys="true" keyProperty="id">
        insert into vip_membership
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="shupm != null">shupm,</if>
            <if test="price != null">price,</if>
            <if test="duration != null">duration,</if>
            <if test="state != null">state,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="shupm != null">#{shupm},</if>
            <if test="price != null">#{price},</if>
            <if test="duration != null">#{duration},</if>
            <if test="state != null">#{state},</if>
         </trim>
    </insert>

    <update id="updateVipMembership" parameterType="VipMembership">
        update vip_membership
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="shupm != null">shupm = #{shupm},</if>
            <if test="price != null">price = #{price},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="state != null">state = #{state},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteVipMembershipById" parameterType="Long">
        delete from vip_membership where id = #{id}
    </delete>

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