Ejemplo n.º 1
0
        /// <summary>
        /// nextNORMAL: 正常节点的下一步扭转
        /// </summary>
        /// <param name="currID">当前节点</param>
        /// <param name="nextID">下个节点</param>
        /// <param name="jsonStr">提交的json字符串</param>
        /// <param name="ext">扩展信息</param>
        /// <returns></returns>
        private string nextNORMAL(int currID, int nextID, string jsonStr, string ext = "")
        {
            string   _return = String.Empty, _nextOwners = String.Empty;
            SqlTrans trans = new SqlTrans(api);

            string[] _onEndResult = new string[] {};
            int      _newNextID = 0;
            Json     _cNode = null, _nNode = null, _parentNode = null;

            try
            {
                _cNode      = trans.execJson("select pid, definedNodeID, owner, cPerson from {0} where id={1};", R.Table.WF_INSTANCE, currID);
                _nNode      = trans.execJson("select * from {0} where id={1};", R.Table.WF_DEFINITION, nextID);
                _parentNode = trans.execJson("select * from {0} where id={1};", R.Table.WF_INSTANCE, _cNode.getValue("pid"));
                switch (_nNode.getInt("logicState"))
                {
                case 0:
                    _nextOwners = trans.getAllUsers(_nNode.getValue("users"), _nNode.getValue("roles"));
                    break;

                case 1:
                case 2:
                    //_nextOwners = trans.getAllUsers(MConvert.removeKey(ref jsonStr, "users"), MConvert.removeKey(ref jsonStr, "roles"));
                    _nextOwners = getParallerUsers(trans, MConvert.removeKey(ref jsonStr, "users"), MConvert.removeKey(ref jsonStr, "roles"), _nNode.getInt("logicState"), _parentNode);
                    break;

                case 3:
                    _nextOwners = "," + trans.execScalar(MString.getSelectStr(R.Table.WF_INSTANCE, "cPerson", "id=" + _cNode.getValue("pid"))) + ",";
                    break;

                case 4:
                    _nextOwners = _cNode.getValue("owner");
                    break;

                case 5:
                    _nextOwners = getAllStepUsers(trans, _cNode.getInt("pid"));
                    break;

                case 6:
                    _nextOwners = "," + trans.execScalar(MString.getSelectStr(R.Table.WF_INSTANCE, "cPerson", "id=" + _cNode.getInt("pid"))) + ",";
                    break;

                case 7:
                    _nextOwners = trans.getDeptOwners(trans.execScalar(MString.getSelectStr(R.Table.WF_INSTANCE, "cPerson", "id=" + _cNode.getInt("pid"))));
                    break;

                case 10:      //自动节点
                    string[] _nextids = trans.execScalar(MString.getSelectStr(R.Table.WF_DEFINITION, "next", nextID)).Split(',');
                    if (_nextids.Length == 3 && !Native.isEmpty(_nextids[1]))
                    {
                        _newNextID = Convert.ToInt16(_nextids[1]);
                    }
                    else
                    {
                        trans.commit();
                        trans.close();
                        return(Native.getErrorMsg("自动进行扭转到下个节点时, 当前节点的next不唯一或为空, 请先确认!"));
                    }
                    break;
                }
                trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, MConvert.toUpdateSql(jsonStr), currID));
                string _nk    = "oid,definedNodeID,nodeName,next,pre,ext,type,state,users,roles,owner";
                string _nv    = _nNode.getValue("oid") + "," + _nNode.getValue("id") + ",'" + _nNode.getValue("nodeName") + "','" + _nNode.getValue("next") + "'," + currID + ",'" + ext + "'," + _nNode.getValue("type") + ",1,'" + _nNode.getValue("users") + "','" + _nNode.getValue("roles") + "','" + _nextOwners + "'";
                string _newID = trans.addTreeNode(R.Table.WF_INSTANCE, _cNode.getInt("pid"), _nk, _nv);
                trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "state=0, next='" + _newID + "'", currID));
                switch (_nNode.getInt("type"))
                {
                case T_PARALLEL:
                    string _nOwners = getParallerUsers(trans, _nNode.getValue("users"), _nNode.getValue("roles"), _nNode.getInt("logicState"), _parentNode);
                    if (_nOwners.Length > 2 && _nNode.getInt("logicState") != 1 && _nNode.getInt("logicState") != 2)
                    {
                        _nextOwners = _nOwners;
                    }
                    trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "owner=dbo.SYS_TRANS_RIGHTS_USERS('" + _nextOwners + "')", Convert.ToInt16(_newID)));
                    string[] _users = _nextOwners.Split(',');
                    for (int _u = 0, _uLen = _users.Length; _u < _uLen; _u++)
                    {
                        string _uid = _users[_u];
                        if (!Native.isEmpty(_uid))
                        {
                            trans.addTreeNode(R.Table.WF_INSTANCE, Convert.ToInt16(_newID), "state,nodeName,owner,users", S_P_NORMAL + ",'" + _uid + "','," + _uid + ",','," + _uid + ",'");
                        }
                    }
                    trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "users='" + _nextOwners + "'", Convert.ToInt16(_newID)));
                    break;

                case T_SUB_PROCESS:
                    string[] subIds = _nNode.getValue("subProcessIdxIds").Split(',');
                    for (int _u = 0, _uLen = subIds.Length; _u < _uLen; _u++)
                    {
                        string _sid = subIds[_u];
                        if (!Native.isEmpty(_sid))
                        {
                            addSubProcess(trans, Convert.ToInt16(_newID), Convert.ToInt16(_sid));
                        }
                    }
                    break;

                case T_END:
                    int _pid = _cNode.getInt("pid");
                    trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "state=" + S_ENDED, _pid));
                    _onEndResult = onProcessEnd(trans, _pid);
                    break;
                }
                trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "owner=dbo.SYS_TRANS_RIGHTS_USERS('" + _nextOwners + "')", _cNode.getInt("pid")));
                api.setDataType("json");
                _return = trans.execReader(MString.getSelectStr(R.Table.WF_INSTANCE, "*, dbo.SYS_TRANS_USERS(users) as t_users", Convert.ToInt16(_newID)));
                api.setDataType("html");
                trans.commit();
            }
            catch (Exception e)
            {
                _return = Native.getErrorMsg(e.Message + "--WFInstance--nextNORMAL");
                trans.rollback();
            }
            finally
            {
                trans.close();
            }
            if (_cNode != null && _nNode != null)
            {
                WFRuler.runNext(_cNode.getInt("definedNodeID"), _nNode.getInt("id"), _cNode.getValue("owner"), _nextOwners);
            }
            if (_newNextID != 0)
            {
                return(next(nextID, _newNextID, jsonStr, "节点[" + nextID + "]---->[" + _newNextID + "]自动扭转"));
            }
            if (_onEndResult.Length > 0)
            {
                return(nextNORMAL(Convert.ToInt16(_onEndResult[0]), Convert.ToInt16(_onEndResult[1]), "子流程结束时主动触发主流程向下扭转", ""));
            }
            return(_return);
        }