|
@@ -1,6 +1,8 @@
|
|
|
using IES.ExamLibrary.Models;
|
|
|
using IES.ExamServer.DI;
|
|
|
+using IES.ExamServer.Filters;
|
|
|
using IES.ExamServer.Helper;
|
|
|
+using IES.ExamServer.Helpers;
|
|
|
using IES.ExamServer.Models;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
@@ -31,17 +33,126 @@ namespace IES.ExamServer.Controllers
|
|
|
_connectionService=connectionService;
|
|
|
_liteDBFactory=liteDBFactory;
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 学生提交科目作答
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="json"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("answer-subject-result")]
|
|
|
+ [AuthToken("student")]
|
|
|
+ public IActionResult AnswerSubjectResult(JsonNode json)
|
|
|
+ {
|
|
|
+ List<List<string>>? answers = json["answer"]?.ToObject<List<List<string>>>();
|
|
|
+ string evaluationId = $"{json["evaluationId"]}";
|
|
|
+ string examId = $"{json["examId"]}";
|
|
|
+ string subjectId = $"{json["subjectId"]}";
|
|
|
+ string paperId = $"{json["paperId"]}";
|
|
|
+ int costTime = int.Parse($"{json["costTime"]}");
|
|
|
+ string settingId = $"{json["settingId"]}";
|
|
|
+ var token = GetAuthTokenInfo();
|
|
|
+ EvaluationRoundSetting? setting = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationRoundSetting>().FindOne(x => x.id!.Equals(settingId) && evaluationId.Equals(x.evaluationId) && x.activate==1);
|
|
|
+ EvaluationClient? evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x=>evaluationId.Equals(x.id));
|
|
|
+ if (evaluationClient!=null && setting!=null && setting.activate==1)
|
|
|
+ {
|
|
|
+ string resultId = ShaHashHelper.GetSHA1(evaluationId+_connectionService?.serverDevice?.school?.id+token.id);
|
|
|
+ EvaluationStudentResult studentResult = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationStudentResult>()
|
|
|
+ .FindOne(x => resultId.Equals(x.id) && token.id.Equals(x.studentId) && evaluationId.Equals(x.evaluationId));
|
|
|
+ if (studentResult!=null)
|
|
|
+ {
|
|
|
+ long now = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
|
|
+ //判断开始时间
|
|
|
+ if ((setting.startline>0 && setting.startline>now)|| evaluationClient.stime>now)
|
|
|
+ {
|
|
|
+ //未到开始时间
|
|
|
+ return Ok(new { msg = "未到开始时间。", code = 1 });
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断截止时间
|
|
|
+ long deadline;
|
|
|
+ if (setting.countdownType==2)
|
|
|
+ {
|
|
|
+
|
|
|
+ deadline= studentResult.startTime+setting.countdown;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ deadline= setting.startline+setting.countdown;
|
|
|
+
|
|
|
+ }
|
|
|
+ deadline+= 10*60*1000;//漂移10分钟,允许学生延迟提交,但是前端页面显示的截止时间是准的,时间一到,可自动提交。
|
|
|
+ if ((deadline>0&&deadline<now)|| evaluationClient.etime<now)
|
|
|
+ {
|
|
|
+ //已过截止时间
|
|
|
+ return Ok(new { msg = "已过截止时间。", code = 2 });
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(subjectId) && !string.IsNullOrWhiteSpace(examId) && !string.IsNullOrWhiteSpace(paperId)&& costTime>0)
|
|
|
+ {
|
|
|
+ var subjectResult = studentResult.subjectResults.Where(x => subjectId.Equals(x.subjectId) && examId.Equals(x.examId) && paperId.Equals(x.paperId)).FirstOrDefault();
|
|
|
+ if (subjectResult!=null)
|
|
|
+ {
|
|
|
+ if (answers!=null)
|
|
|
+ {
|
|
|
+ subjectResult.answers=answers!;
|
|
|
+ }
|
|
|
+ subjectResult.finished=1;
|
|
|
+ subjectResult.costTime=costTime;
|
|
|
+ subjectResult.submitTime=now;
|
|
|
+ }
|
|
|
+ if (_connectionService!.centerIsConnected)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Ok(new { code = 200, studentResult = studentResult, msg = "提交成功!" });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { msg = "未找到该学生的作答信息。", code = 4});
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { msg = "未匹配到正则开考的评测。", code = 3 });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
- /// 提交作答
|
|
|
+ /// 获取学生当前考试的作答信息。
|
|
|
/// </summary>
|
|
|
/// <param name="json"></param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpPost("submit-answer")]
|
|
|
- public IActionResult SubmitAnswer(JsonNode json)
|
|
|
+ [HttpPost("load-evaluation-result")]
|
|
|
+ [AuthToken("student")]
|
|
|
+ public IActionResult LoadEvaluationResult(JsonNode json)
|
|
|
{
|
|
|
- //提交作答,多种保存方式,在数据库,文件中,缓存中,以及日志中都记录防止丢失。
|
|
|
- return Ok();
|
|
|
+ string evaluationId = $"{json["evaluationId"]}";
|
|
|
+ var token = GetAuthTokenInfo();
|
|
|
+ string resultId = ShaHashHelper.GetSHA1(evaluationId+_connectionService?.serverDevice?.school?.id+token.id);
|
|
|
+ EvaluationStudentResult studentResult = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationStudentResult>()
|
|
|
+ .FindOne(x=> resultId.Equals(x.id) && token.id.Equals(x.studentId) && evaluationId.Equals(x.evaluationId));
|
|
|
+ if (studentResult!=null)
|
|
|
+ {
|
|
|
+ //标记开始作答
|
|
|
+ studentResult.finished=1;
|
|
|
+
|
|
|
+ if (studentResult.startTime<=0)
|
|
|
+ {
|
|
|
+ studentResult.startTime=DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
|
|
+ }
|
|
|
+ _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationStudentResult>().Update(studentResult);
|
|
|
+ return Ok(new { code = 200, studentResult = studentResult });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { msg = "未找到该学生的作答信息。", code = 404});
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 登录
|
|
|
/// </summary>
|
|
@@ -50,15 +161,16 @@ namespace IES.ExamServer.Controllers
|
|
|
[HttpPost("login")]
|
|
|
public IActionResult Login(JsonNode json)
|
|
|
{
|
|
|
- string? studentId = json["studentId"]?.ToString();
|
|
|
- string? studentName = json["studentName"]?.ToString();
|
|
|
- string? evaluationId = json["evaluationId"]?.ToString();
|
|
|
- EvaluationRoundSetting? setting = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationRoundSetting>().FindOne(x => x.id!.Equals(evaluationId)&& x.activate==1);
|
|
|
+ string studentId = $"{json["studentId"]}";
|
|
|
+ string studentName = $"{json["studentName"]}";
|
|
|
+ string evaluationId = $"{json["evaluationId"]}";
|
|
|
+ string settingId = $"{json["settingId"]}";
|
|
|
+ EvaluationRoundSetting? setting = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationRoundSetting>().FindOne(x => x.id!.Equals(settingId) && evaluationId.Equals(x.evaluationId) && x.activate==1);
|
|
|
EvaluationClient? evaluationClient = null;
|
|
|
if (setting!=null)
|
|
|
{
|
|
|
- evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x => x.id == setting.evaluationId);
|
|
|
- if (evaluationClient!=null)
|
|
|
+ evaluationClient = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x => x.id!.Equals(setting.evaluationId));
|
|
|
+ if (evaluationClient!=null)
|
|
|
{
|
|
|
//检查是否在作答时间内
|
|
|
(code, msg)= CheckActivate(evaluationClient, setting);
|
|
@@ -72,16 +184,38 @@ namespace IES.ExamServer.Controllers
|
|
|
{
|
|
|
school = server.school;
|
|
|
}
|
|
|
- string id = $"{studentId}";
|
|
|
- string name = $"{studentName}";
|
|
|
+ EvaluationMember? member = _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationMember>().FindOne(x => studentId.Equals(x.id)&& studentName.Equals(x.name));
|
|
|
+ if (member!=null)
|
|
|
+ {
|
|
|
+ if (evaluationId.Equals(member.evaluationId))
|
|
|
+ {
|
|
|
+ string x_auth_token = JwtAuthExtension.CreateAuthToken("www.teammodel.cn", studentId, studentName, picture: string.Empty, ExamConstant.JwtSecretKey, ExamConstant.ScopeVisitor, 8, schoolID: school?.id, new string[] { "student" }, expire: 1);
|
|
|
+ return Ok(new { code = 200, x_auth_token = x_auth_token });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
|
|
|
- string x_auth_token = JwtAuthExtension.CreateAuthToken("www.teammodel.cn", id, name, picture: string.Empty , ExamConstant.JwtSecretKey, ExamConstant.ScopeVisitor, 8, schoolID: school?.id, new string[] { "student" }, expire: 1);
|
|
|
- //_liteDBFactory.GetLiteDatabase().GetCollection<Teacher>().Upsert(new Teacher { id = id, name = $"{name}", picture = null, x_auth_token = x_auth_token, loginTime=time });
|
|
|
- return Ok(new { code = 200, x_auth_token = x_auth_token });
|
|
|
+ return Ok(new { msg = "当前考试未添加该学生!", code = 7 });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { msg = "学者账号和姓名不匹配!", code = 1 });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { msg = msg, code = code });
|
|
|
}
|
|
|
}
|
|
|
+ else {
|
|
|
+ return Ok(new { msg = "未找到考试设置。", code = 6 });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { msg = "未找到考试设置。", code = 2 });
|
|
|
}
|
|
|
- return Ok(new { msg =msg, code = 200 });
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 学生端获取激活的考试
|
|
@@ -160,31 +294,23 @@ namespace IES.ExamServer.Controllers
|
|
|
}
|
|
|
//当前时间
|
|
|
long now = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
|
|
- if (setting.countdownType>0)
|
|
|
+ //if (setting.countdownType>0)
|
|
|
+ //{
|
|
|
+
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+
|
|
|
+ //}
|
|
|
+ if ((setting.startline>0 &&setting.startline>now) || evaluationClient.stime>now)
|
|
|
{
|
|
|
- if (setting.startline>now || evaluationClient.stime>now)
|
|
|
- {
|
|
|
- msg="评测暂未开始。";
|
|
|
- code=4;
|
|
|
- }
|
|
|
- if ((setting.deadline>0 && setting.deadline<now)|| evaluationClient.etime<now)
|
|
|
- {
|
|
|
- msg="评测已经结束。";
|
|
|
- code=5;
|
|
|
- }
|
|
|
+ msg="评测暂未开始。";
|
|
|
+ code=4;
|
|
|
}
|
|
|
- else
|
|
|
+ if ((setting.deadline>0 && setting.deadline<now)|| evaluationClient.etime<now)
|
|
|
{
|
|
|
- if (evaluationClient.stime>now)
|
|
|
- {
|
|
|
- msg="评测暂未开始。";
|
|
|
- code=4;
|
|
|
- }
|
|
|
- if (evaluationClient.etime<now)
|
|
|
- {
|
|
|
- msg="评测已经结束。";
|
|
|
- code=5;
|
|
|
- }
|
|
|
+ msg="评测已经结束。";
|
|
|
+ code=5;
|
|
|
}
|
|
|
return (code, msg);
|
|
|
}
|