AssetRepo.java 8.6 KB

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