|
@@ -16,6 +16,9 @@ using TEAMModelOS.Service.Analysis.Interfaces;
|
|
|
using TEAMModelOS.Service.Models.Core;
|
|
|
using TEAMModelOS.Service.Models.Exam.Models;
|
|
|
using TEAMModelOS.SDK.Module.AzureCosmosDBV3;
|
|
|
+using System.Diagnostics;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.JsonHelper;
|
|
|
+using TEAMModelOS.SDK.Helper.Security.ShaHash;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.Analysis
|
|
|
{
|
|
@@ -26,6 +29,8 @@ namespace TEAMModelOS.Controllers.Analysis
|
|
|
|
|
|
private readonly IAzureCosmosDBV3Repository azureCosmosDBRepository;
|
|
|
private readonly IAchievementService achievementService;
|
|
|
+ private const string CacheCosmosPrefix = "cosmos:";
|
|
|
+ private const int timeoutSeconds = 3600;
|
|
|
public AchievementController(IAchievementService _achievementService, IAzureCosmosDBV3Repository _azureCosmosDBRepository)
|
|
|
{
|
|
|
azureCosmosDBRepository = _azureCosmosDBRepository;
|
|
@@ -35,9 +40,14 @@ namespace TEAMModelOS.Controllers.Analysis
|
|
|
[HttpPost("Achievement")]
|
|
|
public async Task<BaseJosnRPCResponse> FindExam(JosnRPCRequest<Dictionary<string, object>> request)
|
|
|
{
|
|
|
+ Stopwatch stopwatch = new Stopwatch();
|
|
|
+ stopwatch.Start(); // 开始监视代码运行时间
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
Console.WriteLine(DateTimeOffset.Now.Second);
|
|
|
List<ExamResult> exams = await azureCosmosDBRepository.FindByDict<ExamResult>(request.@params);
|
|
|
+ stopwatch.Stop(); // 停止监视
|
|
|
+ TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间
|
|
|
+ double milliseconds = timespan.TotalMilliseconds; // 总毫秒数
|
|
|
Dictionary<string, object> stuMap = new Dictionary<string, object>
|
|
|
{
|
|
|
{ "schoolCode", "Habook" }
|
|
@@ -1224,6 +1234,19 @@ namespace TEAMModelOS.Controllers.Analysis
|
|
|
|
|
|
List<ExamInfo> info = await azureCosmosDBRepository.FindByDict<ExamInfo>(request.@params);
|
|
|
builder.Data(info);
|
|
|
+ if (RedisHelper.Instance != null)
|
|
|
+ {
|
|
|
+ if (!RedisHelper.Exists(CacheCosmosPrefix + "FindExamInfo"))
|
|
|
+ {
|
|
|
+ await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamInfo",ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), info);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await RedisHelper.HSetAsync(CacheCosmosPrefix + "FindExamInfo", ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), info);
|
|
|
+ await RedisHelper.ExpireAsync(CacheCosmosPrefix + ShaHashHelper.GetSHA1(JsonNetHelper.ToJson(request.@params)), timeoutSeconds);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
return builder.build();
|
|
|
}
|