licailing 3 anos atrás
pai
commit
6d7fcc5cfb

+ 7 - 0
src/main/java/com/izouma/nineth/web/StatisticController.java

@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
 import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -69,4 +70,10 @@ public class StatisticController {
         int monthValue = LocalDate.now().getMonthValue();
         cacheService.clearTop(monthValue);
     }
+
+    @PreAuthorize("ADMIN")
+    @GetMapping("/clearWeekTop")
+    public void clearWeekTop(){
+        cacheService.clearWeekTop();
+    }
 }

+ 21 - 0
src/test/java/com/izouma/nineth/service/StatisticServiceTest.java

@@ -6,6 +6,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+
 
 @SpringBootTest
 @RunWith(SpringRunner.class)
@@ -13,6 +17,8 @@ public class StatisticServiceTest {
 
     @Autowired
     private StatisticService statisticService;
+    @Autowired
+    private CacheService     cacheService;
 
     @Test
     public void total() {
@@ -33,4 +39,19 @@ public class StatisticServiceTest {
     public void orderPriceTrend() {
         System.out.println(statisticService.orderPriceTrend(7));
     }
+
+    @Test
+    public void top() {
+        LocalDate now = LocalDate.now();
+        LocalDate endDate = now.minusDays(now.getDayOfWeek().getValue());
+        LocalDateTime start = LocalDateTime.of(endDate.minusDays(6), LocalTime.MIN);
+        System.out.println(start);
+        String top = statisticService.top(start, LocalDateTime.of(endDate, LocalTime.MAX), 50);
+        System.out.println(top);
+    }
+
+    @Test
+    public void test() {
+        cacheService.clearWeekTop();
+    }
 }