87 lines
3.2 KiB
C#
87 lines
3.2 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.Http;
|
|
|
|
namespace JinanCementFactoryAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 全厂设备用电量排名
|
|
/// </summary>
|
|
public class GetFacilityRankingController : 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_facility_ranking();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
var alist = new List<facility_rankingData>();
|
|
var now = DateTime.Now;
|
|
var date = now.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))
|
|
{
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
var slist = list.Where(x => x.EquipmentName == item.EquipmentName).ToList();
|
|
var model = new facility_rankingData();
|
|
model.DeviceName = item.EquipmentName;
|
|
foreach (var aitem in slist)
|
|
{
|
|
var list1 = bll_gw.GetModelListDate(" XTagName like '%" + aitem.EH + "'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault();
|
|
if (list1 == null)
|
|
{
|
|
num1 = num1;
|
|
}
|
|
else
|
|
{
|
|
num1 += Convert.ToDecimal(list1.XValue);
|
|
}
|
|
var list2 = bll_gw.GetModelListDate(" XTagName like '%" + aitem.EH + "' and XTimeStamp='" + date + "'", time).FirstOrDefault();
|
|
if (list2 == null)
|
|
{
|
|
num2 = num2;
|
|
}
|
|
else
|
|
{
|
|
num2 += Convert.ToDecimal(list2.XValue);
|
|
}
|
|
model.EH = num1 - num2;
|
|
|
|
}
|
|
alist.Add(model);
|
|
}
|
|
var blist = alist.OrderByDescending(x => x.EH).ToList();
|
|
res.code = 200;
|
|
res.msg = "成功";
|
|
res.data = blist;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |