| | |
| | | { |
| | | 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 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> |
| | |
| | | public class ZyPrjController : ApiController |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// |
| | | /// </summary> |
| | | /// <param name="request"></param> |
| | | /// <returns></returns> |
| | |
| | | [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" }; |
| | | } |
| | |
| | | |
| | | 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" }; |
| | |
| | | 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小时" }; |
| | | } |
| | | if (request.TotalFlowIn == null) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "取水总量错误" }; |
| | | } |
| | | if (request.TotalFlowIn < 10000) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "注意取水总量单位是吨,当前参数参数过小" }; |
| | | 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.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.AnaGlobalParas.Setting.OptSortType; |
| | | |
| | | |
| | | |
| | | 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.TotalFlow取水总量 = request.TotalFlowIn; |
| | | |
| | | if(request.StartOpenCount == null) |
| | | |
| | | if (string.IsNullOrEmpty(request.TotalFlowIn)) |
| | | { |
| | | if (string.IsNullOrEmpty(request.MaxReservoirLevel)) |
| | | { |
| | | IStation.LogHelper.Info(string.Format("Zy Prj Time:{0}-{1} , 请输入取水总量或水位要求", |
| | | start_timme, end_timme )); |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入取水总量或水位要求" }; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | 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; |
| | | } |
| | | 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 ); |
| | | 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 = "水位预测数据为空,请先保持水位预测服务正常运行" }; |
| | | } |
| | | 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 = "预测数据获取失败,数据条无法匹配, 检查是否预测服务中断" }; |
| | | } |
| | | |
| | | anaRequest.SpaceFlowOut = new List<double>(); |
| | | 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.SpaceFlowOut.Add(r.LastPredictValue/10000); |
| | | } |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(request.MaxReservoirLevelTime)) |
| | | anaRequest.MaxLimitWaterBoxTime = request.MaxReservoirLevelTime; |
| | | |
| | | |
| | | |
| | | |
| | | // |
| | | if (request.StartOpenCount == null) |
| | | { |
| | | anaRequest.StartOpenCount = -1; |
| | | } |
| | |
| | | { |
| | | 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; |
| | | } |
| | | } |
| | | #endregion |
| | | anaRequest.CurrentWaterBoxLevel = ZyConnectHelper.GetRealReservoirWaterLevel(); |
| | | } |
| | | |
| | | 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); |
| | | 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 }; |
| | | IStation.LogHelper.Info(string.Format("Zy Prj Time:{0}-{1} , 计算错误, 原因是:{2} ,Request::: ", |
| | | 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 )); |
| | | } |
| | | |
| | | //保存方案 |
| | |
| | | var dto_prj = ToPrjDto(defaultPrj); |
| | | |
| | | #region 推送 |
| | | |
| | | if (!string.IsNullOrEmpty(request.IsSubmit) && Convert.ToBoolean(request.IsSubmit)) |
| | | { |
| | | Task.Run(() => { |
| | | Task.Run(() => |
| | | { |
| | | _ = ZyProjectHelper.SubmitPrj(defaultPrj); |
| | | }); |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #endregion 推送 |
| | | |
| | | return new IStation.Dto.ApiResult< IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success }; |
| | | return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success }; |
| | | } |
| | | |
| | | #region 换算成DTO |
| | | |
| | | private IStation.ZyDto.SubmitPrj ToPrjDto(AnaPrj defaultPrj) |
| | | { |
| | | IStation.ZyDto.SubmitPrj dto_prj = new ZyDto.SubmitPrj(); |
| | |
| | | dto_item.OpenPumpIndexs = IStation.AnaGlobalParas.Setting.GetOpenPumpIndexArrays(bt.OpenPumpCount); |
| | | dto_prj.Items.Add(dto_item); |
| | | } |
| | | if(defaultPrj.PointTimes != null) |
| | | if (defaultPrj.PointTimes != null) |
| | | { |
| | | dto_prj.Records = new List<SubmitPrjTime>(); |
| | | foreach(var bt in defaultPrj.PointTimes) |
| | | foreach (var bt in defaultPrj.PointTimes) |
| | | { |
| | | dto_prj.Records.Add(new SubmitPrjTime(bt)); |
| | | } |
| | | } |
| | | return dto_prj; |
| | | return dto_prj; |
| | | } |
| | | #endregion |
| | | |
| | | #endregion 换算成DTO |
| | | |
| | | /// <summary> |
| | | /// 获取某一天,最近一条 |
| | |
| | | [HttpGet] |
| | | public IStation.Dto.ApiResult GetHistoryByDay(string day) |
| | | { |
| | | if (string.IsNullOrEmpty(day )) |
| | | if (string.IsNullOrEmpty(day)) |
| | | { |
| | | 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) |
| | | 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="未找到项目" }; |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Alert, Message = "未找到项目" }; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取最近一条 |
| | |
| | | /// <returns></returns> |
| | | [Route("GetLastHistoryRecord")] |
| | | [HttpGet] |
| | | public IStation.Dto.ApiResult GetLastHistoryRecord( ) |
| | | { |
| | | public IStation.Dto.ApiResult GetLastHistoryRecord() |
| | | { |
| | | var dal = new IStation.DAL.AnaProject(); |
| | | var record = dal.GetLastRecord(); |
| | | if (record == null) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [Route("GetSetting")] |
| | | [HttpGet] |
| | |
| | | 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() |
| | | { |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | return new IStation.Dto.ApiResult<IStation.Dto.ZyPrjAnaSetting>(dto_setting); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// |
| | | /// </summary> |
| | | /// <param name="ana"></param> |
| | | /// <returns></returns> |
| | |
| | | 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 = "最少开泵时间 设置过少" }; |
| | |
| | | } |
| | | model_setting.MinSwitchTimeMinute = dto.MinSwitchTimeMinute; |
| | | |
| | | |
| | | |
| | | if (dto.MaxPumpSwitchCount < 1) |
| | | { |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "最大切泵次数 设置过少" }; |
| | |
| | | return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "最大切泵次数 设置过长" }; |
| | | } |
| | | model_setting.MaxPumpSwitchCountQ = 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) |
| | | { |
| | | 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 = "不许切泵时间 时间范围设置不合理" }; |
| | |
| | | { |
| | | 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 = "不许切泵时间 时间范围设置不合理" }; |
| | | } |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | if (dto.OpenPumpTimes != null) |
| | | { |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | 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 = "机泵开泵顺序设置参数不合理" }; |
| | | } |
| | |
| | | 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; |
| | |
| | | _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; |
| | | } |
| | | } |
| | | } |
| | | } |