78 lines
2.9 KiB
C#
78 lines
2.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.Text;
|
|
using System.Web.Http;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 能效管理2-设备运行情况
|
|
/// </summary>
|
|
public class GetEquipmentOperationController : 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_equipment_operation();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
var data = new List<equipment_operationData>();
|
|
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");
|
|
string time;
|
|
if (now.Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
foreach (var item in list.DistinctBy(x=>x.EquipmentName))
|
|
{
|
|
var model=new equipment_operationData();
|
|
model.DeviceName = item.EquipmentName;
|
|
var alist=list.Where(x=>x.EquipmentName==item.EquipmentName).ToList();
|
|
var slist=string.Join(",", alist.Select(x=>x.P));
|
|
decimal? num = 0;
|
|
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();
|
|
foreach (var aitem in list1)
|
|
{
|
|
num += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
if(num> 0)
|
|
{
|
|
model.State = 1;
|
|
}
|
|
else
|
|
{
|
|
model.State= 0;
|
|
}
|
|
model.P = num;
|
|
data.Add(model);
|
|
}
|
|
res.code = 200;
|
|
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;
|
|
}
|
|
}
|
|
} |