using Learun.Cache.Base; using Learun.Cache.Factory; using Learun.Util; using System; using System.Collections.Generic; namespace Learun.Application.WorkFlow { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.04.17 /// 描 述:工作流模板处理 /// public class WfSchemeBLL : WfSchemeIBLL { private WfSchemeService wfSchemeService = new WfSchemeService(); #region 缓存定义 private ICache cache = CacheFactory.CaChe(); private string cacheKey = "Learun_adms_wfscheme_";// +模板主键 #endregion #region 获取数据 /// /// 获取流程分页列表 /// /// 分页参数 /// 关键字 /// 分类 /// public IEnumerable GetSchemeInfoPageList(Pagination pagination, string keyword, string category) { try { return wfSchemeService.GetSchemeInfoPageList(pagination, keyword, category); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取流程模板分页列表 /// /// 分页参数 /// 登录者信息 /// 查询参数 /// public IEnumerable GetAppSchemeInfoPageList(Pagination pagination, UserInfo userInfo, string queryJson) { try { return wfSchemeService.GetAppSchemeInfoPageList(pagination, userInfo, queryJson); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取自定义流程列表 /// /// 用户信息 /// public IEnumerable GetCustmerSchemeInfoList(UserInfo userInfo) { try { return wfSchemeService.GetCustmerSchemeInfoList(userInfo); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取自定义流程列表(app) /// /// 用户信息 /// public IEnumerable GetAppCustmerSchemeInfoList(UserInfo userInfo) { try { return wfSchemeService.GetAppCustmerSchemeInfoList(userInfo); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取模板列表 /// /// 模板信息主键 /// public IEnumerable GetWfSchemeList(string schemeInfoId) { try { return wfSchemeService.GetWfSchemeList(schemeInfoId); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取模板列表 /// /// 分页参数 /// 模板信息主键 /// public IEnumerable GetSchemePageList(Pagination pagination, string schemeInfoId) { try { return wfSchemeService.GetSchemePageList(pagination, schemeInfoId); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取模板基础信息的实体 /// /// 流程编号 /// public WfSchemeInfoEntity GetWfSchemeInfoEntityByCode(string code) { try { WfSchemeInfoEntity wfSchemeInfoEntity = cache.Read(cacheKey + code, CacheId.workflow); if (wfSchemeInfoEntity == null) { wfSchemeInfoEntity = wfSchemeService.GetWfSchemeInfoEntityByCode(code); cache.Write(cacheKey + code, wfSchemeInfoEntity, CacheId.workflow); } return wfSchemeInfoEntity; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取模板的实体 /// /// 主键 /// public WfSchemeEntity GetWfSchemeEntity(string keyValue) { try { WfSchemeEntity wfSchemeEntity = cache.Read(cacheKey + keyValue, CacheId.workflow); if (wfSchemeEntity == null) { wfSchemeEntity = wfSchemeService.GetWfSchemeEntity(keyValue); cache.Write(cacheKey + keyValue, wfSchemeEntity, CacheId.workflow); } return wfSchemeEntity; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取模板的实体通过流程编号 /// /// 流程编号 /// public WfSchemeEntity GetWfSchemeEntityByCode(string code) { try { WfSchemeInfoEntity wfSchemeInfoEntity = GetWfSchemeInfoEntityByCode(code); WfSchemeEntity wfSchemeEntity = cache.Read(cacheKey + wfSchemeInfoEntity.F_SchemeId, CacheId.workflow); if (wfSchemeEntity == null) { wfSchemeEntity = wfSchemeService.GetWfSchemeEntity(wfSchemeInfoEntity.F_SchemeId); cache.Write(cacheKey + wfSchemeInfoEntity.F_SchemeId, wfSchemeEntity, CacheId.workflow); } return wfSchemeEntity; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取流程模板权限列表 /// /// 模板信息主键 /// public IEnumerable GetWfSchemeAuthorizeList(string schemeInfoId) { try { return wfSchemeService.GetWfSchemeAuthorizeList(schemeInfoId); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } #endregion #region 提交数据 /// /// 虚拟删除模板信息 /// /// 主键 public void VirtualDelete(string keyValue) { try { WfSchemeInfoEntity wfSchemeInfoEntity = wfSchemeService.GetWfSchemeInfoEntity(keyValue); cache.Remove(cacheKey + wfSchemeInfoEntity.F_Code, CacheId.workflow); cache.Remove(cacheKey + wfSchemeInfoEntity.F_SchemeId, CacheId.workflow); wfSchemeService.VirtualDelete(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 保存模板信息 /// /// 主键 /// 模板基础信息 /// 模板信息 public void SaveEntity(string keyValue, WfSchemeInfoEntity wfSchemeInfoEntity, WfSchemeEntity wfSchemeEntity, List wfSchemeAuthorizeList) { try { if (!string.IsNullOrEmpty(keyValue)) { WfSchemeEntity wfSchemeEntityOld = GetWfSchemeEntity(wfSchemeInfoEntity.F_SchemeId); if (wfSchemeEntityOld.F_Scheme == wfSchemeEntity.F_Scheme && wfSchemeEntityOld.F_Type == wfSchemeEntity.F_Type) { wfSchemeEntity = null; } cache.Remove(cacheKey + wfSchemeInfoEntity.F_Code, CacheId.workflow); cache.Remove(cacheKey + wfSchemeInfoEntity.F_SchemeId, CacheId.workflow); } wfSchemeService.SaveEntity(keyValue, wfSchemeInfoEntity, wfSchemeEntity, wfSchemeAuthorizeList); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 更新流程模板 /// /// 模板信息主键 /// 模板主键 public void UpdateScheme(string schemeInfoId, string schemeId) { try { WfSchemeInfoEntity wfSchemeInfoEntity = wfSchemeService.GetWfSchemeInfoEntity(schemeInfoId); cache.Remove(cacheKey + wfSchemeInfoEntity.F_Code, CacheId.workflow); cache.Remove(cacheKey + wfSchemeInfoEntity.F_SchemeId, CacheId.workflow); wfSchemeService.UpdateScheme(schemeInfoId, schemeId); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 保存模板基础信息 /// /// 主键 /// 模板基础信息 public void SaveSchemeInfoEntity(string keyValue, WfSchemeInfoEntity schemeInfoEntity) { try { wfSchemeService.SaveSchemeInfoEntity(keyValue, schemeInfoEntity); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 更新自定义表单模板状态 /// /// 模板信息主键 /// 状态1启用0禁用 public void UpdateState(string schemeInfoId, int state) { try { wfSchemeService.UpdateState(schemeInfoId, state); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } #endregion #region 扩展方法 private WfSchemeModel wfSchemeModel; private Dictionary nodesMap; /// /// 初始化模板数据 /// /// 模板数据 public void SchemeInit(WfSchemeEntity wfSchemeEntity) { try { wfSchemeModel = wfSchemeEntity.F_Scheme.ToObject(); nodesMap = new Dictionary(); foreach (var node in wfSchemeModel.nodes) { if (!nodesMap.ContainsKey(node.id)) { nodesMap.Add(node.id, node); } } } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取开始节点 /// /// public WfNodeInfo GetStartNode() { try { WfNodeInfo startnode = null; foreach (var node in wfSchemeModel.nodes) { if (node.type == "startround") { startnode = node; } } return startnode; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取流程处理节点 /// /// 流程处理节点主键 /// public WfNodeInfo GetNode(string nodeId) { try { return nodesMap[nodeId]; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 寻找到下一个节点 /// /// 当前Id /// 流转类型1.同意2.不同意3.超时 /// public List GetNextNodes(string nodeId, WfTransportType transportType) { try { List nextNodes= new List(); // 找到与当前节点相连的线条 foreach (var line in wfSchemeModel.lines) { if (line.from == nodeId) { bool isOk = false; switch (transportType) { case WfTransportType.Agree: if (line.wftype == 1 || line.wftype == 4 || line.wftype == 6) { isOk = true; } break; case WfTransportType.Disagree: if (line.wftype == 2 || line.wftype == 5 || line.wftype == 6) { isOk = true; } break; case WfTransportType.Overtime: if (line.wftype == 3 || line.wftype == 4 || line.wftype == 5) { isOk = true; } break; } if (isOk) { WfNodeInfo nextNode = nodesMap[line.to]; if (nextNode != null) { nextNodes.Add(nextNode); } } } } return nextNodes; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取上一节点数据 /// /// 节点主键 /// public int GetPreNodeNum(string nodeId) { int num = 0; try { // 找到与当前节点相连的线条 foreach (var line in wfSchemeModel.lines) { if (line.to == nodeId) { num++; } } return num; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 判断两节点是否连接 /// /// 开始节点 /// 结束节点 /// public bool IsToNode(string formNodeId, string toNodeId) { bool res = false; try { foreach (var line in wfSchemeModel.lines) { if (line.from == formNodeId) { if (line.to == toNodeId) { res = true; break; } else { if (line.to == formNodeId || nodesMap[line.to] == null || nodesMap[line.to].type == "endround") { break; } else { if (IsToNode(line.to, toNodeId)) { res = true; break; } } } } } return res; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } #endregion #region 扩展数据 /// /// 获取流程模板使用次数列表 /// /// 查询参数 /// public IEnumerable GetWfSchemeUseList(string queryJson) { try { return wfSchemeService.GetWfSchemeUseList(queryJson); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } public IEnumerable GetWfSchemeStart() { try { return wfSchemeService.GetWfSchemeStart(); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } #endregion } }