From 36a0ce55799c95821f39aab5c13566a5f238970b Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期二, 11 二月 2025 12:56:55 +0800
Subject: [PATCH] 修复预测接口问题

---
 WebApi/Controllers/PumpRunController.cs |  222 +++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 141 insertions(+), 81 deletions(-)

diff --git a/WebApi/Controllers/PumpRunController.cs b/WebApi/Controllers/PumpRunController.cs
index 2ad0236..b082193 100644
--- a/WebApi/Controllers/PumpRunController.cs
+++ b/WebApi/Controllers/PumpRunController.cs
@@ -5,6 +5,7 @@
 using IStation.ZyModel;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Security.Policy;
 using System.Threading.Tasks;
@@ -19,7 +20,6 @@
     [RoutePrefix("PumpRun")]
     public class PumpRunController : ApiController
     {
-        bool isdebug = true;
         /// <summary>
         ///  鑾峰彇娉靛疄闄呰繍琛屽弬鏁�(涓�澶�)
         /// </summary>
@@ -27,7 +27,7 @@
         /// <returns></returns>
         [Route("GetByOneDay")]
         [HttpGet]
-        public   async   Task< IStation.Dto.ApiResult>  GetByOneDay(string startday)
+        public async Task<IStation.Dto.ApiResult> GetByOneDay(string startday)
         {
             if (startday == null)
             {
@@ -44,9 +44,9 @@
             }
             RunParasData result = null;
             PumpRunParasHelper pumpRunParasHelper = new PumpRunParasHelper();
-            result =   Common.PumpRunParasHelper.ReadPumpRunParas(d);
-            string geterroer=null;
-            if (result != null&& isdebug)
+            result = Common.PumpRunParasHelper.ReadPumpRunParas(d);
+            string geterroer = null;
+            if (result != null)
             {
                 result.Electric = Math.Round(result.Electric, 2);
                 result.Money = Math.Round(result.Money, 2);
@@ -97,22 +97,22 @@
                     }
                 }
             }
-            else 
+            else
             {
                 var PumpTotalElecty = await ZyConnectHelper.GetPumpTotalElectricity(d, d);    //鑾峰彇鏌愭鏃堕棿鐨勭敤鐢甸噺
-                var PumpState = await ZyConnectHelper.GetPumpOpenStatusBySingleDay(d);  //鑾峰彇娉电殑寮�鏈烘儏鍐�             
-                var TotalWater = await ZyConnectHelper.GetTotalWaterByDayTimeRange_In(d, d);    //鍙栨按閲�
+                var PumpState = await ZyConnectHelper.GetPumpOpenStatusBySingleDay(d);  //鑾峰彇娉电殑寮�鏈烘儏鍐�
+                var TotalWater = await ZyConnectHelper.GetTotalWaterByDayTimeRange_In(d.AddDays(-1), d);    //鍙栨按閲�
 
                 /*        PumpHistoryDataFileHelper pumpHistoryDataFileHelper=new PumpHistoryDataFileHelper();
                         var TotalWater = pumpHistoryDataFileHelper.GetAllWaterData();
                         var PumpState = pumpHistoryDataFileHelper.getpumpstate();
                         var PumpTotalElecty = pumpHistoryDataFileHelper.GetAllEleData();*/
-                result = pumpRunParasHelper.GetRunParasDatas(PumpState, TotalWater, PumpTotalElecty, d,out geterroer);
-             }
+                result = pumpRunParasHelper.GetRunParasDatas(PumpState, TotalWater, PumpTotalElecty, d, out geterroer);
+            }
             if (result != null)
             {
                 pumpRunParasHelper.Save(result, out string error);
-              //  LogHelper.Info(error);
+                //  LogHelper.Info(error);
             }
             if (geterroer != null)
             {
@@ -128,7 +128,7 @@
         /// <returns></returns>
         [Route("GetByHistoryOneDay")]
         [HttpGet]
-        public  IStation.Dto.ApiResult  GetByHistoryOneDay(string day)
+        public IStation.Dto.ApiResult GetByHistoryOneDay(string day)
         {
             if (day == null)
             {
@@ -140,7 +140,7 @@
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
             }
 
-            var history =    Common.PumpRunParasHelper.ReadPumpRunParas(d);
+            var history = Common.PumpRunParasHelper.ReadPumpRunParas(d);
             if (history == null)
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "Data null" };
             history.Electric = Math.Round(history.Electric, 2);
@@ -194,8 +194,6 @@
             return new IStation.Dto.ApiResult<Model.RunParasData>(history) { Code = ApiResultCode.Success, Message = "Success" };
         }
 
