using DataServer.api; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Web.Http; namespace DongYingAPI.Controllers.api { /// /// 空调-气象站 /// public class GetMeteorologicalStationController : ApiController { DataServer.BLL.meteorological_station bll = new DataServer.BLL.meteorological_station(); public HttpResponseMessage Get() { var res = new get_meteorological_station(); try { var data = new List(); var now=DateTime.Now; var edate=Convert.ToDateTime(now.ToString("yyyy-MM-dd HH:00:00")); var list=bll.GetModelList("").Where(x=>x.EntireTime==edate).ToList(); var model1 = new meteorological_stationData(); model1.WeatherName = "湿度"; var alist1 = list.Where(x => x.MeteorologicalName == model1.WeatherName).FirstOrDefault(); if (alist1 == null) { model1.WeatherValue = 0; } else { model1.WeatherValue = alist1.MeteorologicalValue; } data.Add(model1); var model2 = new meteorological_stationData(); model2.WeatherName = "室外噪音"; var alist2 = list.Where(x => x.MeteorologicalName == model2.WeatherName).FirstOrDefault(); if (alist2 == null) { model2.WeatherValue = 0; } else { model2.WeatherValue = alist2.MeteorologicalValue; } data.Add(model2); var model3 = new meteorological_stationData(); model3.WeatherName = "温度"; var alist3 = list.Where(x => x.MeteorologicalName == model3.WeatherName).FirstOrDefault(); if (alist3 == null) { model3.WeatherValue = 0; } else { model3.WeatherValue = alist3.MeteorologicalValue; } data.Add(model3); var model4 = new meteorological_stationData(); model4.WeatherName = "风力"; var alist4 = list.Where(x => x.MeteorologicalName == model4.WeatherName).FirstOrDefault(); if (alist4 == null) { model4.WeatherValue = 0; } else { model4.WeatherValue = alist4.MeteorologicalValue; } data.Add(model4); var model5 = new meteorological_stationData(); model5.WeatherName = "空气质量"; var alist5 = list.Where(x => x.MeteorologicalName == model5.WeatherName).FirstOrDefault(); if (alist5 == null) { model5.WeatherValue = 0; } else { model5.WeatherValue = alist5.MeteorologicalValue; } data.Add(model5); var model6 = new meteorological_stationData(); model6.WeatherName = "紫外线强度"; var alist6 = list.Where(x => x.MeteorologicalName == model6.WeatherName).FirstOrDefault(); if (alist6 == null) { model6.WeatherValue = 0; } else { model6.WeatherValue = alist6.MeteorologicalValue; } data.Add(model6); 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; } } }