<?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.system.mapper.OrderParentMapper">

    <resultMap type="OrderParent" id="OrderParentResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="totalAmount"    column="total_amount"    />
        <result property="totalDiscount"    column="total_discount"    />
        <result property="actualPayAmount"    column="actual_pay_amount"    />
        <result property="paymentMethod"    column="payment_method"    />
        <result property="paymentTime"    column="payment_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="ddId"    column="dd_id"    />
        <result property="tableNum"    column="table_num"    />
        <result property="shdzId"    column="shdz_id"    />
        <result property="shAddress"    column="sh_address"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectOrderParentVo">
        select id, user_id, order_status, total_amount, total_discount, actual_pay_amount, payment_method, payment_time, create_time, update_time, dd_id, table_num, shdz_id, sh_address, remarks from order_parent
    </sql>

    <select id="selectOrderParentList" parameterType="OrderParent" resultMap="OrderParentResult">
        <include refid="selectOrderParentVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="orderStatus != null "> and order_status = #{orderStatus}</if>
            <if test="totalAmount != null "> and total_amount = #{totalAmount}</if>
            <if test="totalDiscount != null "> and total_discount = #{totalDiscount}</if>
            <if test="actualPayAmount != null "> and actual_pay_amount = #{actualPayAmount}</if>
            <if test="paymentMethod != null  and paymentMethod != ''"> and payment_method = #{paymentMethod}</if>
            <if test="paymentTime != null "> and payment_time = #{paymentTime}</if>
            <if test="ddId != null  and ddId != ''"> and dd_id = #{ddId}</if>
            <if test="tableNum != null  and tableNum != ''"> and table_num = #{tableNum}</if>
            <if test="shdzId != null"> and shdz_id = #{shdzId}</if>
            <if test="shAddress != null  and shAddress != ''"> and sh_address = #{shAddress}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>

    <select id="selectOrderParentById" parameterType="Long" resultMap="OrderParentResult">
        <include refid="selectOrderParentVo"/>
        where id = #{id}
    </select>

    <insert id="insertOrderParent" parameterType="OrderParent">
        insert into order_parent
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="orderStatus != null">order_status,</if>
            <if test="totalAmount != null">total_amount,</if>
            <if test="totalDiscount != null">total_discount,</if>
            <if test="actualPayAmount != null">actual_pay_amount,</if>
            <if test="paymentMethod != null">payment_method,</if>
            <if test="paymentTime != null">payment_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="ddId != null">dd_id,</if>
            <if test="tableNum != null and tableNum != ''">table_num,</if>
            <if test="shdzId != null">shdz_id,</if>
            <if test="shAddress != null and shAddress != ''">sh_address,</if>
            <if test="remarks != null and remarks != ''">remarks,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userId != null">#{userId},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="totalAmount != null">#{totalAmount},</if>
            <if test="totalDiscount != null">#{totalDiscount},</if>
            <if test="actualPayAmount != null">#{actualPayAmount},</if>
            <if test="paymentMethod != null">#{paymentMethod},</if>
            <if test="paymentTime != null">#{paymentTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="ddId != null">#{ddId},</if>
            <if test="tableNum != null and tableNum != ''">#{tableNum},</if>
            <if test="shdzId != null">#{shdzId},</if>
            <if test="shAddress != null and shAddress != ''">#{shAddress},</if>
            <if test="remarks != null and remarks != ''">#{remarks},</if>
        </trim>
    </insert>

    <update id="updateOrderParent" parameterType="OrderParent">
        update order_parent
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="totalAmount != null">total_amount = #{totalAmount},</if>
            <if test="totalDiscount != null">total_discount = #{totalDiscount},</if>
            <if test="actualPayAmount != null">actual_pay_amount = #{actualPayAmount},</if>
            <if test="paymentMethod != null">payment_method = #{paymentMethod},</if>
            <if test="paymentTime != null">payment_time = #{paymentTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="ddId != null">dd_id = #{ddId},</if>
            <if test="tableNum != null and tableNum != ''">table_num = #{tableNum},</if>
            <if test="shdzId != null">shdz_id = #{shdzId},</if>
            <if test="shAddress != null and shAddress != ''">sh_address = #{shAddress},</if>
            <if test="remarks != null and remarks != ''">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderParentById" parameterType="Long">
        delete from order_parent where id = #{id}
    </delete>

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