using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Edu.Cache.User;
using Edu.Common.API;
using Edu.Common.Enum;
using Edu.Common.Enum.Exam;
using Edu.Common.Enum.Question;
using Edu.Common.Enum.Sale;
using Edu.Common.Plugin;
using Edu.Model.ViewModel.Exam;
using Edu.Model.ViewModel.Grade;
using Edu.Model.ViewModel.LearningGarden;
using Edu.Model.ViewModel.User;
using Edu.Module.Course;
using Edu.Module.Customer;
using Edu.Module.EduTask;
using Edu.Module.Exam;
using Edu.Module.Public;
using Edu.Module.User;
using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;

namespace Edu.WebApi.Controllers.Applet
{
    [Route("api/[controller]/[action]")]
    [ApiExceptionFilter]
    [ApiController]
    [EnableCors("AllowCors")]
    public class AppletIndexController : AppletBaseController
    {
        /// <summary>
        /// 学生管理处理类
        /// </summary>
        private readonly StudentModule studentModule = new StudentModule();
        /// <summary>
        /// 学生管理处理类
        /// </summary>
        private readonly EducationContractModule educationContractModule = new EducationContractModule();
        /// <summary>
        /// 班级管理处理类
        /// </summary>
        private readonly ClassModule classModule = new ClassModule();
        /// <summary>
        /// 课程处理类对象
        /// </summary>
        private readonly CourseModule courseModule = AOP.AOPHelper.CreateAOPObject<CourseModule>();
        /// <summary>
        /// 教务单据处理类对象
        /// </summary>
        private readonly EducationReceiptModule educationReceiptModule = AOP.AOPHelper.CreateAOPObject<EducationReceiptModule>();
        /// <summary>
        /// 试卷处理类对象
        /// </summary>
        private readonly PaperModule paperModule = AOP.AOPHelper.CreateAOPObject<PaperModule>();
        /// <summary>
        /// 学习园地处理类对象
        /// </summary>
        private readonly LearningGardenModule learningGardenModule = AOP.AOPHelper.CreateAOPObject<LearningGardenModule>();

        /// <summary>
        /// 课程单词学习、测试处理类对象
        /// </summary>
        private readonly CourseExamModule  courseExamModule = new CourseExamModule();

        /// <summary>
        /// 订单仓处理类对象
        /// </summary>
        private readonly CustomerStudentModule customerStudentModule = new CustomerStudentModule();


        #region  小程序首页
        /// <summary>
        /// 小程序首页
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetIndexInfo()
        {
            var appletUserInfo = base.AppletUserInfo;
            //判断学员是否退学
            var studentList = studentModule.GetStudentInfo(appletUserInfo.AccountId, appletUserInfo.Group_Id);
            if (studentList == null || !studentList.Any())
            {
                return ApiResult.Failed(message: $"很抱歉，由于你已经退学/已毕业，无法继续使用本系统", new { Error = 3 });
            }

            RB_Student_ViewModel studentModel = new RB_Student_ViewModel();
            studentModel = studentList.Where(x => x.ClassStatus == 2).FirstOrDefault();
            if (studentModel == null || studentModel.StuId == 0)
            {
                studentModel = new RB_Student_ViewModel();
                studentModel = studentList.Where(x => x.ClassStatus == 1).FirstOrDefault();
                if (studentModel == null || studentModel.StuId == 0)
                {
                    studentModel = new RB_Student_ViewModel();
                    studentModel = studentList.Where(x => x.ClassStatus == 3).FirstOrDefault();
                }
            }

            //获取电子合同 GetStudentContractInfo
            var contractList = educationContractModule.GetStudentContractInfo(appletUserInfo.AccountId, appletUserInfo.Group_Id);
            var backClassList = educationContractModule.GetStudentBackClassInfo(appletUserInfo.AccountId, appletUserInfo.Group_Id);


            var classTimeList = classModule.GetClassTimeByClassId(studentModel.ClassId, appletUserInfo.Group_Id);
            var tempList = classTimeList.OrderBy(x => x.NewEndPlanDateTime).Where(x => x.ClassId == studentModel.ClassId && x.NewPlanDateTime.HasValue && System.DateTime.Now >= x.NewPlanDateTime.Value.AddMinutes(-10) && x.NewEndPlanDateTime.HasValue && System.DateTime.Now < x.NewEndPlanDateTime.Value.AddMinutes(30));
            if (tempList == null || !tempList.Any())
            {
                tempList = classTimeList.OrderBy(x => x.NewEndPlanDateTime).Where(x => x.ClassId == studentModel.ClassId && x.NewPlanDateTime.HasValue && System.DateTime.Now <= x.NewPlanDateTime.Value);
            }
            var classModel = tempList?.OrderBy(x => x.NewPlanDateTime).FirstOrDefault();
            if (classModel == null || classModel.ClassTimeId == 0)
            {
                classModel = new Model.ViewModel.Grade.RB_Class_Time_Extend();
            }
            #region 我的试卷
            List<RB_Examination_Publish_ViewModel> examinationPublishList = new List<RB_Examination_Publish_ViewModel>();
            if (studentModel != null && studentModel.GuestId > 0)
            {
                examinationPublishList = paperModule.GetGuestExaminationPublishPage(1, 5, out long rowsCount,
                    new RB_Examination_Publish_ViewModel { QAccountIds = appletUserInfo.Id.ToString(), Group_Id = studentModel.Group_Id });
                if (examinationPublishList == null)
                {
                    examinationPublishList = new List<Model.ViewModel.Exam.RB_Examination_Publish_ViewModel>();
                }
                else
                {
                    foreach (var item in examinationPublishList)
                    {
                        if (item.ExamStartTime > System.DateTime.Now)
                        {
                            item.ExamStatus = ExamTestStatusEnum.NotStarted;
                        }
                        else if (item.ExamStartTime < System.DateTime.Now && item.ExamEndTime > System.DateTime.Now)
                        {
                            if (item.ExamStatus != ExamTestStatusEnum.FinishTest && item.ExamStatus != ExamTestStatusEnum.FinishScoring)
                            {
                                item.ExamStatus = ExamTestStatusEnum.FinishStarted;
                            }
                        }
                        else if (item.ExamEndTime < System.DateTime.Now)
                        {
                            if (item.ExamStatus != ExamTestStatusEnum.FinishTest && item.ExamStatus != ExamTestStatusEnum.FinishScoring)
                            {
                                item.ExamStatus = ExamTestStatusEnum.MissedTest;
                            }
                        }
                        item.ExamStatusStr = item.ExamStatus.ToName();
                    }
                }
            }
            #endregion


            #region 获取最新一条上课反馈记录
 
            List<RB_Class_FeedBack_ViewModel> feedBackList = classModule.GetClassFeedBackPageListRepository(1, 1, out long count, new RB_Class_FeedBack_ViewModel { StuId = appletUserInfo.AccountId, Group_Id = appletUserInfo.Group_Id });
            if (feedBackList != null && feedBackList.Any())
            {
                feedBackList.ForEach(x => x.PhotoList = (!string.IsNullOrWhiteSpace(x.Photo) ? JsonHelper.DeserializeObject<List<string>>(x.Photo) : new List<string>()));
            }
            #endregion

            var result = new
            {
                studentModel.SName,//学区
                studentModel.CourseName,//课程
                studentModel.SurplusHours,//剩余时间
                studentModel.TeacherName,//老师
                studentModel.ClassId,
                studentModel.ClassName,
                studentModel.CourseId,
                studentModel.GuestId,
                FeedBackList = feedBackList,//上课反馈最新一条数据
                EnterPhone = Cache.User.UserReidsCache.GetUserLoginInfo(studentModel.EnterID).UserMobile,
                ContractNum = (((contractList != null && contractList.Any()) ? contractList.Count() : 0) + ((backClassList != null && backClassList.Any()) ? backClassList.Count() : 0)),//合同数
                ClassPlan = new //我的课表最新一个数据
                {
                    NewPlanDateTimeStr = (classModel.NewPlanDateTime.HasValue) ? classModel?.NewPlanDateTime.Value.ToString("yyyy-MM-dd") : "",
                    TimeStr = (classModel.NewPlanDateTime.HasValue) ? Common.ConvertHelper.GetTimeStr(classModel.NewPlanDateTime.Value) : "",
                    TimeStart = classModel.StartTime,
                    classModel.TeacherName,
                    TimeStatusStr = classModel.ClassStatus,
                    classModel.RoomName,
                    classModel.CourseName,
                    classModel.ClassName
                },
                paperList = examinationPublishList.Select(x => new
                {
                    x.Exam_Student_Id,
                    x.PaperId,
                    x.Id,
                    x.PaperName,
                    x.PicList,
                    x.GuestId,
                    ExamStartTime = x.ExamStartTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    x.ExamStatus,
                    x.ExamStatusStr
                })
            };

            return ApiResult.Success("", result);
        }

