using Edu.Cache.User;
using Edu.Common.API;
using Edu.Common.Enum.User;
using Edu.Common.Plugin;
using Edu.Model.Entity.System;
using Edu.Model.ViewModel.Customer;
using Edu.Model.ViewModel.System;
using Edu.Model.ViewModel.User;
using Edu.Module.Customer;
using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Edu.WebApi.Controllers.Customer
{
    [Route("api/[controller]/[action]")]
    [ApiExceptionFilter]
    [ApiController]
    [EnableCors("AllowCors")]
    public class CustomerStudentController : BaseController
    {
        /// <summary>
        /// 客户学员处理类对象
        /// </summary>
        private readonly CustomerStudentModule customerStudentModule = new CustomerStudentModule();

        /// <summary>
        /// 学员约访分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentAppointmentPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_Appointment_Extend()
            {
                StuId = base.ParmJObj.GetInt("StuId"),
                Id=base.ParmJObj.GetInt("Id"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var data = customerStudentModule.GetStudentAppointmentPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                string CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                list.Add(new
                {
                    item.Id,
                    item.StuId,
                    item.AppointmentPoint,
                    AppointmentTime=Common.ConvertHelper.FormatTime(item.AppointmentTime),
                    item.Remark,
                    item.Feedback,
                    CreateTime = Common.ConvertHelper.FormatTimeStr2(item.CreateTime),
                    CreateByName,
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }


        /// <summary>
        /// 添加修改约访
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentAppointment()
        {
            var extModel = new RB_Student_Appointment_Extend()
            {
                Id = base.ParmJObj.GetInt("Id"),
                StuId = base.ParmJObj.GetInt("StuId"),
                AppointmentPoint = base.ParmJObj.GetStringValue("AppointmentPoint"),
                AppointmentTime = base.ParmJObj.GetDateTime("AppointmentTime"),
                Remark = base.ParmJObj.GetStringValue("Remark"),
            };
            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 = customerStudentModule.SetStudentAppointmentModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 新增修改约访反馈
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentAppointmentFeedBack()
        {
            var Id = base.ParmJObj.GetInt("Id");
            string Feedback = base.ParmJObj.GetStringValue("Feedback");
            bool flag = customerStudentModule.SetStudentAppointmentFeedBackModule(Feedback, Id, base.UserInfo.Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号获取约访
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentAppointment()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var model = customerStudentModule.GetStudentAppointmentModule(Id);
            return ApiResult.Success(data: model);
        }

        /// <summary>
        /// 根据编号删除学员约访
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveStudentAppointment()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var model = customerStudentModule.RemoveStudentAppointmentModule(Id,base.UserInfo.Id);
            return ApiResult.Success(data: model);
        }

        /// <summary>
        /// 学员跟进分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentFollowPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_Follow_Extend()
            {
                StuId = base.ParmJObj.GetInt("StuId"),
                STime = base.ParmJObj.GetStringValue("STime"),
                ETime = base.ParmJObj.GetStringValue("ETime"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var data = customerStudentModule.GetStudentFollowPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                string CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                list.Add(new
                {
                    item.Id,
                    item.StuId,
                    item.Remark,
                    item.CreateBy,
                    CreateTime = Common.ConvertHelper.FormatTimeStr2(item.CreateTime),
                    CreateByName,
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 新增修改学员跟进
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentFollow()
        {
            var extModel = new RB_Student_Follow_Extend()
            {
                Id = base.ParmJObj.GetInt("Id"),
                StuId = base.ParmJObj.GetInt("StuId"),
                Remark = base.ParmJObj.GetStringValue("Remark"),
            };
            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 = customerStudentModule.SetStudentFollowModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号获取跟进信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentFollow()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var model = customerStudentModule.GetStudentFollowModule(Id);
            return ApiResult.Success(data: model);
        }

        /// <summary>
        /// 根据编号删除学员跟进信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveStudentFollow()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var model = customerStudentModule.RemoveStudentFollowModule(Id,base.UserInfo.Id);
            return ApiResult.Success(data: model);
        }

        /// <summary>
        /// 学员到访分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentVisitPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_Visit_Extend()
            {
                StuId = base.ParmJObj.GetInt("StuId"),
                Id=base.ParmJObj.GetInt("Id"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var data = customerStudentModule.GetStudentVisitPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                string CreateByName = "";
                if (item.CreateBy > 0)
                {
                    CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                }
                list.Add(new
                {
                    item.Id,
                    item.StuId,
                    item.SchoolName,
                    item.ReceptionPersionName,
                    item.Remark,
                    item.Feedback,
                    CreateTime = Common.ConvertHelper.FormatTimeStr2(item.CreateTime),
                    CreateByName,
                    item.IsVisit,
                    item.IsVisitStr,
                    item.VisitTime,
                    Date = Common.ConvertHelper.FormatDate(item.Date),
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 新增修改学员到访
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentVisit()
        {
            var extModel = new RB_Student_Visit_Extend()
            {
                Id = base.ParmJObj.GetInt("Id"),
                StuId = base.ParmJObj.GetInt("StuId"),
                School_Id=base.ParmJObj.GetInt("School_Id"),
                Date=base.ParmJObj.GetDateTime("Date"),
                VisitTime=base.ParmJObj.GetStringValue("VisitTime"),
                ReceptionPersion=base.ParmJObj.GetInt("ReceptionPersion"),
                Remark = base.ParmJObj.GetStringValue("Remark"),
            };
            if (extModel.ReceptionPersion <= 0)
            {
                extModel.ReceptionPersion = base.UserInfo.Id;
            }
            extModel.Status = Common.Enum.DateStateEnum.Normal;
            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 = customerStudentModule.SetStudentVisitModule(extModel);
            return flag ? ApiResult.Success(data:extModel) : ApiResult.Failed();
        }

        /// <summary>
        /// 新增修改到访反馈
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentVisitFeedback()
        {
            var Id = base.ParmJObj.GetInt("Id");
            int IsVisit = base.ParmJObj.GetInt("IsVisit");
            string Feedback = base.ParmJObj.GetStringValue("Feedback");
            bool flag = customerStudentModule.SetStudentVisitFeedbackModule(Feedback, Id, base.UserInfo.Id, IsVisit);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号获取到访信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentVisit()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var model = customerStudentModule.GetStudentVisitModule(Id);
            return ApiResult.Success(data: model);
        }

        /// <summary>
        /// 跟进编号删除学员到访信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveStudentVisit()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var model = customerStudentModule.RemoveStudentVisitModule(Id,base.UserInfo.Id);
            return ApiResult.Success(data: model);
        }


        /// <summary>
        /// 获取学员日志分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentLogPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_Log_Extend()
            {
                StuId = base.ParmJObj.GetInt("StuId"),
            };
            if (base.AppletCustomerInfo != null && base.AppletCustomerInfo.GroupId > 0)
            {
                query.Group_Id = base.AppletCustomerInfo.GroupId;
            }
            if (query.Group_Id <= 0)
            {
                query.Group_Id = base.UserInfo.Group_Id;
            }
           
            var data = customerStudentModule.GetStudentLogPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                string CreateByName = "";
                if (item.CreateType == 1)
                {
                    CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                }
                else
                {
                    CreateByName = UserReidsCache.GetAppletCustomerLoginInfo(item.CreateBy)?.CustomerName ?? "";
                }
                list.Add(new
                {
                    item.LogId,
                    item.StuId,
                    item.LogType,
                    LogTypeName=item.LogType.ToName(),
                    item.LogTitle,
                    item.LogContent,
                    item.CreateType,
                    CreateTypeStr=item.CreateType==1?"系统用户":"同业用户",
                    CreateTimeStr=Common.ConvertHelper.FormatTimeStr2(item.CreateTime),
                    CreateByName
                });

            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取学员关联订单分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStuOrderPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_OrderGuest_ViewModel()
            {
                Student_Id = base.ParmJObj.GetInt("StuId"),
            };
            var data = customerStudentModule.GetStuOrderGuestPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                list.Add(new
                {
                    item.OrderId,
                    item.Student_Id,
                    item.ClassName,
                    item.ClassNo,
                    item.TotalHours,
                    item.CompleteHours,
                    item.GuestName,
                    item.CourseName,
                    item.ClassScrollType
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取学员合同分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStuContractPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Student_OrderGuest_ViewModel()
            {
               Student_Id = base.ParmJObj.GetInt("StuId"),
            };
            var data = customerStudentModule.GetStuOrderGuestContractPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                list.Add(new
                {
                    item.OrderId,
                    item.Student_Id,
                    item.ClassName,
                    item.ClassNo,
                    item.TotalHours,
                    item.CompleteHours,
                    item.GuestName,
                    item.CourseName,
                    item.ContractId,
                    item.ContractNo,
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        ///  新增修改协助人员
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentAssist()
        {
            var StuId = base.ParmJObj.GetInt("StuId");
            var model = new RB_Student_Assist_Extend()
            {
                Id = ParmJObj.GetInt("Id"),
                AssistId = ParmJObj.GetInt("AssistId"),
                AssistType = (AssistTypeEnum)ParmJObj.GetInt("AssistType"),
                StuId = StuId,
                Status = Common.Enum.DateStateEnum.Normal
            };
            if (customerStudentModule.CheckAssistTypeExistsModule(model))
            {
                return ApiResult.Failed(message: string.Format("已存在【{0}】类型的协助人员!", model.AssistType.ToName()));
            }
            bool flag = customerStudentModule.SetStudentAssistModule(StuId, model, base.UserInfo.Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 批量添加课程顾问
        /// </summary>
        /// <returns></returns>
        public ApiResult SetStudentAssistBatch()
        {
            var stuIds = base.ParmJObj.GetStringValue("stuIds");
            var result = customerStudentModule.SetStudentAssistBatchModule(stuIds,base.UserInfo.Id);
            return result.result ? ApiResult.Success(message: result.msg) : ApiResult.Failed(message: result.msg);
        }

        /// <summary>
        /// 删除协同人员
        /// </summary>
        /// <returns></returns>
        public ApiResult RemoveStudentAssist()
        {
            int Id = base.ParmJObj.GetInt("Id");
            bool flag = customerStudentModule.RemoveStudentAssistModule(Id, base.UserInfo.Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        ///  获取协助人员列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentAssistList()
        {
            var StuId = base.ParmJObj.GetInt("StuId");
            var data = customerStudentModule.GeStudentAssistListModule(StuId);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                list.Add(new
                {
                    item.Id,
                    item.AssistId,
                    item.AssistType,
                    AssistTypeName = item.AssistType.ToName(),
                    item.AssistName,
                    CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime)
                });
            }
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取客户阶段列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStageList()
        {
            var query = new RB_Stage()
            {
                Group_Id = base.UserInfo.Group_Id
            };
            var list = customerStudentModule.GetStageListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取客户阶段下拉列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStageDropdownList()
        {
            var query = new RB_Stage()
            {
                Group_Id = base.UserInfo.Group_Id
            };
            var list = customerStudentModule.GetStageListModule(query);
            return ApiResult.Success(data: list.Select(qitem => new { qitem.Id, Name = qitem.StageName }));
        }

        /// <summary>
        /// 新增修改客户阶段
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStage()
        {
            var model = new RB_Stage()
            {
                Id = base.ParmJObj.GetInt("Id"),
                StageName=base.ParmJObj.GetStringValue("StageName"),
                No=base.ParmJObj.GetInt("No"),
            };
            if (model.No <= 0)
            {
                return ApiResult.Failed(message: "请填写排序编号!");
            }
            if (string.IsNullOrEmpty(model.StageName))
            {
                return ApiResult.Failed(message: "请填写阶段名称!");
            }
            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 = Common.Enum.DateStateEnum.Normal;
            bool flag = customerStudentModule.SetStageModule(model);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号删除客户阶段
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveStage()
        {
            var Id = base.ParmJObj.GetInt("Id");
            bool flag = customerStudentModule.RemodeStageModule(Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }


        /// <summary>
        /// 获取客户类型列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentTypeList()
        {
            var query = new RB_Student_Type_Extend()
            {
                Group_Id = base.UserInfo.Group_Id
            };
            var list = customerStudentModule.GetStudentTypeListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取客户类型下拉列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudentTypeDropdownList()
        {
            var query = new RB_Student_Type_Extend()
            {
                Group_Id = base.UserInfo.Group_Id
            };
            var list = customerStudentModule.GetStudentTypeListModule(query);
            return ApiResult.Success(data: list.Select(qitem => new { qitem.Id, qitem.Name }));
        }

        /// <summary>
        /// 新增修改客户类型
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudentType()
        {
            var model = new RB_Student_Type_Extend()
            {
                Id = base.ParmJObj.GetInt("Id"),
                Name = base.ParmJObj.GetStringValue("Name"),
                Info=base.ParmJObj.GetStringValue("Info"),
                No = base.ParmJObj.GetInt("No"),
            };
            if (model.No <= 0)
            {
                return ApiResult.Failed(message: "请填写排序编号!");
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                return ApiResult.Failed(message: "请填写类型名称!");
            }
            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 = Common.Enum.DateStateEnum.Normal;
            bool flag = customerStudentModule.SetStudentTypeModule(model);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号删除客户类型
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemodeStudentType()
        {
            var Id = base.ParmJObj.GetInt("Id");
            bool flag = customerStudentModule.RemodeStudentTypeModule(Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取学习目的分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetLearningGoalsPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_LearningGoals_Extend()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var data = customerStudentModule.GetLearningGoalsPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                string CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                list.Add(new
                {
                    item.Id,
                    item.Name,
                    CreateByName,
                    CreateTime = Common.ConvertHelper.FormatTime(item.CreateTime),
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取学习目的下拉列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetLearningGoalsList()
        {
            var query = new RB_LearningGoals_Extend()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var data = customerStudentModule.GetLearningGoalsListModule(query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                string CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                list.Add(new
                {
                    item.Id,
                    item.Name,
                    CreateByName,
                    CreateTime = Common.ConvertHelper.FormatTime(item.CreateTime),
                });
            }
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 新增修改学习目的
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetLearningGoals()
        {
            var extModel = new RB_LearningGoals_Extend()
            {
                Id=base.ParmJObj.GetInt("Id"),
                Name=base.ParmJObj.GetStringValue("Name"),
            };
            extModel.Group_Id = base.UserInfo.Group_Id;
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Status = Common.Enum.DateStateEnum.Normal;
            bool flag = customerStudentModule.SetLearningGoalsModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号获取学习目的详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetLearningGoals()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var model = customerStudentModule.GetLearningGoalsExtEntityModule(Id);
            return ApiResult.Success(data: model);
        }

        /// <summary>
        /// 根据编号删除学习目的详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveLearningGoals()
        {
            var Id = base.ParmJObj.GetInt("Id");
            bool flag = customerStudentModule.RemoveLearningGoalsModule(Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取渠道分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetChannelPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Channel_Extend()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var data = customerStudentModule.GetChannelPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                string CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                list.Add(new
                {
                    item.Id,
                    item.Name,
                    CreateByName,
                    item.StaticType,
                    item.StaticTypeList,
                    CreateTime = Common.ConvertHelper.FormatTime(item.CreateTime),
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取渠道下拉列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetChannelList()
        {
            var query = new RB_Channel_Extend()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var data = customerStudentModule.GetChannelListModule(query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                string CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                list.Add(new
                {
                    item.Id,
                    item.Name,
                    CreateByName,
                    item.StaticType,
                    item.StaticTypeList,
                    CreateTime = Common.ConvertHelper.FormatTime(item.CreateTime),
                });
            }
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 新增修改渠道
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetChannel()
        {
            var extModel = new RB_Channel_Extend()
            {
                Id = base.ParmJObj.GetInt("Id"),
                Name = base.ParmJObj.GetStringValue("Name"),
           
            };
            string staticTypes = base.ParmJObj.GetStringValue("StaticTypeList");
            List<string> Ids = new List<string>();
            if (!string.IsNullOrEmpty(staticTypes))
            {
                Ids = Common.Plugin.JsonHelper.DeserializeObject<List<string>>(staticTypes);
            }
            extModel.StaticType = string.Join(",", Ids);
            extModel.Group_Id = base.UserInfo.Group_Id;
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Status = Common.Enum.DateStateEnum.Normal;
            bool flag = customerStudentModule.SetChannelModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号获取渠道详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetChannel()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var model = customerStudentModule.GetChannelExtEntityModule(Id);
            return ApiResult.Success(data: model);
        }

        /// <summary>
        /// 根据编号删除渠道详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveChannel()
        {
            var Id = base.ParmJObj.GetInt("Id");
            bool flag = customerStudentModule.RemoveChannelModule(Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }


        /// <summary>
        /// 获取客户需求分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetNeedsPage()
        {
            var pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Needs_Extend()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var data = customerStudentModule.GetNeedsPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                string CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                list.Add(new
                {
                    item.Id,
                    item.Name,
                    CreateByName,
                    CreateTime = Common.ConvertHelper.FormatTime(item.CreateTime),
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = list;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取客户需求下拉列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetNeedsList()
        {
            var query = new RB_Needs_Extend()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var data = customerStudentModule.GetNeedsListModule(query);
            List<object> list = new List<object>();
            foreach (var item in data)
            {
                string CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
                list.Add(new
                {
                    item.Id,
                    item.Name,
                    CreateByName,
                    CreateTime = Common.ConvertHelper.FormatTime(item.CreateTime),
                });
            }
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 新增修改客户需求
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetNeeds()
        {
            var extModel = new RB_Needs_Extend()
            {
                Id = base.ParmJObj.GetInt("Id"),
                Name = base.ParmJObj.GetStringValue("Name"),
            };
            extModel.Group_Id = base.UserInfo.Group_Id;
            extModel.CreateBy = base.UserInfo.Id;
            extModel.CreateTime = DateTime.Now;
            extModel.UpdateBy = base.UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Status = Common.Enum.DateStateEnum.Normal;
            bool flag = customerStudentModule.SetNeedsModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号获取客户需求详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetNeeds()
        {
            var Id = base.ParmJObj.GetInt("Id");
            var model = customerStudentModule.GetNeedsExtEntityModule(Id);
            return ApiResult.Success(data: model);
        }

        /// <summary>
        /// 根据编号删除客户需求
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveNeeds()
        {
            var Id = base.ParmJObj.GetInt("Id");
            bool flag = customerStudentModule.RemoveNeedsModule(Id);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }
    }
}
