duheng
2025-02-11 0e57c17412761fc2f46566a8f32fd5c62e636366
WebApi/Controllers/ZyPrjController.cs
@@ -100,12 +100,16 @@
            anaRequest.StartTime = start_timme;
            anaRequest.EndTime = end_timme;
            anaRequest.WaterLevels长江 = GetTide3Day(_tideSouce, start_timme);
            if (anaRequest.WaterLevels长江 == null || anaRequest.WaterLevels长江.Count() == 0)
            {
                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "无法获取长江水位数据" };
            }
            #region 取水总量
            double TotalFlowIn = 0;
            if (!string.IsNullOrEmpty(request.TotalFlowIn) && !string.IsNullOrWhiteSpace(request.TotalFlowIn))
            {
                double TotalFlowIn = 0;
                if (!double.TryParse(request.TotalFlowIn, out TotalFlowIn))
                {
                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入数字型取水总量,接受到的输入值是:" + request.TotalFlowIn };
@@ -148,10 +152,10 @@
                {
                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入取水总量或水位要求" };
                }
                double TotalFlowIn = 0;
                if (!double.TryParse(request.TotalFlowIn, out TotalFlowIn))
                if (TotalFlowIn < 1000)
                {
                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入数字型取水总量,接受到的输入值是:" + request.TotalFlowIn };
                    return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "请输入取水总量,接受到的输入值是:" + request.TotalFlowIn };
                }
            }
@@ -166,6 +170,7 @@
            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);
@@ -201,10 +206,11 @@
                    anaRequest.PerHourFlowOut.Add(r.LastPredictValue);//计算中用吨
                }
                IStation.LogHelper.Info(
                    string.Format("获取水量预测值:  {0} ,  预测值总供水总量:{1} ",
                    string.Format("获取水量预测值:  {0} ,  预测值总供水总量:{1} ",
                    string.Join(",", anaRequest.PerHourFlowOut), TotalFlowOut预测值的供水总量));
                FlowTotalOut需求 = TotalFlowOut预测值的供水总量;
                isPredictRecord = true ;
                isPredictRecord = true;
                #endregion 用预测值
            }
            else
@@ -229,7 +235,7 @@
                anaRequest.PerHourFlowOut = list;
                FlowTotalOut需求 = TotalFlowOut手动输入需求;
                isPredictRecord = false ;
                isPredictRecord = false;
            }
            #endregion 供水量
@@ -276,11 +282,8 @@
                    anaRequest.StartReservoirLevel)
                };
            }
            //bool isTemp = false;
            //if (!string.IsNullOrEmpty(request.IsTemporary))
            //{
            //    isTemp = Convert.ToBoolean(request.IsTemporary);
            //}
            IStation.LogHelper.Info("kashi 计算取水总量 ");
            var calcHelper = new IStation.CalcPrjHelper();
            AnaPrj defaultPrj = null;
@@ -297,16 +300,14 @@
            }
            IStation.LogHelper.Info("-----------------------------END--------------------------------------");
            //保存方案
            //保存方案
            var ret = Common.HistoryAnaPrjFileHelper.SavePrj(IStation.AnaGlobalParas.Setting, isPredictRecord, anaRequest, defaultPrj);
            //
            var dto_prj = ToPrjDto(defaultPrj);
            dto_prj.FlowTotalOut = FlowTotalOut需求;
            #region 推送
            //推送:代码保留
            //if (!string.IsNullOrEmpty(request.IsSubmit) && Convert.ToBoolean(request.IsSubmit))
            //{
            //    Task.Run(() =>
@@ -315,9 +316,8 @@
            //    });
            //}
            #endregion 推送
            // IStation.LogHelper.Info(string.Format(" 产生计算方案:{0}", dto_prj.schemeID));
            //IStation.LogHelper.Info(string.Format(" 产生计算方案:{0}", dto_prj.schemeID));
            //IStation.LogHelper.Info(string.Format("Zy Prj  计算成功:  \r\n {0}  ", JsonHelper.Object2Json(dto_prj)));
            return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success };
        }
@@ -417,8 +417,6 @@
            }
        }
        /// <summary>
        ///  获取某一天,最近一条
        /// </summary>
@@ -437,7 +435,6 @@
            {
                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 格式不正确" };
            }
            IStation.CalcModel.AnaRequestBase requestBase = null;
            var prj = Common.HistoryAnaPrjFileHelper.GetByCreateDay(d, out requestBase);
@@ -449,6 +446,17 @@
                {
                    var sumFlow = (from x in requestBase.PerHourFlowOut select x).Sum();
                    dto_prj.FlowTotalOut = sumFlow;
                }
                if (dto_prj.Switchs != null)
                {
                    var switch2 = from x in dto_prj.Switchs orderby x.Time select x;
                    int index = 1;
                    foreach (var sw in switch2)
                    {
                        sw.Index = index;
                        index++;
                    }
                    dto_prj.Switchs = switch2.ToList();
                }
                return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success };
