<?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.basic.mapper.BasicCanteenEvaluateMapper">
    <resultMap type="com.bonus.canteen.core.basic.domain.BasicCanteenEvaluate" id="BasicCanteenEvaluateResult">
        <result property="evaluateId"    column="evaluate_id"    />
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="nick_name"    />
        <result property="areaId"    column="area_id"    />
        <result property="areaName"    column="area_name"    />
        <result property="canteenId"    column="canteen_id"    />
        <result property="canteenName"    column="canteen_name"    />
        <result property="stallId"    column="stall_id"    />
        <result property="stallName"    column="stall_name"    />
        <result property="evaluateDate"    column="evaluate_date"    />
        <result property="appearance"    column="appearance"    />
        <result property="attitude"    column="attitude"    />
        <result property="taste"    column="taste"    />
        <result property="varieties"    column="varieties"    />
        <result property="hygiene"    column="hygiene"    />
        <result property="price"    column="price"    />
        <result property="weight"    column="weight"    />
        <result property="proposal"    column="proposal"    />
        <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="selectBasicCanteenEvaluateVo">
        select bce.evaluate_id, bce.user_id, bce.area_id, bce.canteen_id, bce.stall_id, bce.evaluate_date, bce.appearance,
               bce.attitude, bce.taste, bce.varieties, bce.hygiene, bce.price, bce.weight, bce.proposal, bce.create_by,
               bce.create_time, bce.update_by, bce.update_time,
               su.nick_name, ba.area_name, bc.canteen_name, bst.stall_name
        from basic_canteen_evaluate bce
         left join sys_user su on su.user_id = bce.user_id
         left join basic_area ba on ba.area_id = bce.area_id
         left join basic_canteen bc on bc.canteen_id = bce.canteen_id
         left join basic_stall bst on bst.stall_id = bce.stall_id
    </sql>

    <select id="selectBasicCanteenEvaluateList" parameterType="com.bonus.canteen.core.basic.domain.BasicCanteenEvaluate" resultMap="BasicCanteenEvaluateResult">
        <include refid="selectBasicCanteenEvaluateVo"/>
        <where>  
            <if test="userId != null "> and bce.user_id = #{userId}</if>
            <if test="areaId != null "> and bce.area_id = #{areaId}</if>
            <if test="canteenId != null "> and bce.canteen_id = #{canteenId}</if>
            <if test="stallId != null "> and bce.stall_id = #{stallId}</if>
            <if test="evaluateDate != null "> and bce.evaluate_date = #{evaluateDate}</if>
            <if test="appearance != null "> and bce.appearance = #{appearance}</if>
            <if test="attitude != null "> and bce.attitude = #{attitude}</if>
            <if test="taste != null "> and bce.taste = #{taste}</if>
            <if test="varieties != null "> and bce.varieties = #{varieties}</if>
            <if test="hygiene != null "> and bce.hygiene = #{hygiene}</if>
            <if test="price != null "> and bce.price = #{price}</if>
            <if test="weight != null "> and bce.weight = #{weight}</if>
            <if test="proposal != null  and proposal != ''"> and bce.proposal = #{proposal}</if>
        </where>
    </select>
    
    <select id="selectBasicCanteenEvaluateByEvaluateId" parameterType="Long" resultMap="BasicCanteenEvaluateResult">
        <include refid="selectBasicCanteenEvaluateVo"/>
        where bce.evaluate_id = #{evaluateId}
    </select>
        
    <insert id="insertBasicCanteenEvaluate" parameterType="com.bonus.canteen.core.basic.domain.BasicCanteenEvaluate" useGeneratedKeys="true" keyProperty="evaluateId">
        insert into basic_canteen_evaluate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="areaId != null">area_id,</if>
            <if test="canteenId != null">canteen_id,</if>
            <if test="stallId != null">stall_id,</if>
            <if test="evaluateDate != null">evaluate_date,</if>
            <if test="appearance != null">appearance,</if>
            <if test="attitude != null">attitude,</if>
            <if test="taste != null">taste,</if>
            <if test="varieties != null">varieties,</if>
            <if test="hygiene != null">hygiene,</if>
            <if test="price != null">price,</if>
            <if test="weight != null">weight,</if>
            <if test="proposal != null">proposal,</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="userId != null">#{userId},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="canteenId != null">#{canteenId},</if>
            <if test="stallId != null">#{stallId},</if>
            <if test="evaluateDate != null">#{evaluateDate},</if>
            <if test="appearance != null">#{appearance},</if>
            <if test="attitude != null">#{attitude},</if>
            <if test="taste != null">#{taste},</if>
            <if test="varieties != null">#{varieties},</if>
            <if test="hygiene != null">#{hygiene},</if>
            <if test="price != null">#{price},</if>
            <if test="weight != null">#{weight},</if>
            <if test="proposal != null">#{proposal},</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="updateBasicCanteenEvaluate" parameterType="com.bonus.canteen.core.basic.domain.BasicCanteenEvaluate">
        update basic_canteen_evaluate
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="canteenId != null">canteen_id = #{canteenId},</if>
            <if test="stallId != null">stall_id = #{stallId},</if>
            <if test="evaluateDate != null">evaluate_date = #{evaluateDate},</if>
            <if test="appearance != null">appearance = #{appearance},</if>
            <if test="attitude != null">attitude = #{attitude},</if>
            <if test="taste != null">taste = #{taste},</if>
            <if test="varieties != null">varieties = #{varieties},</if>
            <if test="hygiene != null">hygiene = #{hygiene},</if>
            <if test="price != null">price = #{price},</if>
            <if test="weight != null">weight = #{weight},</if>
            <if test="proposal != null">proposal = #{proposal},</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 evaluate_id = #{evaluateId}
    </update>

    <delete id="deleteBasicCanteenEvaluateByEvaluateId" parameterType="Long">
        delete from basic_canteen_evaluate where evaluate_id = #{evaluateId}
    </delete>

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