        /// <summary>
        /// 获取小程序首页信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetIndexInfo_V2() {
            var appletUserInfo = base.AppletUserInfo;
            //判断学员是否退学
            var studentList = studentModule.GetStudentInfo(appletUserInfo.AccountId, appletUserInfo.Group_Id);

            //获取正在学习的班级 /未开班/已结班
            RB_Student_ViewModel studentModel = new RB_Student_ViewModel();
            if (studentList.Any())
            {
                studentModel = studentList.Where(x => x.ClassStatus == 2).FirstOrDefault();
                if (studentModel == null || studentModel.StuId == 0)
                {
                    studentModel = new RB_Student_ViewModel();
                    studentModel = studentList.Where(x => x.ClassStatus == 1).FirstOrDefault();
                    if (studentModel == null || studentModel.StuId == 0)
                    {
                        studentModel = new RB_Student_ViewModel();
                        studentModel = studentList.Where(x => x.ClassStatus == 3).FirstOrDefault();
                    }
                }
            }

            //查询下一节课(要查询正在学习中)
            var ClassNext = new object();
            if (studentModel.ClassId > 0 && studentModel.ClassStatus != 3) {
                var classTimeList = classModule.GetClassTimeByClassId(studentModel.ClassId, appletUserInfo.Group_Id);
                int ClassPlanState = 1;//上课中
                var tempList = classTimeList.OrderBy(x => x.NewEndPlanDateTime).Where(x => x.ClassId == studentModel.ClassId && x.NewPlanDateTime.HasValue && System.DateTime.Now >= x.NewPlanDateTime.Value && x.NewEndPlanDateTime.HasValue && System.DateTime.Now < x.NewEndPlanDateTime.Value);
                if (tempList == null || !tempList.Any())
                {
                    tempList = classTimeList.OrderBy(x => x.NewEndPlanDateTime).Where(x => x.ClassId == studentModel.ClassId && x.NewPlanDateTime.HasValue && System.DateTime.Now <= x.NewPlanDateTime.Value);
                    ClassPlanState = 2;//待上课
                }
                var classModel = tempList?.OrderBy(x => x.NewPlanDateTime).FirstOrDefault();
                if (classModel == null || classModel.ClassTimeId == 0)
                {
                    classModel = new Model.ViewModel.Grade.RB_Class_Time_Extend();
                    ClassPlanState = 3;//暂无
                }
                ClassNext = new //我的课表最新一个数据
                {
                    ClassPlanState,// 1上课中  2下一课  3暂无
                    DateStr = (classModel.NewPlanDateTime.HasValue) ? classModel?.NewPlanDateTime.Value.ToString("yyyy-MM-dd") : "",
                    DateStart = classModel.StartTime,
                    TimeStr = (classModel.NewPlanDateTime.HasValue) ? Common.ConvertHelper.GetTimeStr(classModel.NewPlanDateTime.Value) : "",
                    classModel.TeacherName,
                    classModel.RoomName,
                    classModel.CourseName,
                    classModel.ClassName
                };
            }
            else {
                ClassNext = new
                {
                    ClassPlanState = 3//暂无下一节课
                };
            }

            //查询学习园地
            var LearningGardenList = new List<object>();
            var enumlist = EnumHelper.EnumToList(typeof(Common.Enum.Course.LearningGardenTypeEnum));
            foreach (var item in enumlist) {
                var query = new RB_LearningGarden_ViewModel()
                {
                    Group_Id = base.AppletUserInfo.Group_Id,
                    GardenType = (Common.Enum.Course.LearningGardenTypeEnum)item.Id,
                    Status = DateStateEnum.Normal
                };
                var list = learningGardenModule.GetLearningGardenPageModule(1, 3, out long rowsCount, query);
                List<object> resultList = new List<object>();
                foreach (var qitem in list)
                {
                    string CreateByName = "甲鹤教育";
                    if (qitem.CreateBy > 0)
                    {
                        CreateByName = UserReidsCache.GetUserLoginInfo(qitem.CreateBy)?.AccountName ?? "";
                    }
                    resultList.Add(new
                    {
                        qitem.Id,
                        qitem.Title,
                        qitem.Content,
                        qitem.Img,                        
                        qitem.Digest,
                        qitem.LinkUrl,
                        CreateByName,
                        qitem.TypeId,
                        CreateTime = StringHelper.DateFormatToString(qitem.CreateDate)
                    });
                }
                LearningGardenList.Add(new
                {
                    item.Id,
                    item.Name,
                    List = resultList
                });
            }

