|
|
@@ -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();
|