using System;
using System.Collections.Generic;
using Edu.Model.Public;
using Edu.Repository.Public;
using VT.FW.DB;

namespace Edu.Module.Public
{
    /// <summary>
    /// 公共处理类
    /// </summary>
    public class PublicModule
    {
        /// <summary>
        /// 上传配置仓储层对象
        /// </summary>
        private readonly RB_File_StoreRepository storeRepository = new RB_File_StoreRepository();

        #region 上传设置
        /// <summary>
        /// 获取上传存储信息
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_File_Store> GetFileStoreList(RB_File_Store query)
        {
            return storeRepository.GetListRepository(query);
        }


        /// <summary>
        /// 新增/修改存储位置
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddOrUpdateFileStore(RB_File_Store model)
        {
            bool result;
            int id;
            if (model.ID == 0)
            {
                id = storeRepository.Insert(model);
                result = id > 0;
            }
            else
            {
                id = model.ID;
                result = storeRepository.Update(model);
            }
            //判断当前的是否设置成默认没有
            if (model.IsDefault == 1 && result)//将其他的默认赋值成0
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>() { { nameof(RB_File_Store.IsDefault), 0 }, };
                List<WhereHelper> whereHelpers = new List<WhereHelper>()
                {
                    new WhereHelper(){ FiledName=nameof(RB_File_Store.Group_Id),FiledValue=model.Group_Id ,OperatorEnum=OperatorEnum.Equal},
                    new WhereHelper(){ FiledName=nameof(RB_File_Store.ID),FiledValue=id, OperatorEnum=OperatorEnum.NotEqual },
                };
                result = storeRepository.Update(fileds, whereHelpers);
            }
            return result;
        }
        #endregion

        #region 留学就业审核配置

        /// <summary>
        /// 获取留学就业审核配置
        /// </summary>
        /// <returns></returns>
        public List<object> GetStudyAbroadListModule()
        {
            List<object> list = new List<object>
            {
                new
                {
                    Id = Common.Config.StudyAbroadDirectorId,
                    AuditType = 1,
                    Name = "部门主管审核"
                },
                new
                {
                    Id = Common.Config.StudyAbroadManagerId,
                    AuditType = 2,
                    Name = "部门负责人审核"
                }
            };
            return list;
        }
        #endregion
    }
}
