using Sugar.Enties;
using SqlSugar;
using System;
using System.Collections.Generic;
public class rolesManager : DbContext<roles>
{

    //当前类已经继承了 DbContext增、删、查、改的方法

    //这里面写的代码不会给覆盖,如果要重新生成请删除 rolesManager.cs
    /// <summary>
    /// 根据用户编号获取用户角色列表
    /// </summary>
    /// <param name="staffcode">用户编号</param>
    /// <returns></returns>
    public List<roles> GetRoles(string staffcode)
    {
        var sql = $"SELECT a.*   FROM Roles A inner JOIN UsersInRoles B ON A.roleid=B.roleid AND B.StaffCode='{staffcode}'";
        var list = Db.Ado.SqlQuery<roles>(sql);
        return list;
    }
    /// <summary>
    /// 根据用户编号获取打印权限
    /// </summary>
    /// <param name="staffcode"></param>
    /// <returns></returns>
    public List<printfile> GetPrintfiles(string staffcode)
    {
        var sql = $"SELECT a.*   FROM printfile a  inner JOIN usersinprint b on a.printid=b.printid  AND b.staffcode='{staffcode}'";
        var list = Db.Ado.SqlQuery<printfile>(sql);
        return list;
    }
    /// <summary>
    /// 根据用户编号获取用户消息语句权限
    /// </summary>
    /// <param name="staffcode"></param>
    /// <returns></returns>
    public List<msgtype> GetMsgtypes(string staffcode)
    {
        var sql = $"SELECT a.*   FROM msgtype a  inner JOIN usersinmsgtype b on a.msgtypeid=b.msgtypeid  AND b.staffcode='{staffcode}'";
        var list = Db.Ado.SqlQuery<msgtype>(sql);
        return list;
    }

    /// <summary>
    /// 根据角色ID获取用户功能模块权限
    /// </summary>
    /// <param name="staffcode"></param>
    /// <returns></returns>
    public List<dynamic> GetFuncs(string roleid)
    {
        var sql = $"SELECT b.*,a.RoleID FROM dbo.rolesInfuncs a INNER JOIN dbo.funcs b ON a.FuncID=b.FuncID WHERE a.RoleID='{roleid}'";
        var list = Db.Ado.SqlQuery<dynamic>(sql);
        return list;
    }

}
