From 39579aa528747af7ca7b17b04453095e2a27a009 Mon Sep 17 00:00:00 2001 From: tangxu <tangxu76880903> Date: 星期六, 04 五月 2024 17:48:09 +0800 Subject: [PATCH] 添加水量预测API接口 --- WebApi/Controllers/ZyPrjController.cs | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 152 insertions(+), 23 deletions(-) diff --git a/WebApi/Controllers/ZyPrjController.cs b/WebApi/Controllers/ZyPrjController.cs index fc4d818..7bfbbfe 100644 --- a/WebApi/Controllers/ZyPrjController.cs +++ b/WebApi/Controllers/ZyPrjController.cs @@ -10,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; @@ -23,13 +24,18 @@ public class ZyPrjRequest { public ZyPrjRequest() { } - + public string StartTime { get; set; } public string EndTime { get; set; } - public int StartOpenCount { get; set; } = -1; + public int? StartOpenCount { get; set; } = -1; public double? 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 { @@ -96,13 +102,44 @@ start_timme, end_timme, request.StartOpenCount, request.TotalFlowIn)); IStation.CalcModel.AnaRequest anaRequest = new AnaRequest(); - anaRequest.CalcOptType = eCalcOptType.鐢佃垂; + 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; - + + 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; + } + } + #endregion + + 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); @@ -111,8 +148,27 @@ return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璁$畻閿欒, 鍘熷洜鏄�:"+ error_info }; } + //淇濆瓨鏂规 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)) @@ -138,26 +194,80 @@ 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(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; + } + #endregion - //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); - // } - //} + /// <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="鏈壘鍒伴」鐩�" }; + } + } - return new IStation.Dto.ApiResult< IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success }; + + /// <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 = "鏈壘鍒伴」鐩�" }; + } } @@ -175,7 +285,9 @@ dto_setting.MinSwitchTimeMinute = model_setting.MinSwitchTimeMinute; dto_setting.MaxPumpSwitchCount = model_setting.MaxPumpSwitchCountQ; dto_setting.OptSortType = model_setting.OptSortType; - if(model_setting.SwitchPumpIgnoreTimes != null) + 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) @@ -349,7 +461,24 @@ }); } } - + + + if( dto.OpenPumpIndexs != null && dto.OpenPumpIndexs.Count() == 5) + { + 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 = "鏈烘车寮�娉甸『搴忚缃弬鏁颁笉鍚堢悊" }; + } + } + 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)); } -- Gitblit v1.9.3