| | |
| | | //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; }//供水总量 (单位 吨) 不输入就用预测值 |
| | |
| | | [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" }; |
| | |
| | | { |
| | | 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; |
| | |
| | | |
| | | #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.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)) |
| | | if (string.IsNullOrEmpty(request.TotalFlowIn) || string.IsNullOrWhiteSpace(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 = "请输入取水总量或水位要求" }; |
| | | } |
| | | double TotalFlowIn = 0; |
| | | if (!double.TryParse(request.TotalFlowIn, out TotalFlowIn)) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入数字型取水总量,接受到的输入值是:"+ request.TotalFlowIn }; |
| | | } |
| | | } |
| | | |
| | |
| | | double TotalFlowOut = 0; |
| | | double TotalFlowOutPrecid = 0;//预测值的供水总量 |
| | | |
| | | if (string.IsNullOrEmpty(request.TotalFlowOut)) |
| | | if (string.IsNullOrEmpty(request.TotalFlowOut) || string.IsNullOrWhiteSpace(request.TotalFlowOut)) |
| | | {//用预测值 |
| | | #region 用预测值 |
| | | |
| | |
| | | TotalFlowOutPrecid += r.LastPredictValue; |
| | | anaRequest.PerHourFlowOut.Add(r.LastPredictValue);//计算中用吨 |
| | | } |
| | | |
| | | IStation.LogHelper.Info(string.Format(" 获取水量预测值: {0} ", string.Join(",",anaRequest.PerHourFlowOut))); |
| | | #endregion 用预测值 |
| | | } |
| | | else |
| | | { |
| | | 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) |
| | | { |
| | |
| | | #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)) |
| | |
| | | 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--------------------------------------"); |
| | | |
| | | //保存方案 |
| | | //defaultPrj.Name |
| | | //保存方案 |
| | | var ret = Common.HistoryAnaPrjFileHelper.SavePrj(IStation.AnaGlobalParas.Setting, anaRequest, defaultPrj); |
| | | |
| | | // |
| | |
| | | dto_setting.OptSortType = model_setting.OptSortType; |
| | | dto_setting.SwitchPumpMinuteSpace = model_setting.SwitchPumpMinuteSpace; |
| | | |
| | | dto_setting.OpenPumpIndexSequence = model_setting.OpenPumpIndexSequence; |
| | | dto_setting.ClosePumpIndexSequence = model_setting.ClosePumpIndexSequence; |
| | | 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 表示二号泵 为空,表示没有检修 |
| | | var overhallStatus = ZyConnectHelper.GetOverhaulStatus(); |
| | | if(overhallStatus == null || overhallStatus.Count == 0) |
| | | try |
| | | { |
| | | if(model_setting.UnablePumpIndexArray != null) |
| | | var overhallStatus = ZyConnectHelper.GetOverhaulStatus(); |
| | | if (overhallStatus == null || overhallStatus.Count == 0) |
| | | { |
| | | model_setting.UnablePumpIndexArray = null; |
| | | 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); |
| | | } |
| | | } |
| | | else |
| | | catch(Exception ex) |
| | | { |
| | | model_setting.UnablePumpIndexArray = overhallStatus.ToArray(); |
| | | IStation.Common.AnaSetting.SaveSetting(model_setting); |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "无法链接工控服务器,错误原因:" + ex.Message}; |
| | | } |
| | | dto_setting.UnablePumpIndexArray = model_setting.UnablePumpIndexArray; |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | if (dto.OpenPumpIndexSequence != null) |
| | | if (!string.IsNullOrEmpty(dto.OpenPumpIndexSequence)) |
| | | { |
| | | int[] new_set_sequence; |
| | | var error = BuildSequenceFromDto(dto.OpenPumpIndexSequence, out new_set_sequence); |
| | |
| | | model_setting.OpenPumpIndexSequence = new_set_sequence; |
| | | } |
| | | |
| | | if (dto.ClosePumpIndexSequence != null) |
| | | if (!string.IsNullOrEmpty(dto.ClosePumpIndexSequence))// if (dto.ClosePumpIndexSequence != null) |
| | | { |
| | | int[] new_set_sequence; |
| | | var error = BuildSequenceFromDto(dto.ClosePumpIndexSequence, out new_set_sequence); |
| | |
| | | model_setting.ClosePumpIndexSequence = new_set_sequence; |
| | | } |
| | | |
| | | if (dto.OptimalPumpIndexSequence != null) |
| | | if (!string.IsNullOrEmpty(dto.OptimalPumpIndexSequence))// if (dto.OptimalPumpIndexSequence != null) |
| | | { |
| | | int[] new_set_sequence; |
| | | var error = BuildSequenceFromDto(dto.OptimalPumpIndexSequence, out new_set_sequence); |
| | |
| | | |
| | | 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 " 设置参数不合理,机泵序号有非数字"; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private string BuildSequenceFromDto(int[] sequenceDto, out int[] sequenceDs) |
| | | return BuildSequenceFromDto(list,out sequenceDs); |
| | | } |
| | | |
| | | private string BuildSequenceFromDto(List<int> sequenceDto, out int[] sequenceDs) |
| | | { |
| | | sequenceDs = null; |
| | | if (sequenceDto == null || sequenceDto.Count() == 0) |