BaseWorkflowServices.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Configuration;
  6. using System.Data.Entity;
  7. using Autofac;
  8. using EMIS.DataLogic.SystemDAL;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel.SystemView;
  11. using Bowin.Common.JSON;
  12. using EMIS.CommonLogic.PlugworkflowServices;
  13. using Bowin.Common.Linq.Entity;
  14. using Bowin.Common.Utility;
  15. using System.Linq.Expressions;
  16. using EMIS.Utility.FormValidate;
  17. using EMIS.DataLogic.Repositories;
  18. using EMIS.ViewModel.WorkflowManage;
  19. using EMIS.Utility;
  20. using EMIS.DataLogic.StudentManage.StudentProfile;
  21. namespace EMIS.CommonLogic.SystemServices
  22. {
  23. public class BaseWorkflowServices<TEntity> : BaseServices, IBaseWorkflowServices<TEntity> where TEntity : class
  24. {
  25. protected Func<List<Guid>, Guid, bool> DataRangeUserFunc { get; set; }
  26. public Lazy<IWorkflowServices> WorkflowServices { get; set; }
  27. public StudentDAL StudentDAL { get; set; }
  28. private string tableName { get; set; }
  29. /// <summary>
  30. ///
  31. /// </summary>
  32. public BaseWorkflowServices()
  33. {
  34. tableName = typeof(TEntity).Name;
  35. var scope = AutofacHelper.RequestLifetimeScope;
  36. StudentDAL = scope.Resolve<StudentDAL>();
  37. }
  38. /// <summary>
  39. /// 查询对应的接入流程表开始流程环节的Pid(对应的流程环节Pid)
  40. /// </summary>
  41. /// <returns></returns>
  42. public int? GetStartStatus()
  43. {
  44. return WorkflowServices.Value.GetStartStatus(tableName);
  45. }
  46. /// <summary>
  47. /// 查询对应的接入流程表已退回流程环节Pid(注:不包含开始环节、结束环节且为[BP]标识)
  48. /// </summary>
  49. /// <returns></returns>
  50. public int? GetSendBackStatus()
  51. {
  52. return WorkflowServices.Value.GetSendBackStatus(tableName);
  53. }
  54. /// <summary>
  55. /// 查询对应的接入流程表已通过流程环节Pid(注:不包含开始环节、结束环节且为[PASS]标识)
  56. /// </summary>
  57. /// <returns></returns>
  58. public int? GetPassNoEndStatus()
  59. {
  60. return WorkflowServices.Value.GetPassNoEndStatus(tableName);
  61. }
  62. /// <summary>
  63. /// 查询对应的结束流程环节Pid
  64. /// </summary>
  65. /// <returns></returns>
  66. public List<int?> GetEndStatus()
  67. {
  68. return WorkflowServices.Value.GetEndStatus(tableName);
  69. }
  70. /// <summary>
  71. /// 查询对应的结束流程环节且正常结束的流程环节Pid(注:结束环节且不为[BP]标识的)
  72. /// </summary>
  73. /// <returns></returns>
  74. public int? GetCorrectEndStatus()
  75. {
  76. return WorkflowServices.Value.GetCorrectEndStatus(tableName);
  77. }
  78. /// <summary>
  79. /// 查询对应的接入流程表非正常结束的流程环节Pid(注:通常为结束环节且为[BP]标识的)
  80. /// </summary>
  81. /// <returns></returns>
  82. public List<int?> GetBackpointStatus()
  83. {
  84. return WorkflowServices.Value.GetBackpointStatus(tableName);
  85. }
  86. /// <summary>
  87. /// 查询对应的接入流程表中开始环节、审核流程环节Pid(注:不包含结束、非正常[BP]结束环节)
  88. /// </summary>
  89. /// <returns></returns>
  90. public List<int?> GetStartApproveStatusList()
  91. {
  92. return WorkflowServices.Value.GetStartApproveStatusList(tableName);
  93. }
  94. /// <summary>
  95. /// 查询重录待审,重新录入环节Pid(用于期末设定学生名单背景颜色)
  96. /// </summary>
  97. /// <returns></returns>
  98. public List<int?> GetRebutStatus()
  99. {
  100. return WorkflowServices.Value.GetRebutStatus(tableName);
  101. }
  102. /// <summary>
  103. /// 查询对应的接入流程表中全部流程环节信息(WorkflowStatusView)
  104. /// </summary>
  105. /// <returns></returns>
  106. public List<WorkflowStatusView> GetStatusViewList()
  107. {
  108. return WorkflowServices.Value.GetStatusViewList(tableName);
  109. }
  110. /// <summary>
  111. /// 查询对应的接入流程表中审核流程环节信息(WorkflowStatusView,不包含开始、结束、非正常[BP]结束环节)
  112. /// </summary>
  113. /// <returns></returns>
  114. public List<WorkflowStatusView> GetApproveStatusViewList()
  115. {
  116. return WorkflowServices.Value.GetApproveStatusViewList(tableName);
  117. }
  118. /// <summary>
  119. /// 重载方法,根据当前流程环节ID获取全部审批动作
  120. /// </summary>
  121. /// <returns></returns>
  122. public List<ActionView> GetActionView()
  123. {
  124. return WorkflowServices.Value.GetActionView(tableName);
  125. }
  126. /// <summary>
  127. /// 查询开始流程环节的动作列表List
  128. /// </summary>
  129. /// <returns></returns>
  130. public List<ActionView> GetStartActionView()
  131. {
  132. return WorkflowServices.Value.GetStartActionView(tableName);
  133. }
  134. /// <summary>
  135. /// 根据当前环节ID、用户ID查询下一步审批动作信息List(ActionView)
  136. /// </summary>
  137. /// <param name="formID">表单ID</param>
  138. /// <param name="userID">当前用户ID</param>
  139. /// <returns></returns>
  140. public List<ActionView> GetActionView(Guid formID, Guid userID)
  141. {
  142. try
  143. {
  144. return WorkflowServices.Value.GetActionView(tableName, formID, userID);
  145. }
  146. catch (Exception)
  147. {
  148. throw;
  149. }
  150. }
  151. /// <summary>
  152. /// 查询对应的工作流程中是否有对应的操作权限
  153. /// </summary>
  154. /// <param name="formID"></param>
  155. /// <param name="userID"></param>
  156. /// <returns></returns>
  157. public bool IsCanApprove(Guid formID, Guid userID)
  158. {
  159. try
  160. {
  161. var action = this.WorkflowServices.Value.GetActionView(tableName, formID, userID).FirstOrDefault();
  162. if (StudentDAL.StudentRepository.GetSingle(x => x.UserID == userID) == null)
  163. {
  164. return WorkflowServices.Value.IsCanApprove(tableName, userID, action.ActionID, new List<Guid> { formID }, DataRangeUserFunc);
  165. }
  166. else
  167. {
  168. return WorkflowServices.Value.IsCanApprove(tableName, userID, action.ActionID, new List<Guid> { formID });
  169. }
  170. }
  171. catch (Exception ex)
  172. {
  173. throw new Exception(ex.Message);
  174. }
  175. }
  176. /// <summary>
  177. ///
  178. /// </summary>
  179. /// <param name="userID"></param>
  180. /// <param name="formIDs"></param>
  181. /// <returns></returns>
  182. public List<WorkflowPermissionView> IsCanApprove(Guid userID, List<Guid> formIDs)
  183. {
  184. return WorkflowServices.Value.IsCanApprove(tableName, userID, formIDs);
  185. }
  186. /// <summary>
  187. /// 根据当前用户ID、actionID、formIDs判断是否有权限
  188. /// </summary>
  189. /// <param name="userID"></param>
  190. /// <returns></returns>
  191. public bool GetRangeUserList(Guid userID, Guid actionID, List<Guid> formIDs)
  192. {
  193. return WorkflowServices.Value.IsCanApprove(tableName, userID, actionID, formIDs, DataRangeUserFunc);
  194. }
  195. /// <summary>
  196. /// 启动对应的流程并执行指定的动作至下一环节(提交)
  197. /// </summary>
  198. /// <param name="formID">需要提交的记录主键ID</param>
  199. /// <param name="userID">提交人ID</param>
  200. /// <param name="comment">提交意见</param>
  201. public void StartUp(List<Guid> formIDList, Guid userID, string comment = "")
  202. {
  203. try
  204. {
  205. if (StudentDAL.StudentRepository.GetSingle(x => x.UserID == userID) == null)
  206. {
  207. WorkflowServices.Value.BatchStartUp(tableName, formIDList, userID, comment, DataRangeUserFunc);
  208. }
  209. else
  210. {
  211. WorkflowServices.Value.BatchStartUp(tableName, formIDList, userID, comment, null);
  212. }
  213. }
  214. catch (Exception ex)
  215. {
  216. throw new Exception(ex.Message);
  217. }
  218. }
  219. /// <summary>
  220. /// 重载方法,启动对应的流程并执行指定的动作至下一环节(提交),适用于开始节点有两个以上动作时
  221. /// </summary>
  222. /// <param name="formID">需要提交的记录主键ID</param>
  223. /// <param name="userID">提交人ID</param>
  224. /// <param name="actionID">动作ID</param>
  225. /// <param name="comment">提交意见</param>
  226. public void StartUp(Guid formID, Guid userID, Guid actionID, string comment)
  227. {
  228. try
  229. {
  230. if (StudentDAL.StudentRepository.GetSingle(x => x.UserID == userID) == null)
  231. {
  232. WorkflowServices.Value.StartUp(tableName, formID, userID, actionID, comment, DataRangeUserFunc);
  233. }
  234. else
  235. {
  236. WorkflowServices.Value.StartUp(tableName, formID, userID, actionID, comment, null);
  237. }
  238. }
  239. catch (Exception ex)
  240. {
  241. throw new Exception(ex.Message);
  242. }
  243. }
  244. /// <summary>
  245. /// 审核流程(不包括提交——不包含流程启动)
  246. /// </summary>
  247. /// <param name="formID">需要审核的记录主键ID</param>
  248. /// <param name="userID">审核人ID</param>
  249. /// <param name="actionID">审核动作ID</param>
  250. /// <param name="comment">提交意见</param>
  251. public void Approve(List<Guid> formIDList, Guid userID, Guid actionID, string comment = "")
  252. {
  253. try
  254. {
  255. if (StudentDAL.StudentRepository.GetSingle(x => x.UserID == userID) == null)
  256. {
  257. WorkflowServices.Value.BatchApprove(tableName, formIDList, userID, actionID, comment, DataRangeUserFunc);
  258. }
  259. else
  260. {
  261. WorkflowServices.Value.BatchApprove(tableName, formIDList, userID, actionID, comment, null);
  262. }
  263. }
  264. catch (Exception ex)
  265. {
  266. throw new Exception(ex.Message);
  267. }
  268. }
  269. /// <summary>
  270. /// 工作流流程状态修改(通常用于取消申请、撤销等环节)
  271. /// </summary>
  272. /// <param name="formID">表单ID</param>
  273. /// <param name="status">状态:A为活动,D为结束、其他的自己定义</param>
  274. /// <param name="description">描述改变内容</param>
  275. public void ModifyProcessState(Guid formID, string status, string description)
  276. {
  277. try
  278. {
  279. WorkflowServices.Value.ModifyProcessState(tableName, formID, status, description);
  280. }
  281. catch (Exception)
  282. {
  283. throw;
  284. }
  285. }
  286. /// <summary>
  287. /// 查询对应的审核历史信息列表List(WorkflowApproveHistoryView)
  288. /// </summary>
  289. /// <param name="formID">需要获取的记录主键ID</param>
  290. /// <returns></returns>
  291. public IList<ViewModel.SystemView.WorkflowApproveHistoryView> GetApproveHistoryViewList(Guid formID)
  292. {
  293. try
  294. {
  295. return WorkflowServices.Value.GetApproveHistoryViewList(tableName, formID);
  296. }
  297. catch (Exception ex)
  298. {
  299. throw new Exception(ex.Message);
  300. }
  301. }
  302. /// <summary>
  303. /// 根据相应的信息查询待办信息View
  304. /// </summary>
  305. /// <typeparam name="T">视图类型</typeparam>
  306. /// <param name="query">查询视图,指定一个IQueryable决定如何获取表单记录</param>
  307. /// <param name="userID">待办用户ID</param>
  308. /// <param name="pkSelector">指定主键列</param>
  309. /// <param name="pageIndex">页码</param>
  310. /// <param name="pageSize">每页行数</param>
  311. /// <returns></returns>
  312. public IGridResultSet<T> QueryByPendingJob<T, TOrder>(IQueryable<T> query, Guid userID, Expression<Func<T, Guid>> pkSelector,
  313. Expression<Func<T, TOrder>> orderby, bool isDescending = false, int? pageIndex = null, int? pageSize = null)
  314. {
  315. try
  316. {
  317. return WorkflowServices.Value.QueryByPendingJob(tableName, query, userID, pkSelector, orderby, isDescending, pageIndex, pageSize);
  318. }
  319. catch (Exception)
  320. {
  321. throw;
  322. }
  323. }
  324. }
  325. }