MetaTaskToUserRepo.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. package com.izouma.nineth.repo;
  2. import com.izouma.nineth.domain.MetaTaskToUser;
  3. import com.izouma.nineth.enums.MetaTaskStatus;
  4. import org.springframework.data.jpa.repository.JpaRepository;
  5. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  6. import org.springframework.data.jpa.repository.Modifying;
  7. import org.springframework.data.jpa.repository.Query;
  8. import javax.transaction.Transactional;
  9. import java.time.LocalDateTime;
  10. import java.util.List;
  11. import java.util.Map;
  12. public interface MetaTaskToUserRepo extends JpaRepository<MetaTaskToUser, Long>, JpaSpecificationExecutor<MetaTaskToUser> {
  13. MetaTaskToUser findByUserIdAndTaskIdAndDel(Long userId, Long taskId, boolean del);
  14. MetaTaskToUser findByIdAndDel(Long id, boolean del);
  15. List<MetaTaskToUser> findAllByUserIdAndChannelIdAndStatusAndDel(Long userId, Long channelId, MetaTaskStatus status, boolean del);
  16. @Modifying
  17. @Transactional
  18. @Query(value = "update MetaTaskToUser a set a.status = 'FINISH' where a.taskId = ?1 and a.del = false ")
  19. void finish(Long taskId);
  20. @Query(value = " SELECT m.user_id as userId," +
  21. "u.nickname as nickName," +
  22. "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"
  23. , nativeQuery = true)
  24. List<Map<String, Object>> snapshot(Long taskId, LocalDateTime createdAt, LocalDateTime lastCreatedAt);
  25. }