tangxu
2025-02-07 03a0d99de9c5fed6bea8bc83b49ce27786bda38c
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
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; }
        }
 
 
 
    }
}