You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

242 lines
8.1 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace Learun.Application.WorkFlow
  6. {
  7. /// <summary>
  8. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  9. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  10. /// 创建人:陈彬彬
  11. /// 日 期:2017.04.17
  12. /// 描 述:工作流实例
  13. /// </summary>
  14. public class WfProcessInstanceService : RepositoryFactory
  15. {
  16. #region 获取数据
  17. /// <summary>
  18. /// 获取流程实例
  19. /// </summary>
  20. /// <param name="keyValue">主键</param>
  21. /// <returns></returns>
  22. public WfProcessInstanceEntity GetEntity(string keyValue)
  23. {
  24. try
  25. {
  26. return this.BaseRepository().FindEntity<WfProcessInstanceEntity>(keyValue);
  27. }
  28. catch (Exception ex)
  29. {
  30. if (ex is ExceptionEx)
  31. {
  32. throw;
  33. }
  34. else
  35. {
  36. throw ExceptionEx.ThrowServiceException(ex);
  37. }
  38. }
  39. }
  40. /// <summary>
  41. /// 获取流程信息列表
  42. /// </summary>
  43. /// <param name="pagination">分页参数</param>
  44. /// <param name="queryJson">查询条件</param>
  45. /// <returns></returns>
  46. public IEnumerable<WfProcessInstanceEntity> GetPageList(Pagination pagination, string queryJson)
  47. {
  48. try
  49. {
  50. var expression = LinqExtensions.True<WfProcessInstanceEntity>();
  51. var queryParam = queryJson.ToJObject();
  52. // 分类
  53. if (!queryParam["categoryId"].IsEmpty()) // 1:未完成 2:已完成
  54. {
  55. if (queryParam["categoryId"].ToString() == "1")
  56. {
  57. expression = expression.And(t => t.F_IsFinished == 0);
  58. }
  59. else
  60. {
  61. expression = expression.And(t => t.F_IsFinished == 1);
  62. }
  63. }
  64. // 操作时间
  65. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  66. {
  67. DateTime startTime = queryParam["StartTime"].ToDate();
  68. DateTime endTime = queryParam["EndTime"].ToDate();
  69. expression = expression.And(t => t.F_CreateDate >= startTime && t.F_CreateDate <= endTime);
  70. }
  71. // 关键字
  72. if (!queryParam["keyword"].IsEmpty())
  73. {
  74. string keyword = queryParam["keyword"].ToString();
  75. expression = expression.And(t => t.F_ProcessName.Contains(keyword) || t.F_SchemeName.Contains(keyword));
  76. }
  77. return this.BaseRepository().FindList<WfProcessInstanceEntity>(expression, pagination);
  78. }
  79. catch (Exception ex)
  80. {
  81. if (ex is ExceptionEx)
  82. {
  83. throw;
  84. }
  85. else
  86. {
  87. throw ExceptionEx.ThrowServiceException(ex);
  88. }
  89. }
  90. }
  91. /// <summary>
  92. /// 获取我的流程信息列表
  93. /// </summary>
  94. /// <param name="userId">用户主键</param>
  95. /// <param name="pagination">分页参数</param>
  96. /// <param name="queryJson">查询条件</param>
  97. /// <returns></returns>
  98. public IEnumerable<WfProcessInstanceEntity> GetMyPageList(string userId, Pagination pagination, string queryJson)
  99. {
  100. try
  101. {
  102. var expression = LinqExtensions.True<WfProcessInstanceEntity>();
  103. var queryParam = queryJson.ToJObject();
  104. expression = expression.And(t => t.F_CreateUserId == userId);
  105. // 操作时间
  106. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  107. {
  108. DateTime startTime = queryParam["StartTime"].ToDate();
  109. DateTime endTime = queryParam["EndTime"].ToDate();
  110. expression = expression.And(t => t.F_CreateDate >= startTime && t.F_CreateDate <= endTime);
  111. }
  112. // 关键字
  113. if (!queryParam["keyword"].IsEmpty())
  114. {
  115. string keyword = queryParam["keyword"].ToString();
  116. expression = expression.And(t => t.F_ProcessName.Contains(keyword) || t.F_SchemeName.Contains(keyword));
  117. }
  118. return this.BaseRepository().FindList<WfProcessInstanceEntity>(expression, pagination);
  119. }
  120. catch (Exception ex)
  121. {
  122. if (ex is ExceptionEx)
  123. {
  124. throw;
  125. }
  126. else
  127. {
  128. throw ExceptionEx.ThrowServiceException(ex);
  129. }
  130. }
  131. }
  132. /// <summary>
  133. /// 获取流程实例信息(正在运行的)
  134. /// </summary>
  135. /// <param name="processId">实例主键</param>
  136. /// <returns></returns>
  137. public IEnumerable<WfProcessInstanceEntity> GetListByProcessIds(string processIds)
  138. {
  139. try
  140. {
  141. return this.BaseRepository().FindList<WfProcessInstanceEntity>(t => processIds.Contains(t.F_Id) && t.F_IsFinished == 0 && t.F_EnabledMark == 1);
  142. }
  143. catch (Exception ex)
  144. {
  145. if (ex is ExceptionEx)
  146. {
  147. throw;
  148. }
  149. else
  150. {
  151. throw ExceptionEx.ThrowServiceException(ex);
  152. }
  153. }
  154. }
  155. /// <summary>
  156. /// 获取全部流程实例
  157. /// </summary>
  158. /// <param name="processIds"></param>
  159. /// <returns></returns>
  160. public IEnumerable<WfProcessInstanceEntity> GetListByAllProcessIds(string processIds)
  161. {
  162. try
  163. {
  164. return this.BaseRepository().FindList<WfProcessInstanceEntity>(t => processIds.Contains(t.F_Id));
  165. }
  166. catch (Exception ex)
  167. {
  168. if (ex is ExceptionEx)
  169. {
  170. throw;
  171. }
  172. else
  173. {
  174. throw ExceptionEx.ThrowServiceException(ex);
  175. }
  176. }
  177. }
  178. #endregion
  179. #region 提交数据
  180. /// <summary>
  181. /// 删除流程实例
  182. /// </summary>
  183. /// <param name="keyValue"></param>
  184. public void DeleteEntity(string keyValue)
  185. {
  186. try
  187. {
  188. this.BaseRepository().Delete<WfProcessInstanceEntity>(t => t.F_Id == keyValue);
  189. }
  190. catch (Exception ex)
  191. {
  192. if (ex is ExceptionEx)
  193. {
  194. throw;
  195. }
  196. else
  197. {
  198. throw ExceptionEx.ThrowServiceException(ex);
  199. }
  200. }
  201. }
  202. /// <summary>
  203. /// 保存流程实例
  204. /// </summary>
  205. /// <param name="keyValue">主键</param>
  206. /// <param name="entity">实体</param>
  207. public void SaveEntity(string keyValue, WfProcessInstanceEntity entity)
  208. {
  209. try
  210. {
  211. if (string.IsNullOrEmpty(keyValue))
  212. {
  213. entity.Create();
  214. this.BaseRepository().Insert(entity);
  215. }
  216. else
  217. {
  218. entity.Modify(keyValue);
  219. this.BaseRepository().Update(entity);
  220. }
  221. }
  222. catch (Exception ex)
  223. {
  224. if (ex is ExceptionEx)
  225. {
  226. throw;
  227. }
  228. else
  229. {
  230. throw ExceptionEx.ThrowServiceException(ex);
  231. }
  232. }
  233. }
  234. #endregion
  235. }
  236. }