<?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.cardOrder.mapper.CardOrderMapper">

    <resultMap type="CardOrderVO" id="CardOrderResult" autoMapping="true" />

    <sql id="selectCardOrderVo">
        select
            order_id,
            order_no,
            user_id,
            phone,
            user_name,
            real_name,
            pay_time,
            pay_type,
            paid,
            pay_id,
            type,
            total_fee,
            pay_fee,
            mark,
            status,
            create_time,
            pay_channel,
            channel_name,
            channel_cost,
            merchant_id,
            store_id,
            store_name,
            card_name,
            limit_num,
            stored_amount,
            validity_value,
            validity_unit,
            available_rooms,
            available_week,
            available_time_end,
            available_time_start,
            sku_id,
            hours,
            app_id
        from ss_card_order
    </sql>

    <sql id="searchCondition">
        <if test="query.orderNo != null  and query.orderNo != ''"> and order_no = #{query.orderNo}</if>
        <if test="query.userId != null "> and user_id = #{query.userId}</if>
        <if test="query.phone != null  and query.phone != ''"> and phone = #{query.phone}</if>
        <if test="query.userName != null  and query.userName != ''"> and user_name like concat('%', #{query.userName}, '%')</if>
        <if test="query.realName != null  and query.realName != ''"> and real_name like concat('%', #{query.realName}, '%')</if>
        <if test="query.payTime != null "> and pay_time = #{query.payTime}</if>
        <if test="query.payType != null  and query.payType != ''"> and pay_type = #{query.payType}</if>
        <if test="query.paid != null  and query.paid != ''"> and paid = #{query.paid}</if>
        <if test="query.payId != null "> and pay_id = #{query.payId}</if>
        <if test="query.type != null  and query.type != ''"> and type = #{query.type}</if>
        <if test="query.totalFee != null "> and total_fee = #{query.totalFee}</if>
        <if test="query.payFee != null "> and pay_fee = #{query.payFee}</if>
        <if test="query.mark != null  and query.mark != ''"> and mark = #{query.mark}</if>
        <if test="query.status != null  and query.status != ''"> and status = #{query.status}</if>
        <if test="query.payChannel != null "> and pay_channel = #{query.payChannel}</if>
        <if test="query.channelName != null  and query.channelName != ''"> and channel_name like concat('%', #{query.channelName}, '%')</if>
        <if test="query.channelCost != null "> and channel_cost = #{query.channelCost}</if>
        <if test="query.merchantId != null "> and merchant_id = #{query.merchantId}</if>
        <if test="query.storeId != null "> and store_id = #{query.storeId}</if>
        <if test="query.storeName != null  and query.storeName != ''"> and store_name like concat('%', #{query.storeName}, '%')</if>
        <if test="query.cardName != null  and query.cardName != ''"> and card_name like concat('%', #{query.cardName}, '%')</if>
        <if test="query.limitNum != null  and query.limitNum != ''"> and limit_num = #{query.limitNum}</if>
        <if test="query.storedAmount != null "> and stored_amount = #{query.storedAmount}</if>
        <if test="query.validityValue != null "> and validity_value = #{query.validityValue}</if>
        <if test="query.validityUnit != null  and query.validityUnit != ''"> and validity_unit = #{query.validityUnit}</if>
        <if test="query.availableRooms != null  and query.availableRooms != ''"> and available_rooms = #{query.availableRooms}</if>
        <if test="query.availableWeek != null  and query.availableWeek != ''"> and available_week = #{query.availableWeek}</if>
        <if test="query.availableTimeEnd != null "> and available_time_end = #{query.availableTimeEnd}</if>
        <if test="query.availableTimeStart != null "> and available_time_start = #{query.availableTimeStart}</if>
        <if test="query.skuId != null  and query.skuId != ''"> and sku_id = #{query.skuId}</if>
        <if test="query.hours != null "> and hours = #{query.hours}</if>
         <if test="query.appId != null  and query.appId != ''"> and app_id = #{query.appId}</if>
    </sql>

    <select id="selectCardOrderList" parameterType="CardOrderQuery" resultMap="CardOrderResult">
        <include refid="selectCardOrderVo"/>
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="selectCardOrderByOrderId" parameterType="Long" resultMap="CardOrderResult">
        <include refid="selectCardOrderVo"/>
        where order_id = #{orderId}
    </select>

    <select id="selectCardOrderByOrderNo" parameterType="Long" resultMap="CardOrderResult">
        <include refid="selectCardOrderVo"/>
        where order_no = #{orderNo}
    </select>


    <insert id="insertCardOrder" parameterType="CardOrder" useGeneratedKeys="true" keyProperty="orderId">
        insert into ss_card_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">order_no,</if>
            <if test="userId != null">user_id,</if>
            <if test="phone != null">phone,</if>
            <if test="userName != null">user_name,</if>
            <if test="realName != null">real_name,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="payType != null">pay_type,</if>
            <if test="paid != null and paid != ''">paid,</if>
            <if test="payId != null">pay_id,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="totalFee != null">total_fee,</if>
            <if test="payFee != null">pay_fee,</if>
            <if test="mark != null">mark,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="payChannel != null">pay_channel,</if>
            <if test="channelName != null">channel_name,</if>
            <if test="channelCost != null">channel_cost,</if>
            <if test="merchantId != null">merchant_id,</if>
            <if test="storeId != null">store_id,</if>
            <if test="storeName != null">store_name,</if>
            <if test="cardName != null">card_name,</if>
            <if test="limitNum != null">limit_num,</if>
            <if test="storedAmount != null">stored_amount,</if>
            <if test="validityValue != null">validity_value,</if>
            <if test="validityUnit != null">validity_unit,</if>
            <if test="availableRooms != null">available_rooms,</if>
            <if test="availableWeek != null">available_week,</if>
            <if test="availableTimeEnd != null">available_time_end,</if>
            <if test="availableTimeStart != null">available_time_start,</if>
            <if test="skuId != null">sku_id,</if>
            <if test="hours != null">hours,</if>
            <if test="appId != null">app_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">#{orderNo},</if>
            <if test="userId != null">#{userId},</if>
            <if test="phone != null">#{phone},</if>
            <if test="userName != null">#{userName},</if>
            <if test="realName != null">#{realName},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="payType != null">#{payType},</if>
            <if test="paid != null and paid != ''">#{paid},</if>
            <if test="payId != null">#{payId},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="totalFee != null">#{totalFee},</if>
            <if test="payFee != null">#{payFee},</if>
            <if test="mark != null">#{mark},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="payChannel != null">#{payChannel},</if>
            <if test="channelName != null">#{channelName},</if>
            <if test="channelCost != null">#{channelCost},</if>
            <if test="merchantId != null">#{merchantId},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="storeName != null">#{storeName},</if>
            <if test="cardName != null">#{cardName},</if>
            <if test="limitNum != null">#{limitNum},</if>
            <if test="storedAmount != null">#{storedAmount},</if>
            <if test="validityValue != null">#{validityValue},</if>
            <if test="validityUnit != null">#{validityUnit},</if>
            <if test="availableRooms != null">#{availableRooms,typeHandler=com.ruoyi.system.mapper.typehandler.LongSplitListTypeHandler},</if>
            <if test="availableWeek != null">#{availableWeek,typeHandler=com.ruoyi.system.mapper.typehandler.StringSplitListTypeHandler},</if>
            <if test="availableTimeEnd != null">#{availableTimeEnd},</if>
            <if test="availableTimeStart != null">#{availableTimeStart},</if>
            <if test="skuId != null">#{skuId},</if>
            <if test="hours != null">#{hours},</if>
            <if test="appId != null">#{appId},</if>
         </trim>
    </insert>

    <update id="updateCardOrder" parameterType="CardOrder">
        update ss_card_order
        <trim prefix="SET" suffixOverrides=",">
            <include refid="updateColumns"/>
        </trim>
        where order_id = #{data.orderId}
    </update>

    <sql id="updateColumns">
        <if test="data.orderNo != null and data.orderNo != ''">order_no = #{data.orderNo},</if>
        <if test="data.userId != null">user_id = #{data.userId},</if>
        <if test="data.phone != null">phone = #{data.phone},</if>
        <if test="data.userName != null">user_name = #{data.userName},</if>
        <if test="data.realName != null">real_name = #{data.realName},</if>
        <if test="data.payTime != null">pay_time = #{data.payTime},</if>
        <if test="data.payType != null">pay_type = #{data.payType},</if>
        <if test="data.paid != null and data.paid != ''">paid = #{data.paid},</if>
        <if test="data.payId != null">pay_id = #{data.payId},</if>
        <if test="data.type != null and data.type != ''">type = #{data.type},</if>
        <if test="data.totalFee != null">total_fee = #{data.totalFee},</if>
        <if test="data.payFee != null">pay_fee = #{data.payFee},</if>
        <if test="data.mark != null">mark = #{data.mark},</if>
        <if test="data.status != null">status = #{data.status},</if>
        <if test="data.createTime != null">create_time = #{data.createTime},</if>
        <if test="data.payChannel != null">pay_channel = #{data.payChannel},</if>
        <if test="data.channelName != null">channel_name = #{data.channelName},</if>
        <if test="data.channelCost != null">channel_cost = #{data.channelCost},</if>
        <if test="data.merchantId != null">merchant_id = #{data.merchantId},</if>
        <if test="data.storeId != null">store_id = #{data.storeId},</if>
        <if test="data.storeName != null">store_name = #{data.storeName},</if>
        <if test="data.cardName != null">card_name = #{data.cardName},</if>
        <if test="data.limitNum != null">limit_num = #{data.limitNum},</if>
        <if test="data.storedAmount != null">stored_amount = #{data.storedAmount},</if>
        <if test="data.validityValue != null">validity_value = #{data.validityValue},</if>
        <if test="data.validityUnit != null">validity_unit = #{data.validityUnit},</if>
        <if test="data.availableRooms != null">available_rooms = #{data.availableRooms,typeHandler=com.ruoyi.system.mapper.typehandler.LongSplitListTypeHandler},</if>
        <if test="data.availableWeek != null">available_week = #{data.availableWeek,typeHandler=com.ruoyi.system.mapper.typehandler.StringSplitListTypeHandler},</if>
        <if test="data.availableTimeEnd != null">available_time_end = #{data.availableTimeEnd},</if>
        <if test="data.availableTimeStart != null">available_time_start = #{data.availableTimeStart},</if>
        <if test="data.skuId != null">sku_id = #{data.skuId},</if>
        <if test="data.hours != null">hours = #{data.hours},</if>
        <if test="data.appId != null">app_id = #{data.appId},</if>
    </sql>

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

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