|
|
@@ -2,25 +2,28 @@ 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.domain.*;
|
|
|
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.io.FileUtils;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.junit.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.ForkJoinPool;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.StreamSupport;
|
|
|
|
|
|
|
|
|
public class UserPropertyRepoTest extends ApplicationTests {
|
|
|
@@ -309,7 +312,7 @@ public class UserPropertyRepoTest extends ApplicationTests {
|
|
|
@Test
|
|
|
public void test3() {
|
|
|
List<String> result = new ArrayList<>();
|
|
|
- File file = new File("/Users/qiufangchao/Desktop/error.xlsx");
|
|
|
+ File file = new File("/Users/drew/Desktop/error.xlsx");
|
|
|
UploadDataListener<TestDTO> listener = new UploadDataListener<>();
|
|
|
List<TestDTO> dtos = EasyExcel.read(file, TestDTO.class, listener)
|
|
|
.sheet()
|
|
|
@@ -334,4 +337,75 @@ public class UserPropertyRepoTest extends ApplicationTests {
|
|
|
result.forEach(System.out::println);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void fixMaxCount() throws ExecutionException, InterruptedException {
|
|
|
+ userPropertyRepo.deleteAll();
|
|
|
+ List<Long> vipAndNew = userRepo.vipAndNew();
|
|
|
+ List<Long> invitor = userRepo.invitor();
|
|
|
+ List<Long> buyUser = userRepo.buyUser();
|
|
|
+ Set<Long> all = new HashSet<>();
|
|
|
+ all.addAll(vipAndNew);
|
|
|
+ all.addAll(invitor);
|
|
|
+ all.addAll(buyUser);
|
|
|
+ new ForkJoinPool(1000).submit(() -> {
|
|
|
+ StringBuilder err = new StringBuilder("userId,maxCount,orderNum,returnNum\n");
|
|
|
+ StringBuilder csv = new StringBuilder("userId,maxCount,orderNum\n");
|
|
|
+ all.stream().parallel()
|
|
|
+ .forEach(userId -> {
|
|
|
+ int num = userRepo.countAllByCollectionIdAndCollectionInvitorAndSettleAccountIdIsNotNull(8573130L, userId) / 3;
|
|
|
+ if (vipAndNew.contains(userId)) {
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ if (num > 0) {
|
|
|
+ userPropertyRepo.save(new UserProperty(userId, num));
|
|
|
+ }
|
|
|
+ int orderNum = orderRepo.countByUserIdAndCollectionIdAndStatusIn(userId, 8573130L, Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH));
|
|
|
+ if (orderNum > num) {
|
|
|
+ err.append(userId + "," + num + "," + orderNum + "," + (orderNum - num) + "\n");
|
|
|
+ }
|
|
|
+ csv.append(userId + "," + num + "," + orderNum + "\n");
|
|
|
+ });
|
|
|
+ try {
|
|
|
+ FileUtils.write(new File("/Users/drew/Desktop/err.csv"), err.toString());
|
|
|
+ FileUtils.write(new File("/Users/drew/Desktop/all.csv"), csv.toString());
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }).get();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void queryError() throws ExecutionException, InterruptedException {
|
|
|
+ StringBuilder result = new StringBuilder("userId,count,realCount,orderNum\n");
|
|
|
+ List<UserProperty> list = new ArrayList<>();
|
|
|
+ userPropertyRepo.findAll().forEach(list::add);
|
|
|
+ new ForkJoinPool(1000).submit(() -> {
|
|
|
+ list.stream()
|
|
|
+ .filter(userProperty -> userProperty != null && userProperty.getMaxCount() > 0)
|
|
|
+ .parallel()
|
|
|
+ .forEach(userProperty -> {
|
|
|
+ try {
|
|
|
+ User user = userRepo.findById(userProperty.getId()).get();
|
|
|
+ int realInviteNum = userRepo.countAllByCollectionIdAndCollectionInvitorAndSettleAccountIdIsNotNull(8573130L, userProperty.getId());
|
|
|
+ int count = userProperty.getMaxCount();
|
|
|
+ int realCount = realInviteNum / 3;
|
|
|
+ int orderNum = orderRepo.countByUserIdAndCollectionIdAndStatusIn(userProperty.getId(), 8573130L, Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH));
|
|
|
+ if (user.getVipPurchase() > 0 || user.getCreatedAt()
|
|
|
+ .isAfter(LocalDateTime.of(2022, 7, 5, 0, 0, 0))) {
|
|
|
+ realCount++;
|
|
|
+ }
|
|
|
+ if (count > realCount) {
|
|
|
+ result.append(userProperty.getId() + "," + count + "," + realCount + "," + orderNum + "\n");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }).get();
|
|
|
+ try {
|
|
|
+ FileUtils.write(new File("/Users/drew/Desktop/err.csv"), result.toString());
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|