xiongzhu hace 3 años
padre
commit
a504d607ea

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

@@ -107,4 +107,10 @@ public interface OrderRepo extends JpaRepository<Order, Long>, JpaSpecificationE
     int countAllByUserIdAndCollectionIdAndStatusIn(Long userId, Long collectionId, Collection<OrderStatus> status);
 
     List<Order> findByUserIdAndCollectionIdAndStatus(Long userId, Long collectionId, OrderStatus status);
+
+    @Query(value = "select * from order_info o" +
+            " join asset on o.id = asset.order_id" +
+            " where o.collection_id = 8573130 and o.status = 'FINISH' and asset.hold_days != 365 and o.user_id = ?1", nativeQuery = true)
+    List<Order> asdfasdf(Long userId);
+
 }

+ 4 - 1
src/test/java/com/izouma/nineth/CommonTest.java

@@ -737,7 +737,10 @@ public class CommonTest {
     }
 
     @Test
-    public void afasd(){
+    public void afasd() {
         System.out.println(new HashSet<>(Arrays.asList(Long.parseLong("1"))).contains(Long.parseLong("1")));
+
+        List<String> lines = Arrays.asList("1", "2", "3");
+        System.out.println(lines.subList(1, lines.size()));
     }
 }

+ 6 - 3
src/test/java/com/izouma/nineth/repo/UserPropertyRepoTest.java

@@ -356,14 +356,17 @@ public class UserPropertyRepoTest extends ApplicationTests {
                         if (vipAndNew.contains(userId)) {
                             num++;
                         }
+                        num = Math.min(num, 10);
                         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");
+                        synchronized (UserPropertyRepoTest.class){
+                            if (orderNum > num) {
+                                err.append(userId + "," + num + "," + orderNum + "," + (orderNum - num) + "\n");
+                            }
+                            csv.append(userId + "," + num + "," + orderNum + "\n");
                         }
-                        csv.append(userId + "," + num + "," + orderNum + "\n");
                     });
             try {
                 FileUtils.write(new File("/Users/drew/Desktop/err.csv"), err.toString());

+ 36 - 7
src/test/java/com/izouma/nineth/service/AssetServiceTest.java

@@ -31,6 +31,7 @@ import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -266,26 +267,54 @@ class AssetServiceTest extends ApplicationTests {
     }
 
     @Test
-    public void destroy() throws ExecutionException, InterruptedException {
+    public void destroy() throws ExecutionException, InterruptedException, IOException {
+        List<String> lines = FileUtils.readLines(new File("/Users/drew/Desktop/refundOrders0.csv"), StandardCharsets.UTF_8);
+        lines = lines.subList(1, lines.size());
+        List<Long> refunded = lines.stream().map(s -> {
+            return Long.parseLong(s.split(",")[3]);
+        }).collect(Collectors.toList());
+
         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<>();
+                List<Order> refundOrders = Collections.synchronizedList(new ArrayList<>());
+                List<Asset> refundAssets = Collections.synchronizedList(new ArrayList<>());
+                AtomicInteger total = new AtomicInteger(0);
                 Arrays.stream(str.split("\n"))
                         .parallel().forEach(s -> {
                             String[] arr = s.split(",");
                             int returnNum = Integer.parseInt(arr[3]);
+                            total.addAndGet(returnNum);
                             Long userId = Long.parseLong(arr[0]);
                             List<Order> orders = orderRepo.findByUserIdAndCollectionIdAndStatus(userId, 8573130L, OrderStatus.FINISH);
+                            //int rNum = (int) orders.stream().filter(o -> refunded.contains(o.getId())).count();
+                           // returnNum -= rNum;
+                           // orders = orders.stream().filter(o -> !refunded.contains(o.getId())).collect(Collectors.toList());
                             orders.sort(Comparator.comparing(Order::getCreatedAt).reversed());
                             List<Order> refund = orders.subList(0, returnNum);
-                            orderIds.addAll(refund.stream().map(Order::getId).collect(Collectors.toList()));
-
+                            refundOrders.addAll(refund);
+                            for (Order order : refund) {
+                                Asset asset = assetRepo.findByOrderId(order.getId()).get(0);
+//                                asset.setHoldDays(365);
+//                                assetRepo.save(asset);
+                                refundAssets.add(asset);
+//                                asset.setUserId(1435297L);
+//                                asset.setOwnerId(1435297L);
+//                                assetRepo.save(asset);
+//                                tokenHistoryRepo.deleteByTokenId(asset.getTokenId());
+                            }
                         });
-                FileUtils.write(new File("/Users/drew/Desktop/orderIds.txt"), orderIds.stream().map(Object::toString)
-                        .collect(Collectors.joining("\n")), StandardCharsets.UTF_8);
+                FileUtils.write(new File("/Users/drew/Desktop/refundOrders1.csv"),
+                        "用户ID,藏品名称,编号,订单ID\n" +
+                                refundAssets.stream()
+                                        .map(a -> a.getUserId() + "," +
+                                                a.getName() + "," +
+                                                a.getNumber() + "," +
+                                                a.getOrderId())
+                                        .collect(Collectors.joining("\n"))
+                        , "GBK");
+                System.out.println(total.get());
             } catch (Exception e) {
             }
         }).get();

+ 37 - 27
src/test/java/com/izouma/nineth/service/OrderPayServiceTest.java

@@ -8,44 +8,54 @@ import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ForkJoinPool;
 
 import static org.junit.jupiter.api.Assertions.*;
 
-class OrderPayServiceTest extends ApplicationTests {
+public 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";
+    public void queryAndRefund() throws IOException, ExecutionException, InterruptedException {
+        String[] orders = FileUtils.readFileToString(new File("/Users/drew/Desktop/ids"), StandardCharsets.UTF_8)
+                .replaceAll("\n", "").trim().split(",");
+
+        new ForkJoinPool(3).submit(() -> {
+            StringBuilder success = new StringBuilder();
+            StringBuilder fail = new StringBuilder();
+            StringBuilder notExist = new StringBuilder();
+            Arrays.stream(orders).parallel().forEach(order -> {
+                order = order.trim();
+                try {
+                    PayQuery query = orderPayService.query(order);
+                    if (query.isExist()) {
+                        try {
+                            orderPayService.refund(order, query.getTransactionId(), query.getAmount(), query.getChannel());
+                            success.append(order).append("\n");
+                        } catch (Exception e) {
+                            fail.append(order).append("\n");
+                        }
+                    } else {
+                        notExist.append(order).append("\n");
                     }
-                } else {
-                    notExist += order + "\n";
+                } catch (Exception e) {
+                    fail.append(order).append("\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);
             }
-        }
-        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);
-        }
+        }).get();
+
     }
 }