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.Text; using System.Web.Http; namespace JinanCementFactoryAPI.Controllers.api { /// /// 碳流图 /// public class GetCarbonFluxController : ApiController { DataServer.BLL.coal_equipment bll = new DataServer.BLL.coal_equipment(); // GET api/ public HttpResponseMessage Get() { var res = new get_carbon_flux(); try { var list = bll.GetModelList(""); var alist = new List(); var model=new carbon_fluxData(); model.AmountName = "总量"; decimal? num = 0; foreach (var item in list) { num += item.CoalValue; var blist = new List(); var list1 = list.DistinctBy(x => x.CoalName).ToList(); foreach (var aitem in list1) { var model1 = new carbon_fluxlist(); model1.CoalName= aitem.CoalName; var flist1=list.Where(x=>x.CoalName==aitem.CoalName).ToList(); decimal? num1 = 0; var clist=new List(); //decimal? num2 = 0; foreach (var bitem in flist1) { num1 += bitem.CoalValue; var model2=new carbon_flux(); model2.CarbonName = bitem.CoalDescription; model2.CarbonValue= bitem.CoalValue * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12; clist.Add(model2); } model1.CoalValue= num1 * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12; model1.data = clist; blist.Add(model1); } model.list = blist; } model.AmountValue = num * Convert.ToDecimal(25.909) * Convert.ToDecimal(0.02610) * 44 / 12; 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; } } }