|
@@ -209,6 +209,65 @@ public class AssetService {
|
|
|
return asset;
|
|
return asset;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public Asset createAsset(PhotoAsset photoAsset, User user, Long orderId, BigDecimal price, String type,
|
|
|
|
|
+ Integer number, boolean safeFlag) {
|
|
|
|
|
+ Asset asset = Asset.create(photoAsset, user);
|
|
|
|
|
+ asset.setTokenId(TokenUtils.genTokenId());
|
|
|
|
|
+ asset.setNumber(number);
|
|
|
|
|
+ asset.setOrderId(orderId);
|
|
|
|
|
+ asset.setPrice(price);
|
|
|
|
|
+ asset.setPrefixName("星图");
|
|
|
|
|
+ asset.setTags(new HashSet<>());
|
|
|
|
|
+ User fakeUser = null;
|
|
|
|
|
+ if (safeFlag) {
|
|
|
|
|
+ fakeUser = createFakeUser();
|
|
|
|
|
+ asset.setOwner(fakeUser.getNickname());
|
|
|
|
|
+ asset.setOwnerId(fakeUser.getId());
|
|
|
|
|
+ asset.setOwnerAvatar(fakeUser.getAvatar());
|
|
|
|
|
+ }
|
|
|
|
|
+ assetRepo.saveAndFlush(asset);
|
|
|
|
|
+ tokenHistoryRepo.save(TokenHistory.builder()
|
|
|
|
|
+ .tokenId(asset.getTokenId())
|
|
|
|
|
+ .fromUser(photoAsset.getUserName())
|
|
|
|
|
+ .fromUserId(photoAsset.getUserId())
|
|
|
|
|
+ .fromAvatar(photoAsset.getUserAvatar())
|
|
|
|
|
+ .toUser((safeFlag ? fakeUser : user).getNickname())
|
|
|
|
|
+ .toUserId((safeFlag ? fakeUser : user).getId())
|
|
|
|
|
+ .toAvatar((safeFlag ? fakeUser : user).getAvatar())
|
|
|
|
|
+ .operation(type)
|
|
|
|
|
+ .price(price)
|
|
|
|
|
+ .companyId(asset.getCompanyId())
|
|
|
|
|
+ .build());
|
|
|
|
|
+
|
|
|
|
|
+ //绿洲石
|
|
|
|
|
+ rockRecordService.addRock(user.getId(), price, "购买");
|
|
|
|
|
+
|
|
|
|
|
+ rocketMQTemplate.syncSend(generalProperties.getMintTopic(), asset.getId());
|
|
|
|
|
+ if (asset.getOasisId() != null & asset.getSource().equals(AssetSource.OFFICIAL)) {
|
|
|
|
|
+ AirDrop airDrop = new AirDrop();
|
|
|
|
|
+ airDrop.setName("建筑空投展厅");
|
|
|
|
|
+ airDrop.setCollectionId(207012L);
|
|
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
|
|
+ userIds.add(user.getId());
|
|
|
|
|
+ List<Long> nums = new ArrayList<>();
|
|
|
|
|
+ nums.add(1L);
|
|
|
|
|
+ airDrop.setType(AirDropType.asset);
|
|
|
|
|
+ List<DropTarget> dropTargets = new ArrayList<>();
|
|
|
|
|
+ DropTarget dropTarget = new DropTarget();
|
|
|
|
|
+ dropTarget.setNickname(user.getNickname());
|
|
|
|
|
+ dropTarget.setNum(1);
|
|
|
|
|
+ dropTarget.setPhone(user.getPhone());
|
|
|
|
|
+ dropTarget.setUserId(user.getId());
|
|
|
|
|
+ dropTargets.add(dropTarget);
|
|
|
|
|
+ airDrop.setTargets(dropTargets);
|
|
|
|
|
+ airDrop.setUserIds(userIds);
|
|
|
|
|
+ airDrop.setNum(nums);
|
|
|
|
|
+ airDropService.create(airDrop);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return asset;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public Asset createAsset(BlindBoxItem winItem, User user, Long orderId, BigDecimal price, String type,
|
|
public Asset createAsset(BlindBoxItem winItem, User user, Long orderId, BigDecimal price, String type,
|
|
|
Integer number, Integer holdDays, boolean safeFlag) {
|
|
Integer number, Integer holdDays, boolean safeFlag) {
|
|
|
Collection blindBox = collectionRepo.findDetailById(winItem.getBlindBoxId())
|
|
Collection blindBox = collectionRepo.findDetailById(winItem.getBlindBoxId())
|
|
@@ -321,6 +380,10 @@ public class AssetService {
|
|
|
throw new BusinessException("此藏品不属于你");
|
|
throw new BusinessException("此藏品不属于你");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (asset.getType().equals(CollectionType.PICTURE)) {
|
|
|
|
|
+ throw new BusinessException("星图藏品不可寄售");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (asset.getLockTo() != null && asset.getLockTo().isAfter(LocalDateTime.now())) {
|
|
if (asset.getLockTo() != null && asset.getLockTo().isAfter(LocalDateTime.now())) {
|
|
|
throw new BusinessException("已锁仓,不能寄售");
|
|
throw new BusinessException("已锁仓,不能寄售");
|
|
|
}
|
|
}
|
|
@@ -430,6 +493,31 @@ public class AssetService {
|
|
|
assetRepo.saveAndFlush(asset);
|
|
assetRepo.saveAndFlush(asset);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void cancelConsignmentAndStore(Long id) {
|
|
|
|
|
+ Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
|
|
+ if (!asset.getUserId().equals(SecurityUtils.getAuthenticatedUser().getId())) {
|
|
|
|
|
+ throw new BusinessException("此藏品不属于你");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!asset.getStatus().equals(AssetStatus.NORMAL)) {
|
|
|
|
|
+ throw new BusinessException("销毁藏品状态错误!");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (asset.getPublicCollectionId() != null) {
|
|
|
|
|
+ List<Order> orders = orderRepo.findByCollectionId(asset.getPublicCollectionId());
|
|
|
|
|
+ if (orders.stream().anyMatch(o -> o.getStatus() != OrderStatus.CANCELLED)) {
|
|
|
|
|
+ throw new BusinessException("已有订单不可取消");
|
|
|
|
|
+ }
|
|
|
|
|
+ collectionRepo.findById(asset.getPublicCollectionId())
|
|
|
|
|
+ .ifPresent(collection -> {
|
|
|
|
|
+ collection.setSalable(false);
|
|
|
|
|
+ collectionRepo.save(collection);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ asset.setConsignment(false);
|
|
|
|
|
+ asset.setPublicShow(false);
|
|
|
|
|
+ asset.setStatus(AssetStatus.DESTROYING);
|
|
|
|
|
+ assetRepo.saveAndFlush(asset);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void cancelConsignment(Long id) {
|
|
public void cancelConsignment(Long id) {
|
|
|
Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
if (!asset.getUserId().equals(SecurityUtils.getAuthenticatedUser().getId())) {
|
|
if (!asset.getUserId().equals(SecurityUtils.getAuthenticatedUser().getId())) {
|
|
@@ -795,16 +883,16 @@ public class AssetService {
|
|
|
if (tags.isEmpty()) return new PageImpl<>(Collections.emptyList());
|
|
if (tags.isEmpty()) return new PageImpl<>(Collections.emptyList());
|
|
|
return assetRepo.findAll((Specification<Asset>) (root, query, criteriaBuilder) ->
|
|
return assetRepo.findAll((Specification<Asset>) (root, query, criteriaBuilder) ->
|
|
|
query.distinct(true).where(
|
|
query.distinct(true).where(
|
|
|
- // where userId=some id
|
|
|
|
|
- criteriaBuilder.equal(root.get("userId"), userId),
|
|
|
|
|
- // and (lockTo is null or (lockTo is not null and lockTo < now))
|
|
|
|
|
- criteriaBuilder.or(criteriaBuilder.isNull(root.get("lockTo")),
|
|
|
|
|
- criteriaBuilder.and(criteriaBuilder.isNotNull(root.get("lockTo")),
|
|
|
|
|
- criteriaBuilder.lessThan(root.get("lockTo"), LocalDateTime.now()))),
|
|
|
|
|
- // and status = 'NORMAL'
|
|
|
|
|
- criteriaBuilder.equal(root.get("status"), AssetStatus.NORMAL),
|
|
|
|
|
- // and has some tagId
|
|
|
|
|
- root.join("tags").get("id").in(tags.stream().map(Tag::getId).toArray()))
|
|
|
|
|
|
|
+ // where userId=some id
|
|
|
|
|
+ criteriaBuilder.equal(root.get("userId"), userId),
|
|
|
|
|
+ // and (lockTo is null or (lockTo is not null and lockTo < now))
|
|
|
|
|
+ criteriaBuilder.or(criteriaBuilder.isNull(root.get("lockTo")),
|
|
|
|
|
+ criteriaBuilder.and(criteriaBuilder.isNotNull(root.get("lockTo")),
|
|
|
|
|
+ criteriaBuilder.lessThan(root.get("lockTo"), LocalDateTime.now()))),
|
|
|
|
|
+ // and status = 'NORMAL'
|
|
|
|
|
+ criteriaBuilder.equal(root.get("status"), AssetStatus.NORMAL),
|
|
|
|
|
+ // and has some tagId
|
|
|
|
|
+ root.join("tags").get("id").in(tags.stream().map(Tag::getId).toArray()))
|
|
|
.getRestriction(), pageable);
|
|
.getRestriction(), pageable);
|
|
|
} else {
|
|
} else {
|
|
|
return assetRepo.findByUserIdAndStatusAndNameLike(userId, AssetStatus.NORMAL,
|
|
return assetRepo.findByUserIdAndStatusAndNameLike(userId, AssetStatus.NORMAL,
|
|
@@ -871,6 +959,57 @@ public class AssetService {
|
|
|
userRepo.addDestroyPoint(userId, 1);
|
|
userRepo.addDestroyPoint(userId, 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void destroyWithoutTradecode(Long id, Long userId) {
|
|
|
|
|
+ Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
|
|
+ if (!asset.getUserId().equals(userId)) {
|
|
|
|
|
+ throw new BusinessException("此藏品不属于该用户");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (asset.getStatus() != AssetStatus.DESTROYING) {
|
|
|
|
|
+ throw new BusinessException("当前状态不可销毁");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (asset.isPublicShow()) {
|
|
|
|
|
+ throw new BusinessException("请先取消公开展示");
|
|
|
|
|
+// cancelPublic(asset);
|
|
|
|
|
+ }
|
|
|
|
|
+ User toUser = userRepo.findById(Constants.BLACK_HOLE_USER_ID).orElseThrow(new BusinessException("无记录"));
|
|
|
|
|
+
|
|
|
|
|
+ TokenHistory tokenHistory = TokenHistory.builder()
|
|
|
|
|
+ .tokenId(asset.getTokenId())
|
|
|
|
|
+ .fromUser(asset.getOwner())
|
|
|
|
|
+ .fromUserId(asset.getOwnerId())
|
|
|
|
|
+ .fromAvatar(asset.getOwnerAvatar())
|
|
|
|
|
+ .toUser(toUser.getNickname())
|
|
|
|
|
+ .toUserId(toUser.getId())
|
|
|
|
|
+ .toAvatar(toUser.getAvatar())
|
|
|
|
|
+ .operation(TransferReason.DESTROY.getDescription())
|
|
|
|
|
+ .price(null)
|
|
|
|
|
+ .companyId(asset.getCompanyId())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ tokenHistoryRepo.save(tokenHistory);
|
|
|
|
|
+
|
|
|
|
|
+ asset.setPublicShow(false);
|
|
|
|
|
+ asset.setConsignment(false);
|
|
|
|
|
+ asset.setPublicCollectionId(null);
|
|
|
|
|
+ asset.setStatus(AssetStatus.DESTROYED);
|
|
|
|
|
+ asset.setOwner(toUser.getNickname());
|
|
|
|
|
+ asset.setOwnerId(toUser.getId());
|
|
|
|
|
+ asset.setOwnerAvatar(toUser.getAvatar());
|
|
|
|
|
+ assetRepo.saveAndFlush(asset);
|
|
|
|
|
+ //积分记录
|
|
|
|
|
+ destroyRecordRepo.save(DestroyRecord.builder()
|
|
|
|
|
+ .userId(userId)
|
|
|
|
|
+ .assetId(asset.getId())
|
|
|
|
|
+ .name(asset.getName())
|
|
|
|
|
+ .pic(asset.getPic().get(0).getUrl())
|
|
|
|
|
+ .record(1)
|
|
|
|
|
+ .type(RecordType.OBTAIN)
|
|
|
|
|
+ .companyId(asset.getCompanyId())
|
|
|
|
|
+ .build());
|
|
|
|
|
+
|
|
|
|
|
+ //加积分
|
|
|
|
|
+ userRepo.addDestroyPoint(userId, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public double getRoyalties(Long minterId, double royalties, Long userId) {
|
|
public double getRoyalties(Long minterId, double royalties, Long userId) {
|
|
|
if (royalties == 2) {
|
|
if (royalties == 2) {
|
|
|
return 2;
|
|
return 2;
|