xiongzhu 3 năm trước cách đây
mục cha
commit
7e483eee55

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

@@ -105,4 +105,6 @@ public interface OrderRepo extends JpaRepository<Order, Long>, JpaSpecificationE
     Page<Order> byTag(Long tagId, Long userId, Pageable pageable);
 
     int countAllByUserIdAndCollectionIdAndStatusIn(Long userId, Long collectionId, Collection<OrderStatus> status);
+
+    List<Order> findByUserIdAndCollectionIdAndStatus(Long userId, Long collectionId, OrderStatus status);
 }

+ 19 - 0
src/main/java/com/izouma/nineth/repo/UserRepo.java

@@ -258,4 +258,23 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
     @Modifying
     @Query("update User set destroyPoint = destroyPoint + ?2 where id = ?1")
     void addDestroyPoint(Long id, int num);
+
+    @Query(value = "select id " +
+            "from user " +
+            "where (collection_id = 8573130 and settle_account_id is not null) " +
+            "   or (created_at > '2022-07-05 00:00:00' and settle_account_id is not null) " +
+            "   or vip_purchase > 0", nativeQuery = true)
+    List<Long> vipAndNew();
+
+    @Query(value = "select collection_invitor " +
+            "from user " +
+            "where collection_id = 8573130 " +
+            "group by collection_invitor", nativeQuery = true)
+    List<Long> invitor();
+
+    @Query(value = "select user_id " +
+            "from order_info " +
+            "where collection_id = 8573130 " +
+            "  and status != 'CANCELLED' group by user_id", nativeQuery = true)
+    List<Long> buyUser();
 }

+ 5 - 5
src/main/resources/application.yaml

@@ -17,7 +17,7 @@ spring:
     active: dev
   redis:
     host: 120.78.171.194
-    database: 0
+    database: 1
     password: jV%93RtjUx82Tp
     lettuce:
       pool:
@@ -25,10 +25,10 @@ spring:
         max_idle: 50
         min_idle: 0
   datasource:
-#    url: jdbc:mysql://rm-wz9sc79f5255780opqo.mysql.rds.aliyuncs.com/raex?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
-#    username: raex_server
-    url: jdbc:mysql://rm-wz9q65wzuf8c56647ro.mysql.rds.aliyuncs.com/raex_test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
-    username: raex_test
+    url: jdbc:mysql://rm-wz9sc79f5255780opqo.mysql.rds.aliyuncs.com/raex?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
+    username: raex_server
+#    url: jdbc:mysql://rm-wz9q65wzuf8c56647ro.mysql.rds.aliyuncs.com/raex_test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
+#    username: raex_test
     password: tetQsjw!u4!c5$URduo7BH
     hikari:
       minimum-idle: 20

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

@@ -735,4 +735,9 @@ public class CommonTest {
     public void testOneKey() {
         UmengUtils.getMobile("62b8106188ccdf4b7eaba3e8", "eyJjIjoibEVjUGh6WXhwdE5FTHVjQ1p0XC9TREZuMGpLSzlZenZhblBaeUxPUWFrRlJUaFwvaWdrUFA2NU1GZGFDd3F3cjdZVGlPWXhEOVRnWGx3XG5PbGI5MytnN29aaGFpV24rbmd2Q1MxUE1vem5cLzVIQ1BveEk4WG94Zkd3Nkozc3pjMk95NUdFZjBsak9Qd09nMk1iVDBWRjl3Y05zMFxuc2NScGVTd0VoSXh1elpwZ2c5dk5xQlliN2toNWF0cmRtRHQzanZNTHBjUm5OeCtwMXdKS1wvN1VlYTN4b3FJajhSakRuVnFZVmJrcm1cbmtKSDhkNUxrbEEzSzhXU2pVeEF5bkZlSVRWbGNpRlJHTUhvZTBYM1ppZ0pDa0pQWk80VVFGVktSaWlRcFpQbGVGTEhNOHRpTnlTQ0Ncbm1ESmQ1OEM3eWdmWktcLzJcL1ZUc1ZkdFpYUktcL0FqVjNGbk84QnhTZWZQZjVmZEI0YThJQzE2SVFINW91Y2U3NERRbG96SGVIVjhSMldcbmQzaHFRZVh4UFkwd09mdW51elFGSHRscUxnSXlWUDA2bFRaZ0VYdTZpbjJDWDlSUndpa3RxUU81NkRjYzdCeWEzdXQyN0ZcL0VzUmRjXG5Vc3J3ZjVkNE41K0N6cFlBSlpWZmh4ZUlYMUZUVmJPZmFEcWQ0RUpPSTFnclwvTkpXUW9uSG14cUZvXC81WEM2dGwzSG5lQWZwM3dGejJcbk1qQ3d4aWF1ZTJ6OWVpNXZpb1F6Z0lhTWREckJ0eFFPcDU3RW5sZm50NGF1NG8yNGJSQTBSSzI2THZwRzVEakRiZWRTY2xZVEZSY2tcbjBITlUzUFdiQ1hrPVxuIiwiayI6IlQwd0hqc3JiSlV6XC9YRGNUSDVcL0Q5QkpcLzZaVzZmR1BGckdQcmRjdEZDR1Z0NGtcLzdTTzJ6TGU5dlVcL0JlUitcL0VYcDNTWFlLcWhLYXh2QW1vazZjY3FveGk3aE1xckcySHNwbUxLWEtkXC9CbUlHMHhDUjVPWm42SWJvK1BhU2djWlk0MUJic01zRm9RVmRmYUIrZitTVkdJQU50K2lNdm5SRkJpUXNja1N0SVZFd0hvZFgwVkZwd2xVN1UwRTBER01qclJLclI2eGRsMFlSZURIbTVuN3hqaVppOVg1ZTQzZ1UxYk9GOVwvelJwa2ZVd05sN3g2a0tpS25XQ25TU2FuQjhDbHJiNTZ0Qll2czdcL3pKdDJsYXh6UGVMb0Jielp1N0lLTHlUcnc4ZVwvVlNmaUlPYmI5dVNqeXFLRU12dXNQRHFmNmNlQUpRUzlIcW1nQk0wbWZiOVE9PSIsIm8iOiJBbmRyb2lkIn0=");
     }
+
+    @Test
+    public void afasd(){
+        System.out.println(new HashSet<>(Arrays.asList(Long.parseLong("1"))).contains(Long.parseLong("1")));
+    }
 }

