75 lines
3.0 KiB
C#
75 lines
3.0 KiB
C#
using DataServer.api;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
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();
|
|
//表名
|
|
var date_base = ConfigurationManager.AppSettings["MySQLDataBase"].ToString();
|
|
try
|
|
{
|
|
var data = new List<running_statusData>();
|
|
var time = DateTime.Now.ToString("yyyyMM");
|
|
var now=DateTime.Now;
|
|
var list = bll_info.GetModelList(" FloorName='科技馆负一层地源热泵'").ToList();
|
|
string jdate;
|
|
jdate = now.AddHours(-1).ToString("yyyy-MM-dd HH:00:00");
|
|
var jtime = now.ToString("yyyyMM");
|
|
var a = bll.IsExistsTable(date_base, "electricity_data_" + jtime);
|
|
if (a == false)
|
|
{
|
|
bll.CreateTable(jtime);
|
|
}
|
|
var sdate = now.AddDays(- 1).ToString("yyyy-MM-dd 00:00:00");
|
|
var stime = now.AddDays(-1).ToString("yyyyMM");
|
|
var b = bll.IsExistsTable(date_base, "electricity_data_" + stime);
|
|
if (b == false)
|
|
{
|
|
bll.CreateTable(stime);
|
|
}
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
foreach (var aitem in list)
|
|
{
|
|
var model=new running_statusData();
|
|
model.DeviceName= aitem.DeviceName;
|
|
model.DeviceState = 1;
|
|
var jlist = bll.GetModelListDate(" DeviceId='" + aitem.DeviceId + "' and EntireTime='" + jdate + "'", jtime);
|
|
var slist = bll.GetModelListDate(" DeviceId='" + aitem.DeviceId + "' and EntireTime='" + sdate + "'", stime);
|
|
num1 = jlist.Sum(x => Convert.ToDecimal(x.EH));
|
|
num2 = slist.Sum(x => Convert.ToDecimal(x.EH));
|
|
model.EH = num1-num2;
|
|
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;
|
|
}
|
|
}
|
|
} |