DongYing/DongYingAPI/Controllers/api/GetMeteorologicalStationCon...

57 lines
1.9 KiB
C#

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
{
/// <summary>
/// 空调-气象站
/// </summary>
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<meteorological_stationData>();
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();
if (list.Count == 0)
{
var model = new meteorological_stationData();
model.WeatherName = "无";
model.WeatherValue = 0;
data.Add(model);
}
foreach (var item in list)
{
var model = new meteorological_stationData();
model.WeatherName = item.MeteorologicalName;
model.WeatherValue = item.MeteorologicalValue;
data.Add(model);
}
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;
}
}
}