using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Edu.AOP;
using Edu.Cache.User;
using Edu.Cache.WeChat;
using Edu.Common.API;
using Edu.Common.Enum;
using Edu.Common.Enum.Course;
using Edu.Common.Enum.System;
using Edu.Common.Enum.User;
using Edu.Common.Plugin;
using Edu.Model.ViewModel.Customer;
using Edu.Model.ViewModel.Log;
using Edu.Model.ViewModel.User;
using Edu.Module.Course;
using Edu.Module.Customer;
using Edu.Module.Duty;
using Edu.Module.Log;
using Edu.Module.User;
using Edu.ThirdCore.TenCloud;
using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Edu.WebApi.Controllers.User
{
    [Route("api/[controller]/[action]")]
    [ApiExceptionFilter]
    [ApiController]
    [EnableCors("AllowCors")]
    public class UserController : BaseController
    {
        /// <summary>
        /// 助教处理类对象
        /// </summary>
        private readonly AssistModule assistModule = AOPHelper.CreateAOPObject<AssistModule>();

        /// <summary>
        /// 集团处理类对象
        /// </summary>
        private readonly GroupModule groupModule = AOPHelper.CreateAOPObject<GroupModule>();

        /// <summary>
        /// 学校处理类对象
        /// </summary>
        private readonly SchoolModule schoolModule = AOPHelper.CreateAOPObject<SchoolModule>();

        /// <summary>
        /// 学生处理类对象
        /// </summary>
        private readonly StudentModule studentModule = AOPHelper.CreateAOPObject<StudentModule>();

        /// <summary>
        /// 讲师处理类对象
        /// </summary>
        private readonly TeacherModule teacherModule = AOPHelper.CreateAOPObject<TeacherModule>();

        /// <summary>
        /// 系统管理人员处理类对象
        /// </summary>
        private readonly ManagerModule managerModule = AOPHelper.CreateAOPObject<ManagerModule>();

        /// <summary>
        /// 账户相关处理类对象
        /// </summary>
        private readonly AccountModule accountModule = AOPHelper.CreateAOPObject<AccountModule>();

        /// <summary>
        /// 岗位处理类对象
        /// </summary>
        private readonly PostModule postModule = AOPHelper.CreateAOPObject<PostModule>();

        /// <summary>
        /// 部门处理类对象
        /// </summary>
        private readonly DepartmentModule departmentModule = AOPHelper.CreateAOPObject<DepartmentModule>();

        /// <summary>
        /// 员工处理类对象
        /// </summary>
        private readonly EmployeeModule employeeModule = new EmployeeModule();
        /// <summary>
        /// 行政备注处理类对象
        /// </summary>
        private readonly AccountRemarkModule accountRemarkModule = new AccountRemarkModule();
        /// <summary>
        /// 助教处理类对象
        /// </summary>
        private readonly NoticeModule noticeModule = new NoticeModule();
        /// <summary>
        /// 用户修改日志
        /// </summary>
        private readonly UserChangeLogModule userChangeLogModule = new UserChangeLogModule();

        /// <summary>
        /// 班级处理类对象
        /// </summary>
        private readonly ClassModule classModule = new ClassModule();

        /// <summary>
        /// 值班计划处理类对象
        /// </summary>
        private readonly DutyPlanModule dutyPlanModule = AOP.AOPHelper.CreateAOPObject<DutyPlanModule>();

        #region 用户账户管理

        /// <summary>
        /// 重置用户密码信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult ResetUserPassword()
        {
            RB_Account_ViewModel viewModel = JsonConvert.DeserializeObject<RB_Account_ViewModel>(RequestParm.Msg.ToString());
            if (viewModel != null && viewModel.AccountType > 0 && viewModel.AccountId > 0)
            {
                if (int.TryParse(RequestParm.Uid, out int uid))
                {
                    viewModel.Group_Id = UserReidsCache.GetUserLoginInfo(uid).Group_Id;
                    var (reuslt, newPass) = accountModule.SetResetPassword(viewModel);
                    if (reuslt)
                    {
                        return ApiResult.Success($"密码重置成功，用户新密码为【{newPass}】,请复制保存");
                    }
                    else
                    {
                        return ApiResult.Failed(message: "密码重置失败");
                    }
                }
                else
                {
                    return ApiResult.Failed(message: "身份信息不合法，请尝试重新登录");
                }
            }
            else
            {
                return ApiResult.Failed(message: "参数不合法，请刷新页面重试");
            }
        }

        #endregion

        #region 集团管理

        /// <summary>
        /// 获取集团列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetGroupList()
        {
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Group_ViewModel>(RequestParm.Msg.ToString());
            var list = groupModule.GetGroupListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取集团分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetGroupPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Group_ViewModel>(RequestParm.Msg.ToString());
            var list = groupModule.GetGroupPageListModule(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: list);
        }

        /// <summary>
        /// 新增修改
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetGroup()
        {
            var extModel = Common.Plugin.JsonHelper.DeserializeObject<RB_Group_ViewModel>(RequestParm.Msg.ToString());
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            bool flag = groupModule.SetGroupModule(extModel);
            return flag ? ApiResult.Success(data: extModel) : ApiResult.Failed();
        }

        /// <summary>
        /// 获取集团列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetGroup()
        {
            var GId = base.ParmJObj.GetInt("GId", 0);
            var extModel = groupModule.GetGroupEntityModule(GId);
            return ApiResult.Success(data: extModel);
        }

        /// <summary>
        /// 删除集团
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveGroup()
        {
            var GId = base.ParmJObj.GetInt("GId", 0);
            var flag = groupModule.RemoveGroupModule(GId);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        #endregion

        #region 学校管理

        /// <summary>
        /// 获取学校列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetSchoolList()
        {
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_School_ViewModel>(RequestParm.Msg.ToString());
            query.Group_Id = base.UserInfo.Group_Id;
            var list = schoolModule.GetSchoolListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取学校分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetSchoolPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_School_ViewModel>(RequestParm.Msg.ToString());
            query.Group_Id = base.UserInfo.Group_Id;
            var list = schoolModule.GetSchoolPageListModule(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 SetSchool()
        {
            var extModel = new RB_School_ViewModel()
            {
                Dept_Id = base.ParmJObj.GetInt("Dept_Id"),
                ManagerId = base.ParmJObj.GetInt("ManagerId"),
                Remark = base.ParmJObj.GetStringValue("Remark"),
                SAddress = base.ParmJObj.GetStringValue("SAddress"),
                SDomain = base.ParmJObj.GetStringValue("SDomain"),
                SId = base.ParmJObj.GetInt("SId"),
                SLinkTel = base.ParmJObj.GetStringValue("SLinkTel"),
                SLogo = base.ParmJObj.GetStringValue("SLogo"),
                SName = base.ParmJObj.GetStringValue("SName"),
                Status = (DateStateEnum)base.ParmJObj.GetInt("Status"),
                ContractTitle = base.ParmJObj.GetStringValue("ContractTitle"),
            };
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = base.UserInfo.Group_Id;
            bool flag = schoolModule.SetSchoolModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取学校实体
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetSchool()
        {
            var SId = base.ParmJObj.GetInt("SId", 0);
            var extModel = schoolModule.GetSchoolEntityModule(SId);
            return ApiResult.Success(data: extModel);
        }

        /// <summary>
        /// 删除学校
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveSchool()
        {
            var SId = base.ParmJObj.GetInt("SId", 0);
            var flag = schoolModule.RemoveSchoolModule(SId);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }




        /// <summary>
        /// 获取学校列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Microsoft.AspNetCore.Authorization.AllowAnonymous]
        public ApiResult GetDropSchoolList()
        {
            var Group_Id = base.ParmJObj.GetInt("Group_Id", 100000);
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_School_ViewModel>(RequestParm.Msg.ToString());
            query.Group_Id = Group_Id;
            var list = schoolModule.GetSchoolListModule(query);
            return ApiResult.Success(data: list);
        }
        #endregion

        #region 讲师管理

        /// <summary>
        /// 获取教师擅长列表
        /// </summary>
        /// <returns></returns>
        public ApiResult GetTeacherSpecialty()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(SpecialtyEnum));
            return ApiResult.Success(data: list);
        }


        /// <summary>
        /// 获取讲师分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetTeacherPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Teacher_ViewModel()
            {
                TeacherName = base.ParmJObj.GetStringValue("TeacherName"),
                TeacherTel = base.ParmJObj.GetStringValue("TeacherTel"),
                IsShow = base.ParmJObj.GetInt("IsShow"),
                AuditStatus = (AccountStatusEnum)base.ParmJObj.GetInt("AuditStatus"),
                School_Id = -1,
            };
            var schoolId = base.ParmJObj.GetStringValue("School_Id");
            if (!string.IsNullOrEmpty(schoolId))
            {
                Int32.TryParse(schoolId, out int NewSchoolId);
                if (NewSchoolId >= 0)
                {
                    query.School_Id = NewSchoolId;
                }
            }
            query.Group_Id = base.UserInfo.Group_Id;
            var list = teacherModule.GetTeacherPageListModule(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 GetTeacherList()
        {
            var query = new RB_Teacher_ViewModel()
            {
                IsQLeave = base.ParmJObj.GetInt("IsQLeave")
            };
            query.Group_Id = base.UserInfo.Group_Id;
            query.School_Id = base.UserInfo.School_Id;
            var list = teacherModule.GetTeacherListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 添加修改讲师
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetTeacher()
        {
            var extModel = new RB_Teacher_ViewModel()
            {
                TId = base.ParmJObj.GetInt("TId"),
                School_Id = base.ParmJObj.GetInt("School_Id"),
                TeacherName = base.ParmJObj.GetStringValue("TeacherName"),
                TeacherTel = base.ParmJObj.GetStringValue("TeacherTel"),
                TeacherHead = base.ParmJObj.GetStringValue("TeacherHead"),
                TeacherIcon = base.ParmJObj.GetStringValue("TeacherIcon"),
                TeacherSay = base.ParmJObj.GetStringValue("TeacherSay"),
                TeacherIntro = base.ParmJObj.GetStringValue("TeacherIntro"),
                IsShow = base.ParmJObj.GetInt("IsShow"),
                IsRecommend = base.ParmJObj.GetInt("IsRecommend"),
                SortNum = base.ParmJObj.GetInt("SortNum"),
                Dept_Id = base.ParmJObj.GetInt("Dept_Id"),
                Post_Id = base.ParmJObj.GetInt("Post_Id"),
                BaseStuNum = base.ParmJObj.GetInt("BaseStuNum"),
                BaseHourFee = base.ParmJObj.GetDecimal("BaseHourFee"),
                AuditStatus = AccountStatusEnum.Pass,
                Specialty = base.ParmJObj.GetStringValue("Specialty"),
                BaseHoursEnabled = base.ParmJObj.GetInt("BaseHoursEnabled", 0),
                EnableTime = base.ParmJObj.GetStringValue("EnableTime")
            };
            extModel.TeachTag = base.ParmJObj.GetStringValue("TeachTag");
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = base.UserInfo.Group_Id;
            bool flag = teacherModule.SetTeacherModule_V2(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取讲师实体
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetTeacher()
        {
            var TId = base.ParmJObj.GetInt("TId", 0);
            var extModel = teacherModule.GetTeacherModule(TId);
            return ApiResult.Success(data: extModel);
        }

        /// <summary>
        /// 删除讲师
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveTeacher()
        {
            var TId = base.ParmJObj.GetInt("TId", 0);
            var flag = teacherModule.RemoveTeacherModule(TId);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 讲师审核
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult AuditTeacher()
        {
            var TId = base.ParmJObj.GetInt("TId", 0);
            int AuditStatus = base.ParmJObj.GetInt("AuditStatus", 1);
            string AuditRemark = base.ParmJObj.GetStringValue("AuditRemark");
            var flag = teacherModule.AuditTeacherModule(TId, AuditStatus, AuditRemark, base.UserInfo);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 讲师重新申请审核
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult ReApplyTeacher()
        {
            var TId = base.ParmJObj.GetInt("TId", 0);
            var flag = teacherModule.ReApplyTeacherModule(TId);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }



        /// <summary>
        /// 获取讲师列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public ApiResult GetAllTeacherList()
        {
            var query = new RB_Teacher_ViewModel()
            {
                IsQLeave = base.ParmJObj.GetInt("IsQLeave", 0),
                Group_Id = base.ParmJObj.GetInt("Group_Id", 100000)
            };

            var list = teacherModule.GetTeacherListModule(query);
            var result = list.Select(x => new
            {
                x.TeacherHead,
                x.TId
            });
            return ApiResult.Success(data: result);
        }
        #endregion

        #region 助教管理

        /// <summary>
        /// 获取助教分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetAssistPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Assist_ViewModel>(RequestParm.Msg.ToString());
            query.Group_Id = base.UserInfo.Group_Id;
            var list = assistModule.GetAssistPageListModule(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 GetAssistList()
        {
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Assist_ViewModel>(RequestParm.Msg.ToString());
            query.Group_Id = base.UserInfo.Group_Id;
            query.School_Id = base.UserInfo.School_Id;
            var list = assistModule.GetAssistListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 添加修改助教
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetAssist()
        {
            var extModel = new RB_Assist_ViewModel()
            {
                AId = base.ParmJObj.GetInt("AId"),
                School_Id = base.ParmJObj.GetInt("School_Id"),
                AssistName = base.ParmJObj.GetStringValue("AssistName"),
                AssistTel = base.ParmJObj.GetStringValue("AssistTel"),
                AssistIcon = base.ParmJObj.GetStringValue("AssistIcon"),
                AssistIntro = base.ParmJObj.GetStringValue("AssistIntro"),
                Dept_Id = base.ParmJObj.GetInt("Dept_Id"),
                Post_Id = base.ParmJObj.GetInt("Post_Id"),
                AuditStatus = AccountStatusEnum.Pass
            };
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = base.UserInfo.Group_Id;

            bool flag = assistModule.SetAssistModule_V2(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取助教实体
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetAssist()
        {
            var AId = base.ParmJObj.GetInt("AId", 0);
            var extModel = assistModule.GetAssistModule(AId);
            return ApiResult.Success(data: extModel);
        }

        /// <summary>
        /// 删除讲师
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveAssist()
        {
            var AId = base.ParmJObj.GetInt("AId", 0);
            var flag = assistModule.RemoveAssistModule(AId);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 助教重新申请
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult ReApplyAssist()
        {
            var AId = base.ParmJObj.GetInt("AId", 0);
            var flag = assistModule.ReApplyAssistModule(AId);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 助教审核
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult AuditAssist()
        {
            var AId = base.ParmJObj.GetInt("AId", 0);
            int AuditStatus = base.ParmJObj.GetInt("AuditStatus", 1);
            string AuditRemark = base.ParmJObj.GetStringValue("AuditRemark");
            var flag = assistModule.AuditAssistModule(AId, AuditStatus, AuditRemark, base.UserInfo);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }
        #endregion

        #region 学生管理

        /// <summary>
        /// 获取学生分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_ViewModel()
            {
                StuName = base.ParmJObj.GetStringValue("StuName"),
                StuTel = base.ParmJObj.GetStringValue("StuTel"),
                CreateBy = base.ParmJObj.GetInt("CreateBy"),
                IsQueryMyStu = base.ParmJObj.GetInt("IsQueryMyStu"),
                CustomerId = base.ParmJObj.GetInt("CustomerId"),
                StuStage = base.ParmJObj.GetInt("StuStage"),
                StartTime = base.ParmJObj.GetStringValue("StartTime"),
                EndTime = base.ParmJObj.GetStringValue("EndTime"),
                BelongType = base.ParmJObj.GetInt("BelongType"),
                QStudentType = base.ParmJObj.GetInt("QStudentType", -1),
                QQ = base.ParmJObj.GetStringValue("QQ"),
                WeChatNo = base.ParmJObj.GetStringValue("WeChatNo"),
                StuType = base.ParmJObj.GetInt("StuType"),
                ExistCourseConsultant=base.ParmJObj.GetInt("ExistCourseConsultant"),
                CategoryId=base.ParmJObj.GetInt("CategoryId"),
                QStudentStatus=base.ParmJObj.GetInt("QStudentStatus"),
                AdvisorStatus=base.ParmJObj.GetInt("AdvisorStatus"),
            };
            if (query.IsQueryMyStu == 1)
            {
                query.CreateBy = base.UserInfo.Id;
            }

            string CreateIds = base.ParmJObj.GetStringValue("CreateIds");
            if (!string.IsNullOrEmpty(CreateIds))
            {
                query.CreateIds = Common.Plugin.JsonHelper.DeserializeObject<List<int>>(CreateIds);
            }

            int PlanId = base.ParmJObj.GetInt("PlanId");
            if (PlanId > 0)
            {
                var planModel = dutyPlanModule.GetDutyPlanModule(PlanId);
                string planDate = Common.ConvertHelper.FormatDate(planModel.Date);
                if (!string.IsNullOrEmpty(planDate))
                {
                    query.QDate = planDate;
                }
            }
            query.Group_Id = base.UserInfo.Group_Id;
            var data = studentModule.GetStudentPageListModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                if (item.CreateBy > 0)
                {
                    item.CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                }

                list.Add(new
                {
                    item.StuId,
                    item.StuName,
                    item.StuTel,
                    item.StuIcon,
                    item.StuSex,
                    StuSexStr = item.StuSex == 0 ? "男" : "女",
                    StuBirth = Common.ConvertHelper.FormatDate(item.StuBirth),
                    item.StuStage,
                    item.StuStageName,
                    CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime),
                    item.CreateBy,
                    item.CreateByName,
                    item.CreateType,
                    CreateTypeStr = item.CreateType.ToName(),
                    item.StuChannel,
                    item.StuChannelName,
                    item.PlatformName,
                    item.CustomerId,
                    item.CustomerName,
                    AssistList = item.AssistList.Select(qitem => new
                    {
                        qitem.Id,
                        qitem.StuId,
                        qitem.AssistId,
                        qitem.AssistName,
                        qitem.AssistType,
                        AssistTypeName = qitem.AssistType.ToName()
                    }),
                    item.JapanBaseInfo,
                    JapanBaseInfoName = item.JapanBaseInfo.ToName(),
                    item.StuProfession,
                    item.StuEducation,
                    StuEducationName = item.StuEducation.ToName(),
                    item.StuPurpose,
                    item.StuPurposeName,
                    item.VisitCount,
                    item.TrialLessonCount,
                    item.StuSourceId,
                    item.StuSourceIdName,
                    item.QQ,
                    item.WeChatNo,
                    item.StuType,
                    item.StuTypeName,
                    item.StuNeeds,
                    item.StuNeedsName,
                    item.StuRealMobile,
                    item.OrderCount,
                    item.RenewOrderCount,
                    item.EnterpriseName,
                    item.AdvisorExpectDate,
                    item.AdvisorStatus,
                    item.AdvisorStatusName,
                    item.AdvisorList,
                    item.AdvisorWinRate,
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 导出学员信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Obsolete]
        public FileContentResult DownLoadStudent()
        {
            List<ExcelDataSource> slist = new List<ExcelDataSource>();
           
            var query = new RB_Student_ViewModel()
            {
                StuName = base.ParmJObj.GetStringValue("StuName"),
                StuTel = base.ParmJObj.GetStringValue("StuTel"),
                CreateBy = base.ParmJObj.GetInt("CreateBy"),
                IsQueryMyStu = base.ParmJObj.GetInt("IsQueryMyStu"),
                CustomerId = base.ParmJObj.GetInt("CustomerId"),
                StuStage = base.ParmJObj.GetInt("StuStage"),
                StartTime = base.ParmJObj.GetStringValue("StartTime"),
                EndTime = base.ParmJObj.GetStringValue("EndTime"),
                BelongType = base.ParmJObj.GetInt("BelongType"),
                QStudentType = base.ParmJObj.GetInt("QStudentType", -1),
                QQ = base.ParmJObj.GetStringValue("QQ"),
                WeChatNo = base.ParmJObj.GetStringValue("WeChatNo"),
                StuType = base.ParmJObj.GetInt("StuType"),
                ExistCourseConsultant = base.ParmJObj.GetInt("ExistCourseConsultant"),
                CategoryId = base.ParmJObj.GetInt("CategoryId"),
            };
            if (query.IsQueryMyStu == 1)
            {
                query.CreateBy = base.UserInfo.Id;
            }

            string CreateIds = base.ParmJObj.GetStringValue("CreateIds");
            if (!string.IsNullOrEmpty(CreateIds))
            {
                query.CreateIds = Common.Plugin.JsonHelper.DeserializeObject<List<int>>(CreateIds);
            }

            int PlanId = base.ParmJObj.GetInt("PlanId");
            if (PlanId > 0)
            {
                var planModel = dutyPlanModule.GetDutyPlanModule(PlanId);
                string planDate = Common.ConvertHelper.FormatDate(planModel.Date);
                if (!string.IsNullOrEmpty(planDate))
                {
                    query.QDate = planDate;
                }
            }
            query.Group_Id = base.UserInfo.Group_Id;
            string excelName = "客户资料.xls";
            var advisorList = studentModule.GetStudentAdvisorConfigListModule(new RB_Student_AdvisorConfig_Extend() { Group_Id = base.UserInfo.Group_Id });
            var list = studentModule.GetStudentPageListModule(1, 1000000, out long rowsCount, query);
            try
            {
                ExcelDataSource header = new ExcelDataSource
                {
                    ExcelRows = new List<ExcelColumn>()
                    {
                        new ExcelColumn("昵称"){ CellWidth=20},
                        new ExcelColumn("课程顾问"){ CellWidth=10},
                        new ExcelColumn("协助老师"){ CellWidth=10},
                        new ExcelColumn("是否报名"){ CellWidth=10},
                        new ExcelColumn("性别"){ CellWidth=10},
                        new ExcelColumn("电话"){ CellWidth=10},
                        new ExcelColumn("QQ"){ CellWidth=10},
                        new ExcelColumn("微信"){ CellWidth=10},
                        new ExcelColumn("客户类型"){ CellWidth=20},
                        new ExcelColumn("客户阶段"){ CellWidth=20},
                        new ExcelColumn("客户需求"){ CellWidth=20},
                        new ExcelColumn("职业"){ CellWidth=10},
                        new ExcelColumn("学历"){ CellWidth=10},
                        new ExcelColumn("目的"){ CellWidth=10},
                        new ExcelColumn("其他服务人员"){ CellWidth=20},
                        new ExcelColumn("客户来源"){ CellWidth=20},
                        new ExcelColumn("来源关联人"){ CellWidth=20},
                        new ExcelColumn("收客渠道"){ CellWidth=20},
                        new ExcelColumn("到访次数"){ CellWidth=10},
                        new ExcelColumn("试听次数"){ CellWidth=10},
                        new ExcelColumn("创建时间"){ CellWidth=25},
                        new ExcelColumn("负责人"){ CellWidth=15},
                        new ExcelColumn("期望达成协议日期"){ CellWidth=20},
                        new ExcelColumn("胜率"){ CellWidth=20},
                        new ExcelColumn("当前状态"){ CellWidth=20},
                    }
                };
                foreach (var hItem in advisorList)
                {
                    header.ExcelRows.Add(new ExcelColumn(hItem.Name));
                }
                slist.Add(header);
                foreach (var item in list)
                {
                    var courseManager = item?.AssistList?.Where(qtiem => qtiem.AssistType == AssistTypeEnum.CourseAdviser)?.FirstOrDefault();
                    string course = courseManager?.AssistName ?? "暂未推送";
                    var teacherManager= item?.AssistList?.Where(qtiem => qtiem.AssistType == AssistTypeEnum.Teacher)?.FirstOrDefault();
                    string teacher = teacherManager?.AssistName ?? "暂无";
                    string orderStr = item.OrderCount > 0 ? "已报名" + item.OrderCount + "单" : "未报名";
                    string assistStr = "";
                    foreach (var subItem in item.AssistList)
                    {
                        if (subItem.AssistType != AssistTypeEnum.Teacher && subItem.AssistType != AssistTypeEnum.CourseAdviser)
                        {
                            assistStr += subItem.AssistType.ToName() + ":" + subItem.AssistName + ",";
                        }
                    }
                    var dataRow = new ExcelDataSource()
                    {
                         ExcelRows=new List<ExcelColumn>() 
                         { 
                            new ExcelColumn(item.StuName),
                            new ExcelColumn(course),
                            new ExcelColumn(teacher),
                            new ExcelColumn(orderStr),
                            new ExcelColumn(item.StuSex==0?"男":"女"),
                            new ExcelColumn(item.StuTel),
                            new ExcelColumn(item.QQ),
                            new ExcelColumn(item.WeChatNo),
                            new ExcelColumn(item.StuTypeName),
                            new ExcelColumn(item.StuStageName),
                            new ExcelColumn(item.StuNeedsName),
                            new ExcelColumn(item.StuProfession),
                            new ExcelColumn(item.StuEducation.ToName()),
                            new ExcelColumn(item.StuPurposeName),
                            new ExcelColumn(assistStr.TrimEnd(',')),
                            new ExcelColumn(item.CreateType.ToName()),
                            new ExcelColumn(item.StuSourceIdName),
                            new ExcelColumn(item.StuChannelName),
                            new ExcelColumn(item.VisitCount.ToString()),
                            new ExcelColumn(item.TrialLessonCount.ToString()),
                            new ExcelColumn(item.CreateTimeStr),
                            new ExcelColumn(item.CreateByName),
                            new ExcelColumn(item.AdvisorExpectDate),
                            new ExcelColumn(item.AdvisorWinRate+"%"),
                            new ExcelColumn(item.AdvisorStatusName),
                         }
                    };
                    foreach (var hItem in advisorList)
                    {
                        var tempItem = item?.AdvisorList?.Where(qitem => qitem.AdvisorStatus == hItem.Id)?.LastOrDefault()?.AdvisorDate??"";
                        dataRow.ExcelRows.Add(new ExcelColumn(tempItem));
                    }
                    slist.Add(dataRow);
                }
                var byteData = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData, "application/octet-stream", excelName);
            }
            catch (Exception ex)
            {
                LogHelper.Write(ex, "OutToExcelOrderStudentClassHoursList");
                var byteData1 = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData1, "application/octet-stream", excelName);
            }
        }

        /// <summary>
        /// 获取学生列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentList()
        {
            var query = new RB_Student_ViewModel()
            {
                StuName = base.ParmJObj.GetStringValue("StuName"),
                StuTel = base.ParmJObj.GetStringValue("StuTel"),
                CreateBy = base.ParmJObj.GetInt("CreateBy"),
                IsQueryMyStu = base.ParmJObj.GetInt("IsQueryMyStu"),
                CustomerId = base.ParmJObj.GetInt("CustomerId"),
                StuStage = base.ParmJObj.GetInt("StuStage"),
                StartTime = base.ParmJObj.GetStringValue("StartTime"),
                EndTime = base.ParmJObj.GetStringValue("EndTime"),
                BelongType = base.ParmJObj.GetInt("BelongType"),
                QStudentType = base.ParmJObj.GetInt("QStudentType", -1),
                QQ = base.ParmJObj.GetStringValue("QQ"),
                WeChatNo = base.ParmJObj.GetStringValue("WeChatNo"),
                StuType = base.ParmJObj.GetInt("StuType"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            //query.School_Id = base.UserInfo.School_Id;
            var list = studentModule.GetStudentListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 添加修改学生
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudent()
        {
            var extModel = new RB_Student_ViewModel()
            {
                StuId = base.ParmJObj.GetInt("StuId"),
                StuName = base.ParmJObj.GetStringValue("StuName"),
                StuTel = base.ParmJObj.GetStringValue("StuTel"),
                StuIcon = base.ParmJObj.GetStringValue("StuIcon"),
                StuSex = base.ParmJObj.GetInt("StuSex"),
                StuBirth = base.ParmJObj.GetDateTime("StuBirth"),
                ProviceId = base.ParmJObj.GetInt("ProviceId"),
                CityId = base.ParmJObj.GetInt("CityId"),
                AreaId = base.ParmJObj.GetInt("AreaId"),
                Interest = base.ParmJObj.GetInt("Interest"),
                JapanBaseInfo = (GuestBasicsEnum)base.ParmJObj.GetInt("JapanBaseInfo"),
                StuProfession = base.ParmJObj.GetStringValue("StuProfession"),
                StuEducation = (GuestEducationEnum)base.ParmJObj.GetInt("StuEducation"),
                StuPurpose = base.ParmJObj.GetInt("StuPurpose"),
                StuSource = (OrderSourceEnum)base.ParmJObj.GetInt("StuSource"),
                StuAddress = base.ParmJObj.GetStringValue("StuAddress"),
                StuContract = base.ParmJObj.GetStringValue("StuContract"),
                StuContractMobile = base.ParmJObj.GetStringValue("StuContractMobile"),
                StuIDCard = base.ParmJObj.GetStringValue("StuIDCard"),
                StuIDCardAddress = base.ParmJObj.GetStringValue("StuIDCardAddress"),
                StuStage = base.ParmJObj.GetInt("StuStage"),
                StuChannel = base.ParmJObj.GetInt("StuChannel"),
                PlatformName = base.ParmJObj.GetStringValue("PlatformName"),
                CreateType = (StuCreateTypeEnum)base.ParmJObj.GetInt("CreateType"),
                StuSourceId = base.ParmJObj.GetInt("StuSourceId"),
                CustomerId = base.ParmJObj.GetInt("CustomerId"),
                WeChatNo = base.ParmJObj.GetStringValue("WeChatNo"),
                QQ = base.ParmJObj.GetStringValue("QQ"),
                StuType = base.ParmJObj.GetInt("StuType"),
                StuNeeds=base.ParmJObj.GetInt("StuNeeds"),
                StuRealMobile=base.ParmJObj.GetStringValue("StuRealMobile"),
            };
            if (string.IsNullOrEmpty(extModel.StuRealMobile) && string.IsNullOrEmpty(extModel.QQ) && string.IsNullOrEmpty(extModel.WeChatNo))
            {
                return ApiResult.Failed("手机号码、QQ号码、微信号码至少填写一项!");
            }
            if (!string.IsNullOrEmpty(extModel.StuRealMobile) && !Common.Plugin.StringHelper.IsMobilePhone(extModel.StuRealMobile))
            {
                return ApiResult.Failed("手机号码不正确,请重新填写!");
            }
            extModel.Status = DateStateEnum.Normal;
            extModel.StuStatus = 1;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateTime = DateTime.Now;
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = base.UserInfo.Group_Id;

            extModel.IsDisable = 1;
            extModel.OperateType = 1;
            if (!string.IsNullOrEmpty(extModel.StuRealMobile) && studentModule.CheckStudentModule(extModel, 1))
            {
                return ApiResult.Failed("此学员手机号已绑定同行!请重新录入!");
            }
            if (!string.IsNullOrEmpty(extModel.QQ) && studentModule.CheckStudentModule(extModel, 2))
            {
                return ApiResult.Failed("此学员QQ号已绑定同行!请重新录入!");
            }
            if (!string.IsNullOrEmpty(extModel.WeChatNo) && studentModule.CheckStudentModule(extModel, 3))
            {
                return ApiResult.Failed("此学员微信号已绑定同行!请重新录入!");
            }
            var isInsert = extModel.StuId == 0;
            bool flag = studentModule.SetStudentModule(extModel);
            if (flag && isInsert)
            {
                if (base.UserInfo.IsCourseConsultant == 1)
                {
                    //课程顾问创建学员，默认写入顾问信息
                    var assistModel = new RB_Student_Assist_Extend()
                    {
                        Id = 0,
                        AssistId = base.UserInfo.Id,
                        AssistType = Common.Enum.User.AssistTypeEnum.CourseAdviser,
                        StuId = extModel.StuId,
                        Status = Common.Enum.DateStateEnum.Normal
                    };
                    new CustomerStudentModule().SetStudentAssistModule(extModel.StuId, assistModel, base.UserInfo.Id);
                }
            }
            return flag ? ApiResult.Success(data: extModel) : ApiResult.Failed();
        }

        /// <summary>
        /// 修改客户阶段
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentStage()
        {
            var StuId = base.ParmJObj.GetInt("StuId");
            var StuStage = base.ParmJObj.GetInt("StuStage");
            if (StuStage > 0)
            {
                var flag = studentModule.SetStudentStageModule(StuId, StuStage, base.UserInfo.Id);
                return flag ? ApiResult.Success() : ApiResult.Failed();
            }
            return ApiResult.Failed(message:"请选择客户阶段");
        }

        /// <summary>
        /// 检查学员手机号码是否存在
        /// </summary>
        /// <returns></returns>
        public ApiResult CheckExistsStu()
        {
            var query = new RB_Student_ViewModel()
            {
                StuId = base.ParmJObj.GetInt("StuId"),
                StuRealMobile = base.ParmJObj.GetStringValue("StuRealMobile"),
                QQ = base.ParmJObj.GetStringValue("QQ"),
                WeChatNo = base.ParmJObj.GetStringValue("WeChatNo")
            };
            string message = "";
            var customer = base.AppletCustomerInfo;
            //是否是同行注册
            bool isB2B = false;
            if (customer != null && customer.GroupId > 0)
            {
                query.Group_Id = customer.GroupId;
                isB2B = true;
            }
            if (query.Group_Id <= 0)
            {
                query.Group_Id = base.UserInfo.Group_Id;
            }

            if (!string.IsNullOrEmpty(query.StuRealMobile))
            {
                var model = studentModule.CheckExistsStuModule(new RB_Student_ViewModel() { Group_Id = query.Group_Id, StuRealMobile = query.StuRealMobile });
                string name = UserReidsCache.GetUserLoginInfo((model?.CreateBy ?? 0))?.AccountName ?? "";
                if (model != null && model.StuId > 0)
                {
                    if (query.StuId > 0)
                    {
                        if (query.StuId != model.StuId)
                        {
                            if (isB2B)
                            {
                                message = "此学员手机号已绑定同行!请重新录入!";
                                studentModule.PushMessageModule(model,1);
                            }
                            else
                            {
                                message = string.Format("此学员手机号已被【{0}】于【{1}】注册。", name, Common.ConvertHelper.FormatTime(model.CreateTime));
                            }
                        }
                    }
                    else
                    {
                        if (isB2B)
                        {
                            message = "此学员手机号已绑定同行!请重新录入!";
                            studentModule.PushMessageModule(model,1);
                        }
                        else
                        {
                            message = string.Format("此学员手机号已被【{0}】于【{1}】注册。", name, Common.ConvertHelper.FormatTime(model.CreateTime));
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(query.QQ))
            {
                var model = studentModule.CheckExistsStuModule(new RB_Student_ViewModel() { Group_Id = query.Group_Id, QQ = query.QQ });
                string name = UserReidsCache.GetUserLoginInfo((model?.CreateBy ?? 0))?.AccountName ?? "";
                if (model != null && model.StuId > 0)
                {
                    if (query.StuId > 0)
                    {
                        if (query.StuId != model.StuId)
                        {
                            if (isB2B)
                            {
                                message = "此学员QQ已绑定同行!请重新录入!";
                                studentModule.PushMessageModule(model,2);
                            }
                            else
                            {
                                message = string.Format("此学员QQ号已被【{0}】于【{1}】注册。", name, Common.ConvertHelper.FormatTime(model.CreateTime));
                            }
                        }
                    }
                    else
                    {
                        if (isB2B)
                        {
                            message = "此学员QQ已绑定同行!请重新录入!";
                            studentModule.PushMessageModule(model,2);
                        }
                        else
                        {
                            message = string.Format("此学员QQ号已被【{0}】于【{1}】注册。", name, Common.ConvertHelper.FormatTime(model.CreateTime));
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(query.WeChatNo))
            {
                var model = studentModule.CheckExistsStuModule(new RB_Student_ViewModel() { Group_Id = query.Group_Id, WeChatNo = query.WeChatNo });
                string name = UserReidsCache.GetUserLoginInfo((model?.CreateBy ?? 0))?.AccountName ?? "";
                if (model != null && model.StuId > 0)
                {
                    if (query.StuId > 0)
                    {
                        if (query.StuId != model.StuId)
                        {
                            if (isB2B)
                            {
                                message = "此学员微信号已绑定同行!请重新录入!";
                                studentModule.PushMessageModule(model,3);
                            }
                            else
                            {
                                message = string.Format("此学员微信号已被【{0}】于【{1}】注册。", name, Common.ConvertHelper.FormatTime(model.CreateTime));
                            }
                        }
                    }
                    else
                    {
                        if (isB2B)
                        {
                            message = "此学员微信号已绑定同行!请重新录入!";
                            studentModule.PushMessageModule(model,3);
                        }
                        else
                        {
                            message = string.Format("此学员微信号已被【{0}】于【{1}】注册。", name, Common.ConvertHelper.FormatTime(model.CreateTime));
                        }
                    }
                }
            }
            return !string.IsNullOrEmpty(message) ? ApiResult.Failed(message: message) : ApiResult.Success();
        }

        

        /// <summary>
        /// 获取收客平台列表
        /// </summary>
        /// <returns></returns>
        public ApiResult GetStuChannelList()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(StuChannelEnum));
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取协助人员类型列表
        /// </summary>
        /// <returns></returns>
        public ApiResult GetAssistTypeList()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(AssistTypeEnum));
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 同业小程序添加学生名单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult AppSetStudent()
        {
            var extModel = new RB_Student_ViewModel()
            {
                StuId = base.ParmJObj.GetInt("StuId"),
                StuName = base.ParmJObj.GetStringValue("StuName"),
                StuTel = base.ParmJObj.GetStringValue("StuTel"),
                StuIcon = base.ParmJObj.GetStringValue("StuIcon"),
                StuSex = base.ParmJObj.GetInt("StuSex"),
                StuBirth = base.ParmJObj.GetDateTime("StuBirth"),
                ProviceId = base.ParmJObj.GetInt("ProviceId"),
                CityId = base.ParmJObj.GetInt("CityId"),
                AreaId = base.ParmJObj.GetInt("AreaId"),
                Interest = base.ParmJObj.GetInt("Interest"),
                JapanBaseInfo = (GuestBasicsEnum)base.ParmJObj.GetInt("JapanBaseInfo"),
                StuProfession = base.ParmJObj.GetStringValue("StuProfession"),
                StuEducation = (GuestEducationEnum)base.ParmJObj.GetInt("StuEducation"),
                StuPurpose = base.ParmJObj.GetInt("StuPurpose"),
                StuSource = (OrderSourceEnum)base.ParmJObj.GetInt("StuSource"),
                StuAddress = base.ParmJObj.GetStringValue("StuAddress"),
                StuContract = base.ParmJObj.GetStringValue("StuContract"),
                StuContractMobile = base.ParmJObj.GetStringValue("StuContractMobile"),
                StuIDCard = base.ParmJObj.GetStringValue("StuIDCard"),
                StuIDCardAddress = base.ParmJObj.GetStringValue("StuIDCardAddress"),
                WeChatNo = base.ParmJObj.GetStringValue("WeChatNo"),
                QQ = base.ParmJObj.GetStringValue("QQ"),
                StuType = base.ParmJObj.GetInt("StuType"),
                StuRealMobile=base.ParmJObj.GetStringValue("StuRealMobile"),
            };
            extModel.CreateType = StuCreateTypeEnum.CustomerInput;
            extModel.Status = DateStateEnum.Normal;
            extModel.StuStatus = 1;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateTime = DateTime.Now;
            var customer = base.AppletCustomerInfo;
            extModel.CreateBy = customer.SaleId;
            extModel.UpdateBy = customer.SaleId;
            extModel.Group_Id = customer.GroupId;
            extModel.CustomerId = customer.CustomerId;
            extModel.IsDisable = 1;
            extModel.OperateType = 2;
            if (string.IsNullOrEmpty(extModel.StuTel) && string.IsNullOrEmpty(extModel.QQ) && string.IsNullOrEmpty(extModel.WeChatNo))
            {
                return ApiResult.Failed("手机号码、QQ号码、微信号码至少填写一项!");
            }
            if (!string.IsNullOrEmpty(extModel.StuTel) && studentModule.CheckStudentModule(extModel, 1))
            {
                return ApiResult.Failed("此学员手机号已绑定同行!请重新录入!");
            }
            if (!string.IsNullOrEmpty(extModel.QQ) && studentModule.CheckStudentModule(extModel, 2))
            {
                return ApiResult.Failed("此学员QQ号已绑定同行!请重新录入!");
            }
            if (!string.IsNullOrEmpty(extModel.WeChatNo) && studentModule.CheckStudentModule(extModel, 3))
            {
                return ApiResult.Failed("此学员微信号已绑定同行!请重新录入!");
            }
            bool flag = studentModule.SetStudentModule(extModel, fromApp:1);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }


        /// <summary>
        /// 学员转交
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult ForwardStudent()
        {
            var StuId = base.ParmJObj.GetInt("StuId");
            var CreateBy = base.ParmJObj.GetInt("CreateBy");
            bool flag = studentModule.ForwardStudentModule(StuId, CreateBy, base.UserInfo.Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 同业小程序获取客户列表(学生列表)
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult AppGetStudentPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_ViewModel()
            {
                KeyWords = base.ParmJObj.GetStringValue("KeyWords"),
                StuId = base.ParmJObj.GetInt("StuId"),
                StuStage = base.ParmJObj.GetInt("StuStage")
            };
            var customer = base.AppletCustomerInfo;
            query.Group_Id = customer.GroupId;
            query.CustomerId = customer.CustomerId;

            var list = studentModule.GetStudentPageListModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> result = new List<object>();
            foreach (var item in list)
            {
                result.Add(new
                {
                    item.StuId,
                    item.StuIcon,
                    item.StuTel,
                    item.StuSex,
                    StuSexStr = item.StuSex == 0 ? "男" : "女",
                    item.StuName,
                    item.OrderCount,
                    item.RenewOrderCount,
                    item.StuGuestState,
                    StuGuestStateStr = item.StuGuestState.ToName(),
                    item.TodayCount,
                    item.WeekCount,
                    item.followUpTime,
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = result;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取学生实体
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudent()
        {
            var StuId = base.ParmJObj.GetInt("StuId", 0);
            var extModel = studentModule.GetStudentModule(StuId);
            classModule.GetStudentCurrentOrderModule(StuId, out int newClassStatus, out string classStatusName, out _, out _);
            var obj = new
            {
                extModel.StuId,
                extModel.StuName,
                extModel.StuTel,
                extModel.StuIcon,
                extModel.StuSex,
                StuBirth = Common.ConvertHelper.FormatDate(extModel.StuBirth),
                StuBirthStr = Common.ConvertHelper.FormatDate(extModel.StuBirth),
                extModel.ProviceId,
                extModel.CityId,
                extModel.AreaId,
                extModel.IsDisable,
                extModel.StuStatus,
                extModel.Interest,
                extModel.JapanBaseInfo,
                JapanBaseInfoName = extModel.JapanBaseInfo.ToName(),
                extModel.CustomerId,
                extModel.StuProfession,
                extModel.StuEducation,
                StuEducationName = extModel.StuEducation.ToName(),
                extModel.StuPurpose,
                extModel.StuPurposeName,
                extModel.StuSource,
                StuSourceName = extModel.StuSource.ToName(),
                extModel.StuAddress,
                extModel.StuContract,
                extModel.StuContractMobile,
                extModel.StuIDCard,
                extModel.StuIDCardAddress,
                CreateTimeStr = Common.ConvertHelper.FormatDate(extModel.CreateTime),
                newClassStatus,
                classStatusName,
                extModel.CreateType,
                CreateTypeStr = extModel.CreateType.ToName(),
                extModel.StuStage,
                extModel.StuStageName,
                extModel.CreateBy,
                extModel.StuChannel,
                extModel.StuChannelName,
                extModel.PlatformName,
                AssistList = extModel?.AssistList ?? new List<RB_Student_Assist_Extend>(),
                extModel.StuSourceId,
                extModel.StuSourceIdName,
                extModel.QQ,
                extModel.WeChatNo,
                extModel.StuType,
                extModel.StuTypeName,
                extModel.StuNeeds,
                extModel.StuNeedsName,
                extModel.StuRealMobile,
                extModel.CustomerName,
                extModel.PlanPrice,
                extModel.BaseCondition,
                extModel.DemandPoint,
                extModel.ResistPoint,
                extModel.ConsultingResults,
                ConsultDate = extModel.ConsultDate.HasValue ? extModel.ConsultDate.Value.ToString("yyyy-MM-dd") : "",
            };
            return ApiResult.Success(data: obj);
        }


        /// <summary>
        /// 跟进电话号码获取学生信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentByTel()
        {
            var customer = base.AppletCustomerInfo;
            var query = new RB_Student_ViewModel()
            {
                QQ = base.ParmJObj.GetStringValue("QQ"),
                WeChatNo = base.ParmJObj.GetStringValue("WeChatNo")
            };
            if (customer != null && customer.GroupId > 0)
            {
                query.StuRealMobile = base.ParmJObj.GetStringValue("StuTel");
                query.Group_Id = customer.GroupId;
            }
            if (query.Group_Id <= 0)
            {
                query.StuRealMobile = base.ParmJObj.GetStringValue("StuRealMobile");
                query.Group_Id = base.UserInfo.Group_Id;
            }
            var extModel = studentModule.CheckExistsStuModule(query);
            if (extModel != null && extModel.CreateBy > 0)
            {
                extModel.CreateByName = UserReidsCache.GetUserLoginInfo(extModel.CreateBy)?.AccountName ?? "";
                if (customer != null)
                {
                    studentModule.PushMessageModule(extModel,1);
                }
            }
            return ApiResult.Success(data: extModel);
        }

        /// <summary>
        /// 获取客户来源枚举列表
        /// </summary>
        /// <returns></returns>

        [HttpPost]
        public ApiResult CreateTypeList()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(StuCreateTypeEnum));
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 更新学生状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveStudent()
        {
            var StuId = base.ParmJObj.GetInt("StuId", 0);
            int Status = base.ParmJObj.GetInt("Status");
            var flag = studentModule.RemoveStudentModule(StuId, Status);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 更新学生禁用或启用
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult UpdateStudentIsDisable()
        {
            var StuId = base.ParmJObj.GetInt("StuId", 0);
            int IsDisable = base.ParmJObj.GetInt("IsDisable", 0);
            var flag = studentModule.UpdateStudentIsDisableModule(StuId, IsDisable);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 生成学生账号
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult CreateStudentAccount()
        {
            var StuId = base.ParmJObj.GetInt("StuId", 0);
            var flag = studentModule.CreateStudentAccountModule(StuId, base.UserInfo);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 保存学生咨询结果
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentConsultResults() 
        {
            var userInfo = base.UserInfo;
            RB_Student_ViewModel demodel = JsonHelper.DeserializeObject<RB_Student_ViewModel>(base.RequestParm.Msg.ToString());
            if (demodel.StuId <= 0) 
            {
                return ApiResult.ParamIsNull("请传递学员ID");
            }
            string msg = studentModule.SetStudentConsultResults(demodel, userInfo);
            if (msg == "")
            {
                return ApiResult.Success();
            }
            else 
            {
                return ApiResult.Failed(msg);
            }
        }

        #endregion

        #region 管理者管理

        /// <summary>
        /// 获取系统管理者分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetManagerPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new Employee_ViewModel()
            {
                Dept_Id = base.ParmJObj.GetInt("Dept_Id"),
                EmployeeName = base.ParmJObj.GetStringValue("EmployeeName"),
                EndBirthDate = base.ParmJObj.GetStringValue("EndBirthDate"),
                EndEntryTime = base.ParmJObj.GetStringValue("EndEntryTime"),
                EndLeaveTime = base.ParmJObj.GetStringValue("EndLeaveTime"),
                LeaveStatus = (LeaveStatusEnum)base.ParmJObj.GetInt("LeaveStatus"),
                Post_Id = base.ParmJObj.GetInt("Post_Id"),
                School_Id = -1,
                StartBirthDate = base.ParmJObj.GetStringValue("StartBirthDate"),
                StartEntryTime = base.ParmJObj.GetStringValue("StartEntryTime"),
                StartLeaveTime = base.ParmJObj.GetStringValue("StartLeaveTime"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var list = employeeModule.GetEmployeePageListModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            pageModel.Count = rowsCount;
            pageModel.PageData = list.Select((qitem, i) => new
            {
                Id = (pageModel.PageSize * (pageModel.PageIndex - 1)) + i + 1,
                qitem.UserIcon,
                qitem.EmployeeName,
                qitem.SchoolName,
                qitem.DeptName,
                qitem.PostName,
                qitem.EmployeeTel,
                Sex = qitem.Sex == 0 ? "男" : "女",
                BirthDate = Common.ConvertHelper.FormatDate(qitem.BirthDate),
                Education = qitem.Education.ToName(),
                LeaveStatus = qitem.LeaveStatus.ToName(),
                LeaveStatusValue = qitem.LeaveStatus,
                qitem.Account,
                qitem.AccountType,
                qitem.IsBirth,
                qitem.AccountId,
                qitem.School_Id,
                qitem.Group_Id,
                qitem.Dept_Id,
                qitem.AccountRemark,
                qitem.Email,
                EmAccountId = qitem.Id,
                qitem.DirectSupervisor,
                qitem.WorkUserId,
                DirectSupervisorName = qitem.DirectSupervisor > 0 ? base.GetUserInfo(qitem.DirectSupervisor)?.AccountName ?? "" : "",
            });
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取系统管理者列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetManagerList()
        {
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Manager_ViewModel>(RequestParm.Msg.ToString());
            query.Group_Id = base.UserInfo.Group_Id;
            query.School_Id = base.UserInfo.School_Id;
            var list = managerModule.GetManagerListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 添加修改管理者 SetManager
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> SetEmployeeAsync()
        {
            var extModel = new Employee_ViewModel()
            {
                AccountId = base.ParmJObj.GetInt("AccountId"),
                AccountType = (AccountTypeEnum)base.ParmJObj.GetInt("AccountType"),
                EmployeeName = base.ParmJObj.GetStringValue("EmployeeName"),
                EmployeeTel = base.ParmJObj.GetStringValue("EmployeeTel"),
                UserIcon = base.ParmJObj.GetStringValue("UserIcon"),
                Dept_Id = base.ParmJObj.GetInt("Dept_Id"),
                Post_Id = base.ParmJObj.GetInt("Post_Id"),
                IDCard = base.ParmJObj.GetStringValue("IDCard"),
                Sex = base.ParmJObj.GetInt("Sex"),
                EntryTime = base.ParmJObj.GetDateTime("EntryTime"),
                Address = base.ParmJObj.GetStringValue("Address"),
                BirthDate = base.ParmJObj.GetDateTime("BirthDate"),
                LeaveStatus = (LeaveStatusEnum)base.ParmJObj.GetInt("LeaveStatus"),
                LeaveTime = base.ParmJObj.GetDateTime("LeaveTime"),
                Education = (EducationEnum)base.ParmJObj.GetInt("Education"),
                School_Id = base.ParmJObj.GetInt("School_Id"),
                Email = base.ParmJObj.GetStringValue("Email"),
                DirectSupervisor = base.ParmJObj.GetInt("DirectSupervisor"),
                Account = base.ParmJObj.GetStringValue("Account"),
                Password = base.ParmJObj.GetStringValue("Password"),
                UserRole = (UserRoleEnum)base.ParmJObj.GetInt("UserRole"),
                IsTenCccUser = base.ParmJObj.GetInt("IsTenCccUser",0)
            };
            if (!string.IsNullOrEmpty(extModel.Password.Trim()))
            {
                extModel.Password = Common.DES.Encrypt(extModel.Password.Trim());
            }
            else
            {
                extModel.Password = Common.DES.Encrypt(Common.Config.DefaultPwd);
            }
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = base.UserInfo.Group_Id;

            //判断手机号码是否存在
            bool existPhoneResult = employeeModule.ExistPhone(extModel);
            if (existPhoneResult)
            {
                return ApiResult.Failed("手机号码已存在");
            }

            #region 验证离职用户的客户
            string TXLToken = "";//企业微信通讯录token
            if (extModel.AccountId > 0 && extModel.LeaveStatus == Common.Enum.User.LeaveStatusEnum.Departure)
            {
                var accountModel = employeeModule.GetEmployeeModule(0, extModel.AccountId, (int)extModel.AccountType);
                if (accountModel != null && accountModel.LeaveStatus != LeaveStatusEnum.Departure && !string.IsNullOrEmpty(accountModel.WorkUserId))
                {
                    var configmodel = departmentModule.GetWeChatConfigModel(base.UserInfo.Group_Id);
                    if (configmodel != null && configmodel.Enable == 1 && configmodel.DeptEmpEnable == 1)
                    {
                        if (accountModel.IsWorkTransfer != 1)
                        {
                            //获取外部联系人token
                            string token = WeChatReidsCache.GetToken(Cache.CacheKey.QYWeChat_EmpToken_Key + base.UserInfo.Group_Id);
                            if (string.IsNullOrEmpty(token))
                            {
                                var ContactToken = ThirdCore.QYWinXin.QYWeiXinHelper.GetToken(configmodel.WX_CorpId, configmodel.Contact_Secret);
                                if (ContactToken.errcode == Senparc.Weixin.ReturnCode_Work.请求成功)
                                {
                                    WeChatReidsCache.TokenSet(Cache.CacheKey.QYWeChat_EmpToken_Key + base.UserInfo.Group_Id, ContactToken.access_token, ContactToken.expires_in - 1);
                                    token = ContactToken.access_token;
                                }
                                else
                                {
                                    return ApiResult.Failed("企业微信token请求失败");
                                }
                            }
                            //验证员工下是否有客户
                            try
                            {
                                var excontact = ThirdCore.QYWinXin.QYWeiXinHelper.GetExternalContactList(token, accountModel.WorkUserId);
                                if (excontact.errcode == Senparc.Weixin.ReturnCode_Work.请求成功)
                                {
                                    if (excontact.external_userid != null && excontact.external_userid.Any())
                                    {
                                        return ApiResult.Failed("该用户下有未转移的企业客户，请交接客户后再试");
                                    }
                                }
                                else
                                {
                                    return ApiResult.Failed("企业微信获取客户列表失败");
                                }
                            }
                            catch (Exception ex)
                            {
                                if (!ex.Message.Contains("84061"))
                                {
                                    return ApiResult.Failed("企业微信获取客户列表失败");
                                }
                            }
                        }

                        //获取通讯录token
                        TXLToken = GetEmployeeToken(base.UserInfo.Group_Id, configmodel);
                        if (string.IsNullOrEmpty(TXLToken)) { return ApiResult.Failed("企业微信token请求失败"); }
                    }
                }
            }
            else if (extModel.LeaveStatus != LeaveStatusEnum.Departure)
            {
                //新增用户情况
                var configmodel = departmentModule.GetWeChatConfigModel(base.UserInfo.Group_Id);
                if (configmodel != null && configmodel.Enable == 1 && configmodel.DeptEmpEnable == 1)
                {
                    //获取通讯录token
                    TXLToken = GetEmployeeToken(base.UserInfo.Group_Id, configmodel);
                    if (string.IsNullOrEmpty(TXLToken)) { return ApiResult.Failed("企业微信token请求失败"); }
                }
            }
            #endregion

            var oldModel = employeeModule.GetEmployeeModule(0, extModel.AccountId, extModel.AccountType.ToInt());
            if (oldModel.IsTenCccUser == 0 && extModel.IsTenCccUser == 1)
            {
                var cccResult = await new TenCloudCCCHelper().SetUserToCCCUser(extModel);
                if (!cccResult.result)
                {
                    return ApiResult.Failed($"同步电话坐席失败，{cccResult.message}");
                }
            }
            else if (oldModel.IsTenCccUser == 1 && extModel.IsTenCccUser == 0)
            {
                var cccResult = await new TenCloudCCCHelper().DelUserToCCCUser(extModel);
                if (!cccResult.result)
                {
                    return ApiResult.Failed($"电话客服功能关闭失败，请联系管理员");
                }
            }

            bool flag = employeeModule.SetEmployeeModule(extModel, TXLToken);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }


        /// <summary>
        /// 获取用户角色类型列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetUserRoleList()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(UserRoleEnum));
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 修改员工的部门
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult UpdateEmployeeDept()
        {
            var extModel = Common.Plugin.JsonHelper.DeserializeObject<Employee_ViewModel>(RequestParm.Msg.ToString());
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = base.UserInfo.Group_Id;
            extModel.CreateBy = base.UserInfo.Id;

            #region 获取企业微信token
            string TXLToken = "";//通讯录token
            var accountModel = employeeModule.GetEmployeeModule(0, extModel.AccountId, (int)extModel.AccountType);
            if (accountModel != null && accountModel.LeaveStatus != LeaveStatusEnum.Departure && !string.IsNullOrEmpty(accountModel.WorkUserId))
            {
                //新增用户情况
                var configmodel = departmentModule.GetWeChatConfigModel(base.UserInfo.Group_Id);
                if (configmodel != null && configmodel.Enable == 1 && configmodel.DeptEmpEnable == 1)
                {
                    //获取通讯录token
                    TXLToken = GetEmployeeToken(base.UserInfo.Group_Id, configmodel);
                    if (string.IsNullOrEmpty(TXLToken)) { return ApiResult.Failed("企业微信token请求失败"); }
                }
            }
            #endregion

            bool flag = employeeModule.SetEmployeeDeptModule(extModel, TXLToken);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }


        /// <summary>
        /// 修改员工的岗位
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult UpdateEmployeePost()
        {
            var extModel = Common.Plugin.JsonHelper.DeserializeObject<Employee_ViewModel>(RequestParm.Msg.ToString());
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = base.UserInfo.Group_Id;
            extModel.CreateBy = base.UserInfo.Id;
            extModel.School_Id = base.UserInfo.School_Id;

            #region 获取企业微信token
            string TXLToken = "";//通讯录token
            var accountModel = employeeModule.GetEmployeeModule(0, extModel.AccountId, (int)extModel.AccountType);
            if (accountModel != null && accountModel.LeaveStatus != LeaveStatusEnum.Departure && !string.IsNullOrEmpty(accountModel.WorkUserId))
            {
                //新增用户情况
                var configmodel = departmentModule.GetWeChatConfigModel(base.UserInfo.Group_Id);
                if (configmodel != null && configmodel.Enable == 1 && configmodel.DeptEmpEnable == 1)
                {
                    //获取通讯录token
                    TXLToken = GetEmployeeToken(base.UserInfo.Group_Id, configmodel);
                    if (string.IsNullOrEmpty(TXLToken)) { return ApiResult.Failed("企业微信token请求失败"); }
                }
            }
            #endregion

            bool flag = employeeModule.SetEmployeePostModule(extModel, TXLToken);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }


        /// <summary>
        /// 修改员工的离职信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult UpdateEmployeeLeaveTime()
        {
            var extModel = Common.Plugin.JsonHelper.DeserializeObject<List<Employee_ViewModel>>(RequestParm.Msg.ToString());
            extModel.ForEach(x => x.UpdateTime = DateTime.Now);
            extModel.ForEach(x => x.UpdateBy = base.UserInfo.Id);
            extModel.ForEach(x => x.Group_Id = base.UserInfo.Group_Id);
            extModel.ForEach(x => x.CreateBy = base.UserInfo.Id);
            extModel.ForEach(x => x.School_Id = base.UserInfo.School_Id);
            bool flag = employeeModule.SetEmployeeLeaveTimeModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 批量重置用户密码信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult BatchResetUserPassword()
        {
            List<RB_Account_ViewModel> viewList = JsonConvert.DeserializeObject<List<RB_Account_ViewModel>>(RequestParm.Msg.ToString());
            if (viewList == null || viewList.Where(x => x.AccountType > 0).Count() != viewList.Count() || viewList.Where(x => x.AccountId > 0).Count() != viewList.Count())
            {
                return ApiResult.Failed(message: "参数不合法，请刷新页面重试");
            }
            else
            {
                bool result = false;
                //生成随机新密码
                var newPwd = Common.Encrypt.PwHelper.MakePassword(8);
                if (int.TryParse(RequestParm.Uid, out int uid))
                {
                    viewList.ForEach(x => x.Group_Id = UserReidsCache.GetUserLoginInfo(uid).Group_Id);
                    //判断账户信息是否存在，不存在就不去更新密码
                    var list = accountModule.GetUpdateAccountListRepository(viewList);
                    if (list != null && list.Any())
                    {
                        result = accountModule.SetBatchResetPassword(list, newPwd);
                    }
                }
                else
                {
                    return ApiResult.Failed(message: "身份信息不合法，请尝试重新登录");
                }
                if (result)
                {
                    return ApiResult.Success($"密码重置成功，用户新密码为【{newPwd}】,请复制保存");
                }
                else
                {
                    return ApiResult.Failed(message: "密码重置失败");
                }
            }
        }

        /// <summary>
        /// 获取管理者实体
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetEmployee()
        {
            var Id = 0;
            var AccountId = base.ParmJObj.GetInt("AccountId", 0);
            var AccountType = base.ParmJObj.GetInt("AccountType", 0);
            var extModel = employeeModule.GetEmployeeModule(Id, AccountId, AccountType);
            var obj = new
            {
                Account = extModel?.Account ?? "",
                AccountId = extModel?.AccountId ?? 0,
                AccountRemark = extModel?.AccountRemark ?? "",
                AccountType = extModel?.AccountType ?? 0,
                AccountTypeStr = (extModel?.AccountType ?? 0).ToName(),
                Address = extModel?.Address ?? "",
                AnnualLeaveDay = extModel?.AnnualLeaveDay ?? 0,
                extModel?.BirthDate,
                BirthDateStr = (extModel?.BirthDate != null ? Convert.ToDateTime(extModel.BirthDate).ToString("MM-dd") : ""),
                CreateBy = extModel?.CreateBy ?? 0,
                CreateTime = Common.ConvertHelper.FormatDate((extModel?.CreateTime)),
                DeptName = extModel?.DeptName ?? "",
                DeptTier = extModel?.DeptTier ?? 0,
                Dept_Id = extModel?.Dept_Id ?? 0,
                Education = extModel?.Education ?? 0,
                EducationStr = (extModel?.Education ?? 0).ToName(),
                EmployeeName = extModel?.EmployeeName ?? "",
                EmployeeTel = extModel?.EmployeeTel ?? "",
                EntryTime = Common.ConvertHelper.FormatDate((extModel?.EntryTime)),
                GroupName = extModel?.GroupName ?? "",
                Group_Id = extModel?.Group_Id ?? 0,
                IDCard = extModel?.IDCard ?? "",
                Id = extModel?.Id ?? 0,
                IsBirth = extModel?.IsBirth ?? 0,
                LeaveStatus = extModel?.LeaveStatus ?? 0,
                LeaveStatusStr = (extModel?.LeaveStatus ?? 0).ToName(),
                LeaveTime = Common.ConvertHelper.FormatDate(extModel?.LeaveTime),
                PostName = extModel?.PostName ?? "",
                Post_Id = extModel?.Post_Id ?? 0,
                SchoolName = extModel?.SchoolName ?? "",
                School_Id = extModel?.School_Id ?? 0,
                Sex = extModel?.Sex ?? 0,
                SexStr = (extModel?.Sex ?? 0) == 0 ? "男" : "女",
                UserIcon = extModel?.UserIcon ?? "",
                Status = extModel?.Status ?? 0,
                Email = extModel?.Email ?? "",
                DirectSupervisor = extModel?.DirectSupervisor ?? 0,
                DirectSupervisorName = base.GetUserInfo(extModel?.DirectSupervisor ?? 0)?.AccountName ?? "",
                UserRole= extModel?.UserRole??0,
                UserRoleName= extModel?.UserRole.ToName()??"",
                IsTenCccUser = extModel?.IsTenCccUser ?? 0,
            };
            return ApiResult.Success(data: obj);
        }

        /// <summary>
        /// 设置用户OKR直接主管
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetEmployeeDirectSupervisor()
        {
            var parms = ParmJObj;
            int UserId = parms.GetInt("UserId", 0);
            int DirectSupervisor = parms.GetInt("DirectSupervisor", 0);
            if (UserId <= 0)
            {
                return ApiResult.ParamIsNull("请传递用户id");
            }
            if (DirectSupervisor <= 0)
            {
                return ApiResult.ParamIsNull("请传递直接主管id");
            }
            bool flag = employeeModule.SetEmployeeDirectSupervisor(UserId, DirectSupervisor);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 删除管理者
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveManager()
        {
            var MId = base.ParmJObj.GetInt("MId", 0);
            int Status = base.ParmJObj.GetInt("Status");
            var flag = managerModule.RemoveManagerModule(MId, Status);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 创建管理者账号
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult CreateManagerAccount()
        {
            var MId = base.ParmJObj.GetInt("MId", 0);
            var flag = managerModule.CreateManagerAccountModule(MId, base.UserInfo);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }


        /// <summary>
        /// 获取触发事件枚举
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetAccountRemarkTypeEnumList()
        {
            var list = EnumHelper.EnumToList(typeof(RemarkTypeEnum));
            return ApiResult.Success("", list);
        }

        /// <summary>
        /// 行政备注
        /// </summary>
        /// <returns></returns>
        public ApiResult SetAccountRemark()
        {
            var extModel = Common.Plugin.JsonHelper.DeserializeObject<RB_AccountRemark_ViewModel>(RequestParm.Msg.ToString());
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = base.UserInfo.Group_Id;
            extModel.Status = Common.Enum.DateStateEnum.Normal;
            bool flag = accountRemarkModule.SetAccountRemarkModule(extModel);
            if (flag && extModel.IsAddNotice == 1)
            {
                var extAccountModel = employeeModule.GetEmployeeModule(0, extModel.AccountId, (int)extModel.AccountType);
                RB_Notice_ViewModel demodel = new RB_Notice_ViewModel();
                demodel.FileList ??= new List<Model.Public.FileModel>();
                demodel.Is_Top = demodel.Is_Top == 0 ? 2 : demodel.Is_Top;
                demodel.Status = Common.Enum.DateStateEnum.Normal;
                demodel.Group_Id = base.UserInfo.Group_Id;
                demodel.School_Id = base.UserInfo.School_Id;
                demodel.CreateBy = base.UserInfo.Id;
                demodel.CreateTime = DateTime.Now;
                demodel.UpdateBy = base.UserInfo.Id;
                demodel.UpdateTime = DateTime.Now;
                demodel.Id = 0;
                demodel.From = "行政";
                demodel.To = extAccountModel.Dept_Id.ToString();
                demodel.CopyPeople = "-1";
                demodel.Title = extAccountModel.EmployeeName + "的" + EnumHelper.ToName(extModel.RemarkType) + "公告";
                demodel.Content = extModel.Content;
                demodel.NoticeState = NoticeStateEnum.Publish;
                demodel.Is_Top = 2;
                noticeModule.SetNoticeInfo(demodel);
            }
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取行政备注分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetAccountRemarkPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_AccountRemark_ViewList>(RequestParm.Msg.ToString());
            query.Group_Id = base.UserInfo.Group_Id;
            var list = accountRemarkModule.GetPageList(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            foreach (var item in list)
            {
                foreach (var itemRemark in item.AccountRemarkList)
                {
                    if (itemRemark.CreateBy > 0)
                    {
                        itemRemark.CreateByName = UserReidsCache.GetUserLoginInfo(itemRemark.CreateBy)?.AccountName ?? "";
                    }
                    itemRemark.CreateTimeStr = itemRemark.CreateTime.HasValue ? itemRemark.CreateTime.Value.ToString("HH:mm:ss") : "";
                    itemRemark.RemarkTypeStr = EnumHelper.ToName(itemRemark.RemarkType);
                }
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }



        /// <summary>
        /// 获取系统管理者分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetUserChangeLogPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = Common.Plugin.JsonHelper.DeserializeObject<Model.ViewModel.Log.RB_User_ChangeLog_ViewModel>(RequestParm.Msg.ToString());
            query.Group_Id = base.UserInfo.Group_Id;
            var list = userChangeLogModule.GetUserChangeLogList(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.CreateBy > 0)
                {
                    item.CreateByPhoto = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.UserIcon ?? "";
                }
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list.Select(x => new
            {
                x.WeekDay,
                x.CreateByName,
                x.CreateByPhoto,
                x.DayStr,
                x.LogContent,
                x.TimeStr
            });
            return ApiResult.Success(data: pageModel);
        }

        #endregion

        #region 部门管理

        /// <summary>
        /// 获取部门分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetDeptPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Department_ViewModel()
            {
                DeptId = base.ParmJObj.GetInt("DeptId"),
                DeptName = base.ParmJObj.GetStringValue("DeptName"),
                DeptTier = base.ParmJObj.GetInt("DeptTier"),
                ParentId = base.ParmJObj.GetInt("ParentId"),
                Status = (DateStateEnum)base.ParmJObj.GetInt("Status"),
            };
            query.School_Id = -1;
            var School_Id = base.ParmJObj.GetStringValue("School_Id");
            if (!string.IsNullOrEmpty(School_Id))
            {
                query.School_Id = base.ParmJObj.GetInt("School_Id");
            }
            query.Group_Id = base.UserInfo.Group_Id;
            var list = departmentModule.GetDepartmentPageListModule(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 GetDeptList()
        {
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Department_ViewModel>(RequestParm.Msg.ToString());
            query.Group_Id = base.UserInfo.Group_Id;
            var list = departmentModule.GetDepartmentListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取当前部门和当前部门所有的下级部门列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetChildDepartment()
        {
            int DeptId = base.ParmJObj.GetInt("DeptId");
            if (DeptId <= 0)
            {
                return ApiResult.ParamIsNull(message: "请选择部门编号!");
            }
            var list = departmentModule.GetCurrentAndChildDepartmentListModule(DeptId);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取部门树形列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetDeptTree()
        {
            var query = new RB_Department_ViewModel()
            {
                Group_Id = base.UserInfo.Group_Id,
                School_Id = base.ParmJObj.GetInt("School_Id")
            };
            var list = departmentModule.GetDepartmentTreeModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取部门岗位树形列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetDeptPostTree()
        {
            var query = new RB_Department_ViewModel()
            {
                Group_Id = base.UserInfo.Group_Id,
                School_Id = base.ParmJObj.GetInt("School_Id")
            };
            var list = departmentModule.GetDepartmentTreeModule(query, isQueryPost: true);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取组织机构图
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetOrganizationChart()
        {
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Department_ViewModel>(RequestParm.Msg.ToString());
            query.Group_Id = base.UserInfo.Group_Id;
            var rootModel = groupModule.GetGroupEntityModule(query.Group_Id);
            var obj = departmentModule.GetOrganizationChartModule(rootModel, query);
            return ApiResult.Success(data: obj);
        }

        /// <summary>
        /// 添加修改部门
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetDept()
        {
            var extModel = Common.Plugin.JsonHelper.DeserializeObject<RB_Department_ViewModel>(RequestParm.Msg.ToString());
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = base.UserInfo.Group_Id;
            extModel.Status = Common.Enum.DateStateEnum.Normal;

            #region 获取企业微信Token

            var configmodel = departmentModule.GetWeChatConfigModel(base.UserInfo.Group_Id);
            string token = "";//获取企业微信通讯录Token
            if (configmodel != null && configmodel.Enable == 1 && configmodel.DeptEmpEnable == 1)
            {
                token = GetEmployeeToken(base.UserInfo.Group_Id, configmodel);
                if (string.IsNullOrEmpty(token)) { return ApiResult.Failed("企业微信token请求失败"); }
            }
            #endregion

            bool flag = departmentModule.SetDepartmentModule(extModel, token);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取部门实体类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetDept()
        {
            var DeptId = base.ParmJObj.GetInt("DeptId", 0);
            var extModel = departmentModule.GetDepartmentModule(DeptId);
            return ApiResult.Success(data: extModel);
        }

        /// <summary>
        /// 修改部门状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveDept()
        {
            var DeptId = base.ParmJObj.GetInt("DeptId", 0);
            int Status = base.ParmJObj.GetInt("Status");

            #region 获取企业微信Token
            var configmodel = departmentModule.GetWeChatConfigModel(base.UserInfo.Group_Id);
            string token = "";//获取企业微信通讯录Token
            if (configmodel != null && configmodel.Enable == 1 && configmodel.DeptEmpEnable == 1)
            {
                token = GetEmployeeToken(base.UserInfo.Group_Id, configmodel);
                if (string.IsNullOrEmpty(token)) { return ApiResult.Failed("企业微信token请求失败"); }
            }
            #endregion

            var flag = departmentModule.RemoveDepartmentModule(DeptId, Status, token);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }
        #endregion

        #region 岗位管理

        /// <summary>
        /// 获取岗位分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetPostPageList()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Post_ViewModel>(RequestParm.Msg.ToString());
            query.Group_Id = base.UserInfo.Group_Id;
            var list = postModule.GetPostPageListModule(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 GetPostList()
        {
            var query = new RB_Post_ViewModel()
            {
                Group_Id = base.UserInfo.Group_Id,
                PostName = base.ParmJObj.GetStringValue("PostName")
            };
            var list = postModule.GetPostListModule(query);
            return ApiResult.Success(data: list);
        }


        /// <summary>
        /// 根据部门编号获取岗位列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public ApiResult GetDeptPostList()
        {
            var query = new RB_Post_ViewModel()
            {
                Group_Id = base.UserInfo.Group_Id,
                QDeptIds = base.ParmJObj.GetStringValue("QDeptIds")
            };
            var list = postModule.GetDeptPostListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 添加修改岗位
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetPost()
        {
            var extModel = Common.Plugin.JsonHelper.DeserializeObject<RB_Post_ViewModel>(RequestParm.Msg.ToString());
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = base.UserInfo.Group_Id;
            extModel.Status = Common.Enum.DateStateEnum.Normal;
            bool flag = postModule.SetPostModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取部门实体类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetPost()
        {
            var PostId = base.ParmJObj.GetInt("PostId", 0);
            var extModel = postModule.GetPostModule(PostId);
            return ApiResult.Success(data: extModel);
        }

        /// <summary>
        /// 修改岗位状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemovePost()
        {
            var PostId = base.ParmJObj.GetInt("PostId", 0);
            int Status = base.ParmJObj.GetInt("Status");
            var flag = postModule.RemovePostModule(PostId, Status);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }
        #endregion

        #region 员工查询

        /// <summary>
        /// 获取岗位列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetEmployeeList()
        {
            var query = new Employee_ViewModel()
            {
                School_Id = -1,
                Account = base.ParmJObj.GetStringValue("Account"),
                AccountType = (AccountTypeEnum)base.ParmJObj.GetInt("AccountType"),
                Id = base.ParmJObj.GetInt("Id"),
                AccountId = base.ParmJObj.GetInt("AccountId"),
                Post_Id = base.ParmJObj.GetInt("Post_Id"),
                QPostIds = base.ParmJObj.GetStringValue("QPostIds"),
                Dept_Id = base.ParmJObj.GetInt("Dept_Id"),
                QDeptIds = base.ParmJObj.GetStringValue("QDeptIds"),
                EmployeeName = base.ParmJObj.GetStringValue("EmployeeName"),//姓名
                AccountTypeStr = base.ParmJObj.GetStringValue("AccountTypeStr"),//人员类型【逗号分割】
                IsLeave = base.ParmJObj.GetInt("IsLeave"),
                UserRole = (UserRoleEnum)base.ParmJObj.GetInt("UserRole"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var list = employeeModule.GetEmployeeListModule(query);
            return ApiResult.Success(data: list?.Select(qitem => new
            {
                qitem.Id,
                qitem.Account,
                qitem.Group_Id,
                qitem.GroupName,
                qitem.School_Id,
                qitem.SchoolName,
                qitem.EmployeeName,
                qitem.UserIcon,
                qitem.Dept_Id,
                qitem.DeptName,
                qitem.Post_Id,
                qitem.PostName
            }));
        }

        /// <summary>
        /// 获取部门员工树形列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetEmployeeAddrBook()
        {
            var query = new RB_Department_ViewModel()
            {
                Group_Id = base.UserInfo.Group_Id,
                School_Id = base.ParmJObj.GetInt("School_Id")
            };
            var list = departmentModule.GetDepartmentTreeModule(query, isQueryEmployee: true);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取通讯录token
        /// </summary>
        /// <param name="Group_Id"></param>
        /// <param name="configmodel"></param>
        /// <returns></returns>
        private string GetEmployeeToken(int Group_Id, Model.ViewModel.WeChat.RB_WeChat_Config_ViewModel configmodel)
        {
            string token = WeChatReidsCache.GetToken(Cache.CacheKey.QYWeChat_TelToken_Key + Group_Id);
            if (string.IsNullOrEmpty(token))
            {
                var TelToken = ThirdCore.QYWinXin.QYWeiXinHelper.GetToken(configmodel.WX_CorpId, configmodel.Employee_Secret);
                if (TelToken.errcode == Senparc.Weixin.ReturnCode_Work.请求成功)
                {
                    WeChatReidsCache.TokenSet(Cache.CacheKey.QYWeChat_TelToken_Key + Group_Id, TelToken.access_token, TelToken.expires_in - 1);
                    token = TelToken.access_token;
                }
                else
                {
                    LogHelper.Write("token获取失败 GetEmployeeToken");
                    return "";
                }
            }
            return token;
        }
        #endregion

        #region 枚举相列表

        /// <summary>
        /// 获取学历列表
        /// </summary>
        /// <returns></returns>
        public ApiResult GetEducationList()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(EducationEnum));
            list.Insert(0, new EnumItem()
            {
                Id = 0,
                Name = "不限"
            });
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取离职状态列表
        /// </summary>
        /// <returns></returns>
        public ApiResult GetLeaveStatus()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(LeaveStatusEnum));
            list.Insert(0, new EnumItem()
            {
                Id = 0,
                Name = "不限"
            });
            return ApiResult.Success(data: list);
        }
        #endregion

        #region 获取用户修改日志

        /// <summary>
        /// 获取岗位列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetEmpChangeLog()
        {
            var query = new RB_User_ChangeLog_ViewModel()
            {
                AccountType = (AccountTypeEnum)base.ParmJObj.GetInt("AccountType"),
                SourceId = base.ParmJObj.GetInt("AccountId"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var list = userChangeLogModule.GetUserChangeLogListModule(query);
            return ApiResult.Success(data: list);
        }
        #endregion

        #region 调整员工类型

        /// <summary>
        /// 调整员工类型
        /// </summary>
        /// <returns></returns>
        public ApiResult SetEmployeeType()
        {
            var AccountId = base.ParmJObj.GetInt("AccountId");
            var AccountType = (AccountTypeEnum)base.ParmJObj.GetInt("AccountType");
            var Remark = base.ParmJObj.GetStringValue("Remark");
            var targetAccountType = (AccountTypeEnum)base.ParmJObj.GetInt("TargetAccountType");
            if (AccountId <= 0 || base.ParmJObj.GetInt("AccountType") <= 0)
            {
                return ApiResult.ParamIsNull(message: "请选择用户");
            }
            if (base.ParmJObj.GetInt("TargetAccountType") <= 0)
            {
                return ApiResult.ParamIsNull(message: "请选择用户目标职能!");
            }
            var flag = managerModule.SetEmployeeTypeModule(targetAccountType, AccountId, AccountType, Remark, base.UserInfo);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        #endregion

        #region 课程顾问跟进学员信息

        /// <summary>
        /// 获取课程顾问跟进配置分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentAdvisorConfigPage()
        {
            var pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_AdvisorConfig_Extend()
            {
                Group_Id = base.UserInfo.Group_Id,
                Name = base.ParmJObj.GetStringValue("Name")
            };
            var list=studentModule.GetStudentAdvisorConfigPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> result = new List<object>();
            foreach (var item in list)
            {
                string Name =   UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                result.Add(new
                {
                    item.Id,
                    item.Name,
                    item.Num,
                    item.Rate,
                    CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime),
                    CreateByName = Name
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = result;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取课程顾问跟进配置列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentAdvisorConfigList()
        {
            var query = new RB_Student_AdvisorConfig_Extend()
            {
                Group_Id = base.UserInfo.Group_Id,
                Name = base.ParmJObj.GetStringValue("Name")
            };
            var list = studentModule.GetStudentAdvisorConfigListModule(query); 
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 新增修改课程顾问配置
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentAdvisorConfig()
        {
            var model = new RB_Student_AdvisorConfig_Extend()
            {
                Id = base.ParmJObj.GetInt("Id"),
                Name = base.ParmJObj.GetStringValue("Name"),
                Num = base.ParmJObj.GetInt("Num"),
                Rate = base.ParmJObj.GetDecimal("Rate"),
            };
            model.CreateBy = base.UserInfo.Id;
            model.UpdateBy = base.UserInfo.Id;
            model.CreateTime = DateTime.Now;
            model.UpdateTime = DateTime.Now;
            model.Group_Id = base.UserInfo.Group_Id;
            model.Status = DateStateEnum.Normal;
            bool flag = studentModule.SetStudentAdvisorConfigModule(model);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号获取课程顾问配置信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentAdvisorConfig()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var extModel = studentModule.GetStudentAdvisorConfigModule(Id);
            return ApiResult.Success(data: extModel);
        }

        /// <summary>
        /// 根据编号删除课程顾问配置信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveStudentAdvisorConfig()
        {
            var Id = base.ParmJObj.GetInt("Id");
            bool flag = studentModule.RemoveStudentAdvisorConfigModule(Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取课程顾问跟进分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentAdvisorPage()
        {
            var pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_Advisor_Extend()
            {
                StuId = base.ParmJObj.GetInt("StuId"),
            };
            List<object> result = new List<object>();
            var list = studentModule.GetStudentAdvisorPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            foreach (var item in list)
            {
                string Name = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                result.Add(new
                {
                    item.Id,
                    item.StuId,
                    item.AdvisorStatusName,
                    item.AdvisorDate,
                    item.AdvisorRemark,
                    item.AdvisorStatus,
                    item.AdvisorRate,
                    CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime),
                    CreateByName = Name
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = result;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取课程顾问跟进列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentAdvisorList()
        {
            var query = new RB_Student_Advisor_Extend()
            {
                StuId = base.ParmJObj.GetInt("StuId"),
            };
            var list = studentModule.GetStudentAdvisorListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 新增修改课程顾问跟进记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentAdvisor()
        {
            var model = new RB_Student_Advisor_Extend()
            {
                Id = base.ParmJObj.GetInt("Id"),
                StuId = base.ParmJObj.GetInt("StuId"),
                AdvisorStatus = base.ParmJObj.GetInt("AdvisorStatus"),
                AdvisorDate = base.ParmJObj.GetStringValue("AdvisorDate"),
                AdvisorRemark = base.ParmJObj.GetStringValue("AdvisorRemark"),
                AdvisorExpectDate=base.ParmJObj.GetStringValue("AdvisorExpectDate"),
                AdvisorRate=base.ParmJObj.GetDecimal("AdvisorRate"),
            };
            model.CreateBy = base.UserInfo.Id;
            model.CreateTime = DateTime.Now;
            model.Group_Id = base.UserInfo.Group_Id;
            bool flag = studentModule.SetStudentAdvisorModule(model);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号获取课程顾问跟进记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentAdvisor()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var extModel = studentModule.GetStudentAdvisorModule(Id);
            return ApiResult.Success(data: extModel);
        }

        
        #endregion
    }
}