<?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.allocation.canteen.mapper.AllocMealLineMapper">

    <!-- 分页查询餐线列表 -->
    <select id="pageMealLine" resultType="com.bonus.canteen.core.allocation.canteen.vo.AllocMealLineVO">
        SELECT
            t1.meal_line_id, t1.meal_line_num, t1.meal_line_name, t1.img_url, t1.meal_line_type, t1.area_id,
            t1.canteen_id, t1.stall_id, t1.cust_id, t1.contact_tel,
            t4.cust_name, t2.canteen_name, t3.stall_name, t5.area_name
        FROM
            alloc_meal_line t1
        INNER JOIN alloc_canteen t2 ON t1.canteen_id = t2.canteen_id
        INNER JOIN alloc_stall t3 ON t1.stall_id = t3.stall_id
        LEFT JOIN cust_info t4 ON t1.cust_id = t4.cust_id
        INNER JOIN alloc_area t5 ON t2.area_id = t5.area_id
        WHERE
            t1.if_del = #{param.ifDel}
            <if test="param.canteenId != null">
                AND t1.canteen_id = #{param.canteenId}
            </if>
            <if test="param.stallId != null">
                AND t1.stall_id = #{param.stallId}
            </if>
            <if test="param.mealLineName != null and param.mealLineName != ''">
                AND t1.meal_line_name LIKE #{param.mealLineName}
            </if>
            <if test="param.areaIdList != null and param.areaIdList.size() > 0">
                AND t2.area_id IN
                <foreach collection="param.areaIdList" item="areaId" separator="," open="(" close=")">
                    #{areaId}
                </foreach>
            </if>
        ORDER BY t1.meal_line_id DESC
    </select>

    <!-- 查询餐线列表，支持多个档口 -->
    <select id="listMultipleMealLine" resultType="com.bonus.canteen.core.allocation.canteen.vo.AllocMealLineVO">
        SELECT
            t1.meal_line_id, t1.meal_line_name
        FROM
            alloc_meal_line t1
        WHERE
            t1.if_del = 2
            <if test="stallIdList != null and stallIdList.size() > 0">
                AND t1.stall_id IN
                <foreach collection="stallIdList" item="stallId" separator="," open="(" close=")">
                    #{stallId}
                </foreach>
            </if>
    </select>

</mapper>
