代码优化

master
xiaochanghai 1 year ago
parent 64d9d70473
commit 67168bfd2f
  1. 2
      Tiobon.Core.Services/CommonServices.cs
  2. 14
      Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs

@ -310,7 +310,7 @@ public partial class CommonServices : BaseServices<RootEntityTkey<int>>, ICommon
AND a.UserID = '{1}' AND a.UserID = '{1}'
AND a.IsEnable = 1 AND a.IsEnable = 1
AND a.PageSettingQueryId = b.PageSettingQueryId"; AND a.PageSettingQueryId = b.PageSettingQueryId";
sql = string.Format(sql, param.menuName, App.User.ID, param.langId); sql = string.Format(sql, param.menuName, App.User.ID, param.langId);
int UserHasSetting = Db.Ado.GetInt(sql); int UserHasSetting = Db.Ado.GetInt(sql);
if (UserHasSetting == 0) if (UserHasSetting == 0)
{ {

@ -37,18 +37,14 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
{ {
var data1 = await BaseDal.QueryFilterPage(body); var data1 = await BaseDal.QueryFilterPage(body);
var data = Mapper.Map(data1.result.DT_TableDataT1).ToANew<List<Ghre_QuestionDto>>(); 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 courseIds = data.Where(x => x.CourseId != null).Select(x => x.CourseId).Distinct().ToList();
var courses = await _ghre_CourseServices.Query(x => courseIds.Contains(x.Id)); var courses = await _ghre_CourseServices.Query(x => courseIds.Contains(x.Id));
var classs = await _ghre_CourseClassServices.Query(); var classsIds = courses.Select(x => x.CourseClassId).Distinct().ToList();
var classs = await _ghre_CourseClassServices.Query(x => classsIds.Contains(x.Id));
data.ForEach(x => data.ForEach(x =>
{ {
if (x.DifficultyLevel == "Easy") x.DifficultyLevel = ConvertDifficultyLevel(x.DifficultyLevel);
x.DifficultyLevel = "简单";
else if (x.DifficultyLevel == "Normal")
x.DifficultyLevel = "普通";
else if (x.DifficultyLevel == "Hard")
x.DifficultyLevel = "困难";
x.QuestionType = ConvertQuestionType(x.QuestionType); x.QuestionType = ConvertQuestionType(x.QuestionType);
if (x.CourseId != null) if (x.CourseId != null)
@ -493,7 +489,7 @@ public class Ghre_QuestionServices : BaseServices<Ghre_Question, Ghre_QuestionDt
throw new Exception("答案选项必填!"); throw new Exception("答案选项必填!");
if (questionType.detail.answerList.Count < 2) if (questionType.detail.answerList.Count < 2)
throw new Exception("答案选项不能少于两个!"); throw new Exception("答案选项不能少于两个!");
if (string.IsNullOrWhiteSpace( questionType.detail.answer ) && (questionType.detail.answer is null || (questionType.detail.answer != null && !questionType.detail.answerList.Any()))) if (string.IsNullOrWhiteSpace(questionType.detail.answer) && (questionType.detail.answer is null || (questionType.detail.answer != null && !questionType.detail.answerList.Any())))
throw new Exception("正确答案未标记!"); throw new Exception("正确答案未标记!");
} }
} }
Loading…
Cancel
Save