diff --git a/Tiobon.Core.Api/Controllers/Base/BaseController.cs b/Tiobon.Core.Api/Controllers/Base/BaseController.cs index 68e37b81..85726353 100644 --- a/Tiobon.Core.Api/Controllers/Base/BaseController.cs +++ b/Tiobon.Core.Api/Controllers/Base/BaseController.cs @@ -223,9 +223,9 @@ public class BaseController> ImportExcel(IFormFile file) + public async Task> ImportExcel(IFormFile file) { - var data = (await InvokeServiceAsync("ImportExcel", [file])) as ServiceResult; + var data = (await InvokeServiceAsync("ImportExcel", [file])) as ServiceResult; return data; } #endregion diff --git a/Tiobon.Core.Api/wwwroot/files/ExcelTemplate/Ghre_Question.xlsx b/Tiobon.Core.Api/wwwroot/files/ExcelTemplate/Ghre_Question.xlsx index b13f1d76..91b61562 100644 Binary files a/Tiobon.Core.Api/wwwroot/files/ExcelTemplate/Ghre_Question.xlsx and b/Tiobon.Core.Api/wwwroot/files/ExcelTemplate/Ghre_Question.xlsx differ diff --git a/Tiobon.Core.Common/Helper/NPOIHelper.cs b/Tiobon.Core.Common/Helper/NPOIHelper.cs index 7993eac4..4301bb1f 100644 --- a/Tiobon.Core.Common/Helper/NPOIHelper.cs +++ b/Tiobon.Core.Common/Helper/NPOIHelper.cs @@ -285,7 +285,7 @@ public class NPOIHelper for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) { IRow row = sheet.GetRow(i); - if (row.GetCell(row.FirstCellNum) != null && row.GetCell(row.FirstCellNum).ToString().Length > 0) + //if (row.GetCell(row.FirstCellNum) != null && row.GetCell(row.FirstCellNum).ToString().Length > 0) //if (row.GetCell(row.FirstCellNum) != null) { DataRow dataRow = dt.NewRow(); diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index 3798b30c..d35f2a04 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -851,8 +851,8 @@ public partial class CommonServices : BaseServices>, ICommon result.DT_Procedure.IUDProcedure = dt.Rows[0]["IUDProcedure"].ToString(); if (!string.IsNullOrWhiteSpace(result.DT_Procedure.EditProcedure)) { - result.DT_Procedure.ImportExcel = result.DT_Procedure.EditProcedure.Replace("QueryForm", "ImportExcel"); - result.DT_Procedure.DownloadExcel = result.DT_Procedure.EditProcedure.Replace("QueryForm", "DownloadExcel"); + result.DT_Procedure.ImportExcel = "/api" + result.DT_Procedure.EditProcedure.Replace("QueryForm", "ImportExcel"); + result.DT_Procedure.DownloadExcel = "/api" + result.DT_Procedure.EditProcedure.Replace("QueryForm", "DownloadExcel"); } } diff --git a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs index 89babff2..46cad571 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs @@ -804,8 +804,8 @@ public class Ghre_QuestionServices : BaseServices { @@ -830,10 +830,11 @@ public class Ghre_QuestionServices : BaseServices + 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(); 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 x.CourseName == courseName); - if (course is null) - comments.Add("课程不存在,请修正!"); + 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 -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 x.QuestionId = id); await _ghre_QuestionAnswerServices.Add(insertAnswers); } @@ -958,6 +1023,7 @@ public class Ghre_QuestionServices : BaseServices.OprateFailed("导入文件存在错误,请下载后查看!", data); - else - return ServiceResult.OprateSuccess("导入成功!"); + return ServiceResult.OprateSuccess("导入成功!", data); } #endregion } \ No newline at end of file