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.
 
 
 
 
 
 

406 lines
13 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. /// <returns></returns>
  89. public IEnumerable<NWFTaskEntity> GetFinishTaskList()
  90. {
  91. try
  92. {
  93. return this.BaseRepository().FindList<NWFTaskEntity>(t => t.F_IsFinished == 1 && (t.F_Type == 1 || t.F_Type == 3));
  94. }
  95. catch (Exception ex)
  96. {
  97. if (ex is ExceptionEx)
  98. {
  99. throw;
  100. }
  101. else
  102. {
  103. throw ExceptionEx.ThrowServiceException(ex);
  104. }
  105. }
  106. }
  107. /// <summary>
  108. /// 判断任务是否允许撤销
  109. /// </summary>
  110. /// <param name="processId">流程实例</param>
  111. /// <param name="preNodeId">上一个节点(撤销任务节点)</param>
  112. /// <returns></returns>
  113. public bool IsRevokeTask(string processId, string preNodeId)
  114. {
  115. try
  116. {
  117. bool res = true;
  118. var list = this.BaseRepository().FindList<NWFTaskEntity>(t => t.F_ProcessId == processId && t.F_PrevNodeId == preNodeId && t.F_Type == 1 && t.F_IsFinished == 1);
  119. 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);
  120. if (list2.Count > 0)
  121. {
  122. return res;
  123. }
  124. foreach (var item in list)
  125. {
  126. string nodeId = item.F_NodeId;
  127. var entity = this.BaseRepository().FindEntity<NWFTaskEntity>(t => t.F_ProcessId == processId && t.F_NodeId == nodeId && t.F_IsFinished == 0);
  128. if (entity == null)
  129. {
  130. res = false;
  131. break;
  132. }
  133. }
  134. return res;
  135. }
  136. catch (Exception ex)
  137. {
  138. if (ex is ExceptionEx)
  139. {
  140. throw;
  141. }
  142. else
  143. {
  144. throw ExceptionEx.ThrowServiceException(ex);
  145. }
  146. }
  147. }
  148. /// <summary>
  149. /// 获取流程任务实体
  150. /// </summary>
  151. /// <param name="keyValue">主键</param>
  152. /// <returns></returns>
  153. public NWFTaskEntity GetEntity(string keyValue)
  154. {
  155. try
  156. {
  157. return this.BaseRepository().FindEntity<NWFTaskEntity>(keyValue);
  158. }
  159. catch (Exception ex)
  160. {
  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="nodeId">节点Id</param>
  175. /// <param name="processId">流程进程主键</param>
  176. /// <returns></returns>
  177. public NWFTaskEntity GetEntityByNodeId(string nodeId, string processId) {
  178. try
  179. {
  180. var strSql = new StringBuilder();
  181. strSql.Append(@"SELECT * FROM LR_NWF_Task WHERE F_ProcessId = @processId AND F_NodeId = @nodeId AND F_Type != 3 ORDER BY F_CreateDate DESC");
  182. return this.BaseRepository().FindEntity<NWFTaskEntity>(strSql.ToString(),new { processId, nodeId });
  183. }
  184. catch (Exception ex)
  185. {
  186. if (ex is ExceptionEx)
  187. {
  188. throw;
  189. }
  190. else
  191. {
  192. throw ExceptionEx.ThrowServiceException(ex);
  193. }
  194. }
  195. }
  196. /// <summary>
  197. /// 获取任务执行人列表
  198. /// </summary>
  199. /// <param name="taskId">任务主键</param>
  200. /// <returns></returns>
  201. public IEnumerable<NWFTaskRelationEntity> GetTaskUserList(string taskId) {
  202. try
  203. {
  204. var strSql = new StringBuilder();
  205. strSql.Append(@"SELECT * FROM LR_NWF_TaskRelation WHERE F_TaskId = @taskId ORDER BY F_Sort");
  206. return this.BaseRepository().FindList<NWFTaskRelationEntity>(strSql.ToString(), new { taskId });
  207. }
  208. catch (Exception ex)
  209. {
  210. if (ex is ExceptionEx)
  211. {
  212. throw;
  213. }
  214. else
  215. {
  216. throw ExceptionEx.ThrowServiceException(ex);
  217. }
  218. }
  219. }
  220. /// <summary>
  221. /// 获取任务执行日志实体
  222. /// </summary>
  223. /// <param name="nodeId">节点Id</param>
  224. /// <param name="prcoessId">流程进程主键</param>
  225. /// <returns></returns>
  226. public NWFTaskLogEntity GetLogEntityByNodeId(string nodeId,string prcoessId) {
  227. try
  228. {
  229. return this.BaseRepository().FindEntity<NWFTaskLogEntity>(t=>t.F_NodeId.Equals(nodeId)&&t.F_ProcessId.Equals(prcoessId) && t.F_TaskType != 3&& t.F_TaskType != 6);
  230. }
  231. catch (Exception ex)
  232. {
  233. if (ex is ExceptionEx)
  234. {
  235. throw;
  236. }
  237. else
  238. {
  239. throw ExceptionEx.ThrowServiceException(ex);
  240. }
  241. }
  242. }
  243. /// <summary>
  244. /// 获取任务执行日志列表
  245. /// </summary>
  246. /// <param name="nodeId">节点Id</param>
  247. /// <param name="prcoessId">流程进程主键</param>
  248. /// <returns></returns>
  249. public IEnumerable<NWFTaskLogEntity> GetLogListByNodeId(string nodeId, string prcoessId)
  250. {
  251. try
  252. {
  253. return this.BaseRepository().FindList<NWFTaskLogEntity>(t => t.F_NodeId.Equals(nodeId) && t.F_ProcessId.Equals(prcoessId) && t.F_TaskType == 1);
  254. }
  255. catch (Exception ex)
  256. {
  257. if (ex is ExceptionEx)
  258. {
  259. throw;
  260. }
  261. else
  262. {
  263. throw ExceptionEx.ThrowServiceException(ex);
  264. }
  265. }
  266. }
  267. /// <summary>
  268. /// 获取流程进程的任务处理日志
  269. /// </summary>
  270. /// <param name="prcoessId">流程进程主键</param>
  271. /// <returns></returns>
  272. public IEnumerable<NWFTaskLogEntity> GetLogList(string processId)
  273. {
  274. try
  275. {
  276. var strSql = new StringBuilder();
  277. strSql.Append(@"SELECT * FROM LR_NWF_TaskLog WHERE F_ProcessId = @processId ORDER BY F_CreateDate DESC ");
  278. return this.BaseRepository().FindList<NWFTaskLogEntity>(strSql.ToString(),new { processId });
  279. }
  280. catch (Exception ex)
  281. {
  282. if (ex is ExceptionEx)
  283. {
  284. throw;
  285. }
  286. else
  287. {
  288. throw ExceptionEx.ThrowServiceException(ex);
  289. }
  290. }
  291. }
  292. /// <summary>
  293. /// 获取流程进程的任务处理日志
  294. /// </summary>
  295. /// <param name="taskId">任务主键</param>
  296. /// <param name="userId">用户主键</param>
  297. /// <returns></returns>
  298. public NWFTaskLogEntity GetLogEntity(string taskId,string userId)
  299. {
  300. try
  301. {
  302. return this.BaseRepository().FindEntity<NWFTaskLogEntity>(t=>t.F_TaskId == taskId && t.F_CreateUserId == userId && t.F_TaskType != 100);
  303. }
  304. catch (Exception ex)
  305. {
  306. if (ex is ExceptionEx)
  307. {
  308. throw;
  309. }
  310. else
  311. {
  312. throw ExceptionEx.ThrowServiceException(ex);
  313. }
  314. }
  315. }
  316. /// <summary>
  317. /// 获取当前任务节点ID
  318. /// </summary>
  319. /// <param name="processId">流程进程主键</param>
  320. /// <returns></returns>
  321. public List<string> GetCurrentNodeIds(string processId)
  322. {
  323. try
  324. {
  325. var strSql = new StringBuilder();
  326. strSql.Append(@"SELECT
  327. t.F_NodeId
  328. FROM
  329. LR_NWF_Task t
  330. WHERE
  331. t.F_IsFinished = 0 AND t.F_ProcessId = @processId
  332. GROUP BY
  333. t.F_NodeId
  334. ");
  335. var taskList = this.BaseRepository().FindList<NWFTaskEntity>(strSql.ToString(), new { processId });
  336. List<string> list = new List<string>();
  337. foreach (var item in taskList)
  338. {
  339. list.Add(item.F_NodeId);
  340. }
  341. return list;
  342. }
  343. catch (Exception ex)
  344. {
  345. if (ex is ExceptionEx)
  346. {
  347. throw;
  348. }
  349. else
  350. {
  351. throw ExceptionEx.ThrowServiceException(ex);
  352. }
  353. }
  354. }
  355. #endregion
  356. #region 保存数据
  357. /// <summary>
  358. /// 更新审核人
  359. /// </summary>
  360. /// <param name="list">审核人列表</param>
  361. /// <param name="taskList">任务列表</param>
  362. /// <param name="nWFTaskLogEntity">任务日志</param>
  363. public void Save(List<NWFTaskRelationEntity> list, List<string> taskList, NWFTaskLogEntity nWFTaskLogEntity)
  364. {
  365. var db = this.BaseRepository().BeginTrans();
  366. try
  367. {
  368. foreach (string taskId in taskList) {
  369. db.Delete<NWFTaskRelationEntity>(t => t.F_TaskId == taskId && t.F_Result == 0 && t.F_Mark == 0);
  370. }
  371. foreach (var taskUser in list) {
  372. db.Insert(taskUser);
  373. }
  374. db.Insert(nWFTaskLogEntity);
  375. db.Commit();
  376. }
  377. catch (Exception ex)
  378. {
  379. db.Rollback();
  380. if (ex is ExceptionEx)
  381. {
  382. throw;
  383. }
  384. else
  385. {
  386. throw ExceptionEx.ThrowServiceException(ex);
  387. }
  388. }
  389. }
  390. #endregion
  391. }
  392. }