|
|
@@ -1,6 +1,5 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
-import cn.hutool.core.convert.Convert;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.izouma.nineth.TokenHistory;
|
|
|
import com.izouma.nineth.config.Constants;
|
|
|
@@ -28,6 +27,7 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -39,6 +39,7 @@ import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.ForkJoinPool;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -61,6 +62,7 @@ public class AssetService {
|
|
|
private MintActivityRepo mintActivityRepo;
|
|
|
private DestroyRecordRepo destroyRecordRepo;
|
|
|
private AirDropService airDropService;
|
|
|
+ private HCChainService hcChainService;
|
|
|
|
|
|
public Page<Asset> all(PageQuery pageQuery) {
|
|
|
Page<Asset> all = assetRepo
|
|
|
@@ -816,4 +818,28 @@ public class AssetService {
|
|
|
}
|
|
|
return royalties;
|
|
|
}
|
|
|
+
|
|
|
+ @Async
|
|
|
+ public void hcChain() throws ExecutionException, InterruptedException {
|
|
|
+ new ForkJoinPool(1000).submit(() -> {
|
|
|
+ AtomicInteger num = new AtomicInteger();
|
|
|
+ assetRepo.findByStatus(AssetStatus.NORMAL).parallelStream()
|
|
|
+ .forEach(asset -> {
|
|
|
+ if (asset.getHcTxHash() == null) {
|
|
|
+ User user = userRepo.findById(asset.getUserId()).orElse(null);
|
|
|
+ if (user != null) {
|
|
|
+ if (user.getHcChainAddress() == null) {
|
|
|
+ user.setHcChainAddress(hcChainService.createAccount(asset.getUserId()));
|
|
|
+ }
|
|
|
+ NFT nft = hcChainService.mint(user.getHcChainAddress(), asset.getTokenId());
|
|
|
+ asset.setHcTokenId(nft.getTokenId());
|
|
|
+ asset.setHcTxHash(nft.getTxHash());
|
|
|
+ asset.setGasUsed(nft.getGasUsed());
|
|
|
+ assetRepo.save(asset);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("hcChain:" + num.getAndIncrement());
|
|
|
+ });
|
|
|
+ }).get();
|
|
|
+ }
|
|
|
}
|