+ 79 - 5
src/test/java/com/izouma/nineth/repo/UserPropertyRepoTest.java

@@ -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);
+        }
+    }
 }

+ 30 - 6
src/test/java/com/izouma/nineth/service/AssetServiceTest.java

@@ -5,9 +5,11 @@ import com.alibaba.excel.annotation.ExcelProperty;
 import com.izouma.nineth.ApplicationTests;
 import com.izouma.nineth.TokenHistory;
 import com.izouma.nineth.domain.*;
+import com.izouma.nineth.domain.Collection;
 import com.izouma.nineth.dto.NFT;
 import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.enums.AssetStatus;
+import com.izouma.nineth.enums.OrderStatus;
 import com.izouma.nineth.enums.TransferReason;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.*;
@@ -16,16 +18,17 @@ import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.io.File;
+import java.io.IOException;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ForkJoinPool;
 import java.util.stream.Collectors;
@@ -263,8 +266,29 @@ class AssetServiceTest extends ApplicationTests {
     }
 
     @Test
-    public void destroy() {
-        assetService.destroy(8025352L, 9972L);
+    public void destroy() throws ExecutionException, InterruptedException {
+        new ForkJoinPool(1000).submit(() -> {
+            try {
+                String str = FileUtils.readFileToString(new File("/Users/drew/Desktop/err.csv"), StandardCharsets.UTF_8);
+                str = str.substring(str.indexOf("\n")).trim();
+                List<Long> orderIds = new ArrayList<>();
+                List<Long> err = new ArrayList<>();
+                Arrays.stream(str.split("\n"))
+                        .parallel().forEach(s -> {
+                            String[] arr = s.split(",");
+                            int returnNum = Integer.parseInt(arr[3]);
+                            Long userId = Long.parseLong(arr[0]);
+                            List<Order> orders = orderRepo.findByUserIdAndCollectionIdAndStatus(userId, 8573130L, OrderStatus.FINISH);
+                            orders.sort(Comparator.comparing(Order::getCreatedAt).reversed());
+                            List<Order> refund = orders.subList(0, returnNum);
+                            orderIds.addAll(refund.stream().map(Order::getId).collect(Collectors.toList()));
+
+                        });
+                FileUtils.write(new File("/Users/drew/Desktop/orderIds.txt"), orderIds.stream().map(Object::toString)
+                        .collect(Collectors.joining("\n")), StandardCharsets.UTF_8);
+            } catch (Exception e) {
+            }
+        }).get();
     }
 
     @Test

+ 51 - 0
src/test/java/com/izouma/nineth/service/OrderPayServiceTest.java

@@ -0,0 +1,51 @@
+package com.izouma.nineth.service;
+
+import com.izouma.nineth.ApplicationTests;
+import com.izouma.nineth.dto.PayQuery;
+import org.apache.commons.io.FileUtils;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class OrderPayServiceTest extends ApplicationTests {
+    @Autowired
+    private OrderPayService orderPayService;
+
+    @Test
+    public void queryAndRefund() {
+        List<String> orders = new ArrayList<>();
+        String success = "";
+        String fail = "";
+        String notExist = "";
+        for (String order : orders) {
+            try {
+                PayQuery query = orderPayService.query("");
+                if (query.isExist()) {
+                    try {
+                        orderPayService.refund(order, query.getTransactionId(), query.getAmount(), query.getChannel());
+                        success += order + "\n";
+                    } catch (Exception e) {
+                        fail += order + "\n";
+                    }
+                } else {
+                    notExist += order + "\n";
+                }
+            } catch (Exception e) {
+                fail += order + "\n";
+            }
+        }
+        try {
+            FileUtils.write(new File("/Users/drew/Desktop/success.txt"), success);
+            FileUtils.write(new File("/Users/drew/Desktop/fail.txt"), fail);
+            FileUtils.write(new File("/Users/drew/Desktop/notExist.txt"), notExist);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}