package com.izouma.nineth.repo; import com.izouma.nineth.domain.MetaTaskToUser; import com.izouma.nineth.enums.MetaTaskStatus; 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; import java.util.Map; public interface MetaTaskToUserRepo extends JpaRepository, JpaSpecificationExecutor { MetaTaskToUser findByUserIdAndTaskIdAndDel(Long userId, Long taskId, boolean del); MetaTaskToUser findByIdAndDel(Long id, boolean del); List findAllByUserIdAndChannelIdAndStatusAndDel(Long userId, Long channelId, MetaTaskStatus status, boolean del); @Modifying @Transactional @Query(value = "update MetaTaskToUser a set a.status = 'FINISH' where a.taskId = ?1 and a.del = false ") void finish(Long taskId); @Query(value = " SELECT m.user_id as userId," + "u.nickname as nickName," + "u.phone as phone FROM meta_task_to_user m LEFT JOIN USER u ON m.user_id = u.id WHERE m.task_id = ?1 AND m.STATUS = 'FINISH' AND m.del = FALSE AND m.finish_time <= ?2 AND m.user_id NOT IN ( SELECT user_id FROM meta_task_to_user WHERE task_id = ?1 AND STATUS = 'FINISH' AND del = FALSE AND finish_time <= ?3 ) GROUP BY m.user_id" , nativeQuery = true) List> snapshot(Long taskId, LocalDateTime createdAt, LocalDateTime lastCreatedAt); }