Example #1
0
        /// <summary>
        /// 组装页面JSON对象
        /// </summary>
        /// <param name="multiLanguageKeyList">Page内HTML需要替换的Key</param>
        /// <param name="multiLanguageDataList">DB内现有的多语言数据</param>
        /// <returns></returns>
        private string AssemblyLanguagePackages(List <string> multiLanguageKeyList, List <Mc_Language> multiLanguageDataList)
        {
            string langJsStr_ZhCN = "var _Lang_ZhCN = {";
            string langJsStr_ZhTW = "var _Lang_ZhTW = {";
            string langJsStr_EnUS = "var _Lang_EnUS = {";
            //未在DB中的key需要插入
            List <string> keys2AddList = new List <string>();

            if (multiLanguageKeyList != null)
            {
                foreach (string langKey in multiLanguageKeyList)
                {
                    Mc_Language thisLang = multiLanguageDataList.FirstOrDefault(l => l.Language_Key == langKey);
                    if (thisLang != null)
                    {
                        langJsStr_ZhCN += "\"" + langKey + "\":\"" + thisLang.Zh_Cn + "\",";
                        langJsStr_ZhTW += "\"" + langKey + "\":\"" + thisLang.Zh_Tw + "\",";
                        langJsStr_EnUS += "\"" + langKey + "\":\"" + thisLang.En_Us + "\",";
                    }
                    else
                    {
                        keys2AddList.Add(langKey);
                        langJsStr_ZhCN += "\"" + langKey + "\":\"" + langKey + "\",";
                        langJsStr_ZhTW += "\"" + langKey + "\":\"" + langKey + "\",";
                        langJsStr_EnUS += "\"" + langKey + "\":\"" + langKey + "\",";
                    }
                }
            }

            //将新增的Key插入DB
            if (keys2AddList.Count > 0)
            {
                AddLangKey2DB(keys2AddList);
            }
            langJsStr_ZhCN = langJsStr_ZhCN.TrimEnd(',') + "};";
            langJsStr_ZhTW = langJsStr_ZhTW.TrimEnd(',') + "};";
            langJsStr_EnUS = langJsStr_EnUS.TrimEnd(',') + "};";
            string json = langJsStr_ZhCN + "\r\n" + langJsStr_ZhTW + "\r\n" + langJsStr_EnUS;

            return(json);
        }
