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.
 
 
 
 
 
 

713 lines
22 KiB

  1. using Learun.Cache.Base;
  2. using Learun.Cache.Factory;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Learun.Application.WorkFlow
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.04.17
  13. /// 描 述:工作流模板处理
  14. /// </summary>
  15. public class WfSchemeBLL : WfSchemeIBLL
  16. {
  17. private WfSchemeService wfSchemeService = new WfSchemeService();
  18. #region 缓存定义
  19. private ICache cache = CacheFactory.CaChe();
  20. private string cacheKey = "Learun_adms_wfscheme_";// +模板主键
  21. #endregion
  22. #region 获取数据
  23. /// <summary>
  24. /// 获取流程分页列表
  25. /// </summary>
  26. /// <param name="pagination">分页参数</param>
  27. /// <param name="keyword">关键字</param>
  28. /// <param name="category">分类</param>
  29. /// <returns></returns>
  30. public IEnumerable<WfSchemeInfoEntity> GetSchemeInfoPageList(Pagination pagination, string keyword, string category)
  31. {
  32. try
  33. {
  34. return wfSchemeService.GetSchemeInfoPageList(pagination, keyword, category);
  35. }
  36. catch (Exception ex)
  37. {
  38. if (ex is ExceptionEx)
  39. {
  40. throw;
  41. }
  42. else
  43. {
  44. throw ExceptionEx.ThrowBusinessException(ex);
  45. }
  46. }
  47. }
  48. /// <summary>
  49. /// 获取流程模板分页列表
  50. /// </summary>
  51. /// <param name="pagination">分页参数</param>
  52. /// <param name="userInfo">登录者信息</param>
  53. /// <param name="queryJson">查询参数</param>
  54. /// <returns></returns>
  55. public IEnumerable<WfSchemeInfoEntity> GetAppSchemeInfoPageList(Pagination pagination, UserInfo userInfo, string queryJson)
  56. {
  57. try
  58. {
  59. return wfSchemeService.GetAppSchemeInfoPageList(pagination, userInfo, queryJson);
  60. }
  61. catch (Exception ex)
  62. {
  63. if (ex is ExceptionEx)
  64. {
  65. throw;
  66. }
  67. else
  68. {
  69. throw ExceptionEx.ThrowBusinessException(ex);
  70. }
  71. }
  72. }
  73. /// <summary>
  74. /// 获取自定义流程列表
  75. /// </summary>
  76. /// <param name="userInfo">用户信息</param>
  77. /// <returns></returns>
  78. public IEnumerable<WfSchemeInfoEntity> GetCustmerSchemeInfoList(UserInfo userInfo)
  79. {
  80. try
  81. {
  82. return wfSchemeService.GetCustmerSchemeInfoList(userInfo);
  83. }
  84. catch (Exception ex)
  85. {
  86. if (ex is ExceptionEx)
  87. {
  88. throw;
  89. }
  90. else
  91. {
  92. throw ExceptionEx.ThrowBusinessException(ex);
  93. }
  94. }
  95. }
  96. /// <summary>
  97. /// 获取自定义流程列表(app)
  98. /// </summary>
  99. /// <param name="userInfo">用户信息</param>
  100. /// <returns></returns>
  101. public IEnumerable<WfSchemeInfoEntity> GetAppCustmerSchemeInfoList(UserInfo userInfo)
  102. {
  103. try
  104. {
  105. return wfSchemeService.GetAppCustmerSchemeInfoList(userInfo);
  106. }
  107. catch (Exception ex)
  108. {
  109. if (ex is ExceptionEx)
  110. {
  111. throw;
  112. }
  113. else
  114. {
  115. throw ExceptionEx.ThrowBusinessException(ex);
  116. }
  117. }
  118. }
  119. /// <summary>
  120. /// 获取模板列表
  121. /// </summary>
  122. /// <param name="schemeInfoId">模板信息主键</param>
  123. /// <returns></returns>
  124. public IEnumerable<WfSchemeEntity> GetWfSchemeList(string schemeInfoId)
  125. {
  126. try
  127. {
  128. return wfSchemeService.GetWfSchemeList(schemeInfoId);
  129. }
  130. catch (Exception ex)
  131. {
  132. if (ex is ExceptionEx)
  133. {
  134. throw;
  135. }
  136. else
  137. {
  138. throw ExceptionEx.ThrowBusinessException(ex);
  139. }
  140. }
  141. }
  142. /// <summary>
  143. /// 获取模板列表
  144. /// </summary>
  145. /// <param name="pagination">分页参数</param>
  146. /// <param name="schemeInfoId">模板信息主键</param>
  147. /// <returns></returns>
  148. public IEnumerable<WfSchemeEntity> GetSchemePageList(Pagination pagination, string schemeInfoId)
  149. {
  150. try
  151. {
  152. return wfSchemeService.GetSchemePageList(pagination, schemeInfoId);
  153. }
  154. catch (Exception ex)
  155. {
  156. if (ex is ExceptionEx)
  157. {
  158. throw;
  159. }
  160. else
  161. {
  162. throw ExceptionEx.ThrowBusinessException(ex);
  163. }
  164. }
  165. }
  166. /// <summary>
  167. /// 获取模板基础信息的实体
  168. /// </summary>
  169. /// <param name="code">流程编号</param>
  170. /// <returns></returns>
  171. public WfSchemeInfoEntity GetWfSchemeInfoEntityByCode(string code)
  172. {
  173. try
  174. {
  175. WfSchemeInfoEntity wfSchemeInfoEntity = cache.Read<WfSchemeInfoEntity>(cacheKey + code, CacheId.workflow);
  176. if (wfSchemeInfoEntity == null)
  177. {
  178. wfSchemeInfoEntity = wfSchemeService.GetWfSchemeInfoEntityByCode(code);
  179. cache.Write<WfSchemeInfoEntity>(cacheKey + code, wfSchemeInfoEntity, CacheId.workflow);
  180. }
  181. return wfSchemeInfoEntity;
  182. }
  183. catch (Exception ex)
  184. {
  185. if (ex is ExceptionEx)
  186. {
  187. throw;
  188. }
  189. else
  190. {
  191. throw ExceptionEx.ThrowBusinessException(ex);
  192. }
  193. }
  194. }
  195. /// <summary>
  196. /// 获取模板的实体
  197. /// </summary>
  198. /// <param name="keyValue">主键</param>
  199. /// <returns></returns>
  200. public WfSchemeEntity GetWfSchemeEntity(string keyValue)
  201. {
  202. try
  203. {
  204. WfSchemeEntity wfSchemeEntity = cache.Read<WfSchemeEntity>(cacheKey + keyValue, CacheId.workflow);
  205. if (wfSchemeEntity == null)
  206. {
  207. wfSchemeEntity = wfSchemeService.GetWfSchemeEntity(keyValue);
  208. cache.Write<WfSchemeEntity>(cacheKey + keyValue, wfSchemeEntity, CacheId.workflow);
  209. }
  210. return wfSchemeEntity;
  211. }
  212. catch (Exception ex)
  213. {
  214. if (ex is ExceptionEx)
  215. {
  216. throw;
  217. }
  218. else
  219. {
  220. throw ExceptionEx.ThrowBusinessException(ex);
  221. }
  222. }
  223. }
  224. /// <summary>
  225. /// 获取模板的实体通过流程编号
  226. /// </summary>
  227. /// <param name="code">流程编号</param>
  228. /// <returns></returns>
  229. public WfSchemeEntity GetWfSchemeEntityByCode(string code)
  230. {
  231. try
  232. {
  233. WfSchemeInfoEntity wfSchemeInfoEntity = GetWfSchemeInfoEntityByCode(code);
  234. WfSchemeEntity wfSchemeEntity = cache.Read<WfSchemeEntity>(cacheKey + wfSchemeInfoEntity.F_SchemeId, CacheId.workflow);
  235. if (wfSchemeEntity == null)
  236. {
  237. wfSchemeEntity = wfSchemeService.GetWfSchemeEntity(wfSchemeInfoEntity.F_SchemeId);
  238. cache.Write<WfSchemeEntity>(cacheKey + wfSchemeInfoEntity.F_SchemeId, wfSchemeEntity, CacheId.workflow);
  239. }
  240. return wfSchemeEntity;
  241. }
  242. catch (Exception ex)
  243. {
  244. if (ex is ExceptionEx)
  245. {
  246. throw;
  247. }
  248. else
  249. {
  250. throw ExceptionEx.ThrowBusinessException(ex);
  251. }
  252. }
  253. }
  254. /// <summary>
  255. /// 获取流程模板权限列表
  256. /// </summary>
  257. /// <param name="schemeInfoId">模板信息主键</param>
  258. /// <returns></returns>
  259. public IEnumerable<WfSchemeAuthorizeEntity> GetWfSchemeAuthorizeList(string schemeInfoId)
  260. {
  261. try
  262. {
  263. return wfSchemeService.GetWfSchemeAuthorizeList(schemeInfoId);
  264. }
  265. catch (Exception ex)
  266. {
  267. if (ex is ExceptionEx)
  268. {
  269. throw;
  270. }
  271. else
  272. {
  273. throw ExceptionEx.ThrowBusinessException(ex);
  274. }
  275. }
  276. }
  277. #endregion
  278. #region 提交数据
  279. /// <summary>
  280. /// 虚拟删除模板信息
  281. /// </summary>
  282. /// <param name="keyValue">主键</param>
  283. public void VirtualDelete(string keyValue)
  284. {
  285. try
  286. {
  287. WfSchemeInfoEntity wfSchemeInfoEntity = wfSchemeService.GetWfSchemeInfoEntity(keyValue);
  288. cache.Remove(cacheKey + wfSchemeInfoEntity.F_Code, CacheId.workflow);
  289. cache.Remove(cacheKey + wfSchemeInfoEntity.F_SchemeId, CacheId.workflow);
  290. wfSchemeService.VirtualDelete(keyValue);
  291. }
  292. catch (Exception ex)
  293. {
  294. if (ex is ExceptionEx)
  295. {
  296. throw;
  297. }
  298. else
  299. {
  300. throw ExceptionEx.ThrowBusinessException(ex);
  301. }
  302. }
  303. }
  304. /// <summary>
  305. /// 保存模板信息
  306. /// </summary>
  307. /// <param name="keyValue">主键</param>
  308. /// <param name="wfSchemeInfoEntity">模板基础信息</param>
  309. /// <param name="wfSchemeEntity">模板信息</param>
  310. public void SaveEntity(string keyValue, WfSchemeInfoEntity wfSchemeInfoEntity, WfSchemeEntity wfSchemeEntity, List<WfSchemeAuthorizeEntity> wfSchemeAuthorizeList)
  311. {
  312. try
  313. {
  314. if (!string.IsNullOrEmpty(keyValue))
  315. {
  316. WfSchemeEntity wfSchemeEntityOld = GetWfSchemeEntity(wfSchemeInfoEntity.F_SchemeId);
  317. if (wfSchemeEntityOld.F_Scheme == wfSchemeEntity.F_Scheme && wfSchemeEntityOld.F_Type == wfSchemeEntity.F_Type)
  318. {
  319. wfSchemeEntity = null;
  320. }
  321. cache.Remove(cacheKey + wfSchemeInfoEntity.F_Code, CacheId.workflow);
  322. cache.Remove(cacheKey + wfSchemeInfoEntity.F_SchemeId, CacheId.workflow);
  323. }
  324. wfSchemeService.SaveEntity(keyValue, wfSchemeInfoEntity, wfSchemeEntity, wfSchemeAuthorizeList);
  325. }
  326. catch (Exception ex)
  327. {
  328. if (ex is ExceptionEx)
  329. {
  330. throw;
  331. }
  332. else
  333. {
  334. throw ExceptionEx.ThrowBusinessException(ex);
  335. }
  336. }
  337. }
  338. /// <summary>
  339. /// 更新流程模板
  340. /// </summary>
  341. /// <param name="schemeInfoId">模板信息主键</param>
  342. /// <param name="schemeId">模板主键</param>
  343. public void UpdateScheme(string schemeInfoId, string schemeId)
  344. {
  345. try
  346. {
  347. WfSchemeInfoEntity wfSchemeInfoEntity = wfSchemeService.GetWfSchemeInfoEntity(schemeInfoId);
  348. cache.Remove(cacheKey + wfSchemeInfoEntity.F_Code, CacheId.workflow);
  349. cache.Remove(cacheKey + wfSchemeInfoEntity.F_SchemeId, CacheId.workflow);
  350. wfSchemeService.UpdateScheme(schemeInfoId, schemeId);
  351. }
  352. catch (Exception ex)
  353. {
  354. if (ex is ExceptionEx)
  355. {
  356. throw;
  357. }
  358. else
  359. {
  360. throw ExceptionEx.ThrowBusinessException(ex);
  361. }
  362. }
  363. }
  364. /// <summary>
  365. /// 保存模板基础信息
  366. /// </summary>
  367. /// <param name="keyValue">主键</param>
  368. /// <param name="schemeInfoEntity">模板基础信息</param>
  369. public void SaveSchemeInfoEntity(string keyValue, WfSchemeInfoEntity schemeInfoEntity)
  370. {
  371. try
  372. {
  373. wfSchemeService.SaveSchemeInfoEntity(keyValue, schemeInfoEntity);
  374. }
  375. catch (Exception ex)
  376. {
  377. if (ex is ExceptionEx)
  378. {
  379. throw;
  380. }
  381. else
  382. {
  383. throw ExceptionEx.ThrowBusinessException(ex);
  384. }
  385. }
  386. }
  387. /// <summary>
  388. /// 更新自定义表单模板状态
  389. /// </summary>
  390. /// <param name="schemeInfoId">模板信息主键</param>
  391. /// <param name="state">状态1启用0禁用</param>
  392. public void UpdateState(string schemeInfoId, int state)
  393. {
  394. try
  395. {
  396. wfSchemeService.UpdateState(schemeInfoId, state);
  397. }
  398. catch (Exception ex)
  399. {
  400. if (ex is ExceptionEx)
  401. {
  402. throw;
  403. }
  404. else
  405. {
  406. throw ExceptionEx.ThrowBusinessException(ex);
  407. }
  408. }
  409. }
  410. #endregion
  411. #region 扩展方法
  412. private WfSchemeModel wfSchemeModel;
  413. private Dictionary<string, WfNodeInfo> nodesMap;
  414. /// <summary>
  415. /// 初始化模板数据
  416. /// </summary>
  417. /// <param name="wfSchemeEntity">模板数据</param>
  418. public void SchemeInit(WfSchemeEntity wfSchemeEntity)
  419. {
  420. try
  421. {
  422. wfSchemeModel = wfSchemeEntity.F_Scheme.ToObject<WfSchemeModel>();
  423. nodesMap = new Dictionary<string, WfNodeInfo>();
  424. foreach (var node in wfSchemeModel.nodes)
  425. {
  426. if (!nodesMap.ContainsKey(node.id))
  427. {
  428. nodesMap.Add(node.id, node);
  429. }
  430. }
  431. }
  432. catch (Exception ex)
  433. {
  434. if (ex is ExceptionEx)
  435. {
  436. throw;
  437. }
  438. else
  439. {
  440. throw ExceptionEx.ThrowBusinessException(ex);
  441. }
  442. }
  443. }
  444. /// <summary>
  445. /// 获取开始节点
  446. /// </summary>
  447. /// <returns></returns>
  448. public WfNodeInfo GetStartNode()
  449. {
  450. try
  451. {
  452. WfNodeInfo startnode = null;
  453. foreach (var node in wfSchemeModel.nodes)
  454. {
  455. if (node.type == "startround")
  456. {
  457. startnode = node;
  458. }
  459. }
  460. return startnode;
  461. }
  462. catch (Exception ex)
  463. {
  464. if (ex is ExceptionEx)
  465. {
  466. throw;
  467. }
  468. else
  469. {
  470. throw ExceptionEx.ThrowBusinessException(ex);
  471. }
  472. }
  473. }
  474. /// <summary>
  475. /// 获取流程处理节点
  476. /// </summary>
  477. /// <param name="nodeId">流程处理节点主键</param>
  478. /// <returns></returns>
  479. public WfNodeInfo GetNode(string nodeId)
  480. {
  481. try
  482. {
  483. return nodesMap[nodeId];
  484. }
  485. catch (Exception ex)
  486. {
  487. if (ex is ExceptionEx)
  488. {
  489. throw;
  490. }
  491. else
  492. {
  493. throw ExceptionEx.ThrowBusinessException(ex);
  494. }
  495. }
  496. }
  497. /// <summary>
  498. /// 寻找到下一个节点
  499. /// </summary>
  500. /// <param name="nodeId">当前Id</param>
  501. /// <param name="transportType">流转类型1.同意2.不同意3.超时</param>
  502. /// <returns></returns>
  503. public List<WfNodeInfo> GetNextNodes(string nodeId, WfTransportType transportType)
  504. {
  505. try
  506. {
  507. List<WfNodeInfo> nextNodes= new List<WfNodeInfo>();
  508. // 找到与当前节点相连的线条
  509. foreach (var line in wfSchemeModel.lines)
  510. {
  511. if (line.from == nodeId)
  512. {
  513. bool isOk = false;
  514. switch (transportType)
  515. {
  516. case WfTransportType.Agree:
  517. if (line.wftype == 1 || line.wftype == 4 || line.wftype == 6)
  518. {
  519. isOk = true;
  520. }
  521. break;
  522. case WfTransportType.Disagree:
  523. if (line.wftype == 2 || line.wftype == 5 || line.wftype == 6)
  524. {
  525. isOk = true;
  526. }
  527. break;
  528. case WfTransportType.Overtime:
  529. if (line.wftype == 3 || line.wftype == 4 || line.wftype == 5)
  530. {
  531. isOk = true;
  532. }
  533. break;
  534. }
  535. if (isOk)
  536. {
  537. WfNodeInfo nextNode = nodesMap[line.to];
  538. if (nextNode != null)
  539. {
  540. nextNodes.Add(nextNode);
  541. }
  542. }
  543. }
  544. }
  545. return nextNodes;
  546. }
  547. catch (Exception ex)
  548. {
  549. if (ex is ExceptionEx)
  550. {
  551. throw;
  552. }
  553. else
  554. {
  555. throw ExceptionEx.ThrowBusinessException(ex);
  556. }
  557. }
  558. }
  559. /// <summary>
  560. /// 获取上一节点数据
  561. /// </summary>
  562. /// <param name="nodeId">节点主键</param>
  563. /// <returns></returns>
  564. public int GetPreNodeNum(string nodeId)
  565. {
  566. int num = 0;
  567. try
  568. {
  569. // 找到与当前节点相连的线条
  570. foreach (var line in wfSchemeModel.lines)
  571. {
  572. if (line.to == nodeId)
  573. {
  574. num++;
  575. }
  576. }
  577. return num;
  578. }
  579. catch (Exception ex)
  580. {
  581. if (ex is ExceptionEx)
  582. {
  583. throw;
  584. }
  585. else
  586. {
  587. throw ExceptionEx.ThrowBusinessException(ex);
  588. }
  589. }
  590. }
  591. /// <summary>
  592. /// 判断两节点是否连接
  593. /// </summary>
  594. /// <param name="formNodeId">开始节点</param>
  595. /// <param name="toNodeId">结束节点</param>
  596. /// <returns></returns>
  597. public bool IsToNode(string formNodeId, string toNodeId)
  598. {
  599. bool res = false;
  600. try
  601. {
  602. foreach (var line in wfSchemeModel.lines)
  603. {
  604. if (line.from == formNodeId)
  605. {
  606. if (line.to == toNodeId)
  607. {
  608. res = true;
  609. break;
  610. }
  611. else
  612. {
  613. if (line.to == formNodeId || nodesMap[line.to] == null || nodesMap[line.to].type == "endround")
  614. {
  615. break;
  616. }
  617. else
  618. {
  619. if (IsToNode(line.to, toNodeId))
  620. {
  621. res = true;
  622. break;
  623. }
  624. }
  625. }
  626. }
  627. }
  628. return res;
  629. }
  630. catch (Exception ex)
  631. {
  632. if (ex is ExceptionEx)
  633. {
  634. throw;
  635. }
  636. else
  637. {
  638. throw ExceptionEx.ThrowBusinessException(ex);
  639. }
  640. }
  641. }
  642. #endregion
  643. #region 扩展数据
  644. /// <summary>
  645. /// 获取流程模板使用次数列表
  646. /// </summary>
  647. /// <param name="queryJson">查询参数</param>
  648. /// <returns></returns>
  649. public IEnumerable<WfProcessInstanceEntity> GetWfSchemeUseList(string queryJson)
  650. {
  651. try
  652. {
  653. return wfSchemeService.GetWfSchemeUseList(queryJson);
  654. }
  655. catch (Exception ex)
  656. {
  657. if (ex is ExceptionEx)
  658. {
  659. throw;
  660. }
  661. else
  662. {
  663. throw ExceptionEx.ThrowBusinessException(ex);
  664. }
  665. }
  666. }
  667. public IEnumerable<WfProcessInstanceEntity> GetWfSchemeStart()
  668. {
  669. try
  670. {
  671. return wfSchemeService.GetWfSchemeStart();
  672. }
  673. catch (Exception ex)
  674. {
  675. if (ex is ExceptionEx)
  676. {
  677. throw;
  678. }
  679. else
  680. {
  681. throw ExceptionEx.ThrowBusinessException(ex);
  682. }
  683. }
  684. }
  685. #endregion
  686. }
  687. }