Esempio n. 1
0
 /// <summary>
 /// 关联菜单
 /// </summary>
 /// <param name="userMenus"></param>
 /// <param name="roleMenus"></param>
 /// <returns></returns>
 private List <MenuInfo> UnionMenus(List <MenuInfo> userMenus, List <MenuInfo> roleMenus)
 {
     if (userMenus == null && roleMenus == null)
     {
         return(new List <MenuInfo>());
     }
     if (userMenus == null)
     {
         return(roleMenus);
     }
     if (roleMenus == null)
     {
         return(userMenus);
     }
     foreach (var roleMenu in roleMenus)
     {
         MenuInfo userMenu = userMenus.Find(uMenu => uMenu.menu_id == roleMenu.menu_id);
         if (userMenu == null)
         {
             userMenus.Add(roleMenu);
             continue;
         }
         foreach (var roleFunc in roleMenu.i_func_list)
         {
             FuncInfo userFunc = userMenu.i_func_list.Find(uFunc => uFunc.func_id == roleFunc.func_id);
             if (userFunc == null)
             {
                 userMenu.i_func_list.Add(roleFunc);
             }
         }
     }
     return(userMenus);
 }
Esempio n. 2
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);
        }