系统自动判分

master
xiaochanghai 1 year ago
parent ed33a07ba7
commit a83f0bbc6c
  1. 13
      Model/Tiobon.Web.pdm
  2. 2
      Tiobon.Core.Model/Base/Ghre/Ghre_ExamRecordDetail.Dto.Base.cs
  3. 2
      Tiobon.Core.Model/Models/Ghre/Ghre_ExamRecordDetail.cs
  4. 2
      Tiobon.Core.Model/View/Ghre/Ghre_ExamRecordDetail.Dto.View.cs
  5. 123
      Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?PowerDesigner AppLocale="UTF16" ID="{C294868A-C3F3-41AD-98CC-78B6D4E0CC40}" Label="" LastModificationDate="1717650791" Name="Tiobon" Objects="6698" Symbols="286" Target="Microsoft SQL Server 2008" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="15.0.0.2613"?>
<?PowerDesigner AppLocale="UTF16" ID="{C294868A-C3F3-41AD-98CC-78B6D4E0CC40}" Label="" LastModificationDate="1717664029" Name="Tiobon" Objects="6780" Symbols="288" Target="Microsoft SQL Server 2008" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="15.0.0.2613"?>
<!-- do not edit this file -->
<Model xmlns:a="attribute" xmlns:c="collection" xmlns:o="object">
@ -109465,10 +109465,11 @@ LABL 0 Arial Unicode MS,8,N</a:FontList>
<a:Code>QuestionAnswerId</a:Code>
<a:CreationDate>1714108307</a:CreationDate>
<a:Creator>Administrator</a:Creator>
<a:ModificationDate>1717643700</a:ModificationDate>
<a:ModificationDate>1717661446</a:ModificationDate>
<a:Modifier>Administrator</a:Modifier>
<a:Comment>题目答案ID</a:Comment>
<a:DataType>bigint</a:DataType>
<a:DataType>nvarchar(2000)</a:DataType>
<a:Length>2000</a:Length>
</o:Column>
<o:Column Id="o6635">
<a:ObjectID>4B89F3EC-C886-497D-B21D-3C2B7E41FD71</a:ObjectID>
@ -109476,11 +109477,11 @@ LABL 0 Arial Unicode MS,8,N</a:FontList>
<a:Code>AnswerContent</a:Code>
<a:CreationDate>1714108307</a:CreationDate>
<a:Creator>Administrator</a:Creator>
<a:ModificationDate>1717644318</a:ModificationDate>
<a:ModificationDate>1717664029</a:ModificationDate>
<a:Modifier>Administrator</a:Modifier>
<a:Comment>答案内容</a:Comment>
<a:DataType>nvarchar(256)</a:DataType>
<a:Length>256</a:Length>
<a:DataType>nvarchar(2000)</a:DataType>
<a:Length>2000</a:Length>
</o:Column>
<o:Column Id="o6636">
<a:ObjectID>1360ED27-6BCD-4736-912E-0782B001169F</a:ObjectID>

@ -50,7 +50,7 @@ namespace Tiobon.Core.Model.Models
/// <summary>
/// 题目答案ID
/// </summary>
public long? QuestionAnswerId { get; set; }
public string QuestionAnswerId { get; set; }
/// <summary>
/// 答案内容

@ -52,7 +52,7 @@ namespace Tiobon.Core.Model.Models
/// <summary>
/// 题目答案ID
/// </summary>
public long? QuestionAnswerId { get; set; }
public string QuestionAnswerId { get; set; }
/// <summary>
/// 答案内容

@ -31,4 +31,6 @@ public string CreateDataInfo { get; set; }
/// 修改信息
/// </summary>
public string UpdateDataInfo { get; set; }
public List<long> QuestionAnswerIds { get; set; }
}

