|
|
|
@ -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<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
if (name == "page" || name == "pageSize") |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
if (name == "CourseType") |
|
|
|
|
{ |
|
|
|
|
var jsonParam = JsonHelper.JsonToObj<JsonParam>(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<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
filter.pageSize = 10000; |
|
|
|
|
sql += conditions; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(condition)) |
|
|
|
|
sql += " AND " + condition; |
|
|
|
|
var data = await Db.SqlQueryable<Ghre_QuestionDto>(sql) |
|
|
|
|
.OrderBy(filter.orderBy) |
|
|
|
|
.ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); |
|
|
|
|
|
|
|
|
|
var classsIds1 = data.Select(x => x.CourseClassId).Distinct().ToList(); |
|
|
|
|
var classsIds = new List<long>(); |
|
|
|
|
|
|
|
|
|
classsIds1.ForEach(x => |
|
|
|
|
var courseIds = new List<long>(); |
|
|
|
|
data.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
if (!string.IsNullOrWhiteSpace(x)) |
|
|
|
|
{ |
|
|
|
|
var courseClassIds = JsonConvert.DeserializeObject<List<long>>(x); |
|
|
|
|
classsIds = classsIds.Concat(courseClassIds).ToList(); |
|
|
|
|
} |
|
|
|
|
if (x.CourseIds.IsNotEmptyOrNull()) |
|
|
|
|
courseIds.AddRange(JsonHelper.JsonToObj<List<long>>(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<long>(); |
|
|
|
|
|
|
|
|
|
//classsIds1.ForEach(x => |
|
|
|
|
//{ |
|
|
|
|
// if (!string.IsNullOrWhiteSpace(x)) |
|
|
|
|
// { |
|
|
|
|
// var courseClassIds = JsonConvert.DeserializeObject<List<long>>(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<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
x.QuestionTypeLabel = await GetParaLabel("QuestionType", x.QuestionType); |
|
|
|
|
if (!string.IsNullOrEmpty(x.QuestionContent)) |
|
|
|
|
x.QuestionContent = WebUtility.HtmlDecode(x.QuestionContent); |
|
|
|
|
var courseClass = classs.Where(a => 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<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
|
|
|
|
|
#region PageData |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var answerList = new List<FromGhre_QuestionQuestionAnswerList> |
|
|
|
|
{ |
|
|
|
|
new FromGhre_QuestionQuestionAnswerList() |
|
|
|
@ -370,7 +414,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
var question = await base.QueryById(Id); |
|
|
|
|
data.PageData.questionType.ForEach(x => x.isActive = 0); |
|
|
|
|
data.PageData.baseData.questionNo = question.QuestionNo; |
|
|
|
|
data.PageData.baseData.courseID.Add(question.CourseId); |
|
|
|
|
data.PageData.baseData.courseID = JsonHelper.JsonToObj<List<long?>>(question.CourseIds); |
|
|
|
|
data.PageData.baseData.CreateDataInfo = question.CreateDataInfo; |
|
|
|
|
data.PageData.baseData.UpdateDataInfo = question.UpdateDataInfo; |
|
|
|
|
|
|
|
|
@ -442,47 +486,48 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
throw new Exception($"题库中存在相同题目"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
for (int j = 0; j < insertModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var courseID = insertModel.baseData.courseID[j]; |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
insert.CourseId = courseID; |
|
|
|
|
#endregion |
|
|
|
|
//for (int j = 0; j < insertModel.baseData.courseID.Count; j++) |
|
|
|
|
//{ |
|
|
|
|
//var courseID = insertModel.baseData.courseID[j]; |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
//insert.CourseId = courseID; |
|
|
|
|
insert.CourseIds = JsonHelper.ObjToJson(insertModel.baseData.courseID); |
|
|
|
|
|
|
|
|
|
insert.QuestionType = questionType.type; |
|
|
|
|
insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
insert.QuestionContent = questionType.detail.content; |
|
|
|
|
insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
insert.QuestionNo = await GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
insert.QuestionType = questionType.type; |
|
|
|
|
insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
insert.QuestionContent = questionType.detail.content; |
|
|
|
|
insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
insert.QuestionNo = await GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
|
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
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<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
|
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
|
|
|
|
|
for (int j = 0; j < editModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
if (j == 0) |
|
|
|
|
continue; |
|
|
|
|
//for (int j = 0; j < editModel.baseData.courseID.Count; j++) |
|
|
|
|
//{ |
|
|
|
|
// if (j == 0) |
|
|
|
|
// continue; |
|
|
|
|
|
|
|
|
|
var courseID = editModel.baseData.courseID[j]; |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
insert.CourseId = courseID; |
|
|
|
|
//var courseID = editModel.baseData.courseID[j]; |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
insert.CourseIds = JsonHelper.ObjToJson(editModel.baseData.courseID); |
|
|
|
|
|
|
|
|
|
insert.QuestionType = questionType.type; |
|
|
|
|
insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
insert.QuestionContent = questionType.detail.content; |
|
|
|
|
insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
insert.QuestionNo = await GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
insert.QuestionType = questionType.type; |
|
|
|
|
insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
insert.QuestionContent = questionType.detail.content; |
|
|
|
|
insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
insert.QuestionNo = await GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
|
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
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("更新成功!"); |
|
|
|
|