Esempio n. 1
0
        private Model.QuotaAnalyseModel GetQuotaAnalyseModel(QueryQuota query)
        {
            string strwhere = "";
            switch (query.Particle)
            {
                case Particle.Year://年定额分析
                    strwhere = string.Format(@"and objectid={0}
                                               and quotatype={1}
                                               and itemcode='{2}'
                                               and quotatime='{3}'", query.ObjectId, (int)query.Particle - 1, query.ItemCode, query.StartTime.ToString("yyyy-01-01"));

                    break;
                case Particle.Month://月定额分析
                    strwhere = string.Format(@"and objectid={0}
                                               and quotatype={1}
                                               and itemcode='{2}'
                                               and quotatime='{3}'", query.ObjectId, (int)query.Particle - 1, query.ItemCode, query.StartTime.ToString("yyyy-MM-01"));
                    break;
                default:
                    break;
            }

            return new QuotaAnalyse().GetQuotaAnalyse(strwhere);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取定额分析
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public ResultQuota GetQuotaAnalyseChart(QueryQuota query)
        {
            try
            {

                #region 返回对象定义
                ResultQuota result = new ResultQuota()
                {
                    Pie = new QuotaAnalysePie(),
                    BalanceHighChart = new QuotaHighChart() { series = new List<EneryAnalyseSeries>() },
                    TrendHighChart = new QuotaHighChart() { series = new List<EneryAnalyseSeries>() }
                };
                #endregion

                #region itemCodeList
                List<Model.Itemcode> itemCodeList = new List<Model.Itemcode>();

                if (query.ItemCode == "00000")
                {//总能耗
                    itemCodeList = new BLL.Itemcode().GetItemcodeList(" and ParentID=0 ", " order by ItemcodeID");
                    result.Unit = "T";//标准煤单位
                }
                else
                {
                    itemCodeList = new BLL.Itemcode().GetItemcodeList(" and ItemCodeNumber='" + query.ItemCode + "'", " order by ItemcodeID");
                    if (itemCodeList.Count > 0)
                    {
                        result.Unit = itemCodeList[0].Unit;//单个分类分项单位
                    }
                }
                #endregion

                #region 生成EndTime

                switch (query.Particle)
                {
                    case Particle.Month://月 query.StartTime格式为yyyy-MM-01
                        query.EndTime = query.StartTime.AddMonths(1).AddDays(-1);
                        int day = DateTime.Now.Day;
                        if (query.StartTime.Year == DateTime.Now.Year && query.StartTime.Month == DateTime.Now.Month )//月、年第一天不算进去
                        {//当月

                            query.EndTime = DateTime.Now;//精确到前一天的能耗值

                        }
                        break;
                    case Particle.Year://年  query.StartTime格式为yyyy-01-01
                        query.EndTime = query.StartTime.AddYears(1).AddMonths(-1);
                        if (query.StartTime.Year == DateTime.Now.Year)//月、年第一天不算进去
                        {
                            query.EndTime = DateTime.Now;
                        }
                        break;
                    default:
                        query.EndTime = query.StartTime.AddMonths(1).AddDays(-1);
                        if (query.StartTime.Year == DateTime.Now.Year && query.StartTime.Month == DateTime.Now.Month)
                        {
                            query.EndTime = DateTime.Now.AddDays(-1);
                        }
                        break;
                }
                #endregion

                #region 获取定额值
                Model.QuotaAnalyseModel quotaAnalyseModel = GetQuotaAnalyseModel(query);
                if (quotaAnalyseModel != null)
                {
                    result.Pie.QuotaValue = decimal.Round(quotaAnalyseModel.QuotaValue, 2);
                    if (!(quotaAnalyseModel.QuotaValue > 0))
                    {
                        throw new Exception("无效的定额值");
                    }
                }
                else
                {
                     throw new Exception("当前未设置定额值");
                    //result.Pie.QuotaValue = 10000;
                }
                #endregion

                var model = new BaseQueryModel();
                model.IsDevice = 0;
                model.ObjectList = new List<int>() { query.ObjectId };
                model.Unit = BaseTool.GetChartUnit((int)query.Particle - 1);//查询颗粒度比方法中的颗粒度大于一
                decimal averagequotavalue = 0;
                int TotalCount = 1;//月天数或者12月
                if (model.Unit == ChartUnit.unit_month)
                {//年定额分析 精确到天
                    model.Starttime = Convert.ToDateTime(query.StartTime.ToString("yyyy-MM-01"));
                    model.Endtime = Convert.ToDateTime(query.EndTime.ToString("yyyy-MM-01"));
                    //定额月平均值
                    averagequotavalue = decimal.Round(result.Pie.QuotaValue / 12, 2);
                    TotalCount = 12;
                }
                else
                {//月定额分析 精确到小时
                    model.Starttime = query.StartTime;
                    model.Endtime = query.EndTime;
                    //定额日平均值
                    TotalCount = DateTime.DaysInMonth(query.StartTime.Year, query.StartTime.Month);
                    averagequotavalue = decimal.Round(result.Pie.QuotaValue / TotalCount, 2);

                }

                Dictionary<string, decimal> tempConvert = new Dictionary<string, decimal>();
                if(query.EndTime>=query.StartTime)
                {
                    tempConvert = GetSingleItemCodeValue(model, query, itemCodeList);
                }

                result.Pie.ActualValue = decimal.Round(tempConvert.Select(t => t.Value).Sum(), 2);
                result.Pie.OverPlusValue = decimal.Round(result.Pie.QuotaValue - result.Pie.ActualValue, 2);
                result.Pie.OverPlusPercent = (result.Pie.OverPlusValue * 100 / result.Pie.QuotaValue).ToString("0.00") + "%";

                var balanceQuotaValue = new List<decimal>();
                for (int i = 0; i <= TotalCount - 1;i++ )
                {
                    balanceQuotaValue.Add(result.Pie.QuotaValue);
                }
                //趋势分析能耗值
                var TrendActualValue = new List<decimal>();
                TrendActualValue = (from item in tempConvert select decimal.Round(item.Value, 2)).ToList();
                for (int i = 0; i <= TrendActualValue.Count - 1; i++)
                {
                    if (i > 0)
                    {
                        TrendActualValue[i] = TrendActualValue[i] + TrendActualValue[i - 1];
                    }

                }
                //差额分析能耗值
                result.BalanceHighChart.series.Add(new EneryAnalyseSeries()
                {
                    name = "ActualLine",
                    //data = (from item in tempConvert select decimal.Round(item.Value, 2)).ToList()
                    data = TrendActualValue
                });
                //差额分析定额值

                result.BalanceHighChart.series.Add(new EneryAnalyseSeries()
                {
                    name = "QuotaLine",
                    data = balanceQuotaValue
                });
                //差额分析能耗差值
                result.BalanceHighChart.series.Add(new EneryAnalyseSeries()
                {
                    name = "BalanceLine",
                    data = ((from item in TrendActualValue select result.Pie.QuotaValue - decimal.Round(item, 2))).ToList()
                });
                //趋势分析定额值
                var TrendQuotaValue = new List<decimal>();

                //趋势分析预测值
                var TrendForeCastValue = new List<decimal>();

                result.TrendHighChart.series.Add(new EneryAnalyseSeries()
                {
                    name = "ActualLine",
                    data = TrendActualValue
                });
                int[] x = new int[TotalCount];
                int count = 1;
                //TrendQuotaValue.Add(0);//以0坐标开始
                for (int i = 0; i <= x.Length - 1; i++)
                {
                    x[i] = i;
                    if (count == x.Length)
                    {
                        TrendQuotaValue.Add(result.Pie.QuotaValue);
                    }
                    else
                    {
                        TrendQuotaValue.Add(averagequotavalue * count);
                    }
                    count++;
                }
                result.TrendHighChart.series.Add(new EneryAnalyseSeries()
                {
                    name = "QuotaLine",
                    data = TrendQuotaValue
                });
                TrendForeCastValue = SPT(x, TrendActualValue.ToArray());
                //预测节能率:定额值-线性回归公式值(最后一天或者12月)/定额值
                if (TrendForeCastValue.Count>0)
                {
                    result.Pie.ForecastSavingPercent = ((result.Pie.QuotaValue - TrendForeCastValue[TrendForeCastValue.Count - 1]) * 100 / result.Pie.QuotaValue).ToString("0.00") + "%";
                }
                else
                {
                    result.Pie.ForecastSavingPercent = "-";
                }

                #region 暂时禁用

                //decimal lastvalue = 0;
                //decimal lastsecondvalue = 0;
                //if (TrendActualValue.Count > 0)
                //{
                //    lastvalue = TrendActualValue[TrendActualValue.Count - 1];
                //    if (TrendActualValue.Count > 1)
                //    {
                //        lastsecondvalue = TrendActualValue[TrendActualValue.Count - 2];
                //    }
                //}
                //if (query.Particle == Particle.Year)
                //{
                //    if (query.StartTime.Year < DateTime.Now.Year)
                //    {
                //        result.Pie.ForecastSavingPercent = ((result.Pie.QuotaValue - result.Pie.ActualValue) * 100 / result.Pie.QuotaValue).ToString("0.00") + "%";

                //    }
                //    else
                //    {
                //        //当前理论计划值= 年定额值/12*(结束时间月-1)+年定额值/12/结束月的总天数*(结束时间天-1)
                //        decimal theoryPlanvalue = result.Pie.QuotaValue / 12 * (query.EndTime.Month - 1) + result.Pie.QuotaValue / 12 / DateTime.DaysInMonth(query.EndTime.Year, query.EndTime.Month) * (query.EndTime.Day - 1);
                //        //预测节能率=(当前理论计划值-实时能耗值)/年定额值,
                //        result.Pie.ForecastSavingPercent = ((theoryPlanvalue - result.Pie.ActualValue) * 100 / result.Pie.QuotaValue).ToString("0.00") + "%";
                //        if (query.EndTime.Month < 12)
                //        {//添加趋势预测线
                //            TrendForeCastValue.Add(lastvalue);

                //            for (int i = 1; i <= (12 - query.EndTime.Month); i++)
                //            {
                //                TrendForeCastValue.Add(lastvalue + (lastvalue - lastsecondvalue) * i);
                //            }
                //        }
                //    }

                //}
                //else
                //{
                //    if (query.StartTime.Month < DateTime.Now.Month)
                //    {
                //        result.Pie.ForecastSavingPercent = ((result.Pie.QuotaValue - result.Pie.ActualValue) * 100 / result.Pie.QuotaValue).ToString("0.00") + "%";
                //    }
                //    else
                //    {
                //        //当前理论计划值= 月定额值/当月天数*(当前天-1)+月定额值/当月天数/24*(当前小时数)
                //        decimal theoryPlanvalue = result.Pie.QuotaValue / DateTime.DaysInMonth(query.EndTime.Year, query.EndTime.Month) * (query.EndTime.Day - 1) + result.Pie.QuotaValue / DateTime.DaysInMonth(query.EndTime.Year, query.EndTime.Month) / 24 * (query.EndTime.Hour);
                //        //预测节能率=(当前理论计划值-实时能耗值)/年定额值,
                //        result.Pie.ForecastSavingPercent = ((theoryPlanvalue - result.Pie.ActualValue) * 100 / result.Pie.QuotaValue).ToString("0.00") + "%";
                //    }
                //    if (query.EndTime.Day < DateTime.DaysInMonth(query.StartTime.Year, query.StartTime.Month))
                //    {//添加趋势预测线
                //        TrendForeCastValue.Add(lastvalue);

                //        for (int i = 1; i <= (DateTime.DaysInMonth(query.StartTime.Year, query.StartTime.Month) - query.EndTime.Day); i++)
                //        {
                //            TrendForeCastValue.Add(lastvalue + (lastvalue - lastsecondvalue) * i);
                //        }
                //    }
                //}
                #endregion
                result.TrendHighChart.series.Add(new EneryAnalyseSeries()
                {
                    name = "ForeCastLine",
                    data = TrendForeCastValue
                });
                //同比
                query.StartTime = query.StartTime.AddYears(-1);
                query.EndTime = query.EndTime.AddYears(-1);
                quotaAnalyseModel = GetQuotaAnalyseModel(query);
                if (quotaAnalyseModel != null)
                {
                    result.Pie.LastYearQuotaValue = decimal.Round(quotaAnalyseModel.QuotaValue, 2); ;
                    if (!(quotaAnalyseModel.QuotaValue > 0))
                    {
                        throw new Exception("无效的定额值");
                    }
                }
                else
                {
                    //throw new Exception("当前未设置定额值");
                    result.Pie.LastYearQuotaValue = 0;
                }

                model.Unit = BaseTool.GetChartUnit((int)query.Particle - 1);
                if (model.Unit == ChartUnit.unit_month)
                {//年定额分析 精确到天
                    model.Starttime = Convert.ToDateTime(query.StartTime.ToString("yyyy-MM-01"));
                    model.Endtime = Convert.ToDateTime(query.EndTime.ToString("yyyy-12-01"));

                }
                else
                {//月定额分析 精确到小时

                    model.Starttime = query.StartTime;
                    model.Endtime = model.Starttime.AddMonths(1);

                }
                //model.Unit = ChartUnit.unit_month;
                //model.Starttime = Convert.ToDateTime(query.StartTime.ToString("yyyy-MM-01"));
                //model.Endtime = Convert.ToDateTime(query.EndTime.ToString("yyyy-MM-01"));
                //if(query.Particle==Particle.Year)
                //{
                //    model.Endtime = Convert.ToDateTime(query.EndTime.ToString("yyyy-12-01"));
                //}

                tempConvert = new Dictionary<string, decimal>();
                if (query.EndTime >= query.StartTime)
                {
                    tempConvert = GetSingleItemCodeValue(model, query, itemCodeList);
                }

                result.Pie.LastYearActualValue = decimal.Round(tempConvert.Select(t => t.Value).Sum(), 2);
                if (result.Pie.LastYearQuotaValue>0)
                {
                    result.Pie.LastYearSavingPercent =
                   ((result.Pie.LastYearActualValue - result.Pie.LastYearQuotaValue) * 100 / result.Pie.LastYearQuotaValue)
                       .ToString("0.00") + "%";
                }
                else
                {
                    result.Pie.LastYearSavingPercent = "-";
                }

                return result;
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }
Esempio n. 3
0
        public Dictionary<string, decimal> GetSingleItemCodeValue(BaseQueryModel model, QueryQuota query, List<Model.Itemcode> itemCodeList)
        {
            Dictionary<string, decimal> tempConvert = new Dictionary<string, decimal>();
            //if (model.Endtime.Day==1)
            //{
            //    return tempConvert;
            //}
               // Dictionary<string, decimal> tempHourConvert = new Dictionary<string, decimal>();//暂时禁用小时
            switch (model.Unit)
            {
                case ChartUnit.unit_month:
                    for (DateTime i = model.Starttime; i <= model.Endtime; i = i.AddMonths(1))
                    {
                        tempConvert.Add(i.ToString("yyyy-MM-dd"), 0);
                    }
                    break;
                case ChartUnit.unit_hour:
                    for (DateTime i = model.Starttime; i < model.Endtime.AddDays(1); i = i.AddHours(1))
                    {
                        tempConvert.Add(i.ToString("yyyy-MM-dd HH:mm:ss"), 0);
                    }
                    break;
                case ChartUnit.unit_day:
                    if (query.EndTime.Hour > 0)
                    {
                        for (DateTime i = model.Starttime; i <=model.Endtime.AddDays(-1); i = i.AddDays(1))
                        {
                            tempConvert.Add(i.ToString(("yyyy-MM-dd")), 0);
                        }
                        //暂时禁用小时
                        //for (DateTime i = DateTime.Parse(model.Endtime.ToString("yyyy-MM-dd 00:00:00")); i < model.Endtime; i = i.AddHours(1))
                        //{
                        //    tempHourConvert.Add(i.ToString("yyyy-MM-dd HH:mm:ss"), 0);
                        //}
                    }
                    else
                    {
                        for (DateTime i = model.Starttime; i <= model.Endtime; i = i = i.AddDays(1))
                        {
                            tempConvert.Add(i.ToString(("yyyy-MM-dd")), 0);
                        }
                    }

                    break;
            }
            foreach (var item in itemCodeList)
            {
                model.ItemCode = item.ItemCodeNumber;
                BaseResult resList = _reportBll.GetBaseEneryDataList(model, query.ObjType == AreaType.Liquid ? true : false);
                foreach (var r in resList.BaseLayerObjectResults)
                {
                    foreach (var rr in r.Value.Datas)
                    {
                        if (tempConvert.ContainsKey(rr.DatePick))
                        {
                            if (query.ItemCode == "00000")
                            {
                                tempConvert[rr.DatePick] += rr.CoalDataValue;
                            }
                            else
                            {
                                tempConvert[rr.DatePick] += rr.DataValue;
                            }
                        }
                    }
                }

                //if (tempHourConvert.Count > 0)
                //{
                //    model.Starttime = DateTime.Parse(query.EndTime.ToString("yyyy-MM-dd 01:mm:ss"));
                //    model.Unit = ChartUnit.unit_hour;
                //    resList = _reportBll.GetBaseEneryDataList(model, query.ObjType == AreaType.Liquid ? true : false);
                //    foreach (var r in resList.BaseLayerObjectResults)
                //    {
                //        foreach (var rr in r.Value.Datas)
                //        {
                //            if (tempHourConvert.ContainsKey(rr.DatePick))
                //            {
                //                if (query.ItemCode == "00000")
                //                {
                //                    tempHourConvert[rr.DatePick] += rr.CoalDataValue;
                //                }
                //                else
                //                {
                //                    tempHourConvert[rr.DatePick] += rr.DataValue;
                //                }
                //            }

                //        }
                //    }
                //    decimal currentdayvalue = tempHourConvert.Select(t => t.Value).Sum();
                //    tempConvert.Add(model.Endtime.ToString(("yyyy-MM-dd")), currentdayvalue);
                //}
            }
            return tempConvert;
        }
Esempio n. 4
0
 public ResultQuota GetQuotaAnalyseChart(QueryQuota query)
 {
     var pAction = new ExecuteProcess();
     try
     {
         var result = new NTS.WEB.BLL.Charts().GetQuotaAnalyseChart(query);
         if (result == null)
         {
             pAction.Success = false;
             pAction.ExceptionMsg = "暂无数据信息";
             return new ResultQuota() { ActionInfo = pAction };
         }
         pAction.Success = true;
         result.ActionInfo = pAction;
         return result;
     }
     catch (Exception e)
     {
         pAction.Success = false;
         pAction.ExceptionMsg = e.Message;
         return new ResultQuota() { ActionInfo = pAction };
     }
 }