|
|
@@ -6,10 +6,12 @@ import com.huifu.adapay.model.Payment;
|
|
|
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.UserBankCard;
|
|
|
import com.izouma.nineth.enums.AssetStatus;
|
|
|
import com.izouma.nineth.enums.AuthStatus;
|
|
|
import com.izouma.nineth.enums.OrderStatus;
|
|
|
+import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.*;
|
|
|
import com.izouma.nineth.utils.FileUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -20,32 +22,32 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.Future;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
public class OrderServiceTest extends ApplicationTests {
|
|
|
@Autowired
|
|
|
- private OrderService orderService;
|
|
|
+ private OrderService orderService;
|
|
|
@Autowired
|
|
|
- private OrderRepo orderRepo;
|
|
|
+ private OrderRepo orderRepo;
|
|
|
@Autowired
|
|
|
- private AssetRepo assetRepo;
|
|
|
+ private AssetRepo assetRepo;
|
|
|
@Autowired
|
|
|
- private TokenHistoryRepo tokenHistoryRepo;
|
|
|
+ private TokenHistoryRepo tokenHistoryRepo;
|
|
|
@Autowired
|
|
|
- private AssetService assetService;
|
|
|
+ private AssetService assetService;
|
|
|
@Autowired
|
|
|
- private CollectionRepo collectionRepo;
|
|
|
+ private CollectionRepo collectionRepo;
|
|
|
@Autowired
|
|
|
- private UserRepo userRepo;
|
|
|
+ private UserRepo userRepo;
|
|
|
@Autowired
|
|
|
- private IdentityAuthRepo identityAuthRepo;
|
|
|
+ private IdentityAuthRepo identityAuthRepo;
|
|
|
@Autowired
|
|
|
- private UserBankCardRepo userBankCardRepo;
|
|
|
+ private UserBankCardRepo userBankCardRepo;
|
|
|
+ @Autowired
|
|
|
+ private CollectionService collectionService;
|
|
|
|
|
|
@Test
|
|
|
public void create() throws EncoderException, WxPayException {
|
|
|
@@ -174,4 +176,77 @@ public class OrderServiceTest extends ApplicationTests {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void mint() {
|
|
|
+ for (Order order : orderRepo.findByStatus(OrderStatus.PROCESSING)) {
|
|
|
+ if (order.getPayTime().isBefore(LocalDateTime.of(2021, 12, 18, 15, 8))) {
|
|
|
+ try {
|
|
|
+ Collection collection = collectionRepo.findById(order.getCollectionId())
|
|
|
+ .orElseThrow(new BusinessException("无记录"));
|
|
|
+ User user = userRepo.findById(order.getUserId()).orElseThrow(new BusinessException("无记录"));
|
|
|
+ Future<Asset> f = assetService.createAsset(collection, user, order.getId(), order.getPrice(), "出售",
|
|
|
+ collectionService.getNextNumber(order.getCollectionId()));
|
|
|
+ while (true) {
|
|
|
+ if (f.isDone()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Thread.sleep(300);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void removeDuplicate() {
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ orderRepo.findByCollectionId(8012L).stream()
|
|
|
+ .filter(o -> o.getStatus() == OrderStatus.FINISH || o.getStatus() == OrderStatus.PROCESSING)
|
|
|
+ .parallel().forEach(order -> {
|
|
|
+ List<Asset> assets = assetRepo.findByOrderId(order.getId());
|
|
|
+ if (assets.size() > 1) {
|
|
|
+ assets.sort(Comparator.comparing(BaseEntity::getCreatedAt));
|
|
|
+ for (int i = 1; i < assets.size(); i++) {
|
|
|
+ assetRepo.delete(assets.get(i));
|
|
|
+ tokenHistoryRepo.deleteByTokenId(assets.get(i).getTokenId());
|
|
|
+ if (assets.get(i).getPublicCollectionId() != null) {
|
|
|
+ collectionRepo.findById(assets.get(i).getPublicCollectionId()).ifPresent(c -> {
|
|
|
+ collectionRepo.delete(c);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ids.add(order.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ System.out.println(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void setNumber1() {
|
|
|
+ final int[] number = {1};
|
|
|
+ orderRepo.findByCollectionId(8012L).stream()
|
|
|
+ .filter(o -> o.getStatus() == OrderStatus.FINISH || o.getStatus() == OrderStatus.PROCESSING)
|
|
|
+ .sorted(Comparator.comparing(Order::getCreatedAt))
|
|
|
+ .forEach(order -> {
|
|
|
+ Asset asset = assetRepo.findByOrderId(order.getId()).get(0);
|
|
|
+ asset.setNumber(number[0]);
|
|
|
+ assetRepo.save(asset);
|
|
|
+ if (asset.getPublicCollectionId() != null) {
|
|
|
+ collectionRepo.findById(asset.getPublicCollectionId()).ifPresent(c -> {
|
|
|
+ c.setNumber(asset.getNumber());
|
|
|
+ collectionRepo.save(c);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ number[0]++;
|
|
|
+ });
|
|
|
+
|
|
|
+ assetRepo.findByCollectionId(8012L).stream().parallel().forEach(asset -> {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
}
|