81 lines
3.2 KiB
C#
81 lines
3.2 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.Reflection;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 实时负荷功率
|
|
/// </summary>
|
|
public class GetRealLoadController : ApiController
|
|
{
|
|
DataServer.BLL.electric_equipment bll = new DataServer.BLL.electric_equipment();
|
|
DataServer.BLL.gw_data bll_gw=new DataServer.BLL.gw_data();
|
|
// GET api/<controller>
|
|
public HttpResponseMessage Post([FromBody] select_loop_distribution req)
|
|
{
|
|
var res = new get_real_load();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("").Where(x=>x.EquipmentName==req.LoopName&&x.EquipmentDescribe==req.DistributionName).ToList();
|
|
var alist = new List<real_loadData>();
|
|
var now=DateTime.Now;
|
|
string time;
|
|
if (now.Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
var jdate = now.AddHours(-i).ToString("yyyy-MM-dd HH:00:00");
|
|
var zdate = now.AddHours(-i + 1).ToString("yyyy-MM-dd HH:00:00");
|
|
var qdate = now.AddHours(-i + 2).ToString("yyyy-MM-dd HH:00:00");
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
//decimal? num3 = 0;
|
|
var model = new real_loadData();
|
|
model.time = DateTime.Now.AddHours(-i).ToString("HH:00");
|
|
var slist=string.Join(",", list.Select(x=>x.P));
|
|
var blist = bll_gw.GetModelListsDate(slist, time).DistinctBy(x=>new { x.XTagName,x.XTimeStamp}).ToList();
|
|
var blist1 = blist.Where(x=>x.XTimeStamp>=Convert.ToDateTime(jdate)&&x.XTimeStamp<Convert.ToDateTime(zdate)).ToList();
|
|
var blist2=blist.Where(x=>x.XTimeStamp>=Convert.ToDateTime(zdate)&&x.XTimeStamp<Convert.ToDateTime(qdate)).ToList();
|
|
|
|
foreach (var aitem in blist1)
|
|
{
|
|
num1 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
foreach (var item in blist2)
|
|
{
|
|
num2 += Convert.ToDecimal(item.XValue);
|
|
}
|
|
model.TodayLoad = num1 ;
|
|
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;
|
|
}
|
|
}
|
|
} |