tangxu
2024-10-08 54d6c9937e34066e357c3212477914ecef1370b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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
{
    /// <summary>
    /// 水库水位
    /// </summary>
    [RoutePrefix("ReservoirWaterLevel")]
    public class ReservoirWaterLevelController : ApiController
    {
        /// <summary>
        /// 获取实时值
        /// </summary>
        /// <returns></returns>
        [Route("GetRealValue")]
        [HttpGet]
        public   IStation.Dto.ApiResult  GetRealValue()
        {
            var d = ZyConnectHelper.GetRealReservoirWaterLevel();
 
            return new IStation.Dto.ApiResult<double>(d);
        }
 
        /// <summary>
        /// 获取最后一条
        /// </summary>
        /// <returns></returns>
        [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<string>() { Code = ApiResultCode.Error, Data = "数据为空" };
                }
                return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = records.Last().PredictValueList };
            }
            catch (Exception ex)
            {
                return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = ex.Message };
            }
        }
        /// <summary>
        /// 获取最后一条
        /// </summary>
        /// <returns></returns>
        [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<string>() { Code = ApiResultCode.Error, Data = "数据为空" };
                }
                return new IStation.Dto.ApiResult<IStation.Model.WaterPredictRecord>() { Code = ApiResultCode.Error, Data = records  };
            }
            catch (Exception ex)
            {
                return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = ex.Message };
            }
        }
 
        /// <summary>
        /// 获取最后一条
        /// </summary>
        /// <returns></returns>
        [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<string>() { 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<string>() { Code = ApiResultCode.Error, Data = "数据为空" };
                }
                return new IStation.Dto.ApiResult<List<IStation.Model.WaterPredictRecord>>() { Code = ApiResultCode.Error, Data = records };
            }
            catch (Exception ex)
            {
                return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = ex.Message };
            }
        }
 
        ///// <summary>
        ///// 获取今日预测值(24点时)
        ///// </summary>
        ///// <returns></returns>
        //[Route("GetTodayEndPredictiveValue")]
        //[HttpGet]
        //public async Task<IStation.Dto.ApiResult> 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<double>(-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<double>(predictiveValue);
        //        }
        //    }
 
        //    return new IStation.Dto.ApiResult<double>(now_value);
        //}
    }
}