wangqifan 3 лет назад
Родитель
Сommit
3822bf8cf3

+ 2 - 1
src/main/java/com/izouma/nineth/service/CacheService.java

@@ -4,6 +4,7 @@ import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 
 @Service
@@ -87,7 +88,7 @@ public class CacheService {
     }
 
     @CacheEvict(value = "subscribeCollectionList", key = "#now")
-    public void clearSubscribeCollectionList(LocalDateTime now) {
+    public void clearSubscribeCollectionList(LocalDate now) {
     }
 
 }

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

@@ -151,7 +151,7 @@ public class CollectionService {
         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());
+            cacheService.clearSubscribeCollectionList(LocalDate.now());
         }
         return record;
     }
@@ -172,7 +172,7 @@ 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());
+            cacheService.clearSubscribeCollectionList(LocalDate.now());
         }
         return record;
     }
@@ -611,7 +611,7 @@ public class CollectionService {
     }
 
     @Cacheable(value = "subscribeCollectionList", key = "#now")
-    public List<SubscribeListDTO> subscribeAll(LocalDateTime now) {
+    public List<SubscribeListDTO> subscribeAll(LocalDate now) {
         List<SubscribeListDTO> subscribeListDTOS = new ArrayList<>();
 //        Map<String, Object> resultMap = new HashMap<>();
 //

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

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

+ 6 - 1
src/main/java/com/izouma/nineth/web/SubscribeTimeController.java

@@ -1,5 +1,7 @@
 package com.izouma.nineth.web;
+
 import com.izouma.nineth.domain.SubscribeTime;
+import com.izouma.nineth.service.CacheService;
 import com.izouma.nineth.service.SubscribeTimeService;
 import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.exception.BusinessException;
@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.time.LocalDate;
 import java.util.List;
 
 @RestController
@@ -20,11 +23,13 @@ import java.util.List;
 @AllArgsConstructor
 public class SubscribeTimeController extends BaseController {
     private SubscribeTimeService subscribeTimeService;
-    private SubscribeTimeRepo subscribeTimeRepo;
+    private SubscribeTimeRepo    subscribeTimeRepo;
+    private CacheService         cacheService;
 
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
     public SubscribeTime save(@RequestBody SubscribeTime record) {
+        cacheService.clearSubscribeCollectionList(LocalDate.now());
         if (record.getId() != null) {
             SubscribeTime orig = subscribeTimeRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
             ObjUtils.merge(orig, record);