|
@@ -1,10 +1,12 @@
|
|
|
using IES.ExamLib.Models;
|
|
|
using IES.ExamServer.DI;
|
|
|
using IES.ExamServer.Filters;
|
|
|
+using IES.ExamServer.Helper;
|
|
|
using IES.ExamServer.Models;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
+using System.Linq.Expressions;
|
|
|
using System.Net.Http;
|
|
|
using System.Text.Json;
|
|
|
using System.Text.Json.Nodes;
|
|
@@ -41,27 +43,139 @@ namespace IES.ExamServer.Controllers
|
|
|
//下载日志记录:1.步骤,检查,2.获取描述信息,3.分类型,4下载文件,5.前端处理,6.返回结果 , 正在下载...==> https://www.doubao.com/chat/collection/687687510791426?type=Thread Ok...
|
|
|
return Ok();
|
|
|
}
|
|
|
- [HttpPost("search-short-code")]
|
|
|
- public async Task<IActionResult> SearchShortCode(JsonNode json)
|
|
|
+ [HttpPost("check-short-code")]
|
|
|
+ public async Task<IActionResult> CheckShortCode(JsonNode json)
|
|
|
{
|
|
|
+
|
|
|
+ string shortCode = $"{json["shortCode"]}";
|
|
|
+ string evaluationId = $"{json["evaluationId"]}";
|
|
|
+ Expression<Func<EvaluationClient, bool>> predicate = x => true;
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(shortCode))
|
|
|
+ {
|
|
|
+ var codePredicate = ExpressionHelper.Or<EvaluationClient>(
|
|
|
+ x => !string.IsNullOrWhiteSpace(x.shortCode) && x.shortCode == shortCode,
|
|
|
+ x => !string.IsNullOrWhiteSpace(x.password) && x.password == shortCode
|
|
|
+ );
|
|
|
+ predicate= predicate.And(codePredicate);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { code = 400,msg="必须输入开卷码" });
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(evaluationId))
|
|
|
+ {
|
|
|
+ predicate= predicate.And(x => x.id!.Equals(evaluationId));
|
|
|
+ }
|
|
|
+ IEnumerable<EvaluationClient> evaluationClients = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().Find(predicate);
|
|
|
+ EvaluationClient? evaluationLocal = null;
|
|
|
+ EvaluationClient? evaluationCloud = null;
|
|
|
+ if (evaluationClients.Count()>0)
|
|
|
+ {
|
|
|
+ evaluationLocal= evaluationClients.First();
|
|
|
+ }
|
|
|
//如果要访问中心,则需要教师登录联网。
|
|
|
var token = GetAuthTokenInfo();
|
|
|
if (token.scope.Equals(ExamConstant.ScopeTeacher))
|
|
|
{
|
|
|
- string shortCode = $"{json["shortCode"]}";
|
|
|
- if (string.IsNullOrWhiteSpace(shortCode))
|
|
|
+ if ( _connectionService.dataCenterIsConnected)
|
|
|
{
|
|
|
- EvaluationClient evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>()
|
|
|
- .FindOne(x => (!string.IsNullOrWhiteSpace(x.shortCode) && x.shortCode.Equals(shortCode)) || (!string.IsNullOrWhiteSpace(x.password) && x.password.Equals(shortCode)));
|
|
|
- if (evaluationClient == null && _connectionService.dataCenterIsConnected)
|
|
|
+ Teacher teacher= _liteDBFactory.GetLiteDatabase().GetCollection<Teacher>().FindOne(x => x.id!.Equals(token.id));
|
|
|
+ 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);
|
|
|
+ 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 =JsonSerializer.Deserialize<JsonNode>(content);
|
|
|
+ if (jsonNode!=null)
|
|
|
+ {
|
|
|
+ evaluationCloud= JsonSerializer.Deserialize<EvaluationClient>(jsonNode["evaluation"]);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //数据,文件,页面 0 没有更新,1 有更新
|
|
|
+ int data = 0,blob=0,webview=0,status=0;
|
|
|
+ long dataSize = 0, blobSize=0 , webviewSize=0;
|
|
|
+ if (evaluationLocal== null && evaluationCloud==null)
|
|
|
+ {
|
|
|
+ //线上线下没有数据
|
|
|
+ status=1;
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (evaluationLocal!=null && evaluationCloud!=null)
|
|
|
+ {
|
|
|
+ //线上线下有数据
|
|
|
+ status = 2;
|
|
|
+ if ((!string.IsNullOrWhiteSpace(evaluationLocal.blobHash) && !evaluationLocal.blobHash.Equals(evaluationCloud.blobHash))
|
|
|
+ ||(evaluationLocal.blobTime<evaluationCloud.blobTime)
|
|
|
+ ||(evaluationLocal.blobCount!= evaluationCloud.blobCount)
|
|
|
+ ||(evaluationLocal.blobSize!= evaluationCloud.blobSize))
|
|
|
+ {
|
|
|
+ blob=1;
|
|
|
+ blobSize=evaluationCloud.blobSize;
|
|
|
+ }
|
|
|
+ if ((evaluationLocal.dataTime<evaluationCloud.dataTime)
|
|
|
+ ||(evaluationLocal.dataSize!=evaluationCloud.dataSize))
|
|
|
+ {
|
|
|
+ data=1;
|
|
|
+ dataSize=evaluationCloud.dataSize;
|
|
|
+ }
|
|
|
+ if ((evaluationLocal.webviewCount!=evaluationCloud.webviewCount)
|
|
|
+ ||(evaluationLocal.webviewSize!= evaluationCloud.webviewSize)
|
|
|
+ ||(evaluationLocal.webviewTime!= evaluationCloud.webviewTime)
|
|
|
+ ||(!string.IsNullOrWhiteSpace(evaluationLocal.webviewPath)&& !evaluationLocal.webviewPath.Equals(evaluationCloud.webviewPath)))
|
|
|
+ {
|
|
|
+ webview=1;
|
|
|
+ webviewSize=evaluationCloud.webviewSize;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (evaluationLocal!=null && evaluationCloud==null)
|
|
|
+ {
|
|
|
+ //线下有数据,线上没有数据,可能没联网。
|
|
|
+ status = 3;
|
|
|
+ }
|
|
|
+ else if (evaluationLocal==null && evaluationCloud!=null)
|
|
|
+ {
|
|
|
+ //线下没有数据,线上有数据
|
|
|
+ evaluationLocal= evaluationCloud;
|
|
|
+ blob=1;
|
|
|
+ data=1;
|
|
|
+ webview=1;
|
|
|
+ blobSize=evaluationCloud.blobSize;
|
|
|
+ dataSize=evaluationCloud.dataSize;
|
|
|
+ webviewSize=evaluationCloud.webviewSize;
|
|
|
+ status = 4;
|
|
|
+ _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().Insert(evaluationLocal);
|
|
|
+ }
|
|
|
+ List<int> file_intact = new List<int>();
|
|
|
+ if (evaluationLocal!=null)
|
|
|
+ {
|
|
|
+ //校验本地文件数据
|
|
|
+ string packagePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "package");
|
|
|
+ if (!Directory.Exists(packagePath))
|
|
|
+ Directory.CreateDirectory(packagePath);
|
|
|
+ string evaluationPath = Path.Combine(packagePath, evaluationLocal.id!);
|
|
|
+ if (!System.IO.File.Exists(Path.Combine(evaluationPath, "evaluation.json")))
|
|
|
+ {
|
|
|
+ file_intact.Add(0);
|
|
|
+ }
|
|
|
+ if (!System.IO.File.Exists(Path.Combine(evaluationPath, "groupList.json")))
|
|
|
+ {
|
|
|
+ file_intact.Add(0);
|
|
|
+ }
|
|
|
+ if (!System.IO.File.Exists(Path.Combine(evaluationPath, "source.json")))
|
|
|
+ {
|
|
|
+ file_intact.Add(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return Ok();
|
|
|
+ return Ok(new {code=200, evaluation= evaluationLocal,data,blob,webview,dataSize,blobSize,webviewSize,status });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -74,10 +188,13 @@ namespace IES.ExamServer.Controllers
|
|
|
{
|
|
|
string id = $"{json["id"]}";
|
|
|
string shortCode = $"{json["shortCode"]}";
|
|
|
- EvaluationClient evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x=>x.id!.Equals(id));
|
|
|
- if (evaluationClient != null)
|
|
|
+ if (!string.IsNullOrWhiteSpace(id) && !string.IsNullOrWhiteSpace(shortCode))
|
|
|
{
|
|
|
-
|
|
|
+ EvaluationClient evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x => x.id!.Equals(id) && !string.IsNullOrWhiteSpace(x.shortCode) && x.shortCode.Equals(shortCode));
|
|
|
+ if (evaluationClient != null)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
return Ok();
|
|
|
}
|
|
@@ -89,6 +206,7 @@ namespace IES.ExamServer.Controllers
|
|
|
[HttpPost("list-local-evaluation")]
|
|
|
public IActionResult ListLocalEvaluation(JsonNode json)
|
|
|
{
|
|
|
+
|
|
|
IEnumerable<EvaluationClient> evaluationClients = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindAll().OrderByDescending(x=>x.activate).ThenByDescending(x=>x.stime);
|
|
|
var result = evaluationClients.Select(client =>
|
|
|
{
|
|
@@ -103,7 +221,7 @@ namespace IES.ExamServer.Controllers
|
|
|
}
|
|
|
return anonymousObject;
|
|
|
});
|
|
|
- return Ok(new { evaluation= result });
|
|
|
+ return Ok(new {code=200, evaluation= result });
|
|
|
}
|
|
|
}
|
|
|
}
|