From 0e57c17412761fc2f46566a8f32fd5c62e636366 Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期二, 11 二月 2025 14:12:54 +0800
Subject: [PATCH] 修改供水量只取24条

---
 WebApi/Controllers/ZyPrjController.cs |  144 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 107 insertions(+), 37 deletions(-)

diff --git a/WebApi/Controllers/ZyPrjController.cs b/WebApi/Controllers/ZyPrjController.cs
index 9e2822c..e4f85e5 100644
--- a/WebApi/Controllers/ZyPrjController.cs
+++ b/WebApi/Controllers/ZyPrjController.cs
@@ -100,12 +100,16 @@
             anaRequest.StartTime = start_timme;
             anaRequest.EndTime = end_timme;
             anaRequest.WaterLevels闀挎睙 = GetTide3Day(_tideSouce, start_timme);
+            if (anaRequest.WaterLevels闀挎睙 == null || anaRequest.WaterLevels闀挎睙.Count() == 0)
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏃犳硶鑾峰彇闀挎睙姘翠綅鏁版嵁" };
+            }
 
             #region 鍙栨按鎬婚噺
 
+            double TotalFlowIn = 0;
             if (!string.IsNullOrEmpty(request.TotalFlowIn) && !string.IsNullOrWhiteSpace(request.TotalFlowIn))
             {
-                double TotalFlowIn = 0;
                 if (!double.TryParse(request.TotalFlowIn, out TotalFlowIn))
                 {
                     return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璇疯緭鍏ユ暟瀛楀瀷鍙栨按鎬婚噺,鎺ュ彈鍒扮殑杈撳叆鍊兼槸:" + request.TotalFlowIn };
@@ -148,10 +152,10 @@
                 {
                     return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璇疯緭鍏ュ彇姘存�婚噺鎴栨按浣嶈姹�" };
                 }
-                double TotalFlowIn = 0;
-                if (!double.TryParse(request.TotalFlowIn, out TotalFlowIn))
+
+                if (TotalFlowIn < 1000)
                 {
-                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璇疯緭鍏ユ暟瀛楀瀷鍙栨按鎬婚噺,鎺ュ彈鍒扮殑杈撳叆鍊兼槸:" + request.TotalFlowIn };
+                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璇疯緭鍏ュ彇姘存�婚噺,鎺ュ彈鍒扮殑杈撳叆鍊兼槸:" + request.TotalFlowIn };
                 }
             }
 
@@ -166,6 +170,7 @@
             if (string.IsNullOrEmpty(request.TotalFlowOut) || string.IsNullOrWhiteSpace(request.TotalFlowOut))
             {//鐢ㄩ娴嬪��
                 #region 鐢ㄩ娴嬪��
+
                 anaRequest.PerHourFlowOut = new List<double>();
                 IStation.DAL.WaterPredictRecord dal = new DAL.WaterPredictRecord();
                 var water_records = dal.GetByHourRangle(start_timme, end_timme);
@@ -201,10 +206,11 @@
                     anaRequest.PerHourFlowOut.Add(r.LastPredictValue);//璁$畻涓敤鍚�
                 }
                 IStation.LogHelper.Info(
-                    string.Format("鑾峰彇姘撮噺棰勬祴鍊�:  {0} ,  棰勬祴鍊兼�讳緵姘存�婚噺:{1} ", 
+                    string.Format("鑾峰彇姘撮噺棰勬祴鍊�:  {0} ,  棰勬祴鍊兼�讳緵姘存�婚噺:{1} ",
                     string.Join(",", anaRequest.PerHourFlowOut), TotalFlowOut棰勬祴鍊肩殑渚涙按鎬婚噺));
                 FlowTotalOut闇�姹� = TotalFlowOut棰勬祴鍊肩殑渚涙按鎬婚噺;
-                isPredictRecord = true ;
+                isPredictRecord = true;
+
                 #endregion 鐢ㄩ娴嬪��
             }
             else
@@ -229,7 +235,7 @@
                 anaRequest.PerHourFlowOut = list;
 
                 FlowTotalOut闇�姹� = TotalFlowOut鎵嬪姩杈撳叆闇�姹�;
-                isPredictRecord = false ;
+                isPredictRecord = false;
             }
 
             #endregion 渚涙按閲�
@@ -276,11 +282,8 @@
                     anaRequest.StartReservoirLevel)
                 };
             }
