Ejemplo n.º 1
0
        /// <summary>
        /// Информация по счётчику, расчётной точке, объекту учёта, договору из Ампер-М на основании ИД расчётной точки
        /// </summary>
        /// <param name="personalAccount">ИД расчётной точки в Ампер-М</param>
        /// <returns></returns>
        public static AmperGetPointInfo GetPersonalAccountInfoFromAmper(ulong personalAccount)
        {
            AmperGetPointInfo model = null;

            model = GetDataFromAmper <AmperGetPointInfo>(string.Format(@"getpoint?id={0}&format=json", personalAccount));

            if (model != null && model.Status == "200" && model.Found != "0")
            {
                return(model);
            }
            else
            {
                return(null);
            }
        }
        public void Start()
        {
            Status = "Получение данных";

            DateTime today         = DateTime.Today;
            DateTime month         = new DateTime(today.Year, today.Month, 1);
            DateTime prevMonth     = month.AddMonths(-1);
            DateTime prevPrevMonth = month.AddMonths(-2);

            IList <EnterpriseFromAmper> enterpriseFromAmper = Webservice.GetEnterprisesFromAmper("ОЭС");
            var resesNamesFromAmper = enterpriseFromAmper.Select(i => i.FullName);


            //var indicationsAnalizing = Webservice.GetIndicationsAnalyzing(prevPrevMonth, prevMonth, Profile.Months);

            var problemMeters = Webservice.GetMeterProblemInformations(OrderRule.ByLastUpdate);

            if (problemMeters != null && problemMeters.Count > 0)
            {
                ProblemMetersList = problemMeters
                                    .Where(i => Configuration.Instance.ResNames.Contains(i.ResName))
                                    .OrderBy(i => i.ResName)
                                    .OrderBy(i => i.City)
                                    .OrderBy(i => i.Street)
                                    .ToList();
                RaisePropertyChanged("ProblemMetersList");
            }

            List <SmallEngineExportViewItem> sesObjects = new List <SmallEngineExportViewItem>();

            foreach (string res in Configuration.Instance.ResNames)
            {
                var data = Webservice.GetSmallEngineObjects(prevPrevMonth, prevMonth, res);
                if (data != null && data.Count > 0)
                {
                    sesObjects.AddRange(data.Items);
                }
            }

            List <ConfigurationContainer> configs = new List <ConfigurationContainer>();

            foreach (EnterpriseViewItem res in Configuration.Instance.Reses)
            {
                var data = Webservice.GetAllConfigurationInformation(res.EnterpriseId, res.EnterpriseName);
                if (data != null)
                {
                    configs.AddRange(data);
                }
            }


            /*var qqq = q1.Items[0].LastSession;
             *
             *
             * //var q3 = Webservice.GetIndicationsAnalyzing(prevPrevMonth, prevMonth, Profile.Days);
             *
             * //var q4 = Webservice.Statistics(Profile.Months, 0, prevPrevMonth, prevMonth);
             *
             * //var q5 = Webservice.SmallEngineStatistics(Profile.Months, 0, prevMonth, prevPrevMonth);
             * // список модемов и УСПД
             * var q6 = Webservice.GetCollectorDevicesReport();
             *
             * var q7 = Webservice.GetChildElementsInHouseHoldSector("421990");
             *
             * //var t = Webservice.GetCountersGroupInformations("ОшРЭС");*/

            // !!
            //DetailedStatus = "получение информации по абонентам ...";
            //IEnumerable<Subscriber> subscribers = Webservice.GetSubscribers();
            //var groupedSubscribers = subscribers.GroupBy(i => i.SubscribersType).Select(i => new { Key = i.Key, Count = i.Count(), Items = i.ToList() });
            //var sesSubscribers = groupedSubscribers.Where(i => i.Key == "");

            DetailedStatus = "получение расходов ...";
            // записи вида PersonalAccount, TimeStamp и показания и расход по тарифам
            //TODO: Fix prevMonth
            List <AllTariffsExportIndicationViewItem> indications = Webservice.GetSmallEngineExportIndications(prevPrevMonth);

            //List<AllTariffsExportIndicationViewItem> indications1 = Webservice.GetSmallEngineExportIndications(prevPrevMonth, resesNames[0]);

            DetailedStatus = "получение информации по абонентам ...";
            // Получение списка потребителей с полями как в Ампер-М
            //IEnumerable<SmallEngineBillingObject> objects = Webservice.GetSmallEngineBillingObjects();

            //IEnumerable<SmallEngineBillingObject> objects1 = Webservice.GetSmallEngineBillingObjects(resesNames[0]);
            // группировка по РЭС
            //var groupedObjects = objects.GroupBy(i => i.ResName).Select(i => new { Key = i.Key, Count = i.Count(), Items = i.ToList() });
            // отбор с не пустым ИД
            //var emp = objects.Where(i => i.BillingPointPersonalAccount != 0);

            DetailedStatus = "подготовка списка ...";
            List <SmallEngineDataModel> list = new List <SmallEngineDataModel>();

            if (indications != null)
            {
                SmallEngineDataModel dataItem;

                List <AllTariffsExportIndicationViewItem> notFoundedAccounts = new List <AllTariffsExportIndicationViewItem>();
                foreach (AllTariffsExportIndicationViewItem item in indications)
                {
                    if (item.PersonalAccount != 0)
                    {
                        AmperGetPointInfo info = Webservice.GetPersonalAccountInfoFromAmper(item.PersonalAccount);
                        if (info != null && resesNamesFromAmper.Contains(info.Dogovor.Res))
                        {
                            dataItem = new SmallEngineDataModel(info);
                            dataItem.SetIndications(item);
                            list.Add(dataItem);
                        }
                        else
                        {
                            notFoundedAccounts.Add(item);
                        }
                        //SmallEngineBillingObject obj = objects.FirstOrDefault(i => i.BillingPointPersonalAccount == item.PersonalAccount);
                        //if (obj != null)
                        //{
                        //    dataItem = new SmallEngineDataModel(obj);
                        //    dataItem.SetIndications(item);
                        //    list.Add(dataItem);
                        //}
                        //else
                        //    notFoundedAccounts.Add(item);
                    }
                    else
                    {
                        dataItem = new SmallEngineDataModel()
                        {
                            BillingPointPersonalAccount = item.PersonalAccount
                        };
                        dataItem.SetIndications(item);
                        list.Add(dataItem);
                    }
                }

                System.Diagnostics.Debug.WriteLine(">> не найдено " + notFoundedAccounts.Count);

                Items = list;

                Configuration.Instance.Settings = new Data()
                {
                    Items       = list,
                    FromDate    = FromDate,
                    ToDate      = ToDate,
                    Profile     = SelectedProfile,
                    Enterprises = Configuration.Instance.Enterprises.ToList(),
                    SEO         = sesObjects,
                    Configs     = configs
                };
                Configuration.Instance.SaveData();
            }
        }