|
@@ -124,7 +124,7 @@ public class MintOrderService {
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public void create(Long userId, List<Long> assetIds) {
|
|
public void create(Long userId, List<Long> assetIds) {
|
|
|
User user = userRepo.findByIdAndDelFalse(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
User user = userRepo.findByIdAndDelFalse(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
- User blackHole = userRepo.findByIdAndDelFalse(1435297L).orElseThrow(new BusinessException("无法铸造"));
|
|
|
|
|
|
|
+ User blackHole = userRepo.findByIdAndDelFalse(Constants.BLACK_HOLE_USER_ID).orElseThrow(new BusinessException("无法铸造"));
|
|
|
if (assetIds.size() != 3) {
|
|
if (assetIds.size() != 3) {
|
|
|
throw new BusinessException("数量不正确,请重新选择");
|
|
throw new BusinessException("数量不正确,请重新选择");
|
|
|
}
|
|
}
|
|
@@ -239,11 +239,10 @@ public class MintOrderService {
|
|
|
// if (assets.stream().anyMatch(a -> a.isPublicShow() || a.isConsignment())) {
|
|
// if (assets.stream().anyMatch(a -> a.isPublicShow() || a.isConsignment())) {
|
|
|
// throw new BusinessException("请先下架所选藏品");
|
|
// throw new BusinessException("请先下架所选藏品");
|
|
|
// }
|
|
// }
|
|
|
-
|
|
|
|
|
|
|
+ if (assets.stream().anyMatch(a -> a.getStatus() != AssetStatus.NORMAL)) {
|
|
|
|
|
+ throw new BusinessException("所选藏品不符和规则,请重新选择");
|
|
|
|
|
+ }
|
|
|
if (!mintActivity.isAudit()) {
|
|
if (!mintActivity.isAudit()) {
|
|
|
- if (assets.stream().anyMatch(a -> a.getStatus() != AssetStatus.NORMAL)) {
|
|
|
|
|
- throw new BusinessException("所选藏品不符和规则,请重新选择");
|
|
|
|
|
- }
|
|
|
|
|
if (!mintActivityService.matchRule(new ArrayList<>(assets), mintActivity.getRule())) {
|
|
if (!mintActivityService.matchRule(new ArrayList<>(assets), mintActivity.getRule())) {
|
|
|
throw new BusinessException("所选藏品不符和规则,请重新选择");
|
|
throw new BusinessException("所选藏品不符和规则,请重新选择");
|
|
|
}
|
|
}
|
|
@@ -258,38 +257,23 @@ public class MintOrderService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
Map<Long, Long> privilegeIds = new HashMap<>();
|
|
Map<Long, Long> privilegeIds = new HashMap<>();
|
|
|
// 铸造特权
|
|
// 铸造特权
|
|
|
if (!mintActivity.isConsume()) {
|
|
if (!mintActivity.isConsume()) {
|
|
|
- assets.forEach(asset -> {
|
|
|
|
|
- List<Privilege> privileges = asset.getPrivileges()
|
|
|
|
|
- .stream()
|
|
|
|
|
- .filter(p -> p.getName().equals("铸造"))
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
- if (privileges.size() == 0) {
|
|
|
|
|
- throw new BusinessException("无铸造特权");
|
|
|
|
|
- } else {
|
|
|
|
|
- boolean flag = false;
|
|
|
|
|
- for (Privilege privilege : privileges) {
|
|
|
|
|
- // 打开多次 或者 可打开一次但未使用
|
|
|
|
|
- if (!privilege.isOnce() || (privilege.isOnce() && !privilege
|
|
|
|
|
- .isOpened())) {
|
|
|
|
|
- flag = true;
|
|
|
|
|
- privilegeIds.put(asset.getId(), privilege.getId());
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (!flag) {
|
|
|
|
|
- throw new BusinessException("铸造特权已使用");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ assets.forEach(a -> {
|
|
|
|
|
+ if (a.getPrivileges().stream().noneMatch(p ->
|
|
|
|
|
+ "铸造".equals(p.getName())
|
|
|
|
|
+ && (!p.isOnce() || !p.isOpened()))) {
|
|
|
|
|
+ throw new BusinessException(a.getName() + (a.getNumber() == null ? "" : (" #" + a.getNumber().toString())) + " 无铸造特权或特权已使用");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
assets.forEach(asset -> {
|
|
assets.forEach(asset -> {
|
|
|
asset.getPrivileges()
|
|
asset.getPrivileges()
|
|
|
.stream()
|
|
.stream()
|
|
|
- .filter(p -> p.getId().equals(privilegeIds.get(asset.getId())))
|
|
|
|
|
- .forEach(p -> {
|
|
|
|
|
|
|
+ .filter(p -> !p.isOnce() || !p.isOpened())
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .ifPresent(p -> {
|
|
|
|
|
+ privilegeIds.put(asset.getId(), p.getId());
|
|
|
p.setOpened(true);
|
|
p.setOpened(true);
|
|
|
p.setOpenTime(LocalDateTime.now());
|
|
p.setOpenTime(LocalDateTime.now());
|
|
|
p.setOpenedBy(SecurityUtils.getAuthenticatedUser().getId());
|
|
p.setOpenedBy(SecurityUtils.getAuthenticatedUser().getId());
|
|
@@ -298,7 +282,7 @@ public class MintOrderService {
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
// 转让的用户
|
|
// 转让的用户
|
|
|
- userRepo.findByIdAndDelFalse(1435297L).orElseThrow(new BusinessException("无法铸造"));
|
|
|
|
|
|
|
+ userRepo.findByIdAndDelFalse(Constants.BLACK_HOLE_USER_ID).orElseThrow(new BusinessException("无法铸造"));
|
|
|
|
|
|
|
|
// 消耗改为转赠
|
|
// 消耗改为转赠
|
|
|
assets.forEach(asset -> {
|
|
assets.forEach(asset -> {
|
|
@@ -569,7 +553,7 @@ public class MintOrderService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (mintOrder.isConsume()) {
|
|
if (mintOrder.isConsume()) {
|
|
|
- User newOwner = userRepo.findByIdAndDelFalse(1435297L).orElseThrow(new BusinessException("无法铸造"));
|
|
|
|
|
|
|
+ User newOwner = userRepo.findByIdAndDelFalse(Constants.BLACK_HOLE_USER_ID).orElseThrow(new BusinessException("无法铸造"));
|
|
|
assets.forEach(asset -> assetService.transfer(asset, asset.getPrice(), newOwner, TransferReason.GIFT, null));
|
|
assets.forEach(asset -> assetService.transfer(asset, asset.getPrice(), newOwner, TransferReason.GIFT, null));
|
|
|
}
|
|
}
|
|
|
mintOrderRepo.save(mintOrder);
|
|
mintOrderRepo.save(mintOrder);
|