Browse Source

redisHash

licailing 4 years ago
parent
commit
693a49c321

+ 6 - 5
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -221,7 +221,7 @@ public class OrderService {
             AtomicInteger userMax = new AtomicInteger();
             userPropertyRepo.findById(userId).ifPresent(userProperty -> userMax.set(userProperty.getMaxCount()));
 
-            if (userMax.addAndGet(collection.getMaxCount()) > 0) {
+            if (collection.getMaxCount() > 0) {
                 int count;
                 if (StringUtils.isNotBlank(collection.getCountId())) {
                     count = orderRepo.countByUserIdAndCountIdAndStatusIn(userId, collection.getCountId(), Arrays
@@ -230,8 +230,8 @@ public class OrderService {
                     count = orderRepo.countByUserIdAndCollectionIdAndStatusIn(userId, collectionId, Arrays
                             .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
                 }
-                if (count >= collection.getMaxCount()) {
-                    throw new BusinessException("限购" + collection.getMaxCount() + "件");
+                if (count >= userMax.addAndGet(collection.getMaxCount()) ) {
+                    throw new BusinessException("限购" + userMax.get() + "件");
                 }
             }
             User user = null;
@@ -365,13 +365,14 @@ public class OrderService {
 
     public Object checkLimit(Long collectionId, Long userId) {
         Collection collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("藏品不存在"));
-        int limit = collection.getMaxCount();
+
         int count = 0;
 
         AtomicInteger userMax = new AtomicInteger();
         userPropertyRepo.findById(userId).ifPresent(userProperty -> userMax.set(userProperty.getMaxCount()));
+        int limit = userMax.addAndGet(collection.getMaxCount());
 
-        if (userMax.addAndGet(collection.getMaxCount()) > 0) {
+        if (collection.getMaxCount() > 0) {
             if (StringUtils.isNotBlank(collection.getCountId())) {
                 count = orderRepo.countByUserIdAndCountIdAndStatusIn(userId, collection.getCountId(),
                         Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));

+ 5 - 0
src/test/java/com/izouma/nineth/service/OrderServiceTest.java

@@ -329,4 +329,9 @@ public class OrderServiceTest extends ApplicationTests {
                     }
                 });
     }
+
+    @Test
+    public void test() {
+        System.out.println(orderService.checkLimit(8161101L, 9850L));
+    }
 }