From cf68eebf7facf10774c4ca439acd13a4ff581106 Mon Sep 17 00:00:00 2001
From: tangxu <tangxu76880903>
Date: 星期一, 10 六月 2024 22:58:51 +0800
Subject: [PATCH] 增加开泵和关泵顺序设置

---
 WebApi/Controllers/ZyPrjController.cs |  244 ++++++++++++++++++++++++++++++++++--------------
 1 files changed, 171 insertions(+), 73 deletions(-)

diff --git a/WebApi/Controllers/ZyPrjController.cs b/WebApi/Controllers/ZyPrjController.cs
index 23f445e..f4bce48 100644
--- a/WebApi/Controllers/ZyPrjController.cs
+++ b/WebApi/Controllers/ZyPrjController.cs
@@ -15,9 +15,7 @@
 using System.Text;
 using System.Threading.Tasks;
 using System.Web;
-using System.Web.Http;
-using System.Web.UI.WebControls;
-using System.Web.UI.WebControls.WebParts;
+using System.Web.Http; 
 
 namespace IStation.ZyDto
 {
@@ -28,10 +26,13 @@
 
         public string StartTime { get; set; }
         public string EndTime { get; set; }
-        public int? StartOpenCount { get; set; } = -1;
+        //public int? StartOpenCount { get; set; } = -1;//宸蹭綔搴�
+
+        public string StartReservoirLevel { get; set; }//寮�濮嬫按搴撴按浣�(鍙┖):鍗曚綅m
+        public List<int> StartOpenPumpIndexArray { get; set; }//寮�濮嬫満娉靛紑鏈虹姸鎬�
 
         public string TotalFlowIn { get; set; }//鍙栨按鎬婚噺 (鍗曚綅 鍚�)
-        public string StartReservoirLevel { get; set; }//寮�濮嬫按搴撴按浣�(鍙┖):鍗曚綅m
+       
         public string MaxReservoirLevel { get; set; }//鏈�楂樻按搴撴按浣嶉檺鍒�(鍙┖):鍗曚綅m
         public string MaxReservoirLevelTime { get; set; }//鏈�楂樻按搴撴按浣嶉檺鍒舵椂闂�(鍙┖) 鏃堕棿鏍煎紡
 
@@ -56,6 +57,7 @@
         [HttpPost]
         public IStation.Dto.ApiResult Calc([FromBody] ZyPrjRequest request)
         {
+            LogHelper.Info(JsonHelper.Object2Json(request));
             if (request == null)
             {
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "request is null" };
@@ -91,81 +93,124 @@
                 IStation.LogHelper.Error(string.Format("ZyPrjRequest Time:{0}-{1} 鏃堕棿鑼冨洿閿欒,涓嶈兘瓒呰繃24灏忔椂", start_timme, end_timme));
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏃堕棿鑼冨洿閿欒,涓嶈兘瓒呰繃24灏忔椂" };
             }
-            if (request.TotalFlowIn == null)
-            {
-                if (string.IsNullOrEmpty(request.MaxReservoirLevel  ))
-                {
-                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璇疯緭鍏ュ彇姘存�婚噺鎴栨按浣嶈姹�" };
-                } 
-            }
- 
-
-
-            IStation.LogHelper.Info(string.Format("Zy Prj  Time:{0}-{1} ,StartOpenCount:{2} ",
-                start_timme, end_timme, request.StartOpenCount ));
 
             IStation.CalcModel.AnaRequest anaRequest = new AnaRequest();
             anaRequest.CalcOptType = (eCalcOptType)IStation.AnaGlobalParas.Setting.OptSortType;
             anaRequest.StartTime = start_timme;
             anaRequest.EndTime = end_timme;
             anaRequest.WaterLevels闀挎睙 = GetTide3Day(start_timme);
-            if(!string.IsNullOrEmpty(request.TotalFlowIn))
+
+            if (string.IsNullOrEmpty(request.TotalFlowIn))
+            {
+                if (string.IsNullOrEmpty(request.MaxReservoirLevel))
+                {
+                    IStation.LogHelper.Info(string.Format("Zy Prj  Time:{0}-{1} ,  璇疯緭鍏ュ彇姘存�婚噺鎴栨按浣嶈姹�",
+                start_timme, end_timme));
+                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璇疯緭鍏ュ彇姘存�婚噺鎴栨按浣嶈姹�" };
+                }
+            }
+            else
             {
                 double TotalFlowIn = 0;
-                if(!double.TryParse( request.TotalFlowIn,out TotalFlowIn))
-                { 
+                if (!double.TryParse(request.TotalFlowIn, out TotalFlowIn))
+                {
+                    IStation.LogHelper.Info(string.Format("Zy Prj  Time:{0}-{1} ,  娉ㄦ剰鍙栨按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬",
+                start_timme, end_timme));
                     return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "娉ㄦ剰鍙栨按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬" };
                 }
                 if (TotalFlowIn < 10000)
                 {
+                    IStation.LogHelper.Info(string.Format("Zy Prj  Time:{0}-{1} ,  娉ㄦ剰鍙栨按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬",
+                start_timme, end_timme));
                     return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "娉ㄦ剰鍙栨按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬" };
                 }
 
                 anaRequest.TotalFlowIn = TotalFlowIn;
             }
