60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
using DataServer.api;
|
|
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;
|
|
|
|
namespace DongYingAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 用能监测2-用电设备排名
|
|
/// </summary>
|
|
public class GetElectricEquipmentController : ApiController
|
|
{
|
|
DataServer.BLL.electricity_data bll = new DataServer.BLL.electricity_data();
|
|
DataServer.BLL.device_info bll_info = new DataServer.BLL.device_info();
|
|
|
|
public HttpResponseMessage Get()
|
|
{
|
|
var res = new get_electrical_ranking();
|
|
try
|
|
{
|
|
var data = new List<electrical_rankingData>();
|
|
var time = DateTime.Now.ToString("yyyyMM");
|
|
var now = DateTime.Now;
|
|
var sdate = Convert.ToDateTime(now.ToString("yyyy-MM-dd 00:00:00"));
|
|
var edate = Convert.ToDateTime(now.AddDays(+1).ToString("yyyy-MM-dd 00:00:00"));
|
|
var list = bll.GetModelListDate("",time).Where(x => x.EntireTime >= sdate && x.EntireTime < edate).ToList();
|
|
var alist = bll_info.GetModelList("");
|
|
decimal? num = 0;
|
|
foreach (var item in list)
|
|
{
|
|
var model = new electrical_rankingData();
|
|
foreach (var aitem in alist)
|
|
{
|
|
model.ElectricaName = aitem.DeviceName;
|
|
}
|
|
num = item.EH;
|
|
model.ElectricaValue = num;
|
|
data.Add(model);
|
|
}
|
|
var elist = data.OrderByDescending(x => x.ElectricaValue).ToList();
|
|
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;
|
|
}
|
|
}
|
|
} |