/// <summary> /// Читаем параметры балансов /// </summary> /// <param name="transIds"></param> /// <param name="reactorsIds"></param> /// <param name="tis"></param> /// <param name="intgralTis"></param> /// <param name="tps"></param> /// <param name="formulas"></param> /// <param name="sections"></param> /// <param name="formulaConstantIds"></param> /// <returns></returns> private ConcurrentDictionary <string, BalanceFreeHierarchyCalculatedResult> ReadBalanceParams( List <string> balanceFreeHierarchyUN, ConcurrentDictionary <int, string> transIds, ConcurrentStack <int> reactorsIds, ConcurrentStack <TI_ChanelType> tis, ConcurrentStack <TI_ChanelType> intgralTis, ConcurrentStack <TP_ChanelType> tps, ConcurrentStack <TFormulaParam> formulas, ConcurrentStack <TSectionChannel> sections, ConcurrentStack <string> formulaConstantIds) { var resultByBalance = new ConcurrentDictionary <string, BalanceFreeHierarchyCalculatedResult>(); var subsections = new ConcurrentStack <Dict_Balance_FreeHierarchy_Subsection>(); using (var db = new FSKDataContext(Settings.DbConnectionString) { ObjectTrackingEnabled = false, DeferredLoadingEnabled = false, CommandTimeout = 180, }) { foreach (var range in Partitioner.Create(0, balanceFreeHierarchyUN.Count, Settings.MaxStringRows) .GetDynamicPartitions()) { var balanceFreeHierarchyUNs = balanceFreeHierarchyUN.GetRange(range.Item1, range.Item2 - range.Item1); var sprocBalanceParams = db.usp2_Info_GetBalanceFreeHierarchyParams( string.Join(",", balanceFreeHierarchyUNs), _dtServerStart, _dtServerEnd, _isGenerateDoc); var r = new Dictionary <string, BalanceFreeHierarchyCalculatedResult>(); foreach (var balanceParam in sprocBalanceParams.GetResult <Info_Balance_FreeHierarchy_List>() .Select(bl => new BalanceFreeHierarchyCalculatedResult(bl))) { r.Add(balanceParam.BalanceFreeHierarchyUn, balanceParam); resultByBalance.TryAdd(balanceParam.BalanceFreeHierarchyUn, balanceParam); } foreach (var bto in sprocBalanceParams.GetResult <BalanceFreeHierarchyToObject>()) { BalanceFreeHierarchyCalculatedResult hierarchyCalculatedResult; if (r.TryGetValue(bto.BalanceFreeHierarchy_UN, out hierarchyCalculatedResult)) { hierarchyCalculatedResult.ObjectId = bto.ToIdTypeHierarchy(); } } if (_isGenerateDoc) { //Заголовки подгрупп балансов var s = sprocBalanceParams.GetResult <Dict_Balance_FreeHierarchy_Subsection>().ToArray(); if (s.Length > 0) { subsections.PushRange(s); } } foreach (var bp in sprocBalanceParams.GetResult <usp2_Info_GetBalanceFreeHierarchyParamsResult>()) { BalanceFreeHierarchyCalculatedResult balanceResult; if (!r.TryGetValue(bp.BalanceFreeHierarchy_UN, out balanceResult)) { continue; } var itemParam = new BalanceFreeHierarchyItemParams { ChannelType = bp.ChannelType, BalanceFreeHierarchySectionUn = bp.BalanceFreeHierarchySection_UN, BalanceFreeHierarchySubsectionUn = bp.BalanceFreeHierarchySubsection_UN, BalanceFreeHierarchySubsectionUn2 = bp.BalanceFreeHierarchySubsection2_UN, BalanceFreeHierarchySubsectionUn3 = bp.BalanceFreeHierarchySubsection3_UN, IsOtpuskShin = !string.IsNullOrEmpty(bp.MetaString2) && bp.MetaString2.IndexOf("otpusk_shin", 0, StringComparison.Ordinal) >= 0, IsInput = !string.IsNullOrEmpty(bp.MetaString1) && bp.MetaString1.IndexOf("postupilo", 0, StringComparison.Ordinal) >= 0, IsOutput = !string.IsNullOrEmpty(bp.MetaString1) && bp.MetaString1.IndexOf("rashod", 0, StringComparison.Ordinal) >= 0, Coef = bp.Coef, SortNumber = bp.SortNumber, Name = bp.Name, MeasuringComplexError = bp.MeasuringComplexError, CoeffTransformation = bp.CoeffTransformation, CoeffLosses = bp.CoeffLosses, MeterSerialNumber = bp.MeterSerialNumber, Voltage = bp.Voltage }; List <BalanceFreeHierarchyItemParams> items; if (!balanceResult.ItemsParamsBySection.TryGetValue(itemParam.BalanceFreeHierarchySectionUn, out items)) { items = new List <BalanceFreeHierarchyItemParams>(); balanceResult.ItemsParamsBySection[itemParam.BalanceFreeHierarchySectionUn] = items; } items.Add(itemParam); if (bp.TI_ID.HasValue) { tis.Push(new TI_ChanelType { TI_ID = bp.TI_ID.Value, ChannelType = bp.ChannelType ?? 1, DataSourceType = (EnumDataSourceType?)bp.DataSource_ID, //ClosedPeriod_ID = Пока по закрытым периодам не формируем }); itemParam.Id = bp.TI_ID.Value; itemParam.TypeHierarchy = enumTypeHierarchy.Info_TI; } else if (bp.IntegralTI_ID.HasValue) { intgralTis.Push(new TI_ChanelType { TI_ID = bp.IntegralTI_ID.Value, ChannelType = bp.ChannelType ?? 1, DataSourceType = (EnumDataSourceType?)bp.DataSource_ID, //ClosedPeriod_ID = Пока по закрытым периодам не формируем }); itemParam.Id = bp.IntegralTI_ID.Value; itemParam.TypeHierarchy = enumTypeHierarchy.Info_Integral; } else if (bp.TP_ID.HasValue) { tps.Push(new TP_ChanelType { TP_ID = bp.TP_ID.Value, ChannelType = bp.ChannelType ?? 1, //Пока не работает //DataSourceType = (EnumDataSourceType?)bp.DataSource_ID, }); itemParam.Id = bp.TP_ID.Value; itemParam.TypeHierarchy = enumTypeHierarchy.Info_TP; } else if (!string.IsNullOrEmpty(bp.Formula_UN)) { formulas.Push(new TFormulaParam(bp.Formula_UN, enumFormulasTable.Info_Formula_Description, null, null, _dtServerStart, null)); itemParam.Un = bp.Formula_UN; itemParam.TypeHierarchy = enumTypeHierarchy.Formula; } else if (!string.IsNullOrEmpty(bp.OurFormula_UN)) { formulas.Push(new TFormulaParam(bp.OurFormula_UN, enumFormulasTable.Info_TP2_OurSide_Formula_Description, null, null, _dtServerStart, null)); itemParam.Un = bp.OurFormula_UN; itemParam.TypeHierarchy = enumTypeHierarchy.Formula_TP_OurSide; } else if (!string.IsNullOrEmpty(bp.ContrFormula_UN)) { formulas.Push(new TFormulaParam(bp.ContrFormula_UN, enumFormulasTable.Info_TP2_Contr_Formula_Description, null, null, _dtServerStart, null)); itemParam.Un = bp.ContrFormula_UN; itemParam.TypeHierarchy = enumTypeHierarchy.Formula_TP_CA; } else if (bp.PTransformator_ID.HasValue) { transIds.TryAdd(bp.PTransformator_ID.Value, bp.BalanceFreeHierarchy_UN); itemParam.Id = bp.PTransformator_ID.Value; itemParam.TypeHierarchy = enumTypeHierarchy.PTransformator; } else if (bp.PReactor_ID.HasValue) { reactorsIds.Push(bp.PReactor_ID.Value); itemParam.Id = bp.PReactor_ID.Value; itemParam.TypeHierarchy = enumTypeHierarchy.Reactor; } else if (bp.Section_ID.HasValue) { sections.Push(new TSectionChannel { Section_ID = bp.Section_ID.Value, ChannelType = bp.ChannelType.GetValueOrDefault(), }); itemParam.Id = bp.Section_ID.Value; itemParam.TypeHierarchy = enumTypeHierarchy.Section; } else if (!string.IsNullOrEmpty(bp.FormulaConstant_UN)) { formulaConstantIds.Push(bp.FormulaConstant_UN); itemParam.Un = bp.FormulaConstant_UN; itemParam.TypeHierarchy = enumTypeHierarchy.FormulaConstant; } } } } if (subsections.Count > 0) { SubsectionNames = subsections .GroupBy(s => s.BalanceFreeHierarchySubsection_UN) .ToDictionary(k => k.Key, v => v.First().BalanceFreeHierarchySubsectionName); } return(resultByBalance); }