diff --git a/Tiobon.Core.Api/appsettings.json b/Tiobon.Core.Api/appsettings.json index c67ffd5f..3e44c36b 100644 --- a/Tiobon.Core.Api/appsettings.json +++ b/Tiobon.Core.Api/appsettings.json @@ -108,7 +108,7 @@ "DBType": 1, "Enabled": 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" }, { diff --git a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs index 57517ce8..e571e06e 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs @@ -836,108 +836,104 @@ public class Ghre_QuestionServices : BaseServices(); + var filds = new List + { + "课程", + "题目内容", + "课程", + "解析", + "难度", + "课程" + }; for (int i = 0; i < dt.Rows.Count; i++) { - var comments = new List(); - - if (!dt.Columns.Contains("课程(必填)")) + comments = new List(); + for (int j = 0; j < filds.Count; j++) { - comments.Add("未查询到【课程(必填)】列!"); - data.ErrorCount++; - dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); - isExistError = true; - continue; + if (!dt.Columns.Contains(filds[j])) + comments.Add("未查询到【" + filds[j] + "】列!"); } + 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("未查询到【题目内容(必填)】列!"); - data.ErrorCount++; - dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); - isExistError = true; - continue; + if (!await _ghre_CourseServices.AnyAsync(x => x.CourseName == courseName)) + comments.Add("课程不存在,请修正!"); + else + { + 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 (!dt.Columns.Contains("正确答案(必填)")) - { - comments.Add("未查询到【正确答案(必填)】列!"); - data.ErrorCount++; - dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); - isExistError = true; - continue; - } + correctAnswer = dt.Rows[i]["正确答案"].ToString(); + if (string.IsNullOrWhiteSpace(correctAnswer) && questionType != "Completion" && questionType != "ShortAnswer") + comments.Add("正确答案未标记!"); + var difficultyLevel = dt.Rows[i]["难度"].ToString() ?? "普通"; + var questionAnalysis = dt.Rows[i]["解析"].ToString(); + if (string.IsNullOrWhiteSpace(difficultyLevel)) + comments.Add("难易程度必填!"); + if (string.IsNullOrWhiteSpace(questionAnalysis)) + comments.Add("题目解析必填!"); - 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++; - dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); - isExistError = true; - continue; - } - 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.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(); - var questionContent = dt.Rows[i]["题目内容(必填)"].ToString(); + for (int i = 0; i < dt.Rows.Count; i++) + { + comments = new List(); + var courseName = dt.Rows[i]["课程"].ToString(); + var questionContent = dt.Rows[i]["题目内容"].ToString(); var correctAnswer = string.Empty; if (questionType != "Completion" && questionType != "ShortAnswer") - correctAnswer = dt.Rows[i]["正确答案(必填)"].ToString(); + correctAnswer = dt.Rows[i]["正确答案"].ToString(); var questionAnalysis = 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; - if (!string.IsNullOrEmpty(courseName)) - { - course = await _ghre_CourseServices.QuerySingleDto(x => x.CourseName == courseName); - if (course is null) - { - comments.Add("课程不存在,请修正!"); - continue; - } - } + 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); 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() { CourseId = course?.Id, @@ -1092,7 +1088,6 @@ public class Ghre_QuestionServices : BaseServices