-            //bool isTemp = false;
-            //if (!string.IsNullOrEmpty(request.IsTemporary))
-            //{
-            //    isTemp = Convert.ToBoolean(request.IsTemporary);
-            //}
+
+            IStation.LogHelper.Info("kashi 璁$畻鍙栨按鎬婚噺 ");
 
             var calcHelper = new IStation.CalcPrjHelper();
             AnaPrj defaultPrj = null;
@@ -297,16 +300,14 @@
             }
             IStation.LogHelper.Info("-----------------------------END--------------------------------------");
 
-            //淇濆瓨鏂规 
+            //淇濆瓨鏂规
             var ret = Common.HistoryAnaPrjFileHelper.SavePrj(IStation.AnaGlobalParas.Setting, isPredictRecord, anaRequest, defaultPrj);
 
             //
             var dto_prj = ToPrjDto(defaultPrj);
             dto_prj.FlowTotalOut = FlowTotalOut闇�姹�;
-           
 
-            #region 鎺ㄩ��
-
+            //鎺ㄩ��:浠g爜淇濈暀
             //if (!string.IsNullOrEmpty(request.IsSubmit) && Convert.ToBoolean(request.IsSubmit))
             //{
             //    Task.Run(() =>
@@ -315,9 +316,8 @@
             //    });
             //}
 
-            #endregion 鎺ㄩ��
-
-            // IStation.LogHelper.Info(string.Format(" 浜х敓璁$畻鏂规:{0}", dto_prj.schemeID));
+            //IStation.LogHelper.Info(string.Format(" 浜х敓璁$畻鏂规:{0}", dto_prj.schemeID));
+            //IStation.LogHelper.Info(string.Format("Zy Prj  璁$畻鎴愬姛:  \r\n {0}  ", JsonHelper.Object2Json(dto_prj)));
 
             return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success };
         }
@@ -417,8 +417,6 @@
             }
         }
 
-
-
         /// <summary>
         ///  鑾峰彇鏌愪竴澶�,鏈�杩戜竴鏉�
         /// </summary>
@@ -437,7 +435,6 @@
             {
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
             }
-            
 
             IStation.CalcModel.AnaRequestBase requestBase = null;
             var prj = Common.HistoryAnaPrjFileHelper.GetByCreateDay(d, out requestBase);
@@ -449,6 +446,17 @@
                 {
                     var sumFlow = (from x in requestBase.PerHourFlowOut select x).Sum();
                     dto_prj.FlowTotalOut = sumFlow;
+                }
+                if (dto_prj.Switchs != null)
+                {
+                    var switch2 = from x in dto_prj.Switchs orderby x.Time select x;
+                    int index = 1;
+                    foreach (var sw in switch2)
+                    {
+                        sw.Index = index;
+                        index++;
+                    }
+                    dto_prj.Switchs = switch2.ToList();
                 }
 
                 return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success };
@@ -476,25 +484,35 @@
                 IStation.LogHelper.Info(" api GetLastHistoryRecord is null ");
                 return null;
             }
-       
+
             IStation.CalcModel.AnaRequestBase requestBase = null;
             var prj = Common.HistoryAnaPrjFileHelper.GetByStartTime(record.StartTime, out requestBase);
             if (prj != null)
-            { 
+            {
                 var dto_prj = ToPrjDto(prj);
                 if (requestBase != null && requestBase.PerHourFlowOut != null)
                 {
-                    var sumFlow = (from x in requestBase.PerHourFlowOut select x).Sum();
+                    var sumFlow = (from x in requestBase.PerHourFlowOut.Take(24) select x).Sum();
                     dto_prj.FlowTotalOut = sumFlow;
                 }
-
+                if (dto_prj.Switchs != null)
+                {
+                    var switch2 = from x in dto_prj.Switchs orderby x.Time select x;
+                    int index = 1;
+                    foreach (var sw in switch2)
+                    {
+                        sw.Index = index;
+                        index++;
+                    }
+                    dto_prj.Switchs = switch2.ToList();
+                }
                 return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success };
             }
             else
             {
                 IStation.LogHelper.Info(string.Format(
-                    " api GetLastHistoryRecord is null (鏈壘鍒伴」鐩�) LastRecord 淇℃伅: ID:{0}, StartTime:{1}, EndTime:{2}", 
-                    record.ID, 
+                    " api GetLastHistoryRecord is null (鏈壘鍒伴」鐩�) LastRecord 淇℃伅: ID:{0}, StartTime:{1}, EndTime:{2}",
+                    record.ID,
                     record.StartTime, record.EndTime));
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Alert, Message = "鏈壘鍒伴」鐩�" };
             }
@@ -520,14 +538,24 @@
             IStation.CalcModel.AnaRequestBase requestBase = null;
             var prj = Common.HistoryAnaPrjFileHelper.GetByStartTime(record.StartTime, out requestBase);
             if (prj != null)
-            { 
+            {
                 var dto_prj = ToPrjDto(prj);
-                if (requestBase != null && requestBase.PerHourFlowOut != null )
+                if (requestBase != null && requestBase.PerHourFlowOut != null)
                 {
                     var sumFlow = (from x in requestBase.PerHourFlowOut select x).Sum();
                     dto_prj.FlowTotalOut = sumFlow;
                 }
-
+                if (dto_prj.Switchs != null)
+                {
+                    var switch2 = from x in dto_prj.Switchs orderby x.Time select x;
+                    int index = 1;
+                    foreach (var sw in switch2)
+                    {
+                        sw.Index = index;
+                        index++;
+                    }
+                    dto_prj.Switchs = switch2.ToList();
+                }
                 return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success };
             }
             else
@@ -539,7 +567,6 @@
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Alert, Message = "鏈壘鍒伴」鐩�" };
             }
         }
-
 
         /// <summary>
         ///
@@ -1001,7 +1028,7 @@
             dto_prj.MoneyTotal = Math.Round(defaultPrj.SumMoney, 0);
 
             dto_prj.BlockTimes = new List<ZyDto.SubmitPrjBlockTime>();
-            double maxHeight = 0;
+
             double startHeight = 0;
 
             if (defaultPrj.BlockTimes != null)
@@ -1023,7 +1050,13 @@
                         dto_item.Records = new List<SubmitPrjTime>();
                         foreach (var bt2 in bt.PointTimes)
                         {
-                            maxHeight = Math.Max(maxHeight, bt2.WaterLevelH);
+                            //if(maxHeight < bt2.WaterLevelH)
+                            //{
+                            //    maxHeight = bt2.WaterLevelH;
+                            //    //maxHeight = Math.Max(maxHeight, bt2.WaterLevelH);
+                            //    maxHeightTime = bt2.Time;
+                            //}
+
                             dto_item.Records.Add(new SubmitPrjTime(bt2));
                         }
                     }
@@ -1031,8 +1064,46 @@
                     dto_prj.BlockTimes.Add(dto_item);
                 }
             }
-            dto_prj.MaxWaterLevelH = maxHeight;
-            dto_prj.StartWaterLevelH = startHeight;
+            if (defaultPrj.MaxWaterLevelH <= 0)
+            {
+                double maxHeight = 0;
+                DateTime maxHeightTime = defaultPrj.StartTime;
+                if (defaultPrj.BlockTimes != null)
+                {
+                    foreach (var bt in defaultPrj.BlockTimes)
+                    {
+                        if (bt.OpenPumpIndexs == null)
+                            continue;
+
+                        if (bt.PointTimes != null)
+                        {
+                            foreach (var bt2 in bt.PointTimes)
+                            {
+                                if (maxHeight < bt2.WaterLevelH)
+                                {
+                                    maxHeight = bt2.WaterLevelH;
+                                    //maxHeight = Math.Max(maxHeight, bt2.WaterLevelH);
+                                    maxHeightTime = bt2.Time;
+                                }
+                            }
+                        }
+                    }
+                }
+                defaultPrj.MaxWaterLevelH = maxHeight;
+                defaultPrj.MaxWaterLevelTime = maxHeightTime;
+            }
+
+            if (defaultPrj.MaxWaterLevelTime > defaultPrj.StartTime)
+                dto_prj.MaxWaterLevelH = string.Format("{0:N2}  ({1})", Math.Round(defaultPrj.MaxWaterLevelH, 2),
+                    defaultPrj.MaxWaterLevelTime.ToString("HH:mm"));
+            else
+                dto_prj.MaxWaterLevelH = string.Format("{0:N2} ", Math.Round(defaultPrj.MaxWaterLevelH, 2));
+
+            //dto_prj.MaxWaterLevelH = defaultPrj.MaxWaterLevelH;
+            //dto_prj.MaxWaterLevelTime = defaultPrj.MaxWaterLevelTime;
+
+            dto_prj.StartWaterLevelH = string.Format("{0:N2}  ({1})", Math.Round(startHeight, 2),
+                defaultPrj.StartTime.ToString("HH:mm")); ;
             dto_prj.Switchs = new List<SubmitPrjSwitchInfo>();
             if (defaultPrj.PumpSwitchs != null)
             {
@@ -1054,6 +1125,5 @@
         }
 
         #endregion 鎹㈢畻鎴怐TO
-
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3