Example #1
0
        /// <summary>
        ///     获取考试的基本信息
        /// </summary>
        /// <param name="examUserID">考试人员ID</param>
        /// <param name="type">0:独立的考试</param>
        /// <returns></returns>
        public ExampaperShow GetExampaperBaseInforShow(int examUserID, int type = 0)
        {
            var exampaper = new ExampaperShow();                                //new 试卷对象
            var examuser  = Etdb.GetSingleByID <tbExamSendStudent>(examUserID); //单个考生考试信息
            //var exam = new tbExampaper();
            tbExampaper exam = null;
            //var examination = new tbExamination(); //考试分类对象
            tbExamination examination = null;

            exam = Etdb.GetSingleByID <tbExampaper>(examuser.ExamPaperID); //试卷对象
            if (type == 0)
            {
                examination = Etdb.GetSingleByID <tbExamination>(examuser.RelationID);
            }
            exampaper.ExampaperType       = exam.ExamType;
            exampaper.QuestionTypeStrShow = exam.QuestionTypeOrder.GetQuestionTypeStr();
            //获取试题
            if (examination != null)
            {
                GetExampaper(exampaper, exam, examuser, examination);
            }
            else
            {
                GetExampaper(exampaper, exam, examuser);
            }
            //初始化学员答案
            exampaper.QuestionList.ForEach(p => exampaper.StudentAnswer.Add(new StudentAnswer
            {
                Answer = p.UserAnswer,
                Qid    = p.QuestionID,
                QType  = p.QType
            }));
            return(exampaper);
        }
Example #2
0
        /// <summary>
        /// 获取考试中试卷与学员答题情况的基本信息
        /// </summary>
        /// <param name="examUserID">考试关联学员ID</param>
        /// <returns></returns>
        public ExampaperShow GetExampaperBaseInforShow(int examUserID)
        {
            var exampaper   = new ExampaperShow();
            var examuser    = Etdb.GetSingleById <tbExamSendStudent>(examUserID);               //考生考试信息
            var exam        = Etdb.GetSingleById <tbExampaperRedundancy>(examuser.ExamPaperID); //试卷信息
            var examination = new tbExamination();

            if (examuser.SourceType == 0)
            {
                examination = Etdb.GetSingleById <tbExamination>(examuser.RelationID);
            }
            exampaper.TotalScore          = exam.ExampaperScore;
            exampaper.ExampaperType       = exam.ExamType;
            exampaper.QuestionTypeStrShow = exam.QuestionTypeOrder.GetQuestionTypeStr();
            //获取试题
            GetExampaper(exampaper, exam, examuser, examination);
            //初始化学员答案
            exampaper.QuestionList.ForEach(p => exampaper.StudentAnswer.Add(new StudentAnswer
            {
                Answer    = p.UserAnswer,
                Qid       = p.QuestionID,
                QType     = p.QType,
                UserScore = p.UserAnswerScore
            }));
            return(exampaper);
        }
Example #3
0
        /// <summary>
        /// 获取考试中试卷与学员答题情况的基本信息
        /// </summary>
        /// <param name="examUserIDs">考试关联学员ID</param>
        /// <returns></returns>
        public List <ExampaperShow> GetExampaperBaseInforShow(IEnumerable <int> examUserIDs)
        {
            var list         = new List <ExampaperShow>();
            var examuserList = Etdb.GetAllList <tbExamSendStudent>(Query.And(new[]
            {
                Query.In("_id", new BsonArray(examUserIDs))
            }));
            var exampaperList = Etdb.GetAllList <tbExampaperRedundancy>(Query.And(new[]
            {
                Query.In("_id", new BsonArray(examuserList.Select(p => p.ExamPaperID)))
            }));
            var examList = Etdb.GetAllList <tbExamination>(Query.And(new[]
            {
                Query.In("_id", new BsonArray(examuserList.Where(p => p.SourceType == 0).Select(p => p.RelationID)))
            }));

            foreach (var examUserID in examUserIDs)
            {
                var exampaper   = new ExampaperShow();
                var examuser    = examuserList.Find(p => p._id == examUserID);
                var exam        = exampaperList.Find(p => p._id == examuser.ExamPaperID);
                var examination = new tbExamination();
                if (examuser.SourceType == 0)
                {
                    examination = examList.Find(p => p._id == examuser.RelationID);
                }
                exampaper.ExampaperType       = exam.ExamType;
                exampaper.ExampaperID         = exam._id;
                exampaper.QuestionTypeStrShow = exam.QuestionTypeOrder.GetQuestionTypeStr();
                //获取试题
                GetExampaper(exampaper, exam, examuser, examination);
                //初始化学员答案
                exampaper.QuestionList.ForEach(p => exampaper.StudentAnswer.Add(new StudentAnswer
                {
                    Answer    = p.UserAnswer,
                    Qid       = p.QuestionID,
                    QType     = p.QType,
                    UserScore = p.UserAnswerScore
                }));
                list.Add(exampaper);
            }
            return(list);
        }