            //查询单词
            var Words = new object();
            if (studentModel.ClassId > 0)
            {
                Words = classModule.GetIndexWords(studentModel.ClassId, studentModel.CourseId, studentModel.GuestId, studentModel.ClassScrollType, studentModel.StuId, appletUserInfo.Group_Id);
            }
            else 
            {
                Words = new
                {
                    NextWord = 0,
                    ReviewWord = 0,
                    NextCourseNo=0,
                    ReviewCourseNo=0,
                    CourseId=0,
                    ClassId=0,
                };
            }

            return ApiResult.Success("", new {
                studentModel.GuestId,
                studentModel.SName,//学区
                studentModel.SurplusHours,//剩余课时
                studentModel.TeacherName,//老师
                studentModel.ClassId,
                studentModel.ClassName,//班级
                studentModel.CourseId,
                studentModel.CourseName,//课程
                studentModel.ClassScrollType,
                ClassNext,
                LearningGardenList,
                Words
            });

        }

        /// <summary>
        /// 获取学生学习的课程
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudyCourse() {
            var appletUserInfo = base.AppletUserInfo;
            //判断学员是否退学
            var studentList = studentModule.GetStudentInfo(appletUserInfo.AccountId, appletUserInfo.Group_Id);
            if (studentList == null || !studentList.Any())
            {
                return ApiResult.Failed(message: $"很抱歉，由于你已经退学，无法继续使用本系统", new { Error = 3 });
            }

            RB_Student_ViewModel studentModel = new RB_Student_ViewModel();
            studentModel = studentList.Where(x => x.ClassStatus == 2).FirstOrDefault();
            if (studentModel == null || studentModel.StuId == 0)
            {
                studentModel = new RB_Student_ViewModel();
                studentModel = studentList.Where(x => x.ClassStatus == 1).FirstOrDefault();
                if (studentModel == null || studentModel.StuId == 0)
                {
                    studentModel = new RB_Student_ViewModel();
                    studentModel = studentList.Where(x => x.ClassStatus == 3).FirstOrDefault();
                }
            }

            var result = new
            {
                studentModel.GuestId,
                studentModel.SName,//学区
                studentModel.SurplusHours,//剩余时间
                studentModel.TeacherName,//老师
                studentModel.ClassId,
                studentModel.ClassName,
                studentModel.CourseId,
                studentModel.CourseName,//课程
            };
            return ApiResult.Success("", result);
        }
        #endregion

        #region 我的学习

        /// <summary>
        /// 获取我的学习课程列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetMyStudyCourseList() {
            var appletUserInfo = base.AppletUserInfo;
            //获取学生所有的课程
            var studentList = studentModule.GetStudentInfo(appletUserInfo.AccountId, appletUserInfo.Group_Id);
            studentList = studentList.OrderByDescending(x => x.ClassStatus).ToList();

