tangxu
2024-05-30 9d2e93a197a0babf0761d7517f43d9d83143218b
WebApi/Controllers/ZyPrjController.cs
@@ -91,40 +91,88 @@
                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)
            {
                if (string.IsNullOrEmpty(request.MaxReservoirLevel  ))
                {
                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入取水总量或水位要求" };
                }
            }
 
            IStation.LogHelper.Info(string.Format("Zy Prj  Time:{0}-{1} ,StartOpenCount:{2} ",
                start_timme, end_timme, request.StartOpenCount ));
            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.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;
@@ -134,38 +182,32 @@
                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;
                     }*/
                anaRequest.CurrentWaterBoxLevel = ZyConnectHelper.GetRealReservoirWaterLevel();
            }
            #endregion 陈行水库水位
            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);
            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));
                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 ));
            }
            //保存方案
@@ -386,7 +428,11 @@
                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)
            {