<?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.cook.mapper.CookEvaluaDetailMapper">
    <resultMap type="com.bonus.canteen.core.cook.domain.CookEvaluaDetail" id="CookEvaluaDetailResult">
        <result property="evaluaDetailId"    column="evalua_detail_id"    />
        <result property="evaluaId"    column="evalua_id"    />
        <result property="mealType"    column="meal_type"    />
        <result property="mealId"    column="meal_id"    />
        <result property="dishesName"    column="dishes_name"    />
        <result property="starLevel"    column="star_level"    />
        <result property="description"    column="description"    />
        <result property="evaluaNickName"    column="nick_name"    />
        <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="selectCookEvaluaDetailVo">
        select ced.evalua_detail_id, ced.evalua_id, ced.meal_type, ced.meal_id, ced.star_level,
               ced.description, ced.create_by, ced.create_time, ced.update_by, ced.update_time,
               su.nick_name, cd.dishes_name
        from cook_evalua_detail ced
        left join cook_dishes cd on cd.dishes_id = ced.meal_id
        left join cook_evalua_order ceo on ceo.evalua_id = ced.evalua_id
        left join sys_user su on su.user_id = ceo.user_id
    </sql>

    <select id="selectCookEvaluaDetailList" parameterType="com.bonus.canteen.core.cook.domain.CookEvaluaDetail" resultMap="CookEvaluaDetailResult">
        <include refid="selectCookEvaluaDetailVo"/>
        <where>  
            <if test="evaluaId != null "> and ced.evalua_id = #{evaluaId}</if>
            <if test="mealType != null "> and ced.meal_type = #{mealType}</if>
            <if test="mealId != null "> and ced.meal_id = #{mealId}</if>
            <if test="starLevel != null "> and ced.star_level = #{starLevel}</if>
            <if test="description != null  and description != ''"> and ced.description = #{description}</if>
        </where>
    </select>
    
    <select id="selectCookEvaluaDetailByEvaluaDetailId" parameterType="Long" resultMap="CookEvaluaDetailResult">
        <include refid="selectCookEvaluaDetailVo"/>
        where ced.evalua_detail_id = #{evaluaDetailId}
    </select>
        
    <insert id="insertCookEvaluaDetail" parameterType="com.bonus.canteen.core.cook.domain.CookEvaluaDetail" useGeneratedKeys="true" keyProperty="evaluaDetailId">
        insert into cook_evalua_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="evaluaId != null">evalua_id,</if>
            <if test="mealType != null">meal_type,</if>
            <if test="mealId != null">meal_id,</if>
            <if test="starLevel != null">star_level,</if>
            <if test="description != null and description != ''">description,</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="evaluaId != null">#{evaluaId},</if>
            <if test="mealType != null">#{mealType},</if>
            <if test="mealId != null">#{mealId},</if>
            <if test="starLevel != null">#{starLevel},</if>
            <if test="description != null and description != ''">#{description},</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="updateCookEvaluaDetail" parameterType="com.bonus.canteen.core.cook.domain.CookEvaluaDetail">
        update cook_evalua_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="evaluaId != null">evalua_id = #{evaluaId},</if>
            <if test="mealType != null">meal_type = #{mealType},</if>
            <if test="mealId != null">meal_id = #{mealId},</if>
            <if test="starLevel != null">star_level = #{starLevel},</if>
            <if test="description != null and description != ''">description = #{description},</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_detail_id = #{evaluaDetailId}
    </update>

    <delete id="deleteCookEvaluaDetailByEvaluaDetailId" parameterType="Long">
        delete from cook_evalua_detail where evalua_detail_id = #{evaluaDetailId}
    </delete>

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