/// <summary> /// 查看待考信息 /// </summary> /// <param name="CollegeId">学院Id</param> /// <param name="MajorId">专业Id</param> /// <param name="StageId">阶段Id</param> /// <param name="typeId">请求类型Id 0为查看待考信息 1为在线考试列表</param> /// <returns>string 所有待考信息的json字符串</returns> public string GetExamQuestion(int StudentId, int CollegeId, int MajorId, int StageId, int typeId = 0) { try { var list = RedisHelper.Get <List <ExamQuestions> >("Exam"); if (list == null) { var examQuestionsList = examquestion_BLL.GetExamQuestions(); list = examQuestionsList.Where(m => m.CollegeId.Equals(CollegeId) && m.MajorId.Equals(MajorId) && m.StageId.Equals(StageId)).ToList(); var redis = RedisHelper.Set <List <ExamQuestions> >("Exam", examQuestionsList); } list = list.Where(m => m.CollegeId.Equals(CollegeId) && m.MajorId.Equals(MajorId) && m.StageId.Equals(StageId)).ToList(); List <ExamQuestions> resultList = new List <ExamQuestions>(); for (int i = 0; i < list.Count; i++) { //判断类型 if (typeId != 0) { if (list[i].ExamStartDate <= DateTime.Now && list[i].ExamEndDate > DateTime.Now) { var historyRedis = RedisHelper.Get <List <Score_His> >("Score_His" + StudentId); if (historyRedis != null) { historyRedis = historyRedis.Where(m => m.StudentId.Equals(StudentId) && m.ExamQuestionId.Equals(list[i].ExamQuestionId)).ToList(); } var history = iHistoricalPapers_BLL.IsShowTestInfos(StudentId, list[i].ExamQuestionId); if (history == null && historyRedis == null || historyRedis.Count == 0) { resultList.Add(list[i]); } } } else { if (list[i].ExamStartDate > DateTime.Now) { resultList.Add(list[i]); } } } return(JsonConvert.SerializeObject(resultList)); } catch (Exception ex) { ErrorLog.WriteLog(ex); return(null); } }
public bool Add(string ExamName, string Num, DateTime ExamStartDate, DateTime ExamEndDate, int CollegeId, int MajorId, int StageId) { try { var list = examquestion_BLL.QueryByIds(CollegeId, MajorId, StageId); Random random = new Random(); ArrayList ids = new ArrayList(); var singleNums = 0; var moreNums = 0; var judgeNums = 0; switch (Num) { case "20": singleNums = 10; moreNums = 5; judgeNums = 5; break; case "40": singleNums = 20; moreNums = 10; judgeNums = 10; break; case "60": singleNums = 20; moreNums = 20; judgeNums = 20; break; case "100": singleNums = 40; moreNums = 30; judgeNums = 30; break; } for (int i = 0; i < singleNums; i++) { var index = random.Next(list.Single.Count - 1); ids.Add(list.Single[index].QuestionId); list.Single.RemoveAt(index); } for (int i = 0; i < moreNums; i++) { var index = random.Next(list.More.Count - 1); ids.Add(list.More[index].QuestionId); list.More.RemoveAt(index); } for (int i = 0; i < judgeNums; i++) { var index = random.Next(list.Judge.Count - 1); ids.Add(list.Judge[index].QuestionId); list.Judge.RemoveAt(index); } string str = ""; for (int i = 0; i < ids.Count; i++) { if (i == ids.Count - 1) { str = str + ids[i].ToString(); } else { str = str + ids[i].ToString() + ","; } } //添加试卷到试卷表 ExamQuestions model = new ExamQuestions { ExamName = ExamName, ExamQuestionId = DateTime.Now.Ticks.ToString(), QuestionIds = str, ExamStartDate = ExamStartDate, ExamEndDate = ExamEndDate, CreateDate = DateTime.Now, CollegeId = CollegeId, MajorId = MajorId, StageId = StageId, State = 1 }; var result = examquestion_BLL.Add(model); //写入redis缓存 var examQuestionsList = examquestion_BLL.GetExamQuestions(); var redis = RedisHelper.Set <List <ExamQuestions> >("Exam", examQuestionsList); return(result); } catch (Exception ex) { ErrorLog.WriteLog(ex); return(false); } }