55 lines
1.9 KiB
C#
55 lines
1.9 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 GetRunningStatusController : 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_running_status();
|
|
try
|
|
{
|
|
var data = new List<running_statusData>();
|
|
var time = DateTime.Now.ToString("yyyyMM");
|
|
var list = bll_info.GetModelList("");
|
|
var date = DateTime.Now.ToString("yyyy-MM-dd HH:00:00");
|
|
foreach ( var item in list )
|
|
{
|
|
var model=new running_statusData();
|
|
model.DeviceName = item.DeviceName;
|
|
model.DeviceState = "正常";
|
|
var alist = bll.GetModelListDate("", time).Where(x=>x.DeviceId==item.DeviceId&&x.EntireTime==Convert.ToDateTime(date)).ToList();
|
|
foreach (var aitem in alist)
|
|
{
|
|
model.EH += aitem.EH;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |