Przeglądaj źródła

跑错误数据

licailing 3 lat temu
rodzic
commit
eb1677ba76

+ 14 - 0
src/main/java/com/izouma/nineth/dto/TestDTO.java

@@ -0,0 +1,14 @@
+package com.izouma.nineth.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class TestDTO {
+    private Long id;
+    private int  max;
+    private int  real;
+}

+ 2 - 0
src/main/java/com/izouma/nineth/repo/OrderRepo.java

@@ -103,4 +103,6 @@ public interface OrderRepo extends JpaRepository<Order, Long>, JpaSpecificationE
             "  and o.source = com.izouma.nineth.enums.CollectionSource.TRANSFER " +
             "  and o.status = com.izouma.nineth.enums.OrderStatus.FINISH")
     Page<Order> byTag(Long tagId, Long userId, Pageable pageable);
+
+    int countAllByUserIdAndCollectionIdAndStatusIn(Long userId, Long collectionId, Collection<OrderStatus> status);
 }

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

@@ -3,16 +3,21 @@ package com.izouma.nineth.repo;
 import com.alibaba.excel.EasyExcel;
 import com.izouma.nineth.ApplicationTests;
 import com.izouma.nineth.domain.Asset;
+import com.izouma.nineth.domain.Order;
 import com.izouma.nineth.domain.User;
 import com.izouma.nineth.domain.UserProperty;
 import com.izouma.nineth.dto.AirDropExcelDTO;
+import com.izouma.nineth.dto.TestDTO;
 import com.izouma.nineth.enums.AssetStatus;
+import com.izouma.nineth.enums.OrderStatus;
+import com.izouma.nineth.service.CacheService;
 import com.izouma.nineth.utils.excel.UploadDataListener;
 import org.apache.commons.lang3.ObjectUtils;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.File;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
@@ -26,6 +31,10 @@ public class UserPropertyRepoTest extends ApplicationTests {
     private AssetRepo        assetRepo;
     @Autowired
     private UserRepo         userRepo;
+    @Autowired
+    private CacheService     cacheService;
+    @Autowired
+    private OrderRepo        orderRepo;
 
     @Test
     public void save() {
@@ -243,14 +252,86 @@ public class UserPropertyRepoTest extends ApplicationTests {
     }
 
     @Test
-    public void test(){
+    public void test() {
         Iterable<UserProperty> all = userPropertyRepo.findAll();
+        List<String> result = new ArrayList<>();
         all.forEach(p -> {
-            if (p.getMaxCount() > 1) {
-                p.setMaxCount(p.getMaxCount() - 1);
-                userPropertyRepo.save(p);
+            if (p != null && p.getId() != null) {
+                if (p.getMaxCount() > 0) {
+                    int num = userRepo.countAllByCollectionIdAndCollectionInvitorAndSettleAccountIdIsNotNull(8573130L, p.getId());
+                    User user = userRepo.findById(p.getId()).orElse(null);
+                    if (user.getVipPurchase() > 0 || user.getCreatedAt().isAfter(LocalDateTime.of(2022, 7, 5, 0, 0))) {
+                        if ((num / 3) + 1 != p.getMaxCount()) {
+                            result.add(p.getId() + "," + p.getMaxCount() + "," + num);
+                        }
+                    } else {
+                        if (num / 3 != p.getMaxCount()) {
+                            result.add(p.getId() + "," + p.getMaxCount() + "," + num);
+                        }
+                    }
+//                    if (num == 0) {
+//                        userPropertyRepo.delete(p);
+//                        user.setVipPoint(0);
+//                        userRepo.save(user);
+//                        cacheService.clearUser(user.getId());
+//                        cacheService.clearUser(user.getId());
+//                    }
+
+//                    int size = num / 3;
+//                    if (user.getVipPurchase() > 0 || user.getCreatedAt().isAfter(LocalDateTime.of(2022, 7, 5, 0, 0))) {
+//                        if (size + 1 != p.getMaxCount()) {
+//                            if (size + 1 >= 10 && p.getMaxCount() != 10) {
+//                                p.setMaxCount(10);
+//                                userPropertyRepo.save(p);
+//                            } else {
+//                                p.setMaxCount(size + 1);
+//                                userPropertyRepo.save(p);
+//                            }
+//                        }
+//
+//                    } else {
+//                        if (size != p.getMaxCount()) {
+//                            if (size >= 10 && p.getMaxCount() != 10) {
+//                                p.setMaxCount(10);
+//                                userPropertyRepo.save(p);
+//                            } else {
+//                                p.setMaxCount(size);
+//                                userPropertyRepo.save(p);
+//                            }
+//                        }
+//                    }
+                }
             }
         });
+        result.forEach(System.out::println);
+    }
+
+    @Test
+    public void test3() {
+        List<String> result = new ArrayList<>();
+        File file = new File("/Users/qiufangchao/Desktop/error.xlsx");
+        UploadDataListener<TestDTO> listener = new UploadDataListener<>();
+        List<TestDTO> dtos = EasyExcel.read(file, TestDTO.class, listener)
+                .sheet()
+                .doReadSync();
+        dtos.forEach(dto -> {
+            int size = dto.getReal() / 3;
+
+            int orders = orderRepo.countAllByUserIdAndCollectionIdAndStatusIn(dto.getId(), 8573130L, Arrays.asList(OrderStatus.FINISH, OrderStatus.PROCESSING));
+            User user = userRepo.findById(dto.getId()).orElse(null);
+            if (user.getVipPurchase() > 0 || user.getCreatedAt().isAfter(LocalDateTime.of(2022, 7, 5, 0, 0))) {
+                if (size + 1 < orders) {
+                    int num = size + 1;
+                    result.add(dto.getId() + "," + num + "," + orders);
+                }
+            } else {
+                if (size < orders) {
+                    result.add(dto.getId() + "," + size + "," + orders);
+                }
+            }
+
+        });
+        result.forEach(System.out::println);
     }
 
 }