Example #4
0
        /// <summary>
        /// 获取试卷的试题
        /// </summary>
        /// <param name="exampaper">试卷信息</param>
        /// <param name="exam">试卷信息</param>
        /// <param name="examuser">学员答案</param>
        public void GetExampaper(ExampaperShow exampaper, tbExampaper exam, tbExamSendStudent examuser)
        {
            if (exampaper.ExampaperType == 0)
            {
                #region 正常

                IMongoQuery       query  = Query.In("_id", new BsonArray(exam.QuestionList.Select(p => p.Qid)));
                List <tbQuestion> quList = Etdb.GetAllList <tbQuestion>(query); //获取试题
                exam.QuestionList.ForEach(p =>
                {
                    tbQuestion 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.QuestionAnswer[0].AnswerType,
                            QType           = qu.QuestionType,
                            QuestionContent = qu.QuestionContent,
                            QuestionID      = qu._id,
                            QuestionLevel   = ((QuestionLevel)qu.QuestionLevel).ToString(),
                            QuestionOrder   = p.QOrder,
                            Score           = p.QScore,
                            UserAnswer      = an == null ? "" : (an.Answer),
                            FillBlankCount  =
                                qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Count() - 1
                        };
                        qu.QuestionAnswer.OrderBy(o => o.Order)
                        .ToList()
                        .ForEach(pa => newqu.QuestionAnswer.Add(new MQuestionAnswer
                        {
                            AnswerContent = pa.Answer,
                            AnswerFlag    = pa.AnswerFlag,
                            AnswerType    = pa.AnswerType,
                            Order         = pa.Order,
                            QuID          = newqu.QuestionID,
                            QType         = newqu.QType
                        }));
                        qu.FileUpload.ForEach(pa => newqu.FileUpload.Add(new QuestionFile
                        {
                            _fileName = pa.FileName,
                            _fileType = pa.FileType,
                            _realName = pa.RealName
                        }));
                        exampaper.QuestionList.Add(newqu);
                    }
                });

                #endregion
            }
            else
            {
                #region 随机

                List <tbQuestion> questionList = Etdb.GetAllList <tbQuestion>(Query.EQ("Status", 0));
                exam.QuestionRule.ForEach(p =>
                {
                    var newqulist = new List <tbQuestion>();
                    foreach (string s in p.QLevelStr.Split(';'))
                    {
                        newqulist.AddRange(
                            questionList.Where(
                                qu =>
                                p.QSort == qu.QuestionSortID && p.Qtype == qu.QuestionType &&
                                s.Split(':')[0].StringToInt32() == qu.QuestionLevel)
                            .ToList()
                            .RandomGetSome(s.Split(':')[1].StringToInt32()));
                    }
                    newqulist.ForEach(qu =>
                    {
                        var newqu = new MQuestion
                        {
                            QAnswerType     = qu.QuestionAnswer[0].AnswerType,
                            QType           = qu.QuestionType,
                            QuestionContent = qu.QuestionContent,
                            QuestionID      = qu._id,
                            QuestionLevel   = ((QuestionLevel)qu.QuestionLevel).ToString(),
                            QuestionOrder   = 0,
                            Score           = p.QScore,
                            UserAnswer      = "",
                            FillBlankCount  = qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Count() - 1
                        };
                        qu.QuestionAnswer.OrderBy(o => o.Order)
                        .ToList()
                        .ForEach(pa => newqu.QuestionAnswer.Add(new MQuestionAnswer
                        {
                            AnswerContent = pa.Answer,
                            AnswerFlag    = pa.AnswerFlag,
                            AnswerType    = pa.AnswerType,
                            Order         = pa.Order,
                            QuID          = newqu.QuestionID,
                            QType         = newqu.QType
                        }));
                        qu.FileUpload.ForEach(pa => newqu.FileUpload.Add(new QuestionFile
                        {
                            _fileName = pa.FileName,
                            _fileType = pa.FileType,
                            _realName = pa.RealName
                        }));
                        exampaper.QuestionList.Add(newqu);
                    });
                });

                #endregion
            }
            //if (exampaper.ExampaperType == 1 || (examination._id > 0 && examination.RadomOrderFlag == 1))
            if (exampaper.ExampaperType == 1)
            {
                //排序
                int order = 1;
                foreach (string s in exam.QuestionTypeOrder.Split(','))
                {
                    exampaper.QuestionList.Where(p => p.QType == s.StringToInt32())
                    .ToList()
                    .RandomListOrder()
                    .ForEach(p =>
                    {
                        p.QuestionOrder = order;
                        order++;
                    });
                }
            }
            exampaper.QuestionList = exampaper.QuestionList.OrderBy(p => p.QuestionOrder).ToList();
        }
Example #5
0
        /// <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();
        }