DepartmentCache.cs 2.0 KB

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