From c9f27610441de5fa38684ecf0c65f8047af0329d Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Tue, 13 May 2025 18:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=BE=E7=A8=8B=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/Extend/QuestionErrorRanking.cs | 14 +++++++ .../Ghre/Ghre_CourseServices.cs | 39 ++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 Tiobon.Core.Model/ViewModels/Extend/QuestionErrorRanking.cs diff --git a/Tiobon.Core.Model/ViewModels/Extend/QuestionErrorRanking.cs b/Tiobon.Core.Model/ViewModels/Extend/QuestionErrorRanking.cs new file mode 100644 index 00000000..c567e5b2 --- /dev/null +++ b/Tiobon.Core.Model/ViewModels/Extend/QuestionErrorRanking.cs @@ -0,0 +1,14 @@ +namespace Tiobon.Core.Model.ViewModels.Extend; + +public class QuestionErrorRanking +{ + public long Id { get; set; } + public string QuestionContent { get; set; } + public string QuestionNo { get; set; } + public decimal ErrorCount { get; set; } + + public decimal TotalCount { get; set; } + public string Percent1 { get; set; } + public decimal Percent { get; set; } + +} diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs index ebe123e4..997e86a9 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs @@ -1406,7 +1406,7 @@ public class Ghre_CourseServices : BaseServices(sql1); + var data = DbAccess.QueryList(sql1); totalCount = await Db.Ado.GetIntAsync("SELECT COUNT(0) from Ghre_CourseScene_V A WHERE 1=1"); @@ -1558,7 +1558,6 @@ public class Ghre_CourseServices : BaseServices() + .Where(x => x.CourseId == id || x.CourseIds.Contains(id.ToString())) + .Select(x => new QuestionErrorRanking + { + Id = x.Id, + QuestionNo = x.QuestionNo, + QuestionContent = x.QuestionContent + }) + .ToListAsync(); + + var questionIds = questionErrorRankings.Select(x => x.Id).ToList(); + + var recordDetails = await Db.Queryable() + .Where(x => x.QuestionId != null && questionIds.Contains(x.QuestionId.Value)) + .ToListAsync(); + + for (int i = 0; i < questionErrorRankings.Count; i++) + { + questionErrorRankings[i].TotalCount = recordDetails.Where(x => x.QuestionId == questionErrorRankings[i].Id).Count(); + questionErrorRankings[i].ErrorCount = recordDetails.Where(x => x.QuestionId == questionErrorRankings[i].Id && x.IsCorrect != true).Count(); + + if (questionErrorRankings[i].ErrorCount > 0 && questionErrorRankings[i].TotalCount > 0) + { + + decimal? Percent1 = questionErrorRankings[i].ErrorCount / questionErrorRankings[i].TotalCount; + questionErrorRankings[i].Percent1 = Percent1.TrimDecimalString(2); + questionErrorRankings[i].Percent = Convert.ToDecimal((Percent1 * 100).TrimDecimalString(0)); + } + } + questionErrorRankings = questionErrorRankings.OrderByDescending(x => x.Percent).ToList(); + data.QuestionErrorRankings = questionErrorRankings; + + #endregion + obj.Data = data; obj.Success = true; obj.Status = 200;