diff --git a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs index d57f07cd..ee7eefdd 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs @@ -1,5 +1,4 @@ -using Microsoft.IdentityModel.Tokens; -using NPOI.HSSF.UserModel; +using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.SS.Util; using NPOI.XSSF.UserModel; @@ -188,6 +187,44 @@ 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); @@ -196,25 +233,33 @@ public class Ghre_QuestionServices : BaseServices(sql) .OrderBy(filter.orderBy) .ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); - var classsIds1 = data.Select(x => x.CourseClassId).Distinct().ToList(); - var classsIds = new List(); - - classsIds1.ForEach(x => + var courseIds = new List(); + data.ForEach(x => { - if (!string.IsNullOrWhiteSpace(x)) - { - var courseClassIds = JsonConvert.DeserializeObject>(x); - classsIds = classsIds.Concat(courseClassIds).ToList(); - } + if (x.CourseIds.IsNotEmptyOrNull()) + courseIds.AddRange(JsonHelper.JsonToObj>(x.CourseIds)); }); - classsIds = classsIds.Distinct().ToList(); - var classs = await _ghre_CourseClassServices.Query(x => classsIds.Contains(x.Id)); + 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)); data.ForEach(async x => { @@ -222,8 +267,8 @@ public class Ghre_QuestionServices : BaseServices x.CourseClassId.Contains(a.Id.ToString())).ToList(); - x.CourseType = string.Join(",", courseClass.Select(a => a.ClassName + " (" + a.ClassNo + ")")); + var courseClass = courses.Where(a => x.CourseIds.Contains(a.Id.ToString())).ToList(); + x.CourseName = string.Join(",", courseClass.Select(a => a.CourseName + " (" + a.CourseNo + ")")); }); @@ -267,7 +312,6 @@ public class Ghre_QuestionServices : BaseServices { new FromGhre_QuestionQuestionAnswerList() @@ -370,7 +414,7 @@ public class Ghre_QuestionServices : BaseServices x.isActive = 0); data.PageData.baseData.questionNo = question.QuestionNo; - data.PageData.baseData.courseID.Add(question.CourseId); + data.PageData.baseData.courseID = JsonHelper.JsonToObj>(question.CourseIds); data.PageData.baseData.CreateDataInfo = question.CreateDataInfo; data.PageData.baseData.UpdateDataInfo = question.UpdateDataInfo; @@ -442,47 +486,48 @@ 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; - }); - - 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("新增成功!"); } @@ -576,49 +621,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" ? "关键词未填写!" : "正确答案未标记!"); - - 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("更新成功!");