/// <summary>
        /// 将字符串转换成学生答题结果对象
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        private StudentAnswerBase TranslateAnswer(string json)
        {
            JObject           o    = JsonConvert.DeserializeObject(json) as JObject;
            StudentAnswerBase data = null;

            switch ((SubjectTypeEnum)Convert.ToInt32(o["type"]))
            {
            case SubjectTypeEnum.择题:
                data = new StuSelectAnswer()
                {
                    Type            = (int)SubjectTypeEnum.择题,
                    Answers         = JsonConvert.DeserializeObject <List <int> >(o["sanw"].ToString()),
                    OptionSequences = JsonConvert.DeserializeObject <List <int> >(o["sops"].ToString())
                };
                break;

            case SubjectTypeEnum.判断题:
                data = new StuTrueFalseAnswer()
                {
                    Type   = (int)SubjectTypeEnum.判断题,
                    Answer = Convert.ToInt32(o["sanw"])
                };
                break;

            case SubjectTypeEnum.填空题:
                data = new StuBlankAnswer()
                {
                    Type    = (int)SubjectTypeEnum.填空题,
                    Answers = JsonConvert.DeserializeObject <List <BlankAnswerItem> >(o["sanw"].ToString())
                };
                break;

            case SubjectTypeEnum.择填空:
                data = new StuSelectBlankAnswer()
                {
                    Type            = (int)SubjectTypeEnum.择填空,
                    Answers         = JsonConvert.DeserializeObject <List <int[]> >(o["sanw"].ToString()),
                    OptionSequences = JsonConvert.DeserializeObject <List <int> >(o["sops"].ToString())
                };
                break;

            case SubjectTypeEnum.连线题:
                data = new StuMatchAnswer()
                {
                    Type                 = (int)SubjectTypeEnum.连线题,
                    Answers              = JsonConvert.DeserializeObject <List <int[]> >(o["sanw"].ToString()),
                    LeftOptionSequences  = JsonConvert.DeserializeObject <List <int> >(o["slos"].ToString()),
                    RightOptionSequences = JsonConvert.DeserializeObject <List <int> >(o["sros"].ToString())
                };
                break;

            case SubjectTypeEnum.主观题:
                data = new StuFreeAnswer()
                {
                    Type   = (int)SubjectTypeEnum.主观题,
                    Answer = o["sanw"].ToString()
                };
                break;

            case SubjectTypeEnum.圈点批注标色:
                data = new StuMarkColorAnswer()
                {
                    Type    = (int)SubjectTypeEnum.圈点批注标色,
                    Answers = JsonConvert.DeserializeObject <List <int[]> >(o["sanw"].ToString())
                };
                break;

            case SubjectTypeEnum.圈点批注断句:
                data = new StuMarkCutAnswer()
                {
                    Type    = (int)SubjectTypeEnum.圈点批注断句,
                    Answers = JsonConvert.DeserializeObject <List <int> >(o["sanw"].ToString())
                };
                break;
            }
            if (data != null)
            {
                data.SubjectId    = Convert.ToInt32(o["sbId"]);
                data.ResultStars  = Convert.ToInt32(o["rtar"]);
                data.SubjectCoins = Convert.ToInt32(o["scon"]);
                data.ResultCoins  = Convert.ToInt32(o["rcon"]);
                data.KnowledgeId  = Convert.ToInt32(o["kdge"]);
            }
            return(data);
        }
