Пример #1
0
        /// <summary>
        /// 获取模板信息
        /// </summary>
        /// <param name="templateID"></param>
        /// <returns></returns>
        public QueryTemplateView GetQueryTemplateByID(long templateID)
        {
            QueryTemplateView template = null;

            using (var context = UnitOfWork.Get(Unity.ContainerName))
            {
                using (var qt = new QueryTemplateRepository(context))
                {
                    var result = qt.GetQueryTemplateByID(templateID);
                    if (result != null)
                    {
                        template = new QueryTemplateView()
                        {
                            TemplateID    = result.TemplateID,
                            BusinessType  = result.BusinessType,
                            IsHasNe       = result.IsHasNe,
                            MenuID        = result.MenuID,
                            NeLevel       = result.NeLevel,
                            NeType        = result.NeType,
                            ShareType     = result.ShareType,
                            TemplateName  = result.TemplateName,
                            VendorVersion = result.VendorVersion,
                            CreatedBy     = result.CreatedBy,
                            CreatedByName = result.CreatedByName,
                            CreatedTime   = result.CreatedTime,
                            UpdatedBy     = result.UpdatedBy,
                            UpdatedByName = result.UpdatedByName,
                            UpdatedTime   = result.UpdatedTime,
                        };
                    }
                }
                if (template != null)
                {
                    var counters             = _baseFormulaService.GetPerfFormulaDatas();
                    List <QueryGroup> groups = new List <QueryGroup>();
                    using (var qg = new QueryGroupRepository(context))
                    {
                        groups = qg.GetQueryGroups().Where(p => p.TemplateID == templateID).ToList();
                    }
                    List <QueryFilter> queryFilters = new List <QueryFilter>();
                    var condtionGroups = new List <ConditionGroup>();
                    if (groups != null && groups.Count > 0)
                    {
                        var ids = groups.Select(g => g.ID).ToArray();
                        using (var qg = new QueryFilterRepository(context))
                        {
                            queryFilters = qg.GetQueryFilters().Where(p => ids.Contains(p.GroupID)).ToList();
                            queryFilters.ForEach(p =>
                            {
                                p.FieldName = _baseFormulaService.GetById(p.FieldID).AttCnName;
                                p.Alias     = string.Format("{0}{1}", "P", p.FieldID);
                                if (counters.ContainsKey(p.FieldID))
                                {
                                    p.UserInBSC  = 1;//counters[p.FieldID].NeCombination;
                                    p.UserInBTS  = 1;
                                    p.UserInCARR = 1;
                                    p.UserInCELL = 1;
                                }
                            });
                        }

                        BuildCondition(condtionGroups, groups, queryFilters, string.Empty);
                    }
                    template.FilterGroup.AddRange(condtionGroups);

                    List <QueryField> queryFields    = new List <QueryField>();
                    List <QueryField> baseDataFields = new List <QueryField>();
                    using (var qf = new QueryFieldRepository(context))
                    {
                        var queryFieldsList = qf.GetQueryFields().Where(p => p.TemplateID == templateID).ToList();
                        //queryFieldsList.ForEach(p =>
                        //{
                        //    p.FieldName = BaseFormulaManager.GetFormula(p.FieldID).AttCnName;
                        //    p.Alias = string.Format("{0}{1}", "P", p.FieldID);
                        //});

                        foreach (var field in queryFieldsList)
                        {
                            var formula = _baseFormulaService.GetById(field.FieldID);
                            if (formula.DataSource == (int)UqlType.IndicatorData)
                            {
                                field.FieldName = formula.AttCnName;
                                field.Alias     = string.Format("{0}{1}", "P", field.FieldID);
                                if (counters.ContainsKey(field.FieldID))
                                {
                                    field.UserInBSC  = 1;// counters[field.FieldID].NeCombination;
                                    field.UserInBTS  = 1;
                                    field.UserInCARR = 1;
                                    field.UserInCELL = 1;
                                }
                                queryFields.Add(field);
                            }
                            else if (formula.DataSource == (int)UqlType.BaseData)
                            {
                                field.FieldName = formula.Formula;
                                field.Alias     = formula.AttCnName;
                                if (counters.ContainsKey(field.FieldID))
                                {
                                    field.UserInBSC  = 1;// counters[field.FieldID].NeCombination;
                                    field.UserInBTS  = 1;
                                    field.UserInCARR = 1;
                                    field.UserInCELL = 1;
                                }
                                baseDataFields.Add(field);
                            }
                        }
                    }
                    template.QueryFields.AddRange(queryFields);
                    template.BaseQueryFields.AddRange(baseDataFields);
                    if (template.IsHasNe)
                    {
                        var qne = new QueryNeRepository(context).GetQueryNe(templateID);
                        if (qne != null)
                        {
                            template.NeParameter = qne.NeValue;
                            template.NeNames     = qne.NeName;
                        }
                    }
                }
                if (template != null)
                {
                    var  csr           = new ColorSettingRepository(context);
                    long i             = 400000000 + template.MenuID * 1000;
                    var  colorsettings = csr.All().Where(t => t.ModuleId.Equals(i) && t.SettingName.Contains(template.TemplateID + "|")).ToList();
                    if (colorsettings != null)
                    {
                        template.ColorLevelCfgInfos = colorsettings;
                    }
                }
            }



            return(template);
        }
