|
|
|
@ -13,6 +13,7 @@ using System.Data; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
using Tiobon.Core.Common.DB.Dapper; |
|
|
|
|
using MySqlX.XDevAPI.Common; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services |
|
|
|
|
{ |
|
|
|
@ -23,11 +24,61 @@ namespace Tiobon.Core.Services |
|
|
|
|
{ |
|
|
|
|
private readonly IBaseRepository<Ghre_Question> _dal; |
|
|
|
|
private IGhre_QuestionAnswerServices _ghre_QuestionAnswerServices; |
|
|
|
|
public Ghre_QuestionServices(IBaseRepository<Ghre_Question> dal, IGhre_QuestionAnswerServices ghre_QuestionAnswerServices) |
|
|
|
|
private IGhre_CourseServices _ghre_CourseServices; |
|
|
|
|
private IGhre_CourseClassServices _ghre_CourseClassServices; |
|
|
|
|
public Ghre_QuestionServices(IBaseRepository<Ghre_Question> dal, |
|
|
|
|
IGhre_QuestionAnswerServices ghre_QuestionAnswerServices, |
|
|
|
|
IGhre_CourseServices ghre_CourseServices, |
|
|
|
|
IGhre_CourseClassServices ghre_CourseClassServices) |
|
|
|
|
{ |
|
|
|
|
this._dal = dal; |
|
|
|
|
base.BaseDal = dal; |
|
|
|
|
_ghre_QuestionAnswerServices = ghre_QuestionAnswerServices; |
|
|
|
|
_ghre_CourseServices = ghre_CourseServices; |
|
|
|
|
_ghre_CourseClassServices = ghre_CourseClassServices; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override async Task<ServicePageResult<Ghre_QuestionDto>> QueryFilterPage(QueryBody body) |
|
|
|
|
{ |
|
|
|
|
var data1 = await BaseDal.QueryFilterPage(body); |
|
|
|
|
var data = Mapper.Map(data1.result.DT_TableDataT1).ToANew<List<Ghre_QuestionDto>>(); |
|
|
|
|
var courseIds = data.Where(x => x.CourseId != null).Select(x => x.CourseId).ToList(); |
|
|
|
|
|
|
|
|
|
var courses = await _ghre_CourseServices.Query(x => courseIds.Contains(x.Id)); |
|
|
|
|
var classs = await _ghre_CourseClassServices.Query(); |
|
|
|
|
data.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
if (x.DifficultyLevel == "Easy") |
|
|
|
|
x.DifficultyLevel = "简单"; |
|
|
|
|
else if (x.DifficultyLevel == "Normal") |
|
|
|
|
x.DifficultyLevel = "普通"; |
|
|
|
|
else if (x.DifficultyLevel == "Hard") |
|
|
|
|
x.DifficultyLevel = "困难"; |
|
|
|
|
|
|
|
|
|
if (x.QuestionType == "Single") |
|
|
|
|
x.QuestionType = "单选题"; |
|
|
|
|
else if (x.QuestionType == "Multiple") |
|
|
|
|
x.QuestionType = "多选题"; |
|
|
|
|
else if (x.QuestionType == "TrueOrFalse") |
|
|
|
|
x.QuestionType = "判断题"; |
|
|
|
|
else if (x.QuestionType == "Completion") |
|
|
|
|
x.QuestionType = "填空题"; |
|
|
|
|
else if (x.QuestionType == "ShortAnswer") |
|
|
|
|
x.QuestionType = "简答题"; |
|
|
|
|
|
|
|
|
|
if (x.CourseId != null) |
|
|
|
|
{ |
|
|
|
|
var course = courses.Where(a => a.Id == x.CourseId).FirstOrDefault(); |
|
|
|
|
x.CourseName = course?.CourseName; |
|
|
|
|
var courseClass = classs.Where(a => a.Id == course.CourseClassId).FirstOrDefault(); |
|
|
|
|
x.CourseType = courseClass.ClassName; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ServicePageResult<Ghre_QuestionDto>(body.pageNum, data1.result.DT_TablePageInfoT1.TotalCount, body.pageSize, data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -65,25 +116,68 @@ namespace Tiobon.Core.Services |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region PageData |
|
|
|
|
|
|
|
|
|
var answerList = new List<FromGhre_QuestionQuestionAnswerList> |
|
|
|
|
{ |
|
|
|
|
new FromGhre_QuestionQuestionAnswerList() |
|
|
|
|
{ |
|
|
|
|
No = "A", |
|
|
|
|
}, |
|
|
|
|
new FromGhre_QuestionQuestionAnswerList() |
|
|
|
|
{ |
|
|
|
|
No = "B", |
|
|
|
|
}, |
|
|
|
|
new FromGhre_QuestionQuestionAnswerList() |
|
|
|
|
{ |
|
|
|
|
No = "C", |
|
|
|
|
}, |
|
|
|
|
new FromGhre_QuestionQuestionAnswerList() |
|
|
|
|
{ |
|
|
|
|
No = "D", |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
var answerList1 = new List<FromGhre_QuestionQuestionAnswerList> |
|
|
|
|
{ |
|
|
|
|
new FromGhre_QuestionQuestionAnswerList() |
|
|
|
|
{ |
|
|
|
|
No = "A", |
|
|
|
|
}, |
|
|
|
|
new FromGhre_QuestionQuestionAnswerList() |
|
|
|
|
{ |
|
|
|
|
No = "B", |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
data.PageData.questionType = new List<FromGhre_QuestionQuestionType> |
|
|
|
|
{ |
|
|
|
|
new FromGhre_QuestionQuestionType() |
|
|
|
|
{ |
|
|
|
|
label = "单选题", |
|
|
|
|
type = "Single", |
|
|
|
|
isActive = 1 |
|
|
|
|
isActive = 1, |
|
|
|
|
detail= new FromGhre_QuestionQuestionTypeDetail() |
|
|
|
|
{ |
|
|
|
|
answerList=answerList |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
new FromGhre_QuestionQuestionType() |
|
|
|
|
{ |
|
|
|
|
label = "多选题", |
|
|
|
|
type = "Multiple", |
|
|
|
|
isActive = 0, |
|
|
|
|
detail= new FromGhre_QuestionQuestionTypeDetail() |
|
|
|
|
{ |
|
|
|
|
answerList=answerList |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
new FromGhre_QuestionQuestionType() |
|
|
|
|
{ |
|
|
|
|
label = "判断题", |
|
|
|
|
type = "TrueOrFalse", |
|
|
|
|
isActive = 0, |
|
|
|
|
detail= new FromGhre_QuestionQuestionTypeDetail() |
|
|
|
|
{ |
|
|
|
|
answerList=answerList1 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
new FromGhre_QuestionQuestionType() |
|
|
|
|
{ |
|
|
|
@ -104,20 +198,8 @@ namespace Tiobon.Core.Services |
|
|
|
|
var question = await base.QueryById(Id); |
|
|
|
|
data.PageData.questionType.ForEach(x => x.isActive = 0); |
|
|
|
|
data.PageData.baseData.questionNo = question.QuestionNo; |
|
|
|
|
if (!string.IsNullOrEmpty(question.CourseIds)) |
|
|
|
|
{ |
|
|
|
|
var list = question.CourseIds.Split(';'); |
|
|
|
|
list.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
data.PageData.baseData.courseID.Add(long.Parse(x)); |
|
|
|
|
} |
|
|
|
|
catch (Exception) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
data.PageData.baseData.courseID.Add(question.CourseId); |
|
|
|
|
|
|
|
|
|
var questionType = data.PageData.questionType.Where(x => x.type == question.QuestionType).FirstOrDefault(); |
|
|
|
|
if (questionType != null) |
|
|
|
|
{ |
|
|
|
@ -144,52 +226,108 @@ namespace Tiobon.Core.Services |
|
|
|
|
return ServiceResult<FromGhre_QuestionInput>.OprateSuccess("查询成功!", data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult<long>> InsertFrom(FromGhre_QuestionPageData insertModel) |
|
|
|
|
public async Task<ServiceResult> InsertFrom(FromGhre_QuestionPageData insertModel) |
|
|
|
|
{ |
|
|
|
|
var insert = new InsertGhre_QuestionInput(); |
|
|
|
|
insert.CourseId = insertModel.baseData.courseID; |
|
|
|
|
insert.CourseIds = string.Join(";", insert.CourseId.Select(x => x)); |
|
|
|
|
|
|
|
|
|
var questionType = insertModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); |
|
|
|
|
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)); |
|
|
|
|
string questionTypeName = string.Empty; |
|
|
|
|
if (questionType.type == "Single") |
|
|
|
|
questionTypeName = "单选题"; |
|
|
|
|
else if (questionType.type == "Multiple") |
|
|
|
|
questionTypeName = "多选题"; |
|
|
|
|
else if (questionType.type == "TrueOrFalse") |
|
|
|
|
questionTypeName = "判断题"; |
|
|
|
|
else if (questionType.type == "Completion") |
|
|
|
|
questionTypeName = "填空题"; |
|
|
|
|
else if (questionType.type == "ShortAnswer") |
|
|
|
|
questionTypeName = "简答题"; |
|
|
|
|
|
|
|
|
|
var id = await base.Add(insert); |
|
|
|
|
|
|
|
|
|
var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() |
|
|
|
|
#region 判断是否重复 |
|
|
|
|
for (int j = 0; j < insertModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
QuestionNo = x.No, |
|
|
|
|
AnswerContent = x.label, |
|
|
|
|
ImageUrl = x.imageUrl, |
|
|
|
|
ImageWidthPc = x.imgWidthPc, |
|
|
|
|
ImageWidthApp = x.imgWidthApp, |
|
|
|
|
}).ToList(); |
|
|
|
|
int i = 100; |
|
|
|
|
insertAnswers.ForEach(x => |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
for (int j = 0; j < insertModel.baseData.courseID.Count; j++) |
|
|
|
|
{ |
|
|
|
|
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); |
|
|
|
|
return ServiceResult<long>.OprateSuccess("查询成功!", id); |
|
|
|
|
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)); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 = string.Empty; |
|
|
|
|
if (questionType.type == "Single") |
|
|
|
|
questionTypeName = "单选题"; |
|
|
|
|
else if (questionType.type == "Multiple") |
|
|
|
|
questionTypeName = "多选题"; |
|
|
|
|
else if (questionType.type == "TrueOrFalse") |
|
|
|
|
questionTypeName = "判断题"; |
|
|
|
|
else if (questionType.type == "Completion") |
|
|
|
|
questionTypeName = "填空题"; |
|
|
|
|
else if (questionType.type == "ShortAnswer") |
|
|
|
|
questionTypeName = "简答题"; |
|
|
|
|
|
|
|
|
|
#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; |
|
|
|
|
edit.CourseIds = string.Join(";", edit.CourseId.Select(x => x)); |
|
|
|
|
edit.QuestionNo = ""; |
|
|
|
|
edit.CourseId = editModel.baseData.courseID[0]; |
|
|
|
|
|
|
|
|
|
var questionType = editModel.questionType.Where(x => x.isActive == 1).FirstOrDefault(); |
|
|
|
|
edit.QuestionType = questionType.type; |
|
|
|
|
edit.DifficultyLevel = questionType.detail.difficulty; |
|
|
|
|
edit.QuestionContent = questionType.detail.content; |
|
|
|
@ -214,6 +352,44 @@ namespace Tiobon.Core.Services |
|
|
|
|
i = i + 100; |
|
|
|
|
}); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
|
|
|
|
|
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 == x.QuestionNo && insert.QuestionType == "Single") |
|
|
|
|
x.IsCorrect = true; |
|
|
|
|
i = i + 100; |
|
|
|
|
}); |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(insertAnswers); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ServiceResult.OprateSuccess("更新成功!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -224,8 +400,8 @@ namespace Tiobon.Core.Services |
|
|
|
|
string result = string.Empty; |
|
|
|
|
string tableCode = "Ghre_Question"; |
|
|
|
|
string columnCode = "QuestionNo"; |
|
|
|
|
int length = 6; |
|
|
|
|
int tempLength = 5; |
|
|
|
|
int length = 7; |
|
|
|
|
int tempLength = 6; |
|
|
|
|
int sequence; |
|
|
|
|
|
|
|
|
|
#region 查询 |
|
|
|
|