@ -31,6 +31,10 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
private readonly IGhre_ExamRecordServices _ghre_ExamRecordServices;
private readonly IGhre_ExamMessageLogServices _ghre_ExamMessageLogServices;
private readonly IGhre_ExamPaperServices _ghre_ExamPaperServices;
private readonly IGhre_ExamPaperQuestionServices _ghre_ExamPaperQuestionServices;
private readonly IGhre_ExamRecordDetailServices _ghre_ExamRecordDetailServices;
private readonly IGhre_QuestionServices _ghre_QuestionServices;
private readonly IGhre_QuestionAnswerServices _ghre_QuestionAnswerServices;
public Ghre_ExamServices(ICaching caching,
IGhre_CourseServices ghre_CourseServices,
IGhre_CourseSceneServices ghre_CourseSceneServices,
@ -39,6 +43,10 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
IGhre_ExamRecordServices ghre_ExamRecordServices,
IGhre_ExamMessageLogServices ghre_ExamMessageLogServices,
IGhre_ExamPaperServices ghre_ExamPaperServices,
IGhre_ExamPaperQuestionServices ghre_ExamPaperQuestionServices,
IGhre_ExamRecordDetailServices ghre_ExamRecordDetailServices,
IGhre_QuestionServices ghre_QuestionServices,
IGhre_QuestionAnswerServices ghre_QuestionAnswerServices,
IBaseRepository<Ghre_Exam> dal)
{
this._dal = dal;
@ -50,7 +58,11 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
_ghre_ExamStaffServices = ghre_ExamStaffServices;
_ghre_ExamRecordServices = ghre_ExamRecordServices;
_ghre_ExamMessageLogServices = ghre_ExamMessageLogServices;
_ghre_QuestionServices = ghre_QuestionServices;
_ghre_QuestionAnswerServices = ghre_QuestionAnswerServices;
_ghre_ExamPaperServices = ghre_ExamPaperServices;
_ghre_ExamPaperQuestionServices = ghre_ExamPaperQuestionServices;
_ghre_ExamRecordDetailServices = ghre_ExamRecordDetailServices;
}
public async Task<dynamic> GetModuleInfo(ModuleParam param)
{
@ -1255,4 +1267,115 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
return ServiceResult.OprateSuccess("提交成功!");
}
public async Task<ServiceResult> SystemMark(long id)
{
var record = await _ghre_ExamRecordServices.QuerySingleDto(x => x.ExamId == id || x.Id == id);
var examPaper = await _ghre_ExamPaperServices.QuerySingleDto(x => x.Id == record.ExamPaperId && x.ScoreMethod == "System");
if (examPaper != null)
{
var details = await _ghre_ExamRecordDetailServices.QueryDto(x => x.ExamRecordId == record.Id);
details.ForEach(x =>
{
if (!string.IsNullOrWhiteSpace(x.QuestionAnswerId))
x.QuestionAnswerIds = JsonConvert.DeserializeObject<List<long>>(x.QuestionAnswerId);
});
var questionIds = details.Where(x => x.QuestionId != null).SelectMany(m =>
{
return m.QuestionAnswerIds.Select((x, i) =>
{
return x;
});
}).ToList();
var exampaperQuestions = await _ghre_ExamPaperQuestionServices.Query(x => x.ExamPaperId == record.ExamPaperId);
var questions = await _ghre_QuestionServices.Query(x => questionIds.Contains(x.Id));
var answers = await _ghre_QuestionAnswerServices.Query(x => x.QuestionId != null && questionIds.Contains(x.QuestionId.Value) && x.IsCorrect == true);
decimal? score = 0;
var detailGroups = details.GroupBy(m => m.QuestionId)
.Select(m => new
{
m.FirstOrDefault()?.QuestionId,
List = m.ToList()
})
.ToList();
detailGroups.ForEach(group =>
{
var question = questions.FirstOrDefault(x => x.Id == group.QuestionId);
if (question.QuestionType != "Completion" && question.QuestionType != "ShortAnswer")
{
var questionAnswerIds = group.List.Where(x => x.QuestionId != null).SelectMany(m =>
{
return m.QuestionAnswerIds.Select((x, i) =>
{
return x;
});
}).ToList();
if (questionAnswerIds.Count == answers.Where(x => questionAnswerIds.Contains(x.Id)).Count())
{
var exampaperQuestion = exampaperQuestions.FirstOrDefault(x => x.QuestionId == group.QuestionId);
score += exampaperQuestion.Score;
var detail = details.Where(x => x.QuestionId == group.QuestionId).First();
detail.Score = exampaperQuestion.Score;
}
}
else if (question.QuestionType == "Completion")// 填空题
{
if (!string.IsNullOrWhiteSpace(group.List.First().AnswerContent))
{
var completionAnswers = answers.OrderBy(x => x.TaxisNo).Where(x => x.QuestionId == group.QuestionId).ToList();
var contents = JsonConvert.DeserializeObject<List<string>>(group.List.First().AnswerContent);
var count = completionAnswers.Count;
for (int i = 0; i < completionAnswers.Count; i++)
if (completionAnswers[i].AnswerContent == contents[i])
count--;
if (count == 0)
{
var exampaperQuestion = exampaperQuestions.FirstOrDefault(x => x.QuestionId == group.QuestionId);
score += exampaperQuestion.Score;
var detail = details.Where(x => x.QuestionId == group.QuestionId).First();
detail.Score = exampaperQuestion.Score;
}
}
}
else if (question.QuestionType == "ShortAnswer")//简单题
{
if (!string.IsNullOrWhiteSpace(group.List.First().AnswerContent))
{
var completionAnswers = answers.OrderBy(x => x.TaxisNo).Where(x => x.QuestionId == group.QuestionId).ToList();
var content = group.List.First().AnswerContent;
var count = completionAnswers.Count;
for (int i = 0; i < completionAnswers.Count; i++)
if (content.IndexOf(completionAnswers[i].AnswerContent) > -1)
count--;
if (count == 0)
{
var exampaperQuestion = exampaperQuestions.FirstOrDefault(x => x.QuestionId == group.QuestionId);
score += exampaperQuestion.Score;
var detail = details.Where(x => x.QuestionId == group.QuestionId).First();
detail.Score = exampaperQuestion.Score;
}
}
}
});
record.Score = score;
await Db.Updateable(details).UpdateColumns(it => new { it.Score }).ExecuteCommandAsync();
await Db.Updateable(record).UpdateColumns(it => new { it.Score }).ExecuteCommandAsync();
}
return ServiceResult.OprateSuccess("提交成功!");
}
}
Loading…
Cancel
Save