- 
-
-            if (request.StartOpenCount == null)
-            {
-                anaRequest.StartOpenCount = -1;
-            }
-            else
-            {
-                anaRequest.StartOpenCount = request.StartOpenCount.Value;
-            }
-
-            #region 闄堣姘村簱姘翠綅
-
-            if (!string.IsNullOrEmpty(request.StartReservoirLevel))
-            {
-                anaRequest.CurrentWaterBoxLevel = Convert.ToDouble(request.StartReservoirLevel);
-            }
-            else
-            {
-                /*      var tagDict = new Dictionary<string, string> { { "_0402010201030103006", "闄堣姘村簱姘翠綅" } };
-                     var input = new { search = "real", tablename = "闄堣鏅鸿兘璋冨害" };
-                     var tags = tagDict.Keys.ToList();
-                     var realScadaRecordList = ZyConnectHelper.GetRealScadaResultAsync(tags, input).GetAwaiter().GetResult();
-                      if (realScadaRecordList != null && realScadaRecordList.Count() > 0)
-                     {
-                         anaRequest.CurrentWaterBoxLevel = realScadaRecordList.Last().Value;
-                     }*/
-                anaRequest.CurrentWaterBoxLevel = ZyConnectHelper.GetRealReservoirWaterLevel();
-            }
-
-            #endregion 闄堣姘村簱姘翠綅
-
             if (!string.IsNullOrEmpty(request.MaxReservoirLevel))
+            {
                 anaRequest.MaxLimitWaterBoxLevel = Convert.ToDouble(request.MaxReservoirLevel);
+                IStation.DAL.WaterPredictRecord dal = new DAL.WaterPredictRecord();
+                var water_records = dal.GetByHourRangle(start_timme, end_timme);
+                LogHelper.Info(water_records.Count.ToString());
+                if (water_records == null)
+                {
+                    IStation.LogHelper.Info(string.Format("Zy Prj  Time:{0}-{1} ,  姘翠綅棰勬祴鏁版嵁涓虹┖,璇峰厛淇濇寔姘翠綅棰勬祴鏈嶅姟姝e父杩愯",
+                start_timme, end_timme));
+                    return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = "姘翠綅棰勬祴鏁版嵁涓虹┖,璇峰厛淇濇寔姘翠綅棰勬祴鏈嶅姟姝e父杩愯" };
+                }
+                var count = (end_timme - start_timme).TotalHours;
+                if (water_records.Count != count)
+                {
+                    IStation.LogHelper.Info(string.Format("Zy Prj  Time:{0}-{1} ,  棰勬祴鏁版嵁鑾峰彇澶辫触,鏁版嵁鏉℃棤娉曞尮閰�, 妫�鏌ユ槸鍚﹂娴嬫湇鍔′腑鏂�",
+                start_timme, end_timme));
+                    return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = "棰勬祴鏁版嵁鑾峰彇澶辫触,鏁版嵁鏉℃棤娉曞尮閰�, 妫�鏌ユ槸鍚﹂娴嬫湇鍔′腑鏂�" };
+                }
+
+                anaRequest.SpaceFlowOut = new List<double>();
+                foreach (var r in water_records)
+                {
+                    if (r.States == 0)
+                    {
+                        var error_info11 = string.Format("棰勬祴鏁版嵁寮傚父,鏃犳硶杩涜姘翠綅璁$畻:{0} {1},{2}", r.DayHour, r.LastPredictValue, r.Description);
+                        IStation.LogHelper.Info(string.Format("Zy Prj  Time:{0}-{1} , {2}}",
+                start_timme, end_timme, error_info11));
+                        return new IStation.Dto.ApiResult<string>()
+                        {
+                            Code = ApiResultCode.Error,
+                            Data = error_info11
+                        };
+                    }
+                    anaRequest.SpaceFlowOut.Add(r.LastPredictValue / 10000);
+                }
+            }
             if (!string.IsNullOrEmpty(request.MaxReservoirLevelTime))
                 anaRequest.MaxLimitWaterBoxTime = request.MaxReservoirLevelTime;
