|
|
|
@ -804,8 +804,8 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
"单选题", |
|
|
|
|
"多选题", |
|
|
|
|
"判断题", |
|
|
|
|
//"填空题", |
|
|
|
|
//"简答题", |
|
|
|
|
"填空题", |
|
|
|
|
"简答题", |
|
|
|
|
}; |
|
|
|
|
var answers = new List<string> |
|
|
|
|
{ |
|
|
|
@ -830,10 +830,11 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
|
|
|
|
|
// NPOIHelper.ExportExcel(dt, null, x, path + id1 + extension); |
|
|
|
|
//}); |
|
|
|
|
|
|
|
|
|
types.ForEach(async x => |
|
|
|
|
for (int jj = 0; jj < types.Count; jj++) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
var x = types[jj]; |
|
|
|
|
|
|
|
|
|
string questionType = ConvertQuestionType1(x); |
|
|
|
|
DataTable dt = NPOIHelper.ImportExcel(filepath, x); |
|
|
|
|
if (dt.Columns["Comments"] == null) |
|
|
|
@ -844,7 +845,10 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
var comments = new List<string>(); |
|
|
|
|
var courseName = dt.Rows[i]["课程(必填)"].ToString(); |
|
|
|
|
var questionContent = dt.Rows[i]["题目内容(必填)"].ToString(); |
|
|
|
|
var correctAnswer = dt.Rows[i]["正确答案(必填)"].ToString(); |
|
|
|
|
var correctAnswer = string.Empty; |
|
|
|
|
if (questionType != "Completion" && questionType != "ShortAnswer") |
|
|
|
|
correctAnswer = dt.Rows[i]["正确答案(必填)"].ToString(); |
|
|
|
|
|
|
|
|
|
var questionAnalysis = dt.Rows[i]["解析"].ToString(); |
|
|
|
|
var difficultyLevel = dt.Rows[i]["难度"].ToString() ?? "普通"; |
|
|
|
|
if (string.IsNullOrEmpty(questionContent)) |
|
|
|
@ -856,20 +860,24 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(courseName)) |
|
|
|
|
comments.Add("课程为必填项!"); |
|
|
|
|
if (string.IsNullOrWhiteSpace(correctAnswer)) |
|
|
|
|
if (string.IsNullOrWhiteSpace(correctAnswer) && questionType != "Completion" && questionType != "ShortAnswer") |
|
|
|
|
comments.Add("正确答案未标记!"); |
|
|
|
|
if (string.IsNullOrWhiteSpace(difficultyLevel)) |
|
|
|
|
comments.Add("难易程度必填!"); |
|
|
|
|
if (string.IsNullOrWhiteSpace(questionAnalysis)) |
|
|
|
|
comments.Add("题目解析必填!"); |
|
|
|
|
|
|
|
|
|
var course = await _ghre_CourseServices.QuerySingleDto(x => x.CourseName == courseName); |
|
|
|
|
Ghre_CourseDto course = null; |
|
|
|
|
if (!string.IsNullOrEmpty(courseName)) |
|
|
|
|
{ |
|
|
|
|
course = await _ghre_CourseServices.QuerySingleDto(x => x.CourseName == courseName); |
|
|
|
|
if (course is null) |
|
|
|
|
comments.Add("课程不存在,请修正!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var insert = new InsertGhre_QuestionInput() |
|
|
|
|
{ |
|
|
|
|
CourseId = course.Id, |
|
|
|
|
CourseId = course?.Id, |
|
|
|
|
QuestionNo = await GenerateContinuousSequence(questionType.Substring(0, 1)), |
|
|
|
|
DifficultyLevel = ConvertDifficultyLevel1(difficultyLevel), |
|
|
|
|
QuestionType = questionType, |
|
|
|
@ -940,6 +948,63 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
}); |
|
|
|
|
#endregion |
|
|
|
|
} |
|
|
|
|
else if (questionType == "Completion") |
|
|
|
|
{ |
|
|
|
|
questionContent = questionContent.Replace("()", "()"); |
|
|
|
|
|
|
|
|
|
var completionCount = 0; |
|
|
|
|
for (int ii = 1; ii < 11; ii++) |
|
|
|
|
{ |
|
|
|
|
var answer = dt.Rows[i]["答案" + ii].ToString(); |
|
|
|
|
if (!string.IsNullOrWhiteSpace(answer)) |
|
|
|
|
{ |
|
|
|
|
completionCount++; |
|
|
|
|
int index = questionContent.IndexOf("()"); |
|
|
|
|
if (index > -1) |
|
|
|
|
{ |
|
|
|
|
if (questionContent.Length > index + 2) |
|
|
|
|
{ |
|
|
|
|
if (questionContent.Substring(index + 2, 2) == "()") |
|
|
|
|
questionContent = questionContent.Substring(0, index) + "____、" + questionContent.Substring(index + 2); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
questionContent = questionContent.Substring(0, index) + "____" + questionContent.Substring(index + 2); |
|
|
|
|
|
|
|
|
|
insertAnswers.Add(new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
TaxisNo = ii * 100, |
|
|
|
|
QuestionNo = answer, |
|
|
|
|
//QuestionId = id, |
|
|
|
|
AnswerContent = answer, |
|
|
|
|
IsCorrect = true |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (completionCount != insertAnswers.Count) |
|
|
|
|
comments.Add("题目内容填空个数与答案个数不匹配!"); |
|
|
|
|
else |
|
|
|
|
insert.QuestionContent = questionContent; |
|
|
|
|
} |
|
|
|
|
else if (questionType == "ShortAnswer") |
|
|
|
|
{ |
|
|
|
|
for (int ii = 1; ii < 11; ii++) |
|
|
|
|
{ |
|
|
|
|
var answer = dt.Rows[i]["关键词" + ii].ToString(); |
|
|
|
|
if (!string.IsNullOrWhiteSpace(answer)) |
|
|
|
|
{ |
|
|
|
|
insertAnswers.Add(new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
TaxisNo = ii * 100, |
|
|
|
|
QuestionNo = answer, |
|
|
|
|
//QuestionId = id, |
|
|
|
|
AnswerContent = answer, |
|
|
|
|
IsCorrect = true |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (comments.Any()) |
|
|
|
|
{ |
|
|
|
|
data.ErrorCount++; |
|
|
|
@ -950,7 +1015,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
data.SuccessCount++; |
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
id = await base.Add(insert); |
|
|
|
|
insertAnswers.ForEach(x => x.QuestionId = id); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
} |
|
|
|
@ -958,6 +1023,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
dt.Rows[i]["Comments"] = "试题在系统中已存在!"; |
|
|
|
|
data.ErrorCount++; |
|
|
|
|
isExistError = true; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
@ -970,12 +1036,9 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
NPOIHelper.ExportExcel(dt, null, x, physicsPath + errorFileName); |
|
|
|
|
data.filePath = errorFileName; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isExistError) |
|
|
|
|
return ServiceResult<ExcelData>.OprateFailed("导入文件存在错误,请下载后查看!", data); |
|
|
|
|
else |
|
|
|
|
return ServiceResult<ExcelData>.OprateSuccess("导入成功!"); |
|
|
|
|
return ServiceResult<ExcelData>.OprateSuccess("导入成功!", data); |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
} |