using DataServer.api; using Microsoft.Ajax.Utilities; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Web.Http; namespace JinanCementFactoryAPI.Controllers.api { /// /// 熟料边界总览 /// public class GetClinkerBoundaryController : ApiController { DataServer.BLL.electrical_installation bll = new DataServer.BLL.electrical_installation(); DataServer.BLL.coal_equipment bll_coal=new DataServer.BLL.coal_equipment(); DataServer.BLL.gw_data bll_gw=new DataServer.BLL.gw_data(); // GET api/ public HttpResponseMessage Get(string date="") { var res = new get_clinker_boundary(); try { var list = bll.GetModelList("").Where(x=>x.EquipmentName.Contains("熟料")).ToList(); var clist = bll_coal.GetModelList(""); var alist = new List(); var now=DateTime.Now; if (date == "年") { var sdate = now.ToString("yyyy-01-01 00:00:00"); string time; if (now.Month < 10) { time = now.ToString("yyyy_M"); } else { time = now.ToString("yyyy_MM"); } string stime; if (Convert.ToDateTime(sdate).Month < 10) { stime = Convert.ToDateTime(sdate).ToString("yyyy_M"); } else { stime = Convert.ToDateTime(sdate).ToString("yyyy_MM"); } decimal? anum = 0; decimal? bnum = 0; foreach (var item in clist) { var list1 = bll_gw.GetModelListDate(" XTagName like '%"+item.Reserve1+"'", time).OrderByDescending(x=>x.XTimeStamp).FirstOrDefault(); var list2 = bll_gw.GetModelListDate(" XTagName like '%" + item.Reserve1 + "' and XTimeStamp='"+sdate+"'", stime).OrderByDescending(x => x.XTimeStamp).FirstOrDefault(); if (list1 == null) { anum = anum; } else { anum += Convert.ToDecimal(list1.XValue); } if (list2 == null) { bnum = bnum; } else { bnum += Convert.ToDecimal(list2.XValue); } } foreach (var item in list.DistinctBy(x => x.EquipmentName)) { var model = new clinker_boundaryData(); decimal? num1 = 0; decimal? num2 = 0; if (item.EquipmentName == "一号线熟料收尘") { model.ClinkerName = "一号线熟料排放量"; } if (item.EquipmentName == "二号线熟料收尘") { model.ClinkerName = "二号线熟料排放量"; } if (item.EquipmentName == "三号线熟料收尘") { model.ClinkerName = "三号线熟料排放量"; } var list1 = list.Where(x => x.EquipmentName == item.EquipmentName).ToList(); foreach (var aitem in list1) { var slist1 = bll_gw.GetModelListDate(" XTagName like '%" + aitem.EH + "'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault(); var zlist1 = bll_gw.GetModelListDate(" XTagName like '%" + aitem.EH + "' and XTimeStamp='"+date+"'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault(); if (slist1 == null) { num1 = num1; } else { num1 += Convert.ToDecimal(slist1.XValue); } if (zlist1 == null) { num2 = num2; } else { num2+= Convert.ToDecimal(zlist1.XValue); } } model.ClinkerValue = (num1-num2) * Convert.ToDecimal(0.5703) + (anum-bnum) * Convert.ToDecimal(0.02610); alist.Add(model); } } if (date == "月") { var sdate = now.ToString("yyyy-MM-01 00:00:00"); string time; if (now.Month < 10) { time = now.ToString("yyyy_M"); } else { time = now.ToString("yyyy_MM"); } string stime; if (Convert.ToDateTime(sdate).Month < 10) { stime = Convert.ToDateTime(sdate).ToString("yyyy_M"); } else { stime = Convert.ToDateTime(sdate).ToString("yyyy_MM"); } decimal? anum = 0; decimal? bnum = 0; foreach (var item in clist) { var list1 = bll_gw.GetModelListDate(" XTagName like '%" + item.Reserve1 + "'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault(); var list2 = bll_gw.GetModelListDate(" XTagName like '%" + item.Reserve1 + "' and XTimeStamp='" + sdate + "'", stime).OrderByDescending(x => x.XTimeStamp).FirstOrDefault(); if (list1 == null) { anum = anum; } else { anum += Convert.ToDecimal(list1.XValue); } if (list2 == null) { bnum = bnum; } else { bnum += Convert.ToDecimal(list2.XValue); } } foreach (var item in list.DistinctBy(x => x.EquipmentName)) { var model = new clinker_boundaryData(); decimal? num1 = 0; decimal? num2 = 0; if (item.EquipmentName == "一号线熟料收尘") { model.ClinkerName = "一号线熟料排放量"; } if (item.EquipmentName == "二号线熟料收尘") { model.ClinkerName = "二号线熟料排放量"; } if (item.EquipmentName == "三号线熟料收尘") { model.ClinkerName = "三号线熟料排放量"; } var list1 = list.Where(x => x.EquipmentName == item.EquipmentName).ToList(); foreach (var aitem in list1) { var slist1 = bll_gw.GetModelListDate(" XTagName like '%" + aitem.EH + "'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault(); var zlist1 = bll_gw.GetModelListDate(" XTagName like '%" + aitem.EH + "' and XTimeStamp='" + date + "'", time).OrderByDescending(x => x.XTimeStamp).FirstOrDefault(); if (slist1 == null) { num1 = num1; } else { num1 += Convert.ToDecimal(slist1.XValue); } if (zlist1 == null) { num2 = num2; } else { num2 += Convert.ToDecimal(zlist1.XValue); } } model.ClinkerValue = (num1 - num2) * Convert.ToDecimal(0.5703) + (anum - bnum) * Convert.ToDecimal(0.02610); 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; } } }