|
@@ -21,6 +21,7 @@ import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.enums.*;
|
|
import com.izouma.nineth.enums.*;
|
|
|
import com.izouma.nineth.event.CreateAssetEvent;
|
|
import com.izouma.nineth.event.CreateAssetEvent;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
|
|
+import com.izouma.nineth.lock.RedisLockable;
|
|
|
import com.izouma.nineth.repo.*;
|
|
import com.izouma.nineth.repo.*;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import com.izouma.nineth.utils.SecurityUtils;
|
|
import com.izouma.nineth.utils.SecurityUtils;
|
|
@@ -73,76 +74,40 @@ public class AssetService {
|
|
|
return assetRepo.findAll(JpaUtils.toSpecification(pageQuery, Asset.class), JpaUtils.toPageRequest(pageQuery));
|
|
return assetRepo.findAll(JpaUtils.toSpecification(pageQuery, Asset.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Asset createAsset(Order order) {
|
|
|
|
|
- User user = userRepo.findById(order.getUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
|
|
- Collection collection = collectionRepo.findById(order.getCollectionId()).orElseThrow(new BusinessException("藏品不存在"));
|
|
|
|
|
- Asset asset = Asset.builder()
|
|
|
|
|
- .userId(user.getId())
|
|
|
|
|
- .orderId(order.getId())
|
|
|
|
|
- .collectionId(order.getCollectionId())
|
|
|
|
|
- .minter(order.getMinter())
|
|
|
|
|
- .minterId(order.getMinterId())
|
|
|
|
|
- .minterAvatar(order.getMinterAvatar())
|
|
|
|
|
- .name(order.getName())
|
|
|
|
|
- .detail(order.getDetail())
|
|
|
|
|
- .pic(order.getPic())
|
|
|
|
|
- .properties(order.getProperties())
|
|
|
|
|
- .privileges(collection.getPrivileges())
|
|
|
|
|
- .category(order.getCategory())
|
|
|
|
|
- .canResale(order.isCanResale())
|
|
|
|
|
- .royalties(order.getRoyalties())
|
|
|
|
|
- .serviceCharge(order.getServiceCharge())
|
|
|
|
|
- .price(order.getPrice())
|
|
|
|
|
- .status(AssetStatus.NORMAL)
|
|
|
|
|
- .owner(user.getNickname())
|
|
|
|
|
- .ownerId(user.getId())
|
|
|
|
|
- .ownerAvatar(user.getAvatar())
|
|
|
|
|
- .build();
|
|
|
|
|
|
|
+ public Asset createAsset(Collection collection, User user, Long orderId, BigDecimal price, String type) {
|
|
|
|
|
+ Asset asset = Asset.create(collection, user);
|
|
|
|
|
+ asset.setOrderId(orderId);
|
|
|
|
|
+ asset.setPrice(price);
|
|
|
|
|
+ asset.setIpfsUrl(ipfsUpload(collection.getPic().get(0).getUrl()));
|
|
|
assetRepo.save(asset);
|
|
assetRepo.save(asset);
|
|
|
|
|
|
|
|
tokenHistoryRepo.save(TokenHistory.builder()
|
|
tokenHistoryRepo.save(TokenHistory.builder()
|
|
|
.tokenId(asset.getTokenId())
|
|
.tokenId(asset.getTokenId())
|
|
|
- .fromUser(order.getMinter())
|
|
|
|
|
- .fromUserId(order.getMinterId())
|
|
|
|
|
|
|
+ .fromUser(collection.getMinter())
|
|
|
|
|
+ .fromUserId(collection.getMinterId())
|
|
|
.toUser(user.getNickname())
|
|
.toUser(user.getNickname())
|
|
|
.toUserId(user.getId())
|
|
.toUserId(user.getId())
|
|
|
- .operation("出售")
|
|
|
|
|
- .price(order.getPrice())
|
|
|
|
|
|
|
+ .operation(type)
|
|
|
|
|
+ .price(price)
|
|
|
.build());
|
|
.build());
|
|
|
|
|
|
|
|
return asset;
|
|
return asset;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Asset createAsset(Order order, BlindBoxItem winItem) {
|
|
|
|
|
- User user = userRepo.findById(order.getUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
|
|
- Asset asset = Asset.builder()
|
|
|
|
|
- .userId(user.getId())
|
|
|
|
|
- .orderId(order.getId())
|
|
|
|
|
- .collectionId(order.getCollectionId())
|
|
|
|
|
- .minter(winItem.getMinter())
|
|
|
|
|
- .minterId(winItem.getMinterId())
|
|
|
|
|
- .minterAvatar(winItem.getMinterAvatar())
|
|
|
|
|
- .name(winItem.getName())
|
|
|
|
|
- .detail(winItem.getDetail())
|
|
|
|
|
- .pic(winItem.getPic())
|
|
|
|
|
- .properties(winItem.getProperties())
|
|
|
|
|
- .privileges(winItem.getPrivileges())
|
|
|
|
|
- .canResale(winItem.isCanResale())
|
|
|
|
|
- .royalties(winItem.getRoyalties())
|
|
|
|
|
- .serviceCharge(winItem.getServiceCharge())
|
|
|
|
|
- .price(order.getPrice())
|
|
|
|
|
- .status(AssetStatus.NORMAL)
|
|
|
|
|
- .ipfsUrl(ipfsUpload(winItem.getPic().get(0).getUrl()))
|
|
|
|
|
- .build();
|
|
|
|
|
|
|
+ public Asset createAsset(BlindBoxItem winItem, User user, Long orderId, BigDecimal price, String type) {
|
|
|
|
|
+ Asset asset = Asset.create(winItem, user);
|
|
|
|
|
+ asset.setOrderId(orderId);
|
|
|
|
|
+ asset.setPrice(price);
|
|
|
|
|
+ asset.setIpfsUrl(ipfsUpload(winItem.getPic().get(0).getUrl()));
|
|
|
assetRepo.save(asset);
|
|
assetRepo.save(asset);
|
|
|
tokenHistoryRepo.save(TokenHistory.builder()
|
|
tokenHistoryRepo.save(TokenHistory.builder()
|
|
|
.tokenId(asset.getTokenId())
|
|
.tokenId(asset.getTokenId())
|
|
|
- .fromUser(order.getMinter())
|
|
|
|
|
- .fromUserId(order.getMinterId())
|
|
|
|
|
|
|
+ .fromUser(winItem.getMinter())
|
|
|
|
|
+ .fromUserId(winItem.getMinterId())
|
|
|
.toUser(user.getNickname())
|
|
.toUser(user.getNickname())
|
|
|
.toUserId(user.getId())
|
|
.toUserId(user.getId())
|
|
|
- .operation("出售")
|
|
|
|
|
- .price(order.getPrice())
|
|
|
|
|
|
|
+ .operation(type)
|
|
|
|
|
+ .price(price)
|
|
|
.build());
|
|
.build());
|
|
|
|
|
|
|
|
return asset;
|
|
return asset;
|
|
@@ -476,4 +441,10 @@ public class AssetService {
|
|
|
if (tokenId == null) return new ArrayList<>();
|
|
if (tokenId == null) return new ArrayList<>();
|
|
|
return tokenHistoryRepo.findByTokenIdOrderByCreatedAtDesc(tokenId);
|
|
return tokenHistoryRepo.findByTokenIdOrderByCreatedAtDesc(tokenId);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @RedisLockable(key = "#id", expiration = 60, isWaiting = true)
|
|
|
|
|
+ public void testLock(String id, String i) throws InterruptedException {
|
|
|
|
|
+ Thread.sleep(1000);
|
|
|
|
|
+ log.info("" + i);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|