89 lines
3.6 KiB
C#
89 lines
3.6 KiB
C#
using DataServer.api;
|
|
using DataServer.api.threedimensional;
|
|
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;
|
|
using System.Web.Http.Validation;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api.ThreeDimensional
|
|
{
|
|
/// <summary>
|
|
/// 用电设备
|
|
/// </summary>
|
|
public class GetFacilityInformationController : 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(string name = "")
|
|
{
|
|
var res = new get_facility_information();
|
|
try
|
|
{
|
|
var list = bll.GetModelList(" EquipmentName like '" + name + "'");
|
|
var data = new List<facility_informationData>();
|
|
var now = DateTime.Now;
|
|
string time;
|
|
var date = now.ToString("yyyy-MM-dd 00:00:00");
|
|
var sdate = now.ToString("yyyy-MM-dd 00:00:00");
|
|
var edate = now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
|
|
if (now.Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
var EHs = string.Join(",", list.Select(x => x.EH));
|
|
var Ps = string.Join(",", list.Select(x => x.P));
|
|
var list1 = bll_gw.GetModelListsDate(EHs, time).GroupBy(x => x.XTagName).Select(g => g.OrderByDescending(x => x.XTimeStamp).FirstOrDefault()).ToList();
|
|
var list2 = 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();
|
|
var plist = 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();
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
decimal? num = 0;
|
|
foreach (var item in list1)
|
|
{
|
|
num1 += Convert.ToDecimal(item.XValue);
|
|
}
|
|
foreach (var item in list2)
|
|
{
|
|
num2 += Convert.ToDecimal(item.XValue);
|
|
}
|
|
foreach (var item in plist)
|
|
{
|
|
num += Convert.ToDecimal(item.XValue);
|
|
}
|
|
var model = new facility_informationData();
|
|
model.EH = num1 - num2;
|
|
model.P = num;
|
|
if (model.EH > 0 || model.P > 0)
|
|
{
|
|
model.State = "正常";
|
|
}
|
|
else
|
|
{
|
|
model.State = "错误";
|
|
}
|
|
data.Add(model);
|
|
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;
|
|
}
|
|
}
|
|
} |