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
|
{
|
/// <summary>
|
/// 用水量预测值 (对外开放)
|
/// </summary>
|
[RoutePrefix("OpenApi/WaterSupplyPredict")]
|
public class OpenPredictController : ApiController
|
{
|
/// <summary>
|
/// 获取
|
/// </summary>
|
/// <param name="day"></param>
|
/// <returns></returns>
|
[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<string>("start 参数不合理", Dto.ApiResultCode.Error);
|
}
|
if (!DateTime.TryParse(end, out endTime))
|
{
|
return new IStation.Dto.ApiResult<string>("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<string>() { Code = ApiResultCode.Error, Data = "水位预测数据为空,请先保持水位预测服务正常运行" };
|
}
|
|
List<PredictValue> list2 = new List<PredictValue>();
|
|
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<string>()
|
{
|
Code = ApiResultCode.Error,
|
Data = error_info11
|
};
|
}
|
|
list2.Add(new PredictValue(r) { Time = startTime.AddHours(offset) });
|
offset++;
|
}
|
|
|
|
|
|
|
return new IStation.Dto.ApiResult<List<PredictValue>>(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; }
|
}
|
|
|
|
}
|
}
|