package com.izouma.nineth.repo; import com.izouma.nineth.domain.Asset; import com.izouma.nineth.dto.FuAssetDTO; import com.izouma.nineth.dto.MetaRestResult; import com.izouma.nineth.enums.AssetSource; import com.izouma.nineth.enums.AssetStatus; import com.izouma.nineth.enums.CollectionType; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import javax.transaction.Transactional; import java.time.LocalDateTime; import java.util.*; public interface AssetRepo extends JpaRepository, JpaSpecificationExecutor { @Query("update Asset t set t.del = true where t.id = ?1") @Modifying @Transactional void softDelete(Long id); Asset findByIdAndUserIdAndDel(Long id, Long userId, boolean del); long countByIpfsUrlAndStatusNot(String ipfsUrl, AssetStatus status); List findByCollectionId(Long collectionId); List findByCollectionIdInAndStatus(Iterable collectionId, AssetStatus status); List findAllByCollectionIdInAndStatusIn(List collectionId, Iterable statuses); List findAllByCollectionIdAndStatusInAndUserId(Long collectionId, Iterable statuses, Long userId); List findByCreatedAtBefore(LocalDateTime localDateTime); Optional findByCollectionIdAndStatus(Long collectionId,AssetStatus statuses ); Optional findByIdAndStatus(Long collectionId,AssetStatus statuses ); List findByConsignmentTrue(); List findByTokenIdIn(Iterable tokenId); List findByTokenIdOrderByCreatedAt(String tokenId); List findAllByUserIdAndCompanyIdAndStatusIn(Long userId, Long companyId, List status); List findByOrderId(Long orderId); Page findByUserIdAndStatusAndCompanyIdAndNameLikeAndConsignment(Long userId, AssetStatus status, Long companyId, String name, Pageable pageable, Boolean consignment); @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") Optional findChild(Long id); @Query("select a from Asset a join User u on a.userId = u.id where a.consignment = true and u.settleAccountId is null") List findNoAccount(); Set findAllByUserIdInAndCollectionId(List ids, Long collectionId); List findByTxHash(String hash); List findByIdIn(Iterable ids); @Query("select a from Asset a left join TokenHistory t on a.tokenId = t.tokenId where t.id is null") List findByNoHistory(); List findByTokenIdAndCreatedAtBetween(String tokenId, LocalDateTime start, LocalDateTime end); Asset findFirstByTokenId(String tokenId); Asset findFirstByTxHashIsNullAndTokenIdNotNullAndStatusOrderByCreatedAt(AssetStatus status); @Query("select a from Asset a where a.txHash is null and a.tokenId is not null " + "and a.status = com.izouma.nineth.enums.AssetStatus.NORMAL and a.createdAt < ?1 " + "order by a.createdAt desc") List toMint(LocalDateTime time); List findAllByIdInAndUserId(Collection id, Long userId); @Query(value = "select c.id, c.pic, c.model3d, c.minter_avatar, c.owner_avatar, c.detail from asset c", nativeQuery = true) List> selectResource(); List findAllByOwnerIdAndStatusAndOasisIdNotNull(Long userId, AssetStatus status); @Modifying @Transactional @Query(value = "update asset c set c.pic = ?2, c.model3d = ?3, c.minter_avatar = ?4, " + "c.owner_avatar = ?5, c.detail = ?6 where c.id = ?1", nativeQuery = true) int updateCDN(Long id, String pic, String model3d, String minterAvatar, String ownerAvatar, String detail); Page findByUserIdAndStatusAndCompanyIdAndNameLike(Long userId, AssetStatus status, Long companyId, String name, Pageable pageable); List findAllByOasisIdInAndStatusIn(List oasisIds, List assetStatuses); List findAllByUserIdAndCollectionIdAndStatus(Long userId, Long collectionId, AssetStatus status); @Modifying @Transactional @Query(value = "update Asset a set a.holdDays = ?2 where a.id = ?1") void updateHoldDays(Long id, Integer holdDays); @Query("select a from Asset a " + " join a.tags t on t.id = ?2 " + "where a.userId = ?1 " + " and a.status = com.izouma.nineth.enums.AssetStatus.NORMAL") Page byTag(Long userId, Long tagId, Pageable pageable); @Query(nativeQuery = true, value = "select id from asset where user_id = ?1 and collection_id in ?2 " + "and status = 'NORMAL' limit 1") Long findDiscount(Long userId, Collection ids); @Query(nativeQuery = true, value = "select collection_id from asset where user_id = ?1 and collection_id in ?2 " + "and status = 'NORMAL'") Set findDiscounts(Long userId, Collection ids); List findByStatus(AssetStatus status); List findAllByUserIdAndTypeAndOpenedAndCompanyId(Long userId, CollectionType type, Boolean opened, Long companyId); @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") List> findAllUserHold(); List findAllByUserIdAndDelAndStatusIn(Long userId, boolean del, List status); @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)") List findAllByUserIdAndStatusInAndNameLike(Long userId, List status, String name); @Query("select a from Asset a where a.status = 'NORMAL' and a.consignment = true and a.name like ?1") List findOnShelfByNameLike(String search); List findAllByIdNotInAndUserIdAndStatusInAndOpened(List ids, Long userId, List status, boolean opened); List findAllByUserIdAndStatusInAndOpened(Long userId, List status, boolean opened); @Query(value = "select count(tag_id) " + "from asset " + " left join asset_tag on asset.id = asset_tag.asset_id " + "where asset.user_id = ?1 and asset_tag.tag_id in ?2 group by tag_id", nativeQuery = true) long checkHoldingTags(Long userId, List tagIds); @Query(value = "select asset.* from asset left join asset_tag on asset.id = asset_tag.asset_id " + "where asset_tag.tag_id in ?2 " + "and asset.user_id = ?1 " + "and asset.status = 'NORMAL' " + "group by asset.id", nativeQuery = true) List findByTagsContain(Long userId, List tagIds); @Query("select count(id) from Asset where status = ?2 and name like ?1") Long countDestroyed(String name, AssetStatus status); @Query("select count(id) from Asset where name like ?1 and status in ('NORMAL','TRADING','GIFTING','MINTING','AUCTIONING','AUCTION_TRADING','DESTROYING') and ownerId <> 1435297") Long countNameLikeNotDestroyed(String name); @Query("select count(id) from Asset where prefixName like ?1 and status in ('NORMAL','TRADING','GIFTING','MINTING','AUCTIONING','AUCTION_TRADING','DESTROYING') and ownerId <> 1435297") String countPrefixNameLikeNotDestroyed(String name); @Query(value = "SELECT count(a.id) from asset a where a.name LIKE ?1 and status = 'NORMAL' and owner_id = ?2", nativeQuery = true) Long countNameLikeNotDestroyedAndOwner(String name, Long ownerId); @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") List findAllBoats(String name, List status, List boatIds, String like, String unLike, Long userId); @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") List queryFu(Long userId, List status, List prefixNames); Asset findFirstByCollectionIdAndUserIdAndSource(Long collectionId, Long userId, AssetSource source); Long countAllByCollectionIdAndUserIdAndSource(Long collectionId, Long userId, AssetSource source); @Query(nativeQuery = true, value = "select count(a.id) countNum,a.user_Id userId,a.owner_avatar avatar,a.`owner` nickname from asset a inner join `user` u on u.id = a.user_id where a.status = 'NORMAL' and a.type = 'DOMAIN' GROUP BY a.user_id ORDER BY count(a.id) desc limit 60") List> domainTop20(); @Query(nativeQuery = true, value = "select count(a.id) countNum,sum(price) amount,a.user_Id userId,u.avatar avatar,u.nickname nickname from order_info a inner join `user` u on u.id = a.user_id where a.status = 'FINISH' and a.type = 'DOMAIN'\n" + " and a.created_at <= ?2 and a.created_at >= ?1 GROUP BY a.user_id ORDER BY sum(price) desc limit 60") List> domainBuyerTop60(LocalDateTime start, LocalDateTime end); @Query(nativeQuery = true, value = "update asset a set a.hold_days = null,a.old_hold_days = null where a.name like ?1") @Modifying @Transactional void openTrade(String name); Asset findFirstByNameAndStatus(String name, AssetStatus status); Asset findByNameAndStatusAndCategoryAndDel(String name, AssetStatus status, String categroy,boolean del); @Query(nativeQuery = true,value = "select phone from asset inner join user on asset.user_id = user.id where asset.name like ?1 and status = 'NORMAL' and category = '元域名'") String findPhone(String name); }