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 JinanCementFactoryAPI.Controllers.api { /// /// 排放各类占比 /// public class GetCarbonRatioController : ApiController { DataServer.BLL.coal_equipment bll = new DataServer.BLL.coal_equipment(); // GET api/ public HttpResponseMessage Get() { var res = new get_carbon_ratio(); try { var list = bll.GetModelList(""); var alist = new List(); var model=new carbon_ratioData(); decimal? num = 0; foreach (var item in list) { num += item.CoalValue; } model.Amount = num * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12; decimal? num1 = 0; decimal? num2 = 0; decimal? num3 = 0; var blist = new List(); var model1 = new carbon_ratio(); 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_ratio(); 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_ratio(); 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; } } }