TokenHistoryRepo.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.izouma.nineth.repo;
  2. import com.izouma.nineth.TokenHistory;
  3. import org.springframework.data.domain.Page;
  4. import org.springframework.data.domain.Pageable;
  5. import org.springframework.data.jpa.repository.JpaRepository;
  6. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  7. import org.springframework.data.jpa.repository.Modifying;
  8. import org.springframework.data.jpa.repository.Query;
  9. import javax.transaction.Transactional;
  10. import java.time.LocalDateTime;
  11. import java.util.Collection;
  12. import java.util.List;
  13. import java.util.Map;
  14. public interface TokenHistoryRepo extends JpaRepository<TokenHistory, Long>, JpaSpecificationExecutor<TokenHistory> {
  15. List<TokenHistory> findByTokenIdOrderByCreatedAtDesc(String tokenId);
  16. @Query("select t from TokenHistory t where t.toUserId = ?1 or t.fromUserId = ?1 order by t.createdAt desc")
  17. Page<TokenHistory> userHistory(Long userId, Pageable pageable);
  18. @Query("select t from TokenHistory t where t.toUserId = ?2 or t.fromUserId = ?1 order by t.createdAt desc")
  19. Page<TokenHistory> userHistoryTo(Long userId, Long toUserId, Pageable pageable);
  20. @Query("select t from TokenHistory t where t.toUserId = ?1 or t.fromUserId = ?2 order by t.createdAt desc")
  21. Page<TokenHistory> userHistoryFrom(Long userId, Long fromUserId, Pageable pageable);
  22. @Query("select t from TokenHistory t where t.toUserId = ?1 or t.fromUserId = ?1 order by t.createdAt desc")
  23. List<TokenHistory> userHistory(Long userId);
  24. @Query("select t from TokenHistory t where t.toUserId in ?1 and t.price is not null")
  25. List<TokenHistory> userBuy(Collection<Long> userId);
  26. @Transactional
  27. @Modifying
  28. int deleteByTokenId(String tokenId);
  29. @Query("select t from TokenHistory t where t.fromUserId = t.toUserId")
  30. List<TokenHistory> findError();
  31. List<TokenHistory> findByOperationAndPriceNull(String oper);
  32. @Query(nativeQuery = true, value = "select to_user_id , to_user, sum(price) total from token_history " +
  33. "where created_at between ?1 and ?2 group by to_user_id order by sum(price) desc limit ?3")
  34. List<Map<String, Object>> sumPrice(LocalDateTime start, LocalDateTime end, int size);
  35. }