master
xiaochanghai 4 months ago
parent 9701e1c557
commit 1fc7d871ab
  1. 103
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs

@ -1,4 +1,5 @@
using NPOI.HSSF.UserModel; using Microsoft.IdentityModel.Tokens;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.SS.Util; using NPOI.SS.Util;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
@ -187,44 +188,6 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
if (name == "page" || name == "pageSize") if (name == "page" || name == "pageSize")
continue; continue;
if (name == "CourseType")
{
var jsonParam = JsonHelper.JsonToObj<JsonParam>(value);
if (jsonParam.columnValue != null)
{
switch (jsonParam.operationKey)
{
case "Include":
conditions += @$" AND EXISTS
(SELECT 1
FROM Ghre_Course Course
WHERE IsEnable = 1
AND {jsonParam.columnValue} IN
(SELECT value FROM openjson (CourseClassId))
AND Course.Id IN
(SELECT value FROM openjson (A.CourseIDs)))";
break;
case "NotInclude":
if (jsonParam.columnValue != null)
conditions += @$" AND NOT EXISTS
(SELECT 1
FROM Ghre_Course Course
WHERE IsEnable = 1
AND {jsonParam.columnValue} IN
(SELECT value FROM openjson (CourseClassId))
AND Course.Id IN
(SELECT value FROM openjson (A.CourseIDs)))";
break;
break;
default:
break;
}
}
continue;
}
if (!string.IsNullOrWhiteSpace(value)) if (!string.IsNullOrWhiteSpace(value))
conditions = DealConditions(conditions, name, value); conditions = DealConditions(conditions, name, value);
@ -233,33 +196,25 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
filter.pageSize = 10000; filter.pageSize = 10000;
sql += conditions; sql += conditions;
if (!string.IsNullOrWhiteSpace(condition)) if (!string.IsNullOrWhiteSpace(condition))
sql += " AND " + condition; sql += " AND " + condition;
var data = await Db.SqlQueryable<Ghre_QuestionDto>(sql) var data = await Db.SqlQueryable<Ghre_QuestionDto>(sql)
.OrderBy(filter.orderBy) .OrderBy(filter.orderBy)
.ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); .ToPageListAsync(filter.pageNum, filter.pageSize, totalCount);
var courseIds = new List<long>(); var classsIds1 = data.Select(x => x.CourseClassId).Distinct().ToList();
data.ForEach(x => var classsIds = new List<long>();
classsIds1.ForEach(x =>
{
if (!string.IsNullOrWhiteSpace(x))
{ {
if (x.CourseIds.IsNotEmptyOrNull()) var courseClassIds = JsonConvert.DeserializeObject<List<long>>(x);
courseIds.AddRange(JsonHelper.JsonToObj<List<long>>(x.CourseIds)); classsIds = classsIds.Concat(courseClassIds).ToList();
}
}); });
courseIds = courseIds.Distinct().ToList(); classsIds = classsIds.Distinct().ToList();
//var classsIds1 = data.Select(x => x.CourseClassId).Distinct().ToList(); var classs = await _ghre_CourseClassServices.Query(x => classsIds.Contains(x.Id));
//var classsIds = new List<long>();
//classsIds1.ForEach(x =>
//{
// if (!string.IsNullOrWhiteSpace(x))
// {
// var courseClassIds = JsonConvert.DeserializeObject<List<long>>(x);
// classsIds = classsIds.Concat(courseClassIds).ToList();
// }
//});
//classsIds = classsIds.Distinct().ToList();
var courses = await _ghre_CourseServices.Query(x => courseIds.Contains(x.Id));
data.ForEach(async x => data.ForEach(async x =>
{ {
@ -267,8 +222,8 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
x.QuestionTypeLabel = await GetParaLabel("QuestionType", x.QuestionType); x.QuestionTypeLabel = await GetParaLabel("QuestionType", x.QuestionType);
if (!string.IsNullOrEmpty(x.QuestionContent)) if (!string.IsNullOrEmpty(x.QuestionContent))
x.QuestionContent = WebUtility.HtmlDecode(x.QuestionContent); x.QuestionContent = WebUtility.HtmlDecode(x.QuestionContent);
var courseClass = courses.Where(a => x.CourseIds.Contains(a.Id.ToString())).ToList(); var courseClass = classs.Where(a => x.CourseClassId.Contains(a.Id.ToString())).ToList();
x.CourseName = string.Join("", courseClass.Select(a => a.CourseName + " (" + a.CourseNo + ")")); x.CourseType = string.Join(",", courseClass.Select(a => a.ClassName + " (" + a.ClassNo + ")"));
}); });
@ -312,6 +267,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
#region PageData #region PageData
var answerList = new List<FromGhre_QuestionQuestionAnswerList> var answerList = new List<FromGhre_QuestionQuestionAnswerList>
{ {
new FromGhre_QuestionQuestionAnswerList() new FromGhre_QuestionQuestionAnswerList()
@ -414,7 +370,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
var question = await base.QueryById(Id); var question = await base.QueryById(Id);
data.PageData.questionType.ForEach(x => x.isActive = 0); data.PageData.questionType.ForEach(x => x.isActive = 0);
data.PageData.baseData.questionNo = question.QuestionNo; data.PageData.baseData.questionNo = question.QuestionNo;
data.PageData.baseData.courseID = JsonHelper.JsonToObj<List<long?>>(question.CourseIds); data.PageData.baseData.courseID.Add(question.CourseId);
data.PageData.baseData.CreateDataInfo = question.CreateDataInfo; data.PageData.baseData.CreateDataInfo = question.CreateDataInfo;
data.PageData.baseData.UpdateDataInfo = question.UpdateDataInfo; data.PageData.baseData.UpdateDataInfo = question.UpdateDataInfo;
@ -487,12 +443,11 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
} }
} }
#endregion #endregion
//for (int j = 0; j < insertModel.baseData.courseID.Count; j++) for (int j = 0; j < insertModel.baseData.courseID.Count; j++)
//{ {
//var courseID = insertModel.baseData.courseID[j]; var courseID = insertModel.baseData.courseID[j];
var insert = new InsertGhre_QuestionInput(); var insert = new InsertGhre_QuestionInput();
//insert.CourseId = courseID; insert.CourseId = courseID;
insert.CourseIds = JsonHelper.ObjToJson(insertModel.baseData.courseID);
insert.QuestionType = questionType.type; insert.QuestionType = questionType.type;
insert.DifficultyLevel = questionType.detail.difficulty; insert.DifficultyLevel = questionType.detail.difficulty;
@ -527,7 +482,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) if (!insertAnswers.Where(b => b.IsCorrect == true).Any())
throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!");
await _ghre_QuestionAnswerServices.Add(insertAnswers); await _ghre_QuestionAnswerServices.Add(insertAnswers);
//} }
await Db.Ado.CommitTranAsync(); await Db.Ado.CommitTranAsync();
return ServiceResult.OprateSuccess("新增成功!"); return ServiceResult.OprateSuccess("新增成功!");
} }
@ -621,14 +576,14 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
await _ghre_QuestionAnswerServices.Add(insertAnswers); await _ghre_QuestionAnswerServices.Add(insertAnswers);
//for (int j = 0; j < editModel.baseData.courseID.Count; j++) for (int j = 0; j < editModel.baseData.courseID.Count; j++)
//{ {
// if (j == 0) if (j == 0)
// continue; continue;
//var courseID = editModel.baseData.courseID[j]; var courseID = editModel.baseData.courseID[j];
var insert = new InsertGhre_QuestionInput(); var insert = new InsertGhre_QuestionInput();
insert.CourseIds = JsonHelper.ObjToJson(editModel.baseData.courseID); insert.CourseId = courseID;
insert.QuestionType = questionType.type; insert.QuestionType = questionType.type;
insert.DifficultyLevel = questionType.detail.difficulty; insert.DifficultyLevel = questionType.detail.difficulty;
@ -663,7 +618,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!");
await _ghre_QuestionAnswerServices.Add(insertAnswers); await _ghre_QuestionAnswerServices.Add(insertAnswers);
//} }
await Db.Ado.CommitTranAsync(); await Db.Ado.CommitTranAsync();
return ServiceResult.OprateSuccess("更新成功!"); return ServiceResult.OprateSuccess("更新成功!");

Loading…
Cancel
Save