From a83f0bbc6cb28f2ce7f32f784db145cc9d4d1e4b Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Thu, 6 Jun 2024 17:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=87=AA=E5=8A=A8=E5=88=A4?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Tiobon.Web.pdm | 13 +- .../Ghre/Ghre_ExamRecordDetail.Dto.Base.cs | 2 +- .../Models/Ghre/Ghre_ExamRecordDetail.cs | 2 +- .../Ghre/Ghre_ExamRecordDetail.Dto.View.cs | 20 +-- .../Ghre/Ghre_ExamServices.cs | 123 ++++++++++++++++++ 5 files changed, 143 insertions(+), 17 deletions(-) diff --git a/Model/Tiobon.Web.pdm b/Model/Tiobon.Web.pdm index 11698172..1fb73239 100644 --- a/Model/Tiobon.Web.pdm +++ b/Model/Tiobon.Web.pdm @@ -1,5 +1,5 @@ - + @@ -109465,10 +109465,11 @@ LABL 0 Arial Unicode MS,8,N QuestionAnswerId 1714108307 Administrator -1717643700 +1717661446 Administrator 题目答案ID -bigint +nvarchar(2000) +2000 4B89F3EC-C886-497D-B21D-3C2B7E41FD71 @@ -109476,11 +109477,11 @@ LABL 0 Arial Unicode MS,8,N AnswerContent 1714108307 Administrator -1717644318 +1717664029 Administrator 答案内容 -nvarchar(256) -256 +nvarchar(2000) +2000 1360ED27-6BCD-4736-912E-0782B001169F diff --git a/Tiobon.Core.Model/Base/Ghre/Ghre_ExamRecordDetail.Dto.Base.cs b/Tiobon.Core.Model/Base/Ghre/Ghre_ExamRecordDetail.Dto.Base.cs index 3ebaf504..f8ba3f26 100644 --- a/Tiobon.Core.Model/Base/Ghre/Ghre_ExamRecordDetail.Dto.Base.cs +++ b/Tiobon.Core.Model/Base/Ghre/Ghre_ExamRecordDetail.Dto.Base.cs @@ -50,7 +50,7 @@ namespace Tiobon.Core.Model.Models /// /// 题目答案ID /// - public long? QuestionAnswerId { get; set; } + public string QuestionAnswerId { get; set; } /// /// 答案内容 diff --git a/Tiobon.Core.Model/Models/Ghre/Ghre_ExamRecordDetail.cs b/Tiobon.Core.Model/Models/Ghre/Ghre_ExamRecordDetail.cs index 65e7e50c..f289d3f6 100644 --- a/Tiobon.Core.Model/Models/Ghre/Ghre_ExamRecordDetail.cs +++ b/Tiobon.Core.Model/Models/Ghre/Ghre_ExamRecordDetail.cs @@ -52,7 +52,7 @@ namespace Tiobon.Core.Model.Models /// /// 题目答案ID /// - public long? QuestionAnswerId { get; set; } + public string QuestionAnswerId { get; set; } /// /// 答案内容 diff --git a/Tiobon.Core.Model/View/Ghre/Ghre_ExamRecordDetail.Dto.View.cs b/Tiobon.Core.Model/View/Ghre/Ghre_ExamRecordDetail.Dto.View.cs index ab146c07..096da5ba 100644 --- a/Tiobon.Core.Model/View/Ghre/Ghre_ExamRecordDetail.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghre/Ghre_ExamRecordDetail.Dto.View.cs @@ -13,7 +13,7 @@ *│ 此技术信息为本公司机密信息,未经本公司书面同意禁止向第三方披露. │ *│ 作者:SimonHsiao │ *└──────────────────────────────────┘ -*/ +*/ namespace Tiobon.Core.Model.Models; @@ -22,13 +22,15 @@ namespace Tiobon.Core.Model.Models; /// public class Ghre_ExamRecordDetailDto : Ghre_ExamRecordDetail { -/// -/// 创建信息 -/// -public string CreateDataInfo { get; set; } + /// + /// 创建信息 + /// + public string CreateDataInfo { get; set; } -/// -/// 修改信息 -/// -public string UpdateDataInfo { get; set; } + /// + /// 修改信息 + /// + public string UpdateDataInfo { get; set; } + + public List QuestionAnswerIds { get; set; } } diff --git a/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs b/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs index ed3e2c43..ef28d49a 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs @@ -31,6 +31,10 @@ public class Ghre_ExamServices : BaseServices dal) { this._dal = dal; @@ -50,7 +58,11 @@ public class Ghre_ExamServices : BaseServices GetModuleInfo(ModuleParam param) { @@ -1255,4 +1267,115 @@ public class Ghre_ExamServices : BaseServices 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>(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>(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("提交成功!"); + } } \ No newline at end of file