+
+            //寮�濮嬫椂鐨勫紑鏈虹姸鎬�
+            if (request.StartOpenPumpIndexArray == null)
+            {
+                IStation.LogHelper.Info(" 鏈缃紑濮嬫椂鏈烘车寮�鍋滅姸鎬� (Error: StartOpenPumpIndexArray is null)");
+                return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = "鏈缃紑濮嬫椂鏈烘车寮�鍋滅姸鎬� (Error: StartOpenPumpIndexArray is null)" };
+            }
+            anaRequest.IsKnownStartOpenPump = true;
+            anaRequest.StartOpenPumpIndexArray = request.StartOpenPumpIndexArray;
+
+
+            //闄堣姘村簱姘翠綅
+            if (string.IsNullOrEmpty(request.StartReservoirLevel))
+            {
+                IStation.LogHelper.Info(" 鏈缃紑濮嬫椂姘村簱姘翠綅 (Error: StartReservoirLevel is null)");
+                return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = "鏈缃紑濮嬫椂姘村簱姘翠綅 (Error: StartReservoirLevel is null) " };
+            }
+            anaRequest.CurrentWaterBoxLevel = Convert.ToDouble(request.StartReservoirLevel);
+            if (anaRequest.CurrentWaterBoxLevel < 2)
+            {
+                IStation.LogHelper.Info(string.Format("  璁剧疆寮�濮嬫椂姘村簱姘翠綅鐨勬暟鎹繃灏� (Error: StartReservoirLevel is {0}})",
+                    anaRequest.CurrentWaterBoxLevel));
+                return new IStation.Dto.ApiResult<string>()
+                {
+                    Code = ApiResultCode.Error,
+                    Data = string.Format("  璁剧疆寮�濮嬫椂姘村簱姘翠綅鐨勬暟鎹繃灏� (Error: StartReservoirLevel is {0}})",
+                    anaRequest.CurrentWaterBoxLevel)
+                };
+            }
+
+
 
             var calcHelper = new IStation.CalcPrjHelper();
             AnaPrj defaultPrj = null;
             string error_info = calcHelper.Calc(anaRequest, out defaultPrj);
+            LogHelper.Info(error_info);
             if (!string.IsNullOrEmpty(error_info) || defaultPrj == null)
             {
+                IStation.LogHelper.Info(string.Format("Zy Prj  Time:{0}-{1} ,  璁$畻閿欒, 鍘熷洜鏄�:{2} ,Request:::  ",
+                start_timme, end_timme, error_info) + JsonHelper.Object2Json(anaRequest));
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璁$畻閿欒, 鍘熷洜鏄�:" + error_info };
+            }
+            else
+            {
+                IStation.LogHelper.Info(string.Format("Zy Prj  Time:{0}-{1} ,  璁$畻鎴愬姛", start_timme, end_timme));
             }
 
             //淇濆瓨鏂规
@@ -211,23 +256,27 @@
             dto_prj.Items = new List<ZyDto.SubmitPrjItem>();
             foreach (var bt in defaultPrj.BlockTimes)
             {
-                if (bt.OpenPumpCount == 0)
+                if (bt.OpenPumpIndexs  == null)
                     continue;
                 ZyDto.SubmitPrjItem dto_item = new ZyDto.SubmitPrjItem();
                 dto_item.StartTime = bt.StartTime;
                 dto_item.EndTime = bt.EndTime;
-                dto_item.OpenPumpCount = bt.OpenPumpCount;
-                dto_item.OpenPumpIndexs = IStation.AnaGlobalParas.Setting.GetOpenPumpIndexArrays(bt.OpenPumpCount);
+                dto_item.OpenPumpCount = bt.OpenPumpIndexs.Count;
+                dto_item.OpenPumpIndexs = bt.OpenPumpIndexs;//
+
+                if (bt.PointTimes != null)
+                {
+                    dto_item.Records = new List<SubmitPrjTime>();
+                    foreach (var bt2 in bt.PointTimes)
+                    {
+                        dto_item.Records.Add(new SubmitPrjTime(bt2));
+                    }
+                }
+
+
                 dto_prj.Items.Add(dto_item);
             }
-            if (defaultPrj.PointTimes != null)
-            {
-                dto_prj.Records = new List<SubmitPrjTime>();
-                foreach (var bt in defaultPrj.PointTimes)
-                {
-                    dto_prj.Records.Add(new SubmitPrjTime(bt));
-                }
-            }
+
             return dto_prj;
         }
 
@@ -304,9 +353,12 @@
             IStation.Dto.ZyPrjAnaSetting dto_setting = new ZyPrjAnaSetting();
             dto_setting.MinOpenTimeMinute = model_setting.MinOpenTimeMinute;
             dto_setting.MinSwitchTimeMinute = model_setting.MinSwitchTimeMinute;
-            dto_setting.MaxPumpSwitchCount = model_setting.MaxPumpSwitchCountQ;
+            dto_setting.MaxPumpSwitchCount = model_setting.MaxPumpSwitchCount;
             dto_setting.OptSortType = model_setting.OptSortType;
-            dto_setting.OpenPumpIndexs = model_setting.OpenPumpIndexs;
+            dto_setting.OpenPumpIndexSequence = model_setting.OpenPumpIndexSequence;
+            dto_setting.ClosePumpIndexSequence = model_setting.ClosePumpIndexSequence;
+            dto_setting.SwitchPumpMinuteSpace = model_setting.SwitchPumpMinuteSpace;
+            dto_setting.OptimalPumpIndexSequence = model_setting.OptimalPumpIndexSequence;
 
             if (model_setting.SwitchPumpIgnoreTimes != null)
             {
@@ -385,8 +437,11 @@
             {
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈�澶у垏娉垫鏁� 璁剧疆杩囬暱" };
             }
-            model_setting.MaxPumpSwitchCountQ = dto.MaxPumpSwitchCount;
-
+            model_setting.MaxPumpSwitchCount = dto.MaxPumpSwitchCount;
+            if (dto.OptSortType >= 2)
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "OptSortType 鍙兘璁剧疆 0 鎴栬�� 1,  0浠h〃 鐢ㄧ數閲忔渶灏�  1浠h〃 鐢佃垂鏈�灏�" };
+            }
             model_setting.OptSortType = dto.OptSortType;
             if (dto.SwitchPumpIgnoreTimes != null)
             {
@@ -475,15 +530,15 @@
                     });
                 }
             }
-
-            if (dto.OpenPumpIndexs != null)
+ 
+            if (dto.OpenPumpIndexSequence != null)
             {
                 List<int> penPumpIndexs = new List<int>();
-                foreach (var ind in dto.OpenPumpIndexs)
+                foreach (var ind in dto.OpenPumpIndexSequence)
                 {
                     if (ind < 0 || ind > 5)
                     {
-                        return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈烘车寮�娉甸『搴忚缃弬鏁颁笉鍚堢悊" };
+                        return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "寮�娉甸『搴忚缃弬鏁颁笉鍚堢悊" };
                     }
                     else
                     {
@@ -492,10 +547,53 @@
                 }
                 if (penPumpIndexs.Distinct().Count() != 5)
                 {
-                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈烘车寮�娉甸『搴忚缃弬鏁颁笉鍚堢悊" };
+                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "寮�娉甸『搴忚缃弬鏁颁笉鍚堢悊" };
                 }
-                model_setting.OpenPumpIndexs = penPumpIndexs.ToArray();
+                model_setting.OpenPumpIndexSequence = penPumpIndexs.ToArray();
             }
+
+            if (dto.ClosePumpIndexSequence != null)
+            {
+                List<int> penPumpIndexs = new List<int>();
+                foreach (var ind in dto.ClosePumpIndexSequence)
+                {
+                    if (ind < 0 || ind > 5)
+                    {
+                        return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鍏虫车椤哄簭璁剧疆鍙傛暟涓嶅悎鐞�" };
+                    }
+                    else
+                    {
+                        penPumpIndexs.Add(ind);
+                    }
+                }
+                if (penPumpIndexs.Distinct().Count() != 5)
+                {
+                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鍏虫车椤哄簭璁剧疆鍙傛暟涓嶅悎鐞�" };
+                }
+                model_setting.ClosePumpIndexSequence = penPumpIndexs.ToArray();
+            }
+
+            if (dto.OptimalPumpIndexSequence != null)
+            {
+                List<int> penPumpIndexs = new List<int>();
+                foreach (var ind in dto.OptimalPumpIndexSequence)
+                {
+                    if (ind < 0 || ind > 5)
+                    {
+                        return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璋冨害娉典紭鍏堝害椤哄簭璁剧疆鍙傛暟涓嶅悎鐞�" };
+                    }
+                    else
+                    {
+                        penPumpIndexs.Add(ind);
+                    }
+                }
+                if (penPumpIndexs.Distinct().Count() != 5)
+                {
+                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璋冨害娉典紭鍏堝害椤哄簭璁剧疆鍙傛暟涓嶅悎鐞�" };
+                }
+                model_setting.OptimalPumpIndexSequence = penPumpIndexs.ToArray();
+            }
+
             return new IStation.Dto.ApiResult<bool>(IStation.Common.AnaSetting.SaveSetting(model_setting));
         }
 

--
Gitblit v1.9.3