|
|
@@ -12,6 +12,7 @@ import com.izouma.nineth.dto.CreateBlindBox;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.enums.CollectionSource;
|
|
|
import com.izouma.nineth.enums.CollectionType;
|
|
|
+import com.izouma.nineth.enums.OrderStatus;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.*;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
@@ -62,6 +63,7 @@ public class CollectionService {
|
|
|
private RocketMQTemplate rocketMQTemplate;
|
|
|
private GeneralProperties generalProperties;
|
|
|
private Environment env;
|
|
|
+ private OrderRepo orderRepo;
|
|
|
|
|
|
private final Map<Long, ScheduledFuture<?>> tasks = new HashMap<>();
|
|
|
|
|
|
@@ -179,20 +181,25 @@ public class CollectionService {
|
|
|
}
|
|
|
|
|
|
public CollectionDTO toDTO(Collection collection) {
|
|
|
- return toDTO(collection, true);
|
|
|
+ return toDTO(collection, true, false);
|
|
|
}
|
|
|
|
|
|
- public CollectionDTO toDTO(Collection collection, boolean join) {
|
|
|
+ public CollectionDTO toDTO(Collection collection, boolean join, boolean showVip) {
|
|
|
CollectionDTO collectionDTO = new CollectionDTO();
|
|
|
BeanUtils.copyProperties(collection, collectionDTO);
|
|
|
if (join) {
|
|
|
- if (SecurityUtils.getAuthenticatedUser() != null) {
|
|
|
- List<Like> list = likeRepo.findByUserIdAndCollectionId(SecurityUtils.getAuthenticatedUser().getId(),
|
|
|
+ User user = SecurityUtils.getAuthenticatedUser();
|
|
|
+ if (user != null) {
|
|
|
+ List<Like> list = likeRepo.findByUserIdAndCollectionId(user.getId(),
|
|
|
collection.getId());
|
|
|
collectionDTO.setLiked(!list.isEmpty());
|
|
|
if (collection.getType() == CollectionType.BLIND_BOX) {
|
|
|
collectionDTO.setAppointment(appointmentRepo.findFirstByBlindBoxId(collection.getId()).isPresent());
|
|
|
}
|
|
|
+ if (showVip && user.getVipPurchase() > 0) {
|
|
|
+ int purchase = orderRepo.countByUserIdAndCollectionIdAndVipTrueAndStatusIn(user.getId(), collection.getId(), Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
+ collectionDTO.setVipSurplus(user.getVipPurchase() - purchase);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return collectionDTO;
|
|
|
@@ -206,7 +213,7 @@ public class CollectionService {
|
|
|
appointments.addAll(appointmentRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId()));
|
|
|
}
|
|
|
return collections.stream().parallel().map(collection -> {
|
|
|
- CollectionDTO dto = toDTO(collection, false);
|
|
|
+ CollectionDTO dto = toDTO(collection, false, false);
|
|
|
if (!likes.isEmpty()) {
|
|
|
dto.setLiked(likes.stream().anyMatch(l -> l.getCollectionId().equals(collection.getId())));
|
|
|
}
|