<?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.fs.course.mapper.FsUserVipPackageMapper">

    <resultMap type="FsUserVipPackage" id="FsUserVipPackageResult">
        <result property="packageId"    column="package_id"    />
        <result property="packageName"    column="package_name"    />
        <result property="months"    column="months"    />
        <result property="price"    column="price"    />
        <result property="sellPrice"    column="sell_price"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="status"    column="status"    />
        <result property="sort"    column="sort"    />
    </resultMap>

    <sql id="selectFsUserVipPackageVo">
        select package_id, package_name, months, price, sell_price, create_time, update_time, status, sort from fs_user_vip_package
    </sql>

    <select id="selectFsUserVipPackageList" parameterType="FsUserVipPackage" resultMap="FsUserVipPackageResult">
        <include refid="selectFsUserVipPackageVo"/>
        <where>
            <if test="packageName != null  and packageName != ''"> and package_name like concat('%', #{packageName}, '%')</if>
            <if test="months != null "> and months = #{months}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="sellPrice != null "> and sell_price = #{sellPrice}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="sort != null "> and sort = #{sort}</if>
        </where>
    </select>

    <select id="selectFsUserVipPackageByPackageId" parameterType="Long" resultMap="FsUserVipPackageResult">
        <include refid="selectFsUserVipPackageVo"/>
        where package_id = #{packageId}
    </select>

    <insert id="insertFsUserVipPackage" parameterType="FsUserVipPackage" useGeneratedKeys="true" keyProperty="packageId">
        insert into fs_user_vip_package
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="packageName != null">package_name,</if>
            <if test="months != null">months,</if>
            <if test="price != null">price,</if>
            <if test="sellPrice != null">sell_price,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="status != null">status,</if>
            <if test="sort != null">sort,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="packageName != null">#{packageName},</if>
            <if test="months != null">#{months},</if>
            <if test="price != null">#{price},</if>
            <if test="sellPrice != null">#{sellPrice},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="status != null">#{status},</if>
            <if test="sort != null">#{sort},</if>
         </trim>
    </insert>

    <update id="updateFsUserVipPackage" parameterType="FsUserVipPackage">
        update fs_user_vip_package
        <trim prefix="SET" suffixOverrides=",">
            <if test="packageName != null">package_name = #{packageName},</if>
            <if test="months != null">months = #{months},</if>
            <if test="price != null">price = #{price},</if>
            <if test="sellPrice != null">sell_price = #{sellPrice},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="sort != null">sort = #{sort},</if>
        </trim>
        where package_id = #{packageId}
    </update>

    <delete id="deleteFsUserVipPackageByPackageId" parameterType="Long">
        delete from fs_user_vip_package where package_id = #{packageId}
    </delete>

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