using IStation.Common;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Net;
|
using System.Net.Http;
|
using System.Threading.Tasks;
|
using System.Web;
|
using System.Web.Http;
|
|
namespace IStation.WebApi.Controllers
|
{
|
/// <summary>
|
/// 长江Tide (对外开放)
|
/// </summary>
|
[RoutePrefix("OpenApi/Tide")]
|
public class OpenTideController : ApiController
|
{
|
/// <summary>
|
/// 获取
|
/// </summary>
|
/// <param name="day"></param>
|
/// <returns></returns>
|
[Route("GetByRange")]
|
[HttpGet]
|
public IStation.Dto.ApiResult GetByRange(string start, string end)
|
{
|
string error;
|
|
DateTime startTime, endTime;
|
if (!DateTime.TryParse(start, out startTime))
|
{
|
return new IStation.Dto.ApiResult<string>("start 参数不合理", Dto.ApiResultCode.Error);
|
}
|
if (!DateTime.TryParse(end, out endTime))
|
{
|
return new IStation.Dto.ApiResult<string>("end 参数不合理", Dto.ApiResultCode.Error);
|
}
|
var list = TideFromBookHelper.GetByTimeRange(startTime, endTime, out error);
|
|
if (list == null || list.Count() == 0)
|
{
|
return new IStation.Dto.ApiResult<string>("获取失败", Dto.ApiResultCode.Error);
|
}
|
List<TideValue> list2 = new List<TideValue>();
|
foreach (var m in list)
|
{
|
list2.Add(new TideValue(m));
|
}
|
|
return new IStation.Dto.ApiResult<List<TideValue>>(list2);
|
}
|
|
|
/// <summary>
|
/// 获取某日
|
/// </summary>
|
/// <param name="day"></param>
|
/// <returns></returns>
|
[Route("GetByDay")]
|
[HttpGet]
|
public IStation.Dto.ApiResult GetByDay(string day)
|
{
|
string error;
|
|
|
DateTime startTime;
|
if (!DateTime.TryParse(day, out startTime))
|
{
|
return new IStation.Dto.ApiResult<string>("day 参数不合理", Dto.ApiResultCode.Error);
|
}
|
var list = TideFromBookHelper.GetByDay2(startTime, out error);
|
|
if(list == null || list.Count()==0)
|
{
|
return new IStation.Dto.ApiResult<string>("获取失败", Dto.ApiResultCode.Error);
|
}
|
List<TideValue> list2 = new List<TideValue>();
|
foreach(var m in list)
|
{
|
list2.Add(new TideValue(m));
|
}
|
|
return new IStation.Dto.ApiResult<List<TideValue>>(list2);
|
}
|
|
|
|
public class TideValue
|
{
|
public TideValue() { }
|
public TideValue(Model.TimeWaterLevel rhs)
|
{
|
this.Time = rhs.Time;
|
this.Value = rhs.Level;
|
}
|
public TideValue(DateTime time, double level) { this.Time = time; this.Value = level; }
|
public DateTime Time { get; set; }
|
public double Value { get; set; }
|
}
|
|
|
|
}
|
}
|