Ejemplo n.º 1
0
        /// <summary>
        /// 获取用户所有菜单
        /// </summary>
        /// <param name="o4Identity"></param>
        /// <returns></returns>
        public List <MenuInfo> GetUserAllMenus(HsIdentity o4Identity)
        {
            List <MenuInfo> userMenus = GetUserMenus(o4Identity);
            List <RoleInfo> roles     = GetUserRoles((int)o4Identity.OperId);
            List <MenuInfo> roleMenus = GetRoleMenus(roles, o4Identity);
            List <MenuInfo> allMenus  = UnionMenus(userMenus, roleMenus);

            return(allMenus);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public HsIdentity Login(string userID, string pwd)
        {
            IT2ESBMessage esbmsg   = null;
            IT2Packer     packer   = null;
            IT2UnPacker   unpacker = null;
            HsIdentity    identity = null;

            try
            {
                esbmsg = t2.GetT2Esbmsg();
                packer = t2.GetT2Packer(T2PackVersion.PACK_VERSION2);

                packer.BeginPack();
                packer.AddField("user_login_id", T2FieldType.TYPE_STRING, userID);
                packer.AddField("user_pwd", T2FieldType.TYPE_STRING, pwd);
                packer.AddField("ws_mac", T2FieldType.TYPE_STRING, GetMacAddress());
                packer.EndPack();

                esbmsg.Prepare(T2TagDef.REQUEST_PACKET, USER_LOGIN);
                esbmsg.MsgBody = packer.GetPackBuf();
                t2.SynSendEsbMessage(ref esbmsg, 5000);

                if (esbmsg.ReturnCode != 0)
                {
                    if (esbmsg.ReturnCode == 1 || esbmsg.ReturnCode == -1)
                    {
                        throw new T2Exception(esbmsg.ErrorNo, esbmsg.ErrorInfo);
                    }
                }

                unpacker = t2.GetT2UnPacker(esbmsg.MsgBody);

                if (esbmsg.ReturnCode > 1) //说明有错
                {
                    int    errorNo   = unpacker.GetInt("error_no");
                    string errorInfo = unpacker.GetStr("error_info");
                    throw new T2Exception(errorNo, errorInfo);
                }
                else
                {
                    identity             = new HsIdentity();
                    identity.OperId      = unpacker.GetInt("user_id");
                    identity.OperCode    = unpacker.GetStr("user_login_id");
                    identity.CmpId       = unpacker.GetInt("cmp_id");
                    identity.SubSystemID = 1;//目前默认为1
                }
            }
            finally
            {
                //释放T2打包器接口
                if (null != packer)
                {
                    t2.ReleaseT2Packer(packer);
                }
                if (null != esbmsg)
                {
                    t2.ReleaseT2Esbmsg(esbmsg);
                }
                if (null != unpacker)
                {
                    // 释放T2解包器接口
                    t2.ReleaseT2UnPacker(unpacker);
                }
            }
            return(identity);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取角色菜单权限
        /// </summary>
        /// <param name="roles"></param>
        /// <param name="o4Identity"></param>
        /// <returns></returns>
        private List <MenuInfo> GetRoleMenus(List <RoleInfo> roles, HsIdentity o4Identity)
        {
            List <MenuInfo> menus = new List <MenuInfo>();

            if (roles == null || roles.Count == 0)
            {
                return(menus);
            }
            IT2ESBMessage esbmsg       = null;
            IT2Packer     packer       = null;
            IT2UnPacker   unpacker     = null;
            IT2UnPacker   funcUnpacker = null;

            try
            {
                esbmsg = t2.GetT2Esbmsg();
                packer = t2.GetT2Packer(T2PackVersion.PACK_VERSION2);

                packer.BeginPack();
                foreach (var roleInfo in roles)
                {
                    packer.AddField("role_id", T2FieldType.TYPE_INT, roleInfo.role_id);
                    packer.AddField("subsys_id", T2FieldType.TYPE_INT, o4Identity.SubSystemID);
                }
                packer.EndPack();

                esbmsg.Prepare(T2TagDef.REQUEST_PACKET, ROLE_MENU_QUERY);
                esbmsg.MsgBody = packer.GetPackBuf();
                t2.SynSendEsbMessage(ref esbmsg, 5000);

                if (esbmsg.ReturnCode != 0)
                {
                    if (esbmsg.ReturnCode == 1 || esbmsg.ReturnCode == -1)
                    {
                        throw new T2Exception(esbmsg.ErrorNo, esbmsg.ErrorInfo);
                    }
                }
                unpacker = t2.GetT2UnPacker(esbmsg.MsgBody);
                if (esbmsg.ReturnCode > 1) //说明有错
                {
                    int    errorNo   = unpacker.GetInt("error_no");
                    string errorInfo = unpacker.GetStr("error_info");
                    throw new T2Exception(errorNo, errorInfo);
                }
                else
                {
                    while (!unpacker.EOF)
                    {
                        MenuInfo menu = new MenuInfo();
                        menu.menu_id          = unpacker.GetInt("menu_id");
                        menu.menu_parent_id   = unpacker.GetInt("menu_parent_id");
                        menu.menu_order       = unpacker.GetStr("menu_order");
                        menu.menu_name        = unpacker.GetStr("menu_name");
                        menu.menu_plugin_type = Convert.ToChar(unpacker.GetChar("menu_plugin_type"));
                        menu.menu_plugin_name = unpacker.GetStr("menu_plugin_name");
                        menu.menu_plugin_dll  = unpacker.GetStr("menu_plugin_dll");
                        menu.menu_is_leaf     = Convert.ToChar(unpacker.GetChar("menu_is_leaf"));
                        menu.menu_icon_name   = unpacker.GetStr("menu_icon_name");
                        menu.menu_shortcut    = unpacker.GetStr("menu_shortcut");
                        menu.menu_multi_open  = Convert.ToChar(unpacker.GetChar("menu_multi_open"));
                        menu.menu_auto_open   = Convert.ToChar(unpacker.GetChar("menu_auto_open"));
                        menu.menu_allow_close = Convert.ToChar(unpacker.GetChar("menu_allow_close"));

                        List <FuncInfo> funcs   = new List <FuncInfo>();
                        byte[]          funcbuf = unpacker.GetRaw("i_func_list");
                        funcUnpacker = t2.GetT2UnPacker(funcbuf);
                        while (!funcUnpacker.EOF)
                        {
                            FuncInfo func   = new FuncInfo();
                            int      funcId = funcUnpacker.GetInt("func_id");
                            if (funcId > 0)
                            {
                                func.func_id   = funcId;
                                func.func_name = funcUnpacker.GetStr("func_name");
                                funcs.Add(func);
                            }
                            funcUnpacker.Next();
                        }
                        menu.i_func_list = funcs;
                        menus.Add(menu);
                        unpacker.Next();
                    }
                }
            }
            finally
            {
                //释放T2打包器接口
                if (null != packer)
                {
                    t2.ReleaseT2Packer(packer);
                }
                if (null != esbmsg)
                {
                    t2.ReleaseT2Esbmsg(esbmsg);
                }
                if (null != unpacker)
                {
                    // 释放T2解包器接口
                    t2.ReleaseT2UnPacker(unpacker);
                }
                if (null != funcUnpacker)
                {
                    t2.ReleaseT2UnPacker(funcUnpacker);
                }
            }
            return(menus);
        }