package com.bonus.canteen.core.menu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bonus.canteen.core.menu.entity.MenuDishesBase;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface MenuDishesBaseMapper extends BaseMapper<MenuDishesBase> {
   @Select({"select 1 from menu_dishes_base mdb left join menu_dishes md on mdb.base_dishes_id = md.base_dishes_id where md.del_flag = 2 and mdb.dishes_name = #{dishesName} and md.canteen_id = #{canteenId} limit 1"})
   Integer selectExistName(@Param("dishesName") String dishesName, @Param("canteenId") Long canteenId);

   @Select({"select 1 from menu_dishes_base mdb left join menu_dishes md on mdb.base_dishes_id = md.base_dishes_id where md.del_flag = 2 and md.dishes_num = #{dishesNum} and md.canteen_id = #{canteenId} limit 1"})
   Integer selectExistNum(@Param("dishesNum") String dishesNum, @Param("canteenId") Long canteenId);

   @Select({"select 1 from menu_dishes_base mdb left join menu_dishes md on mdb.base_dishes_id = md.base_dishes_id where md.del_flag = 2 and mdb.dishes_name = #{dishesName} and md.canteen_id = #{canteenId} and mdb.base_dishes_id != #{dishesId} limit 1"})
   Integer selectExistNameById(@Param("dishesName") String dishesName, @Param("canteenId") Long canteenId, @Param("dishesId") Long dishesId);

   @Select({"select 1 from menu_dishes_base mdb left join menu_dishes md on mdb.base_dishes_id = md.base_dishes_id where md.del_flag = 2 and md.dishes_num = #{dishesNum} and md.canteen_id = #{canteenId} and mdb.base_dishes_id != #{dishesId} limit 1"})
   Integer selectExistNumById(@Param("dishesNum") String dishesNum, @Param("canteenId") Long canteenId, @Param("dishesId") Long dishesId);
}
