<?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.ss.vipOrder.mapper.VipOrderMapper">

    <resultMap type="VipOrderVO" id="VipOrderResult" autoMapping="true"/>

    <sql id="selectVipOrderVo">
        select
            svo.id,
            svo.order_no,
            svo.user_id,
            svo.mch_id,
            svo.level_id,
            svo.level_name,
            svo.level_discount,
            svo.level_store_id,
            svo.level_solution,
            svo.level_time,
            svo.level_price,
            svo.level_limit_type,
            svo.level_limit_count,
            svo.level_limit_total,
            svo.amount,
            svo.expire_time,
            svo.pay_id,
            svo.status,
            svo.cancel_time,
            svo.cancel_reason,
            svo.create_time,
            svo.user_name,
            svo.mch_name,
            svo.channel_name,
            svo.channel_type,
            svo.pay_no,
            svo.pay_time,
            svo.store_name,
            svo.channel_type,
            svo.channel_id
        from ss_vip_order svo
    </sql>

    <sql id="searchCondition">
        <if test="query.id != null "> and svo.id = #{query.id}</if>
        <if test="query.orderNo != null  and query.orderNo != ''"> and svo.order_no like concat('%', #{query.orderNo}, '%')</if>
        <if test="query.eqOrderNo != null  and query.eqOrderNo != ''"> and svo.order_no = #{query.eqOrderNo}</if>
        <if test="query.userId != null "> and svo.user_id = #{query.userId}</if>
        <if test="query.mchId != null "> and svo.mch_id = #{query.mchId}</if>
        <if test="query.levelId != null "> and svo.level_id = #{query.levelId}</if>
        <if test="query.levelName != null  and query.levelName != ''"> and svo.level_name like concat('%', #{query.levelName}, '%')</if>
        <if test="query.payId != null"> and svo.pay_id = #{query.payId}</if>
        <if test="query.status != null  and query.status != ''"> and svo.status = #{query.status}</if>
        <if test="query.cancelReason != null  and query.cancelReason != ''"> and svo.cancel_reason like concat('%', #{query.cancelReason}, '%')</if>
        <if test="query.userName != null  and query.userName != ''"> and svo.user_name like concat('%', #{query.userName}, '%')</if>
        <if test="query.mchName != null  and query.mchName != ''"> and svo.mch_name like concat('%', #{query.mchName}, '%')</if>
        <if test="query.payNo != null and query.payNo != ''">and svo.pay_no like concat('%', #{query.payNo}, '%')</if>
        <if test="query.levelSolution != null  and query.levelSolution != ''"> and svo.level_solution = #{query.levelSolution}</if>
        <if test="query.levelLimitType != null  and query.levelLimitType != ''"> and svo.level_limit_type = #{query.levelLimitType}</if>
        <if test="query.amount != null  and query.amount != ''"> and svo.amount = #{query.amount}</if>
        <if test="query.channelId != null "> and channel_id = #{query.channelId}</if>
        ${query.params.dataScope}
    </sql>

    <select id="selectVipOrderList" parameterType="VipOrderQuery" resultMap="VipOrderResult">
        <include refid="selectVipOrderVo"/>
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="selectVipOrderById" parameterType="Long" resultMap="VipOrderResult">
        <include refid="selectVipOrderVo"/>
        where svo.id = #{id}
    </select>

    <insert id="insertVipOrder" parameterType="VipOrder" useGeneratedKeys="true" keyProperty="id">
        insert into ss_vip_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">order_no,</if>
            <if test="userId != null">user_id,</if>
            <if test="mchId != null">mch_id,</if>
            <if test="levelId != null">level_id,</if>
            <if test="levelName != null and levelName != ''">level_name,</if>
            <if test="levelDiscount != null">level_discount,</if>
            <if test="levelStoreId != null">level_store_id,</if>
            <if test="levelSolution != null and levelSolution != ''">level_solution,</if>
            <if test="levelTime != null">level_time,</if>
            <if test="levelPrice != null">level_price,</if>
            <if test="levelLimitType != null and levelLimitType != ''">level_limit_type,</if>
            <if test="levelLimitCount != null">level_limit_count,</if>
            <if test="levelLimitTotal != null">level_limit_total,</if>
            <if test="amount != null">amount,</if>
            <if test="expireTime != null">expire_time,</if>
            <if test="payId != null">pay_id,</if>
            <if test="status != null and status != ''">`status`,</if>
            <if test="cancelTime != null">cancel_time,</if>
            <if test="cancelReason != null">cancel_reason,</if>
            <if test="createTime != null">create_time,</if>
            <if test="userName != null">user_name,</if>
            <if test="mchName != null">mch_name,</if>
            <if test="channelName != null">channel_name,</if>
            <if test="payNo != null">pay_no,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="storeName != null">store_name,</if>
            <if test="channelType != null">channel_type,</if>
            <if test="channelId != null">channel_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">#{orderNo},</if>
            <if test="userId != null">#{userId},</if>
            <if test="mchId != null">#{mchId},</if>
            <if test="levelId != null">#{levelId},</if>
            <if test="levelName != null and levelName != ''">#{levelName},</if>
            <if test="levelDiscount != null">#{levelDiscount},</if>
            <if test="levelStoreId != null">#{levelStoreId},</if>
            <if test="levelSolution != null and levelSolution != ''">#{levelSolution},</if>
            <if test="levelTime != null">#{levelTime},</if>
            <if test="levelPrice != null">#{levelPrice},</if>
            <if test="levelLimitType != null and levelLimitType != ''">#{levelLimitType},</if>
            <if test="levelLimitCount != null">#{levelLimitCount},</if>
            <if test="levelLimitTotal != null">#{levelLimitTotal},</if>
            <if test="amount != null">#{amount},</if>
            <if test="expireTime != null">#{expireTime},</if>
            <if test="payId != null">#{payId},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="cancelTime != null">#{cancelTime},</if>
            <if test="cancelReason != null">#{cancelReason},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="userName != null">#{userName},</if>
            <if test="mchName != null">#{mchName},</if>
            <if test="channelName != null">#{channelName},</if>
            <if test="payNo != null">#{payNo},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="storeName != null">#{storeName},</if>
            <if test="channelType != null">#{channelType},</if>
            <if test="channelId != null">#{channelId},</if>
         </trim>
    </insert>

    <update id="updateVipOrder" parameterType="VipOrder">
        update ss_vip_order svo
        <trim prefix="SET" suffixOverrides=",">
            <include refid="updateColumns"/>
        </trim>
        where id = #{data.id}
    </update>

    <update id="updateByQuery">
        update ss_vip_order svo
        <trim prefix="SET" suffixOverrides=",">
            <include refid="updateColumns"/>
        </trim>
        <where>
            <include refid="searchCondition"/>
        </where>
    </update>

    <sql id="updateColumns">
        <if test="data.orderNo != null and data.orderNo != ''">svo.order_no = #{data.orderNo},</if>
        <if test="data.userId != null">svo.user_id = #{data.userId},</if>
        <if test="data.mchId != null">svo.mch_id = #{data.mchId},</if>
        <if test="data.levelId != null">svo.level_id = #{data.levelId},</if>
        <if test="data.levelName != null and data.levelName != ''">svo.level_name = #{data.levelName},</if>
        <if test="data.levelDiscount != null">svo.level_discount = #{data.levelDiscount},</if>
        <if test="data.levelStoreId != null">svo.level_store_id = #{data.levelStoreId},</if>
        <if test="data.levelSolution != null and data.levelSolution != ''">svo.level_solution = #{data.levelSolution},</if>
        <if test="data.levelTime != null">svo.level_time = #{data.levelTime},</if>
        <if test="data.levelPrice != null">svo.level_price = #{data.levelPrice},</if>
        <if test="data.levelLimitType != null and data.levelLimitType != ''">svo.level_limit_type = #{data.levelLimitType},</if>
        <if test="data.levelLimitCount != null">svo.level_limit_count = #{data.levelLimitCount},</if>
        <if test="data.levelLimitTotal != null">svo.level_limit_total = #{data.levelLimitTotal},</if>
        <if test="data.amount != null">svo.amount = #{data.amount},</if>
        <if test="data.expireTime != null">svo.expire_time = #{data.expireTime},</if>
        <if test="data.payId != null">svo.pay_id = #{data.payId},</if>
        <if test="data.status != null and data.status != ''">svo.`status` = #{data.status},</if>
        <if test="data.cancelTime != null">svo.cancel_time = #{data.cancelTime},</if>
        <if test="data.cancelReason != null">svo.cancel_reason = #{data.cancelReason},</if>
        <if test="data.createTime != null">svo.create_time = #{data.createTime},</if>
        <if test="data.userName != null">svo.user_name = #{data.userName},</if>
        <if test="data.mchName != null">svo.mch_name = #{data.mchName},</if>
        <if test="data.channelName != null">svo.channel_name = #{data.channelName},</if>
        <if test="data.payNo != null">svo.pay_no = #{data.payNo},</if>
        <if test="data.payTime != null">svo.pay_time = #{data.payTime},</if>
        <if test="data.storeName != null">svo.store_name = #{data.storeName},</if>
        <if test="data.channelType != null">svo.channel_type = #{data.channelType},</if>
        <if test="data.channelId != null">svo.channel_id = #{data.channelId},</if>
    </sql>

    <delete id="deleteVipOrderById" parameterType="Long">
        delete from ss_vip_order where id = #{id}
    </delete>

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