Просмотр исходного кода

给抽问抽答统计接口增加缓存

simonlll месяцев назад: 2
Родитель
Сommit
d359e9621b

+ 21 - 0
airport-exam/src/main/java/com/sundot/airport/exam/controller/AccuracyStatisticsController.java

@@ -8,6 +8,7 @@ import com.sundot.airport.exam.dto.AccuracyStatisticsDTO;
8
 import com.sundot.airport.exam.dto.AccuracyStatisticsQueryDTO;
8
 import com.sundot.airport.exam.dto.AccuracyStatisticsQueryDTO;
9
 import com.sundot.airport.exam.service.IAccuracyStatisticsService;
9
 import com.sundot.airport.exam.service.IAccuracyStatisticsService;
10
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.cache.annotation.Cacheable;
11
 import org.springframework.security.access.prepost.PreAuthorize;
12
 import org.springframework.security.access.prepost.PreAuthorize;
12
 import org.springframework.web.bind.annotation.*;
13
 import org.springframework.web.bind.annotation.*;
13
 
14
 
@@ -28,6 +29,11 @@ public class AccuracyStatisticsController extends BaseController {
28
     /**
29
     /**
29
      * 获取当前用户或指定部门的正确率统计
30
      * 获取当前用户或指定部门的正确率统计
30
      */
31
      */
32
+    @Cacheable(
33
+            value = "statistics_data",
34
+            keyGenerator = "statisticsKeyGenerator",
35
+            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) || T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
36
+    )
31
     @GetMapping
37
     @GetMapping
32
     public AjaxResult getAccuracyStatistics(AccuracyStatisticsQueryDTO query) {
38
     public AjaxResult getAccuracyStatistics(AccuracyStatisticsQueryDTO query) {
33
         try {
39
         try {
@@ -42,6 +48,11 @@ public class AccuracyStatisticsController extends BaseController {
42
     /**
48
     /**
43
      * 获取指定用户的正确率统计
49
      * 获取指定用户的正确率统计
44
      */
50
      */
51
+    @Cacheable(
52
+            value = "statistics_data",
53
+            keyGenerator = "statisticsKeyGenerator",
54
+            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) || T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
55
+    )
45
     @GetMapping("/user/{userId}")
56
     @GetMapping("/user/{userId}")
46
     public AjaxResult getUserAccuracyStatistics(@PathVariable Long userId, AccuracyStatisticsQueryDTO query) {
57
     public AjaxResult getUserAccuracyStatistics(@PathVariable Long userId, AccuracyStatisticsQueryDTO query) {
47
         try {
58
         try {
@@ -56,6 +67,11 @@ public class AccuracyStatisticsController extends BaseController {
56
     /**
67
     /**
57
      * 获取聚合统计数据(管理员视角)
68
      * 获取聚合统计数据(管理员视角)
58
      */
69
      */
70
+    @Cacheable(
71
+            value = "statistics_data",
72
+            keyGenerator = "statisticsKeyGenerator",
73
+            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) || T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
74
+    )
59
     @PreAuthorize("@ss.hasPermi('exam:daily:statistics:admin') or @ss.hasRole('test') or @ss.hasRole('zhijianke')")
75
     @PreAuthorize("@ss.hasPermi('exam:daily:statistics:admin') or @ss.hasRole('test') or @ss.hasRole('zhijianke')")
60
     @GetMapping("/aggregate")
76
     @GetMapping("/aggregate")
61
     public AjaxResult getAggregateStatistics(AccuracyStatisticsQueryDTO query) {
77
     public AjaxResult getAggregateStatistics(AccuracyStatisticsQueryDTO query) {
@@ -71,6 +87,11 @@ public class AccuracyStatisticsController extends BaseController {
71
     /**
87
     /**
72
      * 获取首页正确率排名
88
      * 获取首页正确率排名
73
      */
89
      */
90
+    @Cacheable(
91
+            value = "statistics_data",
92
+            keyGenerator = "statisticsKeyGenerator",
93
+            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) || T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
94
+    )
74
     @GetMapping("/ranking")
95
     @GetMapping("/ranking")
75
     public AjaxResult getAccuracyRanking(BaseLargeScreenQueryParamDto dto) {
96
     public AjaxResult getAccuracyRanking(BaseLargeScreenQueryParamDto dto) {
76
         try {
97
         try {