-
-
         /// <summary>
         /// 涓�澶╁唴鐨勬�诲彇姘撮噺鍜岀敤鐢甸噺
         /// </summary>
@@ -203,7 +201,7 @@
         /// <returns></returns>
         [Route("GetOneDayData")]
         [HttpGet]
-        public  IStation.Dto.ApiResult  GetOneDayPumpWaterData(string day)
+        public IStation.Dto.ApiResult GetOneDayPumpWaterData(string day)
         {
             if (day == null)
             {
@@ -219,8 +217,6 @@
             return new IStation.Dto.ApiResult<List<Model.PumpWater>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
         }
 
-
-
         /// <summary>
         /// 鑾峰彇鏃堕棿娈靛唴鐨勫崟绠¢亾渚涙按鏁版嵁
         /// </summary>
@@ -230,52 +226,7 @@
         /// <returns></returns>
         [Route("GetPumpOutDayWater")]
         [HttpGet]
-        public IStation.Dto.ApiResult  GetPumpOutWater(string startday,string endday,int sign)
-        {
-            if (startday == null||endday==null)
-            {
-                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
-            }
-            DateTime Start;
-            if (!DateTime.TryParse(startday, out Start))
-            {
-                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
-            }
-            DateTime End;
-            if (!DateTime.TryParse(endday, out End))
-            {
-                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
-            }
-            var WaterParas = Common.PumpRunParasHelper.ReadPumpOutWater(Start,End, sign);
-
-            return new IStation.Dto.ApiResult<List<Model.OutList>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
-        }
-
-
-
-        /// <summary>
-        /// 鑾峰彇鎵�鏈夌殑鏈堝悎璁℃暟鎹�(鍗曠閬�)
-        /// </summary>
-        /// <returns></returns>
-        [Route("GetPumpOutMonthWater")]
-        [HttpGet]
-        public  IStation.Dto.ApiResult  GetPumpOutMonthWater()
-        {
-            var WaterParas = Common.PumpRunParasHelper.ReadPumpMonthOutWater();
-             return new IStation.Dto.ApiResult<List<Model.PumpOutWater>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
-        }
-
-
-
-        /// <summary>
-        /// 鑾峰彇澶╃殑鍚堝苟渚涙按鐬椂鏁版嵁(鎬荤)
-        /// </summary>
-        /// <param name="startday"></param> 寮�濮嬫棩鏈�
-        /// <param name="endday"></param> 缁撴潫鏃ユ湡
-        /// <returns></returns>
-        [Route("GetPumpTotalDayOutWater")]
-        [HttpGet]
-        public  IStation.Dto.ApiResult  GetPumpTotalDayOutWater(string startday, string endday)
+        public IStation.Dto.ApiResult GetPumpOutWater(string startday, string endday, int sign)
         {
             if (startday == null || endday == null)
             {
@@ -291,11 +242,50 @@
             {
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
             }
-            var WaterParas = Common.PumpRunParasHelper.ReadPumpAllDayOutWater(Start,End);
-            return new IStation.Dto.ApiResult<List<Model.OutTotalOneDayList>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
+            var WaterParas = Common.PumpRunParasHelper.ReadPumpOutWater(Start, End, sign);
+
+            return new IStation.Dto.ApiResult<List<Model.OutList>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
         }
 
+        /// <summary>
+        /// 鑾峰彇鎵�鏈夌殑鏈堝悎璁℃暟鎹�(鍗曠閬�)
+        /// </summary>
+        /// <returns></returns>
+        [Route("GetPumpOutMonthWater")]
+        [HttpGet]
+        public IStation.Dto.ApiResult GetPumpOutMonthWater()
+        {
+            var WaterParas = Common.PumpRunParasHelper.ReadPumpMonthOutWater();
+            return new IStation.Dto.ApiResult<List<Model.PumpOutWater>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
+        }
 
+        /*       /// <summary>
+               /// 鑾峰彇澶╃殑鍚堝苟渚涙按鐬椂鏁版嵁(鎬荤)
+               /// </summary>
+               /// <param name="startday"></param> 寮�濮嬫棩鏈�
+               /// <param name="endday"></param> 缁撴潫鏃ユ湡
+               /// <returns></returns>
+               [Route("GetPumpTotalDayOutWater")]
+               [HttpGet]
+               public IStation.Dto.ApiResult GetPumpTotalDayOutWater(string startday, string endday)
+               {
+                   if (startday == null || endday == null)
+                   {
+                       return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
+                   }
+                   DateTime Start;
+                   if (!DateTime.TryParse(startday, out Start))
+                   {
+                       return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+                   }
+                   DateTime End;
+                   if (!DateTime.TryParse(endday, out End))
+                   {
+                       return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+                   }
+                   var WaterParas = Common.PumpRunParasHelper.ReadPumpAllDayOutWater(Start, End);
+                   return new IStation.Dto.ApiResult<List<Model.OutTotalOneDayList>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
+               }*/
 
         /// <summary>
         /// 鑾峰彇澶╃殑鍚堝苟渚涙按绱鏁版嵁(鎬荤)
@@ -305,7 +295,7 @@
         /// <returns></returns>
         [Route("GetPumpTotalDayAccOutWater")]
         [HttpGet]
-        public IStation.Dto.ApiResult  GetPumpTotalDayAccOutWater(string startday, string endday)
+        public IStation.Dto.ApiResult GetPumpTotalDayAccOutWater(string startday, string endday)
         {
             if (startday == null || endday == null)
             {
@@ -325,18 +315,15 @@
             return new IStation.Dto.ApiResult<List<Model.OutTotalOneDayList>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
         }
 
-
-
-
         /// <summary>
-        /// 鑾峰彇缁欓娴嬫按浣嶇敤鐨勬暟鎹殑鍘嗗彶鍙栨按閲� (浠庝紬姣�) 
+        /// 鑾峰彇缁欓娴嬫按浣嶇敤鐨勬暟鎹殑鍘嗗彶鍙栨按閲� (浠庝紬姣�)
         /// </summary>
         /// <param name="startday"></param> 寮�濮嬫棩鏈�
         /// <param name="endday"></param> 缁撴潫鏃ユ湡
         /// <returns></returns>
         [Route("GetPumpHistoryData")]
         [HttpGet]
-        public async Task< IStation.Dto.ApiResult > GetPumpHistoryData(string startday, string endday)
+        public async Task<IStation.Dto.ApiResult> GetPumpHistoryData(string startday, string endday, string resolution)
         {
             if (startday == null || endday == null)
             {
@@ -352,15 +339,22 @@
             {
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
             }
-              var TotalWater = await ZyConnectHelper.GetTotalWaterByDayTimeRange_In(d, d);    //鍙栨按閲�
-            //      ReadPumpAllDayOutAccWater
-       //       var TotalWater = PumpRunParasHelper.ReadPumpAllDayOutAccWater(d, d.AddDays(1));
+            var TotalWater = await ZyConnectHelper.GetTotalWaterByTimeRange_Out(Start, d, resolution);    //鍙栨按閲�
+            /*     var one = TotalWater
+                   .SelectMany(otdl => otdl.MonitorRecords);
+                 var two = one.GroupBy(totalDay => totalDay.Time);
+                 var three = two.Select(group =>
+                 {
+                     var time = group.First().Time; // 浠庣粍涓幏鍙栨椂闂�
+                     var totalSumForTimePoint = group.Sum(totalDay => totalDay.Value); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰
+                     return new { Time = time, Total = totalSumForTimePoint };
+                 });*/
             var totalSumByTimePoint = TotalWater
               .SelectMany(otdl => otdl.MonitorRecords)
-              .GroupBy(totalDay => totalDay.Time.TimeOfDay) // 鎸夌収灏忔椂鍜屽垎閽熻繘琛屽垎缁�
+              .GroupBy(totalDay => totalDay.Time) // 鎸夌収灏忔椂鍜屽垎閽熻繘琛屽垎缁�
               .Select(group =>
               {
-                  var time = group.First().Time.TimeOfDay; // 浠庣粍涓幏鍙栨椂闂�
+                  var time = group.First().Time; // 浠庣粍涓幏鍙栨椂闂�
                   var totalSumForTimePoint = group.Sum(totalDay => totalDay.Value); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰
                   return new { Time = time, Total = totalSumForTimePoint };
               });
@@ -373,12 +367,78 @@
                     var totalSumForTimePoint = group.Sum(totalDay => totalDay.Total); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰
                     return new { Time = time, Total = totalSumForTimePoint };
                 });*/
-            List< TotalOneDay > totalOneDays = new List< TotalOneDay >();
+            List<SSAData> totalOneDays = new List<SSAData>();
             foreach (var item in totalSumByTimePoint)
             {
-                totalOneDays.Add(new TotalOneDay() { DateTime = d + item.Time, Total = (double)item.Total });
+                totalOneDays.Add(new SSAData() { DateTime = item.Time, Total = (double)item.Total });
             }
-            return new IStation.Dto.ApiResult<List<TotalOneDay>>(totalOneDays) { Code = ApiResultCode.Success, Message = "Success" };
+            return new IStation.Dto.ApiResult<List<SSAData>>(totalOneDays) { Code = ApiResultCode.Success, Message = "Success" };
+        }
+
+        /// <summary>
+        /// 鑾峰彇渚涙按寮�鏈虹姸鎬�
+        /// </summary>
+        /// <param name="startday"></param> 寮�濮嬫棩鏈�
+        /// <param name="endday"></param> 缁撴潫鏃ユ湡
+        /// <returns></returns>
+        [Route("GetPumpOpenState")]
+        [HttpGet]
+        public async Task<IStation.Dto.ApiResult> GetPumpOpenState(string startday, string endday)
+        {
+            if (startday == null || endday == null)
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
+            }
+            DateTime Start;
+            if (!DateTime.TryParse(startday, out Start))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            DateTime d;
+            if (!DateTime.TryParse(endday, out d))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            var result = await ZyConnectHelper.GetPumpOpenStatusDay(Start, d, "1h");
+            var totalSumByTimePoint = result
+            .SelectMany(otdl => otdl.MonitorRecords)
+            .GroupBy(totalDay => totalDay.Time) // 鎸夌収灏忔椂鍜屽垎閽熻繘琛屽垎缁�
+            .Select(group =>
+            {
+                var time = group.First().Time; // 浠庣粍涓幏鍙栨椂闂�
+                var totalSumForTimePoint = group.Sum(totalDay => totalDay.Value); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰
+                return new { Time = time, Total = totalSumForTimePoint };
+            });
+            List<SSAData> totalOneDays = new List<SSAData>();
+            foreach (var item in totalSumByTimePoint)
+            {
+                totalOneDays.Add(new SSAData() { DateTime = item.Time, Total = (double)item.Total });
+            }
+            return new IStation.Dto.ApiResult<List<SSAData>>(totalOneDays) { Code = ApiResultCode.Success, Message = "Success" };
+        }
+
+
+
+        [Route("GetPumpRealData")]
+        [HttpGet]
+        public async Task<IStation.Dto.ApiResult> GetPumpRealData(string startday, string endday, string resolution)
+        {
+            if (startday == null || endday == null)
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
+            }
+            DateTime Start;
+            if (!DateTime.TryParse(startday, out Start))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            DateTime d;
+            if (!DateTime.TryParse(endday, out d))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            var TotalWater = await ZyConnectHelper.GetTotalWaterByTimeRange_Out(Start, d, resolution);    //鍙栨按閲�
+            return new IStation.Dto.ApiResult<List<RealScadaData>>(TotalWater) { Code = ApiResultCode.Success, Message = "Success" };
         }
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3