100 lines
3.9 KiB
C#
100 lines
3.9 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;
|
|
using System.Web.Http;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 实时数据
|
|
/// </summary>
|
|
public class GetRealDataController : 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__data();
|
|
try
|
|
{
|
|
var blist = bll.GetModelList("");
|
|
var alist = new List<real__dataData>();
|
|
var now=DateTime.Now;
|
|
string time;
|
|
if (now.Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
var sdate = now.ToString("yyyy-MM-dd 00:00:00");
|
|
var edate = now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
|
|
if (!string.IsNullOrEmpty(req.LoopName) && !string.IsNullOrEmpty(req.DistributionName))
|
|
{
|
|
var list = bll.GetModelList(" EquipmentName ='"+req.LoopName+ "' and EquipmentDescribe='"+req.DistributionName+"'");
|
|
var slist=string.Join(",", list.Select(x=>x.P));
|
|
var list1 = bll_gw.GetModelListsDate(slist, time).Where(x => x.XTimeStamp >= Convert.ToDateTime(sdate) && x.XTimeStamp < Convert.ToDateTime(edate)).DistinctBy(x => new { x.XTagName, x.XTimeStamp }).ToList();
|
|
decimal? num = 0;
|
|
var model = new real__dataData();
|
|
foreach (var item in list1)
|
|
{
|
|
num += Convert.ToDecimal(item.XValue);
|
|
}
|
|
model.CurrentPower = num;
|
|
model.LoadRate = 0;
|
|
var slist1 = string.Join(",", blist.Select(x => x.P));
|
|
var alist1 = bll_gw.GetModelListsDate(slist1, time).Where(x => x.XTimeStamp >= Convert.ToDateTime(sdate) && x.XTimeStamp < Convert.ToDateTime(edate)).DistinctBy(x => new { x.XTagName, x.XTimeStamp }).ToList();
|
|
decimal? num1 = 0;
|
|
foreach (var item in alist1)
|
|
{
|
|
num1 += Convert.ToDecimal(item.XValue);
|
|
}
|
|
if (num == 0)
|
|
{
|
|
model.ConversionRate = 0;
|
|
}
|
|
else
|
|
{
|
|
model.ConversionRate =Convert.ToDecimal( Math.Round(Convert.ToDouble(num/ num1 * 100),3));
|
|
}
|
|
if (model.CurrentPower > 0)
|
|
{
|
|
model.DeviceWroking = "正常";
|
|
}
|
|
else
|
|
{
|
|
model.DeviceWroking = "异常";
|
|
}
|
|
alist.Add(model);
|
|
res.code = 200;
|
|
res.msg = "成功";
|
|
res.data = alist;
|
|
}
|
|
else
|
|
{
|
|
res.code = 201;
|
|
res.msg = "参数不能为空";
|
|
}
|
|
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |