Quellcode durchsuchen

1人一个积分

licailing vor 4 Jahren
Ursprung
Commit
a60e8e4ab1

+ 6 - 2
src/main/java/com/izouma/nineth/repo/UserRepo.java

@@ -181,9 +181,13 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
 
     List<User> findBySettleAccountIdIsNotNull();
 
+//    @Transactional
+//    @Modifying
+//    @Query("update User set vipPoint = vipPoint + ?2 where id = ?1")
+//    void updateVipPoint(Long id, int num);
+
     @Transactional
     @Modifying
-    @Query("update User set vipPoint = vipPoint + ?2 where id = ?1")
+    @Query("update User set vipPoint = ?2 where id = ?1")
     void updateVipPoint(Long id, int num);
-
 }

+ 5 - 4
src/main/java/com/izouma/nineth/service/UserService.java

@@ -202,6 +202,10 @@ public class UserService {
                     if (point <= 0) {
                         long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
                         if (count >= collection.getAssignment()) {
+                            // 扣除藏品额度
+                            if (ObjectUtils.isNotEmpty(collection.getVipQuota())) {
+                                collectionService.decreaseQuota(collectionId, 1);
+                            }
                             userRepo.updateVipPoint(invitor, 1);
                             pointRecordRepo.save(PointRecord.builder()
                                     .collectionId(collectionId)
@@ -209,10 +213,7 @@ public class UserService {
                                     .type("VIP_POINT")
                                     .point(1)
                                     .build());
-                            // 扣除藏品额度
-                            if (ObjectUtils.isNotEmpty(collection.getVipQuota())) {
-                                collectionService.decreaseQuota(collectionId, 1);
-                            }
+
                         }
                     }
                 }

+ 12 - 0
src/test/java/com/izouma/nineth/service/UserServiceTest.java

@@ -185,4 +185,16 @@ public class UserServiceTest extends ApplicationTests {
                 .idNo(identityAuth.getIdNo())
                 .build());
     }
+
+    @Test
+    public void test1() {
+        List<User> users = userRepo.findAll();
+        users.forEach(user -> {
+            if (user.getVipPoint() > 1) {
+                user.setVipPoint(1);
+            } else {
+
+            }
+        });
+    }
 }