using IStation.ChEr.Application;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Yw.Untity;
using static IStation.Service.SSAPredictHelper;
namespace IStation.Application
{
///
///
///
public class ConnectHelper
{
///
///
///
public class OutTotalDayList
{
///
///
///
public DateTime DateTime { get; set; }
///
///
///
public List pumpOutWater { get; set; }
}
///
///
///
public class TotalOneDay
{
///
///
///
public DateTime DateTime { get; set; }
///
///
///
public double Total { get; set; }
}
//获取总管天参数(累计总计)
public static List ReadPumpAllDayAccOutWater(DateTime StartDay, DateTime EndDay)
{
//var root_folder = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(), "供水参数");
var root_folder = "C:\\Users\\ZKC\\Desktop\\累计总计";
// var root_folder = "D:\\IStation\\ChErWebApi\\Data\\供水参数";
if (!System.IO.Directory.Exists(root_folder))
{
return null;
}
// var month_folder = System.IO.Path.Combine(root_folder, "累计总计");
// day.ToString("yyyy-MM")
List outTotalDayLists = new List();
if (StartDay < new DateTime(2022, 11, 2))
{
return null;
}
for (DateTime date = StartDay; date < EndDay; date = date.AddDays(1))
{
string Path = System.IO.Path.Combine(root_folder,
string.Format("{0}", date.ToString("yyyy-MM")));
string filepath = System.IO.Path.Combine(Path,
string.Format("{0}.json", date.ToString("yyyy-MM-dd")));
if (!File.Exists(filepath))
{
// var reuslt = GetByPumpOneDayWaterData(date, date);
// outTotalDayLists.Add(new OutTotalDayList() { pumpOutWater = reuslt, DateTime = reuslt[0].DateTime });
}
else
{
string Text = File.ReadAllText(filepath);
var outwater = Yw.JsonHelper.Json2Object>(Text);
outTotalDayLists.Add(new OutTotalDayList() { pumpOutWater = outwater, DateTime = outwater[0].DateTime });
}
}
return outTotalDayLists;
}
public static List GetByPumpOneDayWaterData(DateTime starttime, DateTime endtime, string resolution)
{
// string apiServiceUrl = System.Configuration.ConfigurationManager.AppSettings["ApiServiceUrl"];
string apiServiceUrl = "http://192.168.21.14:86";
// var apiServiceUrl = System.Configuration.ConfigurationManager.AppSettings["APiServerUrl"];
string url = string.Format(@"{0}/PumpRun/GetPumpHistoryData?startday={1}&endday={2}&resolution={3}", apiServiceUrl, starttime, endtime, resolution);
string Accept = "application/json";
//创建Web访问对象
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
//myRequest.Accept = "application/json";
// myRequest.ContentType = "application/json"; // //Content-Type: application/x-www-form-urlencoded
myRequest.AutomaticDecompression = DecompressionMethods.GZip;
myRequest.Accept = Accept;
//myRequest.ContentType = ContentType;
myRequest.ContentType = "application/json; charset=UTF-8";
//myRequest.ContentLength = buf.Length;
myRequest.MaximumAutomaticRedirections = 1;
myRequest.AllowAutoRedirect = true;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
//通过响应内容流创建StreamReader对象,因为StreamReader更高级更快
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
//string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
string returnData = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
if (string.IsNullOrEmpty(returnData))
{
myResponse.Close();
// error = "利用StreamReader就可以从响应内容从头读到尾";
return null;
}
var ret = Yw.JsonHelper.Json2Object>>(returnData);
reader.Close();
myResponse.Close();
// error = null;
return ret.Data;
}
public static List GetByPumpOpenState(DateTime starttime, DateTime endtime)
{
// string apiServiceUrl = System.Configuration.ConfigurationManager.AppSettings["ApiServiceUrl"];
string apiServiceUrl = "http://192.168.21.14:86";
string url = string.Format(@"{0}/PumpRun/GetPumpOpenState?startday={1}&endday={2}", apiServiceUrl, starttime, endtime);
string Accept = "application/json";
//创建Web访问对象
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
//myRequest.Accept = "application/json";
// myRequest.ContentType = "application/json"; // //Content-Type: application/x-www-form-urlencoded
myRequest.AutomaticDecompression = DecompressionMethods.GZip;
myRequest.Accept = Accept;
//myRequest.ContentType = ContentType;
myRequest.ContentType = "application/json; charset=UTF-8";
//myRequest.ContentLength = buf.Length;
myRequest.MaximumAutomaticRedirections = 1;
myRequest.AllowAutoRedirect = true;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
//通过响应内容流创建StreamReader对象,因为StreamReader更高级更快
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
//string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
string returnData = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
if (string.IsNullOrEmpty(returnData))
{
myResponse.Close();
// error = "利用StreamReader就可以从响应内容从头读到尾";
return null;
}
var ret = Yw.JsonHelper.Json2Object>>(returnData);
reader.Close();
myResponse.Close();
// error = null;
return ret.Data;
}
}
}