|
|
@@ -46,6 +46,8 @@ import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.ForkJoinPool;
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
@@ -370,7 +372,7 @@ public class CollectionService {
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
- public Collection createBlindBox(CreateBlindBox createBlindBox) {
|
|
|
+ public Collection createBlindBox(CreateBlindBox createBlindBox) throws Exception {
|
|
|
Collection blindBox = createBlindBox.getBlindBox();
|
|
|
if (blindBox.getId() != null) {
|
|
|
throw new BusinessException("无法完成此操作");
|
|
|
@@ -398,23 +400,26 @@ public class CollectionService {
|
|
|
blindBox.setStock(blindBox.getTotal());
|
|
|
blindBox.setSale(0);
|
|
|
collectionRepo.save(blindBox);
|
|
|
- createBlindBox.getItems().stream().parallel().forEach(item -> {
|
|
|
- Collection collection = list.stream().filter(i -> i.getId().equals(item.getCollectionId())).findAny()
|
|
|
- .orElseThrow(new BusinessException("所选藏品不存在"));
|
|
|
- decreaseStock(collection.getId(), item.getTotal());
|
|
|
- BlindBoxItem blindBoxItem = new BlindBoxItem();
|
|
|
- BeanUtils.copyProperties(collection, blindBoxItem);
|
|
|
- blindBoxItem.setId(null);
|
|
|
- blindBoxItem.setOasisId(collection.getOasisId());
|
|
|
- blindBoxItem.setCollectionId(item.getCollectionId());
|
|
|
- blindBoxItem.setSale(0);
|
|
|
- blindBoxItem.setTotal(item.getTotal());
|
|
|
- blindBoxItem.setStock(item.getTotal());
|
|
|
- blindBoxItem.setRare(item.isRare());
|
|
|
- blindBoxItem.setBlindBoxId(blindBox.getId());
|
|
|
- blindBoxItemRepo.saveAndFlush(blindBoxItem);
|
|
|
- log.info("createBlindBoxItemSuccess" + blindBoxItem.getId());
|
|
|
- });
|
|
|
+ new ForkJoinPool(128).submit(() -> {
|
|
|
+ createBlindBox.getItems().stream().parallel().forEach(item -> {
|
|
|
+ Collection collection = list.stream().filter(i -> i.getId().equals(item.getCollectionId()))
|
|
|
+ .findFirst().get();
|
|
|
+ decreaseStock(collection.getId(), item.getTotal());
|
|
|
+ BlindBoxItem blindBoxItem = new BlindBoxItem();
|
|
|
+ BeanUtils.copyProperties(collection, blindBoxItem);
|
|
|
+ blindBoxItem.setId(null);
|
|
|
+ blindBoxItem.setOasisId(collection.getOasisId());
|
|
|
+ blindBoxItem.setCollectionId(item.getCollectionId());
|
|
|
+ blindBoxItem.setSale(0);
|
|
|
+ blindBoxItem.setTotal(item.getTotal());
|
|
|
+ blindBoxItem.setStock(item.getTotal());
|
|
|
+ blindBoxItem.setRare(item.isRare());
|
|
|
+ blindBoxItem.setBlindBoxId(blindBox.getId());
|
|
|
+ blindBoxItem.setCompanyId(collection.getCompanyId());
|
|
|
+ blindBoxItemRepo.saveAndFlush(blindBoxItem);
|
|
|
+ log.info("createBlindBoxItemSuccess" + blindBoxItem.getId());
|
|
|
+ });
|
|
|
+ }).get();
|
|
|
return blindBox;
|
|
|
}
|
|
|
|