Beispiel #2
0
        public static ReportVm Create(Yw_SubjectContent content, StudentAnswerBase studentAnswer, Yw_Subject subject)
        {
            DtoSubjectContent subjectContent = SubjectContentDtoBuilder.Create(content, subject);

            ReportVm        vm          = null;
            SubjectTypeEnum subjectType = (SubjectTypeEnum)studentAnswer.Type;

            switch (subjectType)
            {    //选择、选择填空、连线
            case SubjectTypeEnum.择题:
                StuSelectAnswer         selectAnswer  = studentAnswer as StuSelectAnswer;
                DtoSelectSubjectContent selectContent = subjectContent as DtoSelectSubjectContent;
                vm = new MultipleChoiceReportVm
                {
                    SubjectId   = selectAnswer.SubjectId,
                    Stem        = selectContent.Stem,
                    StemType    = (int)selectContent.StemType,
                    Answer      = selectContent.Answer,
                    Options     = selectContent.Options.OrderBy(s => Array.IndexOf(selectAnswer.OptionSequences.ToArray(), s.Key)).ToList(),
                    OptionType  = (int)selectContent.OptionType,
                    SubjectType = (int)selectContent.SubjectType,
                    Analysis    = selectContent.Analysis,

                    StudentAnswer = selectAnswer.Answers,
                    ResultStars   = selectAnswer.ResultStars,
                    Difficulty    = subject.Ysj_Difficulty
                };
                break;

            case SubjectTypeEnum.判断题:
                StuTrueFalseAnswer         trueFalseAns = studentAnswer as StuTrueFalseAnswer;
                DtoTrueFalseSubjectContent trueFalseCon = subjectContent as DtoTrueFalseSubjectContent;
                vm = new TrueFalseReportVm
                {
                    SubjectId   = trueFalseAns.SubjectId,
                    Stem        = trueFalseCon.Stem,
                    StemType    = (int)trueFalseCon.StemType,
                    Answer      = trueFalseCon.Answer,
                    SubjectType = (int)trueFalseCon.SubjectType,
                    Analysis    = trueFalseCon.Analysis,

                    StudentAnswer = trueFalseAns.Answer,
                    ResultStars   = trueFalseAns.ResultStars,
                    Difficulty    = subject.Ysj_Difficulty
                };
                break;

            case SubjectTypeEnum.填空题:
                StuBlankAnswer blankAnswer = studentAnswer as StuBlankAnswer;
                DtoFillInBlankSubjectContent fillInBlank = subjectContent as DtoFillInBlankSubjectContent;
                vm = new FillInBlankReportVm
                {
                    SubjectId   = blankAnswer.SubjectId,
                    Stem        = fillInBlank.Stem,
                    StemType    = (int)fillInBlank.StemType,
                    Answer      = fillInBlank.Answer,
                    SubjectType = (int)fillInBlank.SubjectType,
                    Analysis    = fillInBlank.Analysis,

                    StudentAnswer = blankAnswer.Answers,
                    ResultStars   = blankAnswer.ResultStars,
                    Difficulty    = subject.Ysj_Difficulty
                };
                break;

            case SubjectTypeEnum.择填空:
                StuSelectBlankAnswer selectBlankAnswer = studentAnswer as StuSelectBlankAnswer;

                DtoSelectFillInBlankSubjectContent multipleChoiceFillInBlank = subjectContent as DtoSelectFillInBlankSubjectContent;

                vm = new MultipleChoiceFillInBlankReportVm
                {
                    SubjectId   = selectBlankAnswer.SubjectId,
                    Stem        = multipleChoiceFillInBlank.Stem,
                    StemType    = (int)multipleChoiceFillInBlank.StemType,
                    Answer      = multipleChoiceFillInBlank.Answer,
                    Options     = multipleChoiceFillInBlank.Options.OrderBy(s => Array.IndexOf(selectBlankAnswer.OptionSequences.ToArray(), s.Key)).ToList(),
                    OptionType  = (int)multipleChoiceFillInBlank.OptionType,
                    SubjectType = (int)multipleChoiceFillInBlank.SubjectType,
                    Analysis    = multipleChoiceFillInBlank.Analysis,

                    StudentAnswer = selectBlankAnswer.Answers,
                    ResultStars   = selectBlankAnswer.ResultStars,
                    Difficulty    = subject.Ysj_Difficulty
                };
                break;

            case SubjectTypeEnum.连线题:
                StuMatchAnswer matchAnswer = studentAnswer as StuMatchAnswer;

                DtoMatchSubjectContent match = subjectContent as DtoMatchSubjectContent;

                vm = new MatchReportVm
                {
                    SubjectId       = matchAnswer.SubjectId,
                    Stem            = match.Stem,
                    StemType        = (int)match.StemType,
                    Answer          = match.Answer,
                    SubjectType     = (int)match.SubjectType,
                    LeftOptions     = match.LeftOptions.OrderBy(s => Array.IndexOf(matchAnswer.LeftOptionSequences.ToArray(), s.Key)).ToList(),
                    RightOptions    = match.RightOptions.OrderBy(s => Array.IndexOf(matchAnswer.RightOptionSequences.ToArray(), s.Key)).ToList(),
                    LeftOptionType  = (int)match.LeftOptionType,
                    RightOptionType = (int)match.RightOptionType,
                    Analysis        = match.Analysis,

                    StudentAnswer = matchAnswer.Answers,
                    ResultStars   = matchAnswer.ResultStars,
                    Difficulty    = subject.Ysj_Difficulty
                };
                break;

            case SubjectTypeEnum.主观题:
                StuFreeAnswer         freeAnswer = studentAnswer as StuFreeAnswer;
                DtoFreeSubjectContent free       = subjectContent as DtoFreeSubjectContent;

                vm = new FreeReportVm
                {
                    SubjectId   = freeAnswer.SubjectId,
                    Stem        = free.Stem,
                    StemType    = (int)free.StemType,
                    Answer      = free.Answer,
                    SubjectType = (int)free.SubjectType,
                    Analysis    = free.Analysis,
                    Standard    = free.Standard,

                    StudentAnswer = freeAnswer.Answer,
                    ResultStars   = freeAnswer.ResultStars,
                    Difficulty    = subject.Ysj_Difficulty
                };
                break;

            case SubjectTypeEnum.圈点批注标色:
                StuMarkColorAnswer    markColorAnswer = studentAnswer as StuMarkColorAnswer;
                DtoMarkSubjectContent mark            = subjectContent as DtoMarkSubjectContent;

                vm = new MarkReportVm
                {
                    SubjectId   = markColorAnswer.SubjectId,
                    Stem        = mark.Stem,
                    StemType    = (int)mark.StemType,
                    Answer      = mark.Answer,
                    SubjectType = (int)mark.SubjectType,
                    Analysis    = mark.Analysis,
                    Content     = mark.Content,
                    Color       = mark.Color,

                    StudentAnswer = markColorAnswer.Answers,
                    ResultStars   = markColorAnswer.ResultStars,
                    Difficulty    = subject.Ysj_Difficulty
                };
                break;

            case SubjectTypeEnum.圈点批注断句:
                StuMarkCutAnswer       markCutAnswer = studentAnswer as StuMarkCutAnswer;
                DtoMark2SubjectContent mark2         = subjectContent as DtoMark2SubjectContent;

                vm = new Mark2ReportVm
                {
                    SubjectId   = markCutAnswer.SubjectId,
                    Stem        = mark2.Stem,
                    StemType    = (int)mark2.StemType,
                    Answer      = mark2.Answer,
                    SubjectType = (int)mark2.SubjectType,
                    Analysis    = mark2.Analysis,
                    Content     = mark2.Content,
                    Color       = mark2.Color,

                    StudentAnswer = markCutAnswer.Answers,
                    ResultStars   = markCutAnswer.ResultStars,
                    Difficulty    = subject.Ysj_Difficulty
                };
                break;

            default:
                break;
            }
            return(vm);
        }
        public Yw_StudentStudyTaskAnswerExt MakeTranslator(Yw_StudentStudyTaskAnswer entity)
        {
            Yw_StudentStudyTaskAnswerExt realEntity = entity.ConvertTo <Yw_StudentStudyTaskAnswerExt>();

            if (!string.IsNullOrEmpty(entity.Yta_StudentAnswer))
            {
                realEntity.Yta_Answer_Obj = new StudentAnswerCard();

                JObject jo = JsonConvert.DeserializeObject(entity.Yta_StudentAnswer) as JObject;

                realEntity.Yta_Answer_Obj.UseTime    = Convert.ToInt32(jo["UTim"]);
                realEntity.Yta_Answer_Obj.SubmitTime = jo["STim"].ToString();
                realEntity.Yta_Answer_Obj.TotalStars = (int)jo["EStar"];
                realEntity.Yta_Answer_Obj.TotalCoins = (int)jo["TCoin"];
                realEntity.Yta_Answer_Obj.Part       = (int)jo["Part"];

                string innerJson = jo["Anws"].ToString();
                JArray items     = JsonConvert.DeserializeObject(innerJson) as JArray;

                foreach (JObject o in items)
                {
                    if ((int)o["Type"] == (int)SubjectTypeEnum.择题)
                    {
                        StuSelectAnswer an = JsonConvert.DeserializeObject <StuSelectAnswer>(o.ToString());
                        realEntity.Yta_Answer_Obj.AnswerCollection.Add(an);
                    }
                    else if ((int)o["Type"] == (int)SubjectTypeEnum.填空题)
                    {
                        StuBlankAnswer an = JsonConvert.DeserializeObject <StuBlankAnswer>(o.ToString());
                        realEntity.Yta_Answer_Obj.AnswerCollection.Add(an);
                    }
                    else if ((int)o["Type"] == (int)SubjectTypeEnum.判断题)
                    {
                        StuTrueFalseAnswer an = JsonConvert.DeserializeObject <StuTrueFalseAnswer>(o.ToString());
                        realEntity.Yta_Answer_Obj.AnswerCollection.Add(an);
                    }
                    else if ((int)o["Type"] == (int)SubjectTypeEnum.择填空)
                    {
                        StuSelectBlankAnswer an = JsonConvert.DeserializeObject <StuSelectBlankAnswer>(o.ToString());
                        realEntity.Yta_Answer_Obj.AnswerCollection.Add(an);
                    }
                    else if ((int)o["Type"] == (int)SubjectTypeEnum.连线题)
                    {
                        StuMatchAnswer an = JsonConvert.DeserializeObject <StuMatchAnswer>(o.ToString());
                        realEntity.Yta_Answer_Obj.AnswerCollection.Add(an);
                    }
                    else if ((int)o["Type"] == (int)SubjectTypeEnum.主观题)
                    {
                        StuFreeAnswer an = JsonConvert.DeserializeObject <StuFreeAnswer>(o.ToString());
                        realEntity.Yta_Answer_Obj.AnswerCollection.Add(an);
                    }
                    else if ((int)o["Type"] == (int)SubjectTypeEnum.圈点批注标色)
                    {
                        StuMarkColorAnswer an = JsonConvert.DeserializeObject <StuMarkColorAnswer>(o.ToString());
                        realEntity.Yta_Answer_Obj.AnswerCollection.Add(an);
                    }
                    else if ((int)o["Type"] == (int)SubjectTypeEnum.圈点批注断句)
                    {
                        StuMarkCutAnswer an = JsonConvert.DeserializeObject <StuMarkCutAnswer>(o.ToString());
                        realEntity.Yta_Answer_Obj.AnswerCollection.Add(an);
                    }
                }
            }
            return(realEntity);
        }