|
@@ -70,6 +70,7 @@ public class CollectionService {
|
|
|
private Environment env;
|
|
private Environment env;
|
|
|
private OrderRepo orderRepo;
|
|
private OrderRepo orderRepo;
|
|
|
private TokenHistoryRepo tokenHistoryRepo;
|
|
private TokenHistoryRepo tokenHistoryRepo;
|
|
|
|
|
+ private TagRepo tagRepo;
|
|
|
|
|
|
|
|
private final Map<Long, ScheduledFuture<?>> tasks = new HashMap<>();
|
|
private final Map<Long, ScheduledFuture<?>> tasks = new HashMap<>();
|
|
|
|
|
|
|
@@ -131,6 +132,10 @@ public class CollectionService {
|
|
|
record.setStock(record.getTotal());
|
|
record.setStock(record.getTotal());
|
|
|
record.setSale(0);
|
|
record.setSale(0);
|
|
|
record.setVipQuota(record.getTotalQuota());
|
|
record.setVipQuota(record.getTotalQuota());
|
|
|
|
|
+ if (!record.getTags().isEmpty()) {
|
|
|
|
|
+ record.setTags(new HashSet<>(tagRepo.findAllById(record.getTags().stream().map(Tag::getId)
|
|
|
|
|
+ .collect(Collectors.toList()))));
|
|
|
|
|
+ }
|
|
|
if (record.isScheduleSale()) {
|
|
if (record.isScheduleSale()) {
|
|
|
if (record.getStartTime() == null) {
|
|
if (record.getStartTime() == null) {
|
|
|
throw new BusinessException("请填写定时发布时间");
|
|
throw new BusinessException("请填写定时发布时间");
|
|
@@ -149,18 +154,50 @@ public class CollectionService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Collection update(Collection record) {
|
|
public Collection update(Collection record) {
|
|
|
- collectionRepo.update(record.getId(), record.isOnShelf(), record.isSalable(),
|
|
|
|
|
- record.getStartTime(), record.isScheduleSale(), record.getSort(),
|
|
|
|
|
- record.getDetail(), JSON.toJSONString(record.getPrivileges()),
|
|
|
|
|
- JSON.toJSONString(record.getProperties()), JSON.toJSONString(record.getModel3d()),
|
|
|
|
|
- record.getMaxCount(), record.getCountId(), record.isScanCode(), record.isNoSoldOut(),
|
|
|
|
|
- record.getAssignment(), record.isCouponPayment(), record.getShareBg(), record.getRegisterBg(),
|
|
|
|
|
- record.getVipQuota(), record.getTimeDelay(), record.getSaleTime(), record.getHoldDays(),
|
|
|
|
|
- record.getOpenQuota(), record.getTotalQuota(), record.getMinimumCharge());
|
|
|
|
|
-
|
|
|
|
|
- record = collectionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
|
|
- onShelfTask(record);
|
|
|
|
|
- return record;
|
|
|
|
|
|
|
+// collectionRepo.update(record.getId(), record.isOnShelf(), record.isSalable(),
|
|
|
|
|
+// record.getStartTime(), record.isScheduleSale(), record.getSort(),
|
|
|
|
|
+// record.getDetail(), JSON.toJSONString(record.getPrivileges()),
|
|
|
|
|
+// JSON.toJSONString(record.getProperties()), JSON.toJSONString(record.getModel3d()),
|
|
|
|
|
+// record.getMaxCount(), record.getCountId(), record.isScanCode(), record.isNoSoldOut(),
|
|
|
|
|
+// record.getAssignment(), record.isCouponPayment(), record.getShareBg(), record.getRegisterBg(),
|
|
|
|
|
+// record.getVipQuota(), record.getTimeDelay(), record.getSaleTime(), record.getHoldDays(),
|
|
|
|
|
+// record.getOpenQuota(), record.getTotalQuota(), record.getMinimumCharge());
|
|
|
|
|
+
|
|
|
|
|
+ Collection collection = collectionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
|
|
+ collection.setOnShelf(record.isOnShelf());
|
|
|
|
|
+ collection.setSalable(record.isSalable());
|
|
|
|
|
+ collection.setStartTime(record.getStartTime());
|
|
|
|
|
+ collection.setScheduleSale(record.isScheduleSale());
|
|
|
|
|
+ collection.setSort(record.getSort());
|
|
|
|
|
+ collection.setDetail(record.getDetail());
|
|
|
|
|
+ collection.setPrivileges(record.getPrivileges());
|
|
|
|
|
+ collection.setProperties(record.getProperties());
|
|
|
|
|
+ collection.setModel3d(record.getModel3d());
|
|
|
|
|
+ collection.setMaxCount(record.getMaxCount());
|
|
|
|
|
+ collection.setCountId(record.getCountId());
|
|
|
|
|
+ collection.setScanCode(record.isScanCode());
|
|
|
|
|
+ collection.setNoSoldOut(record.isNoSoldOut());
|
|
|
|
|
+ collection.setAssignment(record.getAssignment());
|
|
|
|
|
+ collection.setCouponPayment(record.isCouponPayment());
|
|
|
|
|
+ collection.setShareBg(record.getShareBg());
|
|
|
|
|
+ collection.setRegisterBg(record.getRegisterBg());
|
|
|
|
|
+ collection.setVipQuota(record.getVipQuota());
|
|
|
|
|
+ collection.setTimeDelay(record.getTimeDelay());
|
|
|
|
|
+ collection.setSaleTime(record.getSaleTime());
|
|
|
|
|
+ collection.setHoldDays(record.getHoldDays());
|
|
|
|
|
+ collection.setOpenQuota(record.getOpenQuota());
|
|
|
|
|
+ collection.setTotalQuota(record.getTotalQuota());
|
|
|
|
|
+ collection.setMinimumCharge(record.getMinimumCharge());
|
|
|
|
|
+ if (record.getTags().isEmpty()) {
|
|
|
|
|
+ collection.setTags(null);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ collection.setTags(new HashSet<>(tagRepo.findAllById(record.getTags().stream().map(Tag::getId)
|
|
|
|
|
+ .collect(Collectors.toList()))));
|
|
|
|
|
+ }
|
|
|
|
|
+ collection = collectionRepo.save(collection);
|
|
|
|
|
+
|
|
|
|
|
+ onShelfTask(collection);
|
|
|
|
|
+ return collection;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void onShelfTask(Collection record) {
|
|
private void onShelfTask(Collection record) {
|
|
@@ -209,6 +246,25 @@ public class CollectionService {
|
|
|
return collectionDTO;
|
|
return collectionDTO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public Collection queryUserDetail(Collection collection, boolean join, boolean showVip) {
|
|
|
|
|
+ if (join) {
|
|
|
|
|
+ User user = SecurityUtils.getAuthenticatedUser();
|
|
|
|
|
+ if (user != null) {
|
|
|
|
|
+ List<Like> list = likeRepo.findByUserIdAndCollectionId(user.getId(),
|
|
|
|
|
+ collection.getId());
|
|
|
|
|
+ collection.setLiked(!list.isEmpty());
|
|
|
|
|
+ if (collection.getType() == CollectionType.BLIND_BOX) {
|
|
|
|
|
+ collection.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));
|
|
|
|
|
+ collection.setVipSurplus(user.getVipPurchase() - purchase);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return collection;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public List<CollectionDTO> toDTO(List<Collection> collections) {
|
|
public List<CollectionDTO> toDTO(List<Collection> collections) {
|
|
|
List<Like> likes = new ArrayList<>();
|
|
List<Like> likes = new ArrayList<>();
|
|
|
List<Appointment> appointments = new ArrayList<>();
|
|
List<Appointment> appointments = new ArrayList<>();
|
|
@@ -228,6 +284,24 @@ public class CollectionService {
|
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void queryUserDetail(List<Collection> collections) {
|
|
|
|
|
+ List<Like> likes = new ArrayList<>();
|
|
|
|
|
+ List<Appointment> appointments = new ArrayList<>();
|
|
|
|
|
+ if (SecurityUtils.getAuthenticatedUser() != null) {
|
|
|
|
|
+ likes.addAll(likeRepo.findByUserIdAndCollectionIdIsNotNull(SecurityUtils.getAuthenticatedUser().getId()));
|
|
|
|
|
+ appointments.addAll(appointmentRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId()));
|
|
|
|
|
+ }
|
|
|
|
|
+ collections.stream().parallel().forEach(collection -> {
|
|
|
|
|
+ queryUserDetail(collection, false, false);
|
|
|
|
|
+ if (!likes.isEmpty()) {
|
|
|
|
|
+ collection.setLiked(likes.stream().anyMatch(l -> l.getCollectionId().equals(collection.getId())));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!appointments.isEmpty()) {
|
|
|
|
|
+ collection.setAppointment(appointments.stream().anyMatch(a -> a.getBlindBoxId().equals(collection.getId())));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public Page<CollectionDTO> toDTO(Page<Collection> collections) {
|
|
public Page<CollectionDTO> toDTO(Page<Collection> collections) {
|
|
|
List<CollectionDTO> userDTOS = toDTO(collections.getContent());
|
|
List<CollectionDTO> userDTOS = toDTO(collections.getContent());
|
|
|
return new PageImpl<>(userDTOS, collections.getPageable(), collections.getTotalElements());
|
|
return new PageImpl<>(userDTOS, collections.getPageable(), collections.getTotalElements());
|
|
@@ -416,7 +490,7 @@ public class CollectionService {
|
|
|
return increaseSale(id, -number);
|
|
return increaseSale(id, -number);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// @Debounce(key = "#id", delay = 500)
|
|
|
|
|
|
|
+ // @Debounce(key = "#id", delay = 500)
|
|
|
public void syncStock(Long id) {
|
|
public void syncStock(Long id) {
|
|
|
Integer stock = (Integer) redisTemplate.opsForValue().get(RedisKeys.COLLECTION_STOCK + id);
|
|
Integer stock = (Integer) redisTemplate.opsForValue().get(RedisKeys.COLLECTION_STOCK + id);
|
|
|
if (stock != null) {
|
|
if (stock != null) {
|