using Edu.Cache.User;
using Edu.Common.API;
using Edu.Common.Enum.Sale;
using Edu.Common.Enum.StudyAbroad;
using Edu.Common.Plugin;
using Edu.Model.ViewModel.StudyAbroad;
using Edu.Module.StudyAbroad;
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.StudyAbroad
{
    /// <summary>
    /// 留学就业控制器相关
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiExceptionFilter]
    [ApiController]
    [EnableCors("AllowCors")]
    public class StudyAbroadController : BaseController
    {
        /// <summary>
        /// 留学就业处理对象
        /// </summary>
        private readonly StudyAbroadModule studyAbroadModule = AOP.AOPHelper.CreateAOPObject<StudyAbroadModule>();

        /// <summary>
        /// 供应商处理对象
        /// </summary>
        private readonly SupplierModule supplierModule = new SupplierModule();

        #region 供应商管理
        /// <summary>
        /// 获取供应商分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetSupplierPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Supplier_ViewModel()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
                Type = (SupplierTypeEnum)base.ParmJObj.GetInt("Type"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            List<object> result = new List<object>();
            var list = supplierModule.GetSupplierPageModule(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 ?? "";
                }
                result.Add(new
                {
                    item.Id,
                    item.Type,
                    TypeName = Common.Plugin.EnumHelper.ToName(item.Type),
                    item.Name,
                    item.LinkMan,
                    item.LinkTel,
                    item.LinkAddress,
                    item.Remark,
                    item.CreateByName,
                    item.CommissionType,
                    item.CommissionMoney,
                    item.ContractUrl,
                    CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime),
                    item.UpdateByName,
                    UpdateTimeStr = Common.ConvertHelper.FormatTime(item.UpdateTime),
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = result;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取供应商列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetSupplierList()
        {
            //是够添加默选项
            int IsAddDefault = base.ParmJObj.GetInt("IsAddDefault");
            var query = new RB_Supplier_ViewModel()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
                Type = (SupplierTypeEnum)base.ParmJObj.GetInt("Type"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            query.School_Id = base.UserInfo.School_Id;
            var list = supplierModule.GetSupplierListModule(query);
            if (list == null)
            {
                list = new List<RB_Supplier_ViewModel>();
            }
            if (IsAddDefault == 1)
            {
                list.Insert(0, new RB_Supplier_ViewModel()
                {
                    Id = 0,
                    Name = "请选择"
                });
            }
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 新增修改供应商
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetSupplier()
        {
            var extModel = new RB_Supplier_ViewModel()
            {
                Id = base.ParmJObj.GetInt("Id"),
                Type = (SupplierTypeEnum)base.ParmJObj.GetInt("Type"),
                Name = base.ParmJObj.GetStringValue("Name"),
                LinkMan = base.ParmJObj.GetStringValue("LinkMan"),
                LinkTel = base.ParmJObj.GetStringValue("LinkTel"),
                LinkAddress = base.ParmJObj.GetStringValue("LinkAddress"),
                Remark = base.ParmJObj.GetStringValue("Remark"),
                CreateBy = UserInfo.Id,
                CreateTime = DateTime.Now,
                UpdateBy = UserInfo.Id,
                UpdateTime = DateTime.Now,
                Group_Id = this.UserInfo.Group_Id,
                School_Id = base.ParmJObj.GetInt("School_Id"),
                CommissionMoney = base.ParmJObj.GetDecimal("CommissionMoney"),
                CommissionType = base.ParmJObj.GetInt("CommissionType"),
                ContractUrl = base.ParmJObj.GetStringValue("ContractUrl")
            };
            bool flag = supplierModule.SetSupplierModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取供应商信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetSupplier()
        {
            var Id = base.ParmJObj.GetInt("Id", 0);
            var extModel = supplierModule.GetSupplierModule(Id);
            var obj = new
            {
                Id = extModel?.Id ?? 0,
                Type = extModel?.Type ?? 0,
                Name = extModel?.Name ?? "",
                LinkMan = extModel?.LinkMan ?? "",
                LinkTel = extModel?.LinkTel ?? "",
                LinkAddress = extModel?.LinkAddress ?? "",
                Remark = extModel?.Remark ?? "",
                CommissionType = extModel?.CommissionType ?? 0,
                CommissionMoney = extModel?.CommissionMoney ?? 0,
                ContractUrl = extModel?.ContractUrl ?? ""
            };
            return ApiResult.Success(data: obj);
        }

        /// <summary>
        /// 更新供应商状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveSupplier()
        {
            var Id = base.ParmJObj.GetInt("Id", 0);
            var Status = base.ParmJObj.GetInt("Status", 0);
            var flag = supplierModule.RemoveSupplierModule(Id, Status);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取供应商类型列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetSupplierType()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(SupplierTypeEnum));
            return ApiResult.Success(data: list);
        }
        #endregion

        #region 留学就业管理
        [HttpPost]
        public ApiResult GetProductTypeList()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(StudyAbroadProductTypeEnum));
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 获取留学就业分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudyAbroadPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_StudyAbroad_ViewModel()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
                Type = base.ParmJObj.GetInt("Type"),
                SupplierId = base.ParmJObj.GetInt("SupplierId"),
                IsQPrice = base.ParmJObj.GetInt("IsQPrice"),
                AuditType = base.ParmJObj.GetInt("AuditType"),
                SaleState = (SaleStateEnum)base.ParmJObj.GetInt("SaleState"),
                AuditState = base.ParmJObj.GetInt("AuditState"),
                ProductType = (StudyAbroadProductTypeEnum)base.ParmJObj.GetInt("ProductType"),
                StudyCountryId = base.ParmJObj.GetInt("StudyCountryId"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            List<object> result = new List<object>();
            var list = studyAbroadModule.GetStudyAbroadPageModule(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 ?? "";
                }
                if (item.DirectorId > 0)
                {
                    item.DirectorName = UserReidsCache.GetUserLoginInfo(item.DirectorId)?.AccountName ?? "";
                }
                if (item.ManagerId > 0)
                {
                    item.ManagerName = UserReidsCache.GetUserLoginInfo(item.ManagerId)?.AccountName ?? "";
                }
                result.Add(new
                {
                    item.Id,
                    item.Type,
                    item.Name,
                    item.SupplierId,
                    item.SupplierName,
                    item.School_Id,
                    item.SchoolName,
                    SupplierContract = item.ContractUrl,
                    item.SuggestPrice,
                    item.SellPrice,
                    item.Remark,
                    item.SaleState,
                    SaleStateName = Common.Plugin.EnumHelper.ToName(item.SaleState),
                    item.CreateByName,
                    CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime),
                    item.UpdateByName,
                    UpdateTimeStr = Common.ConvertHelper.FormatTime(item.UpdateTime),
                    item.PreferentialList,
                    item.DirectorName,
                    item.DirectorId,
                    item.DirectorStatus,
                    item.DirectorOpinion,
                    DirectorAuditTime = Common.ConvertHelper.FormatTime(item.DirectorAuditTime),
                    item.ManagerName,
                    item.ManagerId,
                    item.ManagerStatus,
                    item.ManagerOpinion,
                    ManagerAuditTime = Common.ConvertHelper.FormatTime(item.ManagerAuditTime),
                    item.ImgCover,
                    item.Status,
                    item.ProductType,
                    item.ProductTypeName,
                    item.StudyFeature,
                    item.StudyCountryId,
                    item.StudyCountryName,
                    item.B2CRatio,
                    item.B2CReNewRatio,
                    item.B2BRebateRatio,
                    item.B2BRebateRatioType,
                    item.B2BRebateRatioValue,
                    item.B2BReNewRatio,
                    item.B2BReNewRatioType,
                    item.B2BReNewRatioValue,
                    item.SchoolRebateRatio,
                    item.SchoolRebateRatioType,
                    item.SchoolRebateRatioValue,
                    item.SchoolReNewRatio,
                    item.SchoolReNewRatioType,
                    item.SchoolReNewRatioValue,
                    item.TransIntroductceRatio,
                    item.TransIntroductceRatioType,
                    item.TransIntroductceRatioValue,
                    item.TransIntroductceReNewRatio,
                    item.TransIntroductceReNewRatioType,
                    item.TransIntroductceReNewRatioValue,
                    item.InnerRecommendRatio,
                    item.InnerRecommendRatioType,
                    item.InnerRecommendRatioValue,
                    item.InnerRecommendReNewRatio,
                    item.InnerRecommendReNewRatioType,
                    item.InnerRecommendReNewRatioValue,
                    item.CommissionReType,
                    item.B2CRbRatio,
                    item.B2CRbRatioType,
                    item.B2CRbRatioValue,
                    item.B2CRNRatio,
                    item.B2CRNRatioType,
                    item.B2CRNRatioValue
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = result;
            return ApiResult.Success(data: pageModel);
        }


        /// <summary>
        /// 获取留学就业审核分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudyAbroadAuditPage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_StudyAbroad_ViewModel()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
                Type = base.ParmJObj.GetInt("Type"),
                SupplierId = base.ParmJObj.GetInt("SupplierId"),
                IsQPrice = base.ParmJObj.GetInt("IsQPrice"),
                AuditType = base.ParmJObj.GetInt("AuditType"),
                AuditState = base.ParmJObj.GetInt("AuditState"),
            };
            query.AuditManId = base.UserInfo.Id;
            query.Group_Id = base.UserInfo.Group_Id;
            List<object> result = new List<object>();
            var list = studyAbroadModule.GetStudyAbroadAuditPageModule(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 ?? "";
                }
                if (item.DirectorId > 0)
                {
                    item.DirectorName = UserReidsCache.GetUserLoginInfo(item.DirectorId)?.AccountName ?? "";
                }
                if (item.ManagerId > 0)
                {
                    item.ManagerName = UserReidsCache.GetUserLoginInfo(item.ManagerId)?.AccountName ?? "";
                }
                result.Add(new
                {
                    item.Id,
                    item.Type,
                    item.Name,
                    item.SupplierId,
                    item.SupplierName,
                    SupplierContract = item.ContractUrl,
                    item.SuggestPrice,
                    item.SellPrice,
                    item.Remark,
                    item.SaleState,
                    SaleStateName = Common.Plugin.EnumHelper.ToName(item.SaleState),
                    item.CreateByName,
                    CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime),
                    item.UpdateByName,
                    UpdateTimeStr = Common.ConvertHelper.FormatTime(item.UpdateTime),
                    item.PreferentialList,
                    item.DirectorName,
                    item.DirectorId,
                    item.DirectorStatus,
                    item.DirectorOpinion,
                    DirectorAuditTime = Common.ConvertHelper.FormatTime(item.DirectorAuditTime),
                    item.ManagerName,
                    item.ManagerId,
                    item.ManagerStatus,
                    item.ManagerOpinion,
                    ManagerAuditTime = Common.ConvertHelper.FormatTime(item.ManagerAuditTime),
                    item.ImgCover,
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = result;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取留学就业列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudyAbroadList()
        {
            //是够添加默选项
            int IsAddDefault = base.ParmJObj.GetInt("IsAddDefault");
            var query = new RB_StudyAbroad_ViewModel()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
                Type = base.ParmJObj.GetInt("Type"),
                IsQPrice = base.ParmJObj.GetInt("IsQPrice"),
                SaleState = (SaleStateEnum)base.ParmJObj.GetInt("SaleState"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            query.School_Id = base.UserInfo.School_Id;
            var list = studyAbroadModule.GetStudyAbroadListModule(query);
            if (list == null)
            {
                list = new List<RB_StudyAbroad_ViewModel>();
            }
            if (IsAddDefault == 1)
            {
                list.Insert(0, new RB_StudyAbroad_ViewModel()
                {
                    Id = 0,
                    Name = "请选择"
                });
            }
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 新增修改留学就业产品
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudyAbroad()
        {
            var extModel = new RB_StudyAbroad_ViewModel()
            {
                Id = base.ParmJObj.GetInt("Id"),
                Type = base.ParmJObj.GetInt("Type"),
                Name = base.ParmJObj.GetStringValue("Name"),
                SupplierId = base.ParmJObj.GetInt("SupplierId"),
                SupplierContract = base.ParmJObj.GetStringValue("SupplierContract"),
                Remark = base.ParmJObj.GetStringValue("Remark"),
                CreateBy = UserInfo.Id,
                CreateTime = DateTime.Now,
                UpdateBy = UserInfo.Id,
                UpdateTime = DateTime.Now,
                Group_Id = this.UserInfo.Group_Id,
                School_Id = base.ParmJObj.GetInt("School_Id"),
                ImgCover = base.ParmJObj.GetStringValue("ImgCover"),
                ProductType = (StudyAbroadProductTypeEnum)base.ParmJObj.GetInt("ProductType"),
                StudyFeature = base.ParmJObj.GetStringValue("StudyFeature"),
                StudyCountryId = base.ParmJObj.GetInt("StudyCountryId"),
            };
            extModel.SaleState = Common.Enum.Sale.SaleStateEnum.NoPerfect;
            bool flag = studyAbroadModule.SetStudyAbroadModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 设置留学就业价格及返佣
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudyAbroadPrice()
        {
            var userInfo = base.UserInfo;
            RB_StudyAbroad_ViewModel demodel = JsonHelper.DeserializeObject<RB_StudyAbroad_ViewModel>(base.RequestParm.Msg.ToString());
            if (demodel.Id <= 0)
            {
                return ApiResult.ParamIsNull("请传递留学就业产品Id");
            }

            demodel.UpdateBy = userInfo.Id;
            demodel.UpdateTime = DateTime.Now;
            string msg = studyAbroadModule.SetStudyAbroadPrice(demodel);
            if (msg == "")
            {
                return ApiResult.Success();
            }
            else
            {
                return ApiResult.Failed(msg);
            }
        }

        /// <summary>
        /// 批量设置留学就业价格和优惠
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult BatchStudyAbroad()
        {
            var studyAbroadObj = JObject.Parse(base.ParmJObj.GetStringValue("studyAbroadObj"));
            var studyModel = new RB_StudyAbroad_ViewModel()
            {
                Id = studyAbroadObj.GetInt("Id"),
                SellPrice = studyAbroadObj.GetDecimal("SellPrice"),
                SuggestPrice = studyAbroadObj.GetDecimal("SuggestPrice"),
            };
            var priceObj = base.ParmJObj.GetStringValue("priceList");
            var list = new List<RB_StudyaBroad_Preferential_ViewModel>();
            try
            {
                list = Common.Plugin.JsonHelper.DeserializeObject<List<RB_StudyaBroad_Preferential_ViewModel>>(priceObj);
                if (list != null && list.Count > 0)
                {
                    foreach (var extModel in list)
                    {
                        extModel.CreateTime = DateTime.Now;
                        extModel.CreateBy = base.UserInfo.Id;
                        extModel.UpdateBy = base.UserInfo.Id;
                        extModel.UpdateTime = DateTime.Now;
                        extModel.Group_Id = this.UserInfo.Group_Id;
                        extModel.School_Id = this.UserInfo.School_Id;
                        extModel.StudyabroadId = studyModel.Id;
                    }
                }
            }
            catch (Exception ex)
            {
                Common.Plugin.LogHelper.Write(ex, "BatchStudyAbroad");
            }
            bool flag = studyAbroadModule.SetStudyAbroadPreferentialListModule(studyModel, list);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 根据编号获取留学就业产品信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudyAbroad()
        {
            var Id = base.ParmJObj.GetInt("Id", 0);
            int IsGetPrice = base.ParmJObj.GetInt("IsGetPrice");
            var extModel = studyAbroadModule.GetStudyAbroadModule(Id, IsGetPrice: IsGetPrice);
            if (extModel == null)
            {
                extModel = new RB_StudyAbroad_ViewModel();
            }
            var obj = new
            {
                extModel.Id,
                extModel.Type,
                extModel.Name,
                extModel.SupplierId,
                extModel.SupplierName,
                extModel.School_Id,
                SupplierContract = extModel.ContractUrl,
                extModel.SuggestPrice,
                extModel.SellPrice,
                extModel.Remark,
                extModel.SaleState,
                SaleStateName = Common.Plugin.EnumHelper.ToName(extModel.SaleState),
                extModel.CreateBy,
                CreateByName = UserReidsCache.GetUserLoginInfo(extModel.CreateBy)?.AccountName ?? "",
                CreateTimeStr = Common.ConvertHelper.FormatTime(extModel.CreateTime),
                extModel.DirectorId,
                extModel.DirectorStatus,
                extModel.DirectorOpinion,
                DirectorAuditTimeStr = Common.ConvertHelper.FormatTime(extModel.DirectorAuditTime),
                DirectorName = UserReidsCache.GetUserLoginInfo(extModel.DirectorId)?.AccountName ?? "",
                extModel.ManagerId,
                extModel.ManagerStatus,
                extModel.ManagerOpinion,
                ManagerAuditTimeStr = Common.ConvertHelper.FormatTime(extModel.ManagerAuditTime),
                ManagerName = UserReidsCache.GetUserLoginInfo(extModel.ManagerId)?.AccountName ?? "",
                extModel.PreferentialList,
                extModel.ImgCover,
                extModel.ProductType,
                extModel.StudyFeature,
                extModel.StudyCountryId,
                extModel.B2CRatio,
                extModel.B2CReNewRatio,
                extModel.B2BRebateRatio,
                extModel.B2BRebateRatioType,
                extModel.B2BRebateRatioValue,
                extModel.B2BReNewRatio,
                extModel.B2BReNewRatioType,
                extModel.B2BReNewRatioValue,
                extModel.SchoolRebateRatio,
                extModel.SchoolRebateRatioType,
                extModel.SchoolRebateRatioValue,
                extModel.SchoolReNewRatio,
                extModel.SchoolReNewRatioType,
                extModel.SchoolReNewRatioValue,
                extModel.TransIntroductceRatio,
                extModel.TransIntroductceRatioType,
                extModel.TransIntroductceRatioValue,
                extModel.TransIntroductceReNewRatio,
                extModel.TransIntroductceReNewRatioType,
                extModel.TransIntroductceReNewRatioValue,
                extModel.InnerRecommendRatio,
                extModel.InnerRecommendRatioType,
                extModel.InnerRecommendRatioValue,
                extModel.InnerRecommendReNewRatio,
                extModel.InnerRecommendReNewRatioType,
                extModel.InnerRecommendReNewRatioValue,
                extModel.CommissionReType,
                extModel.B2CRbRatio,
                extModel.B2CRbRatioType,
                extModel.B2CRbRatioValue,
                extModel.B2CRNRatio,
                extModel.B2CRNRatioType,
                extModel.B2CRNRatioValue
            };
            return ApiResult.Success(data: obj);
        }

        /// <summary>
        /// 更新留学就业产品状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveStudyAbroad()
        {
            var Id = base.ParmJObj.GetInt("Id", 0);
            var Status = base.ParmJObj.GetInt("Status", 0);
            var flag = studyAbroadModule.RemoveStudyAbroadModule(Id, Status, out string message);
            return flag ? ApiResult.Success(message: message) : ApiResult.Failed(message: message);
        }

        /// <summary>
        /// OP提交审核
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetSaleState()
        {
            var Id = base.ParmJObj.GetInt("Id", 0);
            var SaleState = base.ParmJObj.GetInt("SaleState", 0);
            var flag = studyAbroadModule.SetSaleStateModule(Id, SaleState);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 部门主管审核
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetDirectorAudit()
        {
            var extModel = new RB_StudyAbroad_ViewModel()
            {
                Id = base.ParmJObj.GetInt("Id"),
                DirectorOpinion = base.ParmJObj.GetStringValue("DirectorOpinion"),
                DirectorAuditTime = DateTime.Now,
                DirectorStatus = base.ParmJObj.GetInt("DirectorStatus"),
            };
            var flag = studyAbroadModule.SetDirectorAuditModule(extModel, base.UserInfo);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 部门负责人审核
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetManagerAudit()
        {
            var extModel = new RB_StudyAbroad_ViewModel()
            {
                Id = base.ParmJObj.GetInt("Id"),
                ManagerOpinion = base.ParmJObj.GetStringValue("ManagerOpinion"),
                DirectorAuditTime = DateTime.Now,
                ManagerStatus = base.ParmJObj.GetInt("ManagerStatus"),
            };
            var flag = studyAbroadModule.SetManagerAuditModule(extModel, base.UserInfo);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取留学就业销售状态列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetSaleStateList()
        {
            var list = Common.Plugin.EnumHelper.EnumToList(typeof(SaleStateEnum));
            return ApiResult.Success(data: list);
        }
        #endregion

        #region 留学就业类型配置

        /// <summary>
        /// 获取留学就业类型分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudyabroadTypePage()
        {
            var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var query = new RB_Studyabroad_Type_Extend()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
                Type = base.ParmJObj.GetInt("Type"),
                CountryId = base.ParmJObj.GetStringValue("CountryId"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            List<object> result = new List<object>();
            var list = studyAbroadModule.GetStudyabroadTypePageModule(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 ?? "";
                }

                result.Add(new
                {
                    item.Id,
                    item.Type,
                    item.Name,
                    item.CountryId,
                    item.CountryIdList,
                    item.CountryName,
                    item.CreateBy,
                    item.CreateByName,
                    item.UpdateBy,
                    item.UpdateByName,
                    CreateTimeStr = Common.ConvertHelper.FormatTime(item.CreateTime),
                    UpdateTimeStr = Common.ConvertHelper.FormatTime(item.UpdateTime),
                });
            }
            pageModel.Count = rowsCount;
            pageModel.PageData = result;
            return ApiResult.Success(data: pageModel);
        }

        /// <summary>
        /// 获取留学就业类型列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudyabroadTypeList()
        {
            //是够添加默选项
            int IsAddDefault = base.ParmJObj.GetInt("IsAddDefault");
            var query = new RB_Studyabroad_Type_Extend()
            {
                Name = base.ParmJObj.GetStringValue("Name"),
                Type = base.ParmJObj.GetInt("Type"),
                CountryId = base.ParmJObj.GetStringValue("CountryId"),
            };
            query.Group_Id = base.UserInfo.Group_Id;
            var list = studyAbroadModule.GetStudyabroadTypeListModule(query);
            return ApiResult.Success(data: list);
        }

        /// <summary>
        /// 新增修改留学就业产品
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetStudyabroadType()
        {
            var extModel = new RB_Studyabroad_Type_Extend()
            {
                Id = base.ParmJObj.GetInt("Id"),
                Type = base.ParmJObj.GetInt("Type"),
                Name = base.ParmJObj.GetStringValue("Name"),
                
                Num = base.ParmJObj.GetInt("Num"),
            };
            List<int> countryList = new List<int>();
            var idList = base.ParmJObj.GetStringValue("CountryIdList");
            if (!string.IsNullOrEmpty(idList))
            {
                countryList = JsonHelper.DeserializeObject<List<int>>(idList);
            }
            extModel.CountryId = string.Join(",", countryList);
            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.School_Id = base.UserInfo.School_Id;
            extModel.Status = Common.Enum.DateStateEnum.Normal;
            bool flag = studyAbroadModule.SetStudyabroadTypeModule(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }

        /// <summary>
        /// 获取留学就业类型实体详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetStudyabroadType()
        {
            var Id = base.ParmJObj.GetInt("Id", 0);
            var extModel = studyAbroadModule.GetStudyabroadTypeModule(Id);
            return ApiResult.Success(data: extModel);
        }

        /// <summary>
        /// 根据编号删除留学就业类型
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult RemoveStudyabroadType()
        {
            var Id = base.ParmJObj.GetInt("Id", 0);
            var extModel = studyAbroadModule.RemoveStudyabroadTypeModule(Id);
            return ApiResult.Success(data: extModel);
        }

        #endregion
    }
}
