예제 #1
0
파일: HomeService.cs 프로젝트: wkxuan/code
        /// <summary>
        /// 获取一个菜单的url
        /// </summary>
        /// <param name="menuid"></param>
        /// <returns></returns>
        public string GetMenuUrl(string menuid)
        {
            if (menuid.IsEmpty())
            {
                return(null);
            }
            MENUEntity menu = DbHelper.ExecuteOneObject <MENUEntity>($"select id,url from MENU where id='{menuid}'");

            if (menu == null)
            {
                throw new Exception($"找不到菜单{menuid}");
            }
            List <PLATFORMEntity> allp = DbHelper.SelectList(new PLATFORMEntity()
            {
                ID = menu.PLATFORMID
            });
            PLATFORMEntity ps = allp.FirstOrDefault(a => HttpContext.Current.Request.Url.Host.IsRegexMatch(a.MATCH));

            if (ps == null)
            {
                ps = allp.First();
            }
            return(ps.DOMAIN + menu.URL);
        }
예제 #2
0
        public UIResult GetMenu(MENUEntity data)
        {
            string host = Request.Url.Host;

            return(service.HomeService.GetMenuNew(data, host));
        }
예제 #3
0
파일: HomeService.cs 프로젝트: wkxuan/code
        public UIResult GetMenuNew(MENUEntity data, string host)
        {
            List <MENUTREEModule> MENU_GROUPList = new List <MENUTREEModule>();
            List <PLATFORMEntity> PlatFormList   = DbHelper
                                                   .SelectList(new PLATFORMEntity()
            {
                ID = data.PLATFORMID
            })
                                                   .GroupBy(a => a.ID)
                                                   .Select(a =>
            {
                var pt = a.FirstOrDefault(b => host.IsRegexMatch(b.MATCH));
                if (pt == null)
                {
                    pt = a.First();
                }
                return(new PLATFORMEntity()
                {
                    ID = a.Key,
                    DOMAIN = pt.DOMAIN
                });
            }).ToList();

            //子系统要多传递参数回来
            string sqlgroup = @" SELECT MODULECODE ID,MODULENAME NAME,ICON FROM USERMODULE WHERE LENGTH(MODULECODE)=4  and ENABLE_FLAG=1";

            if (int.Parse(employee.Id) > 0)
            {
                sqlgroup += @" and MODULECODE in (
                                        SELECT DISTINCT SUBSTR(A.MODULECODE,1,4) FROM USERMODULE A,ROLE_MENU B,USER_ROLE C
                                        WHERE A.MENUID=B.MENUID AND B.ROLEID=C.ROLEID
                                        AND C.USERID=" + employee.Id + ")";
            }
            if (int.Parse(data.PLATFORMID) == 1)
            {
                sqlgroup += @" and MODULECODE like '02%'";
            }
            if (int.Parse(data.PLATFORMID) == 2)
            {
                sqlgroup += @" and MODULECODE like '05%'";
            }
            sqlgroup += @" ORDER BY MODULECODE";
            DataTable menuGroup = DbHelper.ExecuteTable(sqlgroup);


            if (menuGroup.IsNotNull())
            {
                MENU_GROUPList = menuGroup.ToList <MENUTREEModule>();

                foreach (var menuGr in MENU_GROUPList)
                {
                    string sql = @" select aa.moduleid id,
                                    ab.id menuid,
                                    aa.modulename name,
                                    ab.url url,
                                    ab.platformid
                               from usermodule aa, menu ab
                              where  aa.menuid = ab.id and LENGTH(aa.MODULECODE)=6 and aa.ENABLE_FLAG=1
                                and aa.modulecode like  '" + menuGr.ID + "%'";
                    if (int.Parse(employee.Id) > 0)
                    {
                        //因菜单树型权限 按扭权限不全选时 对应菜单未保存到ROLE_MENU
                        //暂改成 由按扭权单id截取6位关联菜单id   by wangkx 20190705
                        //b.menuid 改为 to_number(substr( to_char(b.menuid),1,6))
                        // by DZK  20190716   ID取6位引起crm找不到子菜单,根据PLATFORMID 查询
                        if (int.Parse(data.PLATFORMID) == 1)
                        {
                            sql += @" and aa.menuid in (
                                                   select a.id
                                                     from menu a,
                                                           ROLE_MENU b,
                                                           USER_ROLE c
                                                    where a.id = to_number(substr( to_char(b.menuid),1,6))  
                                                      and b.roleid = c.roleid
                                                      and c.userid = " + employee.Id + @" or
                                    aa.menuid is null)";
                        }
                        else
                        {
                            sql += @" and aa.menuid in (
                                                   select a.id
                                                     from menu a,
                                                           ROLE_MENU b,
                                                           USER_ROLE c
                                                    where a.id = b.menuid 
                                                      and b.roleid = c.roleid
                                                      and c.userid = " + employee.Id + @" or
                                    aa.menuid is null)";
                        }
                    }

                    sql += " order by aa.modulecode  ";
                    DataTable menu = DbHelper.ExecuteTable(sql);
                    foreach (DataRow dr in menu.Rows)
                    {
                        string url = dr["URL"].ToString();
                        dr["PLATFORMID"].ToString().TryToInt(PlatFormId =>
                        {
                            var pt = PlatFormList.FirstOrDefault(a => a.ID == PlatFormId.ToString());
                            if (pt != null)
                            {
                                dr["URL"] = pt.DOMAIN + url;
                            }
                        });
                    }
                    menuGr.MENUList = menu.ToList <MENUEntity>();
                }
                ;
            }
            ;
            return(new UIResult(new
            {
                MENU = MENU_GROUPList
            }));
        }