From 54d6c9937e34066e357c3212477914ecef1370b6 Mon Sep 17 00:00:00 2001 From: tangxu <tangxu76880903> Date: 星期二, 08 十月 2024 13:02:41 +0800 Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/IStation/shys/ChEqCalc.V1.3 --- WebApi/Controllers/AnaPrjController.cs | 445 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 394 insertions(+), 51 deletions(-) diff --git a/WebApi/Controllers/AnaPrjController.cs b/WebApi/Controllers/AnaPrjController.cs index eb81f0f..c72968e 100644 --- a/WebApi/Controllers/AnaPrjController.cs +++ b/WebApi/Controllers/AnaPrjController.cs @@ -1,6 +1,7 @@ 锘縰sing IStation.CalcModel; using IStation.Common; using IStation.Dto; +using IStation.ZyDto; using System; using System.Collections.Generic; using System.IO; @@ -12,8 +13,6 @@ using System.Threading.Tasks; using System.Web; using System.Web.Http; -using System.Web.UI.WebControls; -using System.Web.UI.WebControls.WebParts; namespace IStation.WebApi.Controllers { @@ -24,28 +23,41 @@ public class AnaPrjController : ApiController { /// <summary> - /// + /// /// </summary> /// <param name="day"></param> /// <returns></returns> [Route("Debug")] [HttpGet] public IStation.Dto.ApiResult Debug(string info) - { - IStation.LogHelper.Info("debug:"+ info); - + { + IStation.LogHelper.Info("debug:" + info); - return new IStation.Dto.ApiResult<string >("ok"); + //IStation.CalcModel.AnaPrj entity = new IStation.CalcModel.AnaPrj(); + //entity.ID = "123"; + //entity.StartTime = DateTime.Now; + //entity.EndTime = DateTime.Now; + //entity.Name = "232"; + + //IStation.CalcModel.AnaRequest ana_request = new AnaRequest(); + //ana_request.TotalFlow鍙栨按鎬婚噺 = 102; + + //var dal = new IStation.DAL.AnaProject(); + //dal.Insert(entity, ana_request); + + var dal = new IStation.DAL.AnaProject(); + var aa = dal.GetLastRecord(); + return new IStation.Dto.ApiResult<string>("ok"); } /// <summary> - /// + /// /// </summary> /// <param name="day"></param> /// <returns></returns> - [Route("GetPrj")] + [Route("GetDefaultPrjByStartDay")] [HttpGet] - public IStation.Dto.ApiResult GetPrj(string day) + public IStation.Dto.ApiResult GetDefaultPrjByStartDay(string day) { if (day == null) { @@ -56,16 +68,333 @@ { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; } - - var prj = Common.HistoryAnaPrjFileHelper.GetPrj(d); - + IStation.CalcModel.AnaRequestBase requestBase = null; + var prj = Common.HistoryAnaPrjFileHelper.GetByStartDay(d, out requestBase); return new IStation.Dto.ApiResult<IStation.CalcModel.AnaPrj>(prj); } - - /// <summary> - /// + /// 杩滅▼璁$畻, 鐢ㄤ簬璋冭瘯浼楁瘏 + /// </summary> + /// <param name="request"></param> + /// <returns></returns> + [Route("Calc")] + [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" }; + } + if (string.IsNullOrEmpty(request.StartTime)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "StartTime is null" }; + } + if (string.IsNullOrEmpty(request.EndTime)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "EndTime is null" }; + } + + DateTime start_timme = DateTime.Now; + DateTime end_timme = DateTime.Now; + 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" }; + } + if (!DateTime.TryParse(request.EndTime, out end_timme)) + { + 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)) + { + 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)) + { + 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.CalcModel.AnaRequest anaRequest = new AnaRequest(); + anaRequest.CalcOptType = (eCalcOptType)IStation.AnaGlobalParas.Setting.OptSortType; + anaRequest.StartTime = start_timme; + anaRequest.EndTime = end_timme; + anaRequest.WaterLevels闀挎睙 = ZyPrjController.GetTide3Day(Model.eTideSouce.Book, start_timme); + + #region 鍙栨按鎬婚噺 + + if (!string.IsNullOrEmpty(request.TotalFlowIn)) + { + 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; + } + + #endregion 鍙栨按鎬婚噺 + + #region 姘翠綅瑕佹眰 + + if (!string.IsNullOrEmpty(request.MaxReservoirLevelTime)) + { + anaRequest.MaxReservoirLevelTime = request.MaxReservoirLevelTime; + } + + if (!string.IsNullOrEmpty(request.MaxReservoirLevel)) + { + double MaxReservoirLevel = 0; + if (!double.TryParse(request.MaxReservoirLevel, out MaxReservoirLevel)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璇疯緭鍏ュ悎鐞嗙殑姘翠綅瑕佹眰鍊�" }; + } + if (MaxReservoirLevel < 1 || MaxReservoirLevel > 10) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璇疯緭鍏ュ悎鐞嗙殑姘翠綅瑕佹眰鍊�" }; + } + anaRequest.MaxReservoirLevel = MaxReservoirLevel; + } + else + { + if (string.IsNullOrEmpty(request.TotalFlowIn)) + { + IStation.LogHelper.Info(string.Format("Zy Prj Time:{0}-{1} , 璇疯緭鍏ュ彇姘存�婚噺鎴栨按浣嶈姹�", + start_timme, end_timme)); + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "璇疯緭鍏ュ彇姘存�婚噺鎴栨按浣嶈姹�" }; + } + } + + #endregion 姘翠綅瑕佹眰 + + #region 渚涙按閲� + + if (string.IsNullOrEmpty(request.TotalFlowOut)) + {//鐢ㄩ娴嬪�� + #region 鐢ㄩ娴嬪�� + + anaRequest.PerHourFlowOut = new List<double>(); + 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 = "棰勬祴鏁版嵁鑾峰彇澶辫触,鏁版嵁鏉℃棤娉曞尮閰�, 妫�鏌ユ槸鍚﹂娴嬫湇鍔′腑鏂�" }; + } + + 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.PerHourFlowOut.Add(r.LastPredictValue);//璁$畻涓敤鍚� + } + + #endregion 鐢ㄩ娴嬪�� + } + else + { + double TotalFlowOut = 0; + if (!double.TryParse(request.TotalFlowOut, out TotalFlowOut)) + { + IStation.LogHelper.Info(string.Format("Zy Prj Time:{0}-{1} , 娉ㄦ剰鍙栨按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬", + start_timme, end_timme)); + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "娉ㄦ剰渚涙按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬" }; + } + if (TotalFlowOut < 10000) + { + IStation.LogHelper.Info(string.Format("Zy Prj Time:{0}-{1} , 娉ㄦ剰鍙栨按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬", + start_timme, end_timme)); + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "娉ㄦ剰渚涙按鎬婚噺鍗曚綅鏄惃,褰撳墠鍙傛暟鍙傛暟杩囧皬" }; + } + //TotalFlowOut = TotalFlowOut ;//璁$畻涓敤鍚� + List<double> list = new List<double>(); + var count = (end_timme - start_timme).TotalHours; + for (var d = start_timme; d <= end_timme; d = d.AddHours(1)) + { + list.Add(TotalFlowOut / count); + } + anaRequest.PerHourFlowOut = list; + } + + #endregion 渚涙按閲� + + //寮�濮嬫椂鐨勫紑鏈虹姸鎬� + List<int> StartOpenPumpIndexArray = new List<int>(); + if (!string.IsNullOrEmpty(request.StartOpenPumpIndexArray)) + { + var sss = request.StartOpenPumpIndexArray.Split(','); + foreach (var item in sss) + { + if (int.TryParse(item, out int index)) + { + StartOpenPumpIndexArray.Add(index); + } + } + } + anaRequest.IsKnownStartOpenPump = true; + anaRequest.StartOpenPumpIndexArray = 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.StartReservoirLevel = Convert.ToDouble(request.StartReservoirLevel); + if (anaRequest.StartReservoirLevel < 2) + { + IStation.LogHelper.Info(string.Format(" 璁剧疆寮�濮嬫椂姘村簱姘翠綅鐨勬暟鎹繃灏� (Error: StartReservoirLevel is {0}})", + anaRequest.StartReservoirLevel)); + return new IStation.Dto.ApiResult<string>() + { + Code = ApiResultCode.Error, + Data = string.Format(" 璁剧疆寮�濮嬫椂姘村簱姘翠綅鐨勬暟鎹繃灏� (Error: StartReservoirLevel is {0}})", + anaRequest.StartReservoirLevel) + }; + } + //bool isTemp = false; + //if (!string.IsNullOrEmpty(request.IsTemporary)) + //{ + // isTemp = Convert.ToBoolean(request.IsTemporary); + //} + + var calcHelper = new IStation.CalcPrjHelper(); + AnaPrj defaultPrj = null; + string error_info = calcHelper.Calc(anaRequest, out defaultPrj); + + if (!string.IsNullOrEmpty(error_info) || defaultPrj == null) + { + var er = string.Format("Zy Prj Time:{0}-{1} , 璁$畻閿欒, 鍘熷洜鏄�:{2} ,Request::: {3}", + start_timme, end_timme, error_info, JsonHelper.Object2Json(anaRequest)); + + IStation.LogHelper.Info(er); + 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)); + } + + //淇濆瓨鏂规,涓嶉渶瑕佷繚瀛�, 鐢卞鎴风,鐐瑰嚮淇濆瓨鍐嶄繚瀛� + //if (!isTemp) + //{ + // var ret = Common.HistoryAnaPrjFileHelper.SavePrj(IStation.AnaGlobalParas.Setting, anaRequest, defaultPrj); + //} + + #region 鎺ㄩ�� + + //if (!string.IsNullOrEmpty(request.IsSubmit) && Convert.ToBoolean(request.IsSubmit)) + //{ + // Task.Run(() => + // { + // _ = ZyProjectHelper.SubmitPrj(defaultPrj); + // }); + //} + + #endregion 鎺ㄩ�� + + return new IStation.Dto.ApiResult<AnaPrj>(defaultPrj) { Code = ApiResultCode.Success }; + } + + /// <summary> + /// 鑾峰彇鍒濆姘翠綅,鍜屽綋鏃剁殑寮�鏈虹姸鎬�, 鐢ㄤ簬璋冭瘯浼楁瘏 + /// </summary> + /// <param name="request"></param> + /// <returns></returns> + [Route("GetAnaStartPara")] + [HttpGet] + public IStation.Dto.ApiResult GetAnaStartPara(string AnaStartTime) + { + if (string.IsNullOrEmpty(AnaStartTime)) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; } + + try + { + DateTime last_end_time; + if (!DateTime.TryParse(AnaStartTime, out last_end_time)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; + } + + IStation.CalcModel.AnaRequestBase requestBase; + var prj = Common.HistoryAnaPrjFileHelper.GetByEndTime澶т簬(last_end_time, out requestBase); + if (prj == null) + { + IStation.LogHelper.Info(string.Format("GetAnaStartPara 鏈壘鍒皗0}缁撴潫鐨勫垎鏋愰」鐩�", AnaStartTime)); + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = string.Format("鏈壘鍒皗0}缁撴潫鐨勫垎鏋愰」鐩�", AnaStartTime) }; + } + + DateTime calcTime = DateTime.Now;//new DateTime(2024, 6, 11, 17, 10, 10);// + + IStation.CalcModel.ZyStartInfo zyStartInfo = new IStation.CalcModel.ZyStartInfo(); + if (prj.EndTimeOpenPumpStatus != null && prj.EndTimeOpenPumpStatus.Count > 0) + { + zyStartInfo.OpenPumpStatus = string.Join(",", prj.EndTimeOpenPumpStatus); + } + + var near_pt = prj.NearPointTime(calcTime); + if (near_pt == null) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = string.Format("鍦ㄩ」鐩腑, 鏈壘鍒皗0}鐨勬按搴撴按浣嶆暟鎹�", DateTime.Now) }; + } + + var new_yuce = near_pt.WaterLevelH;//鏄ㄥぉ棰勬祴姘翠綅 + double now_level = ZyConnectHelper.GetRealReservoirWaterLevel();//瀹炴椂姘翠綅 + if (prj.BlockTimes == null || prj.BlockTimes.Count() == 0) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鍦ㄩ」鐩腑, BlockTimes鍊间负绌�" }; + } + if (prj.BlockTimes.Last().PointTimes == null || prj.BlockTimes.Last().PointTimes.Count() == 0) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "鍦ㄩ」鐩腑, 鏈�鍚庝竴涓� BlockTime鐨� PointTimes 灞炴�у�间负绌�" }; + } + var lz = prj.BlockTimes.Last().PointTimes.Last().WaterLevelH; + double start_yuce = lz + now_level - new_yuce; + + IStation.LogHelper.Info(string.Format("GetAnaStartPara {0},{1},{2},{3} ", lz, now_level, new_yuce, start_yuce)); + + zyStartInfo.ReservoirWaterLevel = start_yuce; + return new IStation.Dto.ApiResult<IStation.CalcModel.ZyStartInfo>(zyStartInfo) { Code = ApiResultCode.Success }; + } + catch (Exception ex) + { + IStation.LogHelper.Error("GetAnaStartPara line 277", ex); + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = string.Format("鍦ㄩ」鐩腑, 鎺ュ彛鎶ラ敊: {0} ", ex.Message) }; + } + } + + /// <summary> + /// /// </summary> /// <param name="day"></param> /// <returns></returns> @@ -76,38 +405,58 @@ var list = HistoryAnaPrjFileHelper.GetExistStatus(year, month); if (list == null) { - list = new List<string >(); + list = new List<string>(); } - + return new IStation.Dto.ApiResult<List<string>>(list); } + ///// <summary> + ///// + ///// </summary> + ///// <param name="day"></param> + ///// <returns></returns> + //[Route("GetLastTimeOpenPumpCount")] + //[HttpGet] + //public IStation.Dto.ApiResult GetLastTimeOpenPumpCount(DateTime day) + //{ + // var status = HistoryAnaPrjFileHelper.GetLastTime_OpenPumpStatus (day); + // if(status == null) + // { + // return new IStation.Dto.ApiResult<int>(-1); + // } + // else + // { + // return new IStation.Dto.ApiResult<int>(status.Count); + // } + //} - /// <summary> - /// - /// </summary> - /// <param name="day"></param> - /// <returns></returns> - [Route("GetLastTimeOpenPumpCount")] - [HttpGet] - public IStation.Dto.ApiResult GetLastTimeOpenPumpCount(DateTime day) - { - int dict = HistoryAnaPrjFileHelper.GetLastTime_OpenPumpCount(day); - - return new IStation.Dto.ApiResult<int>(dict); - } - - + ///// <summary> + ///// + ///// </summary> + ///// <param name="day"></param> + ///// <returns></returns> + //[Route("GetLastTimeOpenPumpStatus")] + //[HttpGet] + //public IStation.Dto.ApiResult GetLastTimeOpenPumpStatus(DateTime day) + //{ + // var status = HistoryAnaPrjFileHelper.GetLastTime_OpenPumpStatus(day); + // if(status == null) + // return new IStation.Dto.ApiResult<string >(""); + // else + // return new IStation.Dto.ApiResult<string >(string.Join(",",status)); + //} public class SavePrjRequest - { + { public IStation.CalcModel.AnaSetting settting { get; set; } public IStation.CalcModel.AnaRequestBase requestBase { get; set; } public IStation.CalcModel.AnaPrj prj { get; set; } public bool isSubmit { get; set; } } + /// <summary> - /// + /// /// </summary> /// <param name="request"></param> /// <returns></returns> @@ -115,7 +464,7 @@ [HttpPost] public async Task<IStation.Dto.ApiResult> SavePrj([FromBody] SavePrjRequest request) { - if (request == null ) + if (request == null) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" }; } @@ -123,20 +472,21 @@ { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "prj null" }; } - - var ret = Common.HistoryAnaPrjFileHelper.SavePrj( request.settting, request.requestBase, request.prj); + + var ret = Common.HistoryAnaPrjFileHelper.SavePrj(request.settting, request.requestBase, request.prj); + + //鎻掑叆鍒版暟鎹簱 + //var dal = new IStation.DAL.AnaProject(); + //dal.Insert(request.prj, request.requestBase); if (request.isSubmit) { string error = await ZyProjectHelper.SubmitPrj(request.prj);//, (id) => { IStation.LogHelper.Info("SavePrj success id=" + id); }, (info) => { IStation.LogHelper.Info("SavePrj failse info:" + info); });//.Result; - - - - if(!string.IsNullOrEmpty(error)) + 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}; + return new IStation.Dto.ApiResult<string>(error) { Code = ApiResultCode.Error }; } else { @@ -144,14 +494,7 @@ } } - return new IStation.Dto.ApiResult<bool>(ret) { Code = ApiResultCode.Success }; } - - - - - - } -} +} \ No newline at end of file -- Gitblit v1.9.3