138 lines
6.5 KiB
C#
138 lines
6.5 KiB
C#
using DataServer.api;
|
|
using Microsoft.Ajax.Utilities;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.CodeDom.Compiler;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
using System.Web.Mvc;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
public class GetEquipmentProfileController : ApiController
|
|
{
|
|
/// <summary>
|
|
/// 能效管理1-设备概况
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
DataServer.BLL.electrical_installation bll = new DataServer.BLL.electrical_installation();
|
|
DataServer.BLL.gw_data bll_gw = new DataServer.BLL.gw_data();
|
|
public HttpResponseMessage Get(string date="")
|
|
{
|
|
var res = new get_equipment_profile();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
var data = new List<equipment_profileData>();
|
|
var now = DateTime.Now;
|
|
string time;
|
|
if (now.Month < 10)
|
|
{
|
|
time = now.ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
time = now.ToString("yyyy_MM");
|
|
}
|
|
if (date == "日")
|
|
{
|
|
var sdate = now.ToString("yyyy-MM-dd 00:00:00");
|
|
foreach (var item in list.DistinctBy(x=>x.EquipmentName))
|
|
{
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
var alist = list.Where(x=>x.EquipmentName==item.EquipmentName).ToList();
|
|
var slist = string.Join(",", alist.Select(x => x.EH));
|
|
var list1 = bll_gw.GetModelListsDate(slist, time).GroupBy(x => x.XTagName).Select(g => g.OrderByDescending(x => x.XTimeStamp).FirstOrDefault()).ToList();
|
|
var list2 = bll_gw.GetModelListsDate(slist, time).Where(x => x.XTimeStamp == Convert.ToDateTime(sdate)).GroupBy(x => x.XTagName).Select(g => g.OrderByDescending(x => x.XTimeStamp).FirstOrDefault()).ToList();
|
|
foreach (var aitem in list1)
|
|
{
|
|
num1 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
foreach (var aitem in list2)
|
|
{
|
|
num2 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
var model = new equipment_profileData();
|
|
model.DeviceName = item.EquipmentName;
|
|
model.ServiceRating = num1 - num2;
|
|
data.Add(model);
|
|
}
|
|
}
|
|
else if (date == "月")
|
|
{
|
|
var sdate = now.ToString("yyyy-MM-01 00:00:00");
|
|
foreach (var item in list.DistinctBy(x => x.EquipmentName))
|
|
{
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
var alist = list.Where(x => x.EquipmentName == item.EquipmentName).ToList();
|
|
var slist = string.Join(",", alist.Select(x => x.EH));
|
|
var list1 = bll_gw.GetModelListsDate(slist, time).GroupBy(x => x.XTagName).Select(g => g.OrderByDescending(x => x.XTimeStamp).FirstOrDefault()).ToList();
|
|
var list2 = bll_gw.GetModelListsDate(slist, time).Where(x => x.XTimeStamp == Convert.ToDateTime(sdate)).GroupBy(x => x.XTagName).Select(g => g.OrderByDescending(x => x.XTimeStamp).FirstOrDefault()).ToList();
|
|
foreach (var aitem in list1)
|
|
{
|
|
num1 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
foreach (var aitem in list2)
|
|
{
|
|
num2 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
var model = new equipment_profileData();
|
|
model.DeviceName = item.EquipmentName;
|
|
model.ServiceRating = num1 - num2;
|
|
data.Add(model);
|
|
}
|
|
}
|
|
else if (date == "年")
|
|
{
|
|
var sdate = now.ToString("yyyy-01-01 00:00:00");
|
|
string stime;
|
|
if (Convert.ToDateTime(sdate).Month < 10)
|
|
{
|
|
stime = Convert.ToDateTime(sdate).ToString("yyyy_M");
|
|
}
|
|
else
|
|
{
|
|
stime = Convert.ToDateTime(sdate).ToString("yyyy_MM");
|
|
}
|
|
foreach (var item in list.DistinctBy(x => x.EquipmentName))
|
|
{
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
var alist = list.Where(x => x.EquipmentName == item.EquipmentName).ToList();
|
|
var slist = string.Join(",", alist.Select(x => x.EH));
|
|
var list1 = bll_gw.GetModelListsDate(slist, time).GroupBy(x => x.XTagName).Select(g => g.OrderByDescending(x => x.XTimeStamp).FirstOrDefault()).ToList();
|
|
var list2 = bll_gw.GetModelListsDate(slist, stime).Where(x => x.XTimeStamp == Convert.ToDateTime(sdate)).GroupBy(x => x.XTagName).Select(g => g.OrderByDescending(x => x.XTimeStamp).FirstOrDefault()).ToList();
|
|
foreach (var aitem in list1)
|
|
{
|
|
num1 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
foreach (var aitem in list2)
|
|
{
|
|
num2 += Convert.ToDecimal(aitem.XValue);
|
|
}
|
|
var model = new equipment_profileData();
|
|
model.DeviceName = item.EquipmentName;
|
|
model.ServiceRating = num1 - num2;
|
|
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;
|
|
}
|
|
}
|
|
} |