Example #2
0
        /// <summary>
        /// 获得用户菜单
        /// </summary>
        /// <returns></returns>
        private MenuDTO GetMenuImp()
        {
            MenuDTO result = new MenuDTO();
            //1.当前user的所有function_id_list
            List <Guid> function_id_list = CubeDb.From <Mc_User_Function>()
                                           .Where(Mc_User_Function._.User_Id == User.Id)
                                           .Select(Mc_User_Function._.Function_Id)
                                           .ToList <Guid>();
            List <FunctionDTO> functionList = functionList = new List <FunctionDTO>();

            if (function_id_list != null)
            {
                functionList = CubeDb.From <Mc_Function>()
                               .Where(Mc_Function._.Id.In(function_id_list))
                               .Select(Mc_Function._.All)
                               .OrderBy(Mc_Function._.Code.Asc)
                               .ToList <FunctionDTO>();
            }

            //应对子功能有权限而父功能没有权限的情况
            List <FunctionDTO> parentFunctionList = new List <FunctionDTO>();

            foreach (FunctionDTO function in functionList)
            {
                if (function.Parent_Function_Id != null && function.Parent_Function_Id != Guid.Empty &&
                    !functionList.Exists(f => f.Id == function.Parent_Function_Id))
                {
                    FoundParentFunctionWithoutRight(function, parentFunctionList, functionList);
                }
            }
            functionList.AddRange(parentFunctionList);

            List <string>    system_id_list = functionList.Where(f => f.System_Id != null).Select(f => f.System_Id).ToList();
            List <SystemDTO> systemList     = CubeDb.From <Mc_System>()
                                              .Where(Mc_System._.Id.In(system_id_list))
                                              .Select(Mc_System._.All)
                                              .ToList <SystemDTO>();

            List <Guid>      domain_id_list = systemList.Where(s => s.Domain_Id != null).Select(s => s.Domain_Id).ToList();
            List <DomainDTO> domainList     = CubeDb.From <Mc_Domain>()
                                              .Where(Mc_Domain._.Id.In(domain_id_list))
                                              .Select(Mc_Domain._.All)
                                              .ToList <DomainDTO>();

            List <Guid>       product_id_list_from_system = systemList.Where(s => s.Product_Id != null).Select(s => s.Product_Id).ToList();
            List <Guid>       product_id_list_from_domain = domainList.Where(d => d.Product_Id != null).Select(d => d.Product_Id).ToList();
            List <Guid>       product_id_list             = product_id_list_from_system.Union(product_id_list_from_domain).ToList();
            List <ProductDTO> productList = CubeDb.From <Mc_Product>()
                                            .Where(Mc_Product._.Id.In(product_id_list))
                                            .Select(Mc_Product._.All)
                                            .ToList <ProductDTO>();

            //2.组装function
            foreach (FunctionDTO function in functionList)
            {
                function.SubFunctionList = functionList.FindAll(f => f.Parent_Function_Id != null && f.Parent_Function_Id.ToString().Equals(function.Id.ToString(), StringComparison.CurrentCultureIgnoreCase));

                if (function.Language_Key != null && !result.LanguageList.Exists(l => l.Language_Key == function.Language_Key))
                {
                    Mc_Language l = CubeDb.From <Mc_Language>()
                                    .Where(Mc_Language._.Language_Key == function.Language_Key)
                                    .Select(Mc_Language._.All)
                                    .ToList().FirstOrDefault();
                    if (l != null)
                    {
                        result.LanguageList.Add(l);
                    }
                }
            }

            //3.组装system
            foreach (SystemDTO system in systemList)
            {
                system.FunctionList = functionList.FindAll(f => (f.Parent_Function_Id == null || f.Parent_Function_Id == Guid.Empty) &&
                                                           f.System_Id != null && f.System_Id.ToString().Equals(system.Id.ToString(), StringComparison.CurrentCultureIgnoreCase));

                if (system.Language_Key != null && !result.LanguageList.Exists(l => l.Language_Key == system.Language_Key))
                {
                    Mc_Language l = CubeDb.From <Mc_Language>()
                                    .Where(Mc_Language._.Language_Key == system.Language_Key)
                                    .Select(Mc_Language._.All)
                                    .ToList().FirstOrDefault();
                    if (l != null)
                    {
                        result.LanguageList.Add(l);
                    }
                }
            }
            //System排序
            systemList = systemList.OrderBy(x => x.Code).ToList();

            //4.组装domain
            foreach (DomainDTO domain in domainList)
            {
                domain.SystemList = systemList.FindAll(s => s.Domain_Id != null &&
                                                       s.Domain_Id.ToString().Equals(domain.Id.ToString(), StringComparison.CurrentCultureIgnoreCase));
                if (domain.Language_Key != null && !result.LanguageList.Exists(l => l.Language_Key == domain.Language_Key))
                {
                    Mc_Language l = CubeDb.From <Mc_Language>()
                                    .Where(Mc_Language._.Language_Key == domain.Language_Key)
                                    .Select(Mc_Language._.All)
                                    .ToList().FirstOrDefault();
                    if (l != null)
                    {
                        result.LanguageList.Add(l);
                    }
                }
            }
            //domain排序
            domainList = domainList.OrderBy(d => d.Code).ToList();

            //5.组装product
            foreach (ProductDTO product in productList)
            {
                product.DomainList = domainList.FindAll(d => d.Product_Id != null &&
                                                        d.Product_Id.ToString().Equals(product.Id.ToString(), StringComparison.CurrentCultureIgnoreCase));
                product.SystemList = systemList.FindAll(s => (s.Domain_Id == null || s.Domain_Id == Guid.Empty) && s.Product_Id != null &&
                                                        s.Product_Id.ToString().Equals(product.Id.ToString(), StringComparison.CurrentCultureIgnoreCase));
            }

            //去除多余的Others
            ProductDTO othersProduct = new ProductDTO()
            {
                Id   = Guid.Empty,
                Name = "Others"
            };

            othersProduct.SystemList = systemList.FindAll(s => (s.Product_Id == null || s.Product_Id == Guid.Empty) &&
                                                          (s.Domain_Id == null || s.Domain_Id == Guid.Empty));
            othersProduct.DomainList = domainList.FindAll(sg => sg.Product_Id == null || sg.Product_Id == Guid.Empty);
            if (othersProduct.SystemList.Count() > 0 || othersProduct.DomainList.Count() > 0)
            {
                productList.Add(othersProduct);
            }

            if (SSOContext.IsDebug)
            {
                string     debugUrl     = System.Web.HttpUtility.UrlDecode(SSOContext.LocalDebugUrl).Replace("http://", "").Replace("https://", "");
                ProductDTO debugProduct = new ProductDTO();
                debugProduct.Id   = Guid.NewGuid();
                debugProduct.Name = "Debug";

                SystemDTO debugSystem = new SystemDTO();
                debugSystem.Code = "DEBUG";
                debugSystem.Id   = Guid.NewGuid();

                FunctionDTO debugFunction = new FunctionDTO();
                debugFunction.Code         = "DEBUG";
                debugFunction.Id           = Guid.NewGuid();
                debugFunction.Language_Key = "lang_debug";
                debugFunction.Url          = debugUrl;

                debugSystem.FunctionList.Add(debugFunction);
                debugProduct.SystemList.Add(debugSystem);
                productList.Add(debugProduct);
            }
            result.ProductList = productList;

            List <Guid> BookmarkIdList = CubeDb.From <Mc_Bookmark>()
                                         .Where(Mc_Bookmark._.User_Id == User.Id)
                                         .Select(Mc_Bookmark._.Function_Id).ToList <Guid>();
            List <FunctionDTO> bookmarkFunctionList = CubeDb.From <Mc_Function>()
                                                      .Where(Mc_Function._.Id.In(BookmarkIdList))
                                                      .Select(Mc_Function._.All)
                                                      .OrderBy(Mc_Function._.Code.Asc)
                                                      .ToList <FunctionDTO>();

            bookmarkFunctionList.RemoveAll(f => !function_id_list.Contains(f.Id));
            result.BookmarkList = bookmarkFunctionList;

            return(result);
        }