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; using System.Xml.Linq; namespace JinanCementFactoryAPI.Controllers.api { /// /// 碳排放强度 /// public class GetCarbonIntensityController : ApiController { DataServer.BLL.coal_equipment bll = new DataServer.BLL.coal_equipment(); // GET api/ public HttpResponseMessage Get() { var res = new get_carbon_intensity(); try { var list = bll.GetModelList(""); var alist = new List(); for (int i = 0; i < 6; i++) { var model=new carbon_intensityData(); model.CarbonTime = DateTime.Now.AddMinutes(-i * 10).ToString("HH.mm"); decimal? num1 = 0; decimal? num2 = 0; decimal? num3 = 0; var blist=new List(); var model1 = new carbon_intensity(); model1.CarbonName = "一号线"; var list1 = bll.GetModelList("").Where(x => x.CoalName.Contains("一号线")).ToList(); foreach (var item1 in list1) { num1 += item1.CoalValue; } model1.CarbonValue = num1 * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12; blist.Add(model1); var model2 = new carbon_intensity(); model2.CarbonName = "二号线"; var list2 = bll.GetModelList("").Where(x => x.CoalName.Contains("二号线")).ToList(); foreach (var item2 in list2) { num2 += item2.CoalValue; } model2.CarbonValue = num2 * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12; blist.Add(model2); var model3 = new carbon_intensity(); model3.CarbonName = "三号线"; var list3 = bll.GetModelList("").Where(x => x.CoalName.Contains("三号线")).ToList(); foreach (var item3 in list3) { num3 += item3.CoalValue; } model3.CarbonValue = num3 * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12; blist.Add(model3); model.data = blist; alist.Add(model); } res.code = 200; res.msg = "成功"; res.data = alist; } 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; } } }