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
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" };
            }
            double sum = 100 + DateTime.Parse(day).Day;
            TotalWaterInHelper.Save(DateTime.Parse(day), sum);
            //var sum = ZyConnectHelper.GetTotalWaterByDay_In(DateTime.Parse(day)).Result;//.GetAwaiter().GetResult();
 
            return new IStation.Dto.ApiResult<double>(sum);
        }
 
 
 
 
 
 
 
 
 
 
        /// <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;
        }
 
 
 
 
    }
}