68 lines
2.3 KiB
C#
68 lines
2.3 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.loop_distribution bll = new DataServer.BLL.loop_distribution();
|
|
// GET api/<controller>
|
|
public HttpResponseMessage Get()
|
|
{
|
|
var res = new get_electrical_ranking();
|
|
try
|
|
{
|
|
var list = bll.GetModelList("");
|
|
var alist = new List<electrical_rankingData>();
|
|
int count = 0;
|
|
foreach (var item in list)
|
|
{
|
|
var model = new electrical_rankingData();
|
|
decimal? num1 = 0;
|
|
var blist=list.Where(x=>x.LoopName== item.LoopName).ToList();
|
|
model.DistributionName = item.LoopName;
|
|
foreach (var aitem in blist)
|
|
{
|
|
num1 += aitem.EH;
|
|
}
|
|
model.EH = num1;
|
|
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;
|
|
}
|
|
}
|
|
} |