using Edu.Cache.User;
using Edu.Common.API;
using Edu.Common.Data;
using Edu.Common.Enum.Course;
using Edu.Common.Enum.Question;
using Edu.Common.Plugin;
using Edu.Model.ViewModel.Question;
using Edu.Module.Question;
using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Edu.WebApi.Controllers.Course
{
    [Route("api/[controller]/[action]")]
    [ApiExceptionFilter]
    [ApiController]
    [EnableCors("AllowCors")]
    public class QuestionController : BaseController
    {
        /// <summary>
        /// 题库处理类对象
        /// </summary>
        private readonly QuestionModule questionModule = AOP.AOPHelper.CreateAOPObject<QuestionModule>();

        #region 题库管理
        /// <summary>
        /// 获取课程问题分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetQuestionBankPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Question_Bank_ViewModel()
            {
                BankId = base.ParmJObj.GetInt("BankId"),
                BankName = base.ParmJObj.GetStringValue("BankName"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var list = questionModule.GetQuestionBankPageListModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> resultList = new List<object>();
            int index = 1;
            foreach (var item in list)
            {
                if (item.CreateBy > 0)
                {
                    item.CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                }
                resultList.Add(new
                {
                    RowNum=(pageModel.PageIndex-1)* pageModel.PageSize+index,
                    item.BankId,
                    item.BankNo,
                    item.BankName,
                    item.CreateByName,
                    item.QuestionCount
                });
                index++;
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = resultList;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取题库实体
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetQuestionBank()
        {
            var BankId = base.ParmJObj.GetInt("BankId", 0);
            var extModel = questionModule.GetQuestionBankModule(BankId);
            return ApiResult.Success(data: extModel);
        }


        /// <summary>
        /// 添加修改题库
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetQuestionBank()
        {
            var extModel = Common.Plugin.JsonHelper.DeserializeObject<RB_Question_Bank_ViewModel>(RequestParm.Msg.ToString());
            extModel.CreateTime = DateTime.Now;
            extModel.CreateBy = base.UserInfo.Id;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Status = Common.Enum.DateStateEnum.Normal;
            extModel.Group_Id = base.UserInfo.Group_Id;
            extModel.School_Id = base.UserInfo.School_Id;
            bool flag = questionModule.SetQuestionBankModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 删除题库
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveQuestionBank()
        {
            var bankId = base.ParmJObj.GetInt("bankId", 0);
            int status= base.ParmJObj.GetInt("status", 0);
            var flag = questionModule.RemoveQuestionBankModule(bankId, status);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }


        /// <summary>
        /// 获取题目类型列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetQuestionTypeList()
        {
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Question_Type_ViewModel>(RequestParm.Msg.ToString());
            var list = questionModule.GetQuestionTypeListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取课程问题分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetQuestionPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Question_ViewModel()
            {
                CourseId = base.ParmJObj.GetInt("CourseId"),
                Title = base.ParmJObj.GetStringValue("Title"),
                PointName = base.ParmJObj.GetStringValue("PointName"),
                BankId=base.ParmJObj.GetInt("BankId")
            };
            try
            {
                var DifficultyTypeList = Common.Plugin.JsonHelper.DeserializeObject<List<int>>(base.ParmJObj.GetStringValue("DifficultyType"));
                if (DifficultyTypeList != null && DifficultyTypeList.Count > 0 && !DifficultyTypeList.Contains(0))
                {
                    query.QDifficultyType = string.Join(",", DifficultyTypeList);
                }
            }
            catch
            {
            }
            try
            {
                var QuestionTypeIdList = Common.Plugin.JsonHelper.DeserializeObject<List<int>>(base.ParmJObj.GetStringValue("QuestionTypeId"));
                if (QuestionTypeIdList != null && QuestionTypeIdList.Count > 0)
                {
                    query.QQuestionTypeStr = string.Join(",", QuestionTypeIdList);
                }
            }
            catch
            {
            }
            try
            {
                var categoryList = Common.Plugin.JsonHelper.DeserializeObject<List<int>>(base.ParmJObj.GetStringValue("QCategoryId"));
                if (categoryList != null && categoryList.Count > 0)
                {
                    query.QCategoryId = string.Join(",", categoryList);
                }
            }
            catch
            { 
            
            }
            var list = questionModule.GetQuestionPageListModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> resultList = new List<object>();
            int index = 1;
            foreach (var item in list)
            {
                if (item.CreateBy > 0)
                {
                    item.CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                }
                if (item.UpdateBy > 0)
                {
                    item.UpdateByName = UserReidsCache.GetUserLoginInfo(item.UpdateBy)?.AccountName ?? "";
                }
                // 定义正则表达式用来匹配 img 标签    
                string str=@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>";
                string newTitle = item.Title;
                try
                {
                    newTitle = Regex.Replace(newTitle, str, "[图片]");
                }
                catch
                {
                    newTitle = item.Title;
                }
                try
                {
                    newTitle = Regex.Replace(newTitle, @"<iframe\s*[^>]*>", "[音频", RegexOptions.IgnoreCase);
                    newTitle = Regex.Replace(newTitle, @"</iframe>", "]", RegexOptions.IgnoreCase);
                }
                catch
                {
                    newTitle = item.Title;
                }
                resultList.Add(new
                {
                    Number=(pageModel.PageIndex-1)*pageModel.PageSize+index,
                    item.QuestionId,
                    item.CourseId,
                    Title= newTitle,
                    item.QuestionTypeId,
                    item.QuestionTypeKey,
                    QuestionTypeName=item.QuestionTypeKey!= "single-number" ? item.QuestionTypeName:"选择题",
                    item.CreateByName,
                    item.CreateTimeStr,
                    item.DifficultyType,
                    item.CategoryName,
                    DifficultyTypeName = item.DifficultyType.ToName(),
                    item.LevelTypeName
                }); ;
                index++;
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = resultList;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取问题难易列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [HttpGet]
        public ApiResult GetDifficultyType()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(DifficultyTypeEnum));
            if (list != null)
            {
                list.Insert(0, new EnumItem()
                {
                    Id = 0,
                    Name = "全部难度"
                });
            }
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取问题大类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [HttpGet]
        public ApiResult GetQuestionCategory()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(QuestionCategoryEnum));
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 问题考级程度
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [HttpGet]
        public ApiResult GetQuestionLevelType()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(LevelTypeEnum));
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取课程问题列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetQuestionList()
        {
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Question_ViewModel>(RequestParm.Msg.ToString());
            var list = questionModule.GetQuestionListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 添加修改问题
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetQuestion()
        {
            var extModel = new RB_Question_ViewModel()
            {
                Answer = base.ParmJObj.GetStringValue("Answer"),
                AnswerParse = base.ParmJObj.GetStringValue("AnswerParse"),
                CourseId = base.ParmJObj.GetInt("CourseId"),
                DifficultyType = (DifficultyTypeEnum)base.ParmJObj.GetInt("DifficultyType"),
                IsMutex = base.ParmJObj.GetInt("IsMutex"),
                IsUpdateJobExam = base.ParmJObj.GetInt("IsUpdateJobExam"),
                Knowledge = base.ParmJObj.GetStringValue("Knowledge"),
                QuestionContent = base.ParmJObj.GetStringValue("QuestionContent"),
                QuestionId = base.ParmJObj.GetInt("QuestionId"),
                QuestionTypeId = base.ParmJObj.GetInt("QuestionTypeId"),
                QuestionTypeKey = base.ParmJObj.GetStringValue("QuestionTypeKey"),
                SortNum = base.ParmJObj.GetInt("SortNum"),
                Title = base.ParmJObj.GetStringValue("Title"),
                Category=(QuestionCategoryEnum)base.ParmJObj.GetInt("Category"),
                LevelType= (LevelTypeEnum)base.ParmJObj.GetInt("LevelType"),
                BankId=base.ParmJObj.GetInt("BankId")
            };
            if (string.IsNullOrEmpty(extModel.Title))
            {
                return ApiResult.Failed(message: "请填写问题题干!");
            }

            //单选、多选、单选(数字)题
            if (extModel.QuestionTypeKey == "single" || extModel.QuestionTypeKey == "multiple" || extModel.QuestionTypeKey == "single-number")
            {
                var optionItems = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(extModel.QuestionContent);
                string message = CheckChoose(optionItems);
                if (!string.IsNullOrEmpty(message))
                {
                    return ApiResult.Failed(message: message);
                }
            }
            //填空题
            else if (extModel.QuestionTypeKey == "fill-in")
            {
                var fillInList = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(extModel.QuestionContent);
                string fillMessage = CheckFillIn(fillInList);
                if (!string.IsNullOrEmpty(fillMessage))
                {
                    return ApiResult.Failed(message: fillMessage);
                }
            }
            //简答题
            else if (extModel.QuestionTypeKey == "short-answer")
            {
                string shortMessage = CheckShortAnswer(extModel.Answer);
                if (!string.IsNullOrEmpty(shortMessage))
                {
                    return ApiResult.Failed(message: shortMessage);
                }
                extModel.QuestionContent = "";
            }
            //名词解释
            else if (extModel.QuestionTypeKey == "noun-explanation")
            {
                if (string.IsNullOrEmpty(extModel.Answer))
                {
                    return ApiResult.Failed(message: "请填写名词解释答案!");
                }
                extModel.QuestionContent = "";
            }
            //论述题
            else if (extModel.QuestionTypeKey == "essay-question")
            {
                if (string.IsNullOrEmpty(extModel.Answer))
                {
                    return ApiResult.Failed(message: "请填写论述题答案!");
                }
                extModel.QuestionContent = "";
            }
            //计算题
            else if (extModel.QuestionTypeKey == "calculation")
            {
                if (string.IsNullOrEmpty(extModel.Answer))
                {
                    return ApiResult.Failed(message: "请填写计算题答案!");
                }
                extModel.QuestionContent = "";
            }
            //分录题、资料题
            else if (extModel.QuestionTypeKey == "entry-problem" || extModel.QuestionTypeKey == "data-question")
            {
                var entryList = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(extModel.QuestionContent);
                if (entryList != null && entryList.Count > 0)
                {
                    if (entryList.Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
                    {
                        return ApiResult.Failed(message: "请输入答案!");
                    }
                }
                else
                {
                    return ApiResult.Failed(message: "请添加答案!");
                }
            }
            //排序题
            else if (extModel.QuestionTypeKey == "sorting-problem")
            {
                var sortList = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(extModel.QuestionContent);
                if (sortList != null && sortList.Count > 0)
                {
                    if (sortList[0].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
                    {
                        return ApiResult.Failed(message: "请输入选项内容!");
                    }
                }
                else
                {
                    return ApiResult.Failed(message: "请添加选项!");
                }
            }
            //连线题
            else if (extModel.QuestionTypeKey == "matching")
            {
                var matchList = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(extModel.QuestionContent);
                if (matchList != null && matchList.Count > 0)
                {
                    if (matchList[0] != null && matchList[0].Count > 0)
                    {
                        if (matchList[0].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
                        {
                            return ApiResult.Failed(message: "第一组选项内容不能为空!");
                        }
                    }
                    else
                    {
                        return ApiResult.Failed(message: "请添加第一组选项!");
                    }
                    if (matchList.Count > 1 && matchList[1] != null && matchList[1].Count > 0)
                    {
                        if (matchList[1].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
                        {
                            return ApiResult.Failed(message: "第二组选项内容不能为空!");
                        }
                    }
                    else
                    {
                        return ApiResult.Failed(message: "请添加第二组选项!");
                    }
                    if (matchList.Count > 2)
                    {
                        if (matchList[2].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
                        {
                            return ApiResult.Failed(message: "请设置答案!");
                        }
                    }
                }
                else
                {
                    return ApiResult.Failed(message: "请添加选项!");
                }
            }
            //完型填空
            else if (extModel.QuestionTypeKey == "cloze")
            {
                var clozeList = Common.Plugin.JsonHelper.DeserializeObject<List<List<optionItem>>>(extModel.QuestionContent);
                if (clozeList != null && clozeList.Count > 0)
                {
                    int index = 1;
                    foreach (var subList in clozeList)
                    {
                        if (subList.Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
                        {
                            return ApiResult.Failed(message: string.Format("第{0}小题选项内容不能为空!", index));
                        }
                        if (!(subList.Where(qitem => qitem.IsAnswer == true).Count() > 0))
                        {
                            return ApiResult.Failed(message: string.Format("请设置第{0}小题选项的正确答案!", index));
                        }
                        index++;
                    }
                }
                else
                {
                    return ApiResult.Failed(message: "请添加小题!");
                }
            }
            //口语题
            else if (extModel.QuestionTypeKey == "spoken")
            {
                if (string.IsNullOrEmpty(extModel.Answer))
                {
                    return ApiResult.Failed(message: "请填写口语题答案!");
                }
            }
            //其它题
            else if (extModel.QuestionTypeKey == "other")
            {
                if (string.IsNullOrEmpty(extModel.Answer))
                {
                    return ApiResult.Failed(message: "请填写其它题答案!");
                }
            }
            //阅读理解和听力题
            else if (extModel.QuestionTypeKey == "reading-comprehensio" || extModel.QuestionTypeKey == "listening")
            {
                var readingList = Common.Plugin.JsonHelper.DeserializeObject<List<readingComprehensioItem>>(extModel.QuestionContent);
                if (readingList != null && readingList.Count > 0)
                {
                    foreach (var item in readingList)
                    {
                        if (string.IsNullOrEmpty(item.SubTitle))
                        {
                            return ApiResult.Failed(message: "请填写题干!");
                        }
                        switch (item.QuestionKey)
                        {
                            //单选题
                            case "single":
                                var singleAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
                                string singleMessage = CheckChoose(singleAnwser);
                                if (!string.IsNullOrEmpty(singleMessage))
                                {
                                    return ApiResult.Failed(message: singleMessage);
                                }
                                break;
                            //多选题
                            case "multiple":
                                var multipleAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
                                string multipleMessage = CheckChoose(multipleAnwser);
                                if (!string.IsNullOrEmpty(multipleMessage))
                                {
                                    return ApiResult.Failed(message: multipleMessage);
                                }
                                break;
                            //填空题
                            case "fill-in":
                                var r_fillInList = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
                                string r_fillMessage = CheckFillIn(r_fillInList);
                                if (!string.IsNullOrEmpty(r_fillMessage))
                                {
                                    return ApiResult.Failed(message: r_fillMessage);
                                }
                                break;
                            //判断题
                            case "judge":
                                item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
                                break;
                            //简答题
                            case "short-answer":
                                var shortAnswer = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
                                string r_shortMessage = CheckShortAnswer(shortAnswer[0].Content);
                                if (!string.IsNullOrEmpty(r_shortMessage))
                                {
                                    return ApiResult.Failed(message: r_shortMessage);
                                }
                                break;
                        }
                    }
                }
                else
                {
                    return ApiResult.Failed(message: "请添加小题!");
                }
            }
            //共用选择题
            else if (extModel.QuestionTypeKey == "sharing-choose")
            {
                var shareList = Common.Plugin.JsonHelper.DeserializeObject<List<List<matchingItem>>>(extModel.QuestionContent);
                if (shareList != null && shareList.Count ==2)
                {
                    if (shareList[0].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
                    {
                        return ApiResult.Failed(message: string.Format("选项内容不能为空!"));
                    }
                    //判断选项是否重复
                    if (shareList[0].GroupBy(qitem => new { qitem.Content }).Where(qitem => qitem.Count() > 1).Count() > 0)
                    {
                        return ApiResult.Failed(message: string.Format("选项内容不能相同!"));
                    }
                    if (shareList[1].Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
                    {
                        return ApiResult.Failed(message: string.Format("题干不能为空!"));
                    }
                    //判断题干是否重复
                    if (shareList[1].GroupBy(qitem => new { qitem.Content }).Where(qitem => qitem.Count() > 1).Count() > 0)
                    {
                        return ApiResult.Failed(message: string.Format("题干不能相同!"));
                    }
                    //判断题干是否设置正确选项
                    if (shareList[1].Where(qitem => string.IsNullOrEmpty(qitem.Name)).Count() > 0)
                    {
                        return ApiResult.Failed(message: string.Format("请设置题干的正确选项!"));
                    }
                } 
                else
                {
                    return ApiResult.Failed(message: "请添加选项!");
                }
            }
            extModel.CreateTime = DateTime.Now;
            extModel.CreateBy = base.UserInfo.Id;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            bool flag = questionModule.SetQuestionModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 批量修改问题考级程度
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetBatchQuestionLevel()
        {
            var LevelType = (LevelTypeEnum)base.ParmJObj.GetInt("LevelType");
            List<int> questionIds = Common.Plugin.JsonHelper.DeserializeObject<List<int>>(base.ParmJObj.GetStringValue("questionIds"));
            var flag = questionModule.SetBatchQuestionLevelModule(LevelType, questionIds);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }
        
        /// <summary>
        /// 选择题验证
        /// </summary>
        /// <param name="optionItems"></param>
        /// <returns></returns>
        private string CheckChoose(List<optionItem> optionItems)
        {
            string message = "";
            if (optionItems != null && optionItems.Count > 0)
            {
                if (optionItems.Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
                {
                    message = "选项不能为空!";
                }
                //判断选项是否重复
                if (optionItems.GroupBy(qitem => new { qitem.Content }).Where(qitem => qitem.Count() > 1).Count() > 0)
                {
                    message = "选项不能相同!";
                }
                if (!(optionItems.Where(qitem => qitem.IsAnswer == true).Count() > 0))
                {
                    message = "请设置正确的选项!";
                }
            }
            else
            {
                message = "请添加选择题选项!";
            }
            return message;
        }

        /// <summary>
        /// 验证填空题
        /// </summary>
        /// <param name="fillInList"></param>
        /// <returns></returns>
        private string CheckFillIn(List<fillInItem> fillInList)
        {
            string message = "";
            if (fillInList != null && fillInList.Count > 0)
            {
                if (fillInList.Where(qitem => string.IsNullOrEmpty(qitem.Content)).Count() > 0)
                {
                    message = "请输入答案!";
                }
            }
            else
            {
                message = "请添加答案!";
            }
            return message;
        }

        /// <summary>
        /// 验证简答题
        /// </summary>
        /// <param name="answer"></param>
        /// <returns></returns>
        private string CheckShortAnswer(string answer)
        {
            string message = "";
            if (string.IsNullOrEmpty(answer))
            {
                message= "请填写简答题答案!";
            }
            return message;
        }

        /// <summary>
        /// 获取课程问题
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetQuestion()
        {
            var QuestionId = base.ParmJObj.GetInt("QuestionId", 0);
            int isReplaceClozeTitle = base.ParmJObj.GetInt("isReplaceClozeTitle", 0);
            var extModel = questionModule.GetQuestionModule(QuestionId,isReplaceClozeTitle:isReplaceClozeTitle);
            return ApiResult.Success(data: extModel);
        }

        /// <summary>
        /// 批量添加修改问题
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetQuestionBeatch()
        {
            bool flag=false;
            var list = Common.Plugin.JsonHelper.DeserializeObject<List<RB_Question_ViewModel>>(RequestParm.Msg.ToString());
            if (list != null && list.Count > 0)
            {
                foreach (var item in list)
                {
                    flag = questionModule.SetQuestionModule(item);
                }
            }
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 删除课程问题
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveQuestion()
        {
            var QuestionId = base.ParmJObj.GetInt("QuestionId", 0);
            var flag = questionModule.RemoveQuestionModule(QuestionId);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 更新问题排序
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult UpdateQuestionSort()
        {
            var curQId = base.ParmJObj.GetInt("curQId", 0);
            var targetQId = base.ParmJObj.GetInt("targetQId", 0);
            var flag = questionModule.UpdateQuestionSortModule(curQId, targetQId);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 复制问题
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult CopyQuestion()
        {
            var questionId = base.ParmJObj.GetInt("QuestionId", 0);
            if (questionId > 0)
            {
                var copyModel = questionModule.GetQuestionModule(questionId);
                if (copyModel != null)
                {
                    copyModel.QuestionId = 0;
                    copyModel.CreateTime = DateTime.Now;
                    copyModel.CreateBy = base.UserInfo.Id;
                    copyModel.UpdateBy = base.UserInfo.Id;
                    copyModel.UpdateTime = DateTime.Now;
                }
                var flag = questionModule.SetQuestionModule(copyModel);
                return flag ? ApiResult.Success() : ApiResult.Failed();
            }
            else
            {
                return ApiResult.Failed(message: "请选择要复制的问题!");
            }
        }

        /// <summary>
        /// 获取课程问题知识点列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetPointList()
        {
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Question_Point_ViewModel>(RequestParm.Msg.ToString());
            var list = questionModule.GetPointListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取知识点分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetPointPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Question_Point_ViewModel>(RequestParm.Msg.ToString());
            var list = questionModule.GetPointPageListModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            foreach (var item in list)
            {
                if (item.CreateBy > 0)
                {
                    item.CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                }
                if (item.UpdateBy > 0)
                {
                    item.UpdateByName = UserReidsCache.GetUserLoginInfo(item.UpdateBy)?.AccountName ?? "";
                }
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取课程问题知识点
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetQuestionPoint()
        {
            var PointId = base.ParmJObj.GetInt("PointId", 0);
            var extModel = questionModule.GetQuestionPointModule(PointId);
            return ApiResult.Success(data: extModel);
        }


        /// <summary>
        /// 添加修改问题知识点
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetQuestionPoint()
        {
            var extModel = Common.Plugin.JsonHelper.DeserializeObject<RB_Question_Point_ViewModel>(RequestParm.Msg.ToString());
            extModel.CreateTime = DateTime.Now;
            extModel.CreateBy = base.UserInfo.Id;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            bool flag = questionModule.SetQuestionPointModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 删除课程问题知识点
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveQuestionPoint()
        {
            var PointId = base.ParmJObj.GetInt("PointId", 0);
            var flag = questionModule.RemoveQuestionPointModule(PointId);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }
        #endregion

        #region 问题导入
        /// <summary>
        /// 导入Excel问题
        /// </summary>
        /// <returns></returns>
        public ApiResult ImportExcelQuestion(string filePath,int CourseId,int Uid)
        {
            var userInfo = base.GetUserInfo(Uid);
            var resultList = new List<RB_Question_ViewModel>();
            var list = Common.Data.QuestionHelper.GetXlsQuestionData(filePath);
            if (list != null && list.Count > 0)
            {
                var questionTypeList = questionModule.GetQuestionTypeListModule(new RB_Question_Type_ViewModel());
                foreach (var item in list)
                {
                    var model = GetQuestionModel(item, questionTypeList);
                    model.CourseId = CourseId;
                    model.CreateTime = DateTime.Now;
                    model.CreateBy = userInfo.Id;
                    model.UpdateBy = userInfo.Id;
                    model.UpdateTime = DateTime.Now;
                    resultList.Add(model);
                }
            }
            System.IO.File.Delete(filePath);
            return ApiResult.Success(data:resultList);
        }

        /// <summary>
        /// 解析Word
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="CourseId"></param>
        /// <param name="Uid"></param>
        /// <returns></returns>
        public ApiResult ImportWordQuestion(string filePath, int CourseId, int Uid, bool isDelete = false)
        {
            var userInfo = base.GetUserInfo(Uid);
            var resultList = new List<RB_Question_ViewModel>();
            var list = Common.Data.QuestionHelper.GetWordQuestionData(filePath);
            if (list != null && list.Count > 0)
            {
                var questionTypeList = questionModule.GetQuestionTypeListModule(new RB_Question_Type_ViewModel());
                foreach (var item in list)
                {
                    var model = GetQuestionModel(item, questionTypeList);
                    model.CourseId = CourseId;
                    model.CreateTime = DateTime.Now;
                    model.CreateBy = userInfo.Id;
                    model.UpdateBy = userInfo.Id;
                    model.UpdateTime = DateTime.Now;
                    resultList.Add(model);
                }
            }
            if (isDelete)
            {
                System.IO.File.Delete(filePath);
            }
            return ApiResult.Success(data: resultList);
        }

        /// <summary>
        /// 获取导入数据
        /// </summary>
        /// <param name="item"></param>
        /// <param name="difficultyList"></param>
        /// <param name="questionTypeList"></param>
        /// <returns></returns>
        private RB_Question_ViewModel GetQuestionModel(ImportModel item, List<RB_Question_Type_ViewModel> questionTypeList)
        {
            var DifficultyType = DifficultyTypeEnum.Easy;
            if (item.EasyType == "中")
            {
                DifficultyType = DifficultyTypeEnum.Middle;
            }
            if (item.EasyType == "难")
            {
                DifficultyType = DifficultyTypeEnum.Difficult;
            }
            var Category = QuestionCategoryEnum.Default;
            if (!string.IsNullOrEmpty(item.Category))
            {
                switch (item.Category)
                {
                    case "读音选择题":
                        Category = QuestionCategoryEnum.JapaneseSoundChoose;
                        break;
                    case "汉字选择题":
                        Category = QuestionCategoryEnum.ChineseChoose;
                        break;
                    case "选择最适当的单词":
                        Category = QuestionCategoryEnum.ChooseWord;
                        break;
                    case "选择意义最接近的单词":
                        Category = QuestionCategoryEnum.ChooseMean;
                        break;
                    case "选择单词正确用法":
                        Category = QuestionCategoryEnum.ChooseWordUse;
                        break;
                    case "选择语法正确的一项":
                        Category = QuestionCategoryEnum.ChooseGrammarUse;
                        break;
                    case "选择★应该填入的词":
                        Category = QuestionCategoryEnum.ChooseFillInWord;
                        break;
                    case "阅读选择":
                        Category = QuestionCategoryEnum.ReadingChoose;
                        break;
                }
            }
            var questionTypeModel = questionTypeList?.Where(qitem => qitem.Name == item.QuestionTypeName)?.FirstOrDefault();
            RB_Question_ViewModel model = new RB_Question_ViewModel
            {
                Title = item.QuestionTitle,
                DifficultyType = DifficultyType,
                AnswerParse = item.AnswerAnalysis,
                QuestionTypeId = questionTypeModel?.QId ?? 0,
                QuestionTypeKey = questionTypeModel?.Key ?? "",
                QuestionTypeName= questionTypeModel?.Name??"",
                Category=Category
            };
            Int32.TryParse(item.ChooseOptionCount, out int ChooseOptionCount);
            switch (item.QuestionTypeName)
            {
                case "单选题":
                    AnalysisSingle(ChooseOptionCount, item, model, questionTypeList);
                    break;
                case "多选题":
                    AnalysisMultiple(ChooseOptionCount, item, model, questionTypeList);
                    break;

                case "填空题":
                    if (ChooseOptionCount > 0)
                    {
                        List<fillInItem> fillInList = new List<fillInItem>();
                        for (var i = 0; i < ChooseOptionCount; i++)
                        {
                            var singleModel = new fillInItem()
                            {
                                Content = "",
                            };
                            if (i == 0)
                            {
                                singleModel.Content = item.OptionA;
                            }
                            if (i == 1)
                            {
                                singleModel.Content = item.OptionB;
                            }
                            if (i == 2)
                            {
                                singleModel.Content = item.OptionC;
                            }
                            if (i == 3)
                            {
                                singleModel.Content = item.OptionD;
                            }
                            if (i == 4)
                            {
                                singleModel.Content = item.OptionE;
                            }
                            if (i == 5)
                            {
                                singleModel.Content = item.OptionF;
                            }
                            if (i == 6)
                            {
                                singleModel.Content = item.OptionG;
                            }
                            if (i == 7)
                            {
                                singleModel.Content = item.OptionH;
                            }
                            fillInList.Add(singleModel);
                        }
                        string f_answer = "";
                        foreach (var fItem in fillInList)
                        {
                            f_answer += "★" + fItem.Content;
                        }
                        if (!string.IsNullOrEmpty(f_answer))
                        {
                            f_answer = f_answer[1..];
                        }
                        model.Answer = f_answer;
                        model.QuestionContent = Common.Plugin.JsonHelper.Serialize(fillInList);
                    }
                    if (model.QuestionTypeId == 0)
                    {
                        var tempModel = questionTypeList.Where(qitem => qitem.Key == "fill-in")?.FirstOrDefault();
                        model.QuestionTypeId = tempModel?.QId ?? 0;
                        model.QuestionTypeKey = tempModel?.Key ?? "";
                    }
                    break;

                case "判断题":
                    if (ChooseOptionCount > 0)
                    {
                        List<optionItem> judgeList = new List<optionItem>();
                        for (var i = 0; i < ChooseOptionCount; i++)
                        {
                            var singleModel = new optionItem()
                            {
                                Name = Common.ConvertHelper.GetEnChar(i),
                                Content = "",
                            };
                            if (Common.Plugin.StringHelper.IsUpperLetter(item.QuestionAnswer))
                            {
                                singleModel.IsAnswer = item.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i));
                            }
                            else if (item.QuestionAnswer.Contains("对"))
                            {
                                singleModel.IsAnswer = (i == 0);
                            }
                            else if (item.QuestionAnswer.Contains("错"))
                            {
                                singleModel.IsAnswer = (i > 0);
                            }
                            if (i == 0)
                            {
                                singleModel.Content = item.OptionA;
                            }
                            if (i == 1)
                            {
                                singleModel.Content = item.OptionB;
                            }
                            if (i == 2)
                            {
                                singleModel.Content = item.OptionC;
                            }
                            if (i == 3)
                            {
                                singleModel.Content = item.OptionD;
                            }
                            if (i == 4)
                            {
                                singleModel.Content = item.OptionE;
                            }
                            if (i == 5)
                            {
                                singleModel.Content = item.OptionF;
                            }
                            if (i == 6)
                            {
                                singleModel.Content = item.OptionG;
                            }
                            if (i == 7)
                            {
                                singleModel.Content = item.OptionH;
                            }
                            if (singleModel.IsAnswer)
                            {
                                model.Answer = singleModel.Name;
                            }
                            judgeList.Add(singleModel);
                        }
                        model.QuestionContent = Common.Plugin.JsonHelper.Serialize(judgeList);
                    }
                    if (model.QuestionTypeId == 0)
                    {
                        var tempModel = questionTypeList.Where(qitem => qitem.Key == "judge")?.FirstOrDefault();
                        model.QuestionTypeId = tempModel?.QId ?? 0;
                        model.QuestionTypeKey = tempModel?.Key ?? "";
                    }
                    break;

                case "简答题":
                    model.Answer = item.QuestionAnswer;
                    if (model.QuestionTypeId == 0)
                    {
                        var tempModel = questionTypeList.Where(qitem => qitem.Key == "short-answer")?.FirstOrDefault();
                        model.QuestionTypeId = tempModel?.QId ?? 0;
                        model.QuestionTypeKey = tempModel?.Key ?? "";
                    }
                    break;

                case "名词解释":
                    model.Answer = item.QuestionAnswer;
                    if (model.QuestionTypeId == 0)
                    {
                        var tempModel = questionTypeList.Where(qitem => qitem.Key == "noun-explanation")?.FirstOrDefault();
                        model.QuestionTypeId = tempModel?.QId ?? 0;
                        model.QuestionTypeKey = tempModel?.Key ?? "";
                    }
                    break;
                case "论述题":
                    model.Answer = item.QuestionAnswer;
                    if (model.QuestionTypeId == 0)
                    {
                        var tempModel = questionTypeList.Where(qitem => qitem.Key == "essay-question")?.FirstOrDefault();
                        model.QuestionTypeId = tempModel?.QId ?? 0;
                        model.QuestionTypeKey = tempModel?.Key ?? "";
                    }
                    break;

                case "分录题":
                    if (ChooseOptionCount > 0)
                    {
                        List<fillInItem> fillInList = new List<fillInItem>();
                        for (var i = 0; i < ChooseOptionCount; i++)
                        {
                            var singleModel = new fillInItem()
                            {
                                Content = "",
                            };
                            if (i == 0)
                            {
                                singleModel.Content = item.OptionA;
                            }
                            if (i == 1)
                            {
                                singleModel.Content = item.OptionB;
                            }
                            if (i == 2)
                            {
                                singleModel.Content = item.OptionC;
                            }
                            if (i == 3)
                            {
                                singleModel.Content = item.OptionD;
                            }
                            if (i == 4)
                            {
                                singleModel.Content = item.OptionE;
                            }
                            if (i == 5)
                            {
                                singleModel.Content = item.OptionF;
                            }
                            if (i == 6)
                            {
                                singleModel.Content = item.OptionG;
                            }
                            if (i == 7)
                            {
                                singleModel.Content = item.OptionH;
                            }
                            fillInList.Add(singleModel);
                        }
                        string f_answer = "";
                        foreach (var fItem in fillInList)
                        {
                            f_answer += "★" + fItem.Content;
                        }
                        if (!string.IsNullOrEmpty(f_answer))
                        {
                            f_answer = f_answer[1..];
                        }
                        model.Answer = f_answer;
                        model.QuestionContent = Common.Plugin.JsonHelper.Serialize(fillInList);
                    }
                    if (model.QuestionTypeId == 0)
                    {
                        var tempModel = questionTypeList.Where(qitem => qitem.Key == "entry-problem")?.FirstOrDefault();
                        model.QuestionTypeId = tempModel?.QId ?? 0;
                        model.QuestionTypeKey = tempModel?.Key ?? "";
                    }
                    break;

                case "资料题":
                    if (ChooseOptionCount > 0)
                    {
                        List<fillInItem> fillInList = new List<fillInItem>();
                        for (var i = 0; i < ChooseOptionCount; i++)
                        {
                            var singleModel = new fillInItem()
                            {
                                Content = "",
                            };
                            if (i == 0)
                            {
                                singleModel.Content = item.OptionA;
                            }
                            if (i == 1)
                            {
                                singleModel.Content = item.OptionB;
                            }
                            if (i == 2)
                            {
                                singleModel.Content = item.OptionC;
                            }
                            if (i == 3)
                            {
                                singleModel.Content = item.OptionD;
                            }
                            if (i == 4)
                            {
                                singleModel.Content = item.OptionE;
                            }
                            if (i == 5)
                            {
                                singleModel.Content = item.OptionF;
                            }
                            if (i == 6)
                            {
                                singleModel.Content = item.OptionG;
                            }
                            if (i == 7)
                            {
                                singleModel.Content = item.OptionH;
                            }
                            fillInList.Add(singleModel);
                        }
                        string f_answer = "";
                        foreach (var fItem in fillInList)
                        {
                            f_answer += "★" + fItem.Content;
                        }
                        if (!string.IsNullOrEmpty(f_answer))
                        {
                            f_answer = f_answer[1..];
                        }
                        model.Answer = f_answer;
                        model.QuestionContent = Common.Plugin.JsonHelper.Serialize(fillInList);
                    }
                    if (model.QuestionTypeId == 0)
                    {
                        var tempModel = questionTypeList.Where(qitem => qitem.Key == "data-question")?.FirstOrDefault();
                        model.QuestionTypeId = tempModel?.QId ?? 0;
                        model.QuestionTypeKey = tempModel?.Key ?? "";
                    }
                    break;

                case "阅读理解":
                    List<readingComprehensioItem> readingList = new List<readingComprehensioItem>();
                        foreach (var subItem in item.SubQuestionList)
                        {
                        Int32.TryParse(subItem.ChooseOptionCount, out int subChooseCount);
                        List<optionItem> singleList = new List<optionItem>();
                        switch (subItem.QuestionTypeName)
                            {
                                //单选题
                                case "单选题":
                                readingComprehensioItem readingModel = new readingComprehensioItem()
                                {
                                    QuestionKey = "single",
                                    QuestionName = "单选题",
                                    QuestionType = 1,
                                    SubTitle = subItem.QuestionTitle,
                                    SubAnwser=new object()
                                };
                               
                                for (var i = 0; i < subChooseCount; i++)
                                {
                                    var singleModel = new optionItem()
                                    {
                                        Name = Common.ConvertHelper.GetEnChar(i),
                                        Content = "",
                                        IsAnswer = subItem.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i))
                                    };
                                    if (i == 0)
                                    {
                                        singleModel.Content = subItem.OptionA;
                                    }
                                    if (i == 1)
                                    {
                                        singleModel.Content = subItem.OptionB;
                                    }
                                    if (i == 2)
                                    {
                                        singleModel.Content = subItem.OptionC;
                                    }
                                    if (i == 3)
                                    {
                                        singleModel.Content = subItem.OptionD;
                                    }
                                    if (singleModel.IsAnswer)
                                    {
                                        model.Answer += singleModel.Name + ",";
                                    }
                                    singleList.Add(singleModel);
                                }
                                readingModel.SubAnwser = singleList;
                                readingList.Add(readingModel);
                                break;
                            case "单选题(数字)":
                                readingComprehensioItem readingModel2 = new readingComprehensioItem()
                                {
                                    QuestionKey = "single-number",
                                    QuestionName = "单选题(数字)",
                                    QuestionType = 19,
                                    SubTitle = subItem.QuestionTitle,
                                    SubAnwser = new object()
                                };
                       
                                for (var i = 0; i < subChooseCount; i++)
                                {
                                    var singleModel = new optionItem()
                                    {
                                        Name = (i+1).ToString(),
                                        Content = "",
                                        IsAnswer = subItem.QuestionAnswer.Trim()==(i+1).ToString()
                                    };
                                    if (i == 0)
                                    {
                                        singleModel.Content = subItem.OptionA;
                                    }
                                    if (i == 1)
                                    {
                                        singleModel.Content = subItem.OptionB;
                                    }
                                    if (i == 2)
                                    {
                                        singleModel.Content = subItem.OptionC;
                                    }
                                    if (i == 3)
                                    {
                                        singleModel.Content = subItem.OptionD;
                                    }
                                    if (singleModel.IsAnswer)
                                    {
                                        model.Answer += singleModel.Name + ",";
                                    }
                                    singleList.Add(singleModel);
                                }
                                readingModel2.SubAnwser = singleList;
                                readingList.Add(readingModel2);
                                break;
                            }
                        }
                    model.QuestionContent = Common.Plugin.JsonHelper.Serialize(readingList);
                    if (model.QuestionTypeId == 0)
                    {
                        var tempModel = questionTypeList.Where(qitem => qitem.Key == "reading-comprehensio")?.FirstOrDefault();
                        model.QuestionTypeId = tempModel?.QId ?? 0;
                        model.QuestionTypeKey = tempModel?.Key ?? "";
                    }
                    break;

                case "单选题(数字)":
                    AnalysisSingle(ChooseOptionCount, item, model, questionTypeList,isNumChoose:true);
                    break;
            }
            model.QuestionContentObj = questionModule.ParsingQuestionModule(model.QuestionTypeKey, model.QuestionContent);
            return model;
        }

        /// <summary>
        /// 解析单选题
        /// </summary>
        /// <param name="ChooseOptionCount"></param>
        /// <param name="item"></param>
        /// <param name="model"></param>
        /// <param name="questionTypeList"></param>
        ///  <param name="isNumChoose">是否数字选择题</param>
        private void AnalysisSingle(int ChooseOptionCount, ImportModel item, RB_Question_ViewModel model, List<RB_Question_Type_ViewModel> questionTypeList,bool isNumChoose=false)
        {
            if (ChooseOptionCount > 0)
            {
                List<optionItem> singleList = new List<optionItem>();
                for (var i = 0; i < ChooseOptionCount; i++)
                {
                    var singleModel = new optionItem()
                    {
                        Name = Common.ConvertHelper.GetEnChar(i),
                        Content = "",
                        IsAnswer = item.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i))
                    };
                    if (isNumChoose)
                    {
                        singleModel.Name = (i + 1).ToString();
                        singleModel.IsAnswer = item.QuestionAnswer.Contains((i + 1).ToString());
                    }
                    if (i == 0)
                    {
                        singleModel.Content = item.OptionA;
                    }
                    if (i == 1)
                    {
                        singleModel.Content = item.OptionB;
                    }
                    if (i == 2)
                    {
                        singleModel.Content = item.OptionC;
                    }
                    if (i == 3)
                    {
                        singleModel.Content = item.OptionD;
                    }
                    if (i == 4)
                    {
                        singleModel.Content = item.OptionE;
                    }
                    if (i == 5)
                    {
                        singleModel.Content = item.OptionF;
                    }
                    if (i == 6)
                    {
                        singleModel.Content = item.OptionG;
                    }
                    if (i == 7)
                    {
                        singleModel.Content = item.OptionH;
                    }
                    if (singleModel.IsAnswer)
                    {
                        model.Answer = singleModel.Name;
                    }
                    singleList.Add(singleModel);
                }
                model.QuestionContent = Common.Plugin.JsonHelper.Serialize(singleList);
            }
            if (model.QuestionTypeId == 0)
            {
                string key = isNumChoose ? "single-number" : "single";
                var tempModel = questionTypeList.Where(qitem => qitem.Key == key)?.FirstOrDefault();
                model.QuestionTypeId = tempModel?.QId ?? 0;
                model.QuestionTypeKey = tempModel?.Key ?? "";
            }
        }

        /// <summary>
        /// 解析多选题
        /// </summary>
        /// <param name="ChooseOptionCount"></param>
        /// <param name="item"></param>
        /// <param name="model"></param>
        /// <param name="questionTypeList"></param>
        private void AnalysisMultiple(int ChooseOptionCount, ImportModel item, RB_Question_ViewModel model, List<RB_Question_Type_ViewModel> questionTypeList)
        {
            if (ChooseOptionCount > 0)
            {
                List<optionItem> multipleList = new List<optionItem>();
                string answer = "";
                for (var i = 0; i < ChooseOptionCount; i++)
                {
                    var singleModel = new optionItem()
                    {
                        Name = Common.ConvertHelper.GetEnChar(i),
                        Content = "",
                        IsAnswer = item.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i))
                    };
                    if (i == 0)
                    {
                        singleModel.Content = item.OptionA;
                    }
                    if (i == 1)
                    {
                        singleModel.Content = item.OptionB;
                    }
                    if (i == 2)
                    {
                        singleModel.Content = item.OptionC;
                    }
                    if (i == 3)
                    {
                        singleModel.Content = item.OptionD;
                    }
                    if (i == 4)
                    {
                        singleModel.Content = item.OptionE;
                    }
                    if (i == 5)
                    {
                        singleModel.Content = item.OptionF;
                    }
                    if (i == 6)
                    {
                        singleModel.Content = item.OptionG;
                    }
                    if (i == 7)
                    {
                        singleModel.Content = item.OptionH;
                    }
                    if (singleModel.IsAnswer)
                    {
                        answer += "," + singleModel.Name;
                    }
                    multipleList.Add(singleModel);
                }
                if (!string.IsNullOrEmpty(answer))
                {
                    answer = answer[1..];
                }
                model.Answer = answer;
                model.QuestionContent = Common.Plugin.JsonHelper.Serialize(multipleList);
            }
            if (model.QuestionTypeId == 0)
            {
                var tempModel = questionTypeList.Where(qitem => qitem.Key == "multiple")?.FirstOrDefault();
                model.QuestionTypeId = tempModel?.QId ?? 0;
                model.QuestionTypeKey = tempModel?.Key ?? "";
            }
        }

        #endregion
    }
}