using Longbow.Cache; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; namespace Bootstrap.DataAccess { /// /// /// public class Group { public const string RetrieveGroupsDataKey = "GroupHelper-RetrieveGroups"; public const string RetrieveGroupsByUserIdDataKey = "GroupHelper-RetrieveGroupsByUserId"; public const string RetrieveGroupsByRoleIdDataKey = "GroupHelper-RetrieveGroupsByRoleId"; public const string RetrieveGroupsByUserNameDataKey = "BootstrapAdminGroupMiddleware-RetrieveGroupsByUserName"; /// /// 获得/设置 群组主键ID /// public int Id { get; set; } /// /// 获得/设置 群组名称 /// public string GroupName { get; set; } /// /// 获得/设置 群组描述 /// public string Description { get; set; } /// /// 获取/设置 用户群组关联状态 checked 标示已经关联 '' 标示未关联 /// public string Checked { get; set; } /// /// 查询所有群组信息 /// /// /// public virtual IEnumerable RetrieveGroups(int id = 0) => throw new NotImplementedException(); /// /// 删除群组信息 /// /// public virtual bool DeleteGroup(IEnumerable value) => throw new NotImplementedException(); /// /// 保存新建/更新的群组信息 /// /// /// public virtual bool SaveGroup(Group p) => throw new NotImplementedException(); /// /// 根据用户查询部门信息 /// /// /// public virtual IEnumerable RetrieveGroupsByUserId(int userId) => throw new NotImplementedException(); /// /// 保存用户部门关系 /// /// /// /// public virtual bool SaveGroupsByUserId(int id, IEnumerable groupIds) => throw new NotImplementedException(); /// /// 根据角色ID指派部门 /// /// /// public virtual IEnumerable RetrieveGroupsByRoleId(int roleId) => throw new NotImplementedException(); /// /// 根据角色ID以及选定的部门ID,保到角色部门表 /// /// /// /// public virtual bool SaveGroupsByRoleId(int id, IEnumerable groupIds) => throw new NotImplementedException(); /// /// /// /// /// /// public virtual IEnumerable RetrieveGroupsByUserName(string userName) { return CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => { var entities = new List(); var db = DBAccessManager.DBAccess; using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select g.GroupName, g.[Description] from Groups g inner join UserGroup ug on g.ID = ug.GroupID inner join Users u on ug.UserID = u.ID where UserName = @UserName")) { cmd.Parameters.Add(db.CreateParameter("@UserName", userName)); using (DbDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { entities.Add((string)reader[0]); } } } return entities; }, RetrieveGroupsByUserNameDataKey); } } }