package com.itheima.dao;

import com.itheima.domain.MoneyPackage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/*****
 * @Author: http://www.itheima.com
 * @Description: com.itheima.dao.MoneyPackageDao
 ****/
@Mapper
public interface MoneyPackageDao {


    /***
     * 加载延时发放红包
     * @return
     */
    @Select("SELECT * FROM money_package WHERE type=1 AND hasload=1")
    List<MoneyPackage> loadDelayData();

    /***
     * 变更加载状态
     * @param id
     * @param type ：1 未加载，2 已加载 , 3已落Redis缓存库
     */
    @Update("update money_package set hasload=#{type} where id=#{id} and hasload=#{oldType}")
    int modifyHasload(@Param("id") Integer id,@Param("type") Integer type,@Param("oldType") Integer oldType);

    /***
     * 查询第1条红包记录
     * @return
     */
    @Select("SELECT * FROM money_package WHERE hasload=1 ORDER BY sort DESC LIMIT 1")
    MoneyPackage findOne();

    /*****
     * 根据id修改isload的状态
     * @param id
     */
    @Update("UPDATE money_package SET hasload=3 WHERE id=#{id}")
    void modify(Integer id);
}
