From 14725e33b8edeaa2235e01792c0440d79a0d9b83 Mon Sep 17 00:00:00 2001 From: tangxu <tangxu76880903> Date: 星期三, 29 五月 2024 14:37:18 +0800 Subject: [PATCH] 更正 --- WebApi/Controllers/ZyPrjController.cs | 283 ++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 200 insertions(+), 83 deletions(-) diff --git a/WebApi/Controllers/ZyPrjController.cs b/WebApi/Controllers/ZyPrjController.cs index 3067513..23f445e 100644 --- a/WebApi/Controllers/ZyPrjController.cs +++ b/WebApi/Controllers/ZyPrjController.cs @@ -23,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> @@ -41,7 +48,7 @@ public class ZyPrjController : ApiController { /// <summary> - /// + /// /// </summary> /// <param name="request"></param> /// <returns></returns> @@ -49,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" }; } @@ -64,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" }; @@ -74,46 +81,117 @@ 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 (string.IsNullOrEmpty(request.MaxReservoirLevel )) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璇疯緭鍏ュ彇姘存�婚噺鎴栨按浣嶈姹�" }; + } } - if (request.TotalFlowIn < 10000) - { - return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "娉ㄦ剰鍙栨按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬" }; - } + - 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.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); - 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 }; + double TotalFlowIn = 0; + if(!double.TryParse( request.TotalFlowIn,out TotalFlowIn)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "娉ㄦ剰鍙栨按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬" }; + } + if (TotalFlowIn < 10000) + { + 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); + 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); + if (!string.IsNullOrEmpty(error_info) || defaultPrj == null) + { + 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)) @@ -142,29 +220,81 @@ 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; } + #endregion 鎹㈢畻鎴怐TO /// <summary> - /// - /// </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] @@ -181,7 +311,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() { @@ -208,16 +338,12 @@ }); } } - - - - return new IStation.Dto.ApiResult<IStation.Dto.ZyPrjAnaSetting>(dto_setting); } /// <summary> - /// + /// /// </summary> /// <param name="ana"></param> /// <returns></returns> @@ -230,7 +356,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 = "鏈�灏戝紑娉垫椂闂� 璁剧疆杩囧皯" }; @@ -251,8 +377,6 @@ } model_setting.MinSwitchTimeMinute = dto.MinSwitchTimeMinute; - - if (dto.MaxPumpSwitchCount < 1) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鏈�澶у垏娉垫鏁� 璁剧疆杩囧皯" }; @@ -263,14 +387,14 @@ } model_setting.MaxPumpSwitchCountQ = dto.MaxPumpSwitchCount; - - 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 = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; @@ -287,7 +411,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 = "涓嶈鍒囨车鏃堕棿 鏃堕棿鑼冨洿璁剧疆涓嶅悎鐞�" }; } @@ -308,7 +432,6 @@ }); } } - if (dto.OpenPumpTimes != null) { @@ -352,19 +475,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 = "鏈烘车寮�娉甸『搴忚缃弬鏁颁笉鍚堢悊" }; } @@ -373,11 +499,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; @@ -401,33 +525,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