            return ApiResult.Success("", studentList.Select(x => new
            {
                x.StuId,
                x.Account_Id,
                x.GuestId,
                x.B2BIcon,
                x.B2BBackground,
                x.ClassId,
                x.ClassName,
                x.ClassStatus,
                x.CourseId,
                x.CourseName,
                x.TotalHours,
                x.CompleteHours,
                SurplusHours = x.TotalHours - x.CompleteHours,
                x.ClassScrollType
            }));
        }

        /// <summary>
        /// 获取学习课程回顾
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetMyStudyCourseInfo() 
        {
            var appletUserInfo = base.AppletUserInfo;
            JObject parms = JObject.Parse(base.RequestParm.Msg.ToString());
            int ClassId = parms.GetInt("ClassId", 0);//班级ID
            int CourseId = parms.GetInt("CourseId", 0);//课程ID
            int GuestId = parms.GetInt("GuestId", 0);//订单GuestId
            int ClassScrollType = parms.GetInt("ClassScrollType", 0);//学习类型  1跟班  2约课
            int StuId = parms.GetInt("StuId", 0);//学生ID
            if (ClassId <= 0) 
            {
                return ApiResult.ParamIsNull("请传递班级ID");
            }
            if (ClassScrollType == 2 )
            {
                StuId = appletUserInfo.AccountId;
            }
            //获取课程回顾
            int Day = 7;//默认最近7次上课
            var Review = classModule.GetStudyCourseReview(ClassId, ClassScrollType, StuId, CourseId, Day, appletUserInfo.Group_Id);

            //获取考试试卷
            List<RB_Examination_Publish_ViewModel> examinationPublishList = new List<RB_Examination_Publish_ViewModel>();
            if (GuestId > 0)
            {
                examinationPublishList = paperModule.GetGuestExaminationPublishPage_V2(1, 5, out long rowsCount, new RB_Examination_Publish_ViewModel { GuestId = GuestId, Group_Id = appletUserInfo.Group_Id });
                if (examinationPublishList == null)
                {
                    examinationPublishList = new List<Model.ViewModel.Exam.RB_Examination_Publish_ViewModel>();
                }
                else
                {
                    foreach (var item in examinationPublishList)
                    {
                        if (item.ExamStartTime > System.DateTime.Now)
                        {
                            item.ExamStatus = ExamTestStatusEnum.NotStarted;
                        }
                        else if (item.ExamStartTime < System.DateTime.Now && item.ExamEndTime > System.DateTime.Now)
                        {
                            if (item.ExamStatus != ExamTestStatusEnum.FinishTest && item.ExamStatus != ExamTestStatusEnum.FinishScoring)
                            {
                                item.ExamStatus = ExamTestStatusEnum.FinishStarted;
                            }
                        }
                        else if (item.ExamEndTime < System.DateTime.Now)
                        {
                            if (item.ExamStatus != ExamTestStatusEnum.FinishTest && item.ExamStatus != ExamTestStatusEnum.FinishScoring)
                            {
                                item.ExamStatus = ExamTestStatusEnum.MissedTest;
                            }
                        }
                        item.ExamStatusStr = item.ExamStatus.ToName();
                    }
                }
            }

            //获取单词积分
            //查询单词
            var Words = new object();
            if (ClassId > 0 && CourseId > 0)
            {
                Words = classModule.GetIndexWords(ClassId, CourseId, GuestId, ClassScrollType, StuId, appletUserInfo.Group_Id);
            }
            else
            {
                Words = new
                {
                    NextWord = 0,
                    NextCourseNo=0,
                    ReviewWord = 0,
                    ReviewCourseNo=0,
                    CourseId,
                    ClassId,
                };
            }

            return ApiResult.Success("", new
            {
                Review,
                ExamList = examinationPublishList.Select(x => new
                {
                    x.Exam_Student_Id,
                    x.PaperId,
                    x.Id,
                    x.PaperName,
                    x.PublishPic,
                    x.PicList,
                    ExamStartTime = Common.ConvertHelper.FormatTime(x.ExamStartTime),
                    ExamEndTime = Common.ConvertHelper.FormatTime(x.ExamEndTime),
                    x.ExamStatus,
                    ExamStatusStr = x.ExamStatus.ToName(),
                    x.MyRank,
                    x.TotalScore,
                    x.ExamSecondTime,
                    x.MaxScore
                }),
                Words
            });
        }

        /// <summary>
        /// 获取学习课程章节列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetMyStudyCourseChapterList()
        {
            var appletUserInfo = base.AppletUserInfo;
            JObject parms = JObject.Parse(base.RequestParm.Msg.ToString());
            int ClassId = parms.GetInt("ClassId", 0);//班级ID
            int CourseId = parms.GetInt("CourseId", 0);//课程ID
            if (ClassId <= 0)
            {
                return ApiResult.ParamIsNull("请传递班级ID");
            }
            if (CourseId <= 0) 
            {
                return ApiResult.ParamIsNull("请传递课程ID");
            }

            //先获取计划列表
            var planList = classModule.GetMyStudyCourseList(ClassId, appletUserInfo.Group_Id);
            //查询章节列表 + 完成度 + 单词测试得分
            var MaxChapterNo = planList.Max(x => x.LessonPlanNum);
            //查询所有的章节
            var chapterTreeList = courseModule.GetChapterTreeListModule_V2(new Model.ViewModel.Course.RB_Course_Chapter_ViewModel() { Group_Id = appletUserInfo.Group_Id, CourseId = CourseId });
            var ctList = chapterTreeList.Where(x => Convert.ToInt32(x.ChapterNo) <= MaxChapterNo).OrderByDescending(qitem=> Convert.ToInt32(qitem.ChapterNo)).ToList();
            //章节单词得分
            var prepWordsList = courseExamModule.GetStuWordsPrepListModule(new RB_StuWords_Prep_Extend()
            {
                CourseId = CourseId,
                Group_Id = appletUserInfo.Group_Id,
                Stu_Account_Id = appletUserInfo.Id
            });
            //单词测试列表
            var wordsExamList = courseExamModule.GetStuWordsExamListModule(new RB_StuWords_Exam_Extend()
            {
                ClassId = ClassId,
                CourseId=CourseId,
                Stu_Account_Id= appletUserInfo.Id
            });
            //组装数据
            var RList = new List<object>();
            foreach (var item in ctList)
            {
                //判断是否已经学习
                var planModel = planList.Where(x => item.ChapterNo == x.LessonPlanNum.ToString()).FirstOrDefault();
                var tempPrepWords = prepWordsList?.Where(qitem => qitem.ChapterId.ToString() == item.ChapterNo)?.FirstOrDefault();
                decimal StudyProgress = 0;
                if (tempPrepWords != null && tempPrepWords.TotalNum > 0)
                {
                    StudyProgress = (int)(Convert.ToDecimal(tempPrepWords.StudyNum) / Convert.ToDecimal(tempPrepWords.TotalNum) * 100);
                }
                int Num = 1;
                
                decimal Score = 0;//单词测试得分
                if (wordsExamList != null && wordsExamList.Count > 0)
                {
                    Score = wordsExamList?.Where(qitem => qitem.ChapterId.ToString() == item.ChapterNo)?.OrderByDescending(qitem => qitem.CreateTime)?.FirstOrDefault()?.Score ?? 0;
                }

                RList.Add(new
                {
                    planModel?.ClassPlanId,
                    ClassDate = planModel?.ClassDate.ToString("yyyy-MM-dd"),
                    CourseReview = planModel?.PlanTimeList.OrderBy(x => x.StartTime).Select(x => new
                    {
                        x.ClassTimeId,
                        Num = Num++,
                        x.SuiPai,
                        x.VideoUrl
                    }),
                    ChapterTree = item,
                    Score,
                    StudyProgress,
                    ClassId,
                    CourseId,
                    item.ChapterNo,
                    NextChapterNo = chapterTreeList.Where(x => Convert.ToInt32(x.ChapterNo) > Convert.ToInt32(item.ChapterNo)).OrderBy(x => Convert.ToInt32(x.ChapterNo)).FirstOrDefault()?.ChapterNo ?? ""
                });
            }
            return ApiResult.Success("", RList);
        }
        #endregion

        #region 我的课表
        /// <summary>
        /// 老师上课计划统计
        /// </summary>
        /// <returns></returns>
        public ApiResult GetStundentPlanStatistical()
        {
            var startDate = base.ParmJObj.GetStringValue("StartTime");
            var endDate = base.ParmJObj.GetStringValue("EndTime");
            DateTime now = DateTime.Now;

            //获取当前月的第一天
            DateTime d1 = new DateTime(now.Year, now.Month, 1);
            //当月最后一天
            DateTime d2 = d1.AddMonths(1).AddDays(-1);
            if (string.IsNullOrEmpty(startDate))
            {
                startDate = Common.ConvertHelper.FormatDate(d1);
            }
            if (string.IsNullOrEmpty(endDate))
            {
                endDate = Common.ConvertHelper.FormatDate(d2);
            }
            else
            {
                //if (Convert.ToDateTime(endDate) > Convert.ToDateTime(Common.ConvertHelper.FormatDate(DateTime.Now)))
                //{
                //    endDate = Common.ConvertHelper.FormatDate(DateTime.Now);
                //}
            }
            RB_Class_ViewModel query = new RB_Class_ViewModel()
            {
                StartTime = startDate,
                EndTime = endDate,
                Group_Id = base.AppletUserInfo.Group_Id,
                School_Id = -1,
                ClassId = base.ParmJObj.GetInt("ClassId"),
                CouseId = base.ParmJObj.GetInt("CourseId"),
                ClassScrollType = base.ParmJObj.GetInt("ClassScrollType")
            };
            List<RB_Class_Plan_ViewModel> list = new List<RB_Class_Plan_ViewModel>();
            if (query.ClassScrollType == 2)
            {
                query.ManagerId = base.AppletUserInfo.AccountId;//暂存学生StuId
                //约课
                list = classModule.GetStundentPlanModuleForYK(query);
            }
            else
            {
                list = classModule.GetStundentPlanModule(query);
            }

            List<Model.ViewModel.Course.ChapterTree_ViewModel> chapterTreeList = new List<Model.ViewModel.Course.ChapterTree_ViewModel>();
            if (list != null && list.Any())
            {
                string rannkIds = string.Join(",", list.Select(x => x.Ranks));//查询章节信息
                chapterTreeList = new CourseModule().GetMatchChapterRepository((list.FirstOrDefault()?.CourseId ?? 0), rannkIds);
            }
            DateTime startTime = Convert.ToDateTime(query.StartTime);
            DateTime endTime = Convert.ToDateTime(query.EndTime);

            TimeSpan sp = endTime.Subtract(startTime);
            List<object> planListResult = new List<object>();
            for (int i = 0; i <= sp.Days; i++)
            {
                var plan = list.Where(x => x.ClassDate.ToString("yyyy-MM-dd") == startTime.AddDays(i).ToString("yyyy-MM-dd"));
                string DayTime = string.Empty;

                foreach (var itemGroup in plan)
                {
                    itemGroup.Chapter = chapterTreeList.Where(x => x.ChapterNo == itemGroup.Ranks.ToString() || x.ChapterNo.Contains(itemGroup.Ranks.ToString() + ".")).ToList();
                    if (itemGroup.PlanTimeList != null && itemGroup.PlanTimeList.Any())
                    {
                        itemGroup.PlanTimeList.ForEach(x => x.NewPlanDateTime = itemGroup.ClassDate.ToString("yyyy-MM-dd") + " " + x.StartTime);
                        DayTime = itemGroup.PlanTimeList.Min(x => Convert.ToDateTime(x.NewPlanDateTime)).ToString("HH:ss");
                        itemGroup.PlanTimeList.ForEach(x => x.NewPlanDateTime = itemGroup.ClassDate.ToString("yyyy-MM-dd") + " " + x.EndTime);
                        //  DayTime = DayTime + "~" + itemGroup.PlanTimeList.Max(x => Convert.ToDateTime(x.NewPlanDateTime)).ToString("HH:ss");
                    }
                    if (query.ClassScrollType == 2)
                    {
                        planListResult.Add(new
                        {
                            itemGroup.Chapter,
                            DateYear = startTime.AddDays(i).ToString("yyyy"),
                            DateMonth = startTime.AddDays(i).ToString("MM"),
                            DateDay = startTime.AddDays(i).ToString("dd"),
                            WeekStr = StringHelper.GetJapanWeekChar(startTime.AddDays(i)),
                            ClassDateStr = startTime.AddDays(i).ToString("yyyy-MM-dd"),
                            ClassName = plan.Where(x => x.ClassId == itemGroup.ClassId).FirstOrDefault()?.ClassName ?? "",
                            itemGroup.ClassId,
                            itemGroup.CourseId,
                            PlanTimeList = itemGroup.PlanTimeList.Select(x => new
                            {
                                x.StartTime,
                                x.EndTime,
                                x.ClassPlanId,
                                x.ClassTimeId,
                                x.TimeHour,
                                TeacherName = itemGroup.TeacherName ?? "",
                                UserIcon = itemGroup.UserIcon ?? "",
                                x.IsCheck,
                                OrderGuestId = 0,
                                IsLeave = Convert.ToDateTime(x.NewPlanDateTime) > DateTime.Now ? 1 : 0
                            })
                        });
                    }
                    else
                    {
                        planListResult.Add(new
                        {
                            itemGroup.Chapter,
                            DateYear = startTime.AddDays(i).ToString("yyyy"),
                            DateMonth = startTime.AddDays(i).ToString("MM"),
                            DateDay = startTime.AddDays(i).ToString("dd"),
                            WeekStr = StringHelper.GetJapanWeekChar(startTime.AddDays(i)),
                            ClassDateStr = startTime.AddDays(i).ToString("yyyy-MM-dd"),
                            ClassName = plan.Where(x => x.ClassId == itemGroup.ClassId).FirstOrDefault()?.ClassName ?? "",
                            itemGroup.ClassId,
                            itemGroup.CourseId,
                            PlanTimeList = itemGroup.PlanTimeList.Select(x => new
                            {
                                x.StartTime,
                                x.EndTime,
                                x.ClassPlanId,
                                x.ClassTimeId,
                                x.TimeHour,
                                TeacherName = itemGroup.TeacherName ?? "",
                                UserIcon = itemGroup.UserIcon ?? "",
                                x.GuestList.Where(x => x.StudentId == base.AppletUserInfo.AccountId).FirstOrDefault()?.IsCheck,
                                OrderGuestId = x.GuestList.Where(x => x.StudentId == base.AppletUserInfo.AccountId).FirstOrDefault()?.Id,
                                IsLeave = Convert.ToDateTime(x.NewPlanDateTime) > DateTime.Now ? 1 : 0
                            })
                        });
                    }
                }
            }
            return ApiResult.Success(data: planListResult);
        }

        #endregion


        #region 我的课程
        /// <summary>
        /// 获取章节树形列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetChapterTree()
        {
            var query = new Model.ViewModel.Course.RB_Course_Chapter_ViewModel()
            {
                CourseId = base.ParmJObj.GetInt("CourseId"),
            };
            if (query.CourseId <= 0)
            {
                return ApiResult.ParamIsNull(message: "请传递课程编号!");
            }
            query.Group_Id = base.AppletUserInfo.Group_Id;
            var list = courseModule.GetChapterTreeListModule(query);
            return ApiResult.Success(data: list);
        }
        #endregion


        #region 我的合同
        public ApiResult GetContractList()
        {
            //获取电子合同 GetStudentContractInfo
            var contractList = educationContractModule.GetStudentContractInfo(base.AppletUserInfo.AccountId, base.AppletUserInfo.Group_Id);
            var backClassList = educationContractModule.GetStudentBackClassInfo(base.AppletUserInfo.AccountId, base.AppletUserInfo.Group_Id);

            List<object> result = new List<object>();
            if (contractList != null && contractList.Any())
            {
                foreach (var item in contractList)
                {
                    var nowContractList = new
                    {
                        item.ContractNo,
                        item.IsCompanySeal,
                        Type = 1,
                        item.Id
                    };
                    result.Add(nowContractList);
                }
            }
            if (backClassList != null && backClassList.Any())
            {
                foreach (var item in backClassList)
                {
                    var nowContractList = new
                    {
                        Type = 2,
                        ContractNo = item.ProtocolNum,
                        item.IsCompanySeal,
                        Id = item.BackClassProtocolId
                    };
                    result.Add(nowContractList);
                }
            }
            return ApiResult.Success("", result);
        }
        #endregion

        #region 我的进度
        /// <summary>
        /// 老师上课计划统计
        /// </summary>
        /// <returns></returns>
        public ApiResult GetStundentScheduleList()
        {

            RB_Class_ViewModel query = new RB_Class_ViewModel()
            {

                EndTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                Group_Id = base.AppletUserInfo.Group_Id,
                School_Id = -1,
                ClassId = base.ParmJObj.GetInt("ClassId"),
            };
            var list = classModule.GetStundentScheduleList(query);

            List<Model.ViewModel.Course.ChapterTree_ViewModel> chapterTreeList = new List<Model.ViewModel.Course.ChapterTree_ViewModel>();
            if (list != null && list.Any())
            {
                string rannkIds = string.Join(",", list.Select(x => x.Ranks));//查询章节信息
                chapterTreeList = new CourseModule().GetMatchChapterRepository((list.FirstOrDefault()?.CourseId ?? 0), rannkIds);
            }
            List<object> result = new List<object>();
            foreach (var item in chapterTreeList)
            {
                //判断是否已经学习
                var planModel = list.Where(x => item.ChapterNo == x.Ranks.ToString() || item.ChapterNo.Contains(x.Ranks.ToString() + ".")).FirstOrDefault();
                int IsStudy = 0;//0-未学习，1-已学习
                if (planModel != null && planModel.ClassPlanId > 0)
                {
                    if (planModel.ClassDate < (Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd 00:00:00"))))
                    {
                        IsStudy = 1;
                    }
                }
                result.Add(new
                {
                    IsStudy,
                    ChapterTreeInfo = item,

                });
            }
            return ApiResult.Success(data: result);
        }
        #endregion

        #region 我的剩余课时
        /// <summary>
        /// 老师上课计划统计
        /// </summary>
        /// <returns></returns>
        public ApiResult GetStundentSurplus()
        {

            RB_Class_ViewModel query = new RB_Class_ViewModel()
            {
                StartTime = System.DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00"),
                Group_Id = base.AppletUserInfo.Group_Id,
                School_Id = -1,
                ClassId = base.ParmJObj.GetInt("ClassId"),
            };
            var list = classModule.GetStundentPlanModule(query);
            List<object> planListResult = new List<object>();

            foreach (var itemGroup in list)
            {
                if (itemGroup.PlanTimeList != null && itemGroup.PlanTimeList.Any())
                {
                    itemGroup.PlanTimeList.ForEach(x => x.NewPlanDateTime = itemGroup.ClassDate.ToString("yyyy-MM-dd") + " " + x.StartTime);

                    itemGroup.PlanTimeList.ForEach(x => x.NewPlanDateTime = itemGroup.ClassDate.ToString("yyyy-MM-dd") + " " + x.EndTime);
                }
                planListResult.Add(new
                {
                    WeekStr = StringHelper.GetJapanWeekChar(itemGroup.ClassDate),
                    ClassDateStr = itemGroup.ClassDate.ToString("yyyy-MM-dd"),
                    TeacherName = itemGroup.TeacherName ?? "",
                    UserIcon = itemGroup.UserIcon ?? "",
                    RoomName = itemGroup.RoomName ?? "",
                    PlanTimeList = itemGroup.PlanTimeList.Select(x => new
                    {
                        x.StartTime,
                        x.EndTime,
                        x.GuestList.Where(x => x.StudentId == base.AppletUserInfo.AccountId).FirstOrDefault()?.IsCheck,
                        IsLeave = Convert.ToDateTime(x.NewPlanDateTime) > DateTime.Now ? 1 : 0
                    })
                });
            }

            return ApiResult.Success(data: planListResult);
        }
        #endregion


        #region 我的请假列表
        /// <summary>
        /// 获取请假单据分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetEducationReceiptPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new Model.ViewModel.EduTask.EducationReceiptQuery()
            {
                Group_Id = base.AppletUserInfo.Group_Id,
                StartTime = base.ParmJObj.GetStringValue("StartTime"),
                EndTime = base.ParmJObj.GetStringValue("EndTime"),
                Conditon = Common.Enum.Course.EduReceiptConditionEnum.Launch,
                ReceiptType = 7,
                Title = base.ParmJObj.GetStringValue("Title")
            };
            if (!string.IsNullOrEmpty(base.ParmJObj.GetStringValue("VerifyStatus")))
            {
                query.VerifyStatus = base.ParmJObj.GetInt("VerifyStatus", -1);
            }
            var id = base.ParmJObj.GetInt("Id");
            if (id > 0)
            {
                query.QIds = id.ToString();
            }
            query.CreateBy = base.AppletUserInfo.Id;
            var list = educationReceiptModule.GetEducationReceiptPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            pageModel.PageData = list;
            pageModel.Count = rowsCount;
            return ApiResult.Success(data: pageModel);
        }


        /// <summary>
        /// 获取教务单据类型
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetEduReceiptInfo()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var Info = educationReceiptModule.GetEducationReceiptInfoModule(Id);
            return ApiResult.Success(data: Info);
        }



        /// <summary>
        /// 教务单据作废
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult InvalidReceipt()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var flag = educationReceiptModule.InvalidReceiptModule(Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }
        #endregion


        #region 我的考卷列表
        /// <summary>
        /// 获取考卷列表分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetGuestExaminationPublishPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new Model.ViewModel.Exam.RB_Examination_Publish_ViewModel()
            {
                Group_Id = base.AppletUserInfo.Group_Id,
                ExamStatus = (ExamTestStatusEnum)base.ParmJObj.GetInt("ExamStatus", 0),
                GuestId = base.ParmJObj.GetInt("GuestId", 0),
            };
            var list = paperModule.GetGuestExaminationPublishPage(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            foreach (var item in list)
            {
                if (item.ExamStartTime > System.DateTime.Now)
                {
                    item.ExamStatus = ExamTestStatusEnum.NotStarted;
                }
                else if (item.ExamStartTime < System.DateTime.Now && item.ExamEndTime > System.DateTime.Now)
                {
                    if (item.ExamStatus != ExamTestStatusEnum.FinishTest && item.ExamStatus != ExamTestStatusEnum.FinishScoring)
                    {
                        item.ExamStatus = ExamTestStatusEnum.FinishStarted;
                    }
                }
                else if (item.ExamEndTime < System.DateTime.Now)
                {
                    if (item.ExamStatus != ExamTestStatusEnum.FinishTest && item.ExamStatus != ExamTestStatusEnum.FinishScoring)
                    {
                        item.ExamStatus = ExamTestStatusEnum.MissedTest;
                    }
                }
            }
            pageModel.PageData = list.Select(x => new
            {
                x.Exam_Student_Id,
                x.PaperId,
                x.Id,
                x.PaperName,
                x.PublishPic,
                x.PicList,
                ExamStartTime = Common.ConvertHelper.FormatTime(x.ExamStartTime),
                ExamEndTime = Common.ConvertHelper.FormatTime(x.ExamEndTime),
                x.ExamTimes,
                x.ExamStatus,
                ExamStatusStr = x.ExamStatus.ToName()
            });
            pageModel.Count = rowsCount;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取考卷列表分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetGuestPublishPage_V2()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new Model.ViewModel.Exam.RB_Examination_Publish_ViewModel()
            {
                Group_Id = base.AppletUserInfo.Group_Id,
                ExamStatus = (ExamTestStatusEnum)base.ParmJObj.GetInt("ExamStatus", 0),
                GuestId = base.ParmJObj.GetInt("GuestId", 0),
            };
            var list = paperModule.GetGuestExaminationPublishPage_V2(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            foreach (var item in list)
            {
                if (item.ExamStartTime > System.DateTime.Now)
                {
                    item.ExamStatus = ExamTestStatusEnum.NotStarted;
                }
                else if (item.ExamStartTime < System.DateTime.Now && item.ExamEndTime > System.DateTime.Now)
                {
                    if (item.ExamStatus != ExamTestStatusEnum.FinishTest && item.ExamStatus != ExamTestStatusEnum.FinishScoring)
                    {
                        item.ExamStatus = ExamTestStatusEnum.FinishStarted;
                    }
                }
                else if (item.ExamEndTime < System.DateTime.Now)
                {
                    if (item.ExamStatus != ExamTestStatusEnum.FinishTest && item.ExamStatus != ExamTestStatusEnum.FinishScoring)
                    {
                        item.ExamStatus = ExamTestStatusEnum.MissedTest;
                    }
                }
            }
            pageModel.PageData = list.Select(x => new
            {
                x.Exam_Student_Id,
                x.PaperId,
                x.Id,
                x.PaperName,
                x.PublishPic,
                x.PicList,
                ExamStartTime = Common.ConvertHelper.FormatTime(x.ExamStartTime),
                ExamEndTime = Common.ConvertHelper.FormatTime(x.ExamEndTime),
                x.ExamStatus,
                ExamStatusStr = x.ExamStatus.ToName(),
                x.MyRank,
                x.TotalScore,
                x.ExamSecondTime,
                x.MaxScore
            });
            pageModel.Count = rowsCount;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 根据编号获取试卷信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetPaperDetails()
        {
            var PaperId = base.ParmJObj.GetInt("PaperId");
            var PublishId = base.ParmJObj.GetInt("PublishId");
            var GuestId = base.ParmJObj.GetInt("GuestId", 0);
            var isShowAnswer = base.ParmJObj.GetBoolValue("isShowAnswer");
            if (PublishId <= 0)
            {
                return ApiResult.ParamIsNull(message: "请传递考试编号!");
            }
            if (GuestId <= 0)
            {
                return ApiResult.ParamIsNull(message: "请传递学员编号!");
            }
            var data = paperModule.AppGetExamPaperInfoModule(PaperId, isShowAnswer: isShowAnswer, GuestId: GuestId, PublishId: PublishId);
            return ApiResult.Success(data: data);
        }

        /// <summary>
        /// 更新学员开始考试时间
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStuExamStartTime()
        {
            var PublishId = base.ParmJObj.GetInt("PublishId");
            var GuestId = base.ParmJObj.GetInt("GuestId", 0);
            var PaperId = base.ParmJObj.GetInt("PaperId");
            var Exam_Student_Id = base.ParmJObj.GetInt("Exam_Student_Id");
            bool flag = paperModule.SetStuExamStartTimeModule(PublishId, GuestId, PaperId);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 学生提交答卷
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult StuSubmitExamPaper()
        {
            var PublishId = base.ParmJObj.GetInt("PublishId");
            var GuestId = base.ParmJObj.GetInt("GuestId", 0);
            var PaperId = base.ParmJObj.GetInt("PaperId");
            var Exam_Student_Id = base.ParmJObj.GetInt("Exam_Student_Id");
            List<RB_Examination_Details_ViewModel> paperDetailsList = new List<RB_Examination_Details_ViewModel>();
            string groups = base.ParmJObj.GetStringValue("GroupList");
            if (!string.IsNullOrEmpty(groups))
            {
                JArray jarray = JArray.Parse(groups);
                if (jarray != null && jarray.Count > 0)
                {
                    foreach (var jItem in jarray)
                    {
                        JObject jobj = JObject.Parse(jItem.ToString());
                        string details = jobj.GetStringValue("DetailsList");
                        if (!string.IsNullOrEmpty(details))
                        {
                            JArray subArray = JArray.Parse(details);
                            int dSortNum = 0;
                            foreach (var sItem in subArray)
                            {
                                JObject sObj = JObject.Parse(sItem.ToString());
                                var detailModel = new RB_Examination_Details_ViewModel()
                                {
                                    Id = sObj.GetInt("PaperDetailsId"),
                                    PaperId = sObj.GetInt("PaperId"),
                                    BankId = sObj.GetInt("BankId"),
                                    QuestionId = sObj.GetInt("QuestionId"),
                                    Title = sObj.GetStringValue("Title"),
                                    QuestionContent = sObj.GetStringValue("QuestionContentObj"),
                                    DifficultyType = (DifficultyTypeEnum)sObj.GetInt("DifficultyType"),
                                    AnswerParse = sObj.GetStringValue("AnswerParse"),
                                    QuestionTypeId = sObj.GetInt("QuestionTypeId"),
                                    QuestionTypeKey = sObj.GetStringValue("QuestionTypeKey"),
                                    Knowledge = sObj.GetStringValue("Knowledge"),
                                    UpdateTime = DateTime.Now,
                                    IsUpdateJobExam = sObj.GetInt("IsUpdateJobExam"),
                                    Status = Common.Enum.DateStateEnum.Normal,
                                    SortNum = dSortNum,
                                    StundetAnswer = sObj.GetStringValue("StundetAnswer"),
                                    IsMutex = sObj.GetInt("IsMutex"),
                                    StundetDetailsId = sObj.GetInt("StundetDetailsId"),
                                    LevelType = (LevelTypeEnum)sObj.GetInt("LevelType"),
                                    Answer = sObj.GetStringValue("Answer"),
                                    StuPaperGroupId = jobj.GetInt("GId"),
                                    Score = sObj.GetDecimal("Score"),
                                };
                                paperDetailsList.Add(detailModel);
                            }
                        }
                    }
                }
            }
            int Group_Id = base.ParmJObj.GetInt("Group_Id");
            if (Group_Id <= 0)
            {
                Group_Id = base.AppletUserInfo.Group_Id;
            }
            var result = paperModule.SetStuExamPaperDetailsModule(PublishId, GuestId, PaperId, Group_Id, paperDetailsList, Exam_Student_Id);
            return result ? ApiResult.Success("提交试卷成功") : ApiResult.Failed("提交试卷失败");
        }

        #endregion


        #region 学习园地

        /// <summary>
        /// 获取学习园地分页
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GeLearningGardenPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_LearningGarden_ViewModel()
            {
                Title = base.ParmJObj.GetStringValue("Title"),
                Group_Id = base.ParmJObj.GetInt("Group_Id"),
                GardenType = (Common.Enum.Course.LearningGardenTypeEnum)base.ParmJObj.GetInt("GardenType")
            };
            query.Status = DateStateEnum.Normal;
            query.Group_Id = base.AppletUserInfo.Group_Id;
            var list = learningGardenModule.GetLearningGardenPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> resultList = new List<object>();
            foreach (var item in list)
            {
                string CreateByName = "甲鹤教育";
                if (item.CreateBy > 0)
                {
                    CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                }
                resultList.Add(new
                {
                    item.Id,
                    item.Title,
                    item.Content,
                    item.Img,
                    Ico = "",
                    item.Digest,
                    item.LinkUrl,
                    CreateByName,
                    item.TypeId,
                    CreateTime = Common.Plugin.StringHelper.DateFormatToString(item.CreateDate)
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = resultList;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取学习园地详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetLearningGarden()
        {
            var Id = base.ParmJObj.GetInt("Id", 0);
            var extModel = learningGardenModule.GetLearningGardenModule(Id);
            object obj = new object();
            if (extModel != null && extModel.Id > 0)
            {
                string CreateByName = "甲鹤教育";
                if (extModel.CreateBy > 0)
                {
                    CreateByName = UserReidsCache.GetUserLoginInfo(extModel.CreateBy)?.AccountName ?? "";
                }
                obj = new
                {
                    extModel.Id,
                    extModel.Title,
                    extModel.Img,
                    extModel.Content,
                    extModel.Digest,
                    extModel.LinkUrl,
                    CreateByName,
                    extModel.TypeId,
                    CreateTime = Common.Plugin.StringHelper.DateFormatToString(extModel.CreateDate),
                    Ico = UserReidsCache.GetUserLoginInfo(extModel.CreateBy)?.UserIcon ?? ""
                };
            }
            return ApiResult.Success(data: obj);
        }
        #endregion


        #region 上课反馈记录
        /// <summary>
        /// 获取学习园地分页
        /// </summary>
        /// <returns></returns>
        [HttpPost]

        public ApiResult GeClassFeedBackPage()
        {
            var appletUserInfo = base.AppletUserInfo;
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Class_FeedBack_ViewModel()
            {
                Group_Id = appletUserInfo.Group_Id,
                StuId = appletUserInfo.AccountId,
            };
            var list = classModule.GetClassFeedBackPageListRepository(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);

            if (list != null && list.Any())
            {
                list.ForEach(x => x.PhotoList = (!string.IsNullOrWhiteSpace(x.Photo) ? JsonHelper.DeserializeObject<List<string>>(x.Photo) : new List<string>()));
            }
            List<object> resultList = new List<object>();
            foreach (var item in list)
            {
                resultList.Add(new
                {
                    item.FeedBackId,
                    item.TeacherIcon,
                    item.TeacherName,
                    item.PhotoList,
                    item.Comment,
                    item.Score,
                    CreateTimeYear = item.CreateTime.ToString("yyyy"),
                    CreatetimeStr = item.CreateTime.ToString("MM-dd HH:mm:ss"),
                    item.CourseName,
                    item.ClassDateStr,
                    item.StartTime,
                    item.EndTime
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = resultList;
            return ApiResult.Success(data: pageModel);
        }
        #endregion

        #region 我的订单
        /// <summary>
        /// 学员订单分页列表
        /// </summary>
        /// <returns></returns>
        public ApiResult GetOrderPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_OrderGuest_ViewModel()
            {
                Account_Id = base.AppletUserInfo.Id,
                OrderType=(OrderTypeEnum)base.ParmJObj.GetInt("OrderType")
            };
            var data = customerStudentModule.GetStuOrderGuestPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                list.Add(new
                {
                    item.OrderId,
                    item.Student_Id,
                    item.ClassName,
                    item.ClassNo,
                    item.TotalHours,
                    item.CompleteHours,
                    item.GuestName,
                    item.CourseName,
                    item.OrderState,
                    OrderStateName=item.OrderState.ToName(),
                    item.ClassScrollType
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }
        #endregion

    }
}
