| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Web; |
| | | using System.Web.Http; |
| | | using System.Web.UI.WebControls; |
| | | using System.Web.UI.WebControls.WebParts; |
| | | using System.Web.Http; |
| | | |
| | | namespace IStation.ZyDto |
| | | { |
| | |
| | | |
| | | public string StartTime { get; set; } |
| | | public string EndTime { get; set; } |
| | | public int? StartOpenCount { get; set; } = -1; |
| | | //public int? StartOpenCount { get; set; } = -1;//已作废 |
| | | |
| | | public string StartReservoirLevel { get; set; }//开始水库水位(可空):单位m |
| | | public List<int> StartOpenPumpIndexArray { get; set; }//开始机泵开机状态 |
| | | |
| | | public string TotalFlowIn { get; set; }//取水总量 (单位 吨) |
| | | public string StartReservoirLevel { get; set; }//开始水库水位(可空):单位m |
| | | |
| | | public string MaxReservoirLevel { get; set; }//最高水库水位限制(可空):单位m |
| | | public string MaxReservoirLevelTime { 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 = "时间范围错误,不能超过24小时" }; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | 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); |
| | | |
| | | |
| | | if (string.IsNullOrEmpty(request.TotalFlowIn)) |
| | | { |
| | | if (string.IsNullOrEmpty(request.MaxReservoirLevel)) |
| | | { |
| | | IStation.LogHelper.Info(string.Format("Zy Prj Time:{0}-{1} , 请输入取水总量或水位要求", |
| | | start_timme, end_timme )); |
| | | start_timme, end_timme)); |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入取水总量或水位要求" }; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | double TotalFlowIn = 0; |
| | | if(!double.TryParse( request.TotalFlowIn,out TotalFlowIn)) |
| | | if (!double.TryParse(request.TotalFlowIn, out TotalFlowIn)) |
| | | { |
| | | IStation.LogHelper.Info(string.Format("Zy Prj Time:{0}-{1} , 注意取水总量单位是吨,当前参数参数过小", |
| | | start_timme, end_timme)); |
| | |
| | | if (!string.IsNullOrEmpty(request.MaxReservoirLevel)) |
| | | { |
| | | anaRequest.MaxLimitWaterBoxLevel = Convert.ToDouble(request.MaxReservoirLevel); |
| | | |
| | | IStation.DAL.WaterPredictRecord dal = new DAL.WaterPredictRecord(); |
| | | var water_records = dal.GetByHourRangle( start_timme , end_timme ); |
| | | 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} , 水位预测数据为空,请先保持水位预测服务正常运行", |
| | |
| | | start_timme, end_timme)); |
| | | return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = "预测数据获取失败,数据条无法匹配, 检查是否预测服务中断" }; |
| | | } |
| | | |
| | | |
| | | anaRequest.SpaceFlowOut = new List<double>(); |
| | | foreach(var r in water_records) |
| | | foreach (var r in water_records) |
| | | { |
| | | if(r.States == 0) |
| | | 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 |
| | | return new IStation.Dto.ApiResult<string>() |
| | | { |
| | | Code = ApiResultCode.Error, |
| | | Data = error_info11 |
| | | }; |
| | | } |
| | | anaRequest.SpaceFlowOut.Add(r.LastPredictValue/10000); |
| | | anaRequest.SpaceFlowOut.Add(r.LastPredictValue / 10000); |
| | | } |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(request.MaxReservoirLevelTime)) |
| | | anaRequest.MaxLimitWaterBoxTime = request.MaxReservoirLevelTime; |
| | | |
| | | |
| | | |
| | | |
| | | // |
| | | if (request.StartOpenCount == null) |
| | | //开始时的开机状态 |
| | | if (request.StartOpenPumpIndexArray == null) |
| | | { |
| | | anaRequest.StartOpenCount = -1; |
| | | IStation.LogHelper.Info(" 未设置开始时机泵开停状态 (Error: StartOpenPumpIndexArray is null)"); |
| | | return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = "未设置开始时机泵开停状态 (Error: StartOpenPumpIndexArray is null)" }; |
| | | } |
| | | else |
| | | { |
| | | anaRequest.StartOpenCount = request.StartOpenCount.Value; |
| | | } |
| | | anaRequest.IsKnownStartOpenPump = true; |
| | | anaRequest.StartOpenPumpIndexArray = request.StartOpenPumpIndexArray; |
| | | |
| | | |
| | | //陈行水库水位 |
| | | if (!string.IsNullOrEmpty(request.StartReservoirLevel)) |
| | | if (string.IsNullOrEmpty(request.StartReservoirLevel)) |
| | | { |
| | | anaRequest.CurrentWaterBoxLevel = Convert.ToDouble(request.StartReservoirLevel); |
| | | IStation.LogHelper.Info(" 未设置开始时水库水位 (Error: StartReservoirLevel is null)"); |
| | | return new IStation.Dto.ApiResult<string>() { Code = ApiResultCode.Error, Data = "未设置开始时水库水位 (Error: StartReservoirLevel is null) " }; |
| | | } |
| | | else |
| | | anaRequest.CurrentWaterBoxLevel = Convert.ToDouble(request.StartReservoirLevel); |
| | | if (anaRequest.CurrentWaterBoxLevel < 2) |
| | | { |
| | | anaRequest.CurrentWaterBoxLevel = ZyConnectHelper.GetRealReservoirWaterLevel(); |
| | | IStation.LogHelper.Info(string.Format(" 设置开始时水库水位的数据过小 (Error: StartReservoirLevel is {0}})", |
| | | anaRequest.CurrentWaterBoxLevel)); |
| | | return new IStation.Dto.ApiResult<string>() |
| | | { |
| | | Code = ApiResultCode.Error, |
| | | Data = string.Format(" 设置开始时水库水位的数据过小 (Error: StartReservoirLevel is {0}})", |
| | | anaRequest.CurrentWaterBoxLevel) |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | var calcHelper = new IStation.CalcPrjHelper(); |
| | | AnaPrj defaultPrj = null; |
| | | string error_info = calcHelper.Calc(anaRequest, out defaultPrj); |
| | | LogHelper.Info(error_info); |
| | | if (!string.IsNullOrEmpty(error_info) || defaultPrj == null) |
| | | { |
| | | IStation.LogHelper.Info(string.Format("Zy Prj Time:{0}-{1} , 计算错误, 原因是:{2} ,Request::: ", |
| | | start_timme, end_timme, error_info)+ JsonHelper.Object2Json( anaRequest)); |
| | | start_timme, end_timme, error_info) + JsonHelper.Object2Json(anaRequest)); |
| | | 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 Time:{0}-{1} , 计算成功", start_timme, end_timme)); |
| | | } |
| | | |
| | | //保存方案 |
| | |
| | | dto_prj.Items = new List<ZyDto.SubmitPrjItem>(); |
| | | foreach (var bt in defaultPrj.BlockTimes) |
| | | { |
| | | if (bt.OpenPumpCount == 0) |
| | | 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.OpenPumpCount; |
| | | dto_item.OpenPumpIndexs = IStation.AnaGlobalParas.Setting.GetOpenPumpIndexArrays(bt.OpenPumpCount); |
| | | dto_item.OpenPumpCount = bt.OpenPumpIndexs.Count; |
| | | dto_item.OpenPumpIndexs = bt.OpenPumpIndexs;// |
| | | |
| | | if (bt.PointTimes != null) |
| | | { |
| | | dto_item.Records = new List<SubmitPrjTime>(); |
| | | foreach (var bt2 in bt.PointTimes) |
| | | { |
| | | dto_item.Records.Add(new SubmitPrjTime(bt2)); |
| | | } |
| | | } |
| | | |
| | | |
| | | 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; |
| | | } |
| | | |
| | |
| | | IStation.Dto.ZyPrjAnaSetting dto_setting = new ZyPrjAnaSetting(); |
| | | dto_setting.MinOpenTimeMinute = model_setting.MinOpenTimeMinute; |
| | | dto_setting.MinSwitchTimeMinute = model_setting.MinSwitchTimeMinute; |
| | | dto_setting.MaxPumpSwitchCount = model_setting.MaxPumpSwitchCountQ; |
| | | dto_setting.MaxPumpSwitchCount = model_setting.MaxPumpSwitchCount; |
| | | dto_setting.OptSortType = model_setting.OptSortType; |
| | | dto_setting.OpenPumpIndexs = model_setting.OpenPumpIndexs; |
| | | dto_setting.OpenPumpIndexSequence = model_setting.OpenPumpIndexSequence; |
| | | dto_setting.ClosePumpIndexSequence = model_setting.ClosePumpIndexSequence; |
| | | dto_setting.SwitchPumpMinuteSpace = model_setting.SwitchPumpMinuteSpace; |
| | | dto_setting.OptimalPumpIndexSequence = model_setting.OptimalPumpIndexSequence; |
| | | |
| | | if (model_setting.SwitchPumpIgnoreTimes != null) |
| | | { |
| | |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "最大切泵次数 设置过长" }; |
| | | } |
| | | model_setting.MaxPumpSwitchCountQ = dto.MaxPumpSwitchCount; |
| | | |
| | | model_setting.MaxPumpSwitchCount = dto.MaxPumpSwitchCount; |
| | | if (dto.OptSortType >= 2) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "OptSortType 只能设置 0 或者 1, 0代表 用电量最少 1代表 电费最少" }; |
| | | } |
| | | model_setting.OptSortType = dto.OptSortType; |
| | | if (dto.SwitchPumpIgnoreTimes != null) |
| | | { |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | if (dto.OpenPumpIndexs != null) |
| | | |
| | | if (dto.OpenPumpIndexSequence != null) |
| | | { |
| | | List<int> penPumpIndexs = new List<int>(); |
| | | foreach (var ind in dto.OpenPumpIndexs) |
| | | foreach (var ind in dto.OpenPumpIndexSequence) |
| | | { |
| | | if (ind < 0 || ind > 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "机泵开泵顺序设置参数不合理" }; |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "开泵顺序设置参数不合理" }; |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | if (penPumpIndexs.Distinct().Count() != 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "机泵开泵顺序设置参数不合理" }; |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "开泵顺序设置参数不合理" }; |
| | | } |
| | | model_setting.OpenPumpIndexs = penPumpIndexs.ToArray(); |
| | | model_setting.OpenPumpIndexSequence = penPumpIndexs.ToArray(); |
| | | } |
| | | |
| | | if (dto.ClosePumpIndexSequence != null) |
| | | { |
| | | List<int> penPumpIndexs = new List<int>(); |
| | | foreach (var ind in dto.ClosePumpIndexSequence) |
| | | { |
| | | if (ind < 0 || ind > 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "关泵顺序设置参数不合理" }; |
| | | } |
| | | else |
| | | { |
| | | penPumpIndexs.Add(ind); |
| | | } |
| | | } |
| | | if (penPumpIndexs.Distinct().Count() != 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "关泵顺序设置参数不合理" }; |
| | | } |
| | | model_setting.ClosePumpIndexSequence = penPumpIndexs.ToArray(); |
| | | } |
| | | |
| | | if (dto.OptimalPumpIndexSequence != null) |
| | | { |
| | | List<int> penPumpIndexs = new List<int>(); |
| | | foreach (var ind in dto.OptimalPumpIndexSequence) |
| | | { |
| | | if (ind < 0 || ind > 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "调度泵优先度顺序设置参数不合理" }; |
| | | } |
| | | else |
| | | { |
| | | penPumpIndexs.Add(ind); |
| | | } |
| | | } |
| | | if (penPumpIndexs.Distinct().Count() != 5) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "调度泵优先度顺序设置参数不合理" }; |
| | | } |
| | | model_setting.OptimalPumpIndexSequence = penPumpIndexs.ToArray(); |
| | | } |
| | | |
| | | return new IStation.Dto.ApiResult<bool>(IStation.Common.AnaSetting.SaveSetting(model_setting)); |
| | | } |
| | | |