|
|
@@ -1,19 +1,42 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
+import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
+import com.huifu.adapay.model.Payment;
|
|
|
import com.izouma.nineth.ApplicationTests;
|
|
|
+import com.izouma.nineth.TokenHistory;
|
|
|
+import com.izouma.nineth.domain.Asset;
|
|
|
+import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.domain.Order;
|
|
|
+import com.izouma.nineth.enums.AssetStatus;
|
|
|
import com.izouma.nineth.enums.OrderStatus;
|
|
|
-import com.izouma.nineth.repo.OrderRepo;
|
|
|
+import com.izouma.nineth.repo.*;
|
|
|
import org.apache.commons.codec.EncoderException;
|
|
|
+import org.apache.commons.collections.MapUtils;
|
|
|
import org.junit.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
public class OrderServiceTest extends ApplicationTests {
|
|
|
@Autowired
|
|
|
- private OrderService orderService;
|
|
|
+ private OrderService orderService;
|
|
|
+ @Autowired
|
|
|
+ private OrderRepo orderRepo;
|
|
|
+ @Autowired
|
|
|
+ private AssetRepo assetRepo;
|
|
|
+ @Autowired
|
|
|
+ private TokenHistoryRepo tokenHistoryRepo;
|
|
|
@Autowired
|
|
|
- private OrderRepo orderRepo;
|
|
|
+ private AssetService assetService;
|
|
|
+ @Autowired
|
|
|
+ private CollectionRepo collectionRepo;
|
|
|
+ @Autowired
|
|
|
+ private UserRepo userRepo;
|
|
|
|
|
|
@Test
|
|
|
public void create() throws EncoderException, WxPayException {
|
|
|
@@ -45,4 +68,60 @@ public class OrderServiceTest extends ApplicationTests {
|
|
|
public void cancel() {
|
|
|
orderService.cancel(9892L);
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void fixNotPaid() throws BaseAdaPayException {
|
|
|
+ List<Order> errOrders = new ArrayList<>();
|
|
|
+ orderRepo.findByStatus(OrderStatus.FINISH).stream().parallel().forEach(order -> {
|
|
|
+ if (order.getCreatedAt().isAfter(LocalDateTime.of(2021, 11, 30, 1, 1))) {
|
|
|
+ try {
|
|
|
+ Map<String, Object> res = Payment.query(order.getTransactionId());
|
|
|
+ String status = MapUtils.getString(res, "status");
|
|
|
+ String errMsg = MapUtils.getString(res, "error_msg");
|
|
|
+ if (!"succeeded".equals(status) && !"对应支付记录不存在".equals(errMsg)) {
|
|
|
+ System.out.println(order.getId());
|
|
|
+ errOrders.add(order);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ System.out.println(errOrders.stream().map(o -> o.getId().toString()).collect(Collectors.joining(",")));
|
|
|
+
|
|
|
+
|
|
|
+ for (Order errOrder : errOrders) {
|
|
|
+ Collection collection = collectionRepo.findById(errOrder.getCollectionId()).orElse(null);
|
|
|
+ if (collection == null) continue;
|
|
|
+ List<Asset> assets = assetRepo.findByOrderId(errOrder.getId());
|
|
|
+ for (Asset asset : assets) {
|
|
|
+ if (asset.getStatus() == AssetStatus.NORMAL) {
|
|
|
+ if (asset.isPublicShow()) {
|
|
|
+ assetService.cancelPublic(asset);
|
|
|
+ }
|
|
|
+ tokenHistoryRepo.deleteByTokenId(asset.getTokenId());
|
|
|
+ assetRepo.delete(asset);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ orderRepo.delete(errOrder);
|
|
|
+ collection.setStock(collection.getStock() + 1);
|
|
|
+ collection.setSale(collection.getSale() - 1);
|
|
|
+ collectionRepo.save(collection);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void fixTokenHistory() {
|
|
|
+ for (TokenHistory tokenHistory : tokenHistoryRepo.findError()) {
|
|
|
+ List<Asset> assets = assetRepo.findByTokenIdOrderByCreatedAt(tokenHistory.getTokenId());
|
|
|
+ if (assets.size() == 2) {
|
|
|
+ userRepo.findById(assets.get(0).getUserId()).ifPresent(fromUser -> {
|
|
|
+ tokenHistory.setFromUserId(assets.get(0).getUserId());
|
|
|
+ tokenHistory.setFromUser(fromUser.getNickname());
|
|
|
+ tokenHistory.setFromAvatar(fromUser.getAvatar());
|
|
|
+ tokenHistoryRepo.save(tokenHistory);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|