65 lines
2.5 KiB
C#
65 lines
2.5 KiB
C#
using DataServer.api;
|
|
using DataServer.Model;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Web.Http;
|
|
|
|
namespace DongYingAPI.Controllers.api
|
|
{
|
|
/// <summary>
|
|
/// 碳-排放强度
|
|
/// </summary>
|
|
public class GetCarbonIntensityController : 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_carbon_intensity();
|
|
try
|
|
{
|
|
var data =new List<carbon_intensityData>();
|
|
var time = DateTime.Now.ToString("yyyyMM");
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
var model=new carbon_intensityData();
|
|
var atime = DateTime.Now.AddMonths(-i).ToString("MM月");
|
|
model.time = atime;
|
|
var now = DateTime.Now;
|
|
var sdate = Convert.ToDateTime(now.AddMonths(-i).ToString("yyyy-MM-01 00:00:00"));
|
|
var edate = Convert.ToDateTime(now.AddMonths(-i+1).ToString("yyyy-MM-01 00:00:00"));
|
|
var list = bll_info.GetModelList("");
|
|
decimal? num = 0;
|
|
foreach (var item in list)
|
|
{
|
|
var list1 = bll.GetModelListDate("", time).Where(x => x.EntireTime >= sdate && x.EntireTime < edate&&x.DeviceId==item.DeviceId).ToList();
|
|
foreach (var aitem in list1)
|
|
{
|
|
num += aitem.EH;
|
|
}
|
|
}
|
|
model.CarbonPer = (num / 1000 * Convert.ToDecimal(0.5703))/100000;
|
|
model.ArealCarbon = (num / 1000 * Convert.ToDecimal(0.5703)) / 59000;
|
|
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;
|
|
}
|
|
}
|
|
} |