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

namespace Edu.Repository.System
{
  public  class RB_Menu_InformationRepository:BaseRepository<RB_Menu_Information>
    {
        /// <summary>
        /// 根据where获取菜单列表
        /// </summary>
        /// <param name="dmodel"></param>
        /// <returns></returns>
        public List<RB_Menu_Information_ViewModel> GetList(RB_Menu_Information_ViewModel dmodel)
        {
            string where = $@" 1=1 and Rb_GroupId={dmodel.Group_Id}";
            if (dmodel.MenuId > 0)
            {
                where += " and " + nameof(RB_Menu_Information_ViewModel.MenuId) + "=" + dmodel.MenuId;
            }
            if (!string.IsNullOrWhiteSpace(dmodel.MenuIdStr))
            {
                where += " and " + nameof(RB_Menu_Information_ViewModel.MenuId) + " in(" + dmodel.MenuIdStr + ")";
            }
            if (dmodel.MsgType > 0)
            {
                where += " and " + nameof(RB_Menu_Information_ViewModel.MsgType) + "=" + dmodel.MsgType;
            }
            if (dmodel.EmployeeId > 0)
            {
                where += " and (" + nameof(RB_Menu_Information_ViewModel.EmployeeId) + "=" + dmodel.EmployeeId + " or EmployeeId=-1)";
            }
            if (dmodel.DepartmentId > 0)
            {
                where += " and (" + nameof(RB_Menu_Information_ViewModel.DepartmentId) + "=" + dmodel.DepartmentId + " or DepartmentId=-1)";
            }
            if (dmodel.SourceId > 0)
            {
                where += " and " + nameof(RB_Menu_Information_ViewModel.SourceId) + "=" + dmodel.SourceId;
            }
            if (dmodel.SourceType > 0)
            {
                where += " and " + nameof(RB_Menu_Information_ViewModel.SourceType) + "=" + dmodel.SourceType;
            }
            if (dmodel.School_Id >= 0)
            {
                where += " and " + nameof(RB_Menu_Information_ViewModel.School_Id) + "=" + dmodel.School_Id;
            }
            return Get<RB_Menu_Information_ViewModel>(" select * from RB_Menu_Information where" + where).ToList();
        }
    }
}
