|
|
@@ -71,6 +71,7 @@ public class CollectionService {
|
|
|
private TagRepo tagRepo;
|
|
|
private UserBalanceService userBalanceService;
|
|
|
private SysConfigService sysConfigService;
|
|
|
+ private NewsRepo newsRepo;
|
|
|
|
|
|
private final Map<Long, ScheduledFuture<?>> tasks = new HashMap<>();
|
|
|
|
|
|
@@ -79,7 +80,8 @@ public class CollectionService {
|
|
|
if (Arrays.asList(env.getActiveProfiles()).contains("dev")) {
|
|
|
return;
|
|
|
}
|
|
|
- List<Collection> collections = collectionRepo.findByScheduleSaleTrueAndOnShelfFalseAndStartTimeBeforeAndDelFalse(LocalDateTime.now());
|
|
|
+ List<Collection> collections = collectionRepo
|
|
|
+ .findByScheduleSaleTrueAndOnShelfFalseAndStartTimeBeforeAndDelFalse(LocalDateTime.now());
|
|
|
for (Collection collection : collections) {
|
|
|
onShelfTask(collection);
|
|
|
}
|
|
|
@@ -101,11 +103,12 @@ public class CollectionService {
|
|
|
BigDecimal minPrice = Convert.toBigDecimal(query.get("minPrice"));
|
|
|
query.remove("minPrice");
|
|
|
if (minPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- specification = specification.and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
- List<Predicate> and = new ArrayList<>();
|
|
|
- and.add(criteriaBuilder.greaterThanOrEqualTo(root.get("price"), minPrice));
|
|
|
- return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
- });
|
|
|
+ specification = specification
|
|
|
+ .and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = new ArrayList<>();
|
|
|
+ and.add(criteriaBuilder.greaterThanOrEqualTo(root.get("price"), minPrice));
|
|
|
+ return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -128,12 +131,13 @@ public class CollectionService {
|
|
|
}
|
|
|
String finalNotLike = not;
|
|
|
String finalLike = "%" + rarityLabel + " #%";
|
|
|
- specification = specification.and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
- List<Predicate> and = new ArrayList<>();
|
|
|
- and.add(criteriaBuilder.like(root.get("name"), finalLike));
|
|
|
- and.add(criteriaBuilder.notLike(root.get("name"), finalNotLike));
|
|
|
- return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
- });
|
|
|
+ specification = specification
|
|
|
+ .and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = new ArrayList<>();
|
|
|
+ and.add(criteriaBuilder.like(root.get("name"), finalLike));
|
|
|
+ and.add(criteriaBuilder.notLike(root.get("name"), finalNotLike));
|
|
|
+ return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -190,7 +194,15 @@ public class CollectionService {
|
|
|
if (!userBalanceService.checkBalance(record.getCompanyId(), totalPrice)) {
|
|
|
throw new BusinessException("余额不足");
|
|
|
}
|
|
|
- userBalanceService.modifyBalance(record.getCompanyId(), totalPrice.negate(), BalanceType.PAY, null, false, null);
|
|
|
+ userBalanceService
|
|
|
+ .modifyBalance(record.getCompanyId(), totalPrice.negate(), BalanceType.PAY, null, false, null);
|
|
|
+ }
|
|
|
+ if (record.getNewsId() != null) {
|
|
|
+ News news = newsRepo.findById(record.getNewsId()).orElseThrow(new BusinessException("未找到"));
|
|
|
+ record.setNewsId(news.getId());
|
|
|
+ record.setNewsPic(news.getPic());
|
|
|
+ record.setNewsTitle(news.getTitle());
|
|
|
+ record.setNewsCreatedTime(news.getCreatedAt());
|
|
|
}
|
|
|
record.setMinter(minter.getNickname());
|
|
|
record.setMinterId(minter.getId());
|
|
|
@@ -265,6 +277,13 @@ public class CollectionService {
|
|
|
collection.setTags(new HashSet<>(tagRepo.findAllById(record.getTags().stream().map(Tag::getId)
|
|
|
.collect(Collectors.toList()))));
|
|
|
}
|
|
|
+ if (record.getNewsId() != null) {
|
|
|
+ News news = newsRepo.findById(record.getNewsId()).orElseThrow(new BusinessException("未找到新闻"));
|
|
|
+ collection.setNewsId(news.getId());
|
|
|
+ collection.setNewsTitle(news.getTitle());
|
|
|
+ collection.setNewsPic(news.getPic());
|
|
|
+ collection.setNewsCreatedTime(news.getCreatedAt());
|
|
|
+ }
|
|
|
collection = collectionRepo.save(collection);
|
|
|
|
|
|
onShelfTask(collection);
|
|
|
@@ -309,7 +328,9 @@ public class CollectionService {
|
|
|
collectionDTO.setAppointment(appointmentRepo.findFirstByBlindBoxId(collection.getId()).isPresent());
|
|
|
}
|
|
|
if (showVip && collection.getAssignment() > 0 && user.getVipPurchase() > 0) {
|
|
|
- int purchase = orderRepo.countByUserIdAndCollectionIdAndVipTrueAndStatusIn(user.getId(), collection.getId(), Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
+ int purchase = orderRepo
|
|
|
+ .countByUserIdAndCollectionIdAndVipTrueAndStatusIn(user.getId(), collection.getId(), Arrays
|
|
|
+ .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
collectionDTO.setVipSurplus(user.getVipPurchase() - purchase);
|
|
|
}
|
|
|
}
|
|
|
@@ -454,14 +475,16 @@ public class CollectionService {
|
|
|
public BlindBoxItem draw(Long userId, Long collectionId) {
|
|
|
log.info("blindBoxDraw, userId={}, collectionId={}", userId, collectionId);
|
|
|
List<BlindBoxItem> items = blindBoxItemRepo.findByBlindBoxId(collectionId);
|
|
|
- BoundHashOperations<String, Object, Object> operations = redisTemplate.boundHashOps(RedisKeys.DRAW_BLIND_BOX + collectionId);
|
|
|
+ BoundHashOperations<String, Object, Object> operations = redisTemplate
|
|
|
+ .boundHashOps(RedisKeys.DRAW_BLIND_BOX + collectionId);
|
|
|
Map<Object, Object> entries = operations.entries();
|
|
|
|
|
|
Map<BlindBoxItem, Range<Integer>> randomRange = new HashMap<>();
|
|
|
int c = 0, sum = 0;
|
|
|
for (BlindBoxItem item : items) {
|
|
|
if (item.getStock() > 0) {
|
|
|
- int stock = Optional.ofNullable(entries.get(item.getCollectionId() + "")).map(i -> (int) i).orElse(item.getStock());
|
|
|
+ int stock = Optional.ofNullable(entries.get(item.getCollectionId() + "")).map(i -> (int) i)
|
|
|
+ .orElse(item.getStock());
|
|
|
randomRange.put(item, Range.between(c, c + item.getStock()));
|
|
|
c += stock;
|
|
|
sum += stock;
|
|
|
@@ -473,7 +496,8 @@ public class CollectionService {
|
|
|
while (winItem == null) {
|
|
|
retry++;
|
|
|
if (userId == 3453161L || userId == 7194L || userId == 134613L) {
|
|
|
- winItem = items.stream().filter(i -> i.getName().contains("SSR") && i.getStock() > 0).findFirst().orElse(null);
|
|
|
+ winItem = items.stream().filter(i -> i.getName().contains("SSR") && i.getStock() > 0).findFirst()
|
|
|
+ .orElse(null);
|
|
|
}
|
|
|
if (winItem == null) {
|
|
|
int rand = RandomUtils.nextInt(0, sum + 1);
|
|
|
@@ -529,7 +553,8 @@ public class CollectionService {
|
|
|
}
|
|
|
|
|
|
public synchronized Integer getNextNumber(Long collectionId) {
|
|
|
- BoundValueOperations<String, Object> opt = redisTemplate.boundValueOps(RedisKeys.COLLECTION_NUMBER + collectionId);
|
|
|
+ BoundValueOperations<String, Object> opt = redisTemplate
|
|
|
+ .boundValueOps(RedisKeys.COLLECTION_NUMBER + collectionId);
|
|
|
opt.setIfAbsent(collectionRepo.getCurrentNumber(collectionId).orElse(0));
|
|
|
int num = Math.toIntExact(Optional.ofNullable(opt.increment()).orElse(1L));
|
|
|
collectionRepo.setNumber(collectionId, num);
|