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;
|
using System.Web.UI.WebControls;
|
|
namespace IStation.WebApi.Controllers
|
{
|
/// <summary>
|
/// 供水总量
|
/// </summary>
|
[RoutePrefix("TotalWaterOut")]
|
public class TotalWaterOutController : ApiController
|
{
|
/// <summary>
|
/// 获取某日的供水总量
|
/// </summary>
|
/// <param name="day"></param>
|
/// <returns></returns>
|
[Route("GetByDay")]
|
[HttpGet]
|
public async Task<IStation.Dto.ApiResult> GetByDay(string day)
|
{
|
if (day == null)
|
{
|
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
|
}
|
DateTime dayD;
|
if (!DateTime.TryParse(day, out dayD))
|
{
|
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 格式不正确" };
|
}
|
if (dayD > DateTime.Today)
|
{
|
return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "不能查询今日的数据" };
|
}
|
|
double sum = -1;
|
if (dayD < DateTime.Today)
|
{
|
sum = TotalWaterOutHelper.Read(dayD);
|
}
|
if (sum < 0)
|
{
|
sum = await ZyConnectHelper.GetTotalWaterByDay_Out(DateTime.Parse(day));//.Result;//.GetAwaiter().GetResult();
|
if (dayD < DateTime.Today)
|
{
|
TotalWaterOutHelper.Save(dayD, sum);
|
}
|
}
|
|
return new IStation.Dto.ApiResult<double>(sum / 10000);
|
}
|
|
|
/// <summary>
|
/// 获取最近三天的供水总量
|
/// </summary>
|
/// <param name="day"></param>
|
/// <returns></returns>
|
[Route("GetLastDay3")]
|
[HttpGet]
|
public async Task<IStation.Dto.ApiResult> GetLastDay3()
|
{
|
DateTime yest1 = DateTime.Today.AddDays(-1);
|
var sum1 = TotalWaterOutHelper.Read(yest1);
|
if (sum1 < 0)
|
{
|
sum1 = await ZyConnectHelper.GetTotalWaterByDay_Out(yest1);//.Result;//.GetAwaiter().GetResult();
|
|
TotalWaterOutHelper.Save(yest1, sum1);
|
}
|
|
DateTime yest2 = DateTime.Today.AddDays(-2);
|
var sum2 = TotalWaterOutHelper.Read(yest2);
|
if (sum2 < 0)
|
{
|
sum2 = await ZyConnectHelper.GetTotalWaterByDay_Out(yest2);//.Result;//.GetAwaiter().GetResult();
|
|
TotalWaterOutHelper.Save(yest2, sum2);
|
}
|
|
DateTime yest3 = DateTime.Today.AddDays(-3);
|
var sum3 = TotalWaterOutHelper.Read(yest3);
|
if (sum3 < 0)
|
{
|
sum3 = await ZyConnectHelper.GetTotalWaterByDay_Out(yest3);//.Result;//.GetAwaiter().GetResult();
|
|
TotalWaterOutHelper.Save(yest3, sum3);
|
}
|
|
return new IStation.Dto.ApiResult<List<double>>(new List<double> { sum1 / 10000, sum2 / 10000, sum3 / 10000 });
|
}
|
|
|
|
|
|
|
|
|
/// <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;
|
}
|
|
|
|
|
}
|
}
|