Пример #2
0
        /// <summary>
        /// 更新模板信息
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public int UpdateQueryTemplates(QueryTemplateView item)
        {
            using (var context = UnitOfWork.Get(Unity.ContainerName))
            {
                var result = 0;
                context.UsingTransaction(() =>
                {
                    new QueryTemplateRepository(context).UpdateQueryTemplate(item);
                    var r           = new QueryGroupRepository(context);
                    var queryGroups = r.GetQueryGroups().Where(p => p.TemplateID == item.TemplateID).Select(p => p.ID).ToList();
                    if (queryGroups != null && queryGroups.Count > 0)
                    {
                        r.DeleteQueryGroupByTemplateID(item.TemplateID);
                        new QueryFilterRepository(context).DeleteQueryFilterByGroupID(queryGroups);
                    }
                    List <QueryGroup> groups   = new List <QueryGroup>();
                    List <QueryFilter> filters = new List <QueryFilter>();
                    Recursive(item.FilterGroup, null, null, 0, item.TemplateID, groups, filters);

                    new QueryGroupRepository(context).BacthAddQueryGroup(groups);
                    new QueryFilterRepository(context).AddBatchQueryFilter(filters);
                    if (item.QueryFields != null && item.QueryFields.Count > 0)
                    {
                        var qf = new QueryFieldRepository(context);
                        qf.DeleteQueryFieldByTemplateID(new long[] { item.TemplateID });
                        item.QueryFields.ForEach(p =>
                        {
                            p.TemplateID = item.TemplateID;
                        });

                        if (item.BaseQueryFields != null && item.BaseQueryFields.Count > 0)
                        {
                            item.BaseQueryFields.ForEach(p =>
                            {
                                p.TemplateID = item.TemplateID;
                            });
                            item.QueryFields.AddRange(item.BaseQueryFields);
                        }

                        qf.AddBatchQueryField(item.QueryFields);
                    }

                    if (item.ColorLevelCfgInfos != null && item.ColorLevelCfgInfos.Count > 0)
                    {
                        //var service = ServiceFactory.GetService<IColorSettingService>();
                        var csr      = new ColorSettingRepository(context);
                        var settings = csr.All().Where(t => t.ModuleId.Equals(400000000 + item.MenuID * 1000) && t.SettingName.Contains(item.TemplateID.ToString() + "|")).ToList();
                        if (settings.FirstOrDefault() != null)
                        {
                            csr.Delete(settings.Select(p => p.Id));
                            csr.DeleteDynamic(settings.Select(p => p.Id));
                        }

                        item.ColorLevelCfgInfos.ForEach(p =>
                        {
                            p.ModuleId    = 400000000 + item.MenuID * 1000;
                            p.SettingName = string.Format("{0}|{1}|{2}", p.SettingName, item.TemplateID, item.TemplateName);
                        });
                        csr.Add(item.ColorLevelCfgInfos);
                        var list = new List <ColorLevelDynamicInfo>();
                        item.ColorLevelCfgInfos.ForEach(o =>
                        {
                            list.AddRange(o.SectionList);
                        });
                        csr.Add(list);
                    }

                    if (item.IsHasNe)
                    {
                        var qne = new QueryNeRepository(context).GetQueryNe(item.TemplateID);
                        if (qne != null)
                        {
                            new QueryNeRepository(context).UpdateQueryNe(new QueryNe {
                                TemplateID = item.TemplateID, NeValue = item.NeParameter, NeName = item.NeNames
                            });
                        }
                        else
                        {
                            new QueryNeRepository(context).AddQueryNe(new QueryNe {
                                TemplateID = item.TemplateID, NeValue = item.NeParameter, NeName = item.NeNames
                            });
                        }
                    }
                    result = 1;
                });
                return(result);
            }
        }