diff --git a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs index 5bdfde09..d57f07cd 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs @@ -1,4 +1,5 @@ -using NPOI.HSSF.UserModel; +using Microsoft.IdentityModel.Tokens; +using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.SS.Util; using NPOI.XSSF.UserModel; @@ -187,44 +188,6 @@ public class Ghre_QuestionServices : BaseServices(value); - - if (jsonParam.columnValue != null) - { - - switch (jsonParam.operationKey) - { - case "Include": - conditions += @$" AND EXISTS - (SELECT 1 - FROM Ghre_Course Course - WHERE IsEnable = 1 - AND {jsonParam.columnValue} IN - (SELECT value FROM openjson (CourseClassId)) - AND Course.Id IN - (SELECT value FROM openjson (A.CourseIDs)))"; - break; - case "NotInclude": - if (jsonParam.columnValue != null) - conditions += @$" AND NOT EXISTS - (SELECT 1 - FROM Ghre_Course Course - WHERE IsEnable = 1 - AND {jsonParam.columnValue} IN - (SELECT value FROM openjson (CourseClassId)) - AND Course.Id IN - (SELECT value FROM openjson (A.CourseIDs)))"; - break; - break; - default: - break; - } - } - continue; - } - if (!string.IsNullOrWhiteSpace(value)) conditions = DealConditions(conditions, name, value); @@ -233,33 +196,25 @@ public class Ghre_QuestionServices : BaseServices(sql) .OrderBy(filter.orderBy) .ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); - var courseIds = new List(); - data.ForEach(x => + var classsIds1 = data.Select(x => x.CourseClassId).Distinct().ToList(); + var classsIds = new List(); + + classsIds1.ForEach(x => { - if (x.CourseIds.IsNotEmptyOrNull()) - courseIds.AddRange(JsonHelper.JsonToObj>(x.CourseIds)); + if (!string.IsNullOrWhiteSpace(x)) + { + var courseClassIds = JsonConvert.DeserializeObject>(x); + classsIds = classsIds.Concat(courseClassIds).ToList(); + } }); - courseIds = courseIds.Distinct().ToList(); - //var classsIds1 = data.Select(x => x.CourseClassId).Distinct().ToList(); - //var classsIds = new List(); - - //classsIds1.ForEach(x => - //{ - // if (!string.IsNullOrWhiteSpace(x)) - // { - // var courseClassIds = JsonConvert.DeserializeObject>(x); - // classsIds = classsIds.Concat(courseClassIds).ToList(); - // } - //}); - //classsIds = classsIds.Distinct().ToList(); - var courses = await _ghre_CourseServices.Query(x => courseIds.Contains(x.Id)); + classsIds = classsIds.Distinct().ToList(); + var classs = await _ghre_CourseClassServices.Query(x => classsIds.Contains(x.Id)); data.ForEach(async x => { @@ -267,8 +222,8 @@ public class Ghre_QuestionServices : BaseServices x.CourseIds.Contains(a.Id.ToString())).ToList(); - x.CourseName = string.Join(",", courseClass.Select(a => a.CourseName + " (" + a.CourseNo + ")")); + var courseClass = classs.Where(a => x.CourseClassId.Contains(a.Id.ToString())).ToList(); + x.CourseType = string.Join(",", courseClass.Select(a => a.ClassName + " (" + a.ClassNo + ")")); }); @@ -312,6 +267,7 @@ public class Ghre_QuestionServices : BaseServices { new FromGhre_QuestionQuestionAnswerList() @@ -414,7 +370,7 @@ public class Ghre_QuestionServices : BaseServices x.isActive = 0); data.PageData.baseData.questionNo = question.QuestionNo; - data.PageData.baseData.courseID = JsonHelper.JsonToObj>(question.CourseIds); + data.PageData.baseData.courseID.Add(question.CourseId); data.PageData.baseData.CreateDataInfo = question.CreateDataInfo; data.PageData.baseData.UpdateDataInfo = question.UpdateDataInfo; @@ -486,48 +442,47 @@ public class Ghre_QuestionServices : BaseServices new InsertGhre_QuestionAnswerInput() - { - QuestionNo = x.No, - AnswerContent = x.label, - ImageUrl = x.imageUrl, - ImageWidthPc = x.imgWidthPc, - ImageWidthApp = x.imgWidthApp, - }).ToList(); - int i = 100; - insertAnswers.ForEach(x => - { - x.TaxisNo = i; - x.QuestionId = id; - if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) - x.IsCorrect = true; - if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) - x.IsCorrect = true; - i = i + 100; - }); + var id = await base.Add(insert); - if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent) && string.IsNullOrWhiteSpace(b.ImageUrl)).Any()) - throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); - if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) - throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); - await _ghre_QuestionAnswerServices.Add(insertAnswers); - //} + var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() + { + QuestionNo = x.No, + AnswerContent = x.label, + ImageUrl = x.imageUrl, + ImageWidthPc = x.imgWidthPc, + ImageWidthApp = x.imgWidthApp, + }).ToList(); + int i = 100; + insertAnswers.ForEach(x => + { + x.TaxisNo = i; + x.QuestionId = id; + if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) + x.IsCorrect = true; + if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) + x.IsCorrect = true; + i = i + 100; + }); + + if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent) && string.IsNullOrWhiteSpace(b.ImageUrl)).Any()) + throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); + if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) + throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); + await _ghre_QuestionAnswerServices.Add(insertAnswers); + } await Db.Ado.CommitTranAsync(); return ServiceResult.OprateSuccess("新增成功!"); } @@ -621,49 +576,49 @@ public class Ghre_QuestionServices : BaseServices new InsertGhre_QuestionAnswerInput() - { - QuestionNo = x.No, - AnswerContent = x.label, - ImageUrl = x.imageUrl, - ImageWidthPc = x.imgWidthPc, - ImageWidthApp = x.imgWidthApp, - }).ToList(); - i = 100; - insertAnswers.ForEach(x => - { - x.TaxisNo = i; - x.QuestionId = id; - if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) - x.IsCorrect = true; - if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) - x.IsCorrect = true; - i = i + 100; - }); - if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent)).Any()) - throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); - if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) - throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); + var id = await base.Add(insert); - await _ghre_QuestionAnswerServices.Add(insertAnswers); - //} + insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() + { + QuestionNo = x.No, + AnswerContent = x.label, + ImageUrl = x.imageUrl, + ImageWidthPc = x.imgWidthPc, + ImageWidthApp = x.imgWidthApp, + }).ToList(); + i = 100; + insertAnswers.ForEach(x => + { + x.TaxisNo = i; + x.QuestionId = id; + if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) + x.IsCorrect = true; + if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) + x.IsCorrect = true; + i = i + 100; + }); + if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent)).Any()) + throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); + if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) + throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); + + await _ghre_QuestionAnswerServices.Add(insertAnswers); + } await Db.Ado.CommitTranAsync(); return ServiceResult.OprateSuccess("更新成功!");