AssetRepo.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package com.izouma.nineth.repo;
  2. import com.izouma.nineth.domain.Asset;
  3. import com.izouma.nineth.enums.AssetStatus;
  4. import com.izouma.nineth.enums.CollectionType;
  5. import org.springframework.data.domain.Page;
  6. import org.springframework.data.domain.Pageable;
  7. import org.springframework.data.jpa.repository.JpaRepository;
  8. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  9. import org.springframework.data.jpa.repository.Modifying;
  10. import org.springframework.data.jpa.repository.Query;
  11. import javax.transaction.Transactional;
  12. import java.time.LocalDateTime;
  13. import java.util.*;
  14. public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationExecutor<Asset> {
  15. @Query("update Asset t set t.del = true where t.id = ?1")
  16. @Modifying
  17. @Transactional
  18. void softDelete(Long id);
  19. Asset findByIdAndUserIdAndDel(Long id, Long userId, boolean del);
  20. long countByIpfsUrlAndStatusNot(String ipfsUrl, AssetStatus status);
  21. List<Asset> findByCollectionId(Long collectionId);
  22. List<Asset> findByCollectionIdInAndStatus(Iterable<Long> collectionId, AssetStatus status);
  23. List<Asset> findAllByCollectionIdInAndStatusIn(List<Long> collectionId, Iterable<AssetStatus> statuses);
  24. List<Asset> findByCreatedAtBefore(LocalDateTime localDateTime);
  25. List<Asset> findByConsignmentTrue();
  26. List<Asset> findByTokenIdIn(Iterable<String> tokenId);
  27. List<Asset> findByTokenIdOrderByCreatedAt(String tokenId);
  28. List<Asset> findByOrderId(Long orderId);
  29. @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")
  30. Optional<Asset> findChild(Long id);
  31. @Query("select a from Asset a join User u on a.userId = u.id where a.consignment = true and u.settleAccountId is null")
  32. List<Asset> findNoAccount();
  33. Set<Asset> findAllByUserIdInAndCollectionId(List<Long> ids, Long collectionId);
  34. List<Asset> findByTxHash(String hash);
  35. List<Asset> findByIdIn(Iterable<Long> ids);
  36. @Query("select a from Asset a left join TokenHistory t on a.tokenId = t.tokenId where t.id is null")
  37. List<Asset> findByNoHistory();
  38. List<Asset> findByTokenIdAndCreatedAtBetween(String tokenId, LocalDateTime start, LocalDateTime end);
  39. Asset findFirstByTokenId(String tokenId);
  40. Asset findFirstByTxHashIsNullAndTokenIdNotNullAndStatusOrderByCreatedAt(AssetStatus status);
  41. @Query("select a from Asset a where a.txHash is null and a.tokenId is not null " +
  42. "and a.status = com.izouma.nineth.enums.AssetStatus.NORMAL and a.createdAt < ?1 " +
  43. "order by a.createdAt desc")
  44. List<Asset> toMint(LocalDateTime time);
  45. List<Asset> findAllByIdInAndUserId(Collection<Long> id, Long userId);
  46. @Query(value = "select c.id, c.pic, c.model3d, c.minter_avatar, c.owner_avatar, c.detail from asset c", nativeQuery = true)
  47. List<List<String>> selectResource();
  48. List<Asset> findAllByOwnerIdAndStatusAndOasisIdNotNull(Long userId, AssetStatus status);
  49. @Modifying
  50. @Transactional
  51. @Query(value = "update asset c set c.pic = ?2, c.model3d = ?3, c.minter_avatar = ?4, " +
  52. "c.owner_avatar = ?5, c.detail = ?6 where c.id = ?1", nativeQuery = true)
  53. int updateCDN(Long id, String pic, String model3d, String minterAvatar,
  54. String ownerAvatar, String detail);
  55. Page<Asset> findByUserIdAndStatusAndCompanyIdAndNameLike(Long userId, AssetStatus status, Long companyId, String name, Pageable pageable);
  56. List<Asset> findAllByOasisIdInAndStatusIn(List<Long> oasisIds, List<AssetStatus> assetStatuses);
  57. List<Asset> findAllByUserIdAndCollectionIdAndStatus(Long userId, Long collectionId, AssetStatus status);
  58. @Modifying
  59. @Transactional
  60. @Query(value = "update Asset a set a.holdDays = ?2 where a.id = ?1")
  61. void updateHoldDays(Long id, Integer holdDays);
  62. @Query("select a from Asset a " +
  63. " join a.tags t on t.id = ?2 " +
  64. "where a.userId = ?1 " +
  65. " and a.status = com.izouma.nineth.enums.AssetStatus.NORMAL")
  66. Page<Asset> byTag(Long userId, Long tagId, Pageable pageable);
  67. @Query(nativeQuery = true, value = "select id from asset where user_id = ?1 and collection_id in ?2 " +
  68. "and status = 'NORMAL' limit 1")
  69. Long findDiscount(Long userId, Collection<Long> ids);
  70. List<Asset> findByStatus(AssetStatus status);
  71. List<Asset> findAllByUserIdAndTypeAndOpenedAndCompanyId(Long userId, CollectionType type, Boolean opened, Long companyId);
  72. @Query(nativeQuery = true, value = "SELECT * FROM (SELECT asset.user_id userId,user.nickname nickname,user.username username,user.avatar avatar,asset.name,asset.prefix_name prefixName,count(*) num FROM asset left join user on asset.user_id = user.id where asset.user_id not in (1435297,4273750, 56302, 7209) and asset.status in ('NORMAL','TRADING','GIFTING','MINTING','AUCTIONING') GROUP BY asset.user_id) a WHERE a.num > 10")
  73. List<Map<String, String>> findAllUserHold();
  74. List<Asset> findAllByUserIdAndStatusIn(Long userId, List<AssetStatus> status);
  75. @Query("select a from Asset a where a.status in ?2 and a.userId = ?1 and a.name like ?3 and a.type in (com.izouma.nineth.enums.CollectionType.DEFAULT,com.izouma.nineth.enums.CollectionType.BLIND_BOX)")
  76. List<Asset> findAllByUserIdAndStatusInAndNameLike(Long userId, List<AssetStatus> status, String name);
  77. List<Asset> findAllByIdNotInAndUserIdAndStatusInAndOpened(List<Long> ids, Long userId, List<AssetStatus> status, boolean opened);
  78. List<Asset> findAllByUserIdAndStatusInAndOpened(Long userId, List<AssetStatus> status, boolean opened);
  79. @Query(value = "select count(tag_id) " +
  80. "from asset " +
  81. " left join asset_tag on asset.id = asset_tag.asset_id " +
  82. "where asset.user_id = ?1 and asset_tag.tag_id in ?2 group by tag_id", nativeQuery = true)
  83. long checkHoldingTags(Long userId, List<Long> tagIds);
  84. @Query(value = "select asset.* from asset left join asset_tag on asset.id = asset_tag.asset_id " +
  85. "where asset_tag.tag_id in ?2 " +
  86. "and asset.user_id = ?1 " +
  87. "and asset.status = 'NORMAL' " +
  88. "group by asset.id", nativeQuery = true)
  89. List<Asset> findByTagsContain(Long userId, List<Long> tagIds);
  90. @Query("select count(id) from Asset where status = ?2 and name like ?1")
  91. Long countDestroyed(String name, AssetStatus status);
  92. @Query("select count(id) from Asset where name like ?1 and status = 'NORMAL' and ownerId <> 1435297")
  93. Long countNameLikeNotDestroyed(String name);
  94. @Query(value = "select * from asset where name like ?1 and status in ?2 and id not in ?3 and del = false", nativeQuery = true)
  95. List<Asset> findAllBoats(String name, List<AssetStatus> status, List<Long> boatIds);
  96. @Query("select count(id) from Asset where name like ?1 and status = 'NORMAL' and ownerId = ?2")
  97. Long countNameLikeNotDestroyedAndOwner(String name,Long ownerId);
  98. }