94 lines
3.4 KiB
C#
94 lines
3.4 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 GetElectricalRankingController : ApiController
|
|
{
|
|
DataServer.BLL.electric_equipment bll = new DataServer.BLL.electric_equipment();
|
|
DataServer.BLL.gw_data bll_gw = new DataServer.BLL.gw_data();
|
|
// GET api/<controller>
|
|
public HttpResponseMessage Get()
|
|
{
|
|
var res = new get_electrical_ranking();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
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");
|
|
}
|
|
var alist = new List<electrical_rankingData>();
|
|
int count = 0;
|
|
foreach (var item in list)
|
|
{
|
|
var model = new electrical_rankingData();
|
|
decimal? num1 = 0;
|
|
decimal? num2 = 0;
|
|
model.DistributionName = item.EquipmentName;
|
|
var list1 = bll_gw.GetModelListDate(" XTagName like '%" + item.EH + "'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault();
|
|
var list2= bll_gw.GetModelListDate(" XTagName like '%" + item.EH + "' and XTimeStamp='"+date+"'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault();
|
|
if (list1 == null)
|
|
{
|
|
num1 = num1;
|
|
}
|
|
else
|
|
{
|
|
num1 += Convert.ToDecimal(list1.XValue);
|
|
}
|
|
if (list2 == null)
|
|
{
|
|
num2 = num2;
|
|
}
|
|
else
|
|
{
|
|
num2 += Convert.ToDecimal(list2.XValue);
|
|
}
|
|
model.EH = num1-num2;
|
|
alist.Add(model);
|
|
|
|
}
|
|
var elist= new List<electrical_rankingData>();
|
|
var clist = alist.OrderByDescending(x => x.EH).DistinctBy(x=>x.DistributionName).ToList();
|
|
foreach (var bitem in clist)
|
|
{
|
|
var model1=new electrical_rankingData();
|
|
count++;
|
|
model1 = bitem;
|
|
model1.SerialNumber = count;
|
|
elist.Add(model1);
|
|
}
|
|
|
|
res.code = 200;
|
|
res.msg = "成功";
|
|
res.data = elist;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
} |