duheng
2024-05-29 b4189107397fb4e2da2bd9343d0eb85d44918932
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
158
159
160
161
162
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
{
    /// <summary>
    ///
    /// </summary>
    public class ConnectHelper
    {
        /// <summary>
        ///
        /// </summary>
        public class OutTotalDayList
        {
            /// <summary>
            ///
            /// </summary>
            public DateTime DateTime { get; set; }
 
            /// <summary>
            ///
            /// </summary>
            public List<TotalOneDay> pumpOutWater { get; set; }
        }
 
        /// <summary>
        ///
        /// </summary>
        public class TotalOneDay
        {
            /// <summary>
            ///
            /// </summary>
            public DateTime DateTime { get; set; }
 
            /// <summary>
            ///
            /// </summary>
            public double Total { get; set; }
        }
 
        //获取总管天参数(累计总计)
        public static List<OutTotalDayList> 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<OutTotalDayList> outTotalDayLists = new List<OutTotalDayList>();
            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<List<TotalOneDay>>(Text);
                    outTotalDayLists.Add(new OutTotalDayList() { pumpOutWater = outwater, DateTime = outwater[0].DateTime });
                }
            }
            return outTotalDayLists;
        }
 
        public static List<SSAData> GetByPumpOneDayWaterData(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/GetPumpHistoryData?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<IStation.Dto.ApiResult<List<SSAData>>>(returnData);
            reader.Close();
            myResponse.Close();
            //   error = null;
            return ret.Data;
        }
 
        public static List<SSAData> 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<IStation.Dto.ApiResult<List<SSAData>>>(returnData);
            reader.Close();
            myResponse.Close();
            //   error = null;
            return ret.Data;
        }
    }
}