package com.izouma.nineth.repo;

import com.izouma.nineth.domain.ActivityInvite;
import com.izouma.nineth.domain.Asset;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.time.LocalDateTime;
import java.util.List;

public interface ActivityInviteRepo  extends JpaRepository<ActivityInvite, Long>, JpaSpecificationExecutor<ActivityInvite> {
    @Query("update ActivityInvite t set t.del = true where t.id = ?1")
    @Modifying
    @Transactional
    void softDelete(Long id);

    /**
     *  根据项目ID查询当前开启的活动
     * @param time
     * @return
     */
    @Query(nativeQuery = true ,value = "select * from activity_invite  where invite_startdatetime <= ?1 and invite_enddatetime >?1  and del = false  order by created_at desc limit 1")
    ActivityInvite asdasdasfaf(LocalDateTime time);


    /**
     * 根据项目ID查询最近的活动
     * @return
     */
    @Query(nativeQuery = true ,value = "select * from activity_invite  where del = false order by created_at desc limit 1")
    ActivityInvite findRecent();
}
