数据进行缓存
This commit is contained in:
parent
78c1a6a44a
commit
4a25704e8f
|
@ -60,7 +60,7 @@ public class CenterController {
|
|||
* 依据学院和年级获取四级和六级通过数据
|
||||
*/
|
||||
@GetMapping(value = "/getData")
|
||||
@Cacheable(value = "getData", key = "'getData' + #college+#major+#entrydate")
|
||||
// @Cacheable(cacheNames = "getData", key = "#college+#major+#entrydate")
|
||||
public Result<JSONObject> getData(@RequestParam("college") String college, @RequestParam("major") String major, @RequestParam("entrydate") String entrydate) {
|
||||
return centerService.getData(college, major, entrydate);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -184,6 +185,11 @@ public class CenterServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implement
|
|||
|
||||
@Override
|
||||
public Result<JSONObject> getData(String college, String major, String entryDate) {
|
||||
//判断是否存在缓存
|
||||
String key = "getData:"+college + major + entryDate;
|
||||
if (Boolean.TRUE.equals(redisTemplate.hasKey(key))) {
|
||||
return Result.ok((JSONObject) redisTemplate.opsForValue().get(key));
|
||||
}
|
||||
//获取所有batch
|
||||
JSONObject batch = getBatch();
|
||||
JSONArray batchsArray = batch.getJSONArray("batches");
|
||||
|
@ -324,6 +330,8 @@ public class CenterServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implement
|
|||
result.put("totalName", totalName);//总人数
|
||||
result.put("passNumber",passNumber[n - 1]);//累计通过人数
|
||||
result.put("passRate", df.format((passNumber[n - 1] / (double) allStudent)));//累计通过率
|
||||
// 将数据存入缓存
|
||||
redisTemplate.opsForValue().set(key, result, Duration.ofDays(7));
|
||||
return Result.ok(result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue