Exemplo n.º 1
0
        private void GeneratePeriodValues(BaseQueryModel model, MainInfo mainInfo)
        {
            decimal lastmonthEnergyValue = 0;
            model.Unit = ChartUnit.unit_month;
            model.Starttime = DateTime.Parse(model.Starttime.ToString("yyyy-MM-01"));
            model.Endtime = DateTime.Parse(model.Endtime.ToString("yyyy-MM-01"));
            var ResList = reportBll.GetBaseEneryDataList(model, true);
            if (ResList != null)
            {
                foreach (var r in ResList.BaseLayerObjectResults)
                {
                    lastmonthEnergyValue += decimal.Round(r.Value.Total, 2);
                }
            }

            #region 电能耗综合评价 上月日均用电量PK昨日用电量
            //取日的
            EnerySum enerySum = new EnerySum();
            enerySum.PeriodType = 1;//日
            //上月日均用电量:
            enerySum.Value1 =
                (lastmonthEnergyValue / System.DateTime.DaysInMonth(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month));
            enerySum.Value1 = decimal.Round(enerySum.Value1, 2);
            model.Unit = ChartUnit.unit_day;
            model.Starttime = DateTime.Parse(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));//昨天
            model.Endtime = model.Starttime;
            ResList = reportBll.GetBaseEneryDataList(model, true);
            foreach (var r in ResList.BaseLayerObjectResults)
            {
                //昨日用电量
                enerySum.Value2 += r.Value.Total;
            }
            enerySum.Value2 = decimal.Round(enerySum.Value2, 2);
            if (enerySum.Value1 > 0)
            {
                //环比
                enerySum.MonthCompare = decimal.Round(100 * (enerySum.Value2 - enerySum.Value1) / enerySum.Value1, 2)
                             .ToString(CultureInfo.InvariantCulture) + "%";
            }
            mainInfo.PeriodValues.Add(enerySum);
            #endregion

            #region 电能耗综合评价 上月周均用电量PK上周用电量
            //取周的
            enerySum = new EnerySum();
            enerySum.PeriodType = 2;//周
            //上月周均用电量:
            enerySum.Value1 =
                (lastmonthEnergyValue * 7 / DateTime.DaysInMonth(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month));
            enerySum.Value1 = decimal.Round(enerySum.Value1, 2);
            model.Unit = ChartUnit.unit_day;
            //上周一:
            DateTime lastMonday = getWeekUpOfDate(DateTime.Now, DayOfWeek.Monday, -1);
            model.Starttime = DateTime.Parse(lastMonday.ToString("yyyy-MM-dd"));
            model.Endtime = model.Starttime.AddDays(6);
            ResList = reportBll.GetBaseEneryDataList(model, true);
            foreach (var r in ResList.BaseLayerObjectResults)
            {
                //上周用电量
                enerySum.Value2 += r.Value.Total;
            }
            enerySum.Value2 = decimal.Round(enerySum.Value2, 2);
            if (enerySum.Value1 > 0)
            {
                //环比
                enerySum.MonthCompare = decimal.Round(100 * (enerySum.Value2 - enerySum.Value1) / enerySum.Value1, 2)
                             .ToString(CultureInfo.InvariantCulture) + "%";
            }
            mainInfo.PeriodValues.Add(enerySum);
            #endregion

            #region 电能耗综合评价 去年同月用电量PK本月用电量(精确到小时)
            //取月的,//本月用电量:取法为取昨天之前每天用电量之和加上今天当前时间之前每小时用电量
            enerySum = new EnerySum();
            enerySum.PeriodType = 3;//日
            int tempcount = DateTime.Now.Day - 1;//前几天
            //当前月的一号
            DateTime temptime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01"));
            if (tempcount > 0)
            {
                model.Unit = ChartUnit.unit_day;
                model.Starttime = temptime;
                model.Endtime = model.Starttime.AddDays(tempcount - 1);
                ResList = reportBll.GetBaseEneryDataList(model, true);
                foreach (var r in ResList.BaseLayerObjectResults)
                {
                    //本月用电量:取法为取昨天之前每天用电量之和加上今天当前时间之前每小时用电量
                    enerySum.Value2 += r.Value.Total;//上周用电量
                }
            }
            //-----------------------
            model.Unit = ChartUnit.unit_hour;
            //当前时间零点
            temptime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
            model.Starttime = temptime;
            model.Endtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:00:00"));
            ResList = reportBll.GetBaseEneryDataList(model, true);
            foreach (var r in ResList.BaseLayerObjectResults)
            {
                enerySum.Value2 += r.Value.Total;
            }
            //-----------------------
            //去年同月用电量
            tempcount = DateTime.Now.AddYears(-1).Day - 1;
            if (tempcount > 0)
            {
                model.Unit = ChartUnit.unit_day;
                //去年当月一号
                temptime = DateTime.Parse(DateTime.Now.AddYears(-1).ToString("yyyy-MM-01"));
                model.Starttime = temptime;
                model.Endtime = model.Starttime.AddDays(tempcount - 1);

                ResList = reportBll.GetBaseEneryDataList(model, true);
                foreach (var r in ResList.BaseLayerObjectResults)
                {
                    enerySum.Value1 += r.Value.Total;
                }
            }
            //-----------------------

            model.Unit = ChartUnit.unit_hour;
            //去年同时时间零点
            temptime = DateTime.Parse(DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd 00:00:00"));
            model.Starttime = temptime;
            model.Endtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:00:00"));
            ResList = reportBll.GetBaseEneryDataList(model, true);
            foreach (var r in ResList.BaseLayerObjectResults)
            {
                enerySum.Value1 = r.Value.Total;
            }
            //-----------------------
            enerySum.Value1 = decimal.Round(enerySum.Value1, 2);
            enerySum.Value2 = decimal.Round(enerySum.Value2, 2);
            if (enerySum.Value1 > 0)
            {
                enerySum.MonthCompare = decimal.Round(100 * (enerySum.Value2 - enerySum.Value1) / enerySum.Value1, 2)
                             .ToString(CultureInfo.InvariantCulture) + "%";
            }
            mainInfo.PeriodValues.Add(enerySum);

            #endregion

            #region 电能耗综合评价 去年同期用电PK今年截止本日用电量(精确到天)
            //取年的,//今年截止本日用电量:取法为取这个月之前每月用电量之和加上当前时间之前每天用电量
            enerySum = new EnerySum();
            enerySum.PeriodType = 4;//年
            tempcount = DateTime.Now.Month - 1;//前几月
            model.Unit = ChartUnit.unit_month;
            //当前时间的一月一号
            temptime = DateTime.Parse(DateTime.Now.ToString("yyyy-01-01"));
            if (tempcount>0)
            {
                model.Starttime = temptime;
                model.Endtime = model.Starttime.AddMonths(tempcount-1);
                ResList = reportBll.GetBaseEneryDataList(model, true);
                foreach (var r in ResList.BaseLayerObjectResults)
                {
                    enerySum.Value2 += r.Value.Total;
                }
            }
            //-----------------------
            tempcount = DateTime.Now.Day - 1;//前几天
            model.Unit = ChartUnit.unit_day;
            //当前月的一号
            temptime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01"));
            if (tempcount>0)
            {
                model.Starttime = temptime;
                model.Endtime = model.Starttime.AddDays(tempcount-1);
                ResList = reportBll.GetBaseEneryDataList(model, true);
                foreach (var r in ResList.BaseLayerObjectResults)
                {
                    enerySum.Value2 += r.Value.Total;
                }
            }
            //-----------------------

            //去年同期用电量

            tempcount = DateTime.Now.AddYears(-1).Month - 1;
            model.Unit = ChartUnit.unit_month;
            //去年一月一号
            temptime = DateTime.Parse(DateTime.Now.AddYears(-1).ToString("yyyy-01-01"));
            if (tempcount>0)
            {
                model.Starttime = temptime;
                model.Endtime = model.Starttime.AddMonths(tempcount-1);
                ResList = reportBll.GetBaseEneryDataList(model, true);
                foreach (var r in ResList.BaseLayerObjectResults)
                {
                    enerySum.Value1 += r.Value.Total;
                }
            }

            //-----------------------

            tempcount = DateTime.Now.AddYears(-1).Day - 1;//前几天
            model.Unit = ChartUnit.unit_day;
            //去年同期月一号
            temptime = DateTime.Parse(DateTime.Now.AddYears(-1).ToString("yyyy-MM-01"));
            if (tempcount>0)
            {
                model.Starttime = temptime;
                model.Endtime = model.Starttime.AddDays(tempcount-1);
                ResList = reportBll.GetBaseEneryDataList(model, true);
                foreach (var r in ResList.BaseLayerObjectResults)
                {
                    enerySum.Value1 += r.Value.Total;//上周用电量
                }
            }
            //-----------------------
            enerySum.Value1 = decimal.Round(enerySum.Value1, 2);
            enerySum.Value2 = decimal.Round(enerySum.Value2, 2);
            if (enerySum.Value1 > 0)
            {
                enerySum.MonthCompare = decimal.Round(100 * (enerySum.Value2 - enerySum.Value1) / enerySum.Value1, 2)
                             .ToString(CultureInfo.InvariantCulture) + "%";
            }
            mainInfo.PeriodValues.Add(enerySum);
            #endregion
        }
