/// <summary> /// /// </summary> public void Generate() { if (Exampaper.ExamType == 0) { var s = Exampaper.QuestionList.Select(p => new ReStudentExamAnswer { Qid = p.Qid, Questionid = p.Questionid, Score = p.QScore, Order = p.QOrder, QType = p.QType, Answer = "", DoneFlag = 0, Evlution = "", GetScore = 0, WrongQuestionFlag = 0 }); foreach (var item in ExamSendStudents) { item.StudentAnswerList.Clear(); item.StudentAnswerList.AddRange(s); } } else { ExamSendStudents = new RetechWing.BusinessCommon.Examination.GenerateExampaper().RandomGenerate(ExamSendStudents, Exampaper.QuestionRule); var questionids = new List <int>(); ExamSendStudents.ForEach(p => { questionids.AddRange(p.StudentAnswerList.Select(q => q.Questionid)); }); var newquestions = _questionBL.InsertQuestionRedundancys(questionids.Distinct()); foreach (var item in ExamSendStudents) { int i = 0; foreach (var sa in item.StudentAnswerList) { var tmp = newquestions.FirstOrDefault(p => p.QuestionId == sa.Questionid); sa.Qid = tmp == null ? 0 : tmp._id; sa.Order = i; i++; } } } _examinationBL.SaveExamSendStudent(ExamId, ExamSendStudents); }
/// <summary> /// 获取试卷的试题 /// </summary> /// <param name="exampaper">试卷信息</param> /// <param name="exam">试卷信息</param> /// <param name="examuser">学员答案</param> /// <param name="examination">考试信息</param> private void GetExampaper(ExampaperShow exampaper, tbExampaperRedundancy exam, tbExamSendStudent examuser, tbExamination examination) { var radomOrder = string.IsNullOrWhiteSpace(examination.RadomOrderFlag) ? new string[0] : examination.RadomOrderFlag.Split(','); //IMongoQuery query = Query.In("_id", new BsonArray(exam.QuestionList.Select(p => p.Qid))); IMongoQuery query = Query.In("_id", new BsonArray(examuser.StudentAnswerList.Select(p => p.Qid))); if (!examuser.StudentAnswerList.Any()) { //如果没有试题,则加入试题 if (exam.ExamType == 0) { exam.QuestionList.ForEach(p => { examuser.StudentAnswerList.Add(new ReStudentExamAnswer { Qid = p.Qid, Questionid = p.Questionid, Order = p.QOrder, QType = p.QType, Score = p.QScore, DoneFlag = 0, Answer = "", Evlution = "", GetScore = 0, WrongQuestionFlag = 0 }); }); } else { examuser = new RetechWing.BusinessCommon.Examination.GenerateExampaper().RandomGenerate(examuser, exam.QuestionRule); var questionIds = examuser.StudentAnswerList.Select(p => p.Questionid); var questions = Etdb.GetAllList <tbQuestion>(Query.In("_id", new BsonArray(questionIds))); int i = 1; foreach (var item in examuser.StudentAnswerList) { var tmp = questions.FirstOrDefault(p => p._id == item.Questionid); var questionRed = new tbQuestionRedundancy { QuestionId = tmp._id, QuestionSortID = tmp.QuestionSortID, QuestionOpen = tmp.QuestionOpen, UserID = tmp.UserID, CreateTime = tmp.CreateTime, FileUpload = tmp.FileUpload, LastUpdateTime = tmp.LastUpdateTime, QuestionAnalysis = tmp.QuestionAnalysis, QuestionAnswer = tmp.QuestionAnswer, QuestionAnswerKeys = tmp.QuestionAnswerKeys, QuestionAvailable = tmp.QuestionAvailable, QuestionContent = tmp.QuestionContent, QuestionKey = tmp.QuestionKey, QuestionLevel = tmp.QuestionLevel, QuestionType = tmp.QuestionType, Status = tmp.Status, TenantId = tmp.TenantId }; item.Qid = Etdb.Insert <tbQuestionRedundancy>(questionRed); item.Order = i; i++; } } Etdb.Modify <tbExamSendStudent>(examuser); query = Query.In("_id", new BsonArray(examuser.StudentAnswerList.Select(p => p.Qid))); } ////从缓存中读取所有问题 //List<tbQuestionRedundancy> quList; //获取试题 //var cachekey = "examquestions:tenant:" + exam.TenantId; //quList = _cacheService.Get<List<tbQuestionRedundancy>>(cachekey); //if (quList == null || quList.Count == 0) //{ // quList = Etdb.GetAllList<tbQuestionRedundancy>(query); // _cacheService.Set(cachekey, quList, CachingExpirationType.Stable); //} var quList = Etdb.GetAllList <tbQuestionRedundancy>(query); //题目随机 if (radomOrder.Contains("1")) { var radomList = new List <int>(); var next = 0; var length = examuser.StudentAnswerList.Count; for (int i = 0; i < length; i++) { do { next = new Random().Next(); if (!radomList.Contains(next)) { examuser.StudentAnswerList[i].Order = next; radomList.Add(next); break; } } while (true); } } var m = 0; examuser.StudentAnswerList.OrderBy(p => p.Order).ToList().ForEach(p => { p.Order = ++m; tbQuestionRedundancy qu = quList.FirstOrDefault(q => q._id == p.Qid); if (qu != null) { ReStudentExamAnswer an = examuser == null ? null : examuser.StudentAnswerList.FirstOrDefault( pa => pa.Qid == p.Qid); var newqu = new MQuestion { QAnswerType = qu.QuestionType == 6 ? qu.QuestionAnswer[0].AnswerType : 0, QType = qu.QuestionType, //QuestionContent = qu.QuestionContent, QuestionContent = qu.QuestionContent.NoHtml().HtmlDecode(), QuestionID = qu._id, QuestionLevel = EnumsLanguage.GetString(((QuestionLevel)qu.QuestionLevel).ToString()), QuestionOrder = p.Order, Score = p.Score, UserAnswer = an == null ? "" : (an.Answer), UserAnswerScore = an == null ? 0 : an.GetScore, FillBlankCount = qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Length - 1, WrongQuestionFlag = an == null ? 0 : an.WrongQuestionFlag, QuestionAnalysis = qu.QuestionAnalysis }; //记录选项随机前的原有序号 var tmpquestionlist = new List <MQuestionAnswer>(); //选择随机 if (radomOrder.Contains("2")) { var radomList = new List <int>(); var next = 0; var length = qu.QuestionAnswer.Count; for (int i = 0; i < length; i++) { do { next = new Random().Next(); if (!radomList.Contains(next)) { tmpquestionlist.Add(new MQuestionAnswer { Order = next, oldOrder = qu.QuestionAnswer[i].Order }); qu.QuestionAnswer[i].Order = next; radomList.Add(next); break; } } while (true); } } var n = 0; qu.QuestionAnswer.OrderBy(o => o.Order).ToList().ForEach(pa => { var tmp = tmpquestionlist.FirstOrDefault(t => t.Order == pa.Order); pa.Order = ++n; newqu.QuestionAnswer.Add(new MQuestionAnswer { AnswerContent = pa.Answer, AnswerFlag = pa.AnswerFlag, AnswerType = pa.AnswerType, Order = pa.Order, QuID = newqu.QuestionID, QType = newqu.QType, oldOrder = tmp == null ? pa.Order : tmp.oldOrder }); }); qu.FileUpload.ForEach(pa => newqu.FileUpload.Add(new QuestionFile { _fileName = pa.FileName, _fileType = pa.FileType, _realName = pa.RealName })); exampaper.QuestionList.Add(newqu); } }); exampaper.QuestionList = exampaper.QuestionList.OrderBy(p => p.QuestionOrder).ToList(); }