licailing %!s(int64=3) %!d(string=hai) anos
pai
achega
a2f18e809d

+ 4 - 0
src/main/java/com/izouma/nineth/domain/UserProperty.java

@@ -1,13 +1,17 @@
 package com.izouma.nineth.domain;
 
 import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 import org.springframework.data.redis.core.RedisHash;
 
 import javax.persistence.Id;
 
 @RedisHash(value = "UserProperty", timeToLive = 86400L)
 @Data
+@AllArgsConstructor
+@NoArgsConstructor
 public class UserProperty {
     @ApiModelProperty("userId")
     @Id

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

@@ -25,7 +25,7 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
 
     List<Asset> findByCollectionId(Long collectionId);
 
-    List<Asset> findByCollectionIdAndStatusIn(Long collectionId, Iterable<AssetStatus> statuses);
+    List<Asset> findByCollectionIdInAndStatus(Iterable<Long> collectionId, AssetStatus status);
 
     List<Asset> findByCreatedAtBefore(LocalDateTime localDateTime);
 

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

@@ -240,4 +240,7 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
 
     @Query("select new com.izouma.nineth.dto.InvitedUserDTO(u.phone,u.authStatus,u.avatar,u.createdAt) from  User u where u.collectionId = ?1 and u.collectionInvitor = ?2")
     List<InvitedUserDTO> findInvitedDTO(Long collectionId, Long collectionInvitor);
+
+    @Query("select u.id from User u where u.del = false and u.level = 99")
+    List<Long> findIdByLevel();
 }

+ 44 - 0
src/test/java/com/izouma/nineth/repo/UserPropertyRepoTest.java

@@ -1,17 +1,27 @@
 package com.izouma.nineth.repo;
 
 import com.izouma.nineth.ApplicationTests;
+import com.izouma.nineth.domain.Asset;
 import com.izouma.nineth.domain.UserProperty;
+import com.izouma.nineth.enums.AssetStatus;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 
 public class UserPropertyRepoTest extends ApplicationTests {
 
     @Autowired
     private UserPropertyRepo userPropertyRepo;
+    @Autowired
+    private AssetRepo        assetRepo;
+    @Autowired
+    private UserRepo         userRepo;
 
     @Test
     public void save() {
@@ -35,4 +45,38 @@ public class UserPropertyRepoTest extends ApplicationTests {
     public void clear() {
     }
 
+    @Test
+    public void setProperty() {
+        //封神星主
+        List<Long> userIds = userRepo.findIdByLevel();
+        userIds.forEach(id -> {
+            UserProperty userProperty = userPropertyRepo.findById(id).orElse(new UserProperty(id, 0));
+            userProperty.setMaxCount(userProperty.getMaxCount() + 1);
+            if (userProperty.getMaxCount() > 5) {
+                userProperty.setMaxCount(5);
+            }
+            userPropertyRepo.save(userProperty);
+        });
+
+
+        //OASIS004:绿洲朋克战神3D持斧模型 2516069L 或  OASIS002: 绿洲朋克猴王3D旋转眺望模型 2514968L
+        //OASISPUNK007:OASISPUNK绿洲朋克族人共治会荣誉勋章 5050947L
+        //冠军赛 · 李小龙80周年纪念勋章 7275L
+        List<Asset> assets = assetRepo.findByCollectionIdInAndStatus(Arrays.asList(2516069L, 2514968L, 5050947L, 7275L), AssetStatus.NORMAL);
+        Map<Long, List<Asset>> collect = assets.stream().collect(Collectors.groupingBy(Asset::getOwnerId));
+        collect.forEach((key, value) -> {
+            List<Long> ids = value.stream().map(Asset::getCollectionId).distinct().collect(Collectors.toList());
+            int size = ids.size();
+            if (ids.contains(2516069L) && ids.contains(2514968L)) {
+                size -= 1;
+            }
+            UserProperty userProperty = userPropertyRepo.findById(key).orElse(new UserProperty(key, 0));
+            userProperty.setMaxCount(userProperty.getMaxCount() + size);
+            if (userProperty.getMaxCount() > 5) {
+                userProperty.setMaxCount(5);
+            }
+            userPropertyRepo.save(userProperty);
+        });
+
+    }
 }