|
|
@@ -14,6 +14,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
14
|
14
|
import java.util.concurrent.TimeUnit;
|
|
15
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
16
|
16
|
import org.springframework.stereotype.Service;
|
|
|
17
|
+import com.alibaba.fastjson2.JSON;
|
|
|
18
|
+import com.alibaba.fastjson2.JSONObject;
|
|
17
|
19
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
18
|
20
|
import com.ruoyi.common.utils.StringUtils;
|
|
19
|
21
|
import com.ruoyi.web.modules.openstats.constant.OpenStatsConstants;
|
|
|
@@ -59,7 +61,7 @@ public class MallStatsOpenServiceImpl implements IMallStatsOpenService
|
|
59
|
61
|
{
|
|
60
|
62
|
int year = resolveStatYear(statYear);
|
|
61
|
63
|
ensureYearlyStatsCached(year);
|
|
62
|
|
- return redisCache.getCacheObject(StatsCacheKeys.categorySales(year));
|
|
|
64
|
+ return readCache(StatsCacheKeys.categorySales(year), CategorySalesVO.class);
|
|
63
|
65
|
}
|
|
64
|
66
|
|
|
65
|
67
|
@Override
|
|
|
@@ -67,7 +69,7 @@ public class MallStatsOpenServiceImpl implements IMallStatsOpenService
|
|
67
|
69
|
{
|
|
68
|
70
|
int year = resolveStatYear(statYear);
|
|
69
|
71
|
ensureYearlyStatsCached(year);
|
|
70
|
|
- return redisCache.getCacheObject(StatsCacheKeys.hotCategory(year));
|
|
|
72
|
+ return readCache(StatsCacheKeys.hotCategory(year), HotCategoryRankVO.class);
|
|
71
|
73
|
}
|
|
72
|
74
|
|
|
73
|
75
|
@Override
|
|
|
@@ -75,7 +77,7 @@ public class MallStatsOpenServiceImpl implements IMallStatsOpenService
|
|
75
|
77
|
{
|
|
76
|
78
|
int year = resolveStatYear(statYear);
|
|
77
|
79
|
ensureYearlyStatsCached(year);
|
|
78
|
|
- return redisCache.getCacheObject(StatsCacheKeys.orderTrend(year));
|
|
|
80
|
+ return readCache(StatsCacheKeys.orderTrend(year), OrderTrendVO.class);
|
|
79
|
81
|
}
|
|
80
|
82
|
|
|
81
|
83
|
@Override
|
|
|
@@ -83,7 +85,7 @@ public class MallStatsOpenServiceImpl implements IMallStatsOpenService
|
|
83
|
85
|
{
|
|
84
|
86
|
int year = resolveStatYear(statYear);
|
|
85
|
87
|
ensureYearlyStatsCached(year);
|
|
86
|
|
- return redisCache.getCacheObject(StatsCacheKeys.shopEntry(year));
|
|
|
88
|
+ return readCache(StatsCacheKeys.shopEntry(year), ShopEntryVO.class);
|
|
87
|
89
|
}
|
|
88
|
90
|
|
|
89
|
91
|
@Override
|
|
|
@@ -91,14 +93,14 @@ public class MallStatsOpenServiceImpl implements IMallStatsOpenService
|
|
91
|
93
|
{
|
|
92
|
94
|
int year = resolveStatYear(statYear);
|
|
93
|
95
|
ensureYearlyStatsCached(year);
|
|
94
|
|
- return redisCache.getCacheObject(StatsCacheKeys.regionRank(year));
|
|
|
96
|
+ return readCache(StatsCacheKeys.regionRank(year), RegionRankVO.class);
|
|
95
|
97
|
}
|
|
96
|
98
|
|
|
97
|
99
|
@Override
|
|
98
|
100
|
public ReviewWordCloudVO getReviewWordCloud()
|
|
99
|
101
|
{
|
|
100
|
102
|
ensureWordCloudCached();
|
|
101
|
|
- return redisCache.getCacheObject(StatsCacheKeys.wordCloud());
|
|
|
103
|
+ return readCache(StatsCacheKeys.wordCloud(), ReviewWordCloudVO.class);
|
|
102
|
104
|
}
|
|
103
|
105
|
|
|
104
|
106
|
@Override
|
|
|
@@ -107,12 +109,12 @@ public class MallStatsOpenServiceImpl implements IMallStatsOpenService
|
|
107
|
109
|
int year = resolveStatYear(statYear);
|
|
108
|
110
|
ensureOverviewStatsCached(year);
|
|
109
|
111
|
StatsOverviewVO overview = new StatsOverviewVO();
|
|
110
|
|
- overview.setCategorySales(redisCache.getCacheObject(StatsCacheKeys.categorySales(year)));
|
|
111
|
|
- overview.setHotCategoryRank(redisCache.getCacheObject(StatsCacheKeys.hotCategory(year)));
|
|
112
|
|
- overview.setOrderTrend(redisCache.getCacheObject(StatsCacheKeys.orderTrend(year)));
|
|
113
|
|
- overview.setShopEntry(redisCache.getCacheObject(StatsCacheKeys.shopEntry(year)));
|
|
114
|
|
- overview.setRegionRank(redisCache.getCacheObject(StatsCacheKeys.regionRank(year)));
|
|
115
|
|
- overview.setReviewWordCloud(redisCache.getCacheObject(StatsCacheKeys.wordCloud()));
|
|
|
112
|
+ overview.setCategorySales(readCache(StatsCacheKeys.categorySales(year), CategorySalesVO.class));
|
|
|
113
|
+ overview.setHotCategoryRank(readCache(StatsCacheKeys.hotCategory(year), HotCategoryRankVO.class));
|
|
|
114
|
+ overview.setOrderTrend(readCache(StatsCacheKeys.orderTrend(year), OrderTrendVO.class));
|
|
|
115
|
+ overview.setShopEntry(readCache(StatsCacheKeys.shopEntry(year), ShopEntryVO.class));
|
|
|
116
|
+ overview.setRegionRank(readCache(StatsCacheKeys.regionRank(year), RegionRankVO.class));
|
|
|
117
|
+ overview.setReviewWordCloud(readCache(StatsCacheKeys.wordCloud(), ReviewWordCloudVO.class));
|
|
116
|
118
|
return overview;
|
|
117
|
119
|
}
|
|
118
|
120
|
|
|
|
@@ -169,19 +171,34 @@ public class MallStatsOpenServiceImpl implements IMallStatsOpenService
|
|
169
|
171
|
|
|
170
|
172
|
private boolean isYearlyStatsCached(int year)
|
|
171
|
173
|
{
|
|
172
|
|
- for (String cacheKey : StatsCacheKeys.yearlyStatKeys(year))
|
|
173
|
|
- {
|
|
174
|
|
- if (redisCache.getCacheObject(cacheKey) == null)
|
|
175
|
|
- {
|
|
176
|
|
- return false;
|
|
177
|
|
- }
|
|
178
|
|
- }
|
|
179
|
|
- return true;
|
|
|
174
|
+ return readCache(StatsCacheKeys.categorySales(year), CategorySalesVO.class) != null
|
|
|
175
|
+ && readCache(StatsCacheKeys.hotCategory(year), HotCategoryRankVO.class) != null
|
|
|
176
|
+ && readCache(StatsCacheKeys.orderTrend(year), OrderTrendVO.class) != null
|
|
|
177
|
+ && readCache(StatsCacheKeys.shopEntry(year), ShopEntryVO.class) != null
|
|
|
178
|
+ && readCache(StatsCacheKeys.regionRank(year), RegionRankVO.class) != null;
|
|
180
|
179
|
}
|
|
181
|
180
|
|
|
182
|
181
|
private boolean isWordCloudCached()
|
|
183
|
182
|
{
|
|
184
|
|
- return redisCache.getCacheObject(StatsCacheKeys.wordCloud()) != null;
|
|
|
183
|
+ return readCache(StatsCacheKeys.wordCloud(), ReviewWordCloudVO.class) != null;
|
|
|
184
|
+ }
|
|
|
185
|
+
|
|
|
186
|
+ private <T> T readCache(String key, Class<T> type)
|
|
|
187
|
+ {
|
|
|
188
|
+ Object cached = redisCache.getCacheObject(key);
|
|
|
189
|
+ if (cached == null)
|
|
|
190
|
+ {
|
|
|
191
|
+ return null;
|
|
|
192
|
+ }
|
|
|
193
|
+ if (type.isInstance(cached))
|
|
|
194
|
+ {
|
|
|
195
|
+ return type.cast(cached);
|
|
|
196
|
+ }
|
|
|
197
|
+ if (cached instanceof JSONObject)
|
|
|
198
|
+ {
|
|
|
199
|
+ return ((JSONObject) cached).to(type);
|
|
|
200
|
+ }
|
|
|
201
|
+ return JSON.parseObject(JSON.toJSONString(cached), type);
|
|
185
|
202
|
}
|
|
186
|
203
|
|
|
187
|
204
|
private void refreshYearlyStatsCache(int year)
|