90 lines
3.7 KiB
C#
90 lines
3.7 KiB
C#
using DataServer.api;
|
|
using Microsoft.Ajax.Utilities;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
|
|
namespace DongYingAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 用能监测1-系统用电排名
|
|
/// </summary>
|
|
public class GetElectricalRankingController : ApiController
|
|
{
|
|
DataServer.BLL.electricity_data bll = new DataServer.BLL.electricity_data();
|
|
DataServer.BLL.device_info bll_info = new DataServer.BLL.device_info();
|
|
|
|
public HttpResponseMessage Get()
|
|
{
|
|
var res = new get_electrical_ranking();
|
|
try
|
|
{
|
|
var data = new List<electrical_rankingData>();
|
|
var time = DateTime.Now.ToString("yyyyMM");
|
|
var now = DateTime.Now;
|
|
var sdate = Convert.ToDateTime(now.ToString("yyyy-MM-dd 00:00:00"));
|
|
var edate = Convert.ToDateTime(now.AddDays(+1).ToString("yyyy-MM-dd 00:00:00"));
|
|
|
|
var alist = bll_info.GetModelList("").Where(x => x.DeviceName.Contains("空调")).ToList();
|
|
var model1 = new electrical_rankingData();
|
|
decimal? num = 0;
|
|
foreach (var item in alist)
|
|
{
|
|
var list = bll.GetModelListDate("", time).Where(x =>x.DeviceId==item.DeviceId&& x.EntireTime >= sdate && x.EntireTime < edate).ToList();
|
|
foreach (var aitem in list)
|
|
{
|
|
num += aitem.P;
|
|
}
|
|
}
|
|
model1.ElectricaValue = num;
|
|
model1.ElectricaName = "空调系统";
|
|
data.Add(model1);
|
|
var blist = bll_info.GetModelList("").Where(x => x.DeviceName.Contains("照明")).ToList();
|
|
var model2 = new electrical_rankingData();
|
|
decimal? num1 = 0;
|
|
foreach (var item in blist)
|
|
{
|
|
var list = bll.GetModelListDate("", time).Where(x => x.DeviceId == item.DeviceId && x.EntireTime >= sdate && x.EntireTime < edate).ToList();
|
|
foreach (var aitem in list)
|
|
{
|
|
num1 += aitem.P;
|
|
}
|
|
}
|
|
model2.ElectricaValue = num1;
|
|
model2.ElectricaName = "照明系统";
|
|
data.Add(model2);
|
|
var clist = bll_info.GetModelList("").Where(x => x.DeviceName.Contains("电梯")||x.DeviceName.Contains("货梯")).ToList();
|
|
var model3 = new electrical_rankingData();
|
|
decimal? num2 = 0;
|
|
foreach (var item in clist)
|
|
{
|
|
var list = bll.GetModelListDate("", time).Where(x => x.DeviceId == item.DeviceId && x.EntireTime >= sdate && x.EntireTime < edate).ToList();
|
|
foreach (var aitem in list)
|
|
{
|
|
num2 += aitem.P;
|
|
}
|
|
}
|
|
model3.ElectricaValue = num2;
|
|
model3.ElectricaName = "电梯系统";
|
|
data.Add(model3);
|
|
var elist=data.OrderByDescending(x=>x.ElectricaValue).ToList();
|
|
res.code = 200;
|
|
res.msg = "成功";
|
|
res.data = elist;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
res.code = 500;
|
|
res.msg = "失败," + ex.Message;
|
|
}
|
|
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(res), Encoding.GetEncoding("UTF-8"), "application/json") };
|
|
return result;
|
|
}
|
|
}
|
|
} |