RoleCache.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using LeaRun.Application.Busines.BaseManage;
  2. using LeaRun.Application.Entity.BaseManage;
  3. using LeaRun.Cache.Factory;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. namespace LeaRun.Application.Cache
  8. {
  9. /// <summary>
  10. /// 版 本 6.1
  11. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  12. /// 创建人:佘赐雄
  13. /// 日 期:2016.3.4 9:56
  14. /// 描 述:角色信息缓存
  15. /// </summary>
  16. public class RoleCache
  17. {
  18. private RoleBLL busines = new RoleBLL();
  19. /// <summary>
  20. /// 角色列表
  21. /// </summary>
  22. /// <returns></returns>
  23. public IEnumerable<RoleEntity> GetList()
  24. {
  25. var cacheList = CacheFactory.Cache().GetCache<IEnumerable<RoleEntity>>(busines.cacheKey);
  26. if (cacheList == null)
  27. {
  28. var data = busines.GetList();
  29. CacheFactory.Cache().WriteCache(data, busines.cacheKey);
  30. return data;
  31. }
  32. else
  33. {
  34. return cacheList;
  35. }
  36. }
  37. /// <summary>
  38. /// 角色列表
  39. /// </summary>
  40. /// <param name="organizeId">公司Id</param>
  41. /// <returns></returns>
  42. public IEnumerable<RoleEntity> GetList(string organizeId)
  43. {
  44. var data = this.GetList();
  45. if (!string.IsNullOrEmpty(organizeId))
  46. {
  47. data = data.Where(t => t.OrganizeId == organizeId);
  48. }
  49. return data;
  50. }
  51. /// <summary>
  52. /// 角色实体
  53. /// </summary>
  54. /// <param name="roleId"></param>
  55. /// <returns></returns>
  56. public RoleEntity GetEntity(string roleId)
  57. {
  58. var data = this.GetList();
  59. if (!string.IsNullOrEmpty(roleId))
  60. {
  61. var d = data.Where(t => t.RoleId == roleId).ToList<RoleEntity>();
  62. if (d.Count > 0)
  63. {
  64. return d[0];
  65. }
  66. }
  67. return new RoleEntity();
  68. }
  69. }
  70. }