package com.bonus.canteen.core.menu.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.menu.entity.MenuSeasonDishes;
import com.bonus.canteen.core.menu.mapper.MenuSeasonDishesMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MenuSeasonDishesService extends ServiceImpl<MenuSeasonDishesMapper, MenuSeasonDishes> {
   public void insertBatch(List<Long> seasonList, Long dishesId) {
      seasonList.stream().map((season) -> {
         return (new MenuSeasonDishes()).setDishesId(dishesId).setSeason(season);
      }).forEach(this::save);
   }

   public List<Long> selectSeasonByDishesId(Long dishesId) {
      return this.listObjs(Wrappers.lambdaQuery(MenuSeasonDishes.class).eq(MenuSeasonDishes::getDishesId, dishesId)
              .eq(MenuSeasonDishes::getIfDel, 2).select(MenuSeasonDishes::getSeason)
      , Object::toString).stream().map(Long::valueOf).collect(Collectors.toList());
   }
   public void deleteByDishesId(Long dishesId) {
      this.remove(Wrappers.<MenuSeasonDishes>lambdaQuery()
              .eq(MenuSeasonDishes::getDishesId, dishesId));
   }
}
