ouyang il y a 3 ans
Parent
commit
ff1e702c65

+ 2 - 1
src/main/java/com/izouma/nineth/dto/SubscribeListDTO.java

@@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
 
 import java.time.LocalDateTime;
 import java.util.List;
+import java.util.Map;
 
 @Data
 @Builder
@@ -14,5 +15,5 @@ import java.util.List;
 @NoArgsConstructor
 public class SubscribeListDTO {
     private LocalDateTime       dateTime;
-    private List<CollectionDTO> collectionDTOS;
+    private Map<LocalDateTime,List<CollectionDTO>> collectionDTOS;
 }

+ 23 - 17
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -618,9 +618,9 @@ public class CollectionService {
     }
 
     @Cacheable(value = "subscribeCollectionList", key = "#now.hashCode()")
-    public Map<LocalDate, List<SubscribeListDTO>> subscribeAll(LocalDate now) {
-
+    public List<SubscribeListDTO> subscribeAll(LocalDate now) {
         List<SubscribeListDTO> subscribeListDTOS = new ArrayList<>();
+        Map<LocalDateTime,List<CollectionDTO>> map = new HashMap<>();
 //        Map<String, Object> resultMap = new HashMap<>();
 //        resultMap.put("subList", subscribeListDTOS);
 //        resultMap.put("notSubscribedIds", dtoPage.getContent().stream().filter(dto -> !dto.isSubscribed())
@@ -656,23 +656,29 @@ public class CollectionService {
             PageWrapper<Collection> dtoPage = new PageWrapper<>(page.getContent(), page.getPageable().getPageNumber(),
                     page.getPageable().getPageSize(), page.getTotalElements());
             Page<CollectionDTO> pageNew = toDTO(dtoPage.toPage());
-//            LocalDateTime dateTime;
-//            if (pageNew.getTotalElements() > 0){
-//                dateTime = pageNew.getContent().get(0).getStartTime();
-//                subscribeListDTOS
-//                        .add(SubscribeListDTO.builder().dateTime(dateTime)
-//                                .collectionDTOS(pageNew.getContent())
-//                                .build());
-//            }
             if (CollectionUtils.isNotEmpty(pageNew.getContent())){
-                subscribeListDTOS
-                        .add(SubscribeListDTO.builder().dateTime(subscribeTime.getStart())
-                                .collectionDTOS(pageNew.getContent())
-                                .build());
+                LocalDateTime dateTime = null;
+                List<CollectionDTO>  collectionDtoList = new ArrayList<>();
+                for (CollectionDTO collectionDTO : pageNew.getContent()) {
+                    if (dateTime == null) {
+                        dateTime = collectionDTO.getStartTime();
+                        collectionDtoList.add(collectionDTO);
+                    }else if (dateTime.equals(collectionDTO.getStartTime())){
+                        collectionDtoList.add(collectionDTO);
+                    }else {
+                        map.put(dateTime,collectionDtoList);
+                        dateTime = collectionDTO.getStartTime();
+                        collectionDtoList.clear();
+                        collectionDtoList.add(collectionDTO);
+                    }
+                }
+                map.put(dateTime,collectionDtoList);
+                subscribeListDTOS.add(SubscribeListDTO.builder()
+                        .dateTime(pageNew.getContent().get(0).getStartTime())
+                        .collectionDTOS(map)
+                        .build());
             }
         });
-//        resultMap.put("notSubscribedIds", );
-        return subscribeListDTOS.stream()
-                .collect(Collectors.groupingBy(subscribeListDTO -> subscribeListDTO.getDateTime().toLocalDate()));
+        return subscribeListDTOS;
     }
 }

+ 2 - 1
src/main/java/com/izouma/nineth/web/CollectionController.java

@@ -177,7 +177,8 @@ public class CollectionController extends BaseController {
 
     @GetMapping("/subscribeList")
     public Map<String, Object> subscribeList() {
-        Map<LocalDate, List<SubscribeListDTO>> dtoPage = collectionService.subscribeAll(LocalDate.now());
+        List<SubscribeListDTO> dtoPage = collectionService.subscribeAll(LocalDate.now());
+        List<SubscribeListDTO> subscribeListDTOS = new ArrayList<>();
         Map<String, Object> resultMap = new HashMap<>();
         resultMap.put("subList", dtoPage);
 //        resultMap.put("notSubscribedIds", dtoPage.getContent().stream().filter(dto -> !dto.isSubscribed())