tangxu
2024-03-09 ebe1b29ddb5ad27698487cd830b42a042ff28c3a
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using IStation.Common;
using IStation.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.UI.WebControls;
 
namespace IStation.WebApi.Controllers
{
    /// <summary>
    /// 取水总量
    /// </summary>
    [RoutePrefix("TotalWaterIn")]
    public class TotalWaterInController : ApiController
    {
        /// <summary>
        /// 获取某日的取水总量
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        [Route("GetByDay")]
        [HttpGet]
        public IStation.Dto.ApiResult GetByDay(string day)
        {
            if (day == null)
            {
                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
            }
            DateTime d;
            if (!DateTime.TryParse(day, out d))
            {
                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 格式不正确" };
            }
            var sum = TotalWaterInHelper.Read(d);
            if (sum < 0)
            {
                sum = ZyConnectHelper.GetTotalWaterByDay_In(DateTime.Parse(day)).Result;//.GetAwaiter().GetResult();
 
                TotalWaterInHelper.Save(d, sum);
            }
             
            return new IStation.Dto.ApiResult<double>(sum);
        }
 
 
 
        /// <summary>
        /// 获取最近三天的取水总量
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        [Route("GetLastDay3")]
        [HttpGet]
        public IStation.Dto.ApiResult GetLastDay3( )
        { 
            DateTime yest1 = DateTime.Today.AddDays(-1); 
            var sum1 = TotalWaterInHelper.Read(yest1);
            if (sum1 < 0)
            {
                sum1 = ZyConnectHelper.GetTotalWaterByDay_In(yest1).Result;//.GetAwaiter().GetResult();
 
                TotalWaterInHelper.Save(yest1, sum1);
            }
 
            DateTime yest2 = DateTime.Today.AddDays(-2);
            var sum2 = TotalWaterInHelper.Read(yest2);
            if (sum2 < 0)
            {
                sum2 = ZyConnectHelper.GetTotalWaterByDay_In(yest2).Result;//.GetAwaiter().GetResult();
 
                TotalWaterInHelper.Save(yest2, sum2);
            }
 
            DateTime yest3 = DateTime.Today.AddDays(-3);
            var sum3 = TotalWaterInHelper.Read(yest3);
            if (sum3 < 0)
            {
                sum3 = ZyConnectHelper.GetTotalWaterByDay_In(yest3).Result;//.GetAwaiter().GetResult();
 
                TotalWaterInHelper.Save(yest3, sum3);
            }
 
            return new IStation.Dto.ApiResult<List<double>>(new List<double> { sum1 , sum2, sum3});
        }
 
 
 
 
 
 
        /// <summary>
        /// 获取web客户端ip
        /// </summary>
        /// <returns></returns>
        public static string GetWebClientIp()
        {
            string userIP = "";
 
            try
            {
                if (System.Web.HttpContext.Current == null
                 || System.Web.HttpContext.Current.Request == null
                 || System.Web.HttpContext.Current.Request.ServerVariables == null)
                {
                    return "";
                }
 
                string CustomerIP = "";
 
                //CDN加速后取到的IP simone 090805
                CustomerIP = System.Web.HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
                if (!string.IsNullOrEmpty(CustomerIP))
                {
                    return CustomerIP;
                }
 
                CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
 
                if (!String.IsNullOrEmpty(CustomerIP))
                {
                    return CustomerIP;
                }
 
                if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
                {
                    CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
 
                    if (CustomerIP == null)
                    {
                        CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    }
                }
                else
                {
                    CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
 
                if (string.Compare(CustomerIP, "unknown", true) == 0 || String.IsNullOrEmpty(CustomerIP))
                {
                    return System.Web.HttpContext.Current.Request.UserHostAddress;
                }
                return CustomerIP;
            }
            catch { }
 
            return userIP;
        }
 
 
 
 
    }
}