RoadFlow2.1 临时演示

WorkFlowComment.cs 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Linq;
  5. namespace RoadFlow.Platform
  6. {
  7. public class WorkFlowComment
  8. {
  9. private RoadFlow.Data.Interface.IWorkFlowComment dataWorkFlowComment;
  10. public WorkFlowComment()
  11. {
  12. this.dataWorkFlowComment = Data.Factory.Factory.GetWorkFlowComment();
  13. }
  14. /// <summary>
  15. /// 新增
  16. /// </summary>
  17. public int Add(RoadFlow.Data.Model.WorkFlowComment model)
  18. {
  19. return dataWorkFlowComment.Add(model);
  20. }
  21. /// <summary>
  22. /// 更新
  23. /// </summary>
  24. public int Update(RoadFlow.Data.Model.WorkFlowComment model)
  25. {
  26. return dataWorkFlowComment.Update(model);
  27. }
  28. /// <summary>
  29. /// 查询所有记录
  30. /// </summary>
  31. public List<RoadFlow.Data.Model.WorkFlowComment> GetAll()
  32. {
  33. return dataWorkFlowComment.GetAll();
  34. }
  35. /// <summary>
  36. /// 查询单条记录
  37. /// </summary>
  38. public RoadFlow.Data.Model.WorkFlowComment Get(Guid id)
  39. {
  40. return dataWorkFlowComment.Get(id);
  41. }
  42. /// <summary>
  43. /// 删除
  44. /// </summary>
  45. public int Delete(Guid id)
  46. {
  47. return dataWorkFlowComment.Delete(id);
  48. }
  49. /// <summary>
  50. /// 查询记录条数
  51. /// </summary>
  52. public long GetCount()
  53. {
  54. return dataWorkFlowComment.GetCount();
  55. }
  56. /// <summary>
  57. /// 查询管理员的所有记录
  58. /// </summary>
  59. public List<RoadFlow.Data.Model.WorkFlowComment> GetManagerAll()
  60. {
  61. return dataWorkFlowComment.GetManagerAll();
  62. }
  63. /// <summary>
  64. /// 得到管理员类别的最大排序值
  65. /// </summary>
  66. /// <returns></returns>
  67. public int GetManagerMaxSort()
  68. {
  69. return dataWorkFlowComment.GetManagerMaxSort();
  70. }
  71. /// <summary>
  72. /// 得到一个人员的最大排序值
  73. /// </summary>
  74. /// <returns></returns>
  75. public int GetUserMaxSort(Guid userID)
  76. {
  77. return dataWorkFlowComment.GetUserMaxSort(userID);
  78. }
  79. /// <summary>
  80. /// 获得所有列表
  81. /// </summary>
  82. /// <param name="fromCache">是否从缓存获取</param>
  83. /// <returns></returns>
  84. private List<Tuple<Guid, string, int, int, List<Guid>>> GetAllList(bool fromCache = true)
  85. {
  86. string key = RoadFlow.Utility.Keys.CacheKeys.WorkFlowComments.ToString();
  87. if (!fromCache)
  88. {
  89. return getAllListByDb();
  90. }
  91. else
  92. {
  93. object obj = RoadFlow.Cache.IO.Opation.Get(key);
  94. if (obj == null)
  95. {
  96. var list = getAllListByDb();
  97. RoadFlow.Cache.IO.Opation.Set(key, list);
  98. return list;
  99. }
  100. else
  101. {
  102. return obj as List<Tuple<Guid, string, int, int, List<Guid>>>;
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// 从数据库获取所有意见列表
  108. /// </summary>
  109. /// <returns></returns>
  110. private List<Tuple<Guid, string, int, int, List<Guid>>> getAllListByDb()
  111. {
  112. var comments = GetAll();
  113. Organize borganize=new Organize();
  114. List<Tuple<Guid, string, int, int, List<Guid>>> list = new List<Tuple<Guid, string, int, int, List<Guid>>>();
  115. foreach (var comment in comments)
  116. {
  117. List<Guid> userList=new List<Guid>();
  118. if(!comment.MemberID.IsNullOrEmpty())
  119. {
  120. var users=borganize.GetAllUsers(comment.MemberID);
  121. foreach(var user in users)
  122. {
  123. userList.Add(user.ID);
  124. }
  125. }
  126. Tuple<Guid, string, int, int, List<Guid>> tuple = new Tuple<Guid, string, int, int, List<Guid>>(
  127. comment.ID,
  128. comment.Comment,
  129. comment.Type,
  130. comment.Sort,
  131. userList
  132. );
  133. list.Add(tuple);
  134. }
  135. return list;
  136. }
  137. /// <summary>
  138. /// 清除缓存
  139. /// </summary>
  140. public void ClearCache()
  141. {
  142. RoadFlow.Cache.IO.Opation.Remove(RoadFlow.Utility.Keys.CacheKeys.WorkFlowComments.ToString());
  143. }
  144. /// <summary>
  145. /// 刷新缓存
  146. /// </summary>
  147. public void RefreshCache()
  148. {
  149. RoadFlow.Cache.IO.Opation.Set(RoadFlow.Utility.Keys.CacheKeys.WorkFlowComments.ToString(), getAllListByDb());
  150. }
  151. /// <summary>
  152. /// 得到一个用户的所有意见
  153. /// </summary>
  154. /// <param name="userID"></param>
  155. /// <returns></returns>
  156. public List<string> GetListByUserID(Guid userID)
  157. {
  158. var list = GetAllList();
  159. var list1 = list.Where(p => p.Item5.Count == 0 || p.Item5.Exists(q => q == userID)).OrderByDescending(p => p.Item3).ThenBy(p => p.Item4);
  160. List<string> commentsList = new List<string>();
  161. foreach (var li in list1.OrderBy(p=>p.Item3).ThenBy(p=>p.Item4))
  162. {
  163. commentsList.Add(li.Item2);
  164. }
  165. return commentsList;
  166. }
  167. /// <summary>
  168. /// 得到一个用户的所有意见选择项
  169. /// </summary>
  170. /// <param name="userID"></param>
  171. /// <returns></returns>
  172. public string GetOptionsStringByUserID(Guid userID)
  173. {
  174. var list = GetListByUserID(userID);
  175. StringBuilder options = new StringBuilder();
  176. foreach (var li in list)
  177. {
  178. options.AppendFormat("<option value=\"{0}\">{0}</option>", li);
  179. }
  180. return options.ToString();
  181. }
  182. }
  183. }