<?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.order.mapper.TCanteenOrderMapper">
    
    <resultMap type="TCanteenOrder" id="TCanteenOrderResult">
        <result property="orderId"    column="order_id"    />
        <result property="userId"    column="user_id"    />
        <result property="supplierId"    column="supplier_id"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="totalAmount"    column="total_amount"    />
        <result property="scheduledTime"    column="scheduled_time"    />
        <result property="completeTime"    column="complete_time"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTCanteenOrderVo">
        select order_id, user_id, supplier_id, order_status, total_amount, scheduled_time, complete_time, status, del_flag, creater_code, createdate, updater_code, updatedate, dept_id, remarks from t_canteen_order
    </sql>

    <select id="selectTCanteenOrderList" parameterType="TCanteenOrder" resultMap="TCanteenOrderResult">
        <include refid="selectTCanteenOrderVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="supplierId != null "> and supplier_id = #{supplierId}</if>
            <if test="orderStatus != null "> and order_status = #{orderStatus}</if>
            <if test="totalAmount != null  and totalAmount != ''"> and total_amount = #{totalAmount}</if>
            <if test="scheduledTime != null "> and scheduled_time = #{scheduledTime}</if>
            <if test="completeTime != null "> and complete_time = #{completeTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>
    
    <select id="selectTCanteenOrderByOrderId" parameterType="Long" resultMap="TCanteenOrderResult">
        <include refid="selectTCanteenOrderVo"/>
        where order_id = #{orderId}
    </select>

    <insert id="insertTCanteenOrder" parameterType="TCanteenOrder" useGeneratedKeys="true" keyProperty="orderId">
        insert into t_canteen_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="supplierId != null">supplier_id,</if>
            <if test="orderStatus != null">order_status,</if>
            <if test="totalAmount != null">total_amount,</if>
            <if test="scheduledTime != null">scheduled_time,</if>
            <if test="completeTime != null">complete_time,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="supplierId != null">#{supplierId},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="totalAmount != null">#{totalAmount},</if>
            <if test="scheduledTime != null">#{scheduledTime},</if>
            <if test="completeTime != null">#{completeTime},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTCanteenOrder" parameterType="TCanteenOrder">
        update t_canteen_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="supplierId != null">supplier_id = #{supplierId},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="totalAmount != null">total_amount = #{totalAmount},</if>
            <if test="scheduledTime != null">scheduled_time = #{scheduledTime},</if>
            <if test="completeTime != null">complete_time = #{completeTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where order_id = #{orderId}
    </update>

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

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