示例#1
0
        public ResultEnergyAnalyse GetEnergyAnalyseLineChart_OLD(QueryAnalyse query)
        {
            try
            {

                VerifyPersonOrAreaExist(query);
                #region 返回对象定义
                ResultEnergyAnalyse result = new ResultEnergyAnalyse()
                {
                    OrderLst = new List<EnergyOrder>(),
                    series = new List<EneryAnalyseSeries>()

                };
                result.series.Add(new EneryAnalyseSeries() { data = new List<decimal>() });
                #endregion

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

                            //var itemchildCodeList = new BLL.Itemcode().GetItemcodeList(string.Format(" and ParentID={0} ", itemCodeList[0].ItemcodeID), " order by ItemcodeID");

                            //if (itemchildCodeList.Count > 0)
                            //{
                            //    itemCodeList = itemchildCodeList;
                            //}
                        }

                    }
                }
                else
                {
                    var deviceList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(string.Format(" and deviceid={0}", query.ObjectId), " order by deviceid");
                    itemCodeList = new BLL.Itemcode().GetItemcodeList(" and ItemCodeNumber='" + deviceList[0].ItemCodeID + "'", " order by ItemcodeID");
                    if (itemCodeList.Count > 0)
                    {
                        result.Unit = itemCodeList[0].Unit;//单个分类分项单位
                        result.series[0].name = itemCodeList[0].ItemCodeName;
                    }
                    if (query.ItemCode == "00000")
                    {//总能耗

                        result.Unit = "T";//标准煤单位
                        result.series[0].name = "总能耗";
                    }

                }

                switch (query.QueryType)
                {
                    case EnergyAnalyseQueryType.Convert2Co2:
                    case EnergyAnalyseQueryType.Convert2Coal:
                        result.Unit = "T";//标准煤单位
                        break;
                    case EnergyAnalyseQueryType.Convert2Money:
                        result.Unit = "元";//标准煤单位
                        break;
                }

                DateTime tempStartTime = query.StartTime;
                DateTime tempEndTime = query.EndTime;
                switch (query.QueryType)
                {
                    case EnergyAnalyseQueryType.YearCompare://同比值
                        tempStartTime = tempStartTime.AddYears(-1);
                        tempEndTime = tempEndTime.AddYears(-1);
                        break;
                    case EnergyAnalyseQueryType.MonthCompare://环比值
                        tempStartTime = tempStartTime.AddMonths(-1);
                        tempEndTime = tempEndTime.AddMonths(-1);

                        break;
                }
                Dictionary<string, decimal> tempConvert = new Dictionary<string, decimal>();
                Dictionary<string, decimal> tempConvertHour = new Dictionary<string, decimal>();
                var model = new BaseQueryModel();
                model.IsDevice = query.IsDevice;
                model.ObjectList = new List<int>();

                model.ObjectList = new List<int>() { query.ObjectId };

                //if (model.IsDevice == 0)
                //{//区域
                //    model.ObjectList = new List<int>() { query.ObjectId };
                //}
                //else
                //{
                //    var device = new BLL.BaseLayerObject().GetDeviceObjectList(string.Format(" and deviceid={0}", query.ObjectId), " order by deviceid");
                //    if (device.Count > 0)
                //    {
                //        model.ObjectList = (from p in device select p.DeviceID).ToList<int>();
                //    }
                //}
                //model.Unit = GetUnit(query.StartTime, query.EndTime);
                model.Unit = BaseTool.GetChartUnit(query.particle);
                if (model.Unit == ChartUnit.unit_month)
                {
                    model.Starttime = Convert.ToDateTime(tempStartTime.ToString("yyyy-MM-1"));
                    model.Endtime = Convert.ToDateTime(tempEndTime.ToString("yyyy-MM-1"));
                }
                else
                {
                    model.Starttime = tempStartTime;
                    model.Endtime = tempEndTime;
                }
                int templastmonthdays = 0;
                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:00:00"), 0);
                        }
                        break;
                    case ChartUnit.unit_day:
                        if ((DateTime.Now- model.Endtime).Days>0)
                        {
                            for (DateTime i = model.Starttime; i <= model.Endtime; i = i.AddDays(1))
                            {
                                tempConvert.Add(i.ToString(("yyyy-MM-dd")), 0);
                            }
                        }
                        else
                        {
                            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 = model.Endtime; i <= DateTime.Now; i = i.AddHours(1))
                            {
                                tempConvertHour.Add(i.ToString("yyyy-MM-dd HH:00:00"), 0);
                            }

                        }

                        templastmonthdays = (model.Endtime - model.Starttime).Days;
                        break;
                }
                string objName = "";
                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)
                    {
                        if (model.IsDevice == 0)
                        {
                            objName = r.Value.baseLayerObject.LayerObjectName;//取区域名称
                        }
                        else
                        {
                            objName = r.Value.device.DeviceName;
                        }
                        foreach (var rr in r.Value.Datas)
                        {
                            if (query.ItemCode == "00000")
                            {
                                switch (query.QueryType)
                                {
                                    case EnergyAnalyseQueryType.Default://默认
                                    case EnergyAnalyseQueryType.YearCompare://默认
                                    case EnergyAnalyseQueryType.MonthCompare://默认
                                        tempConvert[rr.DatePick] += rr.CoalDataValue;
                                        break;
                                    case EnergyAnalyseQueryType.UnitArea://单位面积
                                        tempConvert[rr.DatePick] += rr.CoalDataValue / decimal.Parse(r.Value.baseLayerObject.AreaNum.ToString());

                                        break;
                                    case EnergyAnalyseQueryType.UnitPerson://人均
                                        tempConvert[rr.DatePick] += rr.CoalDataValue / decimal.Parse(r.Value.baseLayerObject.PersonNum.ToString());
                                        break;
                                    case EnergyAnalyseQueryType.Convert2Coal://
                                        tempConvert[rr.DatePick] += rr.CoalDataValue;
                                        break;
                                    case EnergyAnalyseQueryType.Convert2Co2://
                                        tempConvert[rr.DatePick] += rr.Co2DataValue;
                                        break;
                                    case EnergyAnalyseQueryType.Convert2Money://
                                        tempConvert[rr.DatePick] += rr.MoneyDataValue;
                                        break;
                                }
                            }
                            else
                            {
                                switch (query.QueryType)
                                {
                                    case EnergyAnalyseQueryType.Default://默认
                                    case EnergyAnalyseQueryType.YearCompare://默认
                                    case EnergyAnalyseQueryType.MonthCompare://默认
                                        tempConvert[rr.DatePick] += rr.DataValue;
                                        break;
                                    case EnergyAnalyseQueryType.UnitArea://单位面积
                                        tempConvert[rr.DatePick] += rr.DataValue / decimal.Parse(r.Value.baseLayerObject.AreaNum.ToString());

                                        break;
                                    case EnergyAnalyseQueryType.UnitPerson://人均
                                        tempConvert[rr.DatePick] += rr.DataValue / decimal.Parse(r.Value.baseLayerObject.PersonNum.ToString());
                                        break;
                                    case EnergyAnalyseQueryType.Convert2Coal://
                                        tempConvert[rr.DatePick] += rr.CoalDataValue;
                                        break;
                                    case EnergyAnalyseQueryType.Convert2Co2://
                                        tempConvert[rr.DatePick] += rr.Co2DataValue;
                                        break;
                                    case EnergyAnalyseQueryType.Convert2Money://
                                        tempConvert[rr.DatePick] += rr.MoneyDataValue;
                                        break;
                                }

                            }
                        }
                    }
                }
                int order = 1;
                foreach (var item in tempConvert)
                {

                    var time = item.Key;
                    if (model.Unit == ChartUnit.unit_month)
                    {
                        time = Convert.ToDateTime(time).ToString("yyyy-MM");
                    }

                    decimal value = decimal.Round(item.Value, 2);
                    result.series[0].data.Add(value);
                    result.OrderLst.Add(new EnergyOrder()
                    {
                        Order = order,
                        Tm = time,
                        Obj = objName,
                        Val = value,
                        EneType = result.series[0].name
                        // EneType =itemCodeList.Count > 1 ? "总能耗" : itemCodeList[0].ItemCodeName

                    });
                    order++;
                }
                if (query.QueryType == EnergyAnalyseQueryType.MonthCompare)
                {
                    int tempcurrentdays = (query.EndTime - query.StartTime).Days;
                    //int index = (28 - query.StartTime.Day) < 0 ? 0 : (28 - query.StartTime.Day);

                    if (model.Unit == ChartUnit.unit_day)
                    {
                        if (tempcurrentdays > templastmonthdays)
                        {//当前时间范围大于上月环比范围
                            int index = System.DateTime.DaysInMonth(query.StartTime.AddMonths(-1).Year, query.StartTime.AddMonths(-1).Month) - query.StartTime.Day;
                            if (index < 0)
                            {
                                index = 0;
                            }
                            for (int i = templastmonthdays; i < tempcurrentdays; i++)
                            {
                                result.series[0].data.Insert(index, result.series[0].data[index]);
                            }

                        }
                        else
                        {
                            if (tempcurrentdays < templastmonthdays)
                            {
                                int index = System.DateTime.DaysInMonth(query.StartTime.AddMonths(-1).Year, query.StartTime.AddMonths(-1).Month) - query.StartTime.Day;
                                for (int i = tempcurrentdays; i < templastmonthdays; i++)
                                {
                                    result.series[0].data.RemoveAt(index);
                                    index--;
                                }
                            }
                        }

                        //for (int i = 0; i < ((query.EndTime - query.StartTime).Days - tempdaycount); i++)
                        //{
                        //    result.series[0].data.Insert(index, result.series[0].data[index]);

                        //}

                    }
                }

                return result;
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }
示例#2
0
        public ResultEnergyAnalyse GetEnergyAnalyseLineChart(QueryAnalyse query)
        {
            try
            {
                VerifyPersonOrAreaExist(query);
                #region 返回对象定义
                ResultEnergyAnalyse result = new ResultEnergyAnalyse()
                {
                    OrderLst = new List<EnergyOrder>(),
                    series = new List<EneryAnalyseSeries>()

                };
                result.series.Add(new EneryAnalyseSeries() { data = new List<decimal>() });
                #endregion

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

                    }
                }
                else
                {
                    var deviceList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(string.Format(" and deviceid={0}", query.ObjectId), " order by deviceid");
                    itemCodeList = new BLL.Itemcode().GetItemcodeList(" and ItemCodeNumber='" + deviceList[0].ItemCodeID + "'", " order by ItemcodeID");
                    if (itemCodeList.Count > 0)
                    {
                        result.Unit = itemCodeList[0].Unit;//单个分类分项单位
                        result.series[0].name = itemCodeList[0].ItemCodeName;
                    }
                    if (query.ItemCode == "00000")
                    {//总能耗

                        result.Unit = "T";//标准煤单位
                        result.series[0].name = "总能耗";
                    }

                }

                switch (query.QueryType)
                {
                    case EnergyAnalyseQueryType.Convert2Co2:
                    case EnergyAnalyseQueryType.Convert2Coal:
                        result.Unit = "T";//标准煤单位
                        break;
                    case EnergyAnalyseQueryType.Convert2Money:
                        result.Unit = "元";//标准煤单位
                        break;
                }

                DateTime tempStartTime = query.StartTime;
                DateTime tempEndTime = query.EndTime;
                if ((DateTime.Now - tempEndTime).Days == 0)
                {
                    tempEndTime = DateTime.Now;
                }
                switch (query.QueryType)
                {
                    case EnergyAnalyseQueryType.YearCompare://同比值
                        tempStartTime = tempStartTime.AddYears(-1);
                        tempEndTime = tempEndTime.AddYears(-1);
                        break;
                    case EnergyAnalyseQueryType.MonthCompare://环比值

                        tempStartTime = tempStartTime.AddMonths(-1);
                        tempEndTime = tempEndTime.AddMonths(-1);

                        break;
                }
                Dictionary<string, decimal> tempConvert = new Dictionary<string, decimal>();
                Dictionary<string, decimal> tempConvertHour = new Dictionary<string, decimal>();
                var model = new BaseQueryModel();
                model.IsDevice = query.IsDevice;
                model.ObjectList = new List<int>();

                model.ObjectList = new List<int>() { query.ObjectId };

                model.Unit = BaseTool.GetChartUnit(query.particle);
                if (model.Unit == ChartUnit.unit_month)
                {
                    model.Starttime = Convert.ToDateTime(tempStartTime.ToString("yyyy-MM-1"));
                    model.Endtime = Convert.ToDateTime(tempEndTime.ToString("yyyy-MM-1"));
                }
                else
                {
                    model.Starttime = tempStartTime;
                    model.Endtime = tempEndTime;
                }
                int templastmonthdays = 0;
                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:00:00"), 0);
                        }
                        break;
                    case ChartUnit.unit_day:
                        templastmonthdays = (model.Endtime - model.Starttime).Days;
                        if (model.Endtime.Hour== 0)
                        {
                            for (DateTime i = model.Starttime; i <= model.Endtime; i = i.AddDays(1))
                            {
                                tempConvert.Add(i.ToString(("yyyy-MM-dd")), 0);
                            }
                        }
                        else
                        {

                            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))
                            {
                                tempConvertHour.Add(i.ToString("yyyy-MM-dd HH:00:00"), 0);
                            }
                            model.Endtime = DateTime.Parse(tempEndTime.AddDays(-1).ToString("yyyy-MM-dd"));
                        }

                        break;
                }
                string objName = "";

                decimal temphourValue = 0;
                foreach (var item in itemCodeList)
                {
                    model.ItemCode = item.ItemCodeNumber;
                    GenerateEnergyDicValue(model, query, tempConvert,ref objName);
                    if (tempConvertHour.Count>0)
                    {
                        model.Unit = ChartUnit.unit_hour;
                        model.Starttime = DateTime.Parse(tempEndTime.ToString("yyyy-MM-dd 00:00:00"));
                        model.Endtime = DateTime.Parse(tempEndTime.ToString("yyyy-MM-dd HH:00:00"));
                        GenerateEnergyDicValue(model, query, tempConvertHour, ref objName);
                        temphourValue = tempConvertHour.Sum(i => i.Value);

                        model.Starttime = tempStartTime;
                        model.Endtime = DateTime.Parse(tempEndTime.AddDays(-1).ToString("yyyy-MM-dd"));
                        model.Unit = ChartUnit.unit_day;
                    }

                }
                if (tempConvertHour.Count > 0)
                {
                    tempConvert.Add(DateTime.Now.ToString("yyyy-MM-dd"), temphourValue);
                }
                int order = 1;
                foreach (var item in tempConvert)
                {

                    var time = item.Key;
                    if (model.Unit == ChartUnit.unit_month)
                    {
                        time = Convert.ToDateTime(time).ToString("yyyy-MM");
                    }

                    decimal value = decimal.Round(item.Value, 2);
                    result.series[0].data.Add(value);
                    result.OrderLst.Add(new EnergyOrder()
                    {
                        Order = order,
                        Tm = time,
                        Obj = objName,
                        Val = value,
                        EneType = result.series[0].name
                        // EneType =itemCodeList.Count > 1 ? "总能耗" : itemCodeList[0].ItemCodeName

                    });
                    order++;
                }
                if (query.QueryType == EnergyAnalyseQueryType.MonthCompare)
                {
                    int tempcurrentdays = (query.EndTime - query.StartTime).Days;
                    //int index = (28 - query.StartTime.Day) < 0 ? 0 : (28 - query.StartTime.Day);

                    if (model.Unit == ChartUnit.unit_day)
                    {
                        if (tempcurrentdays > templastmonthdays)
                        {//当前时间范围大于上月环比范围
                            int index = System.DateTime.DaysInMonth(query.StartTime.AddMonths(-1).Year, query.StartTime.AddMonths(-1).Month) - query.StartTime.Day;
                            if (index < 0)
                            {
                                index = 0;
                            }
                            for (int i = templastmonthdays; i < tempcurrentdays; i++)
                            {
                                result.series[0].data.Insert(index, result.series[0].data[index]);
                            }

                        }
                        else
                        {
                            if (tempcurrentdays < templastmonthdays)
                            {
                                int index = System.DateTime.DaysInMonth(query.StartTime.AddMonths(-1).Year, query.StartTime.AddMonths(-1).Month) - query.StartTime.Day;
                                for (int i = tempcurrentdays; i < templastmonthdays; i++)
                                {
                                    result.series[0].data.RemoveAt(index);
                                    index--;
                                }
                            }
                        }

                        //for (int i = 0; i < ((query.EndTime - query.StartTime).Days - tempdaycount); i++)
                        //{
                        //    result.series[0].data.Insert(index, result.series[0].data[index]);

                        //}

                    }
                }

                return result;
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }