| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Web; |
| | | using System.Web.Http; |
| | | using System.Web.Http; |
| | | |
| | | namespace IStation.ZyDto |
| | | { |
| | |
| | | //public int? StartOpenCount { get; set; } = -1;//已作废 |
| | | |
| | | public string StartReservoirLevel { get; set; }//开始水库水位(可空):单位m |
| | | public List<int> StartOpenPumpIndexArray { get; set; }//开始机泵开机状态(新) |
| | | public string StartOpenPumpIndexArray { get; set; }//开始机泵开机状态(不可空) |
| | | |
| | | public string TotalFlowIn { get; set; }//取水总量 (单位 吨) |
| | | public string TotalFlowOut { get; set; }//供水总量 (单位 吨) 不输入就用预测值 |
| | | |
| | | |
| | | public string MaxReservoirLevel { get; set; }//最高水库水位限制(可空):单位m |
| | | public string MaxReservoirLevelTime { get; set; }//最高水库水位限制时间(可空) 时间格式 |
| | | |
| | | public string IsSubmit { get; set; }//计算完,是否推送 |
| | | public string IsTemporary { get; set; }//是否是临时算一下(新) |
| | | } |
| | | } |
| | | |
| | |
| | | [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" }; |
| | |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "EndTime is null" }; |
| | | } |
| | | // |
| | | IStation.LogHelper.Info("--------------------------START-----------------------------------------"); |
| | | IStation.LogHelper.Info(string.Format("Zy Prj Calc Request: {0}", JsonHelper.Object2Json(request))); |
| | | |
| | | DateTime start_timme = DateTime.Now; |
| | | DateTime end_timme = DateTime.Now; |
| | |
| | | anaRequest.WaterLevels长江 = GetTide3Day(_tideSouce, start_timme); |
| | | |
| | | #region 取水总量 |
| | | if (!string.IsNullOrEmpty(request.TotalFlowIn)) |
| | | |
| | | if (!string.IsNullOrEmpty(request.TotalFlowIn) && !string.IsNullOrWhiteSpace(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 = "注意取水总量单位是吨,当前参数参数过小" }; |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入数字型取水总量,接受到的输入值是:" + request.TotalFlowIn }; |
| | | } |
| | | if (TotalFlowIn < 10000) |
| | | { |
| | |
| | | } |
| | | |
| | | anaRequest.TotalFlowIn = TotalFlowIn; |
| | | } |
| | | #endregion |
| | | } |
| | | |
| | | #region 水位要求 |
| | | #endregion 取水总量 |
| | | |
| | | #region 水位要求 |
| | | |
| | | if (!string.IsNullOrEmpty(request.MaxReservoirLevelTime)) |
| | | { |
| | | anaRequest.MaxReservoirLevelTime = request.MaxReservoirLevelTime; |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(request.MaxReservoirLevel)) |
| | | if (!string.IsNullOrEmpty(request.MaxReservoirLevel) && !string.IsNullOrWhiteSpace(request.MaxReservoirLevel)) |
| | | { |
| | | double MaxReservoirLevel = 0; |
| | | if (!double.TryParse(request.MaxReservoirLevel, out MaxReservoirLevel)) |
| | |
| | | } |
| | | else |
| | | { |
| | | if (string.IsNullOrEmpty(request.TotalFlowIn)) |
| | | { |
| | | IStation.LogHelper.Info(string.Format("Zy Prj Time:{0}-{1} , 请输入取水总量或水位要求", |
| | | start_timme, end_timme)); |
| | | if (string.IsNullOrEmpty(request.TotalFlowIn) || string.IsNullOrWhiteSpace(request.TotalFlowIn)) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入取水总量或水位要求" }; |
| | | } |
| | | } |
| | | #endregion |
| | | double TotalFlowIn = 0; |
| | | if (!double.TryParse(request.TotalFlowIn, out TotalFlowIn)) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入数字型取水总量,接受到的输入值是:" + request.TotalFlowIn }; |
| | | } |
| | | } |
| | | |
| | | #endregion 水位要求 |
| | | |
| | | #region 供水量 |
| | | if (string.IsNullOrEmpty(request.TotalFlowOut)) |
| | | |
| | | double TotalFlowOut = 0; |
| | | double TotalFlowOutPrecid = 0;//预测值的供水总量 |
| | | |
| | | if (string.IsNullOrEmpty(request.TotalFlowOut) || string.IsNullOrWhiteSpace(request.TotalFlowOut)) |
| | | {//用预测值 |
| | | #region 用预测值 |
| | | |
| | | anaRequest.PerHourFlowOut = new List<double>(); |
| | | IStation.DAL.WaterPredictRecord dal = new DAL.WaterPredictRecord(); |
| | | var water_records = dal.GetByHourRangle(start_timme, end_timme); |
| | |
| | | Data = error_info11 |
| | | }; |
| | | } |
| | | anaRequest.PerHourFlowOut.Add(r.LastPredictValue );//计算中用吨 |
| | | TotalFlowOutPrecid += r.LastPredictValue; |
| | | anaRequest.PerHourFlowOut.Add(r.LastPredictValue);//计算中用吨 |
| | | } |
| | | #endregion |
| | | IStation.LogHelper.Info(string.Format(" 获取水量预测值: {0} ", string.Join(",", anaRequest.PerHourFlowOut))); |
| | | |
| | | #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 = "注意供水总量单位是吨,当前参数参数过小" }; |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "注意供水总量输入参数无法识别,参数是:" + request.TotalFlowOut }; |
| | | } |
| | | if (TotalFlowOut < 10000) |
| | | { |
| | |
| | | var count = (end_timme - start_timme).TotalHours; |
| | | for (var d = start_timme; d <= end_timme; d = d.AddHours(1)) |
| | | { |
| | | list.Add(Math.Round( TotalFlowOut / count,1)); |
| | | list.Add(Math.Round(TotalFlowOut / count, 1)); |
| | | } |
| | | anaRequest.PerHourFlowOut = list; |
| | | } |
| | | #endregion |
| | | } |
| | | |
| | | #endregion 供水量 |
| | | |
| | | //开始时的开机状态 |
| | | if (request.StartOpenPumpIndexArray == null) |
| | | List<int> StartOpenPumpIndexArray = new List<int>(); |
| | | if (!string.IsNullOrEmpty(request.StartOpenPumpIndexArray)) |
| | | { |
| | | IStation.LogHelper.Info(" 未设置开始时机泵开停状态 (Error: StartOpenPumpIndexArray is null)"); |
| | | return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = "未设置开始时机泵开停状态 (Error: StartOpenPumpIndexArray is null)" }; |
| | | var sss = request.StartOpenPumpIndexArray.Split(','); |
| | | foreach (var item in sss) |
| | | { |
| | | if (int.TryParse(item, out int index)) |
| | | { |
| | | if (index < 0 || index > 4) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "开始时的开机状态,机泵角标要求不超过4" }; |
| | | } |
| | | StartOpenPumpIndexArray.Add(index); |
| | | } |
| | | else |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "开始时的开机状态,参数不正确" }; |
| | | } |
| | | } |
| | | } |
| | | anaRequest.IsKnownStartOpenPump = true; |
| | | anaRequest.StartOpenPumpIndexArray = request.StartOpenPumpIndexArray; |
| | | |
| | | anaRequest.StartOpenPumpIndexArray = StartOpenPumpIndexArray; |
| | | |
| | | //陈行水库水位 |
| | | if (string.IsNullOrEmpty(request.StartReservoirLevel)) |
| | |
| | | anaRequest.StartReservoirLevel) |
| | | }; |
| | | } |
| | | bool isTemp = false; |
| | | if (!string.IsNullOrEmpty(request.IsTemporary)) |
| | | { |
| | | isTemp = Convert.ToBoolean(request.IsTemporary); |
| | | } |
| | | |
| | | //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); |
| | | IStation.LogHelper.Info(string.Format("Zy Prj 计算错误: \r\n {0} ", error_info)); |
| | | 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)); |
| | | // IStation.LogHelper.Info(string.Format("Zy Prj 计算成功: \r\n {0} ", JsonHelper.Object2Json(defaultPrj))); |
| | | } |
| | | IStation.LogHelper.Info("-----------------------------END--------------------------------------"); |
| | | |
| | | //保存方案 |
| | | if (!isTemp) |
| | | { |
| | | var ret = Common.HistoryAnaPrjFileHelper.SavePrj(IStation.AnaGlobalParas.Setting, anaRequest, defaultPrj); |
| | | } |
| | | |
| | | var ret = Common.HistoryAnaPrjFileHelper.SavePrj(IStation.AnaGlobalParas.Setting, anaRequest, defaultPrj); |
| | | |
| | | // |
| | | var dto_prj = ToPrjDto(defaultPrj); |
| | | if (TotalFlowOutPrecid > 1) |
| | | { |
| | | dto_prj.FlowTotalOut = Math.Round(TotalFlowOutPrecid / 10000, 1); |
| | | } |
| | | else |
| | | { |
| | | dto_prj.FlowTotalOut = TotalFlowOut; |
| | | } |
| | | |
| | | #region 推送 |
| | | |
| | | if (!string.IsNullOrEmpty(request.IsSubmit) && Convert.ToBoolean(request.IsSubmit)) |
| | | { |
| | | Task.Run(() => |
| | | { |
| | | _ = ZyProjectHelper.SubmitPrj(defaultPrj); |
| | | }); |
| | | } |
| | | //if (!string.IsNullOrEmpty(request.IsSubmit) && Convert.ToBoolean(request.IsSubmit)) |
| | | //{ |
| | | // Task.Run(() => |
| | | // { |
| | | // _ = ZyProjectHelper.SubmitPrj(defaultPrj); |
| | | // }); |
| | | //} |
| | | |
| | | #endregion 推送 |
| | | |
| | | // IStation.LogHelper.Info(string.Format(" 产生计算方案:{0}", dto_prj.schemeID)); |
| | | |
| | | return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success }; |
| | | } |
| | |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 格式不正确" }; |
| | | } |
| | | |
| | | |
| | | |
| | | IStation.CalcModel.AnaRequestBase requestBase; |
| | | var prj = Common.HistoryAnaPrjFileHelper.GetByEndTime(last_end_time, out 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) }; |
| | | } |
| | | |
| | | |
| | | |
| | | IStation.CalcModel.ZyStartInfo zyStartInfo = new IStation.CalcModel.ZyStartInfo(); |
| | | zyStartInfo.OpenPumpStatus = prj.EndTimeOpenPumpStatus; |
| | | //zyStartInfo.OpenPumpStatus = prj.EndTimeOpenPumpStatus; |
| | | if (prj.EndTimeOpenPumpStatus != null && prj.EndTimeOpenPumpStatus.Count > 0) |
| | | { |
| | | zyStartInfo.OpenPumpStatus = string.Join(",", prj.EndTimeOpenPumpStatus); |
| | | } |
| | | |
| | | var near_pt = prj.NearPointTime(DateTime.Now); |
| | | if (near_pt == null) |
| | |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "在项目中, 最后一个 BlockTime的 PointTimes 属性值为空" }; |
| | | } |
| | | var lz = prj.BlockTimes.Last().PointTimes.Last().WaterLevelH; |
| | | var lz_pt = prj.FindPointTime(last_end_time); |
| | | if (lz_pt != null) |
| | | { |
| | | lz = lz_pt.WaterLevelH; |
| | | } |
| | | |
| | | double start_yuce = lz + now_level - new_yuce; |
| | | |
| | | IStation.LogHelper.Info(string.Format("GetAnaStartPara StartTime {0} Level: {1},{2},{3} ,{4} ", AnaStartTime, lz, now_level, new_yuce, start_yuce)); |
| | | |
| | | // IStation.LogHelper.Info(string.Format("GetAnaStartPara {0},{1},{2},{3} ", lz , now_level , new_yuce, start_yuce)); |
| | | |
| | | zyStartInfo.ReservoirWaterLevel = start_yuce; |
| | | zyStartInfo.ReservoirWaterLevel = Math.Round(start_yuce, 3); |
| | | 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="ana"></param> |
| | | /// <returns></returns> |
| | | [Route("ConfirmSchemeByID")] |
| | | [HttpPost] |
| | | public IStation.Dto.ApiResult ConfirmSchemeByID(string ID) |
| | | { |
| | | if (string.IsNullOrEmpty(ID) || ID == "string") |
| | | { |
| | | return new IStation.Dto.ApiResult<bool>(false); |
| | | } |
| | | var dal = new IStation.DAL.AnaProject(); |
| | | var info = dal.SetConfirmStatusByID(ID); |
| | | if (string.IsNullOrEmpty(info)) |
| | | return new IStation.Dto.ApiResult<bool>(true); |
| | | else |
| | | { |
| | | IStation.LogHelper.Info(string.Format(" ConfirmSchemeByID error ID:{0}, reason:{1}", ID, info)); |
| | | return new IStation.Dto.ApiResult<bool>(false); |
| | | } |
| | | } |
| | | |
| | |
| | | defaultPrj.ID = $"{time.Year}{time.Month}{time.Day}{time.Hour}{time.Minute}{time.Second}"; |
| | | } |
| | | dto_prj.schemeID = defaultPrj.ID; |
| | | dto_prj.schemeName = defaultPrj.Name; |
| | | dto_prj.Day = defaultPrj.StartTime.ToString("yyyy-MM-dd"); |
| | | dto_prj.StartTime = defaultPrj.StartTime.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | dto_prj.EndTime = defaultPrj.EndTime.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | dto_prj.FlowTotal = Math.Round(defaultPrj.SumFlow, 0); |
| | | dto_prj.FlowTotalIn = Math.Round(defaultPrj.SumFlow, 0); |
| | | dto_prj.PowerTotal = Math.Round(defaultPrj.SumPower, 0); |
| | | dto_prj.MoneyTotal = Math.Round(defaultPrj.SumMoney, 0); |
| | | |
| | | dto_prj.Items = new List<ZyDto.SubmitPrjItem>(); |
| | | foreach (var bt in defaultPrj.BlockTimes) |
| | | dto_prj.BlockTimes = new List<ZyDto.SubmitPrjBlockTime>(); |
| | | double maxHeight = 0; |
| | | double startHeight = 0; |
| | | |
| | | if (defaultPrj.BlockTimes != null) |
| | | { |
| | | if (bt.OpenPumpIndexs == null) |
| | | continue; |
| | | ZyDto.SubmitPrjItem dto_item = new ZyDto.SubmitPrjItem(); |
| | | dto_item.StartTime = bt.StartTime; |
| | | dto_item.EndTime = bt.EndTime; |
| | | dto_item.OpenPumpCount = bt.OpenPumpIndexs.Count; |
| | | dto_item.OpenPumpIndexs = bt.OpenPumpIndexs;// |
| | | |
| | | if (bt.PointTimes != null) |
| | | startHeight = defaultPrj.BlockTimes.First().ReservoirStartHeight; |
| | | foreach (var bt in defaultPrj.BlockTimes) |
| | | { |
| | | dto_item.Records = new List<SubmitPrjTime>(); |
| | | foreach (var bt2 in bt.PointTimes) |
| | | if (bt.OpenPumpIndexs == null) |
| | | continue; |
| | | ZyDto.SubmitPrjBlockTime dto_item = new ZyDto.SubmitPrjBlockTime(); |
| | | dto_item.StartTime = bt.StartTime; |
| | | dto_item.EndTime = bt.EndTime; |
| | | dto_item.OpenPumpCount = bt.OpenPumpIndexs.Count; |
| | | dto_item.OpenPumpIndexs = bt.OpenPumpIndexs; |
| | | dto_item.StartSwitchGroupID = bt.StartSwitchGroupID; |
| | | |
| | | if (bt.PointTimes != null) |
| | | { |
| | | dto_item.Records.Add(new SubmitPrjTime(bt2)); |
| | | dto_item.Records = new List<SubmitPrjTime>(); |
| | | foreach (var bt2 in bt.PointTimes) |
| | | { |
| | | maxHeight = Math.Max(maxHeight, bt2.WaterLevelH); |
| | | dto_item.Records.Add(new SubmitPrjTime(bt2)); |
| | | } |
| | | } |
| | | |
| | | dto_prj.BlockTimes.Add(dto_item); |
| | | } |
| | | } |
| | | dto_prj.MaxWaterLevelH = maxHeight; |
| | | dto_prj.StartWaterLevelH = startHeight; |
| | | dto_prj.Switchs = new List<SubmitPrjSwitchInfo>(); |
| | | if (defaultPrj.PumpSwitchs != null) |
| | | { |
| | | foreach (var bt in defaultPrj.PumpSwitchs) |
| | | { |
| | | ZyDto.SubmitPrjSwitchInfo dto_item = new ZyDto.SubmitPrjSwitchInfo(); |
| | | dto_item.Index = bt.Index; |
| | | dto_item.GroupID = bt.GroupID;//分组ID |
| | | dto_item.PumpIndex = bt.PumpIndex;//泵角标 |
| | | dto_item.Time = bt.Time.ToString("yyyy-MM-dd HH:mm:ss");//时间 |
| | | dto_item.SwitchType = bt.SwitchType;///1 开机 0 关机 |
| | | |
| | | |
| | | dto_prj.Items.Add(dto_item); |
| | | dto_prj.Switchs.Add(dto_item); |
| | | } |
| | | } |
| | | |
| | | return dto_prj; |
| | | } |
| | | |
| | | #endregion 换算成DTO |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取某一天,最近一条 |
| | |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 格式不正确" }; |
| | | } |
| | | IStation.LogHelper.Info(string.Format(" api GetHistoryByDay {0} format: {1} ", day, d)); |
| | | |
| | | IStation.CalcModel.AnaRequestBase requestBase = null; |
| | | var prj = Common.HistoryAnaPrjFileHelper.GetByStartDay(d, out requestBase); |
| | | var prj = Common.HistoryAnaPrjFileHelper.GetByCreateDay(d, out requestBase); |
| | | |
| | | if (prj != null) |
| | | { |
| | |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Alert, Message = "未找到项目" }; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取最近一条 |
| | |
| | | dto_setting.MinSwitchTimeMinute = model_setting.MinSwitchTimeMinute; |
| | | dto_setting.MaxPumpSwitchCount = model_setting.MaxPumpSwitchCount; |
| | | dto_setting.OptSortType = model_setting.OptSortType; |
| | | dto_setting.OpenPumpIndexSequence = model_setting.OpenPumpIndexSequence; |
| | | dto_setting.ClosePumpIndexSequence = model_setting.ClosePumpIndexSequence; |
| | | dto_setting.SwitchPumpMinuteSpace = model_setting.SwitchPumpMinuteSpace; |
| | | dto_setting.OptimalPumpIndexSequence = model_setting.OptimalPumpIndexSequence; |
| | | |
| | | dto_setting.OpenPumpIndexSequence = IStation.Dto.ZyPrjAnaSetting.ListToString(model_setting.OpenPumpIndexSequence); |
| | | dto_setting.ClosePumpIndexSequence = IStation.Dto.ZyPrjAnaSetting.ListToString(model_setting.ClosePumpIndexSequence); |
| | | dto_setting.OptimalPumpIndexSequence = IStation.Dto.ZyPrjAnaSetting.ListToString(model_setting.OptimalPumpIndexSequence); |
| | | |
| | | //dto_setting.OpenPumpIndexSequence = BuildSequenceToDto(model_setting.OpenPumpIndexSequence); |
| | | //dto_setting.ClosePumpIndexSequence = BuildSequenceToDto(model_setting.ClosePumpIndexSequence); |
| | | //dto_setting.OptimalPumpIndexSequence = BuildSequenceToDto(model_setting.OptimalPumpIndexSequence); |
| | | |
| | | //检修泵的角标, 0 表示1号泵 1 表示二号泵 为空,表示没有检修 |
| | | try |
| | | { |
| | | var overhallStatus = ZyConnectHelper.GetOverhaulStatus(); |
| | | if (overhallStatus == null || overhallStatus.Count == 0) |
| | | { |
| | | if (model_setting.UnablePumpIndexArray != null) |
| | | { |
| | | dto_setting.UnablePumpIndexArray = ""; |
| | | model_setting.UnablePumpIndexArray = null; |
| | | IStation.Common.AnaSetting.SaveSetting(model_setting); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | model_setting.UnablePumpIndexArray = overhallStatus.ToArray(); |
| | | dto_setting.UnablePumpIndexArray = string.Join(",", overhallStatus); |
| | | IStation.Common.AnaSetting.SaveSetting(model_setting); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "无法链接工控服务器,错误原因:" + ex.Message }; |
| | | } |
| | | |
| | | if (model_setting.SwitchPumpIgnoreTimes != null) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | IStation.LogHelper.Info("ZyPrj GetSetting : Content: " + JsonHelper.Object2Json(dto_setting)); |
| | | |
| | | return new IStation.Dto.ApiResult<IStation.Dto.ZyPrjAnaSetting>(dto_setting); |
| | | } |
| | | |
| | |
| | | { |
| | | if (dto == null) |
| | | { |
| | | return new IStation.Dto.ApiResult<bool>(false); |
| | | return new IStation.Dto.ApiResult<bool>(false) { Message = "入参为空" }; |
| | | } |
| | | var model_setting = IStation.AnaGlobalParas.Setting; |
| | | IStation.LogHelper.Info("ZyPrj SaveSetting"); |
| | | |
| | | IStation.LogHelper.Info("ZyPrj SaveSetting : Content: " + JsonHelper.Object2Json(dto)); |
| | | |
| | | if (dto.MinOpenTimeMinute < 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "最少开泵时间 设置过少" }; |
| | |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "最少切泵时间 设置过长" }; |
| | | } |
| | | model_setting.MinSwitchTimeMinute = dto.MinSwitchTimeMinute; |
| | | if (dto.SwitchPumpMinuteSpace < 2 || dto.SwitchPumpMinuteSpace > 30) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "切换泵时间间隔 设置不合理" }; |
| | | } |
| | | model_setting.SwitchPumpMinuteSpace = dto.SwitchPumpMinuteSpace; |
| | | |
| | | if (dto.MaxPumpSwitchCount < 1) |
| | | { |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | if (dto.OpenPumpIndexSequence != null) |
| | | |
| | | if (!string.IsNullOrEmpty(dto.OpenPumpIndexSequence)) |
| | | { |
| | | List<int> penPumpIndexs = new List<int>(); |
| | | foreach (var ind in dto.OpenPumpIndexSequence) |
| | | int[] new_set_sequence; |
| | | var error = BuildSequenceFromDto(dto.OpenPumpIndexSequence, out new_set_sequence); |
| | | if (!string.IsNullOrEmpty(error)) |
| | | { |
| | | if (ind < 0 || ind > 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "开泵顺序设置参数不合理" }; |
| | | } |
| | | else |
| | | { |
| | | penPumpIndexs.Add(ind); |
| | | } |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "开泵顺序 " + error }; |
| | | } |
| | | if (penPumpIndexs.Distinct().Count() != 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "开泵顺序设置参数不合理" }; |
| | | } |
| | | model_setting.OpenPumpIndexSequence = penPumpIndexs.ToArray(); |
| | | |
| | | model_setting.OpenPumpIndexSequence = new_set_sequence; |
| | | } |
| | | |
| | | if (dto.ClosePumpIndexSequence != null) |
| | | if (!string.IsNullOrEmpty(dto.ClosePumpIndexSequence))// if (dto.ClosePumpIndexSequence != null) |
| | | { |
| | | List<int> penPumpIndexs = new List<int>(); |
| | | foreach (var ind in dto.ClosePumpIndexSequence) |
| | | int[] new_set_sequence; |
| | | var error = BuildSequenceFromDto(dto.ClosePumpIndexSequence, out new_set_sequence); |
| | | if (!string.IsNullOrEmpty(error)) |
| | | { |
| | | if (ind < 0 || ind > 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "关泵顺序设置参数不合理" }; |
| | | } |
| | | else |
| | | { |
| | | penPumpIndexs.Add(ind); |
| | | } |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "关泵顺序 " + error }; |
| | | } |
| | | if (penPumpIndexs.Distinct().Count() != 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "关泵顺序设置参数不合理" }; |
| | | } |
| | | model_setting.ClosePumpIndexSequence = penPumpIndexs.ToArray(); |
| | | |
| | | model_setting.ClosePumpIndexSequence = new_set_sequence; |
| | | } |
| | | |
| | | if (dto.OptimalPumpIndexSequence != null) |
| | | if (!string.IsNullOrEmpty(dto.OptimalPumpIndexSequence))// if (dto.OptimalPumpIndexSequence != null) |
| | | { |
| | | List<int> penPumpIndexs = new List<int>(); |
| | | foreach (var ind in dto.OptimalPumpIndexSequence) |
| | | int[] new_set_sequence; |
| | | var error = BuildSequenceFromDto(dto.OptimalPumpIndexSequence, out new_set_sequence); |
| | | if (!string.IsNullOrEmpty(error)) |
| | | { |
| | | if (ind < 0 || ind > 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "调度泵优先度顺序设置参数不合理" }; |
| | | } |
| | | else |
| | | { |
| | | penPumpIndexs.Add(ind); |
| | | } |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "调度泵优先度顺序 " + error }; |
| | | } |
| | | if (penPumpIndexs.Distinct().Count() != 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "调度泵优先度顺序设置参数不合理" }; |
| | | } |
| | | model_setting.OptimalPumpIndexSequence = penPumpIndexs.ToArray(); |
| | | |
| | | model_setting.OptimalPumpIndexSequence = new_set_sequence; |
| | | } |
| | | |
| | | //检修状态, 直接读SCADA系统 |
| | | //if (dto.UnablePumpIndexArray != null && dto.UnablePumpIndexArray.Count()>0) |
| | | //{ |
| | | // if (dto.UnablePumpIndexArray.Count() > 2) |
| | | // { |
| | | // return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "检修泵数量不能超过2台 " }; |
| | | // } |
| | | // if (dto.UnablePumpIndexArray.Contains(5)) |
| | | // { |
| | | // List<int> penPumpIndexs1 = new List<int>(); |
| | | // foreach (var p in dto.UnablePumpIndexArray) |
| | | // { |
| | | // penPumpIndexs1.Add(p - 1); |
| | | // } |
| | | // model_setting.UnablePumpIndexArray = penPumpIndexs1.ToArray(); |
| | | // } |
| | | // else |
| | | // { |
| | | // model_setting.UnablePumpIndexArray = dto.UnablePumpIndexArray; |
| | | // } |
| | | // model_setting.Check_Optimal_UnablePumpIndexArray(); |
| | | //} |
| | | //else |
| | | //{ |
| | | // model_setting.UnablePumpIndexArray = null; |
| | | //} |
| | | |
| | | return new IStation.Dto.ApiResult<bool>(IStation.Common.AnaSetting.SaveSetting(model_setting)); |
| | | } |
| | | |
| | | /// <summary> |
| | | ///获取机泵检修状态 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [Route("SynOverhaulStatus")] |
| | | [HttpGet] |
| | | public IStation.Dto.ApiResult SynOverhaulStatus() |
| | | { |
| | | var overhallStatus = ZyConnectHelper.GetOverhaulStatus();//检修泵的角标, 0 表示1号泵 1 表示二号泵 为空,表示没有检修 |
| | | |
| | | return new IStation.Dto.ApiResult<List<int>>(overhallStatus); |
| | | } |
| | | |
| | | private string BuildSequenceFromDto(string sequenceDto, out int[] sequenceDs) |
| | | { |
| | | sequenceDs = null; |
| | | if (string.IsNullOrEmpty(sequenceDto)) |
| | | return null; |
| | | |
| | | List<int> list = new List<int>(); |
| | | if (!string.IsNullOrEmpty(sequenceDto)) |
| | | { |
| | | var sss = sequenceDto.Split(','); |
| | | foreach (var item in sss) |
| | | { |
| | | if (int.TryParse(item, out int index)) |
| | | { |
| | | list.Add(index); |
| | | } |
| | | else |
| | | { |
| | | return " 设置参数不合理,机泵序号有非数字"; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return BuildSequenceFromDto(list, out sequenceDs); |
| | | } |
| | | |
| | | private string BuildSequenceFromDto(List<int> sequenceDto, out int[] sequenceDs) |
| | | { |
| | | sequenceDs = null; |
| | | if (sequenceDto == null || sequenceDto.Count() == 0) |
| | | return null; |
| | | List<int> penPumpIndexs = new List<int>(); |
| | | foreach (var ind in sequenceDto) |
| | | { |
| | | if (ind < 0) |
| | | { |
| | | return " 设置参数不合理,机泵序号有负数"; |
| | | } |
| | | else if (ind > 5) |
| | | { |
| | | return " 设置参数不合理,机泵序号超过5"; |
| | | } |
| | | else |
| | | { |
| | | penPumpIndexs.Add(ind); |
| | | } |
| | | } |
| | | if (penPumpIndexs.Distinct().Count() != 5) |
| | | { |
| | | return " 设置参数不合理"; |
| | | } |
| | | |
| | | if (penPumpIndexs.Contains(5)) |
| | | {//表示界面从1 2 3 4 5 |
| | | List<int> penPumpIndexs1 = new List<int>(); |
| | | foreach (var p in penPumpIndexs) |
| | | { |
| | | penPumpIndexs1.Add(p - 1); |
| | | } |
| | | sequenceDs = penPumpIndexs1.ToArray(); |
| | | } |
| | | else |
| | | { |
| | | sequenceDs = penPumpIndexs.ToArray(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private int[] BuildSequenceToDto(int[] sequenceDs) |
| | | { |
| | | if (sequenceDs == null || sequenceDs.Length == 0) return null; |
| | | |
| | | List<int> sequenceDto = new List<int>(); |
| | | |
| | | foreach (var sequence in sequenceDs) |
| | | { |
| | | sequenceDto.Add(sequence + 1); |
| | | } |
| | | return sequenceDto.ToArray(); |
| | | } |
| | | |
| | | private Model.eTideSouce _tideSouce = Model.eTideSouce.Book; |
| | | |
| | | public static List<Model.TimeWaterLevel> GetTide3Day(Model.eTideSouce tideSouce, DateTime calc_day) |
| | | public static List<Model.TimeWaterLevel> GetTide3Day(Model.eTideSouce tideSouce, DateTime calc_day) |
| | | { |
| | | DateTime _rangDay1, _rangDay2, _rangDay3; |
| | | string error1, error2, error3; |