|
@@ -103,165 +103,174 @@ namespace IES.ExamServer.Controllers
|
|
|
EvaluationClient? evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x => x.id!.Equals(id) && x.shortCode!.Equals(shortCode));
|
|
|
if (teacher != null && evaluationClient!= null)
|
|
|
{
|
|
|
- string? CenterUrl = _configuration.GetValue<string>("ExamServer:CenterUrl");
|
|
|
- var client = _httpClientFactory.CreateClient();
|
|
|
- if (client.DefaultRequestHeaders.Contains(Constant._X_Auth_AuthToken))
|
|
|
+ var dataInfo= await GetEvaluationFromCenter(teacher, _configuration, _httpClientFactory, shortCode, evaluationClient.id!);
|
|
|
+ if (dataInfo.centerCode.Equals("200"))
|
|
|
{
|
|
|
- client.DefaultRequestHeaders.Remove(Constant._X_Auth_AuthToken);
|
|
|
- }
|
|
|
- client.DefaultRequestHeaders.Add(Constant._X_Auth_AuthToken, teacher.x_auth_token);
|
|
|
- HttpResponseMessage message = await client.PostAsJsonAsync($"{CenterUrl}/blob/sas-read", new { containerName = $"{evaluationClient.ownerId}" });
|
|
|
- string sas = string.Empty;
|
|
|
- string url = string.Empty;
|
|
|
- string cnt = string.Empty;
|
|
|
- if (message.IsSuccessStatusCode)
|
|
|
- {
|
|
|
- //url sas timeout name
|
|
|
- string content = await message.Content.ReadAsStringAsync();
|
|
|
- JsonNode? jsonNode = content.ToObject<JsonNode>();
|
|
|
- if (jsonNode != null)
|
|
|
+ string? CenterUrl = _configuration.GetValue<string>("ExamServer:CenterUrl");
|
|
|
+ var client = _httpClientFactory.CreateClient();
|
|
|
+ if (client.DefaultRequestHeaders.Contains(Constant._X_Auth_AuthToken))
|
|
|
{
|
|
|
- sas = $"{jsonNode["sas"]}";
|
|
|
- cnt = $"{jsonNode["name"]}";
|
|
|
- url = $"{jsonNode["url"]}";
|
|
|
+ client.DefaultRequestHeaders.Remove(Constant._X_Auth_AuthToken);
|
|
|
}
|
|
|
- }
|
|
|
- var httpClient = _httpClientFactory.CreateClient();
|
|
|
- string packagePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "package");
|
|
|
- string evaluationPath = Path.Combine(packagePath, evaluationClient.id!);
|
|
|
- //删除文件夹
|
|
|
- FileHelper.DeleteFolder(evaluationPath);
|
|
|
- string evaluationDataPath = Path.Combine(evaluationPath, "data");
|
|
|
- if (!Directory.Exists(evaluationDataPath))
|
|
|
- {
|
|
|
- Directory.CreateDirectory(evaluationDataPath);
|
|
|
- }
|
|
|
-
|
|
|
- string evaluationData = string.Empty;
|
|
|
- {
|
|
|
- //evaluation
|
|
|
- string evaluationUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/evaluation.json?{sas}";
|
|
|
- HttpResponseMessage dataMessage = await httpClient.GetAsync(evaluationUrl);
|
|
|
- if (dataMessage.IsSuccessStatusCode)
|
|
|
+ client.DefaultRequestHeaders.Add(Constant._X_Auth_AuthToken, teacher.x_auth_token);
|
|
|
+ HttpResponseMessage message = await client.PostAsJsonAsync($"{CenterUrl}/blob/sas-read", new { containerName = $"{evaluationClient.ownerId}" });
|
|
|
+ string sas = string.Empty;
|
|
|
+ string url = string.Empty;
|
|
|
+ string cnt = string.Empty;
|
|
|
+ if (message.IsSuccessStatusCode)
|
|
|
{
|
|
|
- var content = await dataMessage.Content.ReadAsStringAsync();
|
|
|
- evaluationData=content;
|
|
|
- string path_evaluation = Path.Combine(evaluationDataPath, "evaluation.json");
|
|
|
- await System.IO.File.WriteAllTextAsync(path_evaluation, content);
|
|
|
- successMsgs.Add("评测信息文件evaluation.json文件下载成功!");
|
|
|
+ //url sas timeout name
|
|
|
+ string content = await message.Content.ReadAsStringAsync();
|
|
|
+ JsonNode? jsonNode = content.ToObject<JsonNode>();
|
|
|
+ if (jsonNode != null)
|
|
|
+ {
|
|
|
+ sas = $"{jsonNode["sas"]}";
|
|
|
+ cnt = $"{jsonNode["name"]}";
|
|
|
+ url = $"{jsonNode["url"]}";
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ var httpClient = _httpClientFactory.CreateClient();
|
|
|
+ string packagePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "package");
|
|
|
+ string evaluationPath = Path.Combine(packagePath, evaluationClient.id!);
|
|
|
+ //删除文件夹
|
|
|
+ FileHelper.DeleteFolder(evaluationPath);
|
|
|
+ string evaluationDataPath = Path.Combine(evaluationPath, "data");
|
|
|
+ if (!Directory.Exists(evaluationDataPath))
|
|
|
{
|
|
|
- errorMsgs.Add("评测信息文件evaluation.json文件下载失败!");
|
|
|
+ Directory.CreateDirectory(evaluationDataPath);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- }
|
|
|
- {
|
|
|
- //source.json
|
|
|
- string sourceUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/source.json?{sas}";
|
|
|
- HttpResponseMessage dataMessage = await httpClient.GetAsync(sourceUrl);
|
|
|
- if (dataMessage.IsSuccessStatusCode)
|
|
|
+ string evaluationData = string.Empty;
|
|
|
{
|
|
|
- var content = await dataMessage.Content.ReadAsStringAsync();
|
|
|
- string path_source = Path.Combine(evaluationDataPath, "source.json");
|
|
|
- await System.IO.File.WriteAllTextAsync(path_source, content);
|
|
|
- successMsgs.Add("评测数据原始文件source.json文件下载成功!");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- errorMsgs.Add("评测数据原始文件source.json文件下载失败!");
|
|
|
+ //evaluation
|
|
|
+ string evaluationUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/evaluation.json?{sas}";
|
|
|
+ HttpResponseMessage dataMessage = await httpClient.GetAsync(evaluationUrl);
|
|
|
+ if (dataMessage.IsSuccessStatusCode)
|
|
|
+ {
|
|
|
+ var content = await dataMessage.Content.ReadAsStringAsync();
|
|
|
+ evaluationData=content;
|
|
|
+ string path_evaluation = Path.Combine(evaluationDataPath, "evaluation.json");
|
|
|
+ await System.IO.File.WriteAllTextAsync(path_evaluation, content);
|
|
|
+ successMsgs.Add("评测信息文件evaluation.json文件下载成功!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ errorMsgs.Add("评测信息文件evaluation.json文件下载失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
- }
|
|
|
- {
|
|
|
- //grouplist.json
|
|
|
- string grouplistUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/grouplist.json?{sas}";
|
|
|
- HttpResponseMessage groupListMessage = await httpClient.GetAsync(grouplistUrl);
|
|
|
- if (groupListMessage.IsSuccessStatusCode)
|
|
|
{
|
|
|
- var content = await groupListMessage.Content.ReadAsStringAsync();
|
|
|
- string path_groupList = Path.Combine(evaluationDataPath, "grouplist.json");
|
|
|
- await System.IO.File.WriteAllTextAsync(path_groupList, content);
|
|
|
- successMsgs.Add("评测名单grouplist.json文件下载成功!");
|
|
|
+ //source.json
|
|
|
+ string sourceUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/source.json?{sas}";
|
|
|
+ HttpResponseMessage dataMessage = await httpClient.GetAsync(sourceUrl);
|
|
|
+ if (dataMessage.IsSuccessStatusCode)
|
|
|
+ {
|
|
|
+ var content = await dataMessage.Content.ReadAsStringAsync();
|
|
|
+ string path_source = Path.Combine(evaluationDataPath, "source.json");
|
|
|
+ await System.IO.File.WriteAllTextAsync(path_source, content);
|
|
|
+ successMsgs.Add("评测数据原始文件source.json文件下载成功!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ errorMsgs.Add("评测数据原始文件source.json文件下载失败!");
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
{
|
|
|
- errorMsgs.Add("评测名单grouplist.json文件下载失败!");
|
|
|
+ //grouplist.json
|
|
|
+ string grouplistUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/grouplist.json?{sas}";
|
|
|
+ HttpResponseMessage groupListMessage = await httpClient.GetAsync(grouplistUrl);
|
|
|
+ if (groupListMessage.IsSuccessStatusCode)
|
|
|
+ {
|
|
|
+ var content = await groupListMessage.Content.ReadAsStringAsync();
|
|
|
+ string path_groupList = Path.Combine(evaluationDataPath, "grouplist.json");
|
|
|
+ await System.IO.File.WriteAllTextAsync(path_groupList, content);
|
|
|
+ successMsgs.Add("评测名单grouplist.json文件下载成功!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ errorMsgs.Add("评测名单grouplist.json文件下载失败!");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- {
|
|
|
- //下载试卷文件
|
|
|
- List<EvaluationExam>? evaluationExams = evaluationData.ToObject<JsonNode>()?["evaluationExams"]?.ToObject<List<EvaluationExam>>();
|
|
|
- foreach (var evaluationExam in evaluationExams!)
|
|
|
{
|
|
|
- foreach (var evaluationPaper in evaluationExam.papers)
|
|
|
+ //下载试卷文件
|
|
|
+ List<EvaluationExam>? evaluationExams = evaluationData.ToObject<JsonNode>()?["evaluationExams"]?.ToObject<List<EvaluationExam>>();
|
|
|
+ foreach (var evaluationExam in evaluationExams!)
|
|
|
{
|
|
|
- string path_paper = Path.Combine(evaluationPath, $"papers/{evaluationPaper.paperId}");
|
|
|
- if (!Directory.Exists(path_paper))
|
|
|
- {
|
|
|
- Directory.CreateDirectory(path_paper);
|
|
|
- }
|
|
|
- //最多开启10个线程并行下载
|
|
|
- var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = 20 };
|
|
|
- // 使用 Parallel.ForEachAsync 并行处理每个 blob
|
|
|
- await Parallel.ForEachAsync(evaluationPaper.blobs, parallelOptions, async (blob, cancellationToken) =>
|
|
|
+ foreach (var evaluationPaper in evaluationExam.papers)
|
|
|
{
|
|
|
- try
|
|
|
+ string path_paper = Path.Combine(evaluationPath, $"papers/{evaluationPaper.paperId}");
|
|
|
+ if (!Directory.Exists(path_paper))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(path_paper);
|
|
|
+ }
|
|
|
+ //最多开启10个线程并行下载
|
|
|
+ var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = 20 };
|
|
|
+ // 使用 Parallel.ForEachAsync 并行处理每个 blob
|
|
|
+ await Parallel.ForEachAsync(evaluationPaper.blobs, parallelOptions, async (blob, cancellationToken) =>
|
|
|
{
|
|
|
- // 下载 Blob 文件到本地
|
|
|
- HttpResponseMessage blobMessage = await httpClient.GetAsync($"{url}/{cnt}/{blob.path}?{sas}", cancellationToken);
|
|
|
- if (blobMessage.IsSuccessStatusCode)
|
|
|
+ try
|
|
|
{
|
|
|
- byte[] bytes = await blobMessage.Content.ReadAsByteArrayAsync(cancellationToken);
|
|
|
- string? extension = Path.GetExtension(blob.path);
|
|
|
- if (extension!=null)
|
|
|
+ // 下载 Blob 文件到本地
|
|
|
+ HttpResponseMessage blobMessage = await httpClient.GetAsync($"{url}/{cnt}/{blob.path}?{sas}", cancellationToken);
|
|
|
+ if (blobMessage.IsSuccessStatusCode)
|
|
|
{
|
|
|
- if (extension.Equals(extension.ToUpper()))
|
|
|
- {
|
|
|
- string? fileNameWithoutExtension = Path.GetFileNameWithoutExtension(blob.path);
|
|
|
- await System.IO.File.WriteAllBytesAsync(Path.Combine(path_paper, $"{fileNameWithoutExtension!}_1{extension}"), bytes, cancellationToken);
|
|
|
- }
|
|
|
- else
|
|
|
+ byte[] bytes = await blobMessage.Content.ReadAsByteArrayAsync(cancellationToken);
|
|
|
+ string? extension = Path.GetExtension(blob.path);
|
|
|
+ if (extension!=null)
|
|
|
{
|
|
|
- string? fileName = Path.GetFileName(blob.path);
|
|
|
- await System.IO.File.WriteAllBytesAsync(Path.Combine(path_paper, fileName!), bytes, cancellationToken);
|
|
|
+ if (extension.Equals(extension.ToUpper()))
|
|
|
+ {
|
|
|
+ string? fileNameWithoutExtension = Path.GetFileNameWithoutExtension(blob.path);
|
|
|
+ await System.IO.File.WriteAllBytesAsync(Path.Combine(path_paper, $"{fileNameWithoutExtension!}_1{extension}"), bytes, cancellationToken);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ string? fileName = Path.GetFileName(blob.path);
|
|
|
+ await System.IO.File.WriteAllBytesAsync(Path.Combine(path_paper, fileName!), bytes, cancellationToken);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ string? error = await blobMessage.Content.ReadAsStringAsync(cancellationToken);
|
|
|
+ errorMsgs.Add($"{evaluationExam.subjectName},{evaluationPaper.paperName},{blob.path}文件下载失败,{blobMessage.StatusCode},{error}");
|
|
|
+ // Console.WriteLine($"Error downloading {blob.path},{blobMessage.StatusCode},{error}");
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- string? error = await blobMessage.Content.ReadAsStringAsync(cancellationToken);
|
|
|
- errorMsgs.Add($"{evaluationExam.subjectName},{evaluationPaper.paperName},{blob.path}文件下载失败,{blobMessage.StatusCode},{error}");
|
|
|
- // Console.WriteLine($"Error downloading {blob.path},{blobMessage.StatusCode},{error}");
|
|
|
+ errorMsgs.Add($"{evaluationExam.subjectName},{evaluationPaper.paperName},{blob.path}文件下载错误,{ex.Message}");
|
|
|
+ // 处理异常
|
|
|
+ //Console.WriteLine($"Error downloading {blob.path}: {ex.Message}");
|
|
|
}
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- errorMsgs.Add($"{evaluationExam.subjectName},{evaluationPaper.paperName},{blob.path}文件下载错误,{ex.Message}");
|
|
|
- // 处理异常
|
|
|
- //Console.WriteLine($"Error downloading {blob.path}: {ex.Message}");
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- (successMsgs, errorMsgs) = await ManageService.CheckFile(evaluationClient, successMsgs, errorMsgs, _signalRExamServerHub, _memoryCache, _logger, deviceId, evaluationPath);
|
|
|
- //下载完成后,对数据进行检查,然后在加密压缩。
|
|
|
- string zipPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "zip");
|
|
|
- if (!Directory.Exists(zipPath))
|
|
|
- {
|
|
|
- Directory.CreateDirectory(zipPath);
|
|
|
- }
|
|
|
- string zipFilePath = Path.Combine(zipPath, $"{evaluationClient.id}-{evaluationClient.blobHash}.zip");
|
|
|
- var zipInfo = ZipHelper.CreatePasswordProtectedZip(evaluationPath, zipFilePath, evaluationClient.openCode!);
|
|
|
- if (zipInfo.res)
|
|
|
- {
|
|
|
- successMsgs.Add("评测数据压缩包创建成功!");
|
|
|
+ (successMsgs, errorMsgs) = await ManageService.CheckFile(evaluationClient, successMsgs, errorMsgs, _signalRExamServerHub, _memoryCache, _logger, deviceId, evaluationPath);
|
|
|
+ //下载完成后,对数据进行检查,然后在加密压缩。
|
|
|
+ string zipPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "zip");
|
|
|
+ if (!Directory.Exists(zipPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(zipPath);
|
|
|
+ }
|
|
|
+ string zipFilePath = Path.Combine(zipPath, $"{evaluationClient.id}-{evaluationClient.blobHash}.zip");
|
|
|
+ var zipInfo = ZipHelper.CreatePasswordProtectedZip(evaluationPath, zipFilePath, evaluationClient.openCode!);
|
|
|
+ if (zipInfo.res)
|
|
|
+ {
|
|
|
+ successMsgs.Add("评测数据压缩包创建成功!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ errorMsgs.Add("评测数据压缩包创建失败!");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
else {
|
|
|
- errorMsgs.Add("评测数据压缩包创建失败!");
|
|
|
+ errorMsgs.Add($"云端数据检测结果:{dataInfo. centerMsg},状态:{dataInfo. centerCode}");
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -431,46 +440,7 @@ namespace IES.ExamServer.Controllers
|
|
|
Teacher? teacher = _liteDBFactory.GetLiteDatabase().GetCollection<Teacher>().FindOne(x => x.id!.Equals(token.id));
|
|
|
if (teacher != null)
|
|
|
{
|
|
|
- string? CenterUrl = _configuration.GetValue<string>("ExamServer:CenterUrl");
|
|
|
- var client = _httpClientFactory.CreateClient();
|
|
|
- if (client.DefaultRequestHeaders.Contains(Constant._X_Auth_AuthToken))
|
|
|
- {
|
|
|
- client.DefaultRequestHeaders.Remove(Constant._X_Auth_AuthToken);
|
|
|
- }
|
|
|
- client.DefaultRequestHeaders.Add(Constant._X_Auth_AuthToken, teacher.x_auth_token);
|
|
|
- try
|
|
|
- {
|
|
|
- HttpResponseMessage message = await client.PostAsJsonAsync($"{CenterUrl}/evaluation-sync/find-sync-info", new { shortCode, evaluationId });
|
|
|
- if (message.IsSuccessStatusCode)
|
|
|
- {
|
|
|
- string content = await message.Content.ReadAsStringAsync();
|
|
|
- JsonNode? jsonNode = content.ToObject<JsonNode>();
|
|
|
- if (jsonNode != null)
|
|
|
- {
|
|
|
- centerCode = $"{jsonNode["code"]}";
|
|
|
- centerMsg = $"{jsonNode["msg"]}";
|
|
|
- if ($"{jsonNode["code"]}".Equals("200"))
|
|
|
- {
|
|
|
- evaluationCloud = jsonNode["evaluation"]?.ToObject<EvaluationClient>();
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- centerCode = "500";
|
|
|
- centerMsg = "数据转换异常";
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- centerCode = $"{message.StatusCode}";
|
|
|
- centerMsg = "数据中心访问异常";
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- centerCode = $"500";
|
|
|
- centerMsg = $"数据中心访问异常:{ex.Message}";
|
|
|
- }
|
|
|
+ (evaluationCloud, centerCode, centerMsg)= await ManageService.GetEvaluationFromCenter(teacher, _configuration,_httpClientFactory,shortCode,evaluationId);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -531,7 +501,38 @@ namespace IES.ExamServer.Controllers
|
|
|
result = checkDataResult
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 获取当前评测的开考设置信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="json"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("list-evaluation-round")]
|
|
|
+ [AuthToken("admin", "teacher", "visitor")]
|
|
|
+ public IActionResult ListEvaluationRound(JsonNode json)
|
|
|
+ {
|
|
|
+ string evaluationId = $"{json["evaluationId"]}";
|
|
|
+ string openCode = $"{json["openCode"]}";
|
|
|
+ string shortCode = $"{json["shortCode"]}";
|
|
|
+ EvaluationClient? evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>()
|
|
|
+ .FindOne(x => x.id!.Equals(evaluationId) && x.shortCode!.Equals(shortCode) && x.openCode!.Equals(openCode));
|
|
|
+ if (evaluationClient!=null)
|
|
|
+ {
|
|
|
+ IEnumerable<EvaluationRoundSetting>? settings = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationRoundSetting>().Find(x => x.evaluationId!.Equals(evaluationClient.id)).OrderByDescending(x => x.activate).ThenByDescending(x => x.startline).ThenByDescending(x => x.createTime);
|
|
|
+ if (settings.IsNotEmpty())
|
|
|
+ {
|
|
|
+ return Ok(new { code = 200, msg = "OK", settings = settings });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { code = 2, msg = "未设置开考信息!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { code = 1, msg = "未找到评测信息!" });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 获取当前评测的开考设置信息
|
|
|
/// </summary>
|
|
@@ -544,16 +545,13 @@ namespace IES.ExamServer.Controllers
|
|
|
string evaluationId = $"{json["evaluationId"]}";
|
|
|
string openCode = $"{json["openCode"]}";
|
|
|
string shortCode = $"{json["shortCode"]}";
|
|
|
+ string settingId = $"{json["settingId"]}";
|
|
|
EvaluationClient? evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>()
|
|
|
.FindOne(x => x.id!.Equals(evaluationId) && x.shortCode!.Equals(shortCode) && x.openCode!.Equals(openCode));
|
|
|
EvaluationRoundSetting? setting = null;
|
|
|
if (evaluationClient!=null)
|
|
|
{
|
|
|
- if (!string.IsNullOrWhiteSpace(evaluationClient.roundId))
|
|
|
- {
|
|
|
- setting = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationRoundSetting>().FindOne(x => x.id!.Equals(evaluationClient.roundId));
|
|
|
- }
|
|
|
-
|
|
|
+ setting = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationRoundSetting>().FindOne(x =>x.id!.Equals(settingId) && x.evaluationId!.Equals(evaluationClient.id));
|
|
|
if (setting!=null)
|
|
|
{
|
|
|
IEnumerable<EvaluationStudentResult>? results = null;
|
|
@@ -609,32 +607,29 @@ namespace IES.ExamServer.Controllers
|
|
|
&& !string.IsNullOrWhiteSpace(x.openCode) && x.openCode.Equals(openCode) );
|
|
|
if (evaluationClient!=null)
|
|
|
{
|
|
|
- IEnumerable<EvaluationClient> evaluationClients = collection.Find(x => x.activate==1);
|
|
|
- if (evaluationClients != null && evaluationClients.Count() > 0)
|
|
|
+ IEnumerable<EvaluationRoundSetting> settings = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationRoundSetting>().Find(x => x.evaluationId!.Equals(evaluationClient.id));
|
|
|
+ if (settings != null && settings.Count() > 0)
|
|
|
{
|
|
|
- var datas = evaluationClients.ToList();
|
|
|
- foreach (EvaluationClient item in datas)
|
|
|
+ var datas = settings.ToList();
|
|
|
+ foreach (EvaluationRoundSetting item in datas)
|
|
|
{
|
|
|
item.activate = 0;
|
|
|
}
|
|
|
- collection.Upsert(datas);
|
|
|
+ _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationRoundSetting>().Upsert(datas);
|
|
|
}
|
|
|
/// 判断是否包含所有分组
|
|
|
bool isAllContained = setting.groupList.All(x => evaluationClient.grouplist.Any(y => y.id == x.id));
|
|
|
if (isAllContained && evaluationClient.grouplist.IsNotEmpty())
|
|
|
{
|
|
|
- evaluationClient.countdownType = setting.countdownType;
|
|
|
- evaluationClient.countdown = setting.countdown;
|
|
|
- evaluationClient.deadline = setting.deadline;
|
|
|
- evaluationClient.startline = setting.startline;
|
|
|
- evaluationClient.activate = setting.activate;
|
|
|
+
|
|
|
//增加排序,保证id的唯一性
|
|
|
setting.id=ShaHashHelper.GetSHA1($"{evaluationClient.id}_{string.Join("", setting.groupList.Select(x => x.id)).OrderBy(x => x)}");
|
|
|
setting.createTime= DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
|
|
- evaluationClient.roundId = setting.id;
|
|
|
+
|
|
|
_liteDBFactory.GetLiteDatabase().GetCollection<EvaluationRoundSetting>().Upsert(setting);
|
|
|
_liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().Upsert(evaluationClient);
|
|
|
/// 分配试卷
|
|
|
+
|
|
|
var (roundStudentPapers, members, results,code,msg) = AssignStudentPaper(evaluationClient, setting);
|
|
|
return Ok(new { code = code, msg =msg , setting, results });
|
|
|
}
|
|
@@ -661,9 +656,7 @@ namespace IES.ExamServer.Controllers
|
|
|
[AuthToken("admin", "teacher", "visitor")]
|
|
|
public IActionResult ListLocalEvaluation(JsonNode json)
|
|
|
{
|
|
|
-
|
|
|
- IEnumerable<EvaluationClient>? evaluationClients = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindAll().OrderByDescending(x=>x.activate).ThenByDescending(x=>x.stime);
|
|
|
-
|
|
|
+ IEnumerable<EvaluationClient>? evaluationClients = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindAll().OrderByDescending(x=>x.stime);
|
|
|
if (evaluationClients != null)
|
|
|
{
|
|
|
var result = evaluationClients.Select(client =>
|
|
@@ -694,7 +687,8 @@ namespace IES.ExamServer.Controllers
|
|
|
/// <returns></returns>
|
|
|
//[HttpPost("assign-student-paper")]
|
|
|
//[AuthToken("admin", "teacher", "visitor")]
|
|
|
- private (List<EvaluationStudentPaper> roundStudentPapers, List<EvaluationMember> members, List<EvaluationStudentResult> results, int code, string msg) AssignStudentPaper(EvaluationClient evaluationClient, EvaluationRoundSetting setting)
|
|
|
+ private (List<EvaluationStudentPaper> roundStudentPapers, List<EvaluationMember> members, List<EvaluationStudentResult> results, int code, string msg)
|
|
|
+ AssignStudentPaper(EvaluationClient evaluationClient, EvaluationRoundSetting setting)
|
|
|
{
|
|
|
int code = 200;
|
|
|
string msg = string.Empty;
|
|
@@ -853,10 +847,10 @@ namespace IES.ExamServer.Controllers
|
|
|
foreach (var studentPaper in studentPapers)
|
|
|
{
|
|
|
string subjectResultId = ShaHashHelper.GetSHA1(evaluationClient.id+studentPaper.examId+studentPaper.subjectId+member.id);
|
|
|
- var subjectResult = studentResult.subjectResults.Find(x => x.id!.Equals(subjectResultId));
|
|
|
+ var subjectResult = studentResult.subjectResults.Where(x => x.id!.Equals(subjectResultId)).FirstOrDefault();
|
|
|
if (subjectResult==null)
|
|
|
{
|
|
|
- studentResult.subjectResults.Add(new EvaluationSubjectResult()
|
|
|
+ subjectResult= new EvaluationSubjectResult()
|
|
|
{
|
|
|
id = ShaHashHelper.GetSHA1(evaluationClient.id+studentPaper.examId+studentPaper.subjectId+member.id),
|
|
|
evaluationId = studentPaper.evaluationId,
|
|
@@ -866,18 +860,20 @@ namespace IES.ExamServer.Controllers
|
|
|
subjectName = studentPaper.subjectName,
|
|
|
paperId = studentPaper.paperId,
|
|
|
paperName = studentPaper.paperName,
|
|
|
- });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- subjectResult.evaluationId = studentPaper.evaluationId;
|
|
|
- subjectResult.examId = studentPaper.examId;
|
|
|
- subjectResult.examName = studentPaper.examName;
|
|
|
- subjectResult.subjectId = studentPaper.subjectId;
|
|
|
- subjectResult.subjectName = studentPaper.subjectName;
|
|
|
- subjectResult.paperId = studentPaper.paperId;
|
|
|
- subjectResult.paperName = studentPaper.paperName;
|
|
|
+ };
|
|
|
+ //studentResult.subjectResults.Add();
|
|
|
}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // subjectResult.evaluationId = studentPaper.evaluationId;
|
|
|
+ // subjectResult.examId = studentPaper.examId;
|
|
|
+ // subjectResult.examName = studentPaper.examName;
|
|
|
+ // subjectResult.subjectId = studentPaper.subjectId;
|
|
|
+ // subjectResult.subjectName = studentPaper.subjectName;
|
|
|
+ // subjectResult.paperId = studentPaper.paperId;
|
|
|
+ // subjectResult.paperName = studentPaper.paperName;
|
|
|
+ //}
|
|
|
+ studentResult.subjectResults.Add(subjectResult);
|
|
|
}
|
|
|
}
|
|
|
//_liteDBFactory.GetLiteDatabase().GetCollection<EvaluationStudentResult>().Upsert(studentResult);
|
|
@@ -889,10 +885,10 @@ namespace IES.ExamServer.Controllers
|
|
|
}
|
|
|
if (results.Count>0)
|
|
|
{
|
|
|
- foreach (var item in results)
|
|
|
- {
|
|
|
- item.subjectResults= item.subjectResults.DistinctBy(x => x.id).ToList();
|
|
|
- }
|
|
|
+ //foreach (var item in results)
|
|
|
+ //{
|
|
|
+ // item.subjectResults= item.subjectResults.DistinctBy(x => x.id).ToList();
|
|
|
+ //}
|
|
|
_liteDBFactory.GetLiteDatabase().GetCollection<EvaluationStudentResult>().Upsert(results);
|
|
|
}
|
|
|
}
|