@@ -476,25 +484,35 @@
                IStation.LogHelper.Info(" api GetLastHistoryRecord is null ");
                return null;
            }
            IStation.CalcModel.AnaRequestBase requestBase = null;
            var prj = Common.HistoryAnaPrjFileHelper.GetByStartTime(record.StartTime, out requestBase);
            if (prj != null)
            {
            {
                var dto_prj = ToPrjDto(prj);
                if (requestBase != null && requestBase.PerHourFlowOut != null)
                {
                    var sumFlow = (from x in requestBase.PerHourFlowOut select x).Sum();
                    var sumFlow = (from x in requestBase.PerHourFlowOut.Take(24) select x).Sum();
                    dto_prj.FlowTotalOut = sumFlow;
                }
                if (dto_prj.Switchs != null)
                {
                    var switch2 = from x in dto_prj.Switchs orderby x.Time select x;
                    int index = 1;
                    foreach (var sw in switch2)
                    {
                        sw.Index = index;
                        index++;
                    }
                    dto_prj.Switchs = switch2.ToList();
                }
                return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success };
            }
            else
            {
                IStation.LogHelper.Info(string.Format(
                    " api GetLastHistoryRecord is null (未找到项目) LastRecord 信息: ID:{0}, StartTime:{1}, EndTime:{2}",
                    record.ID,
                    " api GetLastHistoryRecord is null (未找到项目) LastRecord 信息: ID:{0}, StartTime:{1}, EndTime:{2}",
                    record.ID,
                    record.StartTime, record.EndTime));
                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Alert, Message = "未找到项目" };
            }
@@ -520,14 +538,24 @@
            IStation.CalcModel.AnaRequestBase requestBase = null;
            var prj = Common.HistoryAnaPrjFileHelper.GetByStartTime(record.StartTime, out requestBase);
            if (prj != null)
            {
            {
                var dto_prj = ToPrjDto(prj);
                if (requestBase != null && requestBase.PerHourFlowOut != null )
                if (requestBase != null && requestBase.PerHourFlowOut != null)
                {
                    var sumFlow = (from x in requestBase.PerHourFlowOut select x).Sum();
                    dto_prj.FlowTotalOut = sumFlow;
                }
                if (dto_prj.Switchs != null)
                {
                    var switch2 = from x in dto_prj.Switchs orderby x.Time select x;
                    int index = 1;
                    foreach (var sw in switch2)
                    {
                        sw.Index = index;
                        index++;
                    }
                    dto_prj.Switchs = switch2.ToList();
                }
                return new IStation.Dto.ApiResult<IStation.ZyDto.SubmitPrj>(dto_prj) { Code = ApiResultCode.Success };
            }
            else
@@ -539,7 +567,6 @@
                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Alert, Message = "未找到项目" };
            }
        }
        /// <summary>
        ///
@@ -1001,7 +1028,7 @@
            dto_prj.MoneyTotal = Math.Round(defaultPrj.SumMoney, 0);
            dto_prj.BlockTimes = new List<ZyDto.SubmitPrjBlockTime>();
            double maxHeight = 0;
            double startHeight = 0;
            if (defaultPrj.BlockTimes != null)
@@ -1023,7 +1050,13 @@
                        dto_item.Records = new List<SubmitPrjTime>();
                        foreach (var bt2 in bt.PointTimes)
                        {
                            maxHeight = Math.Max(maxHeight, bt2.WaterLevelH);
                            //if(maxHeight < bt2.WaterLevelH)
                            //{
                            //    maxHeight = bt2.WaterLevelH;
                            //    //maxHeight = Math.Max(maxHeight, bt2.WaterLevelH);
                            //    maxHeightTime = bt2.Time;
                            //}
                            dto_item.Records.Add(new SubmitPrjTime(bt2));
                        }
                    }
@@ -1031,8 +1064,46 @@
                    dto_prj.BlockTimes.Add(dto_item);
                }
            }
            dto_prj.MaxWaterLevelH = maxHeight;
            dto_prj.StartWaterLevelH = startHeight;
            if (defaultPrj.MaxWaterLevelH <= 0)
            {
                double maxHeight = 0;
                DateTime maxHeightTime = defaultPrj.StartTime;
                if (defaultPrj.BlockTimes != null)
                {
                    foreach (var bt in defaultPrj.BlockTimes)
                    {
                        if (bt.OpenPumpIndexs == null)
                            continue;
                        if (bt.PointTimes != null)
                        {
                            foreach (var bt2 in bt.PointTimes)
                            {
                                if (maxHeight < bt2.WaterLevelH)
                                {
                                    maxHeight = bt2.WaterLevelH;
                                    //maxHeight = Math.Max(maxHeight, bt2.WaterLevelH);
                                    maxHeightTime = bt2.Time;
                                }
                            }
                        }
                    }
                }
                defaultPrj.MaxWaterLevelH = maxHeight;
                defaultPrj.MaxWaterLevelTime = maxHeightTime;
            }
            if (defaultPrj.MaxWaterLevelTime > defaultPrj.StartTime)
                dto_prj.MaxWaterLevelH = string.Format("{0:N2}  ({1})", Math.Round(defaultPrj.MaxWaterLevelH, 2),
                    defaultPrj.MaxWaterLevelTime.ToString("HH:mm"));
            else
                dto_prj.MaxWaterLevelH = string.Format("{0:N2} ", Math.Round(defaultPrj.MaxWaterLevelH, 2));
            //dto_prj.MaxWaterLevelH = defaultPrj.MaxWaterLevelH;
            //dto_prj.MaxWaterLevelTime = defaultPrj.MaxWaterLevelTime;
            dto_prj.StartWaterLevelH = string.Format("{0:N2}  ({1})", Math.Round(startHeight, 2),
                defaultPrj.StartTime.ToString("HH:mm")); ;
            dto_prj.Switchs = new List<SubmitPrjSwitchInfo>();
            if (defaultPrj.PumpSwitchs != null)
            {
@@ -1054,6 +1125,5 @@
        }
        #endregion 换算成DTO
    }
}