/// <summary> /// 验证文件是否都上传。 /// </summary> /// <param name="workflowId">流程Id。</param> /// <param name="itemCode">项目编号。</param> /// <param name="node">节点。</param> /// <param name="fileCodes">是否制定验证文件的类型。</param> /// <returns>错误信息。</returns> protected string FileValidation(string workflowId, string itemCode, WorkFlowNode node, List <string> fileCodes) { WfNode nodeInfo = this.GetNodeInfo(workflowId, ((int)node).ToString()); List <string> nodeFileCodes = nodeInfo.NodeFileCode.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (fileCodes == null) { fileCodes = nodeFileCodes; } else { fileCodes = fileCodes.Intersect(nodeFileCodes).ToList(); } string format = "\"{0}\"必须上传!"; StringBuilder sb = new StringBuilder(); List <Item_File> fileInfos = new BusiItemManage().GetItemFile(itemCode, node); foreach (var fileInfo in fileInfos) { fileCodes.Remove(fileInfo.FileCode); } if (fileCodes.Count != 0) { foreach (var fileCode in fileCodes) { sb.AppendLine(string.Format(format, EnumHelper.GetFieldDescription(typeof(FileCode), int.Parse(fileCode)))); } } return(sb.ToString()); }
/// <summary> /// 根据项目编号过滤环节的权限部分 /// </summary> /// <param name="itemCode"></param> /// <param name="node"></param> private void changeNodeQx(string itemCode, ref WfNode node) { string cCode = itemCode.Substring(0, 6); string cShiCode = CommonHelper.GetSHICode(cCode); string strSql = string.Empty; if (!string.IsNullOrEmpty(node.NodeDepartCode)) { strSql = "select wm_concat(deptCode) from department where deptcode in ({0})" + " and (ccode = '{1}' or ccode = '{2}')"; strSql = string.Format(strSql, node.NodeDepartCode, cCode, cShiCode); node.NodeDepartCode = OracleHelper.ExecuteDataTable(strSql).Rows[0][0].ToString(); } if (!string.IsNullOrEmpty(node.NodeUserId)) { strSql = "select wm_concat(userid) from users where userid in ({0})" + " and (ccode = '{1}' or ccode = '{2}')"; strSql = string.Format(strSql, node.NodeUserId, cCode, cShiCode); node.NodeUserId = OracleHelper.ExecuteDataTable(strSql).Rows[0][0].ToString(); } if (!string.IsNullOrEmpty(node.NodeRoleId)) { strSql = "select wm_concat(roleid) from role where roleId in ({0})" + " and (roleType = 1 or ccode = '{1}' or ccode = '{2}')"; strSql = string.Format(strSql, node.NodeRoleId, cCode, cShiCode); node.NodeRoleId = OracleHelper.ExecuteDataTable(strSql).Rows[0][0].ToString(); } }
private WfNode GetNodeInfo(string workFlowId, string nodeId) { WfNode node = null; string strSql = "select * from wf_node where FlowId = {0} and NodeId = {1}"; strSql = string.Format(strSql, workFlowId, nodeId); DataTable dt = OracleHelper.ExecuteDataTable(strSql); if (dt.Rows.Count == 1) { node = new WfNode(); node.NodeId = dt.Rows[0]["nodeId"].ToString(); node.NodeDesc = dt.Rows[0]["NodeDesc"].ToString(); node.Stage = dt.Rows[0]["Stage"].ToString(); node.PerNode = dt.Rows[0]["Pernode"].ToString(); node.NextNode = dt.Rows[0]["NextNode"].ToString(); node.NodeLevel = dt.Rows[0]["NodeLevel"].ToString(); node.TimeOut = dt.Rows[0]["TimeOut"].ToString(); node.NodeDepartCode = dt.Rows[0]["NodeDepartCode"].ToString(); node.NodeRoleId = dt.Rows[0]["NodeRoleId"].ToString(); node.NodeUserId = dt.Rows[0]["NodeUserId"].ToString(); node.NodeFileCode = dt.Rows[0]["NodeFileCode"].ToString(); node.NodeType = (NodeType)EnumHelper.StringValueToEnum(typeof(NodeType), dt.Rows[0]["NodeType"].ToString()); node.NotifyType = dt.Rows[0]["NotifyType"].ToString(); node.BeginText = dt.Rows[0]["notifyBeginText"].ToString(); node.NextText = dt.Rows[0]["notifyNextText"].ToString(); node.HistoryText = dt.Rows[0]["notifyHistoryText"].ToString(); } return(node); }
/// <summary> /// 保存环节信息 /// </summary> /// <param name="wfNode"></param> /// <returns></returns> public bool SaveWfNodeInfo(WfNode wfNode) { string strSql = "update wf_node set nodedesc = '{2}',nodeLevel = '{3}', nodedepartcode = '{4}', noderoleid = '{5}', nodeuserid = '{6}'" + ", nodefilecode = '{7}', timeout = '{8}', notifytype = '{9}', notifybegintext = '{10}', notifynexttext = '{11}', notifyhistorytext = '{12}'" + "Where flowId = {0} and nodeId = {1}"; strSql = string.Format(strSql, wfNode.FlowId, wfNode.NodeId, wfNode.NodeDesc, wfNode.NodeLevel, wfNode.NodeDepartCode, wfNode.NodeRoleId, wfNode.NodeUserId, wfNode.NodeFileCode, wfNode.TimeOut, wfNode.NotifyType, wfNode.BeginText, wfNode.NextText, wfNode.HistoryText); return(OracleHelper.ExecuteCommand(strSql)); }
/// <summary> /// 获取登录用户的环节权限 /// </summary> /// <param name="user"></param> /// <returns></returns> public List <WfNode> GetNodeListByUser(LoginUser user) { List <WfNode> nodeList = new List <WfNode>(); ////角色条件 string strRoleWhere = string.Empty; string[] roleAry = user.RoleId.Split(new char[] { ',' }); for (int i = 0; i < roleAry.Length; i++) { if (roleAry[i] != string.Empty) { strRoleWhere += string.Format(" or instr(',' || NodeRoleId || ',', ',{0},') <> 0", roleAry[i]); } } ////部门条件 string strDeptWhere = string.Empty; if (!string.IsNullOrEmpty(user.DepartCode)) { strDeptWhere = string.Format(" or instr(',' || NodeDepartCode || ',', ',{0},') <> 0", user.DepartCode); } string strSql = "select * from wf_node where instr(',' || NodeUserId || ',', ',{0},') <> 0 " + " {1} {2} "; strSql = string.Format(strSql, user.UserId, strDeptWhere, strRoleWhere); IDataReader dr = OracleHelper.ExecuteReader(strSql); while (dr.Read()) { WfNode node = new WfNode(); node.NodeId = dr["nodeId"].ToString(); node.NodeType = (NodeType)EnumHelper.StringValueToEnum(typeof(NodeType), dr["nodeType"].ToString()); node.FunctionCode = dr["FunctionCode"].ToString(); nodeList.Add(node); } dr.Close(); return(nodeList); }
/// <summary> /// 站内发送短消息 /// </summary> /// <param name="dt"></param> /// <param name="wfItem"></param> private void notifyUser(WfNode curNode, WfNode nextNode, WfItem wfItem) { string[] notifyAry = curNode.NotifyType.Split(new char[] { ',' }); string msg = string.Empty; List<string> userId = new List<string>(); string[] itemAry = wfItem.ItemCode.Split(','); for (int i = 0; i < itemAry.Length; i++) { string itemName = this.getItemName(itemAry[i]); List<string> beginuserId = new List<string>(); List<string> nextuserId = new List<string>(); List<string> historyuserId = new List<string>(); if (curNode.NodeType == NodeType.BeginNode)////开始结点 { //beginuserId = wfItem.UserId; //historyuserId = wfItem.UserId; } else { beginuserId = this.getBeginUserId(itemAry[i]); historyuserId = this.getHistoryUserId(itemAry[i]); } if (nextNode != null) nextuserId = this.getUserId(itemAry[i], nextNode.NodeDepartCode, nextNode.NodeRoleId, nextNode.NodeUserId); for (int j = 0; j < notifyAry.Length; j++) { WfNotifyType notifyEnum = (WfNotifyType)EnumHelper.StringValueToEnum(typeof(WfNotifyType), notifyAry[j]); switch (notifyEnum) { case WfNotifyType.Begin: msg = curNode.BeginText.Replace("{wf_username}", wfItem.UserName) .Replace("{wf_time}", DateTime.Now.ToString()) .Replace("{wf_title}", itemName) .Replace("{wf_stage}", string.Format("{0}-{1}", EnumHelper.GetFieldDescription(typeof(ItemStage), int.Parse(nextNode.Stage)), EnumHelper.GetFieldDescription(typeof(WorkFlowNode),int.Parse(nextNode.NodeId)))); userId = beginuserId; break; case WfNotifyType.Next: msg = curNode.NextText.Replace("{wf_title}", itemName) .Replace("{wf_timeout}", nextNode.TimeOut.Equals("0") ? "无" : string.Format("{0}天", nextNode.TimeOut)); userId = nextuserId; break; case WfNotifyType.History: msg = curNode.HistoryText.Replace("{wf_username}", wfItem.UserName) .Replace("{wf_time}", DateTime.Now.ToString()) .Replace("{wf_title}", itemName); userId = historyuserId; break; } if (msg != string.Empty || userId.Count > 0) { this.SendMessage(userId, msg); } } } }
/// <summary> /// 保存环节信息 /// </summary> /// <param name="wfNode"></param> /// <returns></returns> public bool SaveWfNodeInfo(WfNode wfNode) { string strSql = "update wf_node set nodedesc = '{2}',nodeLevel = '{3}', nodedepartcode = '{4}', noderoleid = '{5}', nodeuserid = '{6}'" + ", nodefilecode = '{7}', timeout = '{8}', notifytype = '{9}', notifybegintext = '{10}', notifynexttext = '{11}', notifyhistorytext = '{12}'" + "Where flowId = {0} and nodeId = {1}"; strSql = string.Format(strSql, wfNode.FlowId, wfNode.NodeId, wfNode.NodeDesc, wfNode.NodeLevel, wfNode.NodeDepartCode, wfNode.NodeRoleId, wfNode.NodeUserId, wfNode.NodeFileCode, wfNode.TimeOut, wfNode.NotifyType, wfNode.BeginText, wfNode.NextText, wfNode.HistoryText); return OracleHelper.ExecuteCommand(strSql); }
/// <summary> /// 获取环节配置信息 /// </summary> /// <param name="nodeId"></param> /// <returns></returns> public WfNode GetNodeInfo(string workFlowId, string nodeId) { WfNode node = null; string strSql = "select * from wf_node where FlowId = {0} and NodeId = {1}"; strSql = string.Format(strSql, workFlowId, nodeId); DataTable dt = OracleHelper.ExecuteDataTable(strSql); if (dt.Rows.Count == 1) { node = new WfNode(); node.NodeId = dt.Rows[0]["nodeId"].ToString(); node.NodeDesc = dt.Rows[0]["NodeDesc"].ToString(); node.Stage = dt.Rows[0]["Stage"].ToString(); node.PerNode = dt.Rows[0]["Pernode"].ToString(); node.NextNode = dt.Rows[0]["NextNode"].ToString(); node.NodeLevel = dt.Rows[0]["NodeLevel"].ToString(); node.TimeOut = dt.Rows[0]["TimeOut"].ToString(); node.NodeDepartCode = dt.Rows[0]["NodeDepartCode"].ToString(); node.NodeRoleId = dt.Rows[0]["NodeRoleId"].ToString(); node.NodeUserId = dt.Rows[0]["NodeUserId"].ToString(); node.NodeFileCode = dt.Rows[0]["NodeFileCode"].ToString(); node.NodeType = (NodeType)EnumHelper.StringValueToEnum(typeof(NodeType), dt.Rows[0]["NodeType"].ToString()); node.NotifyType = dt.Rows[0]["NotifyType"].ToString(); node.BeginText = dt.Rows[0]["notifyBeginText"].ToString(); node.NextText = dt.Rows[0]["notifyNextText"].ToString(); node.HistoryText = dt.Rows[0]["notifyHistoryText"].ToString(); } return node; }
/// <summary> /// 创建流程实例 /// </summary> /// <param name="wfItem"></param> /// <returns></returns> public WfReturn CreateInstance(WfItem wfItem) { WfReturn result = new WfReturn(); ItemState itemState = ItemState.Beginning; WfState wfState = WfState.Normal; string orderNo = string.Empty; try { ////判断该项目的状态是否可以操作 DataTable dt = OracleHelper.ExecuteDataTable("select * from xm_xmxx where ItemCode in (" + wfItem.ItemCode + ")"); WfState ItemWfState = (WfState)EnumHelper.StringValueToEnum(typeof(WfState), dt.Rows[0]["wfState"].ToString()); if (ItemWfState != WfState.Normal) { result.Success = false; result.ResultDesc = string.Format("该项目处于{0}状态,无法操作", EnumHelper.GetFieldDescription(typeof(WfState), (int)ItemWfState)); return(result); } ////当前环节信息(0为开始环节) WfNode curNode = this.GetNodeInfo(this.strFlowId, wfItem.NodeId); if (curNode == null) { result.Success = false; result.ResultDesc = "获取当前环节信息失败!"; return(result); } ////下一环节信息 WfNode nextNode = null; string perNodeId = string.Empty; string nextNodeId = string.Empty; ////存在跳转ID if (!string.IsNullOrEmpty(wfItem.SwicthNode)) { perNodeId = wfItem.SwicthNode; nextNodeId = wfItem.SwicthNode; } else { perNodeId = curNode.PerNode; nextNodeId = curNode.NextNode; } ////退回操作--上一结点 if (wfItem.Result == WfResult.Return) { nextNode = this.GetNodeInfo(this.strFlowId, perNodeId); } ////同意操作--下一结点 if (wfItem.Result == WfResult.Agree) { nextNode = this.GetNodeInfo(this.strFlowId, nextNodeId); } ArrayList strSql = new ArrayList(); string tmpSql = string.Empty; if (curNode.PerNode == ((int)WorkFlowNode.Begin).ToString())////开始结点 { //// 1 删除该项目所有进程信息 tmpSql = "delete from wf_instance where itemcode = '{0}'"; tmpSql = string.Format(tmpSql, wfItem.ItemCode); strSql.Add(tmpSql); //// 2 插入开始环节的已完成记录 tmpSql = "Insert into wf_instance(flowid,itemcode,orderno,nodeid,perNode,nextNode,userid,username,result,resultdesc,begindate,enddate,state)" + " values ('{0}','{1}',1,'{2}','{3}','{4}','{5}','{6}','{7}','{8}',sysdate,sysdate,1)"; tmpSql = string.Format(tmpSql, strFlowId, wfItem.ItemCode, curNode.NodeId, curNode.PerNode, curNode.NextNode, wfItem.UserId, wfItem.UserName, ((int)wfItem.Result).ToString(), wfItem.ResultDesc); strSql.Add(tmpSql); //// 3 插入下一环节的未完成记录 tmpSql = "Insert into wf_instance(flowid,itemcode,orderno,nodeid,perNode,nextNode,userid,username,result,resultdesc,begindate,enddate,state)" + " values ('{0}','{1}',2,'{2}','{3}','{4}','','','','',sysdate,'',0)"; tmpSql = string.Format(tmpSql, strFlowId, wfItem.ItemCode, nextNode.NodeId, nextNode.PerNode, nextNode.NextNode); strSql.Add(tmpSql); itemState = ItemState.Progressing; wfState = WfState.Normal; } else ////任务结点 { //// 更新项目进程表中当前环节的状态 tmpSql = "update wf_instance set enddate = sysdate, state = 1,userid = '{2}',username = '******',result = '{4}', resultdesc = '{5}'" + " where itemCode in ({0}) and nodeid = {1} and state = 0"; tmpSql = string.Format(tmpSql, wfItem.ItemCode, wfItem.NodeId, wfItem.UserId, wfItem.UserName, ((int)wfItem.Result).ToString(), wfItem.ResultDesc); strSql.Add(tmpSql); //// 插入下一环节的进程信息 if (wfItem.Result != WfResult.Delete) { tmpSql = "delete from wf_instance where itemCode in ({0}) and nodeid = {1} and state = 0"; tmpSql = string.Format(tmpSql, wfItem.ItemCode, nextNode.NodeId); strSql.Add(tmpSql); ////针对批量操作 string[] itemAry = wfItem.ItemCode.Split(','); for (int i = 0; i < itemAry.Length; i++) { orderNo = getOrdernoByItem(itemAry[i]); //// 插入下一环节的未完成记录 tmpSql = "Insert into wf_instance(flowid,itemcode,orderno,nodeid,perNode,nextNode,userid,username,result,resultdesc,begindate,enddate,state)" + " values ('{0}','{1}','{2}','{3}','{4}','{5}','','','','',sysdate,'',0)"; tmpSql = string.Format(tmpSql, strFlowId, itemAry[i], orderNo, nextNode.NodeId, nextNode.PerNode, nextNode.NextNode); strSql.Add(tmpSql); } } if (nextNode != null) { if (nextNode.NodeType == NodeType.EndNode) { tmpSql = "update wf_instance set enddate = sysdate, state = 1,userid = '{2}',username = '******',result = '{4}', resultdesc = '{5}'" + " where itemCode in ({0}) and nodeid = {1} and state = 0"; tmpSql = string.Format(tmpSql, wfItem.ItemCode, nextNode.NodeId, wfItem.UserId, wfItem.UserName, ((int)wfItem.Result).ToString(), wfItem.ResultDesc); strSql.Add(tmpSql); } } switch (wfItem.Result) { case WfResult.Agree: if (nextNode.NodeType == NodeType.EndNode) { wfState = WfState.Normal; itemState = ItemState.Ending; } else { wfState = WfState.Normal; itemState = ItemState.Progressing; } break; case WfResult.Return: wfState = WfState.Normal; itemState = ItemState.Progressing; break; case WfResult.Delete: wfState = WfState.Delete; itemState = ItemState.Ending; break; } } if (wfItem.Result == WfResult.Delete) { tmpSql = "update xm_xmxx set itemstate = '{1}', wfstate = '{2}', ItemDesc = '{3}',read = 0 where ItemCode in ({0})"; tmpSql = string.Format(tmpSql, wfItem.ItemCode, ((int)itemState).ToString(), ((int)wfState).ToString(), wfItem.ResultDesc); strSql.Add(tmpSql); } else { //// 更新项目主表的状态标识 tmpSql = "update xm_xmxx set itemstage = '{1}', nodeid = '{2}', itemstate = '{3}', wfstate = '{4}',read = 0 where ItemCode in ({0})"; tmpSql = string.Format(tmpSql, wfItem.ItemCode, nextNode.Stage, nextNode.NodeId, ((int)itemState).ToString(), ((int)wfState).ToString()); strSql.Add(tmpSql); } bool succ = OracleHelper.ExecuteCommand(strSql); if (succ) { if (curNode.NotifyType != string.Empty && nextNode != null)////有消息发送设置 { ////发送消息 this.notifyUser(curNode, nextNode, wfItem); } result.Success = true; result.ResultDesc = "成功"; if (nextNode != null) { result.Stage = nextNode.Stage; result.NodeName = nextNode.NodeName; this.changeNodeQx(wfItem.ItemCode.Split(',')[0], ref nextNode); result.DepartList = this.getItemName(1, nextNode.NodeDepartCode); result.RoleList = this.getItemName(2, nextNode.NodeRoleId); result.UserList = this.getItemName(3, nextNode.NodeUserId); } } } catch (Exception ex) { throw ex; } return(result); }
/// <summary> /// 站内发送短消息 /// </summary> /// <param name="dt"></param> /// <param name="wfItem"></param> private void notifyUser(WfNode curNode, WfNode nextNode, WfItem wfItem) { string[] notifyAry = curNode.NotifyType.Split(new char[] { ',' }); string msg = string.Empty; List <string> userId = new List <string>(); string[] itemAry = wfItem.ItemCode.Split(','); for (int i = 0; i < itemAry.Length; i++) { string itemName = this.getItemName(itemAry[i]); List <string> beginuserId = new List <string>(); List <string> nextuserId = new List <string>(); List <string> historyuserId = new List <string>(); if (curNode.NodeType == NodeType.BeginNode)////开始结点 { //beginuserId = wfItem.UserId; //historyuserId = wfItem.UserId; } else { beginuserId = this.getBeginUserId(itemAry[i]); historyuserId = this.getHistoryUserId(itemAry[i]); } if (nextNode != null) { nextuserId = this.getUserId(itemAry[i], nextNode.NodeDepartCode, nextNode.NodeRoleId, nextNode.NodeUserId); } for (int j = 0; j < notifyAry.Length; j++) { WfNotifyType notifyEnum = (WfNotifyType)EnumHelper.StringValueToEnum(typeof(WfNotifyType), notifyAry[j]); switch (notifyEnum) { case WfNotifyType.Begin: msg = curNode.BeginText.Replace("{wf_username}", wfItem.UserName) .Replace("{wf_time}", DateTime.Now.ToString()) .Replace("{wf_title}", itemName) .Replace("{wf_stage}", string.Format("{0}-{1}", EnumHelper.GetFieldDescription(typeof(ItemStage), int.Parse(nextNode.Stage)), EnumHelper.GetFieldDescription(typeof(WorkFlowNode), int.Parse(nextNode.NodeId)))); userId = beginuserId; break; case WfNotifyType.Next: msg = curNode.NextText.Replace("{wf_title}", itemName) .Replace("{wf_timeout}", nextNode.TimeOut.Equals("0") ? "无" : string.Format("{0}天", nextNode.TimeOut)); userId = nextuserId; break; case WfNotifyType.History: msg = curNode.HistoryText.Replace("{wf_username}", wfItem.UserName) .Replace("{wf_time}", DateTime.Now.ToString()) .Replace("{wf_title}", itemName); userId = historyuserId; break; } if (msg != string.Empty || userId.Count > 0) { this.SendMessage(userId, msg); } } } }
/// <summary> /// 获取登录用户的环节权限 /// </summary> /// <param name="user"></param> /// <returns></returns> public List<WfNode> GetNodeListByUser(LoginUser user) { List<WfNode> nodeList = new List<WfNode>(); ////角色条件 string strRoleWhere = string.Empty; string[] roleAry = user.RoleId.Split(new char[] { ',' }); for (int i = 0; i < roleAry.Length; i++) { if (roleAry[i] != string.Empty) { strRoleWhere += string.Format(" or instr(',' || NodeRoleId || ',', ',{0},') <> 0", roleAry[i]); } } ////部门条件 string strDeptWhere = string.Empty; if (!string.IsNullOrEmpty(user.DepartCode)) { strDeptWhere = string.Format(" or instr(',' || NodeDepartCode || ',', ',{0},') <> 0", user.DepartCode); } string strSql = "select * from wf_node where instr(',' || NodeUserId || ',', ',{0},') <> 0 " + " {1} {2} "; strSql = string.Format(strSql, user.UserId, strDeptWhere, strRoleWhere); IDataReader dr = OracleHelper.ExecuteReader(strSql); while (dr.Read()) { WfNode node = new WfNode(); node.NodeId = dr["nodeId"].ToString(); node.NodeType = (NodeType)EnumHelper.StringValueToEnum(typeof(NodeType), dr["nodeType"].ToString()); node.FunctionCode = dr["FunctionCode"].ToString(); nodeList.Add(node); } dr.Close(); return nodeList; }