RoadFlow2.1 临时演示

WorkFlowDelegation.cs 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Linq;
  5. namespace RoadFlow.Platform
  6. {
  7. public class WorkFlowDelegation
  8. {
  9. private RoadFlow.Data.Interface.IWorkFlowDelegation dataWorkFlowDelegation;
  10. private static string cacheKey = RoadFlow.Utility.Keys.CacheKeys.WorkFlowDelegation.ToString();
  11. public WorkFlowDelegation()
  12. {
  13. this.dataWorkFlowDelegation = Data.Factory.Factory.GetWorkFlowDelegation();
  14. }
  15. /// <summary>
  16. /// 新增
  17. /// </summary>
  18. public int Add(RoadFlow.Data.Model.WorkFlowDelegation model)
  19. {
  20. return dataWorkFlowDelegation.Add(model);
  21. }
  22. /// <summary>
  23. /// 更新
  24. /// </summary>
  25. public int Update(RoadFlow.Data.Model.WorkFlowDelegation model)
  26. {
  27. return dataWorkFlowDelegation.Update(model);
  28. }
  29. /// <summary>
  30. /// 查询所有记录
  31. /// </summary>
  32. public List<RoadFlow.Data.Model.WorkFlowDelegation> GetAll()
  33. {
  34. return dataWorkFlowDelegation.GetAll();
  35. }
  36. /// <summary>
  37. /// 查询单条记录
  38. /// </summary>
  39. public RoadFlow.Data.Model.WorkFlowDelegation Get(Guid id)
  40. {
  41. return dataWorkFlowDelegation.Get(id);
  42. }
  43. /// <summary>
  44. /// 删除
  45. /// </summary>
  46. public int Delete(Guid id)
  47. {
  48. return dataWorkFlowDelegation.Delete(id);
  49. }
  50. /// <summary>
  51. /// 查询记录条数
  52. /// </summary>
  53. public long GetCount()
  54. {
  55. return dataWorkFlowDelegation.GetCount();
  56. }
  57. /// <summary>
  58. /// 查询一个用户所有记录
  59. /// </summary>
  60. public List<RoadFlow.Data.Model.WorkFlowDelegation> GetByUserID(Guid userID)
  61. {
  62. return dataWorkFlowDelegation.GetByUserID(userID);
  63. }
  64. /// <summary>
  65. /// 得到一页数据
  66. /// </summary>
  67. /// <param name="pager"></param>
  68. /// <param name="query"></param>
  69. /// <param name="userID"></param>
  70. /// <param name="startTime"></param>
  71. /// <param name="endTime"></param>
  72. /// <returns></returns>
  73. public List<RoadFlow.Data.Model.WorkFlowDelegation> GetPagerData(out string pager, string query = "", string userID = "", string startTime = "", string endTime = "")
  74. {
  75. return dataWorkFlowDelegation.GetPagerData(out pager, query, userID, startTime, endTime);
  76. }
  77. /// <summary>
  78. /// 得到未过期的委托
  79. /// </summary>
  80. public List<RoadFlow.Data.Model.WorkFlowDelegation> GetNoExpiredList()
  81. {
  82. return dataWorkFlowDelegation.GetNoExpiredList();
  83. }
  84. /// <summary>
  85. /// 刷新缓存
  86. /// </summary>
  87. public void RefreshCache()
  88. {
  89. var list = GetNoExpiredList();
  90. RoadFlow.Cache.IO.Opation.Set(cacheKey, list);
  91. }
  92. /// <summary>
  93. /// 从缓存得到所有有效委托
  94. /// </summary>
  95. /// <returns></returns>
  96. public List<RoadFlow.Data.Model.WorkFlowDelegation> GetNoExpiredListFromCache()
  97. {
  98. object obj = RoadFlow.Cache.IO.Opation.Get(cacheKey);
  99. if (obj != null && obj is List<RoadFlow.Data.Model.WorkFlowDelegation>)
  100. {
  101. return obj as List<RoadFlow.Data.Model.WorkFlowDelegation>;
  102. }
  103. else
  104. {
  105. var list = GetNoExpiredList();
  106. RoadFlow.Cache.IO.Opation.Set(cacheKey, list);
  107. return list;
  108. }
  109. }
  110. /// <summary>
  111. /// 得到一个流程一个用户是否有委托
  112. /// </summary>
  113. /// <param name="flowID"></param>
  114. /// <param name="userID"></param>
  115. /// <returns>返回Guid.Empty表示没有委托</returns>
  116. public Guid GetFlowDelegationByUserID(Guid flowID, Guid userID)
  117. {
  118. var list = GetNoExpiredListFromCache();
  119. if (list.Count == 0)
  120. {
  121. return Guid.Empty;
  122. }
  123. Guid toUserID = Guid.Empty;
  124. var userList = list.Where(p => p.UserID == userID && (!p.FlowID.HasValue || p.FlowID.Value == Guid.Empty || p.FlowID.Value == flowID) && p.EndTime >= RoadFlow.Utility.DateTimeNew.Now);
  125. if (userList.Count() == 0)
  126. {
  127. toUserID = Guid.Empty;
  128. }
  129. else
  130. {
  131. toUserID = userList.OrderByDescending(p => p.WriteTime).First().ToUserID;
  132. }
  133. return getFlowDelegationByUserID1(flowID, toUserID, list);
  134. }
  135. private Guid getFlowDelegationByUserID1(Guid flowID, Guid userID, List<RoadFlow.Data.Model.WorkFlowDelegation> list)
  136. {
  137. var userList = list.Where(p => p.UserID == userID && (!p.FlowID.HasValue || p.FlowID.Value == Guid.Empty || p.FlowID.Value == flowID) && p.EndTime >= RoadFlow.Utility.DateTimeNew.Now);
  138. if (userList.Count() == 0)
  139. {
  140. return userID;
  141. }
  142. else
  143. {
  144. userID = userList.OrderByDescending(p => p.WriteTime).First().ToUserID;
  145. getFlowDelegationByUserID1(flowID, userID, list);
  146. }
  147. return Guid.Empty;
  148. }
  149. }
  150. }