package com.tenlionsoft.baselib.core.db.daos;

import com.tenlionsoft.baselib.core.db.beans.FoodFoodBean;

import java.util.List;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

/**
 * 作者: adam
 * 日期: 2022/3/28 - 4:43 下午
 * 邮箱: itgaojian@163.com
 * 描述: 菜品表
 */
@Dao
public interface FoodFoodDao {
    /**
     * 插入多个菜品
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertAll(FoodFoodBean... beans);

    /**
     * 批量添加
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertAll(List<FoodFoodBean> beans);

    /**
     * 获取全部信息
     *
     * @return
     */
    @Query("SELECT * FROM food_food")
    List<FoodFoodBean> getAllFood();

    /**
     * 获取某个时间 某个类型(早、中、晚)所有菜品
     */
    @Query("SELECT * FROM food_food  WHERE uid IN (SELECT food_id FROM food_publish_food f2 WHERE f2.publish_id = (SELECT publish_id FROM food_publish f1 WHERE publish_type=:type AND publish_date=:date)) ORDER BY gmt_create DESC LIMIT ((:page)-1)*(:pageSize),(:pageSize)")
    List<FoodFoodBean> getFoodByDateAndType(String date, String type, int page, int pageSize);

    /**
     * 获取最后一条数据
     */
    @Query("SELECT * FROM food_food order by sync_number desc limit 1")
    FoodFoodBean getLastOne();

}
