题库模板导入对应课程按照一笔题目对一笔课程导入,相同试题(题目类型、难易程度、题目内容一致才定义为相同)对应不同课程时成功导入后要在同一个单元格中合并显示

master
xiaochanghai 3 months ago
parent 20b3eae8df
commit 8ab14bc131
  1. 34
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs

@ -879,6 +879,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
var x = types[jj]; var x = types[jj];
string questionType = ConvertQuestionType1(x); string questionType = ConvertQuestionType1(x);
string difficultyLevel = string.Empty;
try try
{ {
var dt = NPOIHelper.ImportExcel(filepath, x); var dt = NPOIHelper.ImportExcel(filepath, x);
@ -913,6 +914,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
if (string.IsNullOrEmpty(questionContent)) if (string.IsNullOrEmpty(questionContent))
comments.Add("题目内容为必填项!"); comments.Add("题目内容为必填项!");
if (courseName.IsNullOrEmpty()) if (courseName.IsNullOrEmpty())
comments.Add("课程为必填项!"); comments.Add("课程为必填项!");
else else
@ -936,7 +938,6 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
correctAnswer = dt.Rows[i]["正确答案"].ToString(); correctAnswer = dt.Rows[i]["正确答案"].ToString();
if (string.IsNullOrWhiteSpace(correctAnswer) && questionType != "Completion" && questionType != "ShortAnswer") if (string.IsNullOrWhiteSpace(correctAnswer) && questionType != "Completion" && questionType != "ShortAnswer")
comments.Add("正确答案未标记!"); comments.Add("正确答案未标记!");
var difficultyLevel = dt.Rows[i]["难度"].ToString() ?? "普通";
var questionAnalysis = dt.Rows[i]["解析"].ToString(); var questionAnalysis = dt.Rows[i]["解析"].ToString();
if (string.IsNullOrWhiteSpace(difficultyLevel)) if (string.IsNullOrWhiteSpace(difficultyLevel))
comments.Add("难易程度必填!"); comments.Add("难易程度必填!");
@ -971,19 +972,24 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
correctAnswer = dt.Rows[i]["正确答案"].ToString(); correctAnswer = dt.Rows[i]["正确答案"].ToString();
var questionAnalysis = dt.Rows[i]["解析"].ToString(); var questionAnalysis = dt.Rows[i]["解析"].ToString();
var difficultyLevel = dt.Rows[i]["难度"].ToString() ?? "普通"; difficultyLevel = dt.Rows[i]["难度"].ToString() ?? "普通";
difficultyLevel = ConvertDifficultyLevel1(difficultyLevel);
Ghre_CourseDto course = await _ghre_CourseServices.QuerySingleDto(x => x.CourseName == courseName); Ghre_CourseDto course = await _ghre_CourseServices.QuerySingleDto(x => x.CourseName == courseName);
var question = await base.Query(x => x.QuestionContent == questionContent && x.QuestionType == questionType && x.CourseId == course.Id); var question = await base.Query(x =>
x.QuestionContent == questionContent &&
x.DifficultyLevel == difficultyLevel &&
x.QuestionType == questionType);
if (!question.Any()) if (!question.Any())
{ {
var insert = new InsertGhre_QuestionInput() var insert = new InsertGhre_QuestionInput()
{ {
CourseId = course?.Id, CourseId = course?.Id,
CourseIds = "[" + course?.Id + "]",
QuestionNo = await GenerateContinuousSequence(questionType.Substring(0, 1)), QuestionNo = await GenerateContinuousSequence(questionType.Substring(0, 1)),
DifficultyLevel = ConvertDifficultyLevel1(difficultyLevel), DifficultyLevel = difficultyLevel,
QuestionType = questionType, QuestionType = questionType,
QuestionContent = questionContent, QuestionContent = questionContent,
QuestionAnalysis = questionAnalysis QuestionAnalysis = questionAnalysis
@ -1126,12 +1132,30 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
} }
} }
else else
{
if (question.Where(x => x.CourseIds != null && x.CourseIds.Contains(course.Id.ObjToString())).Any())
{ {
dt.Rows[i]["Comments"] = "试题在系统中已存在!"; dt.Rows[i]["Comments"] = "试题在系统中已存在!";
data.ErrorCount++; data.ErrorCount++;
isExistError = true; isExistError = true;
continue; continue;
} }
else
{
var coursIds = question.FirstOrDefault()?.CourseIds;
var coursIds1 = new List<long>();
if (coursIds.IsNotEmptyOrNull())
coursIds1 = JsonHelper.JsonToObj<List<long>>(coursIds);
coursIds1.Add(course.Id);
var question1 = question.FirstOrDefault();
question1.CourseIds = JsonHelper.ObjToJson(coursIds1);
await base.Update(question1, ["CourseIds"]);
}
}
} }
if (isExistError) if (isExistError)

Loading…
Cancel
Save