package com.webchat.repository.dao.lottery;

import com.webchat.repository.entity.lottery.LotteryActivityEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author 程序员七七
 * @webSite https://www.coderutil.com
 * @Date 2022/11/16 23:49
 * @description
 */
@Repository
public interface ILotteryActivityDAO extends JpaSpecificationExecutor<LotteryActivityEntity>,
        JpaRepository<LotteryActivityEntity, Long> {

    /**
     * 根据活动id查询活动详情数据
     * @param activityId
     * @return
     */
    LotteryActivityEntity findByActivityId(String activityId);

    /**
     * 查询历史所有抽奖活动
     * @param status
     * @return
     */
    List<LotteryActivityEntity> findAllByStatusNotOrderByCreateDateDesc(Integer status);

    @Query(value = "select a.activity_id from web_chat_lottery_activity a where a.status != 4 order by a. id desc limit 1",
            nativeQuery = true)
    String findByLastLotteryActivity();
}
