<?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.pay.mapper.PayOrderMapper">

    <resultMap type="PayOrder" id="PayOrderResult">
        <result property="orderId" column="order_id" />
        <result property="userId" column="user_id" />
        <result property="orderNumber" column="order_number" />
        <result property="orderStatus" column="order_status" />
        <result property="totalAmount" column="total_amount" />
        <result property="orderContent" column="order_content" />
        <result property="orderRemark" column="order_remark" />
        <result property="orderMessage" column="order_message" />
    </resultMap>

    <sql id="selectPayOrderVo"> select order_id, user_id, order_number, order_status, total_amount,
        order_content, order_remark, order_message from pay_order </sql>

    <select id="selectPayOrderList" parameterType="PayOrder" resultMap="PayOrderResult">
        <include refid="selectPayOrderVo" />
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="orderNumber != null  and orderNumber != ''"> and order_number = #{orderNumber}</if>
            <if test="orderStatus != null  and orderStatus != ''"> and order_status = #{orderStatus}</if>
            <if test="totalAmount != null  and totalAmount != ''"> and total_amount = #{totalAmount}</if>
            <if test="orderContent != null  and orderContent != ''"> and order_content =
        #{orderContent}</if>
            <if test="orderRemark != null  and orderRemark != ''"> and order_remark
        = #{orderRemark}</if>
            <if test="orderMessage != null  and orderMessage != ''"> and
        order_message = #{orderMessage}</if>
        </where>
    </select>

    <select id="selectPayOrderByOrderId" parameterType="Long" resultMap="PayOrderResult">
        <include refid="selectPayOrderVo" />
        where pay_order.order_id = #{orderId} 
    </select>

    <select id="selectPayOrderByOrderNumber" parameterType="String" resultMap="PayOrderResult">
        <include refid="selectPayOrderVo" />
        where pay_order.order_number = #{orderNumber} 
    </select>

    <insert id="insertPayOrder" parameterType="PayOrder"> insert into pay_order 
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="orderNumber != null">order_number,</if>
            <if test="orderStatus != null">
        order_status,</if>
            <if test="totalAmount != null">total_amount,</if>
            <if test="orderContent != null">order_content,</if>
            <if test="orderRemark != null">
        order_remark,</if>
            <if test="orderMessage != null">order_message,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="orderNumber != null">#{orderNumber},</if>
            <if test="orderStatus != null">
        #{orderStatus},</if>
            <if test="totalAmount != null">#{totalAmount},</if>
            <if test="orderContent != null">#{orderContent},</if>
            <if test="orderRemark != null">
        #{orderRemark},</if>
            <if test="orderMessage != null">#{orderMessage},</if>
        </trim>
    </insert>

    <update id="updatePayOrder" parameterType="PayOrder"> update pay_order 
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="orderNumber != null">order_number
            = #{orderNumber},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="totalAmount != null">total_amount = #{totalAmount},</if>
            <if test="orderContent != null">order_content = #{orderContent},</if>
            <if test="orderRemark != null">order_remark = #{orderRemark},</if>
            <if test="orderMessage != null">order_message = #{orderMessage},</if>
        </trim>
        where pay_order.order_id = #{orderId} </update>

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

    <delete id="deletePayOrderByOrderNumber" parameterType="String"> 
            delete from pay_order where order_number= #{orderNumber} 
    </delete>

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

    <update id="updateStatus" parameterType="String">
    update pay_order set order_status = #{orderStatus} where order_number = #{orderNumber}
    </update>
</mapper>