Kaynağa Gözat

distinctPrefix

wangqifan 3 yıl önce
ebeveyn
işleme
5b7128d68d

+ 4 - 0
src/main/java/com/izouma/nineth/config/CacheConfig.java

@@ -171,6 +171,10 @@ public class CacheConfig {
         cacheNamesConfigurationMap.put("domainBuyerTop", RedisCacheConfiguration.defaultCacheConfig()
                 .entryTtl(Duration.ofDays(7))
                 .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisTemplate.getValueSerializer())));
+        cacheNamesConfigurationMap.put("countByPrefix", RedisCacheConfiguration.defaultCacheConfig()
+                .entryTtl(Duration.ofMinutes(15))
+                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisTemplate.getValueSerializer())));
+
         RedisCacheManager redisCacheManager = RedisCacheManager.builder()
                 .cacheWriter(RedisCacheWriter.nonLockingRedisCacheWriter(redisTemplate.getConnectionFactory()))
                 .withInitialCacheConfigurations(cacheNamesConfigurationMap)

+ 5 - 2
src/main/java/com/izouma/nineth/domain/Collection.java

@@ -272,10 +272,10 @@ public class Collection extends CollectionBaseEntity {
     @Column(columnDefinition = "TEXT")
     private String rule;
 
-    private String hcTxHash;
+    private String     hcTxHash;
     private BigInteger hcBlockNumber;
     private BigInteger hcGasUsed;
-    private String hcTokenId;
+    private String     hcTokenId;
 
     @ApiModelProperty("系列名称")
     @Column(length = 100)
@@ -309,4 +309,7 @@ public class Collection extends CollectionBaseEntity {
     @ApiModelProperty("元宇宙尺寸")
     @Enumerated(EnumType.STRING)
     private MetaSize metaSize;
+
+    @Transient
+    private Long transferringCount;
 }

+ 3 - 0
src/main/java/com/izouma/nineth/repo/AssetRepo.java

@@ -152,6 +152,9 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
     @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);
 

+ 6 - 0
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -36,6 +36,7 @@ import org.springframework.data.redis.core.BoundValueOperations;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.TaskScheduler;
 import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import javax.annotation.PostConstruct;
@@ -824,4 +825,9 @@ public class CollectionService {
     public Long countDestroyAssets(String search) {
         return assetRepo.countDestroyed("%" + search + "%", AssetStatus.DESTROYED);
     }
+
+    @Cacheable(value = "countByPrefix", key = "#prefixName")
+    public String countNum(String prefixName) {
+        return assetRepo.countPrefixNameLikeNotDestroyed("%" + prefixName + "%");
+    }
 }

+ 12 - 0
src/main/java/com/izouma/nineth/web/CollectionController.java

@@ -22,6 +22,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.Pageable;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.util.CollectionUtils;
@@ -82,6 +83,16 @@ public class CollectionController extends BaseController {
     public Page<Collection> all(@RequestBody PageQuery pageQuery) {
         pageQuery.getQuery().putIfAbsent("companyId", 1);
         Page<Collection> page = collectionService.all(pageQuery).toPage();
+        if (pageQuery.getQuery().get("distinctPrefix") != null) {
+            List<Collection> newContent = new ArrayList<>();
+            page.getContent().forEach(collection -> {
+                String count = collectionService.countNum(collection.getPrefixName());
+                collection.setTransferringCount(Long.valueOf(count));
+                newContent.add(collection);
+            });
+            collectionService.queryUserDetail(page.getContent());
+            return new PageImpl<>(newContent, page.getPageable(), page.getTotalElements());
+        }
         collectionService.queryUserDetail(page.getContent());
         return page;
     }
@@ -248,5 +259,6 @@ public class CollectionController extends BaseController {
         map.put("tranferingNum", String.valueOf(tranferCount - 1));
         return map;
     }
+
 }