题库对应课程名称可以多选,且同一试题对应不同课程,课程呈现在相同单元格

master
xiaochanghai 3 months ago
parent 2939a84ece
commit 4ad5eb8224
  1. 103
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs

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

Loading…
Cancel
Save