88 lines
3.1 KiB
C#
88 lines
3.1 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.Reflection;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 实时负荷功率
|
|
/// </summary>
|
|
public class GetRealLoadController : ApiController
|
|
{
|
|
DataServer.BLL.loop_distribution bll = new DataServer.BLL.loop_distribution();
|
|
// GET api/<controller>
|
|
public HttpResponseMessage Get([FromBody] select_loop_distribution req)
|
|
{
|
|
var res = new get_real_load();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
var alist = new List<real_loadData>();
|
|
|
|
foreach (var item in list)
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(req.LoopName))
|
|
{
|
|
if (!string.IsNullOrEmpty(req.DistributionName))
|
|
{
|
|
if (item.LoopName == req.LoopName)
|
|
{
|
|
if (item.DistributionName == req.DistributionName)
|
|
{
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
var model = new real_loadData();
|
|
model.time = DateTime.Now.AddHours(-i).ToString("HH:00");
|
|
model.TodayLoad = item.CurrentPower;
|
|
model.YesterdayLoad= item.CurrentPower;
|
|
alist.Add(model);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
var model = new real_loadData();
|
|
model.time = DateTime.Now.AddHours(-i).ToString("HH:00");
|
|
var blist = bll.GetModelList("");
|
|
foreach (var aitem in blist)
|
|
{
|
|
model.TodayLoad = aitem.CurrentPower;
|
|
num1 = model.TodayLoad + num1;
|
|
model.TodayLoad = num1;
|
|
model.YesterdayLoad = aitem.CurrentPower;
|
|
num2 = model.YesterdayLoad + num2;
|
|
model.YesterdayLoad = num2;
|
|
}
|
|
|
|
alist.Add(model);
|
|
}
|
|
|
|
res.code = 200;
|
|
res.msg = "成功";
|
|
res.data = alist;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |