<?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.BasicStallMealtimeMapper">
    <resultMap type="com.bonus.canteen.core.basic.domain.BasicStallMealtime" id="BasicStallMealtimeResult">
        <result property="id"    column="id"    />
        <result property="stallId"    column="stall_id"    />
        <result property="mealtimeType"    column="mealtime_type"    />
        <result property="mealtimeName"    column="mealtime_name"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="ifEnable"    column="if_enable"    />
        <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="selectBasicStallMealtimeVo">
        select id, stall_id, mealtime_type, mealtime_name, start_time, end_time, if_enable, create_by, create_time, update_by, update_time from basic_stall_mealtime
    </sql>

    <select id="selectBasicStallMealtimeList" parameterType="com.bonus.canteen.core.basic.domain.BasicStallMealtime" resultMap="BasicStallMealtimeResult">
        <include refid="selectBasicStallMealtimeVo"/>
        <where>  
            <if test="stallId != null "> and stall_id = #{stallId}</if>
            <if test="mealtimeType != null "> and mealtime_type = #{mealtimeType}</if>
            <if test="mealtimeName != null  and mealtimeName != ''"> and mealtime_name like concat('%', #{mealtimeName}, '%')</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="ifEnable != null  and ifEnable != ''"> and if_enable = #{ifEnable}</if>
        </where>
    </select>
    
    <select id="selectBasicStallMealtimeById" parameterType="Long" resultMap="BasicStallMealtimeResult">
        <include refid="selectBasicStallMealtimeVo"/>
        where id = #{id}
    </select>

    <insert id="batchInsertBasicStallMealtime" parameterType="com.bonus.canteen.core.basic.domain.BasicStallMealtime" useGeneratedKeys="true" keyProperty="id">
        insert into basic_stall_mealtime(stall_id, mealtime_type, mealtime_name, start_time, end_time)
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.stallId},
            #{item.mealtimeType},
            #{item.mealtimeName},
            #{item.startTime},
            #{item.endTime}
            )
        </foreach>
    </insert>

    <insert id="insertBasicStallMealtime" parameterType="com.bonus.canteen.core.basic.domain.BasicStallMealtime" useGeneratedKeys="true" keyProperty="id">
        insert into basic_stall_mealtime
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stallId != null">stall_id,</if>
            <if test="mealtimeType != null">mealtime_type,</if>
            <if test="mealtimeName != null">mealtime_name,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="ifEnable != null">if_enable,</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="stallId != null">#{stallId},</if>
            <if test="mealtimeType != null">#{mealtimeType},</if>
            <if test="mealtimeName != null">#{mealtimeName},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="ifEnable != null">#{ifEnable},</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="updateBasicStallMealtime" parameterType="com.bonus.canteen.core.basic.domain.BasicStallMealtime">
        update basic_stall_mealtime
        <trim prefix="SET" suffixOverrides=",">
            <if test="stallId != null">stall_id = #{stallId},</if>
            <if test="mealtimeType != null">mealtime_type = #{mealtimeType},</if>
            <if test="mealtimeName != null">mealtime_name = #{mealtimeName},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="ifEnable != null">if_enable = #{ifEnable},</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 id = #{id}
    </update>

    <delete id="deleteBasicStallMealtimeById" parameterType="Long">
        delete from basic_stall_mealtime where id = #{id}
    </delete>

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

    <delete id="deleteBasicStallMealtimeByStallId" parameterType="Long">
        delete from basic_stall_mealtime where stall_id = #{stallId}
    </delete>
</mapper>