using IStation.Common;
using IStation.Dto;
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
{
///
/// 用水量预测值 (对外开放)
///
[RoutePrefix("OpenApi/WaterSupplyPredict")]
public class OpenPredictController : ApiController
{
///
/// 获取
///
///
///
[Route("GetByRange")]
[HttpGet]
public IStation.Dto.ApiResult GetByRange(string start, string end)
{
DateTime startTime, endTime;
if (!DateTime.TryParse(start, out startTime))
{
return new IStation.Dto.ApiResult("start 参数不合理", Dto.ApiResultCode.Error);
}
if (!DateTime.TryParse(end, out endTime))
{
return new IStation.Dto.ApiResult("end 参数不合理", Dto.ApiResultCode.Error);
}
IStation.DAL.WaterPredictRecord dal = new DAL.WaterPredictRecord();
var water_records = dal.GetByHourRangle(startTime, endTime);
if (water_records == null || water_records.Count == 0)
{
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Data = "水位预测数据为空,请先保持水位预测服务正常运行" };
}
List list2 = new List();
int offset=0;
foreach (var r in water_records)
{
if (r.States == 0)
{
var error_info11 = string.Format("预测数据异常,无法进行水位计算:{0} {1},{2}", r.DayHour, r.LastPredictValue, r.Description);
return new IStation.Dto.ApiResult()
{
Code = ApiResultCode.Error,
Data = error_info11
};
}
list2.Add(new PredictValue(r) { Time = startTime.AddHours(offset) });
offset++;
}
return new IStation.Dto.ApiResult>(list2);
}
public class PredictValue
{
public PredictValue() { }
public PredictValue(IStation.Model.WaterPredictRecord rhs)
{
this.Value = rhs.LastPredictValue;
}
public PredictValue(DateTime time, double level) { this.Time = time; this.Value = level; }
public DateTime Time { get; set; }
public double Value { get; set; }
}
}
}