<?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.bonus.canteen.core.menu.mapper.MenuEvaluaOrderMapper">
    <resultMap type="com.bonus.canteen.core.menu.domain.MenuEvaluaOrder" id="MenuEvaluaOrderResult">
        <result property="evaluaId"    column="evalua_id"    />
        <result property="ordId"    column="ord_id"    />
        <result property="starLevel"    column="star_level"    />
        <result property="description"    column="description"    />
        <result property="reply"    column="reply"    />
        <result property="replyTime"    column="reply_time"    />
        <result property="shopstallId"    column="shopstall_id"    />
        <result property="stallName"    column="stall_name"    />
        <result property="showFlag"    column="show_flag"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="revision"    column="revision"    />
        <result property="orderEvaluaType"    column="order_evalua_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMenuEvaluaOrderVo">
        select meo.evalua_id, meo.ord_id, meo.star_level, meo.description, meo.reply, meo.reply_time,
               meo.shopstall_id, meo.show_flag, meo.del_flag, meo.revision, meo.order_evalua_type,
               meo.create_by, meo.create_time, meo.update_by, meo.update_time, ast.stall_name
        from menu_evalua_order meo
        left join alloc_stall ast on meo.shopstall_id = ast.stall_id
    </sql>

    <select id="selectMenuEvaluaOrderList" parameterType="com.bonus.canteen.core.menu.domain.MenuEvaluaOrder" resultMap="MenuEvaluaOrderResult">
        <include refid="selectMenuEvaluaOrderVo"/>
        <where>  
            <if test="evaluaId != null "> and meo.evalua_id = #{evaluaId}</if>
            <if test="ordId != null "> and meo.ord_id = #{ordId}</if>
            <if test="starLevel != null "> and meo.star_level = #{starLevel}</if>
            <if test="description != null  and description != ''"> and meo.description = #{description}</if>
            <if test="reply != null  and reply != ''"> and meo.reply = #{reply}</if>
            <if test="replyTime != null "> and meo.reply_time = #{replyTime}</if>
            <if test="shopstallId != null "> and meo.shopstall_id = #{shopstallId}</if>
            <if test="showFlag != null "> and meo.show_flag = #{showFlag}</if>
            <if test="revision != null "> and meo.revision = #{revision}</if>
            <if test="orderEvaluaType != null "> and meo.order_evalua_type = #{orderEvaluaType}</if>
        </where>
    </select>
    
    <select id="selectMenuEvaluaOrderById" parameterType="Long" resultMap="MenuEvaluaOrderResult">
        <include refid="selectMenuEvaluaOrderVo"/>
        where meo.ord_id = #{orderId}
    </select>
        
    <insert id="insertMenuEvaluaOrder" parameterType="com.bonus.canteen.core.menu.dto.MenuEvaluaOrderAddDTO" useGeneratedKeys="true" keyProperty="evaluaId">
        insert into menu_evalua_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ordId != null">ord_id,</if>
            <if test="starLevel != null">star_level,</if>
            <if test="description != null and description != ''">description,</if>
            <if test="reply != null">reply,</if>
            <if test="replyTime != null">reply_time,</if>
            <if test="shopstallId != null">shopstall_id,</if>
            <if test="showFlag != null">show_flag,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="revision != null">revision,</if>
            <if test="orderEvaluaType != null">order_evalua_type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ordId != null">#{ordId},</if>
            <if test="starLevel != null">#{starLevel},</if>
            <if test="description != null and description != ''">#{description},</if>
            <if test="reply != null">#{reply},</if>
            <if test="replyTime != null">#{replyTime},</if>
            <if test="shopstallId != null">#{shopstallId},</if>
            <if test="showFlag != null">#{showFlag},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="revision != null">#{revision},</if>
            <if test="orderEvaluaType != null">#{orderEvaluaType},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateMenuEvaluaOrder" parameterType="com.bonus.canteen.core.menu.domain.MenuEvaluaOrder">
        update menu_evalua_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="ordId != null">ord_id = #{ordId},</if>
            <if test="starLevel != null">star_level = #{starLevel},</if>
            <if test="description != null and description != ''">description = #{description},</if>
            <if test="reply != null">reply = #{reply},</if>
            <if test="replyTime != null">reply_time = #{replyTime},</if>
            <if test="shopstallId != null">shopstall_id = #{shopstallId},</if>
            <if test="showFlag != null">show_flag = #{showFlag},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="revision != null">revision = #{revision},</if>
            <if test="orderEvaluaType != null">order_evalua_type = #{orderEvaluaType},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where evalua_id = #{evaluaId}
    </update>

    <delete id="deleteMenuEvaluaOrderById" parameterType="Long">
        delete from menu_evalua_order where evalua_id = #{evaluaId}
    </delete>

    <delete id="deleteMenuEvaluaOrderByIds" parameterType="String">
        delete from menu_evalua_order where evalua_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{evaluaId}
        </foreach>
    </delete>

    <update id="updateOrderEvaluaStatus" parameterType="Long">
        update order_info
        set comment_state = 1
        where order_id = #{orderId}
    </update>
</mapper>