using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Edu.Model.ViewModel.User;
using Edu.Model.Entity.User;
using Edu.Common.Enum.User;
using System.Text;
using Edu.Common.Enum;

namespace Edu.Repository.User
{
    /// <summary>
    /// 数据字典仓储层
    /// </summary>
    public partial class Rb_dictvalueRepository : BaseRepository<RB_Dictvalue>
    {
        /// <summary>
        /// 表名称
        /// </summary>
        public string TableName { get { return nameof(RB_Dictvalue); } }

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="where"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List<RB_Dictvalue_Extend> GetPageList(int pageIndex, int pageSize, RB_Dictvalue_Extend where, out long count)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(" SELECT * FROM {0} WHERE 1=1 ", TableName);
            sb.AppendFormat(" AND {0}={1} ", nameof(RB_Dictvalue_Extend.Status), (int)DateStateEnum.Normal);
            if (where != null)
            {
                if (where.RB_Group_id > 0)
                {
                    sb.AppendFormat(" AND {0}={1} ", nameof(RB_Dictvalue_Extend.RB_Group_id), where.RB_Group_id);
                }
                if (!string.IsNullOrEmpty(where.Content))
                {
                    sb.AppendFormat(" AND {0} LIKE '%{1}%' ", nameof(RB_Dictvalue_Extend.Name), where.Content.Trim());
                }
            }
            return GetPage<RB_Dictvalue_Extend>(pageIndex, pageSize, out count, sb.ToString()).ToList();
        }

        /// <summary>
        /// 获取条件下所有的字典
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public List<RB_Dictvalue_Extend> GetList(RB_Dictvalue_Extend where)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(" SELECT * FROM {0} WHERE 1=1 ", TableName);
            if (where != null)
            {
                if (where.Status >= 0)
                {
                    sb.AppendFormat(" AND {0}={1} ", nameof(RB_Dictvalue_Extend.Status), (int)where.Status);
                }
                if (!string.IsNullOrEmpty(where.Name))
                {
                    sb.AppendFormat(" AND {0}='{1}' ", nameof(RB_Dictvalue_Extend.Name), where.Name.Trim());
                }
                if (!string.IsNullOrEmpty(where.Code))
                {
                    sb.AppendFormat(" AND {0}='{1}' ", nameof(RB_Dictvalue_Extend.Code), where.Code.Trim());
                }
                if (where.RB_Group_id > 0)
                {
                    sb.AppendFormat(" AND {0}={1} ", nameof(RB_Dictvalue_Extend.RB_Group_id), where.RB_Group_id);
                }
                if (!string.IsNullOrEmpty(where.DictKey))
                {
                    sb.AppendFormat(" AND {0}='{1}' ", nameof(RB_Dictvalue_Extend.DictKey), where.DictKey.Trim());
                }
            }
            return Get<RB_Dictvalue_Extend>(sb.ToString()).ToList();
        }
    }
}