|
|
@@ -41,6 +41,7 @@ import javax.annotation.PostConstruct;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.transaction.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
@@ -71,6 +72,7 @@ public class CollectionService {
|
|
|
private PointRecordRepo pointRecordRepo;
|
|
|
private SubscribeRepo subscribeRepo;
|
|
|
private FollowRepo followRepo;
|
|
|
+ private SubscribeTimeRepo subscribeTimeRepo;
|
|
|
|
|
|
private final Map<Long, ScheduledFuture<?>> tasks = new HashMap<>();
|
|
|
|
|
|
@@ -148,6 +150,9 @@ public class CollectionService {
|
|
|
// onShelfTask(record);
|
|
|
redisTemplate.opsForValue().set(RedisKeys.COLLECTION_STOCK + record.getId(), record.getStock());
|
|
|
redisTemplate.opsForValue().set(RedisKeys.COLLECTION_SALE + record.getId(), record.getSale());
|
|
|
+ if (record.getSource().equals(CollectionSource.OFFICIAL) & record.isOnShelf()) {
|
|
|
+ cacheService.clearSubscribeCollectionList(LocalDate.now().atStartOfDay());
|
|
|
+ }
|
|
|
return record;
|
|
|
}
|
|
|
|
|
|
@@ -166,6 +171,9 @@ public class CollectionService {
|
|
|
|
|
|
record = collectionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
// onShelfTask(record);
|
|
|
+ if (record.getSource().equals(CollectionSource.OFFICIAL) & record.isOnShelf()) {
|
|
|
+ cacheService.clearSubscribeCollectionList(LocalDate.now().atStartOfDay());
|
|
|
+ }
|
|
|
return record;
|
|
|
}
|
|
|
|
|
|
@@ -602,27 +610,51 @@ public class CollectionService {
|
|
|
return dtos;
|
|
|
}
|
|
|
|
|
|
- @Cacheable(value = "subscribeCollectionList", key = "#pageQuery.hashCode()")
|
|
|
- public PageWrapper<Collection> subscribeAll(PageQuery pageQuery) {
|
|
|
- pageQuery.getQuery().put("del", false);
|
|
|
- Specification<Collection> specification = JpaUtils.toSpecification(pageQuery, Collection.class);
|
|
|
- PageRequest pageRequest = JpaUtils.toPageRequest(pageQuery);
|
|
|
- if (pageRequest.getSort().stream().noneMatch(order -> order.getProperty().equals("purchaseTime"))) {
|
|
|
- pageRequest = PageRequest.of(pageRequest.getPageNumber(), pageQuery.getSize(),
|
|
|
- pageRequest.getSort().and(Sort.by("purchaseTime").ascending()));
|
|
|
- }
|
|
|
+ @Cacheable(value = "subscribeCollectionList", key = "#now")
|
|
|
+ public List<SubscribeListDTO> subscribeAll(LocalDateTime now) {
|
|
|
+ List<SubscribeListDTO> subscribeListDTOS = new ArrayList<>();
|
|
|
+// Map<String, Object> resultMap = new HashMap<>();
|
|
|
+//
|
|
|
+// resultMap.put("subList", subscribeListDTOS);
|
|
|
+// resultMap.put("notSubscribedIds", dtoPage.getContent().stream().filter(dto -> !dto.isSubscribed())
|
|
|
+// .map(CollectionDTO::getId).collect(Collectors
|
|
|
+// .toList()));
|
|
|
+ List<SubscribeTime> subscribeTimes = subscribeTimeRepo
|
|
|
+ .findAllByStartAfterOrderBySort(LocalDate.now().atStartOfDay());
|
|
|
+ subscribeTimes.forEach(subscribeTime -> {
|
|
|
+ PageQuery pageQuery = new PageQuery();
|
|
|
+ pageQuery.setPage(0);
|
|
|
+ pageQuery.setSize(10000);
|
|
|
+ pageQuery.getQuery().put("del", false);
|
|
|
+ Specification<Collection> specification = JpaUtils.toSpecification(pageQuery, Collection.class);
|
|
|
+ PageRequest pageRequest = JpaUtils.toPageRequest(pageQuery);
|
|
|
+ if (pageRequest.getSort().stream().noneMatch(order -> order.getProperty().equals("startTime"))) {
|
|
|
+ pageRequest = PageRequest.of(pageRequest.getPageNumber(), pageQuery.getSize(),
|
|
|
+ pageRequest.getSort().and(Sort.by("startTime").ascending()));
|
|
|
+ }
|
|
|
|
|
|
- specification = specification.and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
- List<Predicate> and = new ArrayList<>();
|
|
|
- List<SubscribeStatus> statuses = new ArrayList<>();
|
|
|
- statuses.add(SubscribeStatus.NOT_STARTED);
|
|
|
- statuses.add(SubscribeStatus.ONGOING);
|
|
|
- and.add(root.get("subscribeStatus").in(statuses));
|
|
|
- and.add(criteriaBuilder.equal(root.get("source"), CollectionSource.OFFICIAL));
|
|
|
- return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ specification = specification.and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = new ArrayList<>();
|
|
|
+ List<SubscribeStatus> statuses = new ArrayList<>();
|
|
|
+ statuses.add(SubscribeStatus.NOT_STARTED);
|
|
|
+ statuses.add(SubscribeStatus.ONGOING);
|
|
|
+ and.add(root.get("subscribeStatus").in(statuses));
|
|
|
+ and.add(criteriaBuilder.equal(root.get("onShelf"), true));
|
|
|
+ and.add(criteriaBuilder.equal(root.get("source"), CollectionSource.OFFICIAL));
|
|
|
+ and.add(criteriaBuilder
|
|
|
+ .between(root.get("startTime"), subscribeTime.getStart(), subscribeTime.getEnd()));
|
|
|
+ return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ });
|
|
|
+ Page<Collection> page = collectionRepo.findAll(specification, pageRequest);
|
|
|
+ PageWrapper<Collection> dtoPage = new PageWrapper<>(page.getContent(), page.getPageable().getPageNumber(),
|
|
|
+ page.getPageable().getPageSize(), page.getTotalElements());
|
|
|
+ Page<CollectionDTO> pageNew = toDTO(dtoPage.toPage());
|
|
|
+ subscribeListDTOS
|
|
|
+ .add(SubscribeListDTO.builder().dateTime(subscribeTime.getStart())
|
|
|
+ .collectionDTOS(pageNew.getContent())
|
|
|
+ .build());
|
|
|
});
|
|
|
- Page<Collection> page = collectionRepo.findAll(specification, pageRequest);
|
|
|
- return new PageWrapper<>(page.getContent(), page.getPageable().getPageNumber(),
|
|
|
- page.getPageable().getPageSize(), page.getTotalElements());
|
|
|
+// resultMap.put("notSubscribedIds", );
|
|
|
+ return subscribeListDTOS;
|
|
|
}
|
|
|
}
|