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.
 
 
 
 
 
 

384 lines
12 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace Learun.Application.WorkFlow
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架
  10. /// Copyright (c) 2013-2018 上海力软信息技术有限公司
  11. /// 创建人:力软-框架开发组
  12. /// 日 期:2018.12.09
  13. /// 描 述:流程任务
  14. /// </summary>
  15. public class NWFTaskSerivce : RepositoryFactory
  16. {
  17. #region 获取数据
  18. /// <summary>
  19. /// 获取所有的任务
  20. /// </summary>
  21. /// <param name="processId">流程进程主键</param>
  22. /// <returns></returns>
  23. public IEnumerable<NWFTaskEntity> GetALLTaskList(string processId)
  24. {
  25. try
  26. {
  27. return this.BaseRepository().FindList<NWFTaskEntity>(t => t.F_ProcessId == processId);
  28. }
  29. catch (Exception ex)
  30. {
  31. if (ex is ExceptionEx)
  32. {
  33. throw;
  34. }
  35. else
  36. {
  37. throw ExceptionEx.ThrowServiceException(ex);
  38. }
  39. }
  40. }
  41. /// <summary>
  42. /// 获取未完成的任务
  43. /// </summary>
  44. /// <param name="processId">流程进程主键</param>
  45. /// <returns></returns>
  46. public IEnumerable<NWFTaskEntity> GetUnFinishTaskList(string processId) {
  47. try
  48. {
  49. return this.BaseRepository().FindList<NWFTaskEntity>(t=>t.F_ProcessId == processId && t.F_IsFinished == 0);
  50. }
  51. catch (Exception ex)
  52. {
  53. if (ex is ExceptionEx)
  54. {
  55. throw;
  56. }
  57. else
  58. {
  59. throw ExceptionEx.ThrowServiceException(ex);
  60. }
  61. }
  62. }
  63. /// <summary>
  64. /// 获取所有未完成的任务
  65. /// </summary>
  66. /// <returns></returns>
  67. public IEnumerable<NWFTaskEntity> GetUnFinishTaskList()
  68. {
  69. try
  70. {
  71. return this.BaseRepository().FindList<NWFTaskEntity>(t => t.F_IsFinished == 0 && (t.F_Type == 1 || t.F_Type == 3));
  72. }
  73. catch (Exception ex)
  74. {
  75. if (ex is ExceptionEx)
  76. {
  77. throw;
  78. }
  79. else
  80. {
  81. throw ExceptionEx.ThrowServiceException(ex);
  82. }
  83. }
  84. }
  85. /// <summary>
  86. /// 判断任务是否允许撤销
  87. /// </summary>
  88. /// <param name="processId">流程实例</param>
  89. /// <param name="preNodeId">上一个节点(撤销任务节点)</param>
  90. /// <returns></returns>
  91. public bool IsRevokeTask(string processId, string preNodeId)
  92. {
  93. try
  94. {
  95. bool res = true;
  96. var list = this.BaseRepository().FindList<NWFTaskEntity>(t => t.F_ProcessId == processId && t.F_PrevNodeId == preNodeId && t.F_Type == 1 && t.F_IsFinished == 1);
  97. var list2 = (List<NWFTaskEntity>)this.BaseRepository().FindList<NWFTaskEntity>(t => t.F_ProcessId == processId && t.F_PrevNodeId == preNodeId && (t.F_Type == 1 || t.F_Type == 5) && t.F_IsFinished == 0);
  98. if (list2.Count > 0)
  99. {
  100. return res;
  101. }
  102. foreach (var item in list)
  103. {
  104. string nodeId = item.F_NodeId;
  105. var entity = this.BaseRepository().FindEntity<NWFTaskEntity>(t => t.F_ProcessId == processId && t.F_NodeId == nodeId && t.F_IsFinished == 0);
  106. if (entity == null)
  107. {
  108. res = false;
  109. break;
  110. }
  111. }
  112. return res;
  113. }
  114. catch (Exception ex)
  115. {
  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. /// <returns></returns>
  131. public NWFTaskEntity GetEntity(string keyValue)
  132. {
  133. try
  134. {
  135. return this.BaseRepository().FindEntity<NWFTaskEntity>(keyValue);
  136. }
  137. catch (Exception ex)
  138. {
  139. if (ex is ExceptionEx)
  140. {
  141. throw;
  142. }
  143. else
  144. {
  145. throw ExceptionEx.ThrowServiceException(ex);
  146. }
  147. }
  148. }
  149. /// <summary>
  150. /// 获取最近一次的任务信息(审批任务)
  151. /// </summary>
  152. /// <param name="nodeId">节点Id</param>
  153. /// <param name="processId">流程进程主键</param>
  154. /// <returns></returns>
  155. public NWFTaskEntity GetEntityByNodeId(string nodeId, string processId) {
  156. try
  157. {
  158. var strSql = new StringBuilder();
  159. strSql.Append(@"SELECT * FROM LR_NWF_Task WHERE F_ProcessId = @processId AND F_NodeId = @nodeId AND F_Type != 3 ORDER BY F_CreateDate DESC");
  160. return this.BaseRepository().FindEntity<NWFTaskEntity>(strSql.ToString(),new { processId, nodeId });
  161. }
  162. catch (Exception ex)
  163. {
  164. if (ex is ExceptionEx)
  165. {
  166. throw;
  167. }
  168. else
  169. {
  170. throw ExceptionEx.ThrowServiceException(ex);
  171. }
  172. }
  173. }
  174. /// <summary>
  175. /// 获取任务执行人列表
  176. /// </summary>
  177. /// <param name="taskId">任务主键</param>
  178. /// <returns></returns>
  179. public IEnumerable<NWFTaskRelationEntity> GetTaskUserList(string taskId) {
  180. try
  181. {
  182. var strSql = new StringBuilder();
  183. strSql.Append(@"SELECT * FROM LR_NWF_TaskRelation WHERE F_TaskId = @taskId ORDER BY F_Sort");
  184. return this.BaseRepository().FindList<NWFTaskRelationEntity>(strSql.ToString(), new { taskId });
  185. }
  186. catch (Exception ex)
  187. {
  188. if (ex is ExceptionEx)
  189. {
  190. throw;
  191. }
  192. else
  193. {
  194. throw ExceptionEx.ThrowServiceException(ex);
  195. }
  196. }
  197. }
  198. /// <summary>
  199. /// 获取任务执行日志实体
  200. /// </summary>
  201. /// <param name="nodeId">节点Id</param>
  202. /// <param name="prcoessId">流程进程主键</param>
  203. /// <returns></returns>
  204. public NWFTaskLogEntity GetLogEntityByNodeId(string nodeId,string prcoessId) {
  205. try
  206. {
  207. return this.BaseRepository().FindEntity<NWFTaskLogEntity>(t=>t.F_NodeId.Equals(nodeId)&&t.F_ProcessId.Equals(prcoessId) && t.F_TaskType != 3&& t.F_TaskType != 6);
  208. }
  209. catch (Exception ex)
  210. {
  211. if (ex is ExceptionEx)
  212. {
  213. throw;
  214. }
  215. else
  216. {
  217. throw ExceptionEx.ThrowServiceException(ex);
  218. }
  219. }
  220. }
  221. /// <summary>
  222. /// 获取任务执行日志列表
  223. /// </summary>
  224. /// <param name="nodeId">节点Id</param>
  225. /// <param name="prcoessId">流程进程主键</param>
  226. /// <returns></returns>
  227. public IEnumerable<NWFTaskLogEntity> GetLogListByNodeId(string nodeId, string prcoessId)
  228. {
  229. try
  230. {
  231. return this.BaseRepository().FindList<NWFTaskLogEntity>(t => t.F_NodeId.Equals(nodeId) && t.F_ProcessId.Equals(prcoessId) && t.F_TaskType == 1);
  232. }
  233. catch (Exception ex)
  234. {
  235. if (ex is ExceptionEx)
  236. {
  237. throw;
  238. }
  239. else
  240. {
  241. throw ExceptionEx.ThrowServiceException(ex);
  242. }
  243. }
  244. }
  245. /// <summary>
  246. /// 获取流程进程的任务处理日志
  247. /// </summary>
  248. /// <param name="prcoessId">流程进程主键</param>
  249. /// <returns></returns>
  250. public IEnumerable<NWFTaskLogEntity> GetLogList(string processId)
  251. {
  252. try
  253. {
  254. var strSql = new StringBuilder();
  255. strSql.Append(@"SELECT * FROM LR_NWF_TaskLog WHERE F_ProcessId = @processId ORDER BY F_CreateDate DESC ");
  256. return this.BaseRepository().FindList<NWFTaskLogEntity>(strSql.ToString(),new { processId });
  257. }
  258. catch (Exception ex)
  259. {
  260. if (ex is ExceptionEx)
  261. {
  262. throw;
  263. }
  264. else
  265. {
  266. throw ExceptionEx.ThrowServiceException(ex);
  267. }
  268. }
  269. }
  270. /// <summary>
  271. /// 获取流程进程的任务处理日志
  272. /// </summary>
  273. /// <param name="taskId">任务主键</param>
  274. /// <param name="userId">用户主键</param>
  275. /// <returns></returns>
  276. public NWFTaskLogEntity GetLogEntity(string taskId,string userId)
  277. {
  278. try
  279. {
  280. return this.BaseRepository().FindEntity<NWFTaskLogEntity>(t=>t.F_TaskId == taskId && t.F_CreateUserId == userId && t.F_TaskType != 100);
  281. }
  282. catch (Exception ex)
  283. {
  284. if (ex is ExceptionEx)
  285. {
  286. throw;
  287. }
  288. else
  289. {
  290. throw ExceptionEx.ThrowServiceException(ex);
  291. }
  292. }
  293. }
  294. /// <summary>
  295. /// 获取当前任务节点ID
  296. /// </summary>
  297. /// <param name="processId">流程进程主键</param>
  298. /// <returns></returns>
  299. public List<string> GetCurrentNodeIds(string processId)
  300. {
  301. try
  302. {
  303. var strSql = new StringBuilder();
  304. strSql.Append(@"SELECT
  305. t.F_NodeId
  306. FROM
  307. LR_NWF_Task t
  308. WHERE
  309. t.F_IsFinished = 0 AND t.F_ProcessId = @processId
  310. GROUP BY
  311. t.F_NodeId
  312. ");
  313. var taskList = this.BaseRepository().FindList<NWFTaskEntity>(strSql.ToString(), new { processId });
  314. List<string> list = new List<string>();
  315. foreach (var item in taskList)
  316. {
  317. list.Add(item.F_NodeId);
  318. }
  319. return list;
  320. }
  321. catch (Exception ex)
  322. {
  323. if (ex is ExceptionEx)
  324. {
  325. throw;
  326. }
  327. else
  328. {
  329. throw ExceptionEx.ThrowServiceException(ex);
  330. }
  331. }
  332. }
  333. #endregion
  334. #region 保存数据
  335. /// <summary>
  336. /// 更新审核人
  337. /// </summary>
  338. /// <param name="list">审核人列表</param>
  339. /// <param name="taskList">任务列表</param>
  340. /// <param name="nWFTaskLogEntity">任务日志</param>
  341. public void Save(List<NWFTaskRelationEntity> list, List<string> taskList, NWFTaskLogEntity nWFTaskLogEntity)
  342. {
  343. var db = this.BaseRepository().BeginTrans();
  344. try
  345. {
  346. foreach (string taskId in taskList) {
  347. db.Delete<NWFTaskRelationEntity>(t => t.F_TaskId == taskId && t.F_Result == 0 && t.F_Mark == 0);
  348. }
  349. foreach (var taskUser in list) {
  350. db.Insert(taskUser);
  351. }
  352. db.Insert(nWFTaskLogEntity);
  353. db.Commit();
  354. }
  355. catch (Exception ex)
  356. {
  357. db.Rollback();
  358. if (ex is ExceptionEx)
  359. {
  360. throw;
  361. }
  362. else
  363. {
  364. throw ExceptionEx.ThrowServiceException(ex);
  365. }
  366. }
  367. }
  368. #endregion
  369. }
  370. }