<?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.MenuCollectionDishesMapper">

    <!-- 根据人员id获取收藏菜品档口 -->
    <select id="selectCollectionDishesListById"
            resultType="com.bonus.canteen.core.menu.vo.MenuCollectionDishesVO">
        select
            md.shopstall_id,
            md.base_dishes_id as dishes_id,
            mdb.dishes_name,
            md.intro,
            md.type_id,
            md.image_url,
            if(md.large_price is not null, md.large_price, md.price) as price,
            mcd.cust_id,
            sum(mdsr.monthly_sales) as sale_num
        from
            menu_collection_dishes mcd
                left join alloc_stall ass on mcd.shopstall_id = ass.stall_id
                left join cust_info ci on mcd.cust_id = ci.cust_id
                left join menu_dishes md on mcd.dishes_id = md.base_dishes_id
                left join menu_dishes_base mdb on md.base_dishes_id = mdb.base_dishes_id
                left join menu_dishes_sale_record mdsr on md.dishes_id = mdsr.dishes_id
                    and mdsr.sale_month = month(curdate())
        where
            mcd.cust_id = #{custId}
            and md.del_flag = 2
        group by
            md.shopstall_id,
            md.base_dishes_id,
            mdb.dishes_name,
            md.intro,
            md.type_id,
            md.image_url,
            if(md.large_price is not null, md.large_price, md.price),
            mcd.cust_id
    </select>
</mapper>
