109 lines
4.6 KiB
C#
109 lines
4.6 KiB
C#
using DataServer.api;
|
|
using Microsoft.Ajax.Utilities;
|
|
using Microsoft.SqlServer.Server;
|
|
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 JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 水泥磨系统监控
|
|
/// </summary>
|
|
public class GetCementMonitoringController : ApiController
|
|
{
|
|
DataServer.BLL.electrical_installation bll = new DataServer.BLL.electrical_installation();
|
|
DataServer.BLL.gw_data bll_gw=new DataServer.BLL.gw_data();
|
|
// GET api/<controller>
|
|
public HttpResponseMessage Get()
|
|
{
|
|
var res = new get_one_monitoring();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("").Where(x => x.EquipmentName.Contains("水泥磨")).ToList();
|
|
var now = DateTime.Now;
|
|
var sdate = now.ToString("yyyy-MM-dd 00:00:00");
|
|
var edate = now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
|
|
var date = now.ToString("yyyy-MM-dd 00:00:00");
|
|
var alist = new List<one_monitoringData>();
|
|
var count = 0;
|
|
var model = new one_monitoringData();
|
|
model.Amount = list.DistinctBy(x => x.EquipmentName).Count();
|
|
string time;
|
|
if (now.Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
var blist = new List<one_monitoring>();
|
|
foreach (var aitem in list.DistinctBy(x => x.EquipmentName))
|
|
{
|
|
count++;
|
|
var amodel = new one_monitoring();
|
|
amodel.SerialNumber = count;
|
|
amodel.ProductionName = aitem.EquipmentName;
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
decimal? num3 = 0;
|
|
var alist1 = list.Where(x => x.EquipmentName == aitem.EquipmentName).ToList();
|
|
var EHs = string.Join(",", alist1.Select(x => x.EH));
|
|
var Ps = string.Join(",", alist1.Select(x => x.P));
|
|
var list1 = bll_gw.GetModelListsDate(Ps, time).Where(x => x.XTimeStamp >= Convert.ToDateTime(sdate) && x.XTimeStamp < Convert.ToDateTime(edate)).DistinctBy(x => new { x.XTagName, x.XTimeStamp }).ToList();
|
|
var list2 = bll_gw.GetModelListsDate(EHs, time).GroupBy(x => x.XTagName).Select(g => g.OrderByDescending(x => x.XTimeStamp).FirstOrDefault()).DistinctBy(x => new { x.XTagName, x.XTimeStamp }).ToList();
|
|
var list3 = bll_gw.GetModelListsDate(EHs, time).Where(x => x.XTimeStamp == Convert.ToDateTime(date)).GroupBy(x => x.XTagName).Select(g => g.OrderByDescending(x => x.XTimeStamp).FirstOrDefault()).ToList();
|
|
foreach (var bitem in list1)
|
|
{
|
|
num1 += Convert.ToDecimal(bitem.XValue);
|
|
}
|
|
foreach (var item in list2)
|
|
{
|
|
num2 += Convert.ToDecimal(item.XValue);
|
|
}
|
|
foreach (var item in list3)
|
|
{
|
|
num3 += Convert.ToDecimal(item.XValue);
|
|
}
|
|
amodel.P = num1;
|
|
amodel.EH = num2 - num3;
|
|
if (Convert.ToDecimal(amodel.P) > 0 && Convert.ToDecimal(amodel.EH) > 0)
|
|
{
|
|
amodel.EquipmentStatus = "正常";
|
|
}
|
|
else
|
|
{
|
|
amodel.EquipmentStatus = "异常";
|
|
}
|
|
if (amodel.P == null)
|
|
{
|
|
amodel.P = 0;
|
|
}
|
|
if (amodel.EH == null)
|
|
{
|
|
amodel.EH = 0;
|
|
}
|
|
blist.Add(amodel);
|
|
}
|
|
model.data = blist;
|
|
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;
|
|
}
|
|
}
|
|
} |