<?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.TCanteenOrderDetailMapper">
    
    <resultMap type="TCanteenOrderDetail" id="TCanteenOrderDetailResult">
        <result property="detailId"    column="detail_id"    />
        <result property="orderId"    column="order_id"    />
        <result property="menuId"    column="menu_id"    />
        <result property="quantity"    column="quantity"    />
        <result property="unitPrice"    column="unit_price"    />
        <result property="transactionTime"    column="transaction_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="selectTCanteenOrderDetailVo">
        select detail_id, order_id, menu_id, quantity, unit_price, transaction_time, status, del_flag, creater_code, createdate, updater_code, updatedate, dept_id, remarks from t_canteen_order_detail
    </sql>

    <select id="selectTCanteenOrderDetailList" parameterType="TCanteenOrderDetail" resultMap="TCanteenOrderDetailResult">
        <include refid="selectTCanteenOrderDetailVo"/>
        <where>  
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="menuId != null "> and menu_id = #{menuId}</if>
            <if test="quantity != null  and quantity != ''"> and quantity = #{quantity}</if>
            <if test="unitPrice != null  and unitPrice != ''"> and unit_price = #{unitPrice}</if>
            <if test="transactionTime != null "> and transaction_time = #{transactionTime}</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="selectTCanteenOrderDetailByDetailId" parameterType="Long" resultMap="TCanteenOrderDetailResult">
        <include refid="selectTCanteenOrderDetailVo"/>
        where detail_id = #{detailId}
    </select>

    <insert id="insertTCanteenOrderDetail" parameterType="TCanteenOrderDetail" useGeneratedKeys="true" keyProperty="detailId">
        insert into t_canteen_order_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="menuId != null">menu_id,</if>
            <if test="quantity != null">quantity,</if>
            <if test="unitPrice != null">unit_price,</if>
            <if test="transactionTime != null">transaction_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="orderId != null">#{orderId},</if>
            <if test="menuId != null">#{menuId},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="unitPrice != null">#{unitPrice},</if>
            <if test="transactionTime != null">#{transactionTime},</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="updateTCanteenOrderDetail" parameterType="TCanteenOrderDetail">
        update t_canteen_order_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="menuId != null">menu_id = #{menuId},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="unitPrice != null">unit_price = #{unitPrice},</if>
            <if test="transactionTime != null">transaction_time = #{transactionTime},</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 detail_id = #{detailId}
    </update>

    <delete id="deleteTCanteenOrderDetailByDetailId" parameterType="Long">
        delete from t_canteen_order_detail where detail_id = #{detailId}
    </delete>

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