Exemplo n.º 2
0
        public MainInfo GetIndexCompareEneryNew()
        {
            //string username= HttpContext.Current.Session["userid"].ToString() ;
            MainInfo mainInfo = new MainInfo();
            var nowMonth = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-1"));
            var endTime = DateTime.Now;
            var pAction = new ExecuteProcess();

            try
            {
                mainInfo = new NTS.WEB.BLL.IndexEnery().GetIndexCompareEneryNew(nowMonth, endTime);
                pAction.Success = true;
                mainInfo.ActionInfo = pAction;
                return mainInfo;
            }
            catch (Exception e)
            {
                pAction.Success = false;
                pAction.ExceptionMsg = e.Message;
                return new MainInfo() { ActionInfo = pAction };
            }
        }
Exemplo n.º 3
0
        public MainInfo GetIndexCompareEneryNew(DateTime startTime, DateTime endTime)
        {
            MainInfo mainInfo = new MainInfo();
            mainInfo.IsOnlyElec = false;
            mainInfo.ItemValues = new List<EneryStatistic>();
            mainInfo.PeriodValues = new List<EnerySum>();
            var ObjectList = new BLL.BaseLayerObject().GetBaseFuncLayerObjectList(string.Format(" and LayerObjectParentID={0}", 0), " order by LayerObjectID");
            var ItemList = new BLL.Itemcode().GetItemcodeList(" and ParentID=0", " order by ItemcodeID");
            //var ItemList = new BLL.Itemcode().GetItemcodeList("", " order by ItemcodeID");

            EneryStatistic eneryStatistic4Elec = new EneryStatistic();
            if (ItemList.Count == 1)
            {//只有电
                mainInfo.IsOnlyElec = true;//只有电
                eneryStatistic4Elec.CName = ItemList[0].ItemCodeName;
                eneryStatistic4Elec.ItemCode = ItemList[0].ItemCodeNumber;
                eneryStatistic4Elec.Unit = ItemList[0].Unit;
                ItemList = new BLL.Itemcode().GetItemcodeList(string.Format(" and ParentID={0}", ItemList[0].ItemcodeID), " order by ItemcodeID");
            }
            BaseQueryModel model = new BaseQueryModel();
            model.IsDevice = 0;
            model.ObjectList = (from p in ObjectList select p.LayerObjectID).ToList<int>();

            foreach (var item in ItemList)
            {
                EneryStatistic eneryStatistic = new EneryStatistic();
                eneryStatistic.CName = item.ItemCodeName;
                eneryStatistic.ItemCode = item.ItemCodeNumber;
                eneryStatistic.Unit = item.Unit;

                model.ItemCode = item.ItemCodeNumber;
                decimal tempItemCoalEneryValue = 0;
                decimal tempLastMonthItemCoalEneryValue = 0;
                BaseResult ResList = new BaseResult();
                if ((endTime - startTime).Days > 0)
                {
                    model.Unit = ChartUnit.unit_day;
                    model.Starttime = startTime;
                    model.Endtime = DateTime.Parse(endTime.AddDays(-1).ToString("yyyy-MM-dd 00:00:00"));
                    ResList = reportBll.GetBaseEneryDataList(model, true);
                    if (ResList == null)
                    {
                        continue;
                    }
                    foreach (var r in ResList.BaseLayerObjectResults)
                    {
                        eneryStatistic.EneryValue += r.Value.Total;
                        eneryStatistic.EnergyValue2Coal += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                        tempItemCoalEneryValue += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                    }
                }
                if (endTime.Hour > 0)
                {
                    model.Unit = ChartUnit.unit_hour;
                    model.Starttime = DateTime.Parse(endTime.ToString("yyyy-MM-dd 00:00:00"));
                    model.Endtime = DateTime.Parse(endTime.ToString("yyyy-MM-dd HH:00:00"));
                    ResList = reportBll.GetBaseEneryDataList(model, true);
                    if (ResList == null)
                    {
                        continue;
                    }
                    foreach (var r in ResList.BaseLayerObjectResults)
                    {
                        eneryStatistic.EneryValue += r.Value.Total;
                        eneryStatistic.EnergyValue2Coal += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                        tempItemCoalEneryValue += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                    }
                }

                eneryStatistic.EneryValue = decimal.Round(eneryStatistic.EneryValue, 2);
                eneryStatistic.EnergyValue2Coal = decimal.Round(eneryStatistic.EnergyValue2Coal, 2);
                tempItemCoalEneryValue = decimal.Round(tempItemCoalEneryValue, 2);

                model.Starttime = startTime.AddMonths(-1);
                model.Endtime = endTime.AddMonths(-1);

                if ((endTime - startTime).Days > 0)
                {
                    model.Unit = ChartUnit.unit_day;
                    model.Endtime = DateTime.Parse(model.Endtime.AddDays(-1).ToString("yyyy-MM-dd 00:00:00"));
                    ResList = reportBll.GetBaseEneryDataList(model, true);
                    if (ResList == null)
                    {
                        continue;
                    }
                    foreach (var r in ResList.BaseLayerObjectResults)
                    {
                        eneryStatistic.EnergyLastMonth += decimal.Round(r.Value.Total, 2);
                        tempLastMonthItemCoalEneryValue += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                    }
                }
                if (endTime.Hour > 0)
                {
                    model.Unit = ChartUnit.unit_hour;
                    model.Starttime = DateTime.Parse(endTime.AddMonths(-1).ToString("yyyy-MM-dd 00:00:00"));
                    model.Endtime = DateTime.Parse(endTime.AddMonths(-1).ToString("yyyy-MM-dd HH:00:00"));
                    ResList = reportBll.GetBaseEneryDataList(model, true);
                    if (ResList == null)
                    {
                        continue;
                    }
                    foreach (var r in ResList.BaseLayerObjectResults)
                    {
                        eneryStatistic.EnergyLastMonth += decimal.Round(r.Value.Total, 2);
                        tempLastMonthItemCoalEneryValue += decimal.Parse(r.Value.ConvertDataValueList["ITEMCOAL"].ToString());
                    }
                }

                eneryStatistic.EnergyLastMonth = decimal.Round(eneryStatistic.EnergyLastMonth, 2);
                tempLastMonthItemCoalEneryValue = decimal.Round(tempLastMonthItemCoalEneryValue, 2);
                if (eneryStatistic.EnergyLastMonth > 0)
                {
                    eneryStatistic.MonthCompare = decimal.Round(100 * (eneryStatistic.EneryValue - eneryStatistic.EnergyLastMonth) / eneryStatistic.EnergyLastMonth, 2)
                                 .ToString(CultureInfo.InvariantCulture) + "%";
                }

                mainInfo.Total += Math.Round(tempItemCoalEneryValue, 2);
                mainInfo.TotalLastMon += Math.Round(tempLastMonthItemCoalEneryValue, 2);

                if (mainInfo.IsOnlyElec)
                {
                    eneryStatistic4Elec.EneryValue += eneryStatistic.EneryValue;
                    eneryStatistic4Elec.EnergyValue2Coal += eneryStatistic.EneryValue;
                    eneryStatistic4Elec.EnergyLastMonth += eneryStatistic.EnergyLastMonth;
                }
                mainInfo.ItemValues.Add(eneryStatistic);

                if (item.ItemCodeNumber == "01000")
                {

                    GeneratePeriodValues(model, mainInfo);
                }

            }

            if (mainInfo.TotalLastMon > 0)
            {
                mainInfo.TotalCompare = decimal.Round(100 * (mainInfo.Total - mainInfo.TotalLastMon) / mainInfo.TotalLastMon, 2)
                             .ToString(CultureInfo.InvariantCulture) + "%";
            }
            if (mainInfo.IsOnlyElec)
            {
                eneryStatistic4Elec.MonthCompare = mainInfo.TotalCompare;
                mainInfo.ItemValues.Insert(0, eneryStatistic4Elec);
                model.ItemCode = "01000";
                GeneratePeriodValues(model, mainInfo);
            }
            return mainInfo;
        }