From 9d2e93a197a0babf0761d7517f43d9d83143218b Mon Sep 17 00:00:00 2001 From: tangxu <tangxu76880903> Date: 星期四, 30 五月 2024 14:12:47 +0800 Subject: [PATCH] 众毅 添加 OptSortType 校核 --- WebApi/Controllers/ZyPrjController.cs | 246 ++++++++++++++++++++++++++++++------------------- 1 files changed, 150 insertions(+), 96 deletions(-) diff --git a/WebApi/Controllers/ZyPrjController.cs b/WebApi/Controllers/ZyPrjController.cs index 7bfbbfe..bb7de69 100644 --- a/WebApi/Controllers/ZyPrjController.cs +++ b/WebApi/Controllers/ZyPrjController.cs @@ -23,20 +23,22 @@ { public class ZyPrjRequest { - public ZyPrjRequest() { } + public ZyPrjRequest() + { } public string StartTime { get; set; } public string EndTime { get; set; } public int? StartOpenCount { get; set; } = -1; - public double? TotalFlowIn { get; set; }//鍙栨按鎬婚噺 (鍗曚綅 鍚�) + public string TotalFlowIn { get; set; }//鍙栨按鎬婚噺 (鍗曚綅 鍚�) public string StartReservoirLevel { get; set; }//寮�濮嬫按搴撴按浣�(鍙┖):鍗曚綅m public string MaxReservoirLevel { get; set; }//鏈�楂樻按搴撴按浣嶉檺鍒�(鍙┖):鍗曚綅m public string MaxReservoirLevelTime { get; set; }//鏈�楂樻按搴撴按浣嶉檺鍒舵椂闂�(鍙┖) 鏃堕棿鏍煎紡 public string IsSubmit { get; set; }//璁$畻瀹�,鏄惁鎺ㄩ�� - } + } } + namespace IStation.WebApi.Controllers { /// <summary> @@ -46,7 +48,7 @@ public class ZyPrjController : ApiController { /// <summary> - /// + /// /// </summary> /// <param name="request"></param> /// <returns></returns> @@ -54,7 +56,7 @@ [HttpPost] public IStation.Dto.ApiResult Calc([FromBody] ZyPrjRequest request) { - if (request == null ) + if (request == null) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "request is null" }; } @@ -69,7 +71,7 @@ DateTime start_timme = DateTime.Now; DateTime end_timme = DateTime.Now; - if(!DateTime.TryParse(request.StartTime,out start_timme)) + if (!DateTime.TryParse(request.StartTime, out start_timme)) { IStation.LogHelper.Error(string.Format("ZyPrjRequest Time:{0}-{1} StartTime is error format", start_timme, end_timme)); return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "StartTime is error format" }; @@ -79,37 +81,99 @@ IStation.LogHelper.Error(string.Format("ZyPrjRequest Time:{0}-{1} EndTime is error format", start_timme, end_timme)); return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "EndTime is error format" }; } - if(end_timme< start_timme.AddMinutes(60)) + if (end_timme < start_timme.AddMinutes(60)) { IStation.LogHelper.Error(string.Format("ZyPrjRequest Time:{0}-{1} 鏃堕棿鑼冨洿閿欒,闂撮殧杩囩煭", start_timme, end_timme)); return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏃堕棿鑼冨洿閿欒,闂撮殧杩囩煭" }; } - if(end_timme > start_timme.AddDays(1)) + if (end_timme > start_timme.AddDays(1)) { - 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) - { - return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鍙栨按鎬婚噺閿欒" }; - } - if (request.TotalFlowIn < 10000) - { - return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "娉ㄦ剰鍙栨按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬" }; + IStation.LogHelper.Error(string.Format("ZyPrjRequest Time:{0}-{1} 鏃堕棿鑼冨洿閿欒,涓嶈兘瓒呰繃24灏忔椂", start_timme, end_timme)); + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏃堕棿鑼冨洿閿欒,涓嶈兘瓒呰繃24灏忔椂" }; } - IStation.LogHelper.Info(string.Format("Zy Prj Time:{0}-{1} ,StartOpenCount:{2}, TotalFlowIn:{3}", - start_timme, end_timme, request.StartOpenCount, request.TotalFlowIn)); + - IStation.CalcModel.AnaRequest anaRequest = new AnaRequest(); - anaRequest.CalcOptType = (eCalcOptType) IStation.AnaGlobalParas.Setting.OptSortType; + + + + 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); - - anaRequest.TotalFlow鍙栨按鎬婚噺 = request.TotalFlowIn; - if(request.StartOpenCount == null) + + 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)) + { + 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 (!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 ); + 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.StartOpenCount == null) { anaRequest.StartOpenCount = -1; } @@ -117,35 +181,33 @@ { 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; - } - } - #endregion + anaRequest.CurrentWaterBoxLevel = ZyConnectHelper.GetRealReservoirWaterLevel(); + } - if (!string.IsNullOrEmpty(request.MaxReservoirLevel)) - anaRequest.MaxLimitWaterBoxLevel = Convert.ToDouble(request.MaxReservoirLevel); - if (!string.IsNullOrEmpty(request.MaxReservoirLevelTime)) - anaRequest.MaxLimitWaterBoxTime = request.MaxReservoirLevelTime; + + + var calcHelper = new IStation.CalcPrjHelper(); AnaPrj defaultPrj = null; - string error_info = calcHelper.Calc(anaRequest, out defaultPrj); + string error_info = calcHelper.Calc(anaRequest, out defaultPrj); if (!string.IsNullOrEmpty(error_info) || defaultPrj == null) { - return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璁$畻閿欒, 鍘熷洜鏄�:"+ error_info }; + 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 )); } //淇濆瓨鏂规 @@ -154,19 +216,22 @@ var dto_prj = ToPrjDto(defaultPrj); #region 鎺ㄩ�� + if (!string.IsNullOrEmpty(request.IsSubmit) && Convert.ToBoolean(request.IsSubmit)) { - Task.Run(() => { + Task.Run(() => + { _ = ZyProjectHelper.SubmitPrj(defaultPrj); - }); + }); } - #endregion + #endregion 鎺ㄩ�� - return new IStation.Dto.ApiResult< IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success }; + return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success }; } #region 鎹㈢畻鎴怐TO + private IStation.ZyDto.SubmitPrj ToPrjDto(AnaPrj defaultPrj) { IStation.ZyDto.SubmitPrj dto_prj = new ZyDto.SubmitPrj(); @@ -197,17 +262,18 @@ dto_item.OpenPumpIndexs = IStation.AnaGlobalParas.Setting.GetOpenPumpIndexArrays(bt.OpenPumpCount); dto_prj.Items.Add(dto_item); } - if(defaultPrj.PointTimes != null) + if (defaultPrj.PointTimes != null) { dto_prj.Records = new List<SubmitPrjTime>(); - foreach(var bt in defaultPrj.PointTimes) + foreach (var bt in defaultPrj.PointTimes) { dto_prj.Records.Add(new SubmitPrjTime(bt)); } } - return dto_prj; + return dto_prj; } - #endregion + + #endregion 鎹㈢畻鎴怐TO /// <summary> /// 鑾峰彇鏌愪竴澶�,鏈�杩戜竴鏉� @@ -218,7 +284,7 @@ [HttpGet] public IStation.Dto.ApiResult GetHistoryByDay(string day) { - if (string.IsNullOrEmpty(day )) + if (string.IsNullOrEmpty(day)) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鍏ュ弬day 涓虹┖" }; } @@ -230,18 +296,16 @@ IStation.CalcModel.AnaRequestBase requestBase = null; var prj = Common.HistoryAnaPrjFileHelper.GetByDay(d, out requestBase); - if(prj != null) + if (prj != null) { var dto_prj = ToPrjDto(prj); return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success }; } else { - return new IStation.Dto.ApiResult() { Code = ApiResultCode.Alert, Message="鏈壘鍒伴」鐩�" }; + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Alert, Message = "鏈壘鍒伴」鐩�" }; } } - - /// <summary> /// 鑾峰彇鏈�杩戜竴鏉� @@ -250,8 +314,8 @@ /// <returns></returns> [Route("GetLastHistoryRecord")] [HttpGet] - public IStation.Dto.ApiResult GetLastHistoryRecord( ) - { + public IStation.Dto.ApiResult GetLastHistoryRecord() + { var dal = new IStation.DAL.AnaProject(); var record = dal.GetLastRecord(); if (record == null) @@ -270,10 +334,9 @@ } } - /// <summary> - /// - /// </summary> + /// + /// </summary> /// <returns></returns> [Route("GetSetting")] [HttpGet] @@ -290,7 +353,7 @@ if (model_setting.SwitchPumpIgnoreTimes != null) { dto_setting.SwitchPumpIgnoreTimes = new List<ZyPrjAnaSetting.TimeRangeZy>(); - foreach(var m in model_setting.SwitchPumpIgnoreTimes) + foreach (var m in model_setting.SwitchPumpIgnoreTimes) { dto_setting.SwitchPumpIgnoreTimes.Add(new ZyPrjAnaSetting.TimeRangeZy() { @@ -317,16 +380,12 @@ }); } } - - - - return new IStation.Dto.ApiResult<IStation.Dto.ZyPrjAnaSetting>(dto_setting); } /// <summary> - /// + /// /// </summary> /// <param name="ana"></param> /// <returns></returns> @@ -339,7 +398,7 @@ return new IStation.Dto.ApiResult<bool>(false); } var model_setting = IStation.AnaGlobalParas.Setting; - + IStation.LogHelper.Info("ZyPrj SaveSetting"); if (dto.MinOpenTimeMinute < 5) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈�灏戝紑娉垫椂闂� 璁剧疆杩囧皯" }; @@ -360,8 +419,6 @@ } model_setting.MinSwitchTimeMinute = dto.MinSwitchTimeMinute; - - if (dto.MaxPumpSwitchCount < 1) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈�澶у垏娉垫鏁� 璁剧疆杩囧皯" }; @@ -371,15 +428,19 @@ return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈�澶у垏娉垫鏁� 璁剧疆杩囬暱" }; } model_setting.MaxPumpSwitchCountQ = 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) { model_setting.SwitchPumpIgnoreTimes = new List<CalcModel.AnaSetting.TimeRange>(); foreach (var m in dto.SwitchPumpIgnoreTimes) { + if (m.StartHour == 0 && m.EndHour == 0 && m.StartMinute == 0 && m.EndMinute == 0) + continue; if (m.StartHour < 0 || m.StartHour > 24) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; @@ -396,7 +457,7 @@ { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; } - if(m.StartHour > m.EndHour) + if (m.StartHour > m.EndHour) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; } @@ -417,7 +478,6 @@ }); } } - if (dto.OpenPumpTimes != null) { @@ -461,19 +521,22 @@ }); } } - - - if( dto.OpenPumpIndexs != null && dto.OpenPumpIndexs.Count() == 5) + + if (dto.OpenPumpIndexs != null) { List<int> penPumpIndexs = new List<int>(); - foreach(var ind in dto.OpenPumpIndexs) + foreach (var ind in dto.OpenPumpIndexs) { - if(ind<0 || ind > 5) + if (ind < 0 || ind > 5) { - return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈烘车寮�娉甸『搴忚缃弬鏁颁笉鍚堢悊" }; + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈烘车寮�娉甸『搴忚缃弬鏁颁笉鍚堢悊" }; + } + else + { + penPumpIndexs.Add(ind); } } - if(penPumpIndexs.Distinct().Count() != 5) + if (penPumpIndexs.Distinct().Count() != 5) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈烘车寮�娉甸『搴忚缃弬鏁颁笉鍚堢悊" }; } @@ -482,11 +545,9 @@ return new IStation.Dto.ApiResult<bool>(IStation.Common.AnaSetting.SaveSetting(model_setting)); } + private Model.eTideSouce _tideSouce = Model.eTideSouce.Book; - - - Model.eTideSouce _tideSouce = Model.eTideSouce.Book; - private List<Model.TimeWaterLevel> GetTide3Day(DateTime calc_day ) + private List<Model.TimeWaterLevel> GetTide3Day(DateTime calc_day) { DateTime _rangDay1, _rangDay2, _rangDay3; string error1, error2, error3; @@ -510,33 +571,26 @@ _rangDay3 = calc_day.AddDays(1); } waterLevels闀挎睙1 = TideHelper.GetByDay(_tideSouce, _rangDay1, out error1); - waterLevels闀挎睙2 = TideHelper.GetByDay(_tideSouce, _rangDay2, out error2); + waterLevels闀挎睙2 = TideHelper.GetByDay(_tideSouce, _rangDay2, out error2); waterLevels闀挎睙3 = TideHelper.GetByDay(_tideSouce, _rangDay3, out error3); - - - List<Model.TimeWaterLevel> timeValues = new List<Model.TimeWaterLevel>(); if (waterLevels闀挎睙1 != null) { timeValues.AddRange(waterLevels闀挎睙1); } - + if (waterLevels闀挎睙2 != null) { timeValues.AddRange(waterLevels闀挎睙2); } - + if (waterLevels闀挎睙3 != null) { timeValues.AddRange(waterLevels闀挎睙3); } - - - - return timeValues; } } -} +} \ No newline at end of file -- Gitblit v1.9.3