AssetRepo.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.izouma.nineth.repo;
  2. import com.izouma.nineth.domain.Asset;
  3. import com.izouma.nineth.enums.AssetStatus;
  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.Optional;
  12. public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationExecutor<Asset> {
  13. @Query("update Asset t set t.del = true where t.id = ?1")
  14. @Modifying
  15. @Transactional
  16. void softDelete(Long id);
  17. long countByIpfsUrlAndStatusNot(String ipfsUrl, AssetStatus status);
  18. List<Asset> findByCollectionId(Long collectionId);
  19. List<Asset> findByCollectionIdAndStatusIn(Long collectionId, Iterable<AssetStatus> statuses);
  20. List<Asset> findByCreatedAtBefore(LocalDateTime localDateTime);
  21. List<Asset> findByConsignmentTrue();
  22. List<Asset> findByTokenIdIn(Iterable<String> tokenId);
  23. List<Asset> findByTokenIdOrderByCreatedAt(String tokenId);
  24. List<Asset> findByOrderId(Long orderId);
  25. @Query("select a from Asset a join Order o on o.assetId = a.id join Asset aa on aa.orderId = o.id where a.id = ?1")
  26. Optional<Asset> findChild(Long id);
  27. @Query("select a from Asset a join User u on a.userId = u.id where a.consignment = true and u.settleAccountId is null")
  28. List<Asset> findNoAccount();
  29. List<Asset> findByUserId(Long userId);
  30. Asset findFirstByTokenIdAndCreatedAtAfterOrderByCreatedAt(String tokenId, LocalDateTime time);
  31. List<Asset> findByTxHashIsNullAndTokenIdNotNullAndCreatedAtBefore(LocalDateTime time);
  32. @Query("select id from Asset where status = ?1")
  33. List<Long> findAllByStatus(AssetStatus status);
  34. @Query(nativeQuery = true, value = "select asset.* from asset " +
  35. "join collection_info on asset.collection_id = collection_info.id " +
  36. "where asset.number > collection_info.total and status = 'NORMAL'")
  37. List<Asset> findOverNumber();
  38. @Query(nativeQuery = true, value = "select * from asset " +
  39. "where name = ?1 " +
  40. "and number <= ?2 and public_show = false and consignment = false " +
  41. "and modified_at < date_sub(now(), INTERVAL 7 DAY) " +
  42. "and number > 5 and status = 'NORMAL' " +
  43. "order by modified_at")
  44. List<Asset> findColdAsset(String name, int number);
  45. }