|
@@ -12,6 +12,7 @@ using Microsoft.AspNetCore.SignalR;
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using System;
|
|
|
+using System.Diagnostics.Eventing.Reader;
|
|
|
using System.Linq.Expressions;
|
|
|
using System.Net.Http;
|
|
|
using System.Net.Http.Json;
|
|
@@ -27,7 +28,7 @@ namespace IES.ExamServer.Controllers
|
|
|
{
|
|
|
[ApiController]
|
|
|
[Route("manage")]
|
|
|
- public class ManageController:BaseController
|
|
|
+ public class ManageController : BaseController
|
|
|
{
|
|
|
private readonly IConfiguration _configuration;
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
@@ -38,7 +39,7 @@ namespace IES.ExamServer.Controllers
|
|
|
private readonly int DelayMicro = 10;//微观数据延迟
|
|
|
private readonly int DelayMacro = 100;//宏观数据延迟
|
|
|
private readonly IHubContext<SignalRExamServerHub> _signalRExamServerHub;
|
|
|
- public ManageController(LiteDBFactory liteDBFactory,ILogger<ManageController> logger, IConfiguration configuration,
|
|
|
+ public ManageController(LiteDBFactory liteDBFactory, ILogger<ManageController> logger, IConfiguration configuration,
|
|
|
IHttpClientFactory httpClientFactory, IMemoryCache memoryCache, CenterServiceConnectionService connectionService, IHubContext<SignalRExamServerHub> signalRExamServerHub)
|
|
|
{
|
|
|
_logger = logger;
|
|
@@ -51,7 +52,7 @@ namespace IES.ExamServer.Controllers
|
|
|
}
|
|
|
///通过线上回传数据需要鉴权验证等操作。
|
|
|
///通过离线包回传数据需要加密操作
|
|
|
-
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 清理缓存,列出缓存占用空间,type =list列出,type=clear清理,不能清理近期及正在激活的数据,并且提示清理中暂未上传或者导出的数据。
|
|
|
/// </summary>
|
|
@@ -59,31 +60,38 @@ namespace IES.ExamServer.Controllers
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("clean-cache")]
|
|
|
[AuthToken("admin", "teacher", "visitor")]
|
|
|
- public async Task<IActionResult> CleanCache(JsonNode json)
|
|
|
+ public async Task<IActionResult> CleanCache(JsonNode json)
|
|
|
{
|
|
|
return Ok();
|
|
|
}
|
|
|
+
|
|
|
+ //C#.NET 6 后端与前端流式通信
|
|
|
+ //https://www.doubao.com/chat/collection/687687510791426?type=Thread
|
|
|
+ //下载日志记录:1.步骤,检查,2.获取描述信息,3.分类型,4下载文件,5.前端处理,6.返回结果 , 正在下载...==> [INFO]https://www.doubao.com/chat/collection/687687510791426?type=Thread [Size=180kb] Ok...
|
|
|
+ //进度条 展示下载文件总大小和已下载,末尾展示 文件总个数和已下载个数
|
|
|
+ //https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/8.0.7/signalr.min.js
|
|
|
+ /* int data = 0,blob=0, groupList=0
|
|
|
+ {
|
|
|
+ "evaluationId":"idssss",
|
|
|
+ "shortCode":"1234567890",
|
|
|
+ "ownerId":"hbcn/tmdid",
|
|
|
+ "data":1,
|
|
|
+ "blob":1,
|
|
|
+ "groupList":1
|
|
|
+ }
|
|
|
+ */
|
|
|
+ //如果要访问中心,则需要教师登录联网。
|
|
|
+
|
|
|
[HttpPost("download-package")]
|
|
|
[AuthToken("admin", "teacher", "visitor")]
|
|
|
public async Task<IActionResult> DownloadPackage(JsonNode json)
|
|
|
{
|
|
|
- //C#.NET 6 后端与前端流式通信
|
|
|
- //https://www.doubao.com/chat/collection/687687510791426?type=Thread
|
|
|
- //下载日志记录:1.步骤,检查,2.获取描述信息,3.分类型,4下载文件,5.前端处理,6.返回结果 , 正在下载...==> [INFO]https://www.doubao.com/chat/collection/687687510791426?type=Thread [Size=180kb] Ok...
|
|
|
- //进度条 展示下载文件总大小和已下载,末尾展示 文件总个数和已下载个数
|
|
|
- //https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/8.0.7/signalr.min.js
|
|
|
- /* int data = 0,blob=0, groupList=0
|
|
|
- {
|
|
|
- "evaluationId":"idssss",
|
|
|
- "shortCode":"1234567890",
|
|
|
- "ownerId":"hbcn/tmdid",
|
|
|
- "data":1,
|
|
|
- "blob":1,
|
|
|
- "groupList":1
|
|
|
- }
|
|
|
- */
|
|
|
- //如果要访问中心,则需要教师登录联网。
|
|
|
var token = GetAuthTokenInfo();
|
|
|
+
|
|
|
+ //检查试卷文件完整性
|
|
|
+ List<string> successMsgs = new List<string>();
|
|
|
+ List<string> errorMsgs = new List<string>();
|
|
|
+ EvaluationCheckFileResult result = new EvaluationCheckFileResult() { successMsgs=successMsgs, errorMsgs=errorMsgs };
|
|
|
if (token.scope.Equals(ExamConstant.ScopeTeacher) || token.scope.Equals(ExamConstant.ScopeVisitor))
|
|
|
{
|
|
|
if (_connectionService.centerIsConnected)
|
|
@@ -91,6 +99,7 @@ namespace IES.ExamServer.Controllers
|
|
|
Teacher? teacher = _liteDBFactory.GetLiteDatabase().GetCollection<Teacher>().FindOne(x => x.id!.Equals(token.id));
|
|
|
string id = $"{json["evaluationId"]}";
|
|
|
string shortCode = $"{json["shortCode"]}";
|
|
|
+ string deviceId = $"{json["deviceId"]}";
|
|
|
EvaluationClient? evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x => x.id!.Equals(id) && x.shortCode!.Equals(shortCode));
|
|
|
if (teacher != null && evaluationClient!= null)
|
|
|
{
|
|
@@ -101,7 +110,7 @@ namespace IES.ExamServer.Controllers
|
|
|
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 = $"{json["ownerId"]}" });
|
|
|
+ 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;
|
|
@@ -120,50 +129,69 @@ namespace IES.ExamServer.Controllers
|
|
|
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;
|
|
|
- if ($"{json["data"]}".Equals("1"))
|
|
|
{
|
|
|
+ //evaluation
|
|
|
+ string evaluationUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/evaluation.json?{sas}";
|
|
|
+ HttpResponseMessage dataMessage = await httpClient.GetAsync(evaluationUrl);
|
|
|
+ if (dataMessage.IsSuccessStatusCode)
|
|
|
{
|
|
|
- string evaluationUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/evaluation.json?{sas}";
|
|
|
- HttpResponseMessage dataMessage = await httpClient.GetAsync(evaluationUrl);
|
|
|
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文件下载失败!");
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ //source.json
|
|
|
+ string sourceUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/source.json?{sas}";
|
|
|
+ HttpResponseMessage dataMessage = await httpClient.GetAsync(sourceUrl);
|
|
|
+ if (dataMessage.IsSuccessStatusCode)
|
|
|
{
|
|
|
- //source.json
|
|
|
- string sourceUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/source.json?{sas}";
|
|
|
- HttpResponseMessage dataMessage = await httpClient.GetAsync(sourceUrl);
|
|
|
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文件下载失败!");
|
|
|
}
|
|
|
}
|
|
|
- if ($"{json["groupList"]}".Equals("1"))
|
|
|
{
|
|
|
+ //grouplist.json
|
|
|
string grouplistUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/grouplist.json?{sas}";
|
|
|
HttpResponseMessage groupListMessage = await httpClient.GetAsync(grouplistUrl);
|
|
|
- var content = await groupListMessage.Content.ReadAsStringAsync();
|
|
|
- string path_groupList = Path.Combine(evaluationDataPath, "grouplist.json");
|
|
|
- await System.IO.File.WriteAllTextAsync(path_groupList, content);
|
|
|
- }
|
|
|
- if ($"{json["blob"]}".Equals("1"))
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(evaluationData))
|
|
|
+ if (groupListMessage.IsSuccessStatusCode)
|
|
|
{
|
|
|
- string evaluationUrl = $"{url}/{cnt}/package/{json["evaluationId"]}/data/evaluation.json?{sas}";
|
|
|
- HttpResponseMessage dataMessage = await httpClient.GetAsync(evaluationUrl);
|
|
|
- var content = await dataMessage.Content.ReadAsStringAsync();
|
|
|
- evaluationData=content;
|
|
|
+ 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!)
|
|
|
{
|
|
@@ -175,7 +203,7 @@ namespace IES.ExamServer.Controllers
|
|
|
Directory.CreateDirectory(path_paper);
|
|
|
}
|
|
|
//最多开启10个线程并行下载
|
|
|
- var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = 10 };
|
|
|
+ var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = 20 };
|
|
|
// 使用 Parallel.ForEachAsync 并行处理每个 blob
|
|
|
await Parallel.ForEachAsync(evaluationPaper.blobs, parallelOptions, async (blob, cancellationToken) =>
|
|
|
{
|
|
@@ -186,17 +214,17 @@ namespace IES.ExamServer.Controllers
|
|
|
if (blobMessage.IsSuccessStatusCode)
|
|
|
{
|
|
|
byte[] bytes = await blobMessage.Content.ReadAsByteArrayAsync(cancellationToken);
|
|
|
- string? fileName = Path.GetFileName(blob.path);
|
|
|
- string? fileNameWithoutExtension = Path.GetFileNameWithoutExtension(blob.path);
|
|
|
string? extension = Path.GetExtension(blob.path);
|
|
|
if (extension!=null)
|
|
|
{
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
@@ -204,71 +232,65 @@ namespace IES.ExamServer.Controllers
|
|
|
else
|
|
|
{
|
|
|
string? error = await blobMessage.Content.ReadAsStringAsync(cancellationToken);
|
|
|
- Console.WriteLine($"Error downloading {blob.path},{blobMessage.StatusCode},{error}");
|
|
|
+ errorMsgs.Add($"{evaluationExam.subjectName},{evaluationPaper.paperName},{blob.path}文件下载失败,{blobMessage.StatusCode},{error}");
|
|
|
+ // Console.WriteLine($"Error downloading {blob.path},{blobMessage.StatusCode},{error}");
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
+ errorMsgs.Add($"{evaluationExam.subjectName},{evaluationPaper.paperName},{blob.path}文件下载错误,{ex.Message}");
|
|
|
// 处理异常
|
|
|
- Console.WriteLine($"Error downloading {blob.path}: {ex.Message}");
|
|
|
+ //Console.WriteLine($"Error downloading {blob.path}: {ex.Message}");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- //foreach (var evaluationExam in evaluationExams!)
|
|
|
- //{
|
|
|
- // foreach (var evaluationPaper in evaluationExam.papers)
|
|
|
- // {
|
|
|
- // string path_paper = Path.Combine(evaluationPath, $"papers/{evaluationPaper.paperId}");
|
|
|
- // if (!Directory.Exists(path_paper))
|
|
|
- // {
|
|
|
- // Directory.CreateDirectory(path_paper);
|
|
|
- // }
|
|
|
- // foreach (var blob in evaluationPaper.blobs)
|
|
|
- // {
|
|
|
- // HttpResponseMessage blobMessage = await httpClient.GetAsync($"{url}/{cnt}/{blob.path}?{sas}");
|
|
|
-
|
|
|
- // byte[] bytes = await blobMessage.Content.ReadAsByteArrayAsync();
|
|
|
-
|
|
|
- // string? path = blob.path;
|
|
|
- // string? fileName = Path.GetFileName(path);
|
|
|
- // if (fileName!=null)
|
|
|
- // {
|
|
|
- // await System.IO.File.WriteAllBytesAsync(Path.Combine(path_paper, fileName), bytes);
|
|
|
- // }
|
|
|
-
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
}
|
|
|
|
|
|
+ (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");
|
|
|
- ZipHelper.CreatePasswordProtectedZip(evaluationPath, zipFilePath, evaluationClient.openCode!);
|
|
|
- return Ok(new { code = 200, msg = "下载成功!", url = zipFilePath });
|
|
|
+ var zipInfo = ZipHelper.CreatePasswordProtectedZip(evaluationPath, zipFilePath, evaluationClient.openCode!);
|
|
|
+ if (zipInfo.res)
|
|
|
+ {
|
|
|
+ successMsgs.Add("评测数据压缩包创建成功!");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ errorMsgs.Add("评测数据压缩包创建失败!");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string teacherMsg = teacher==null ? "未找到教师信息" : "";
|
|
|
string evaluationMsg = evaluationClient==null ? "未找到评测信息" : "";
|
|
|
- return Ok(new { code = 1, msg = $"用户信息或未找到评测信息!{teacherMsg}{evaluationMsg}" });
|
|
|
+ errorMsgs.Add($"用户信息或未找到评测信息!{teacherMsg}{evaluationMsg}");
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
- return Ok(new { code = 2, msg = "云端数据中心未连接" });
|
|
|
+ else {
|
|
|
+ errorMsgs.Add($"云端数据中心未连接");
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return Ok(new { code = 3, msg = "请使用教师或访客账号登录!" });
|
|
|
+ errorMsgs.Add($"请使用教师或访客账号登录!");
|
|
|
}
|
|
|
-
|
|
|
+ result.checkError=result.errorMsgs.Count();
|
|
|
+ result.checkSuccess=result.successMsgs.Count();
|
|
|
+ result.checkTotal=result.checkSuccess+result.checkError;
|
|
|
+ if (result.errorMsgs.Count()==0)
|
|
|
+ {
|
|
|
+ return Ok(new { code = 200, msg = "下载成功!", result });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { code = 1, msg = "下载失败!", result });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -284,15 +306,15 @@ namespace IES.ExamServer.Controllers
|
|
|
string evaluationId = $"{json["evaluationId"]}";
|
|
|
string openCode = $"{json["openCode"]}";
|
|
|
var token = GetAuthTokenInfo();
|
|
|
- int checkTotal = 0, checkSuccess = 0, checkError = 0;
|
|
|
- List<string> msgs = new List<string>();
|
|
|
- EvaluationCheckFileResult evaluationCheckFileResult = new EvaluationCheckFileResult();
|
|
|
+ List<string> successMsgs = new List<string>();
|
|
|
+ List<string> errorMsgs = new List<string>();
|
|
|
+ EvaluationCheckFileResult result = new EvaluationCheckFileResult() { successMsgs=successMsgs, errorMsgs =errorMsgs };
|
|
|
if (!string.IsNullOrEmpty(openCode) && !string.IsNullOrEmpty(evaluationId))
|
|
|
{
|
|
|
- EvaluationClient? evaluationLocal = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x=>x.id!.Equals(evaluationId) && x.openCode!.Equals(openCode));
|
|
|
+ EvaluationClient? evaluationLocal = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x => x.id!.Equals(evaluationId) && x.openCode!.Equals(openCode));
|
|
|
if (evaluationLocal!=null)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
await _signalRExamServerHub.SendMessage(_memoryCache, _logger, deviceId, Constant._Message_grant_type_check_file,
|
|
|
new MessageContent { dataId=evaluationLocal.id, dataName=evaluationLocal.name, messageType=Constant._Message_type_message, status=0, content="开始检查评测信息文件.." });
|
|
|
//判断文件包的压缩包是否存在。
|
|
@@ -302,6 +324,7 @@ namespace IES.ExamServer.Controllers
|
|
|
string evaluationPath = Path.Combine(packagePath, evaluationLocal.id!);
|
|
|
if (System.IO.File.Exists(Path.Combine(zipPath, $"{evaluationLocal.id}-{evaluationLocal.blobHash}.zip")))
|
|
|
{
|
|
|
+ successMsgs.Add("加载评测试卷文件包!");
|
|
|
//删除文件夹
|
|
|
FileHelper.DeleteFolder(evaluationPath);
|
|
|
if (!Directory.Exists(evaluationPath))
|
|
@@ -310,20 +333,46 @@ namespace IES.ExamServer.Controllers
|
|
|
}
|
|
|
//解压文件包
|
|
|
var extractRes = ZipHelper.ExtractPasswordProtectedZip(Path.Combine(zipPath, $"{evaluationLocal.id}-{evaluationLocal.blobHash}.zip"), evaluationPath, evaluationLocal.openCode!);
|
|
|
- if (extractRes.res)
|
|
|
+ if (extractRes.res)
|
|
|
{
|
|
|
- evaluationCheckFileResult= await ManageService.CheckFile(evaluationLocal, msgs,_signalRExamServerHub,_memoryCache,_logger, deviceId,evaluationPath);
|
|
|
+ successMsgs.Add("评测试卷文件包解压成功!");
|
|
|
+ (successMsgs, errorMsgs) = await ManageService.CheckFile(evaluationLocal, successMsgs, errorMsgs, _signalRExamServerHub, _memoryCache, _logger, deviceId, evaluationPath);
|
|
|
}
|
|
|
+ else {
|
|
|
+ errorMsgs.Add("评测试卷文件包解压失败!");
|
|
|
+ //return Ok(new { code = 3, msg = "评测试卷文件包解压失败!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ errorMsgs.Add("评测试卷文件包不存在!");
|
|
|
+ //return Ok(new { code = 3, msg = "评测试卷文件包不存在!" });
|
|
|
}
|
|
|
}
|
|
|
+ else {
|
|
|
+ errorMsgs.Add("未找到评测信息!");
|
|
|
+ // return Ok(new { code = 2, msg = "未找到评测信息!" });
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return Ok(new { code = 400, msg = "评测ID或提取码均未填写!" });
|
|
|
+ errorMsgs.Add("评测ID或提取码均未填写!");
|
|
|
+ // return Ok(new { code = 1, msg = "评测ID或提取码均未填写!" });
|
|
|
}
|
|
|
- return Ok(new { result=evaluationCheckFileResult, code = 200, msgs });
|
|
|
+
|
|
|
+ result.checkTotal = result.errorMsgs.Count() + result.successMsgs.Count();
|
|
|
+ result.checkError= result.errorMsgs.Count();
|
|
|
+ result.checkSuccess = result.successMsgs.Count();
|
|
|
+ if (result.errorMsgs.Count()==0)
|
|
|
+ {
|
|
|
+ return Ok(new { code = 200, msg = "校验成功!", result });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { code = 1, msg = "校验失败!", result });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
[HttpPost("check-evaluation")]
|
|
|
[AuthToken("admin", "teacher", "visitor")]
|
|
|
public async Task<IActionResult> CheckEvaluation(JsonNode json)
|
|
@@ -358,7 +407,8 @@ namespace IES.ExamServer.Controllers
|
|
|
{
|
|
|
evaluationLocal= evaluationClients.First();
|
|
|
}
|
|
|
- List<string> msgs = new List<string>();
|
|
|
+ List<string> successMsgs = new List<string>();
|
|
|
+ List<string> errorMsgs = new List<string>();
|
|
|
//从数据中心搜索
|
|
|
if ("1".Equals($"{checkCenter}"))
|
|
|
{
|
|
@@ -422,24 +472,32 @@ namespace IES.ExamServer.Controllers
|
|
|
centerCode = $"404";
|
|
|
centerMsg = "云端数据中心未连接";
|
|
|
}
|
|
|
- msgs.Add($"云端数据检测结果:{centerMsg},状态:{centerCode}");
|
|
|
+ if (centerCode.Equals("200"))
|
|
|
+ {
|
|
|
+ successMsgs.Add($"云端数据检测结果:{centerMsg},状态:{centerCode}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ errorMsgs.Add($"云端数据检测结果:{centerMsg},状态:{centerCode}");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- var checkDataResult = ManageService.CheckData(evaluationLocal, evaluationCloud, msgs, _liteDBFactory);
|
|
|
- Dictionary<string, object?>? evaluation =null;
|
|
|
+ var checkDataResult = ManageService.CheckData(evaluationLocal, evaluationCloud, successMsgs, errorMsgs, _liteDBFactory);
|
|
|
+ Dictionary<string, object?>? evaluation = null;
|
|
|
if (evaluationLocal!=null)
|
|
|
{
|
|
|
string zipPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "zip");
|
|
|
//判断文件包的压缩包是否存在。
|
|
|
if (!System.IO.File.Exists(Path.Combine(zipPath, $"{evaluationLocal.id}-{evaluationLocal.blobHash}.zip")))
|
|
|
{
|
|
|
- checkDataResult. zip =1;
|
|
|
+ checkDataResult.zip =1;
|
|
|
checkDataResult.blob=1;
|
|
|
checkDataResult.data=1;
|
|
|
checkDataResult.groupList=1;
|
|
|
checkDataResult.blobSize=evaluationLocal.blobSize;
|
|
|
checkDataResult.dataSize=evaluationLocal.dataSize;
|
|
|
checkDataResult.studentCount=evaluationLocal.studentCount;
|
|
|
- msgs.Add($"评测文件包压缩包不存在,需要重新下载评测!");
|
|
|
+ errorMsgs.Add($"评测文件包压缩包不存在,需要重新下载评测!");
|
|
|
|
|
|
}
|
|
|
var properties = evaluationLocal.GetType().GetProperties();
|
|
@@ -452,16 +510,51 @@ namespace IES.ExamServer.Controllers
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return Ok(new
|
|
|
{
|
|
|
code = 200,
|
|
|
evaluation = evaluation,
|
|
|
- result= checkDataResult
|
|
|
+ result = checkDataResult
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 获取当前评测的开考设置信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="json"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("load-evaluation-round-setting")]
|
|
|
+ [AuthToken("admin", "teacher", "visitor")]
|
|
|
+ public IActionResult LoadEvaluationRoundSetting(JsonNode json)
|
|
|
+ {
|
|
|
+ EvaluationClient? evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x => x.id!.Equals(json["evaluationId"]));
|
|
|
+ EvaluationRoundSetting? setting = null;
|
|
|
+ if (evaluationClient!=null)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(evaluationClient.roundId))
|
|
|
+ {
|
|
|
+ setting = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationRoundSetting>().FindOne(x => x.id!.Equals(evaluationClient.roundId));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (setting!=null)
|
|
|
+ {
|
|
|
+ return Ok(new
|
|
|
+ {
|
|
|
+ code = 200,
|
|
|
+ setting = setting
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { code = 2, msg = "未设置开考信息!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { code = 1, msg = "未找到评测信息!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设置评测开考信息(本轮名单,计时规则等)
|
|
@@ -470,13 +563,13 @@ namespace IES.ExamServer.Controllers
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("setting-evaluation-round")]
|
|
|
[AuthToken("admin", "teacher", "visitor")]
|
|
|
- public IActionResult SettingEvaluationRound(JsonNode json)
|
|
|
+ public IActionResult SettingEvaluationRound(JsonNode json)
|
|
|
{
|
|
|
EvaluationRoundSetting? setting = json.ToObject<EvaluationRoundSetting>();
|
|
|
- if (setting!=null )
|
|
|
+ if (setting!=null)
|
|
|
{
|
|
|
- EvaluationClient? evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x => x.id!.Equals(setting.evaluationId));
|
|
|
- if (evaluationClient!=null)
|
|
|
+ EvaluationClient? evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x => x.id!.Equals(setting.evaluationId) && x.openCode!.Equals(json["openCode"])&& x.shortCode!.Equals(json["shortCode"]));
|
|
|
+ if (evaluationClient!=null)
|
|
|
{
|
|
|
IEnumerable<EvaluationClient> evaluationClients = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().Find(x => x.activate==1);
|
|
|
if (evaluationClients != null && evaluationClients.Count() > 0)
|
|
@@ -497,15 +590,25 @@ namespace IES.ExamServer.Controllers
|
|
|
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.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);
|
|
|
return Ok(new { code = 200, msg = "操作成功!" });
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { code = 3, msg = "开考名单不在当前评测中!" });
|
|
|
+ }
|
|
|
}
|
|
|
+ else { return Ok(new { code = 2, msg = "未找到评测,请确认评测ID、提取码、开卷码是否正确!" }); }
|
|
|
}
|
|
|
- return Ok(new { code = 1, msg = "操作失败!" });
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { code = 1, msg = "未完善设置信息!" });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|