using Edu.Model.Entity.System;
using Edu.Model.ViewModel.System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Edu.Repository.System
{
    /// <summary>
    /// 角色功能权限表仓储层
    /// </summary>
    public class RB_Role_FunctionPermissionRepository : BaseRepository<RB_Role_FunctionPermission>
    {
        /// <summary>
        /// 获取角色功能菜单分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Role_FunctionPermission_ViewModel> GetRoleFunctionPermissionPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Role_FunctionPermission_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT * 
FROM RB_Role_FunctionPermission
WHERE 1=1
");
            if (query != null)
            {
                if (query.ID > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Role_FunctionPermission_ViewModel.ID), query.ID);
                }
                if (query.Action_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Role_FunctionPermission_ViewModel.Action_Id), query.Action_Id);
                }
                if (query.Role_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Role_FunctionPermission_ViewModel.Role_Id), query.Role_Id);
                }
            }
            return GetPage<RB_Role_FunctionPermission_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }

        /// <summary>
        /// 获取角色功能菜单列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Role_FunctionPermission_ViewModel> GetRoleFunctionPermissionListRepository(RB_Role_FunctionPermission_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT * 
FROM RB_Role_FunctionPermission
WHERE 1=1
");
            if (query != null)
            {
                if (query.ID > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Role_FunctionPermission_ViewModel.ID), query.ID);
                }
                if (query.Action_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Role_FunctionPermission_ViewModel.Action_Id), query.Action_Id);
                }
                if (query.Role_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Role_FunctionPermission_ViewModel.Role_Id), query.Role_Id);
                }
            }
            return Get<RB_Role_FunctionPermission_ViewModel>(builder.ToString()).ToList();
        }
    }
}
