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

    <resultMap type="FsUserVipOrder" id="FsUserVipOrderResult">
        <result property="orderId"    column="order_id"    />
        <result property="userId"    column="user_id"    />
        <result property="packageId"    column="package_id"    />
        <result property="purchaseDate"    column="purchase_date"    />
        <result property="expireDate"    column="expire_date"    />
        <result property="price"    column="price"    />
        <result property="payMoney"    column="pay_money"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="payType"    column="pay_type"    />
        <result property="payTime"    column="pay_time"    />
        <result property="orderCode"    column="order_code"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectFsUserVipOrderVo">
        select order_id, pay_money,user_id,pay_type,pay_time, package_id, purchase_date, expire_date, price, status, create_time, order_code, update_time from fs_user_vip_order
    </sql>

    <select id="selectFsUserVipOrderList" parameterType="FsUserVipOrder" resultMap="FsUserVipOrderResult">
        <include refid="selectFsUserVipOrderVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="packageId != null "> and package_id = #{packageId}</if>
            <if test="purchaseDate != null "> and purchase_date = #{purchaseDate}</if>
            <if test="expireDate != null "> and expire_date = #{expireDate}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
        </where>
    </select>

    <select id="selectFsUserVipOrderByOrderId" parameterType="Long" resultMap="FsUserVipOrderResult">
        <include refid="selectFsUserVipOrderVo"/>
        where order_id = #{orderId}
    </select>

    <insert id="insertFsUserVipOrder" parameterType="FsUserVipOrder" useGeneratedKeys="true" keyProperty="orderId">
        insert into fs_user_vip_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="packageId != null">package_id,</if>
            <if test="purchaseDate != null">purchase_date,</if>
            <if test="expireDate != null">expire_date,</if>
            <if test="price != null">price,</if>
            <if test="payMoney != null">pay_money,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="orderCode != null">order_code,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="payType != null">pay_type,</if>
            <if test="payTime != null">pay_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="packageId != null">#{packageId},</if>
            <if test="purchaseDate != null">#{purchaseDate},</if>
            <if test="expireDate != null">#{expireDate},</if>
            <if test="price != null">#{price},</if>
            <if test="payMoney != null">#{payMoney},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="orderCode != null">#{orderCode},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="payType != null">#{payType},</if>
            <if test="payTime != null">#{payTime},</if>
         </trim>
    </insert>

    <update id="updateFsUserVipOrder" parameterType="FsUserVipOrder">
        update fs_user_vip_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="packageId != null">package_id = #{packageId},</if>
            <if test="purchaseDate != null">purchase_date = #{purchaseDate},</if>
            <if test="expireDate != null">expire_date = #{expireDate},</if>
            <if test="price != null">price = #{price},</if>
            <if test="payMoney != null">pay_money = #{payMoney},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="orderCode != null">order_code = #{orderCode},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="payType != null">pay_type = #{payType},</if>
        </trim>
        where order_id = #{orderId}
    </update>

    <delete id="deleteFsUserVipOrderByOrderId" parameterType="Long">
        delete from fs_user_vip_order where order_id = #{orderId}
    </delete>

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