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.
 
 
 
 
 
 

206 lines
6.7 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 WfDelegateRuleService : RepositoryFactory
  15. {
  16. #region 获取数据
  17. /// <summary>
  18. /// 获取分页列表
  19. /// </summary>
  20. /// <param name="pagination">分页参数</param>
  21. /// <param name="keyword">关键字(被委托人)</param>
  22. /// <param name="userInfo">用户信息</param>
  23. /// <returns></returns>
  24. public IEnumerable<WfDelegateRuleEntity> GetPageList(Pagination pagination, string keyword, UserInfo userInfo)
  25. {
  26. try
  27. {
  28. var expression = LinqExtensions.True<WfDelegateRuleEntity>();
  29. if (!userInfo.isSystem)
  30. {
  31. string userId = userInfo.userId;
  32. expression = expression.And(t => t.F_CreateUserId == userId);
  33. }
  34. if (!string.IsNullOrEmpty(keyword))
  35. {
  36. expression = expression.And(t => t.F_ToUserName.Contains(keyword));
  37. }
  38. return this.BaseRepository().FindList<WfDelegateRuleEntity>(expression, pagination);
  39. }
  40. catch (Exception ex)
  41. {
  42. if (ex is ExceptionEx)
  43. {
  44. throw;
  45. }
  46. else
  47. {
  48. throw ExceptionEx.ThrowServiceException(ex);
  49. }
  50. }
  51. }
  52. /// <summary>
  53. /// 根据委托人获取委托记录
  54. /// </summary>
  55. /// <returns></returns>
  56. public IEnumerable<WfDelegateRuleEntity> GetList(UserInfo userInfo)
  57. {
  58. try
  59. {
  60. string userId = userInfo.userId;
  61. DateTime datatime = DateTime.Now;
  62. return this.BaseRepository().FindList<WfDelegateRuleEntity>(t => t.F_ToUserId == userId && t.F_BeginDate >= datatime && t.F_EndDate <= datatime);
  63. }
  64. catch (Exception ex)
  65. {
  66. if (ex is ExceptionEx)
  67. {
  68. throw;
  69. }
  70. else
  71. {
  72. throw ExceptionEx.ThrowServiceException(ex);
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 获取关联的模板数据
  78. /// </summary>
  79. /// <returns></returns>
  80. public IEnumerable<WfDelegateRuleRelationEntity> GetRelationList(string keyValue)
  81. {
  82. try
  83. {
  84. return this.BaseRepository().FindList<WfDelegateRuleRelationEntity>(t => t.F_DelegateRuleId == keyValue);
  85. }
  86. catch (Exception ex)
  87. {
  88. if (ex is ExceptionEx)
  89. {
  90. throw;
  91. }
  92. else
  93. {
  94. throw ExceptionEx.ThrowServiceException(ex);
  95. }
  96. }
  97. }
  98. #endregion
  99. #region 提交数据
  100. /// <summary>
  101. /// 删除实体
  102. /// </summary>
  103. /// <param name="keyValue">主键</param>
  104. public void DeleteEntity(string keyValue)
  105. {
  106. var db = this.BaseRepository().BeginTrans();
  107. try
  108. {
  109. db.Delete<WfDelegateRuleEntity>(t => t.F_Id == keyValue);
  110. db.Delete<WfDelegateRuleRelationEntity>(t => t.F_DelegateRuleId == keyValue);
  111. db.Commit();
  112. }
  113. catch (Exception ex)
  114. {
  115. db.Rollback();
  116. if (ex is ExceptionEx)
  117. {
  118. throw;
  119. }
  120. else
  121. {
  122. throw ExceptionEx.ThrowServiceException(ex);
  123. }
  124. }
  125. }
  126. /// <summary>
  127. /// 保存实体
  128. /// </summary>
  129. /// <param name="keyValue">主键</param>
  130. /// <param name="wfDelegateRuleEntity">实体数据</param>
  131. /// <param name="schemeInfoList">关联模板主键</param>
  132. public void SaveEntity(string keyValue, WfDelegateRuleEntity wfDelegateRuleEntity, string[] schemeInfoList)
  133. {
  134. var db = this.BaseRepository().BeginTrans();
  135. try
  136. {
  137. if (string.IsNullOrEmpty(keyValue))
  138. {
  139. wfDelegateRuleEntity.Create();
  140. db.Insert(wfDelegateRuleEntity);
  141. }
  142. else
  143. {
  144. wfDelegateRuleEntity.Modify(keyValue);
  145. db.Update(wfDelegateRuleEntity);
  146. db.Delete<WfDelegateRuleRelationEntity>(t => t.F_DelegateRuleId == keyValue);
  147. }
  148. foreach (string schemeInfoId in schemeInfoList)
  149. {
  150. WfDelegateRuleRelationEntity wfDelegateRuleRelationEntity = new WfDelegateRuleRelationEntity();
  151. wfDelegateRuleRelationEntity.Create();
  152. wfDelegateRuleRelationEntity.F_DelegateRuleId = wfDelegateRuleEntity.F_Id;
  153. wfDelegateRuleRelationEntity.F_SchemeInfoId = schemeInfoId;
  154. db.Insert(wfDelegateRuleRelationEntity);
  155. }
  156. db.Commit();
  157. }
  158. catch (Exception ex)
  159. {
  160. db.Rollback();
  161. if (ex is ExceptionEx)
  162. {
  163. throw;
  164. }
  165. else
  166. {
  167. throw ExceptionEx.ThrowServiceException(ex);
  168. }
  169. }
  170. }
  171. /// <summary>
  172. /// 更新委托规则状态信息
  173. /// </summary>
  174. /// <param name="keyValue">主键</param>
  175. /// <param name="state"></param>
  176. public void UpdateState(string keyValue, int state)
  177. {
  178. try
  179. {
  180. WfDelegateRuleEntity wfDelegateRuleEntity = new WfDelegateRuleEntity
  181. {
  182. F_Id = keyValue,
  183. F_EnabledMark = state
  184. };
  185. this.BaseRepository().Update(wfDelegateRuleEntity);
  186. }
  187. catch (Exception ex)
  188. {
  189. if (ex is ExceptionEx)
  190. {
  191. throw;
  192. }
  193. else
  194. {
  195. throw ExceptionEx.ThrowServiceException(ex);
  196. }
  197. }
  198. }
  199. #endregion
  200. }
  201. }