题库对应课程名称可以多选,且同一试题对应不同课程,课程呈现在相同单元格

master
xiaochanghai 3 months ago
parent ff145bb7ed
commit 0bbfc60bfe
  1. 73
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs

@ -570,20 +570,14 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
for (int j = 0; j < editModel.baseData.courseID.Count; j++) for (int j = 0; j < editModel.baseData.courseID.Count; j++)
{ {
var courseID = editModel.baseData.courseID[j]; var courseID = editModel.baseData.courseID[j];
string sql = "SELECT * FROM Ghre_Question WHERE QuestionType='{0}' AND CourseId='{1}' AND QuestionContent ='{2}' AND Id !='{3}' AND IsEnable =1"; string sql = "SELECT * FROM Ghre_Question WHERE QuestionType='{0}' AND CourseIds like'%{1}%' AND QuestionContent ='{2}' AND Id !='{3}' AND IsEnable =1";
sql = string.Format(sql, questionType.type, courseID, questionType.detail.content, Id); sql = string.Format(sql, questionType.type, courseID, questionType.detail.content, Id);
DataTable dt = Db.Ado.GetDataTable(sql); DataTable dt = Db.Ado.GetDataTable(sql);
if (dt.Rows.Count > 0) if (dt.Rows.Count > 0)
{
//var course = await _ghre_CourseServices.QueryById(courseID);
//throw new Exception($"课程【{course.CourseName}】存在相同内容【{questionTypeName}】");
throw new Exception($"题库中存在相同题目"); throw new Exception($"题库中存在相同题目");
} }
}
#endregion #endregion
var data = await base.QueryById(Id); var data = await base.QueryById(Id);
await _ghre_QuestionAnswerServices.Delete(x => x.QuestionId == Id); await _ghre_QuestionAnswerServices.Delete(x => x.QuestionId == Id);
var edit = Mapper.Map(data).ToANew<EditGhre_QuestionInput>(); var edit = Mapper.Map(data).ToANew<EditGhre_QuestionInput>();
@ -593,6 +587,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
edit.DifficultyLevel = questionType.detail.difficulty; edit.DifficultyLevel = questionType.detail.difficulty;
edit.QuestionContent = questionType.detail.content; edit.QuestionContent = questionType.detail.content;
edit.QuestionAnalysis = questionType.detail.RemarkSz; edit.QuestionAnalysis = questionType.detail.RemarkSz;
edit.CourseIds = JsonHelper.ObjToJson(editModel.baseData.courseID);
await base.Update(Id, edit); await base.Update(Id, edit);
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput()
@ -627,42 +622,42 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
// continue; // continue;
//var courseID = editModel.baseData.courseID[j]; //var courseID = editModel.baseData.courseID[j];
var insert = new InsertGhre_QuestionInput(); //var insert = new InsertGhre_QuestionInput();
insert.CourseIds = JsonHelper.ObjToJson(editModel.baseData.courseID); //insert.CourseIds = JsonHelper.ObjToJson(editModel.baseData.courseID);
insert.QuestionType = questionType.type; //insert.QuestionType = questionType.type;
insert.DifficultyLevel = questionType.detail.difficulty; //insert.DifficultyLevel = questionType.detail.difficulty;
insert.QuestionContent = questionType.detail.content; //insert.QuestionContent = questionType.detail.content;
insert.QuestionAnalysis = questionType.detail.RemarkSz; //insert.QuestionAnalysis = questionType.detail.RemarkSz;
insert.QuestionNo = await GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); //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() //insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput()
{ //{
QuestionNo = x.No, // QuestionNo = x.No,
AnswerContent = x.label, // AnswerContent = x.label,
ImageUrl = x.imageUrl, // ImageUrl = x.imageUrl,
ImageWidthPc = x.imgWidthPc, // ImageWidthPc = x.imgWidthPc,
ImageWidthApp = x.imgWidthApp, // ImageWidthApp = x.imgWidthApp,
}).ToList(); //}).ToList();
i = 100; //i = 100;
insertAnswers.ForEach(x => //insertAnswers.ForEach(x =>
{ //{
x.TaxisNo = i; // x.TaxisNo = i;
x.QuestionId = id; // x.QuestionId = id;
if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) // if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse"))
x.IsCorrect = true; // x.IsCorrect = true;
if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) // if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion"))
x.IsCorrect = true; // x.IsCorrect = true;
i = i + 100; // i = i + 100;
}); //});
if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent)).Any()) //if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent)).Any())
throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); // throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!");
if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) //if (!insertAnswers.Where(b => b.IsCorrect == true).Any())
throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); // throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!");
await _ghre_QuestionAnswerServices.Add(insertAnswers); //await _ghre_QuestionAnswerServices.Add(insertAnswers);
//} //}
await Db.Ado.CommitTranAsync(); await Db.Ado.CommitTranAsync();

Loading…
Cancel
Save