duheng
2025-02-07 938c924c1acee378031e3f68331e50c6d58b1879
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
using IStation.Common; 
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>
    /// 长江Tide (对外开放)
    /// </summary>
    [RoutePrefix("OpenApi/Tide")]
    public class OpenTideController : ApiController
    {
        /// <summary>
        ///  获取
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        [Route("GetByRange")]
        [HttpGet]
        public IStation.Dto.ApiResult GetByRange(string start, string end)
        {
            string error;
         
            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);
            }
            var list = TideFromBookHelper.GetByTimeRange(startTime, endTime, out error);
 
            if (list == null || list.Count() == 0)
            {
                return new IStation.Dto.ApiResult<string>("获取失败", Dto.ApiResultCode.Error);
            }
            List<TideValue> list2 = new List<TideValue>();
            foreach (var m in list)
            {
                list2.Add(new TideValue(m));
            }
 
            return new IStation.Dto.ApiResult<List<TideValue>>(list2); 
        }
 
 
        /// <summary>
        /// 获取某日 
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        [Route("GetByDay")]
        [HttpGet]
        public IStation.Dto.ApiResult GetByDay(string day)
        {
            string error;
         
 
            DateTime startTime;
            if (!DateTime.TryParse(day, out startTime))
            {
                return new IStation.Dto.ApiResult<string>("day 参数不合理", Dto.ApiResultCode.Error);
            }
            var list = TideFromBookHelper.GetByDay2(startTime, out error);
 
            if(list == null || list.Count()==0)
            {
                return new IStation.Dto.ApiResult<string>("获取失败", Dto.ApiResultCode.Error);
            }
            List<TideValue> list2 = new List<TideValue>();
            foreach(var  m in list)
            {
                list2.Add(new TideValue(m));
            }
 
            return new IStation.Dto.ApiResult<List<TideValue>>(list2);
        }
 
 
 
        public class TideValue
        {
            public TideValue() { }
            public TideValue(Model.TimeWaterLevel rhs)
            {
                this.Time = rhs.Time;
                this.Value = rhs.Level;
            }
            public TideValue(DateTime time, double level) { this.Time = time; this.Value = level; }
            public DateTime Time { get; set; }
            public double Value { get; set; }
        }
 
 
 
    }
}