licailing 4 gadi atpakaļ
vecāks
revīzija
c5fa5ab4fd

+ 11 - 4
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -218,6 +218,7 @@ public class OrderService {
                 throw new BusinessException("该藏品当前不可购买");
             }
 
+
             AtomicInteger userMax = new AtomicInteger();
             userPropertyRepo.findById(userId).ifPresent(userProperty -> userMax.set(userProperty.getMaxCount()));
 
@@ -230,9 +231,16 @@ public class OrderService {
                     count = orderRepo.countByUserIdAndCollectionIdAndStatusIn(userId, collectionId, Arrays
                             .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
                 }
-                if (count >= userMax.addAndGet(collection.getMaxCount()) ) {
-                    throw new BusinessException("限购" + userMax.get() + "件");
+                if (userMax.get() > 0) {
+                    if (count >= userMax.get()) {
+                        throw new BusinessException("限购" + userMax.get() + "件");
+                    }
+                } else {
+                    if (count >= collection.getMaxCount()) {
+                        throw new BusinessException("限购" + collection.getMaxCount() + "件");
+                    }
                 }
+
             }
             User user = null;
             if (ObjectUtils.isNotEmpty(collection.getMinimumCharge()) && collection.getMinimumCharge()
@@ -370,7 +378,6 @@ public class OrderService {
 
         AtomicInteger userMax = new AtomicInteger();
         userPropertyRepo.findById(userId).ifPresent(userProperty -> userMax.set(userProperty.getMaxCount()));
-        int limit = userMax.addAndGet(collection.getMaxCount());
 
         if (collection.getMaxCount() > 0) {
             if (StringUtils.isNotBlank(collection.getCountId())) {
@@ -382,7 +389,7 @@ public class OrderService {
             }
         }
         Map<String, Object> map = new HashMap<>();
-        map.put("limit", limit);
+        map.put("limit", userMax.get() > 0 ? userMax.get() : collection.getMaxCount());
         map.put("count", count);
         return map;
     }

+ 22 - 4
src/test/java/com/izouma/nineth/repo/UserPropertyRepoTest.java

@@ -11,10 +11,7 @@ import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.File;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
@@ -105,6 +102,27 @@ public class UserPropertyRepoTest extends ApplicationTests {
         });
     }
 
+    @Test
+    public void setById() {
+        File file = new File("/Users/qiufangchao/Desktop/VIP.xlsx");
+        UploadDataListener<AirDropExcelDTO> listener = new UploadDataListener<>();
+        List<AirDropExcelDTO> dtos = EasyExcel.read(file, AirDropExcelDTO.class, listener)
+                .sheet()
+                .doReadSync();
+        Set<String> userIds = dtos.stream()
+                .map(AirDropExcelDTO::getPhone)
+                .collect(Collectors.toSet());
+        System.out.println(userIds);
+//        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);
+//        });
+    }
+
     @Test
     public void statistic() {
         Map<Long, Integer> map = new HashMap<>();