using IStation.Common;
using IStation.Dto;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
namespace IStation.WebApi.Controllers
{
///
/// 水库水位
///
[RoutePrefix("ReservoirWaterLevel")]
public class ReservoirWaterLevelController : ApiController
{
///
/// 获取实时值
///
///
[Route("GetRealValue")]
[HttpGet]
public IStation.Dto.ApiResult GetRealValue()
{
var d = ZyConnectHelper.GetRealReservoirWaterLevel();
return new IStation.Dto.ApiResult(d);
}
///
/// 获取最后一条
///
///
[Route("GetLastPredictValue")]
[HttpGet]
public IStation.Dto.ApiResult GetLastPredictValue()
{
try
{
IStation.DAL.WaterPredictRecord dal = new DAL.WaterPredictRecord();
var records = dal.GetLast(1);
if (records == null || records.Count == 0)
{
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Data = "数据为空" };
}
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Data = records.Last().PredictValueList };
}
catch (Exception ex)
{
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Data = ex.Message };
}
}
///
/// 获取最后一条
///
///
[Route("GetPredictRecordBySingleHour")]
[HttpGet]
public IStation.Dto.ApiResult GetPredictRecordBySingleHour(DateTime time)
{
try
{
IStation.DAL.WaterPredictRecord dal = new DAL.WaterPredictRecord();
var records = dal.GetBySingleHour(time);
if (records == null )
{
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Data = "数据为空" };
}
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Data = records };
}
catch (Exception ex)
{
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Data = ex.Message };
}
}
///
/// 获取最后一条
///
///
[Route("GetPredictRecordByHourRange")]
[HttpGet]
public IStation.Dto.ApiResult GetPredictRecordByHourRange(string start_time, string end_time)
{
if (string .IsNullOrEmpty(start_time) || string .IsNullOrEmpty(end_time))
{
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Data = "start_time 或者 end_time 数据为空" };
}
try
{
IStation.DAL.WaterPredictRecord dal = new DAL.WaterPredictRecord();
var records = dal.GetByHourRangle(DateTime.Parse( start_time), DateTime.Parse(end_time));
if (records == null)
{
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Data = "数据为空" };
}
return new IStation.Dto.ApiResult>() { Code = ApiResultCode.Error, Data = records };
}
catch (Exception ex)
{
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Data = ex.Message };
}
}
/////
///// 获取今日预测值(24点时)
/////
/////
//[Route("GetTodayEndPredictiveValue")]
//[HttpGet]
//public async Task GetTodayEndPredictiveValue()
//{
// var now_value = await ZyConnectHelper.GetRealReservoirWaterLevel();
// IStation.CalcModel.AnaRequestBase requestBase
// var today_prj = Common.HistoryAnaPrjFileHelper.GetPrj(DateTime.Today);
// if(today_prj == null || today_prj.BlockTimes == null || today_prj.PointTimes == null)
// {
// return new IStation.Dto.ApiResult(-100);
// }
// var now = DateTime.Now;
// double predictiveValue = now_value;
// foreach(var pt in today_prj.PointTimes)
// {
// if (now > pt.Time)
// {
// predictiveValue = now_value + today_prj.PointTimes.Last().WaterLevelH - pt.WaterLevelH;
// return new IStation.Dto.ApiResult(predictiveValue);
// }
// }
// return new IStation.Dto.ApiResult(now_value);
//}
}
}