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.
 
 
 
 
 
 

1492 lines
64 KiB

  1. using Learun.Application.Organization;
  2. using Learun.Application.Base.SystemModule;
  3. using Learun.Ioc;
  4. using Learun.Util;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. namespace Learun.Application.WorkFlow
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  12. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  13. /// 创建人:陈彬彬
  14. /// 日 期:2017.04.17
  15. /// 描 述:工作流引擎
  16. /// </summary>
  17. public class WfEngineBLL : WfEngineIBLL
  18. {
  19. private WfProcessInstanceIBLL wfProcessInstanceIBLL = new WfProcessInstanceBLL();
  20. private WfSchemeIBLL wfSchemeIBLL = new WfSchemeBLL();
  21. private WfTaskIBLL wfTaskIBLL = new WfTaskBLL();
  22. private WfTaskHistoryIBLL wfTaskHistoryIBLL = new WfTaskHistoryBLL();
  23. private WfConfluenceIBLL wfConfluenceBLL = new WfConfluenceBLL();
  24. private UserIBLL userIBLL = new UserBLL();
  25. private DatabaseLinkIBLL databaseLinkIBLL = new DatabaseLinkBLL();
  26. #region 属性值
  27. /// <summary>
  28. /// 流程模板数据
  29. /// </summary>
  30. private WfSchemeEntity wfSchemeEntity = null;
  31. /// <summary>
  32. /// 流程模板信息数据
  33. /// </summary>
  34. private WfSchemeInfoEntity wfSchemeInfoEntity = null;
  35. private UserEntity processCreater = null;
  36. #endregion
  37. #region 工作流模板处理
  38. /// <summary>
  39. /// 初始化模板
  40. /// </summary>
  41. /// <param name="parameter"></param>
  42. private bool InitScheme(WfParameter parameter)
  43. {
  44. bool res = false;
  45. try
  46. {
  47. if (parameter.isNew)
  48. {
  49. wfSchemeInfoEntity = wfSchemeIBLL.GetWfSchemeInfoEntityByCode(parameter.schemeCode);
  50. wfSchemeEntity = wfSchemeIBLL.GetWfSchemeEntity(wfSchemeInfoEntity.F_SchemeId);
  51. }
  52. else
  53. {
  54. // 如果是重新发起的流程实例(获取当前实例的流程模板)
  55. WfProcessInstanceEntity wfProcessInstanceEntity = wfProcessInstanceIBLL.GetEntity(parameter.processId);
  56. processCreater = userIBLL.GetEntityByUserId(wfProcessInstanceEntity.F_CreateUserId);
  57. wfSchemeInfoEntity = wfSchemeIBLL.GetWfSchemeInfoEntityByCode(wfProcessInstanceEntity.F_SchemeCode);
  58. wfSchemeEntity = wfSchemeIBLL.GetWfSchemeEntity(wfProcessInstanceEntity.F_SchemeId);
  59. }
  60. wfSchemeIBLL.SchemeInit(wfSchemeEntity);
  61. res = true;
  62. return res;
  63. }
  64. catch (Exception)
  65. {
  66. return res;
  67. }
  68. }
  69. #endregion
  70. #region 流程实例处理
  71. /// <summary>
  72. /// 保存实例数据
  73. /// </summary>
  74. /// <param name="parameter">参数</param>
  75. private void SaveProcess(WfParameter parameter)
  76. {
  77. try
  78. {
  79. WfProcessInstanceEntity wfProcessInstanceEntity = new WfProcessInstanceEntity();
  80. if (parameter.isNew)
  81. {
  82. wfProcessInstanceEntity.F_Id = parameter.processId;
  83. wfProcessInstanceEntity.F_SchemeId = wfSchemeEntity.F_Id;
  84. wfProcessInstanceEntity.F_SchemeCode = wfSchemeInfoEntity.F_Code;
  85. wfProcessInstanceEntity.F_SchemeName = wfSchemeInfoEntity.F_Name;
  86. wfProcessInstanceEntity.F_ProcessName = parameter.processName;
  87. wfProcessInstanceEntity.F_ProcessLevel = parameter.processLevel;
  88. wfProcessInstanceEntity.F_CompanyId = parameter.companyId;
  89. wfProcessInstanceEntity.F_DepartmentId = parameter.departmentId;
  90. wfProcessInstanceEntity.F_CreateUserId = parameter.userId;
  91. wfProcessInstanceEntity.F_CreateUserName = parameter.userName;
  92. wfProcessInstanceEntity.F_Description = parameter.description;
  93. wfProcessInstanceIBLL.SaveEntity("",wfProcessInstanceEntity);
  94. }
  95. else
  96. {
  97. wfProcessInstanceEntity.F_IsAgain = 0;
  98. wfProcessInstanceEntity.F_ProcessLevel = parameter.processLevel;
  99. wfProcessInstanceEntity.F_Description = parameter.description;
  100. wfProcessInstanceIBLL.SaveEntity(parameter.processId, wfProcessInstanceEntity);
  101. }
  102. }
  103. catch (Exception ex)
  104. {
  105. if (ex is ExceptionEx)
  106. {
  107. throw;
  108. }
  109. else
  110. {
  111. throw ExceptionEx.ThrowBusinessException(ex);
  112. }
  113. }
  114. }
  115. #endregion
  116. #region 流程节点处理
  117. /// <summary>
  118. /// 会签节点判断
  119. /// </summary>
  120. /// <param name="wfNodeInfo">节点信息</param>
  121. /// <param name="parameter">参数</param>
  122. /// <returns>0 不做处理 1 通过 -1 不通过</returns>
  123. private int CalcConfluenceNode(WfNodeInfo wfNodeInfo, WfNodeInfo preWfNodeInfo, WfParameter parameter, bool isOk)
  124. {
  125. int res = 0;
  126. try
  127. {
  128. List<WfConfluenceEntity> list = (List<WfConfluenceEntity>)wfConfluenceBLL.GetList(parameter.processId, wfNodeInfo.id);
  129. int notOkNum = list.FindAll(t => t.F_IsOk == 0).Count;
  130. int okNum = list.FindAll(t => t.F_IsOk == 1).Count;
  131. int allNum = wfSchemeIBLL.GetPreNodeNum(wfNodeInfo.id);
  132. switch (wfNodeInfo.confluenceType)//会签策略1-所有步骤通过,2-一个步骤通过即可,3-按百分比计算
  133. {
  134. case 1://所有步骤通过
  135. if (isOk)
  136. {
  137. if (allNum == okNum + 1)
  138. {
  139. res = 1;
  140. wfConfluenceBLL.DeleteEntity(parameter.processId, wfNodeInfo.id);
  141. }
  142. else
  143. {
  144. WfConfluenceEntity wfConfluenceEntity = new WfConfluenceEntity();
  145. wfConfluenceEntity.F_ProcessId = parameter.processId;
  146. wfConfluenceEntity.F_NodeId = wfNodeInfo.id;
  147. wfConfluenceEntity.F_FormNodeId = preWfNodeInfo.id;
  148. wfConfluenceEntity.F_IsOk = 1;
  149. // 存储一条记录
  150. wfConfluenceBLL.SaveEntity(wfConfluenceEntity);
  151. }
  152. }
  153. else
  154. {
  155. res = -1;
  156. wfConfluenceBLL.DeleteEntity(parameter.processId, wfNodeInfo.id);
  157. }
  158. break;
  159. case 2:
  160. if (isOk)
  161. {
  162. res = 1;
  163. wfConfluenceBLL.DeleteEntity(parameter.processId, wfNodeInfo.id);
  164. }
  165. else
  166. {
  167. if ((list.Count + 1) == allNum)
  168. {
  169. res = -1;
  170. wfConfluenceBLL.DeleteEntity(parameter.processId, wfNodeInfo.id);
  171. }
  172. else
  173. {
  174. WfConfluenceEntity wfConfluenceEntity = new WfConfluenceEntity();
  175. wfConfluenceEntity.F_ProcessId = parameter.processId;
  176. wfConfluenceEntity.F_NodeId = wfNodeInfo.id;
  177. wfConfluenceEntity.F_FormNodeId = preWfNodeInfo.id;
  178. wfConfluenceEntity.F_IsOk = 0;
  179. // 存储一条记录
  180. wfConfluenceBLL.SaveEntity(wfConfluenceEntity);
  181. }
  182. }
  183. break;
  184. case 3:
  185. if (isOk)
  186. {
  187. if ((okNum + 1) * 100 / allNum >= Convert.ToInt32(wfNodeInfo.confluenceRate))
  188. {
  189. res = 1;
  190. wfConfluenceBLL.DeleteEntity(parameter.processId, wfNodeInfo.id);
  191. }
  192. else
  193. {
  194. WfConfluenceEntity wfConfluenceEntity = new WfConfluenceEntity();
  195. wfConfluenceEntity.F_ProcessId = parameter.processId;
  196. wfConfluenceEntity.F_NodeId = wfNodeInfo.id;
  197. wfConfluenceEntity.F_FormNodeId = preWfNodeInfo.id;
  198. wfConfluenceEntity.F_IsOk = 1;
  199. // 存储一条记录
  200. wfConfluenceBLL.SaveEntity(wfConfluenceEntity);
  201. }
  202. }
  203. else
  204. {
  205. if ((allNum - notOkNum - 1) * 100 / allNum < Convert.ToInt32(wfNodeInfo.confluenceRate))
  206. {
  207. res = -1;
  208. wfConfluenceBLL.DeleteEntity(parameter.processId, wfNodeInfo.id);
  209. }
  210. else
  211. {
  212. WfConfluenceEntity wfConfluenceEntity = new WfConfluenceEntity();
  213. wfConfluenceEntity.F_ProcessId = parameter.processId;
  214. wfConfluenceEntity.F_NodeId = wfNodeInfo.id;
  215. wfConfluenceEntity.F_FormNodeId = preWfNodeInfo.id;
  216. wfConfluenceEntity.F_IsOk = 0;
  217. // 存储一条记录
  218. wfConfluenceBLL.SaveEntity(wfConfluenceEntity);
  219. }
  220. }
  221. break;
  222. }
  223. if (res != 0)
  224. {
  225. // 需要清除下此会签其他发布的任务
  226. ClearConfluenceTask(wfNodeInfo.id, preWfNodeInfo, parameter.processId);
  227. }
  228. return res;
  229. }
  230. catch (Exception ex)
  231. {
  232. if (ex is ExceptionEx)
  233. {
  234. throw;
  235. }
  236. else
  237. {
  238. throw ExceptionEx.ThrowBusinessException(ex);
  239. }
  240. }
  241. }
  242. /// <summary>
  243. /// 清除会签其他发布的任务
  244. /// </summary>
  245. /// <param name="nodeId">会签节点主键</param>
  246. /// <param name="preWfNodeInfo">上一个节点</param>
  247. /// <param name="processId">流程实例主键</param>
  248. /// <returns></returns>
  249. private void ClearConfluenceTask(string nodeId, WfNodeInfo preWfNodeInfo, string processId)
  250. {
  251. try
  252. {
  253. Dictionary<string, string> hasMap = new Dictionary<string, string>();// 记录已经处理的节点ID
  254. var taskList = wfTaskIBLL.GetList(processId);
  255. foreach (var task in taskList)
  256. {
  257. if (task.F_IsFinished == 0 && task.F_NodeId != preWfNodeInfo.id)
  258. {
  259. if (hasMap.ContainsKey(task.F_NodeId))
  260. {
  261. wfTaskIBLL.UpdateState(hasMap[task.F_NodeId], 2);
  262. }
  263. else
  264. {
  265. if (wfSchemeIBLL.IsToNode(task.F_NodeId, nodeId))
  266. {
  267. hasMap.Add(task.F_NodeId, task.F_Id);
  268. wfTaskIBLL.UpdateState(task.F_Id, 2);
  269. }
  270. }
  271. }
  272. }
  273. }
  274. catch (Exception ex)
  275. {
  276. if (ex is ExceptionEx)
  277. {
  278. throw;
  279. }
  280. else
  281. {
  282. throw ExceptionEx.ThrowBusinessException(ex);
  283. }
  284. }
  285. }
  286. /// <summary>
  287. /// 条件节点判断
  288. /// </summary>
  289. /// <param name="wfNodeInfo">节点信息</param>
  290. /// <param name="parameter">参数</param>
  291. /// <returns></returns>
  292. private bool CalcConditionNode(WfNodeInfo wfNodeInfo, WfParameter parameter)
  293. {
  294. bool res = false;
  295. try
  296. {
  297. if (wfNodeInfo.conditions.Count > 0)
  298. {
  299. #region 字段条件判断
  300. var formData = parameter.formData.ToJObject();
  301. foreach (var condition in wfNodeInfo.conditions)
  302. {
  303. res = false;
  304. if (!formData[condition.fieldId].IsEmpty()) {
  305. string v1 = Convert.ToString(formData[condition.fieldId].ToString());
  306. switch (condition.compareType)//比较类型1.等于2.不等于3.大于4.大于等于5.小于6.小于等于7.包含8.不包含9.包含于10.不包含于
  307. {
  308. case 1:
  309. if (v1 == condition.value)
  310. {
  311. res = true;
  312. }
  313. break;
  314. case 2:
  315. if (v1 != condition.value)
  316. {
  317. res = true;
  318. }
  319. break;
  320. case 3:
  321. if (Convert.ToDecimal(v1) > Convert.ToDecimal(condition.value))
  322. {
  323. res = true;
  324. }
  325. break;
  326. case 4:
  327. if (Convert.ToDecimal(v1) >= Convert.ToDecimal(condition.value))
  328. {
  329. res = true;
  330. }
  331. break;
  332. case 5:
  333. if (Convert.ToDecimal(v1) < Convert.ToDecimal(condition.value))
  334. {
  335. res = true;
  336. }
  337. break;
  338. case 6:
  339. if (Convert.ToDecimal(v1) <= Convert.ToDecimal(condition.value))
  340. {
  341. res = true;
  342. }
  343. break;
  344. case 7:
  345. if (v1.Contains(condition.value))
  346. {
  347. res = true;
  348. }
  349. break;
  350. case 8:
  351. if (!v1.Contains(condition.value))
  352. {
  353. res = true;
  354. }
  355. break;
  356. case 9:
  357. if (condition.value.Contains(v1))
  358. {
  359. res = true;
  360. }
  361. break;
  362. case 10:
  363. if (!condition.value.Contains(v1))
  364. {
  365. res = true;
  366. }
  367. break;
  368. }
  369. }
  370. }
  371. #endregion
  372. }
  373. else if (!string.IsNullOrEmpty(wfNodeInfo.conditionSql))
  374. {
  375. string conditionSql = wfNodeInfo.conditionSql.Replace("{processId}", "@processId");
  376. DataTable dataTable = databaseLinkIBLL.FindTable(wfNodeInfo.dbConditionId, conditionSql, new { processId = parameter.processId });
  377. if (dataTable.Rows.Count > 0)
  378. {
  379. res = true;
  380. }
  381. }
  382. else
  383. {
  384. res = true;
  385. }
  386. return res;
  387. }
  388. catch (Exception ex)
  389. {
  390. if (ex is ExceptionEx)
  391. {
  392. throw;
  393. }
  394. else
  395. {
  396. throw ExceptionEx.ThrowBusinessException(ex);
  397. }
  398. }
  399. }
  400. #endregion
  401. #region 流程实例任务处理
  402. /// <summary>
  403. /// 创建流程实例节点任务
  404. /// </summary>
  405. /// <param name="wfNodeInfo">节点信息</param>
  406. /// <param name="preWfNodeInfo">上一节点信息</param>
  407. /// <param name="parameter">参数</param>
  408. /// <returns></returns>
  409. private WfTaskEntity CreateTask(WfNodeInfo wfNodeInfo, WfNodeInfo preWfNodeInfo, WfParameter parameter)
  410. {
  411. try
  412. {
  413. WfTaskEntity wfTaskEntity = new WfTaskEntity();
  414. wfTaskEntity.F_ProcessId = parameter.processId;
  415. wfTaskEntity.F_NodeId = wfNodeInfo.id;
  416. wfTaskEntity.F_NodeName = wfNodeInfo.name;
  417. wfTaskEntity.auditors = wfNodeInfo.auditors;
  418. switch (wfNodeInfo.type)//开始startround;结束endround;一般stepnode;会签节点:confluencenode;条件判断节点:conditionnode;查阅节点:auditornode;
  419. {
  420. case "startround":
  421. wfTaskEntity.auditors = new List<WfAuditor>();
  422. WfAuditor wfAuditor = new WfAuditor();
  423. wfAuditor.id = Guid.NewGuid().ToString();
  424. var wfProcessInstanceEntity = wfProcessInstanceIBLL.GetEntity(parameter.processId);
  425. wfAuditor.auditorId = wfProcessInstanceEntity.F_CreateUserId;
  426. wfAuditor.auditorName = wfProcessInstanceEntity.F_CreateUserName;
  427. wfTaskEntity.auditors.Add(wfAuditor);
  428. wfTaskEntity.F_TaskType = 2;
  429. break;
  430. case "stepnode":
  431. wfTaskEntity.F_TaskType = 1;
  432. break;
  433. case "auditornode":
  434. wfTaskEntity.F_TaskType = 3;
  435. break;
  436. }
  437. wfTaskEntity.F_TimeoutAction = wfNodeInfo.timeoutAction;
  438. wfTaskEntity.F_TimeoutNotice = wfNodeInfo.timeoutNotice;
  439. wfTaskEntity.F_PreviousId = preWfNodeInfo.id;
  440. wfTaskEntity.F_PreviousName = preWfNodeInfo.name;
  441. wfTaskEntity.F_CreateUserId = parameter.userId;
  442. wfTaskEntity.F_CreateUserName = parameter.userName;
  443. return wfTaskEntity;
  444. }
  445. catch (Exception ex)
  446. {
  447. if (ex is ExceptionEx)
  448. {
  449. throw;
  450. }
  451. else
  452. {
  453. throw ExceptionEx.ThrowBusinessException(ex);
  454. }
  455. }
  456. }
  457. /// <summary>
  458. /// 创建一个加签任务
  459. /// </summary>
  460. /// <param name="preWfNodeInfo">上一节点信息</param>
  461. /// <param name="parameter">流程参数信息</param>
  462. /// <returns></returns>
  463. private WfTaskEntity CreateTaskSign(WfNodeInfo preWfNodeInfo, WfParameter parameter)
  464. {
  465. try
  466. {
  467. WfTaskEntity wfTaskEntity = new WfTaskEntity();
  468. wfTaskEntity.F_ProcessId = parameter.processId;
  469. wfTaskEntity.F_NodeId = preWfNodeInfo.id;
  470. wfTaskEntity.F_NodeName = preWfNodeInfo.name;
  471. wfTaskEntity.F_TaskType = 4;
  472. wfTaskEntity.auditors = new List<WfAuditor>();
  473. WfAuditor wfAuditor = new WfAuditor();
  474. wfAuditor.id = Guid.NewGuid().ToString();
  475. wfAuditor.auditorId = parameter.auditorId;
  476. wfAuditor.auditorName = parameter.auditorName;
  477. wfTaskEntity.auditors.Add(wfAuditor);
  478. wfTaskEntity.F_PreviousId = preWfNodeInfo.id;
  479. wfTaskEntity.F_PreviousName = preWfNodeInfo.name;
  480. wfTaskEntity.F_CreateUserId = parameter.userId;
  481. wfTaskEntity.F_CreateUserName = parameter.userName;
  482. return wfTaskEntity;
  483. }
  484. catch (Exception ex)
  485. {
  486. if (ex is ExceptionEx)
  487. {
  488. throw;
  489. }
  490. else
  491. {
  492. throw ExceptionEx.ThrowBusinessException(ex);
  493. }
  494. }
  495. }
  496. /// <summary>
  497. /// 获取接下来需要处理的任务列表
  498. /// </summary>
  499. /// <param name="nodeId">当前节点主键</param>
  500. /// <param name="transportType">节点流转类型</param>
  501. /// <param name="wfTaskList">任务列表</param>
  502. /// <param name="wfReadTaskList">任务列表</param>
  503. /// <param name="parameter">参数</param>
  504. /// <returns>false 表示流程结束 true 表示流程还未运行完</returns>
  505. private bool GetNextTaskes(WfNodeInfo currentNode, WfTransportType transportType, List<WfTaskEntity> wfTaskList, List<WfTaskEntity> wfReadTaskList, WfParameter parameter)
  506. {
  507. try
  508. {
  509. List<WfNodeInfo> nextNodes = wfSchemeIBLL.GetNextNodes(currentNode.id, transportType);
  510. if (nextNodes.Count == 0)
  511. {
  512. return false;
  513. }
  514. foreach (var node in nextNodes)
  515. {
  516. if (node.type == "conditionnode")// 条件节点
  517. {
  518. if (CalcConditionNode(node, parameter))
  519. {
  520. GetNextTaskes(node, WfTransportType.Agree, wfTaskList, wfReadTaskList, parameter);
  521. }
  522. else
  523. {
  524. GetNextTaskes(node, WfTransportType.Disagree, wfTaskList, wfReadTaskList, parameter);
  525. }
  526. }
  527. else if (node.type == "confluencenode")// 会签节点
  528. {
  529. if (parameter.isGetAuditer)
  530. {
  531. GetNextTaskes(node, WfTransportType.Agree, wfTaskList, wfReadTaskList, parameter);
  532. }
  533. else
  534. {
  535. int confluenceRes;
  536. if (transportType == WfTransportType.Agree)
  537. {
  538. confluenceRes = CalcConfluenceNode(node, currentNode, parameter, true);
  539. }
  540. else
  541. {
  542. confluenceRes = CalcConfluenceNode(node, currentNode, parameter, false);
  543. }
  544. if (confluenceRes == 1)
  545. {
  546. GetNextTaskes(node, WfTransportType.Agree, wfTaskList, wfReadTaskList, parameter);
  547. currentNode.cfres = true;
  548. currentNode.cfIocName = node.iocName;
  549. currentNode.cfDbId = node.dbSuccessId;
  550. currentNode.cfDbSql = node.dbSuccessSql;
  551. }
  552. else if (confluenceRes == -1)
  553. {
  554. GetNextTaskes(node, WfTransportType.Disagree, wfTaskList, wfReadTaskList, parameter);
  555. currentNode.cfres = false;
  556. currentNode.cfIocName = node.iocName;
  557. currentNode.cfDbId = node.dbFailId;
  558. currentNode.cfDbSql = node.dbFailSql;
  559. }
  560. else
  561. {
  562. // 添加一个空数据的任务项表示当前流程还未结束
  563. WfTaskEntity wfTaskEntity = new WfTaskEntity();
  564. wfTaskList.Add(wfTaskEntity);
  565. }
  566. }
  567. }
  568. else if (node.type == "auditornode") {
  569. WfTaskEntity wfTaskEntity = CreateTask(node, currentNode, parameter);
  570. wfReadTaskList.Add(wfTaskEntity);
  571. }
  572. else if (node.type != "endround")
  573. {
  574. WfTaskEntity wfTaskEntity = CreateTask(node, currentNode, parameter);
  575. wfTaskList.Add(wfTaskEntity);
  576. }
  577. }
  578. return true;
  579. }
  580. catch (Exception ex)
  581. {
  582. if (ex is ExceptionEx)
  583. {
  584. throw;
  585. }
  586. else
  587. {
  588. throw ExceptionEx.ThrowBusinessException(ex);
  589. }
  590. }
  591. }
  592. #endregion
  593. #region 流程实例任务历史处理
  594. /// <summary>
  595. /// 创建一个任务处理记录
  596. /// </summary>
  597. /// <param name="parameter">工作流传递参数</param>
  598. /// <param name="wfTaskEntity">当前任务信息</param>
  599. /// <param name="wfNodeInfo">节点信息</param>
  600. /// <param name="result">节点信息 1.同意 2.反对 3.超时</param>
  601. /// <param name="description">处理意见</param>
  602. private void CreateTaskHistory(WfParameter parameter, WfNodeInfo wfNodeInfo, WfTaskEntity wfTaskEntity, int result, string description)
  603. {
  604. try
  605. {
  606. WfTaskHistoryEntity wfTaskHistoryEntity = new WfTaskHistoryEntity();
  607. wfTaskHistoryEntity.F_ProcessId = parameter.processId;
  608. wfTaskHistoryEntity.F_NodeId = wfNodeInfo.id;
  609. wfTaskHistoryEntity.F_NodeName = wfNodeInfo.name;
  610. wfTaskHistoryEntity.F_Result = result;
  611. wfTaskHistoryEntity.F_Description = description;
  612. if (wfTaskEntity == null)// 表示新创建流程实例
  613. {
  614. wfTaskHistoryEntity.F_TaskType = 0;
  615. }
  616. else
  617. {
  618. wfTaskHistoryEntity.F_TaskType = wfTaskEntity.F_TaskType;
  619. wfTaskHistoryEntity.F_PreviousId = wfTaskEntity.F_PreviousId;
  620. wfTaskHistoryEntity.F_PreviousName = wfTaskEntity.F_PreviousName;
  621. }
  622. wfTaskHistoryEntity.F_CreateUserId = parameter.userId;
  623. wfTaskHistoryEntity.F_CreateUserName = parameter.userName;
  624. wfTaskHistoryIBLL.SaveEntity(wfTaskHistoryEntity);
  625. }
  626. catch (Exception ex)
  627. {
  628. if (ex is ExceptionEx)
  629. {
  630. throw;
  631. }
  632. else
  633. {
  634. throw ExceptionEx.ThrowBusinessException(ex);
  635. }
  636. }
  637. }
  638. #endregion
  639. #region 执行sql语句
  640. /// <summary>
  641. /// 执行sql语句
  642. /// </summary>
  643. /// <param name="processId">流程实例Id</param>
  644. /// <param name="dbId">数据库主键ID</param>
  645. /// <param name="strSql">sql语句</param>
  646. /// <returns></returns>
  647. private bool ExecuteSql(string processId, string dbId, string strSql)
  648. {
  649. bool res = false;
  650. try
  651. {
  652. if (!string.IsNullOrEmpty(dbId) && !string.IsNullOrEmpty(strSql))
  653. {
  654. strSql = strSql.Replace("{processId}", "@processId");
  655. databaseLinkIBLL.ExecuteBySql(dbId, strSql, new { processId = processId });
  656. }
  657. res = true;
  658. }
  659. catch (Exception)
  660. {
  661. }
  662. return res;
  663. }
  664. #endregion
  665. #region 对外API
  666. /// <summary>
  667. /// 流程发起初始化接口(用于流程发起前的数据获取)
  668. /// </summary>
  669. /// <param name="parameter">流程参数</param>
  670. /// <returns></returns>
  671. public WfResult<WfContent> Bootstraper(WfParameter parameter)
  672. {
  673. WfResult<WfContent> wfResult = new WfResult<WfContent>();
  674. try
  675. {
  676. // 初始化流程模板
  677. bool res = InitScheme(parameter);
  678. if (res)
  679. {
  680. // 获取开始节点
  681. WfNodeInfo startNode = wfSchemeIBLL.GetStartNode();
  682. if (startNode == null)
  683. {
  684. wfResult.status = 2;
  685. wfResult.desc = "获取不到开始节点信息!";
  686. }
  687. else
  688. {
  689. wfResult.status = 1;
  690. wfResult.desc = "流程发起初始化成功!";
  691. wfResult.data = new WfContent();
  692. wfResult.data.currentNode = startNode;
  693. wfResult.data.scheme = wfSchemeEntity.F_Scheme;
  694. if (!parameter.isNew)
  695. {
  696. wfResult.data.currentNodeIds = wfTaskIBLL.GetCurrentNodeIds(parameter.processId);
  697. wfResult.data.history = (List<WfTaskHistoryEntity>)wfTaskHistoryIBLL.GetList(parameter.processId);
  698. }
  699. else
  700. {
  701. wfResult.data.currentNodeIds = new List<string>();
  702. wfResult.data.currentNodeIds.Add(startNode.id);
  703. }
  704. }
  705. }
  706. else
  707. {
  708. wfResult.status = 2;
  709. wfResult.desc = "获取流程模板失败!";
  710. }
  711. return wfResult;
  712. }
  713. catch (Exception ex)
  714. {
  715. if (ex is ExceptionEx)
  716. {
  717. throw;
  718. }
  719. else
  720. {
  721. throw ExceptionEx.ThrowBusinessException(ex);
  722. }
  723. }
  724. }
  725. /// <summary>
  726. /// 创建流程实例
  727. /// </summary>
  728. /// <param name="parameter">流程参数</param>
  729. /// <returns></returns>
  730. public WfResult Create(WfParameter parameter)
  731. {
  732. WfResult wfResult = new WfResult();
  733. try
  734. {
  735. // 初始化流程模板
  736. InitScheme(parameter);
  737. // 获取开始节点
  738. WfNodeInfo startNode = wfSchemeIBLL.GetStartNode();
  739. // 获取下一个节点任务
  740. List<WfTaskEntity> wfTaskList = new List<WfTaskEntity>();
  741. List<WfTaskEntity> wfReadTaskList = new List<WfTaskEntity>();
  742. GetNextTaskes(startNode, WfTransportType.Agree, wfTaskList, wfReadTaskList, parameter);
  743. // 保存一个流程实例
  744. SaveProcess(parameter);
  745. // 创建一个任务处理记录
  746. if (!parameter.isNew)
  747. {
  748. // 如果是重新发起的流程需要获取当前任务
  749. // 更新当前任务节点
  750. WfTaskEntity currentTask = wfTaskIBLL.GetEntityUnFinish(parameter.processId, startNode.id);
  751. wfTaskIBLL.UpdateStateByNodeId(parameter.processId, startNode.id, currentTask.F_Id, parameter.userId, parameter.userName);
  752. CreateTaskHistory(parameter, startNode, currentTask, 1, "【重新发起】" + parameter.description);
  753. }
  754. else
  755. {
  756. CreateTaskHistory(parameter, startNode, null, 1, "【发起】" + parameter.description);
  757. }
  758. // 记录查阅节点
  759. foreach (var wfTask in wfReadTaskList)
  760. {
  761. Dictionary<string, AuditerModel> auditers = parameter.auditers.ToObject<Dictionary<string, AuditerModel>>();
  762. if (auditers != null && auditers.ContainsKey(wfTask.F_NodeId))
  763. {
  764. wfTask.auditors = new List<WfAuditor>();
  765. WfAuditor wfAuditor = new WfAuditor()
  766. {
  767. id = Guid.NewGuid().ToString(),
  768. auditorId = auditers[wfTask.F_NodeId].userId,
  769. auditorName = auditers[wfTask.F_NodeId].userName
  770. };
  771. wfTask.auditors.Add(wfAuditor);
  772. }
  773. wfTaskIBLL.SaveEntitys(wfTask, parameter.companyId, parameter.departmentId);
  774. }
  775. if (wfTaskList.Count == 0)
  776. {
  777. // 没有任务了表示该流程已经结束了
  778. WfProcessInstanceEntity wfProcessInstanceEntity = new WfProcessInstanceEntity();
  779. wfProcessInstanceEntity.F_IsFinished = 1;
  780. wfProcessInstanceIBLL.SaveEntity(parameter.processId, wfProcessInstanceEntity);
  781. }
  782. else
  783. {
  784. // 记录下面节点任务
  785. foreach (var wfTask in wfTaskList)
  786. {
  787. Dictionary<string, AuditerModel> auditers = parameter.auditers.ToObject<Dictionary<string, AuditerModel>>();
  788. if (auditers != null && auditers.ContainsKey(wfTask.F_NodeId)) {
  789. wfTask.auditors = new List<WfAuditor>();
  790. WfAuditor wfAuditor = new WfAuditor()
  791. {
  792. id = Guid.NewGuid().ToString(),
  793. auditorId = auditers[wfTask.F_NodeId].userId,
  794. auditorName = auditers[wfTask.F_NodeId].userName
  795. };
  796. wfTask.auditors.Add(wfAuditor);
  797. }
  798. wfTaskIBLL.SaveEntitys(wfTask, parameter.companyId, parameter.departmentId);
  799. if (wfTask.F_TaskType == 2)
  800. {
  801. WfProcessInstanceEntity wfProcessInstanceEntity = new WfProcessInstanceEntity();
  802. wfProcessInstanceEntity.F_IsAgain = 1;
  803. wfProcessInstanceIBLL.SaveEntity(parameter.processId, wfProcessInstanceEntity);
  804. }
  805. }
  806. }
  807. wfResult.status = 1;
  808. wfResult.desc = "创建流程成功";
  809. // 触发执行sql语句
  810. if (!ExecuteSql(parameter.processId, startNode.dbSuccessId, startNode.dbSuccessSql))
  811. {
  812. CreateTaskHistory(parameter, startNode, null, 1, "新发起一个流程实例【执行sql语句异常】");
  813. }
  814. // 触发接口方法
  815. if (!string.IsNullOrEmpty(startNode.iocName))
  816. {
  817. INodeMethod iNodeMethod = UnityIocHelper.WfInstance.GetService<INodeMethod>(startNode.iocName);
  818. iNodeMethod.Sucess(parameter.processId);
  819. }
  820. return wfResult;
  821. }
  822. catch (Exception ex)
  823. {
  824. if (ex is ExceptionEx)
  825. {
  826. throw;
  827. }
  828. else
  829. {
  830. throw ExceptionEx.ThrowBusinessException(ex);
  831. }
  832. }
  833. }
  834. /// <summary>
  835. /// 审核流程节点
  836. /// </summary>
  837. /// <param name="parameter">流程参数verifyType:1.审核同意2.审核不同意3.加签4.加签-同意5.加签-不同意6.确认阅读7.保存草稿</param>
  838. /// <returns></returns>
  839. public WfResult Audit(WfParameter parameter)
  840. {
  841. WfResult wfResult = new WfResult();
  842. try
  843. {
  844. WfTaskEntity currentTask = wfTaskIBLL.GetEntity(parameter.taskId);
  845. if (currentTask == null)
  846. {
  847. wfResult.desc = "找不到当前任务信息";
  848. wfResult.status = 2;
  849. }
  850. else if (currentTask.F_IsFinished == 1)
  851. {
  852. wfResult.desc = "当前任务已经被处理完";
  853. wfResult.status = 2;
  854. }
  855. else {
  856. // 初始化流程模板
  857. parameter.processId = currentTask.F_ProcessId;
  858. parameter.isNew = false;
  859. InitScheme(parameter);
  860. WfNodeInfo currentNode = wfSchemeIBLL.GetNode(currentTask.F_NodeId);
  861. if (currentNode == null)
  862. {
  863. wfResult.desc = "获取不到当前审核节点信息,请检查流程模板是否被改动";
  864. wfResult.status = 2;
  865. }
  866. else
  867. {
  868. // 获取下一个节点任务
  869. List<WfTaskEntity> wfTaskList = new List<WfTaskEntity>();
  870. List<WfTaskEntity> wfReadTaskList = new List<WfTaskEntity>();
  871. bool res = true;
  872. switch (parameter.verifyType)//1.审核同意2.审核不同意3.加签4.加签-同意5.加签-不同意6.确认阅读7.保存草稿(暂时不做处理)
  873. {
  874. case "1":
  875. res = GetNextTaskes(currentNode, WfTransportType.Agree, wfTaskList, wfReadTaskList, parameter);
  876. CreateTaskHistory(parameter, currentNode, currentTask, 1, parameter.description);
  877. wfResult.desc = "流程审核成功";
  878. break;
  879. case "2":
  880. res = GetNextTaskes(currentNode, WfTransportType.Disagree, wfTaskList, wfReadTaskList, parameter);
  881. CreateTaskHistory(parameter, currentNode, currentTask, 2, parameter.description);
  882. wfResult.desc = "流程审核成功";
  883. break;
  884. case "3":
  885. // 创建一个任务节点
  886. WfTaskEntity taskEntity = CreateTaskSign(currentNode, parameter);
  887. wfTaskList.Add(taskEntity);
  888. parameter.description = "请【" + parameter.auditorName + "】审核;" + parameter.description;
  889. currentTask.F_TaskType = 4;
  890. CreateTaskHistory(parameter, currentNode, currentTask, 1, parameter.description);
  891. wfResult.desc = "流程加签成功";
  892. break;
  893. case "4":
  894. res = GetNextTaskes(currentNode, WfTransportType.Agree, wfTaskList, wfReadTaskList, parameter);
  895. parameter.description = "【加签】"+parameter.description;
  896. currentTask.F_TaskType = 1;
  897. CreateTaskHistory(parameter, currentNode, currentTask, 1, parameter.description);
  898. wfResult.desc = "流程审核成功";
  899. break;
  900. case "5":
  901. WfTaskEntity taskEntity2 = CreateTask(currentNode, currentNode, parameter);
  902. wfTaskList.Add(taskEntity2);
  903. parameter.description = "【加签】"+parameter.description;
  904. currentTask.F_TaskType = 1;
  905. CreateTaskHistory(parameter, currentNode, currentTask, 2, parameter.description);
  906. wfResult.desc = "流程审核成功";
  907. break;
  908. case "6":
  909. res = GetNextTaskes(currentNode, WfTransportType.Agree, wfTaskList, wfReadTaskList, parameter);
  910. CreateTaskHistory(parameter, currentNode, currentTask, 1, parameter.description);
  911. wfResult.desc = "流程确认成功";
  912. break;
  913. }
  914. // 更新当前任务节点
  915. wfTaskIBLL.UpdateStateByNodeId(currentTask.F_ProcessId, currentTask.F_NodeId, currentTask.F_Id, parameter.userId, parameter.userName);
  916. if (parameter.verifyType == "6")
  917. {
  918. wfResult.status = 1;
  919. return wfResult;
  920. }
  921. // 记录查阅节点
  922. foreach (var wfTask in wfReadTaskList)
  923. {
  924. Dictionary<string, AuditerModel> auditers = parameter.auditers.ToObject<Dictionary<string, AuditerModel>>();
  925. if (auditers != null && auditers.ContainsKey(wfTask.F_NodeId))
  926. {
  927. wfTask.auditors = new List<WfAuditor>();
  928. WfAuditor wfAuditor = new WfAuditor()
  929. {
  930. id = Guid.NewGuid().ToString(),
  931. auditorId = auditers[wfTask.F_NodeId].userId,
  932. auditorName = auditers[wfTask.F_NodeId].userName
  933. };
  934. wfTask.auditors.Add(wfAuditor);
  935. }
  936. wfTaskIBLL.SaveEntitys(wfTask, processCreater.F_CompanyId, processCreater.F_DepartmentId);
  937. }
  938. if (wfTaskList.Count == 0)
  939. {
  940. // 没有任务了表示该流程已经结束了
  941. WfProcessInstanceEntity wfProcessInstanceEntity = new WfProcessInstanceEntity();
  942. wfProcessInstanceEntity.F_IsFinished = 1;
  943. wfProcessInstanceIBLL.SaveEntity(parameter.processId, wfProcessInstanceEntity);
  944. }
  945. else
  946. {
  947. // 记录下面节点任务
  948. foreach (var wfTask in wfTaskList)
  949. {
  950. if (wfTask.auditors != null)
  951. {
  952. switch (parameter.verifyType)//1.审核同意2.审核不同意3.加签4.加签-同意5.加签-不同意6.确认阅读7.保存草稿(暂时不做处理)
  953. {
  954. case "1":
  955. case "4":
  956. case "5":
  957. Dictionary<string, AuditerModel> auditers = parameter.auditers.ToObject<Dictionary<string, AuditerModel>>();
  958. if (auditers != null && auditers.ContainsKey(wfTask.F_NodeId))
  959. {
  960. wfTask.auditors = new List<WfAuditor>();
  961. WfAuditor wfAuditor = new WfAuditor()
  962. {
  963. id = Guid.NewGuid().ToString(),
  964. auditorId = auditers[wfTask.F_NodeId].userId,
  965. auditorName = auditers[wfTask.F_NodeId].userName
  966. };
  967. wfTask.auditors.Add(wfAuditor);
  968. }
  969. break;
  970. case "2": // 驳回,原来谁审核就谁审核
  971. WfTaskEntity _wfTaskEntity = wfTaskIBLL.GetEntity(parameter.processId, wfTask.F_NodeId);
  972. if (_wfTaskEntity != null)
  973. {
  974. wfTask.auditors = new List<WfAuditor>();
  975. WfAuditor wfAuditor = new WfAuditor()
  976. {
  977. id = Guid.NewGuid().ToString(),
  978. auditorId = _wfTaskEntity.F_ModifyUserId,
  979. auditorName = _wfTaskEntity.F_ModifyUserName
  980. };
  981. wfTask.auditors.Add(wfAuditor);
  982. }
  983. break;
  984. }
  985. wfTaskIBLL.SaveEntitys(wfTask, processCreater.F_CompanyId, processCreater.F_DepartmentId);
  986. if (wfTask.F_TaskType == 2)
  987. {
  988. WfProcessInstanceEntity wfProcessInstanceEntity = new WfProcessInstanceEntity();
  989. wfProcessInstanceEntity.F_IsAgain = 1;
  990. wfProcessInstanceIBLL.SaveEntity(parameter.processId, wfProcessInstanceEntity);
  991. }
  992. }
  993. }
  994. }
  995. #region 执行sql语句触发
  996. int _res = 1;
  997. switch (parameter.verifyType)//1.审核同意2.审核不同意3.加签4.加签-同意5.加签-不同意6.确认阅读7.保存草稿(暂时不做处理)
  998. {
  999. case "1":
  1000. case "4":
  1001. case "6":
  1002. if (!ExecuteSql(parameter.processId, currentNode.dbSuccessId, currentNode.dbSuccessSql))
  1003. {
  1004. CreateTaskHistory(parameter, currentNode, currentTask, 1, parameter.description + "【执行sql语句异常】");
  1005. }
  1006. // 触发接口方法
  1007. if (!string.IsNullOrEmpty(currentNode.iocName))
  1008. {
  1009. INodeMethod iNodeMethod = UnityIocHelper.WfInstance.GetService<INodeMethod>(currentNode.iocName);
  1010. iNodeMethod.Sucess(parameter.processId);
  1011. }
  1012. break;
  1013. case "2":
  1014. case "5":
  1015. _res = 2;
  1016. if (!ExecuteSql(parameter.processId, currentNode.dbFailId, currentNode.dbFailSql))
  1017. {
  1018. CreateTaskHistory(parameter, currentNode, currentTask, 2, parameter.description + "【执行sql语句异常】");
  1019. }
  1020. // 触发接口方法
  1021. if (!string.IsNullOrEmpty(currentNode.iocName))
  1022. {
  1023. INodeMethod iNodeMethod = UnityIocHelper.WfInstance.GetService<INodeMethod>(currentNode.iocName);
  1024. iNodeMethod.Fail(parameter.processId);
  1025. }
  1026. break;
  1027. }
  1028. // 会签
  1029. if (!ExecuteSql(parameter.processId, currentNode.cfDbId, currentNode.cfDbSql))
  1030. {
  1031. CreateTaskHistory(parameter, currentNode, currentTask, _res, parameter.description + "【执行sql语句异常】");
  1032. }
  1033. // 触发接口方法
  1034. if (!string.IsNullOrEmpty(currentNode.cfIocName))
  1035. {
  1036. INodeMethod iNodeMethod = UnityIocHelper.WfInstance.GetService<INodeMethod>(currentNode.cfIocName);
  1037. if (currentNode.cfres)
  1038. {
  1039. iNodeMethod.Sucess(parameter.processId);
  1040. }
  1041. else
  1042. {
  1043. iNodeMethod.Fail(parameter.processId);
  1044. }
  1045. }
  1046. #endregion
  1047. wfResult.status = 1;
  1048. }
  1049. }
  1050. return wfResult;
  1051. }
  1052. catch (Exception ex)
  1053. {
  1054. if (ex is ExceptionEx)
  1055. {
  1056. throw;
  1057. }
  1058. else
  1059. {
  1060. throw ExceptionEx.ThrowBusinessException(ex);
  1061. }
  1062. }
  1063. }
  1064. /// <summary>
  1065. /// 获取下一个节点审核者信息
  1066. /// </summary>
  1067. /// <param name="parameter"></param>
  1068. /// <returns></returns>
  1069. public WfResult<List<object>> GetAuditer(WfParameter parameter)
  1070. {
  1071. WfResult<List<object>> wfResult = new WfResult<List<object>>();
  1072. string companyId = parameter.companyId;
  1073. string departmentId = parameter.departmentId;
  1074. try
  1075. {
  1076. // 获取下一个节点任务
  1077. List<WfTaskEntity> wfTaskList = new List<WfTaskEntity>();
  1078. List<WfTaskEntity> wfReadTaskList = new List<WfTaskEntity>();
  1079. parameter.isGetAuditer = true;
  1080. // 获取下一节点
  1081. if (parameter.isNew)// 开始发起节点的人
  1082. {
  1083. // 初始化流程模板
  1084. InitScheme(parameter);
  1085. // 获取开始节点
  1086. WfNodeInfo startNode = wfSchemeIBLL.GetStartNode();
  1087. GetNextTaskes(startNode, WfTransportType.Agree, wfTaskList, wfReadTaskList, parameter);
  1088. }
  1089. else
  1090. {
  1091. if (!string.IsNullOrEmpty(parameter.taskId))// 审核节点
  1092. {
  1093. WfTaskEntity currentTask = wfTaskIBLL.GetEntity(parameter.taskId);
  1094. parameter.processId = currentTask.F_ProcessId;
  1095. InitScheme(parameter);
  1096. companyId = processCreater.F_CompanyId;
  1097. departmentId = processCreater.F_DepartmentId;
  1098. WfNodeInfo currentNode = wfSchemeIBLL.GetNode(currentTask.F_NodeId);
  1099. GetNextTaskes(currentNode, WfTransportType.Agree, wfTaskList, wfReadTaskList, parameter);
  1100. }
  1101. else {// 重新发起节点
  1102. InitScheme(parameter);
  1103. WfNodeInfo startNode = wfSchemeIBLL.GetStartNode();
  1104. GetNextTaskes(startNode, WfTransportType.Agree, wfTaskList, wfReadTaskList, parameter);
  1105. }
  1106. }
  1107. if (wfTaskList.Count <= 0 && wfReadTaskList.Count <= 0)
  1108. {
  1109. wfResult.status = 3;// 表示没有一下节点
  1110. }
  1111. else
  1112. {
  1113. wfResult.status = 1;// 表示有一下节点
  1114. List<object> list = new List<object>();
  1115. wfResult.data = list;
  1116. foreach (var item in wfReadTaskList)
  1117. {
  1118. if (item.auditors.Count > 0)
  1119. {
  1120. var data = new
  1121. {
  1122. auditors = item.auditors,
  1123. name = item.F_NodeName,
  1124. companyId = companyId,
  1125. departmentId = departmentId,
  1126. nodeId = item.F_NodeId,
  1127. };
  1128. list.Add(data);
  1129. }
  1130. else
  1131. {
  1132. var data = new
  1133. {
  1134. all = true,
  1135. name = item.F_NodeName,
  1136. nodeId = item.F_NodeId
  1137. };
  1138. list.Add(data);
  1139. }
  1140. }
  1141. foreach (var item in wfTaskList)
  1142. {
  1143. if (item.auditors.Count > 0)
  1144. {
  1145. var data = new
  1146. {
  1147. auditors = item.auditors,
  1148. name = item.F_NodeName,
  1149. companyId = companyId,
  1150. departmentId = departmentId,
  1151. nodeId = item.F_NodeId,
  1152. };
  1153. list.Add(data);
  1154. }
  1155. else
  1156. {
  1157. var data = new
  1158. {
  1159. all = true,
  1160. name = item.F_NodeName,
  1161. nodeId = item.F_NodeId
  1162. };
  1163. list.Add(data);
  1164. }
  1165. }
  1166. }
  1167. return wfResult;
  1168. }
  1169. catch (Exception ex)
  1170. {
  1171. if (ex is ExceptionEx)
  1172. {
  1173. throw;
  1174. }
  1175. else
  1176. {
  1177. throw ExceptionEx.ThrowBusinessException(ex);
  1178. }
  1179. }
  1180. }
  1181. /// <summary>
  1182. /// 获取某个任务节点的信息
  1183. /// </summary>
  1184. /// <param name="parameter">流程参数</param>
  1185. /// <returns></returns>
  1186. public WfResult<WfContent> GetTaskInfo(WfParameter parameter)
  1187. {
  1188. WfResult<WfContent> wfResult = new WfResult<WfContent>();
  1189. try
  1190. {
  1191. // 初始化模板信息
  1192. bool res = InitScheme(parameter);
  1193. if (res)
  1194. {
  1195. // 获取任务实体信息
  1196. WfTaskEntity wfTaskEntity = wfTaskIBLL.GetEntity(parameter.taskId);
  1197. if (wfTaskEntity.F_IsFinished != 0)
  1198. {
  1199. wfResult.status = 2;
  1200. wfResult.desc = "该任务已经处理!";
  1201. }
  1202. else
  1203. {
  1204. // 获取任务所在节点信息
  1205. WfNodeInfo currentNode = wfSchemeIBLL.GetNode(wfTaskEntity.F_NodeId);
  1206. if (currentNode == null)
  1207. {
  1208. wfResult.status = 2;
  1209. wfResult.desc = "获取不到节点信息!";
  1210. }
  1211. else
  1212. {
  1213. wfResult.status = 1;
  1214. wfResult.desc = "获取流程任务信息成功!";
  1215. wfResult.data = new WfContent();
  1216. wfResult.data.currentNodeIds = wfTaskIBLL.GetCurrentNodeIds(parameter.processId);
  1217. wfResult.data.currentNode = currentNode;
  1218. // 获取下一个节点所有审核者信息
  1219. //List<WfTaskEntity> wfTaskList = new List<WfTaskEntity>();
  1220. //res = GetNextTaskes(currentNode, WfTransportType.Agree, wfTaskList, parameter);
  1221. wfResult.data.scheme = wfSchemeEntity.F_Scheme;
  1222. if (!parameter.isNew)
  1223. {
  1224. wfResult.data.history = (List<WfTaskHistoryEntity>)wfTaskHistoryIBLL.GetList(parameter.processId);
  1225. }
  1226. }
  1227. }
  1228. }
  1229. else
  1230. {
  1231. wfResult.status = 2;
  1232. wfResult.desc = "获取流程模板失败!";
  1233. }
  1234. return wfResult;
  1235. }
  1236. catch (Exception ex)
  1237. {
  1238. if (ex is ExceptionEx)
  1239. {
  1240. throw;
  1241. }
  1242. else
  1243. {
  1244. throw ExceptionEx.ThrowBusinessException(ex);
  1245. }
  1246. }
  1247. }
  1248. /// <summary>
  1249. /// 获取流程实例信息
  1250. /// </summary>
  1251. /// <param name="parameter">流程参数</param>
  1252. /// <returns></returns>
  1253. public WfResult<WfContent> GetProcessInfo(WfParameter parameter)
  1254. {
  1255. WfResult<WfContent> wfResult = new WfResult<WfContent>();
  1256. try
  1257. {
  1258. // 初始化模板信息
  1259. bool res = InitScheme(parameter);
  1260. if (res)
  1261. {
  1262. // 获取任务实体信息
  1263. WfTaskEntity wfTaskEntity;
  1264. WfNodeInfo currentNode;
  1265. WfNodeInfo startNode = wfSchemeIBLL.GetStartNode();
  1266. if (!string.IsNullOrEmpty(parameter.taskId))
  1267. {
  1268. wfTaskEntity = wfTaskIBLL.GetEntity(parameter.taskId);
  1269. }
  1270. else
  1271. {
  1272. wfTaskEntity = wfTaskIBLL.GetEntity(parameter.processId, startNode.id);
  1273. }
  1274. // 获取任务所在节点信息
  1275. if (wfTaskEntity != null)
  1276. {
  1277. currentNode = wfSchemeIBLL.GetNode(wfTaskEntity.F_NodeId);
  1278. }
  1279. else
  1280. {
  1281. currentNode = wfSchemeIBLL.GetNode(startNode.id);
  1282. }
  1283. if (currentNode == null)
  1284. {
  1285. wfResult.status = 2;
  1286. wfResult.desc = "获取不到节点信息!";
  1287. }
  1288. else
  1289. {
  1290. wfResult.status = 1;
  1291. wfResult.desc = "获取流程实例数据成功!";
  1292. wfResult.data = new WfContent();
  1293. wfResult.data.currentNodeIds = wfTaskIBLL.GetCurrentNodeIds(parameter.processId);
  1294. wfResult.data.currentNode = currentNode;
  1295. wfResult.data.scheme = wfSchemeEntity.F_Scheme;
  1296. wfResult.data.history = (List<WfTaskHistoryEntity>)wfTaskHistoryIBLL.GetList(parameter.processId);
  1297. }
  1298. }
  1299. else
  1300. {
  1301. wfResult.status = 2;
  1302. wfResult.desc = "获取流程模板失败!";
  1303. }
  1304. return wfResult;
  1305. }
  1306. catch (Exception ex)
  1307. {
  1308. if (ex is ExceptionEx)
  1309. {
  1310. throw;
  1311. }
  1312. else
  1313. {
  1314. throw ExceptionEx.ThrowBusinessException(ex);
  1315. }
  1316. }
  1317. }
  1318. /// <summary>
  1319. /// 获取流程实例信息(流程监控)
  1320. /// </summary>
  1321. /// <param name="parameter">流程参数</param>
  1322. /// <returns></returns>
  1323. public WfResult<WfContent> GetProcessInfoByMonitor(WfParameter parameter)
  1324. {
  1325. WfResult<WfContent> wfResult = new WfResult<WfContent>();
  1326. try
  1327. {
  1328. // 初始化模板信息
  1329. bool res = InitScheme(parameter);
  1330. if (res)
  1331. {
  1332. // 获取任务实体信息
  1333. WfTaskEntity wfTaskEntity;
  1334. WfNodeInfo currentNode;
  1335. WfNodeInfo startNode = wfSchemeIBLL.GetStartNode();
  1336. var currentNodeIds = wfTaskIBLL.GetCurrentNodeIds(parameter.processId);
  1337. if (!string.IsNullOrEmpty(parameter.taskId))
  1338. {
  1339. wfTaskEntity = wfTaskIBLL.GetEntity(parameter.taskId);
  1340. }
  1341. else
  1342. {
  1343. wfTaskEntity = wfTaskIBLL.GetEntity(parameter.processId, currentNodeIds[0]);
  1344. }
  1345. // 获取任务所在节点信息
  1346. if (wfTaskEntity != null)
  1347. {
  1348. currentNode = wfSchemeIBLL.GetNode(wfTaskEntity.F_NodeId);
  1349. }
  1350. else
  1351. {
  1352. currentNode = wfSchemeIBLL.GetNode(startNode.id);
  1353. }
  1354. if (currentNode == null)
  1355. {
  1356. wfResult.status = 2;
  1357. wfResult.desc = "获取不到节点信息!";
  1358. }
  1359. else
  1360. {
  1361. wfResult.status = 1;
  1362. wfResult.desc = "获取流程实例数据成功!";
  1363. wfResult.data = new WfContent();
  1364. wfResult.data.currentNodeIds = currentNodeIds;
  1365. wfResult.data.currentNode = currentNode;
  1366. wfResult.data.scheme = wfSchemeEntity.F_Scheme;
  1367. wfResult.data.history = (List<WfTaskHistoryEntity>)wfTaskHistoryIBLL.GetList(parameter.processId);
  1368. }
  1369. }
  1370. else
  1371. {
  1372. wfResult.status = 2;
  1373. wfResult.desc = "获取流程模板失败!";
  1374. }
  1375. return wfResult;
  1376. }
  1377. catch (Exception ex)
  1378. {
  1379. if (ex is ExceptionEx)
  1380. {
  1381. throw;
  1382. }
  1383. else
  1384. {
  1385. throw ExceptionEx.ThrowBusinessException(ex);
  1386. }
  1387. }
  1388. }
  1389. #endregion
  1390. }
  1391. }