72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
using DataServer.api;
|
|
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>
|
|
/// 空调-日用电量
|
|
/// </summary>
|
|
public class GetDailyElectricityController : 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_daily_electricity();
|
|
try
|
|
{
|
|
var data = new List<daily_electricityData>();
|
|
var time = DateTime.Now.ToString("yyyyMM");
|
|
//今天
|
|
var sdate = DateTime.Now.ToString("yyyy-MM-dd HH:00:00");
|
|
//昨天
|
|
var edate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 00:00:00");
|
|
//前天
|
|
var qdate=DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd 00:00:00");
|
|
//今天列表
|
|
var list1=bll.GetModelListDate("",time).Where(x=>x.EntireTime==Convert.ToDateTime(sdate)).ToList();
|
|
decimal? num1 = 0;
|
|
foreach (var item in list1)
|
|
{
|
|
num1 += item.EH;
|
|
}
|
|
//明天列表
|
|
var list2 = bll.GetModelListDate("", time).Where(x => x.EntireTime == Convert.ToDateTime(sdate)).ToList();
|
|
decimal? num2 = 0;
|
|
foreach (var item in list1)
|
|
{
|
|
num2 += item.EH;
|
|
}
|
|
//昨天列表
|
|
var list3 = bll.GetModelListDate("", time).Where(x => x.EntireTime == Convert.ToDateTime(sdate)).ToList();
|
|
decimal? num3 = 0;
|
|
foreach (var item in list1)
|
|
{
|
|
num3 += item.EH;
|
|
}
|
|
var model = new daily_electricityData();
|
|
model.CurrentDate = num1 - num2;
|
|
model.YesterDay=num2- num3;
|
|
data.Add(model);
|
|
res.code = 200;
|
|
res.msg = "成功";
|
|
res.data = data;
|
|
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |