From 18a1a6faf82b1ad00d27f6fc7f5734c34aea32df Mon Sep 17 00:00:00 2001 From: tangxu <tangxu76880903> Date: 星期五, 07 六月 2024 15:30:23 +0800 Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/IStation/shys/ChEqCalc.V1.3 --- WebApi/Controllers/ZyPrjController.cs | 498 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 435 insertions(+), 63 deletions(-) diff --git a/WebApi/Controllers/ZyPrjController.cs b/WebApi/Controllers/ZyPrjController.cs index 33995f3..6cc8eae 100644 --- a/WebApi/Controllers/ZyPrjController.cs +++ b/WebApi/Controllers/ZyPrjController.cs @@ -1,4 +1,5 @@ -锘縰sing IStation.CalcModel; +锘縰sing Antlr.Runtime.Tree; +using IStation.CalcModel; using IStation.Common; using IStation.Dto; using IStation.Model; @@ -9,6 +10,7 @@ using System.Linq; using System.Net; using System.Net.Http; +using System.Runtime.CompilerServices; using System.Security.Permissions; using System.Text; using System.Threading.Tasks; @@ -21,15 +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 int? StartOpenCount { get; set; } = -1; + 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> @@ -39,7 +48,7 @@ public class ZyPrjController : ApiController { /// <summary> - /// + /// /// </summary> /// <param name="request"></param> /// <returns></returns> @@ -47,7 +56,8 @@ [HttpPost] public IStation.Dto.ApiResult Calc([FromBody] ZyPrjRequest request) { - if (request == null ) + LogHelper.Info(JsonHelper.Object2Json(request)); + if (request == null) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "request is null" }; } @@ -62,7 +72,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" }; @@ -72,43 +82,148 @@ 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灏忔椂" }; + 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.CalcModel.AnaRequest anaRequest = new AnaRequest(); - anaRequest.CalcOptType = eCalcOptType.鐢佃垂; + + 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.StartOpenCount = request.StartOpenCount; - anaRequest.TotalFlow鍙栨按鎬婚噺 = request.TotalFlowIn; - - var calcHelper = new IStation.CalcPrjHelper(); - AnaPrj defaultPrj = null; - string error_info = calcHelper.Calc(anaRequest, out defaultPrj); - if (!string.IsNullOrEmpty(error_info) || defaultPrj == null) + + if (string.IsNullOrEmpty(request.TotalFlowIn)) { - return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璁$畻閿欒, 鍘熷洜鏄�:"+ error_info }; + 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); + 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.StartOpenCount == null) + { + anaRequest.StartOpenCount = -1; + } + else + { + anaRequest.StartOpenCount = request.StartOpenCount.Value; } + //闄堣姘村簱姘翠綅 + if (!string.IsNullOrEmpty(request.StartReservoirLevel)) + { + anaRequest.CurrentWaterBoxLevel = Convert.ToDouble(request.StartReservoirLevel); + } + else + { + anaRequest.CurrentWaterBoxLevel = ZyConnectHelper.GetRealReservoirWaterLevel(); + } + + 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)); + } + + //淇濆瓨鏂规 var ret = Common.HistoryAnaPrjFileHelper.SavePrj(IStation.AnaGlobalParas.Setting, anaRequest, defaultPrj); + var dto_prj = ToPrjDto(defaultPrj); + + #region 鎺ㄩ�� + + if (!string.IsNullOrEmpty(request.IsSubmit) && Convert.ToBoolean(request.IsSubmit)) + { + Task.Run(() => + { + _ = ZyProjectHelper.SubmitPrj(defaultPrj); + }); + } + + #endregion 鎺ㄩ�� + + 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(); if (string.IsNullOrEmpty(defaultPrj.ID)) @@ -134,30 +249,294 @@ dto_item.StartTime = bt.StartTime; dto_item.EndTime = bt.EndTime; dto_item.OpenPumpCount = bt.OpenPumpCount; - dto_item.OpenPumpIndexs = CalcPrjHelper.GetOpenPumpIndexs(bt.OpenPumpCount); + dto_item.OpenPumpIndexs = IStation.AnaGlobalParas.Setting.GetOpenPumpIndexArrays(bt.OpenPumpCount); dto_prj.Items.Add(dto_item); } - - //if (request.isSubmit) - //{ - // string error = await ZyConnectHelper.SubmitPrj(request.prj);//, (id) => { IStation.LogHelper.Info("SavePrj success id=" + id); }, (info) => { IStation.LogHelper.Info("SavePrj failse info:" + info); });//.Result; - // if (!string.IsNullOrEmpty(error)) - // { - // IStation.LogHelper.Info("Submit prj finish (fail) day:" + request.requestBase.StartTime + ",error:" + error); - // return new IStation.Dto.ApiResult<string>(error) { Code = ApiResultCode.Error }; - // } - // else - // { - // IStation.LogHelper.Info("Submit prj finish (success) day:" + request.requestBase.StartTime); - // } - //} - - - return new IStation.Dto.ApiResult< IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success }; + 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; } - Model.eTideSouce _tideSouce = Model.eTideSouce.Book; - private List<Model.TimeWaterLevel> GetTide3Day(DateTime calc_day ) + #endregion 鎹㈢畻鎴怐TO + + /// <summary> + /// 鑾峰彇鏌愪竴澶�,鏈�杩戜竴鏉� + /// </summary> + /// <param name="day"></param> + /// <returns></returns> + [Route("GetHistoryByDay")] + [HttpGet] + public IStation.Dto.ApiResult GetHistoryByDay(string day) + { + if (string.IsNullOrEmpty(day)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鍏ュ弬day 涓虹┖" }; + } + DateTime d; + if (!DateTime.TryParse(day, out d)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; + } + IStation.CalcModel.AnaRequestBase requestBase = null; + var prj = Common.HistoryAnaPrjFileHelper.GetByDay(d, out requestBase); + + 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 = "鏈壘鍒伴」鐩�" }; + } + } + + /// <summary> + /// 鑾峰彇鏈�杩戜竴鏉� + /// </summary> + /// <param name="day"></param> + /// <returns></returns> + [Route("GetLastHistoryRecord")] + [HttpGet] + public IStation.Dto.ApiResult GetLastHistoryRecord() + { + var dal = new IStation.DAL.AnaProject(); + var record = dal.GetLastRecord(); + if (record == 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); + return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success }; + } + else + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Alert, Message = "鏈壘鍒伴」鐩�" }; + } + } + + /// <summary> + /// + /// </summary> + /// <returns></returns> + [Route("GetSetting")] + [HttpGet] + public IStation.Dto.ApiResult GetSetting() + { + var model_setting = IStation.AnaGlobalParas.Setting; + 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.OptSortType = model_setting.OptSortType; + dto_setting.OpenPumpIndexs = model_setting.OpenPumpIndexs; + + if (model_setting.SwitchPumpIgnoreTimes != null) + { + dto_setting.SwitchPumpIgnoreTimes = new List<ZyPrjAnaSetting.TimeRangeZy>(); + foreach (var m in model_setting.SwitchPumpIgnoreTimes) + { + dto_setting.SwitchPumpIgnoreTimes.Add(new ZyPrjAnaSetting.TimeRangeZy() + { + IsUse = m.IsUse, + StartHour = m.StartHour, + StartMinute = m.StartMinute, + EndHour = m.EndHour, + EndMinute = m.EndMinute, + }); + } + } + if (model_setting.OpenPumpTimes != null) + { + dto_setting.OpenPumpTimes = new List<ZyPrjAnaSetting.TimeRangeZy>(); + foreach (var m in model_setting.OpenPumpTimes) + { + dto_setting.OpenPumpTimes.Add(new ZyPrjAnaSetting.TimeRangeZy() + { + IsUse = m.IsUse, + StartHour = m.StartHour, + StartMinute = m.StartMinute, + EndHour = m.EndHour, + EndMinute = m.EndMinute, + }); + } + } + + return new IStation.Dto.ApiResult<IStation.Dto.ZyPrjAnaSetting>(dto_setting); + } + + /// <summary> + /// + /// </summary> + /// <param name="ana"></param> + /// <returns></returns> + [Route("SaveSetting")] + [HttpPost] + public IStation.Dto.ApiResult SaveSetting([FromBody] IStation.Dto.ZyPrjAnaSetting dto) + { + if (dto == null) + { + 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 = "鏈�灏戝紑娉垫椂闂� 璁剧疆杩囧皯" }; + } + if (dto.MinOpenTimeMinute > 120) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈�灏戝紑娉垫椂闂� 璁剧疆杩囬暱" }; + } + model_setting.MinOpenTimeMinute = dto.MinOpenTimeMinute; + + if (dto.MinSwitchTimeMinute < 5) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈�灏戝垏娉垫椂闂� 璁剧疆杩囧皯" }; + } + if (dto.MinSwitchTimeMinute > 120) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈�灏戝垏娉垫椂闂� 璁剧疆杩囬暱" }; + } + model_setting.MinSwitchTimeMinute = dto.MinSwitchTimeMinute; + + if (dto.MaxPumpSwitchCount < 1) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈�澶у垏娉垫鏁� 璁剧疆杩囧皯" }; + } + if (dto.MaxPumpSwitchCount > 10) + { + 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 = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + if (m.EndHour < 0 || m.EndHour > 24) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + if (m.StartMinute < 0 || m.StartMinute > 60) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + if (m.EndMinute < 0 || m.EndMinute > 60) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + if (m.StartHour > m.EndHour) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + if (m.StartHour == m.EndHour) + { + if (m.StartMinute > m.EndMinute) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + } + model_setting.SwitchPumpIgnoreTimes.Add(new CalcModel.AnaSetting.TimeRange() + { + IsUse = m.IsUse, + StartHour = m.StartHour, + StartMinute = m.StartMinute, + EndHour = m.EndHour, + EndMinute = m.EndMinute, + }); + } + } + + if (dto.OpenPumpTimes != null) + { + model_setting.OpenPumpTimes = new List<CalcModel.AnaSetting.TimeRange>(); + foreach (var m in dto.OpenPumpTimes) + { + if (m.StartHour < 0 || m.StartHour > 24) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "寮�娉垫椂闂� 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + if (m.EndHour < 0 || m.EndHour > 24) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "寮�娉垫椂闂� 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + if (m.StartMinute < 0 || m.StartMinute > 60) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "寮�娉垫椂闂� 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + if (m.EndMinute < 0 || m.EndMinute > 60) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "寮�娉垫椂闂� 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + if (m.StartHour > m.EndHour) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "寮�娉垫椂闂� 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + if (m.StartHour == m.EndHour) + { + if (m.StartMinute > m.EndMinute) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "寮�娉垫椂闂� 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; + } + } + model_setting.OpenPumpTimes.Add(new CalcModel.AnaSetting.TimeRange() + { + IsUse = m.IsUse, + StartHour = m.StartHour, + StartMinute = m.StartMinute, + EndHour = m.EndHour, + EndMinute = m.EndMinute, + }); + } + } + + if (dto.OpenPumpIndexs != null) + { + List<int> penPumpIndexs = new List<int>(); + foreach (var ind in dto.OpenPumpIndexs) + { + 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.OpenPumpIndexs = penPumpIndexs.ToArray(); + } + return new IStation.Dto.ApiResult<bool>(IStation.Common.AnaSetting.SaveSetting(model_setting)); + } + + private Model.eTideSouce _tideSouce = Model.eTideSouce.Book; + + private List<Model.TimeWaterLevel> GetTide3Day(DateTime calc_day) { DateTime _rangDay1, _rangDay2, _rangDay3; string error1, error2, error3; @@ -181,33 +560,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