|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
|
|
|
|
|
using System.Data; |
|
|
|
|
using AgileObjects.AgileMapper; |
|
|
|
|
using Mysqlx.Crud; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
using Tiobon.Core.Common.DB.Dapper; |
|
|
|
|
using Tiobon.Core.IRepository.Base; |
|
|
|
@ -189,7 +190,6 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
questionType.detail.difficulty = question.DifficultyLevel; |
|
|
|
|
questionType.detail.answer = answers.Where(x => x.IsCorrect == true).FirstOrDefault()?.QuestionNo; |
|
|
|
|
questionType.detail.answer1 = answers.Where(x => x.IsCorrect == true).Select(x => x.QuestionNo).ToList(); |
|
|
|
|
questionType.detail.answer1 = answers.Where(x => x.IsCorrect == true).Select(x => x.QuestionNo).ToList(); |
|
|
|
|
questionType.detail.content = question.QuestionContent; |
|
|
|
|
questionType.detail.RemarkSz = question.QuestionAnalysis; |
|
|
|
|
questionType.detail.answerList = answers.Select(x => new FromGhre_QuestionQuestionAnswerList() |
|
|
|
@ -209,129 +209,113 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult> InsertFrom(FromGhre_QuestionPageData insertModel) |
|
|
|
|
{ |
|
|
|
|
var questionType = insertModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); |
|
|
|
|
string questionTypeName = ConvertQuestionType(questionType.type); |
|
|
|
|
|
|
|
|
|
#region 判断是否重复 |
|
|
|
|
for (int j = 0; j < insertModel.baseData.courseID.Count; j++) |
|
|
|
|
ValidForm(insertModel); |
|
|
|
|
await Db.Ado.BeginTranAsync(); |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
var courseID = insertModel.baseData.courseID[j]; |
|
|
|
|
string sql = "SELECT * FROM Ghre_Question where QuestionType='{0}' and CourseId='{1}' and QuestionContent ='{2}'"; |
|
|
|
|
sql = string.Format(sql, questionType.type, courseID, questionType.detail.content); |
|
|
|
|
DataTable dt = Db.Ado.GetDataTable(sql); |
|
|
|
|
if (dt.Rows.Count > 0) |
|
|
|
|
var questionType = insertModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); |
|
|
|
|
string questionTypeName = ConvertQuestionType(questionType.type); |
|
|
|
|
|
|
|
|
|
#region 判断是否重复 |
|
|
|
|
for (int j = 0; j < insertModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var course = await _ghre_CourseServices.QueryById(courseID); |
|
|
|
|
throw new Exception($"课程【{course.CourseName}】存在相同内容【{questionTypeName}】"); |
|
|
|
|
var courseID = insertModel.baseData.courseID[j]; |
|
|
|
|
string sql = "SELECT * FROM Ghre_Question where QuestionType='{0}' and CourseId='{1}' and QuestionContent ='{2}'"; |
|
|
|
|
sql = string.Format(sql, questionType.type, courseID, questionType.detail.content); |
|
|
|
|
DataTable dt = Db.Ado.GetDataTable(sql); |
|
|
|
|
if (dt.Rows.Count > 0) |
|
|
|
|
{ |
|
|
|
|
var course = await _ghre_CourseServices.QueryById(courseID); |
|
|
|
|
throw new Exception($"课程【{course.CourseName}】存在相同内容【{questionTypeName}】"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
for (int j = 0; j < insertModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var courseID = insertModel.baseData.courseID[j]; |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
insert.CourseId = courseID; |
|
|
|
|
for (int j = 0; j < insertModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var courseID = insertModel.baseData.courseID[j]; |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
insert.CourseId = courseID; |
|
|
|
|
|
|
|
|
|
insert.QuestionType = questionType.type; |
|
|
|
|
insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
insert.QuestionContent = questionType.detail.content; |
|
|
|
|
insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
insert.QuestionNo = GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
insert.QuestionType = questionType.type; |
|
|
|
|
insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
insert.QuestionContent = questionType.detail.content; |
|
|
|
|
insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
insert.QuestionNo = GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
|
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
|
|
|
|
|
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
QuestionNo = x.No, |
|
|
|
|
AnswerContent = x.label, |
|
|
|
|
ImageUrl = x.imageUrl, |
|
|
|
|
ImageWidthPc = x.imgWidthPc, |
|
|
|
|
ImageWidthApp = x.imgWidthApp, |
|
|
|
|
}).ToList(); |
|
|
|
|
int i = 100; |
|
|
|
|
insertAnswers.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TaxisNo = i; |
|
|
|
|
x.QuestionId = id; |
|
|
|
|
if (questionType.detail.answer == x.QuestionNo && insert.QuestionType == "Single") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
i = i + 100; |
|
|
|
|
}); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
QuestionNo = x.No, |
|
|
|
|
AnswerContent = x.label, |
|
|
|
|
ImageUrl = x.imageUrl, |
|
|
|
|
ImageWidthPc = x.imgWidthPc, |
|
|
|
|
ImageWidthApp = x.imgWidthApp, |
|
|
|
|
}).ToList(); |
|
|
|
|
int i = 100; |
|
|
|
|
insertAnswers.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TaxisNo = i; |
|
|
|
|
x.QuestionId = id; |
|
|
|
|
if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && insert.QuestionType == "Single") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && insert.QuestionType == "Multiple") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
i = i + 100; |
|
|
|
|
}); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
} |
|
|
|
|
await Db.Ado.CommitTranAsync(); |
|
|
|
|
return ServiceResult.OprateSuccess("新增成功!"); |
|
|
|
|
} |
|
|
|
|
catch (Exception) |
|
|
|
|
{ |
|
|
|
|
await Db.Ado.RollbackTranAsync(); |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ServiceResult.OprateSuccess("新增成功!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult> UpdareFrom(long Id, FromGhre_QuestionPageData editModel) |
|
|
|
|
{ |
|
|
|
|
var questionType = editModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); |
|
|
|
|
string questionTypeName = ConvertQuestionType(questionType.type); |
|
|
|
|
|
|
|
|
|
#region 判断是否重复 |
|
|
|
|
for (int j = 0; j < editModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var courseID = editModel.baseData.courseID[j]; |
|
|
|
|
string sql = "SELECT * FROM Ghre_Question where QuestionType='{0}' and CourseId='{1}' and QuestionContent ='{2}' AND Id !='{3}'"; |
|
|
|
|
sql = string.Format(sql, questionType.type, courseID, questionType.detail.content, Id); |
|
|
|
|
DataTable dt = Db.Ado.GetDataTable(sql); |
|
|
|
|
if (dt.Rows.Count > 0) |
|
|
|
|
{ |
|
|
|
|
var course = await _ghre_CourseServices.QueryById(courseID); |
|
|
|
|
throw new Exception($"课程【{course.CourseName}】存在相同内容【{questionTypeName}】"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
var data = await base.QueryById(Id); |
|
|
|
|
await _ghre_QuestionAnswerServices.Delete(x => x.QuestionId == Id); |
|
|
|
|
var edit = Mapper.Map(data).ToANew<EditGhre_QuestionInput>(); |
|
|
|
|
edit.CourseId = editModel.baseData.courseID[0]; |
|
|
|
|
|
|
|
|
|
edit.QuestionType = questionType.type; |
|
|
|
|
edit.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
edit.QuestionContent = questionType.detail.content; |
|
|
|
|
edit.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
ValidForm(editModel); |
|
|
|
|
|
|
|
|
|
await base.Update(Id, edit); |
|
|
|
|
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
QuestionNo = x.No, |
|
|
|
|
AnswerContent = x.label, |
|
|
|
|
ImageUrl = x.imageUrl, |
|
|
|
|
ImageWidthPc = x.imgWidthPc, |
|
|
|
|
ImageWidthApp = x.imgWidthApp, |
|
|
|
|
}).ToList(); |
|
|
|
|
int i = 100; |
|
|
|
|
insertAnswers.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TaxisNo = i; |
|
|
|
|
x.QuestionId = Id; |
|
|
|
|
if (questionType.detail.answer == x.QuestionNo && edit.QuestionType == "Single") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
i = i + 100; |
|
|
|
|
}); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
await Db.Ado.BeginTranAsync(); |
|
|
|
|
|
|
|
|
|
for (int j = 0; j < editModel.baseData.courseID.Count; j++) |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
if (j == 0) |
|
|
|
|
continue; |
|
|
|
|
var questionType = editModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); |
|
|
|
|
string questionTypeName = ConvertQuestionType(questionType.type); |
|
|
|
|
|
|
|
|
|
var courseID = editModel.baseData.courseID[j]; |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
insert.CourseId = courseID; |
|
|
|
|
#region 判断是否重复 |
|
|
|
|
for (int j = 0; j < editModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var courseID = editModel.baseData.courseID[j]; |
|
|
|
|
string sql = "SELECT * FROM Ghre_Question where QuestionType='{0}' and CourseId='{1}' and QuestionContent ='{2}' AND Id !='{3}'"; |
|
|
|
|
sql = string.Format(sql, questionType.type, courseID, questionType.detail.content, Id); |
|
|
|
|
DataTable dt = Db.Ado.GetDataTable(sql); |
|
|
|
|
if (dt.Rows.Count > 0) |
|
|
|
|
{ |
|
|
|
|
var course = await _ghre_CourseServices.QueryById(courseID); |
|
|
|
|
throw new Exception($"课程【{course.CourseName}】存在相同内容【{questionTypeName}】"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
insert.QuestionType = questionType.type; |
|
|
|
|
insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
insert.QuestionContent = questionType.detail.content; |
|
|
|
|
insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
insert.QuestionNo = GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
var data = await base.QueryById(Id); |
|
|
|
|
await _ghre_QuestionAnswerServices.Delete(x => x.QuestionId == Id); |
|
|
|
|
var edit = Mapper.Map(data).ToANew<EditGhre_QuestionInput>(); |
|
|
|
|
edit.CourseId = editModel.baseData.courseID[0]; |
|
|
|
|
|
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
edit.QuestionType = questionType.type; |
|
|
|
|
edit.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
edit.QuestionContent = questionType.detail.content; |
|
|
|
|
edit.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
|
|
|
|
|
insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
await base.Update(Id, edit); |
|
|
|
|
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
QuestionNo = x.No, |
|
|
|
|
AnswerContent = x.label, |
|
|
|
@ -339,19 +323,66 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
ImageWidthPc = x.imgWidthPc, |
|
|
|
|
ImageWidthApp = x.imgWidthApp, |
|
|
|
|
}).ToList(); |
|
|
|
|
i = 100; |
|
|
|
|
int i = 100; |
|
|
|
|
insertAnswers.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TaxisNo = i; |
|
|
|
|
x.QuestionId = id; |
|
|
|
|
if (questionType.detail.answer == x.QuestionNo && insert.QuestionType == "Single") |
|
|
|
|
x.QuestionId = Id; |
|
|
|
|
if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && edit.QuestionType == "Single") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && edit.QuestionType == "Multiple") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
i = i + 100; |
|
|
|
|
}); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ServiceResult.OprateSuccess("更新成功!"); |
|
|
|
|
for (int j = 0; j < editModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
if (j == 0) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
var courseID = editModel.baseData.courseID[j]; |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
insert.CourseId = courseID; |
|
|
|
|
|
|
|
|
|
insert.QuestionType = questionType.type; |
|
|
|
|
insert.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
insert.QuestionContent = questionType.detail.content; |
|
|
|
|
insert.QuestionAnalysis = questionType.detail.RemarkSz; |
|
|
|
|
insert.QuestionNo = GenerateContinuousSequence(insert.QuestionType.Substring(0, 1)); |
|
|
|
|
|
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
|
|
|
|
|
insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
{ |
|
|
|
|
QuestionNo = x.No, |
|
|
|
|
AnswerContent = x.label, |
|
|
|
|
ImageUrl = x.imageUrl, |
|
|
|
|
ImageWidthPc = x.imgWidthPc, |
|
|
|
|
ImageWidthApp = x.imgWidthApp, |
|
|
|
|
}).ToList(); |
|
|
|
|
i = 100; |
|
|
|
|
insertAnswers.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TaxisNo = i; |
|
|
|
|
x.QuestionId = id; |
|
|
|
|
if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && insert.QuestionType == "Single") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && insert.QuestionType == "Multiple") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
i = i + 100; |
|
|
|
|
}); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
} |
|
|
|
|
await Db.Ado.CommitTranAsync(); |
|
|
|
|
|
|
|
|
|
return ServiceResult.OprateSuccess("更新成功!"); |
|
|
|
|
} |
|
|
|
|
catch (Exception) |
|
|
|
|
{ |
|
|
|
|
await Db.Ado.RollbackTranAsync(); |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static string GenerateContinuousSequence(string prefixTemp) |
|
|
|
@ -431,4 +462,38 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
questionTypeName = "简答题"; |
|
|
|
|
return questionTypeName; |
|
|
|
|
} |
|
|
|
|
public static string ConvertDifficultyLevel(string type) |
|
|
|
|
{ |
|
|
|
|
string questionTypeName = string.Empty; |
|
|
|
|
if (type == "Easy") |
|
|
|
|
questionTypeName = "简单"; |
|
|
|
|
else if (type == "Normal") |
|
|
|
|
questionTypeName = "普通"; |
|
|
|
|
else if (type == "Hard") |
|
|
|
|
questionTypeName = "困难"; |
|
|
|
|
return questionTypeName; |
|
|
|
|
} |
|
|
|
|
public static void ValidForm(FromGhre_QuestionPageData model) |
|
|
|
|
{ |
|
|
|
|
if (model.baseData.courseID is null || (model.baseData.courseID != null && !model.baseData.courseID.Any())) |
|
|
|
|
throw new Exception("课程编号必填!"); |
|
|
|
|
|
|
|
|
|
var questionType = model.questionType.Where(x => x.isActive == 1).FirstOrDefault(); |
|
|
|
|
|
|
|
|
|
if (questionType is null) |
|
|
|
|
throw new Exception("提交参数异常!"); |
|
|
|
|
if (string.IsNullOrWhiteSpace(questionType.detail.difficulty)) |
|
|
|
|
throw new Exception("难易程度不能为空!"); |
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(ConvertDifficultyLevel(questionType.detail.difficulty))) |
|
|
|
|
throw new Exception("无效的难易程度类型!"); |
|
|
|
|
if (string.IsNullOrWhiteSpace(questionType.detail.content)) |
|
|
|
|
throw new Exception("题目内容必填!"); |
|
|
|
|
if (questionType.detail.answerList is null || (questionType.detail.answerList != null && !questionType.detail.answerList.Any())) |
|
|
|
|
throw new Exception("答案选项必填!"); |
|
|
|
|
if (questionType.detail.answerList.Count < 2) |
|
|
|
|
throw new Exception("答案选项不能少于两个!"); |
|
|
|
|
if (string.IsNullOrWhiteSpace( questionType.detail.answer ) && (questionType.detail.answer is null || (questionType.detail.answer != null && !questionType.detail.answerList.Any()))) |
|
|
|
|
throw new Exception("正确答案未标记!"); |
|
|
|
|
} |
|
|
|
|
} |