课程Excel导入优化

master
xiaochanghai 5 months ago
parent 550f1f2332
commit 5f67916b15
  1. 2
      Tiobon.Core.Api/appsettings.json
  2. 145
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs

@ -108,7 +108,7 @@
"DBType": 1, "DBType": 1,
"Enabled": true, "Enabled": true,
"Connection": "Data Source=47.99.54.186;User ID=GHR;Password=Tiobon20190101;Database=GHR30;Encrypt=True;TrustServerCertificate=True;", "Connection": "Data Source=47.99.54.186;User ID=GHR;Password=Tiobon20190101;Database=GHR30;Encrypt=True;TrustServerCertificate=True;",
//"Connection": "Data Source=116.204.98.209;User ID=Tiobon;Password=&($!4UGUyU#$2sp9O;Database=Tiobon;Encrypt=True;TrustServerCertificate=True;", "Connection1": "Data Source=47.99.54.186;User ID=GHR;Password=Tiobon20190101;Database=GHR5_TY;Encrypt=True;TrustServerCertificate=True;",
"ProviderName": "System.Data.SqlClient" "ProviderName": "System.Data.SqlClient"
}, },
{ {

@ -836,108 +836,104 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
string questionType = ConvertQuestionType1(x); string questionType = ConvertQuestionType1(x);
try try
{ {
DataTable dt = NPOIHelper.ImportExcel(filepath, x); var dt = NPOIHelper.ImportExcel(filepath, x);
if (dt.Columns["Comments"] == null) if (dt.Columns["Comments"] == null)
dt.Columns.Add("Comments", typeof(string)); dt.Columns.Add("Comments", typeof(string));
var comments = new List<string>();
var filds = new List<string>
{
"课程",
"题目内容",
"课程",
"解析",
"难度",
"课程"
};
for (int i = 0; i < dt.Rows.Count; i++) for (int i = 0; i < dt.Rows.Count; i++)
{ {
var comments = new List<string>(); comments = new List<string>();
for (int j = 0; j < filds.Count; j++)
if (!dt.Columns.Contains("课程(必填)"))
{ {
comments.Add("未查询到【课程(必填)】列!"); if (!dt.Columns.Contains(filds[j]))
data.ErrorCount++; comments.Add("未查询到【" + filds[j] + "】列!");
dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
isExistError = true;
continue;
} }
if (questionType != "Completion" && questionType != "ShortAnswer")
if (!dt.Columns.Contains("正确答案"))
comments.Add("未查询到【正确答案】列!");
var courseName = dt.Rows[i]["课程"].ToString();
var questionContent = dt.Rows[i]["题目内容"].ToString();
if (string.IsNullOrEmpty(questionContent))
comments.Add("题目内容为必填项!");
if (!dt.Columns.Contains("题目内容(必填)")) if (courseName.IsNullOrEmpty())
comments.Add("课程为必填项!");
else
{ {
comments.Add("未查询到【题目内容(必填)】列!"); if (!await _ghre_CourseServices.AnyAsync(x => x.CourseName == courseName))
data.ErrorCount++; comments.Add("课程不存在,请修正!");
dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); else
isExistError = true; {
continue; Ghre_CourseDto course = await _ghre_CourseServices.QuerySingleDto(x => x.CourseName == courseName);
if (course != null)
{
var question = await base.Query(x => x.QuestionContent == questionContent && x.QuestionType == questionType && x.CourseId == course.Id);
if (question.Any())
comments.Add("试题在系统中已存在!");
}
}
} }
var correctAnswer = string.Empty;
if (questionType != "Completion" && questionType != "ShortAnswer") if (questionType != "Completion" && questionType != "ShortAnswer")
if (!dt.Columns.Contains("正确答案(必填)")) correctAnswer = dt.Rows[i]["正确答案"].ToString();
{ if (string.IsNullOrWhiteSpace(correctAnswer) && questionType != "Completion" && questionType != "ShortAnswer")
comments.Add("未查询到【正确答案(必填)】列!"); comments.Add("正确答案未标记!");
data.ErrorCount++; var difficultyLevel = dt.Rows[i]["难度"].ToString() ?? "普通";
dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); var questionAnalysis = dt.Rows[i]["解析"].ToString();
isExistError = true; if (string.IsNullOrWhiteSpace(difficultyLevel))
continue; comments.Add("难易程度必填!");
} if (string.IsNullOrWhiteSpace(questionAnalysis))
comments.Add("题目解析必填!");
if (!dt.Columns.Contains("课程(必填)")) if (comments.Any())
{
comments.Add("未查询到【课程(必填)】列!");
data.ErrorCount++;
dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
isExistError = true;
continue;
}
if (!dt.Columns.Contains("解析"))
{
comments.Add("未查询到【解析】列!");
data.ErrorCount++;
dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
isExistError = true;
continue;
}
if (!dt.Columns.Contains("难度"))
{ {
comments.Add("未查询到【难度】列!");
data.ErrorCount++; data.ErrorCount++;
dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
isExistError = true; isExistError = true;
continue; if (dt.Rows[i]["Comments"].ToString().IsNullOrEmpty())
dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
else
dt.Rows[i]["Comments"] += string.Join(";", comments.Select(a => a));
} }
}
//if (isExistError)
//{
// NPOIHelper.ExportExcel(dt, null, x, physicsPath + errorFileName);
// data.filePath = "/Advanced" + errorFileName;
// continue;
//}
var courseName = dt.Rows[i]["课程(必填)"].ToString(); for (int i = 0; i < dt.Rows.Count; i++)
var questionContent = dt.Rows[i]["题目内容(必填)"].ToString(); {
comments = new List<string>();
var courseName = dt.Rows[i]["课程"].ToString();
var questionContent = dt.Rows[i]["题目内容"].ToString();
var correctAnswer = string.Empty; var correctAnswer = string.Empty;
if (questionType != "Completion" && questionType != "ShortAnswer") if (questionType != "Completion" && questionType != "ShortAnswer")
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() ?? "普通"; var difficultyLevel = dt.Rows[i]["难度"].ToString() ?? "普通";
if (string.IsNullOrEmpty(questionContent))
comments.Add("题目内容为必填项!");
if (courseName.IsNullOrEmpty())
{
comments.Add("课程为必填项!");
continue;
}
Ghre_CourseDto course = null; Ghre_CourseDto course = await _ghre_CourseServices.QuerySingleDto(x => x.CourseName == courseName);
if (!string.IsNullOrEmpty(courseName))
{
course = await _ghre_CourseServices.QuerySingleDto(x => x.CourseName == courseName);
if (course is null)
{
comments.Add("课程不存在,请修正!");
continue;
}
}
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.QuestionType == questionType && x.CourseId == course.Id);
if (!question.Any()) if (!question.Any())
{ {
if (string.IsNullOrEmpty(courseName))
comments.Add("课程为必填项!");
if (string.IsNullOrWhiteSpace(correctAnswer) && questionType != "Completion" && questionType != "ShortAnswer")
comments.Add("正确答案未标记!");
if (string.IsNullOrWhiteSpace(difficultyLevel))
comments.Add("难易程度必填!");
if (string.IsNullOrWhiteSpace(questionAnalysis))
comments.Add("题目解析必填!");
var insert = new InsertGhre_QuestionInput() var insert = new InsertGhre_QuestionInput()
{ {
CourseId = course?.Id, CourseId = course?.Id,
@ -1092,7 +1088,6 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
isExistError = true; isExistError = true;
continue; continue;
} }
} }
if (isExistError) if (isExistError)
@ -1101,7 +1096,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
data.filePath = "/Advanced" + errorFileName; data.filePath = "/Advanced" + errorFileName;
} }
} }
catch (Exception) catch (Exception E)
{ {
} }
} }

Loading…
Cancel
Save