|
|
|
@ -4,7 +4,6 @@ using AgileObjects.AgileMapper; |
|
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
|
using Newtonsoft.Json; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using SharpCompress.Common; |
|
|
|
|
using SqlSugar; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
using Tiobon.Core.Common.Caches; |
|
|
|
@ -785,24 +784,25 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region Excel导入 |
|
|
|
|
public async Task<ServiceResult> ImportExcelAsync(IFormFile file) |
|
|
|
|
public override async Task<ServiceResult<string>> ImportExcel(IFormFile file) |
|
|
|
|
{ |
|
|
|
|
long id = SnowFlakeSingle.instance.getID(); |
|
|
|
|
var path = $"{$"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}import{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}"; |
|
|
|
|
if (!Directory.Exists(path)) |
|
|
|
|
Directory.CreateDirectory(path); |
|
|
|
|
var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot"; |
|
|
|
|
var path = $"{$"{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}import{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}"; |
|
|
|
|
if (!Directory.Exists(physicsPath + path)) |
|
|
|
|
Directory.CreateDirectory(physicsPath + path); |
|
|
|
|
|
|
|
|
|
var filepath = path + file.FileName; |
|
|
|
|
var filepath = physicsPath + path + file.FileName; |
|
|
|
|
using (var stream = File.Create(filepath)) |
|
|
|
|
{ |
|
|
|
|
await file.CopyToAsync(stream); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string extension = Path.GetExtension(filepath); |
|
|
|
|
var types = new List<string> |
|
|
|
|
{ |
|
|
|
|
"单选题", |
|
|
|
|
//"多选题", |
|
|
|
|
//"判断题", |
|
|
|
|
"多选题", |
|
|
|
|
"判断题", |
|
|
|
|
//"填空题", |
|
|
|
|
//"简答题", |
|
|
|
|
}; |
|
|
|
@ -818,35 +818,68 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
"H", |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
bool isExistError = false; |
|
|
|
|
var id1 = SnowFlakeSingle.instance.getID(); |
|
|
|
|
string errorFileName = path + SnowFlakeSingle.instance.getID() + extension; |
|
|
|
|
//types.ForEach(async x => |
|
|
|
|
//{ |
|
|
|
|
|
|
|
|
|
types.ForEach(async x => |
|
|
|
|
{ |
|
|
|
|
// string questionType = ConvertQuestionType1(x); |
|
|
|
|
// DataTable dt = NPOIHelper.ImportExcel(filepath, x); |
|
|
|
|
|
|
|
|
|
// NPOIHelper.ExportExcel(dt, null, x, path + id1 + extension); |
|
|
|
|
//}); |
|
|
|
|
|
|
|
|
|
types.ForEach(async x => |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
string questionType = ConvertQuestionType1(x); |
|
|
|
|
DataTable dt = NPOIHelper.ImportExcel(filepath, "单选题"); |
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++) |
|
|
|
|
string questionType = ConvertQuestionType1(x); |
|
|
|
|
DataTable dt = NPOIHelper.ImportExcel(filepath, x); |
|
|
|
|
if (dt.Columns["Comments"] == null) |
|
|
|
|
dt.Columns.Add("Comments", typeof(string)); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var comments = new List<string>(); |
|
|
|
|
var courseName = dt.Rows[i]["课程(必填)"].ToString(); |
|
|
|
|
var questionContent = dt.Rows[i]["题目内容(必填)"].ToString(); |
|
|
|
|
var correctAnswer = dt.Rows[i]["正确答案(必填)"].ToString(); |
|
|
|
|
var questionAnalysis = dt.Rows[i]["解析"].ToString(); |
|
|
|
|
var difficultyLevel = dt.Rows[i]["难度"].ToString() ?? "普通"; |
|
|
|
|
if (string.IsNullOrEmpty(questionContent)) |
|
|
|
|
comments.Add("题目内容为必填项!"); |
|
|
|
|
|
|
|
|
|
var question = await base.Query(x => x.QuestionContent == questionContent && x.QuestionType == questionType); |
|
|
|
|
if (!question.Any()) |
|
|
|
|
{ |
|
|
|
|
var course = await _ghre_CourseServices.Query(x => x.CourseName == dt.Rows[i]["课程(必填)"].ToString()); |
|
|
|
|
|
|
|
|
|
var questionContent = dt.Rows[i]["题干(必填)"].ToString(); |
|
|
|
|
var correctAnswer = dt.Rows[i]["正确答案(必填)"].ToString(); |
|
|
|
|
var questionAnalysis = dt.Rows[i]["解析"].ToString(); |
|
|
|
|
var difficultyLevel = dt.Rows[i]["难度"].ToString(); |
|
|
|
|
if (string.IsNullOrEmpty(courseName)) |
|
|
|
|
comments.Add("课程为必填项!"); |
|
|
|
|
if (string.IsNullOrWhiteSpace(correctAnswer)) |
|
|
|
|
comments.Add("正确答案未标记!"); |
|
|
|
|
if (string.IsNullOrWhiteSpace(difficultyLevel)) |
|
|
|
|
comments.Add("难易程度必填!"); |
|
|
|
|
if (string.IsNullOrWhiteSpace(questionAnalysis)) |
|
|
|
|
comments.Add("题目解析必填!"); |
|
|
|
|
|
|
|
|
|
var question = await base.Query(x => x.QuestionContent == questionContent); |
|
|
|
|
if (!question.Any()) |
|
|
|
|
var course = await _ghre_CourseServices.QuerySingleDto(x => x.CourseName == courseName); |
|
|
|
|
if (course is null) |
|
|
|
|
comments.Add("课程不存在,请修正!"); |
|
|
|
|
|
|
|
|
|
var insert = new InsertGhre_QuestionInput() |
|
|
|
|
{ |
|
|
|
|
var insert = new InsertGhre_QuestionInput() |
|
|
|
|
{ |
|
|
|
|
CourseId = course.FirstOrDefault().Id, |
|
|
|
|
QuestionNo = await GenerateContinuousSequence(questionType.Substring(0, 1)), |
|
|
|
|
DifficultyLevel = ConvertDifficultyLevel1(difficultyLevel), |
|
|
|
|
QuestionType = questionType, |
|
|
|
|
QuestionContent = questionContent, |
|
|
|
|
QuestionAnalysis = questionAnalysis |
|
|
|
|
}; |
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
var insertAnswers = new List<InsertGhre_QuestionAnswerInput>(); |
|
|
|
|
CourseId = course.Id, |
|
|
|
|
QuestionNo = await GenerateContinuousSequence(questionType.Substring(0, 1)), |
|
|
|
|
DifficultyLevel = ConvertDifficultyLevel1(difficultyLevel), |
|
|
|
|
QuestionType = questionType, |
|
|
|
|
QuestionContent = questionContent, |
|
|
|
|
QuestionAnalysis = questionAnalysis |
|
|
|
|
}; |
|
|
|
|
var insertAnswers = new List<InsertGhre_QuestionAnswerInput>(); |
|
|
|
|
|
|
|
|
|
if (questionType == "Single" || questionType == "Multiple") |
|
|
|
|
{ |
|
|
|
|
#region 单选题/多选题 |
|
|
|
|
int j = 100; |
|
|
|
|
answers.ForEach(a => |
|
|
|
|
{ |
|
|
|
@ -855,14 +888,14 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
{ |
|
|
|
|
var isCorrect = false; |
|
|
|
|
|
|
|
|
|
if (x == "单选题" && correctAnswer == a) |
|
|
|
|
if (correctAnswer.Contains(a)) |
|
|
|
|
isCorrect = true; |
|
|
|
|
|
|
|
|
|
insertAnswers.Add(new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
TaxisNo = j, |
|
|
|
|
QuestionNo = a, |
|
|
|
|
QuestionId = id, |
|
|
|
|
//QuestionId = id, |
|
|
|
|
AnswerContent = answer, |
|
|
|
|
IsCorrect = isCorrect |
|
|
|
|
}); |
|
|
|
@ -871,19 +904,73 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
j = j + 100; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
if (!insertAnswers.Any()) |
|
|
|
|
comments.Add(questionType == "ShortAnswer" ? "关键词未填写!" : "答案选项必填!"); |
|
|
|
|
if (insertAnswers.Count < 2 && questionType != "ShortAnswer" && questionType != "Completion") |
|
|
|
|
comments.Add("答案选项不能少于两个!"); |
|
|
|
|
|
|
|
|
|
if ((questionType == "Single" || questionType == "Multiple" || questionType == "TrueOrFalse") && !insertAnswers.Any(o => o.IsCorrect == true)) |
|
|
|
|
comments.Add("正确答案未标记!"); |
|
|
|
|
|
|
|
|
|
if (questionType == "Multiple" && insertAnswers.Where(o => o.IsCorrect == true).Count() < 2) |
|
|
|
|
comments.Add("答案至少需标记处两个正确答案!"); |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
else if (questionType == "TrueOrFalse") |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
#region 判断题 |
|
|
|
|
insertAnswers.Add(new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
TaxisNo = 100, |
|
|
|
|
QuestionNo = "A", |
|
|
|
|
//QuestionId = id, |
|
|
|
|
AnswerContent = "对", |
|
|
|
|
IsCorrect = correctAnswer == "正确" |
|
|
|
|
}); |
|
|
|
|
insertAnswers.Add(new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
TaxisNo = 200, |
|
|
|
|
QuestionNo = "B", |
|
|
|
|
//QuestionId = id, |
|
|
|
|
AnswerContent = "错", |
|
|
|
|
IsCorrect = correctAnswer == "错误" |
|
|
|
|
}); |
|
|
|
|
#endregion |
|
|
|
|
} |
|
|
|
|
if (comments.Any()) |
|
|
|
|
{ |
|
|
|
|
dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); |
|
|
|
|
isExistError = true; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
insertAnswers.ForEach(x => x.QuestionId = id); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
dt.Rows[i]["Comments"] = "试题在系统中已存在!"; |
|
|
|
|
isExistError = true; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return ServiceResult.OprateSuccess("新增成功!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isExistError) |
|
|
|
|
NPOIHelper.ExportExcel(dt, null, x, physicsPath + errorFileName); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (isExistError) |
|
|
|
|
return ServiceResult<string>.OprateFailed("导入文件存在错误,请下载后查看!", errorFileName); |
|
|
|
|
else |
|
|
|
|
return ServiceResult<string>.OprateSuccess("导入成功!"); |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
} |