From 39579aa528747af7ca7b17b04453095e2a27a009 Mon Sep 17 00:00:00 2001 From: tangxu <tangxu76880903> Date: 星期六, 04 五月 2024 17:48:09 +0800 Subject: [PATCH] 添加水量预测API接口 --- WebApi/Controllers/PumpRunController.cs | 137 ++++++++++++++++++++++++++++++++++++--------- 1 files changed, 108 insertions(+), 29 deletions(-) diff --git a/WebApi/Controllers/PumpRunController.cs b/WebApi/Controllers/PumpRunController.cs index 79b2d2c..2ad0236 100644 --- a/WebApi/Controllers/PumpRunController.cs +++ b/WebApi/Controllers/PumpRunController.cs @@ -1,11 +1,16 @@ -锘縰sing IStation.Dto; +锘縰sing IStation.CalcModel.Tide; +using IStation.Common; +using IStation.Dto; using IStation.Model; using IStation.ZyModel; using System; using System.Collections.Generic; +using System.Linq; using System.Security.Policy; using System.Threading.Tasks; using System.Web.Http; +using System.Web.Http.Results; + namespace IStation.WebApi.Controllers { /// <summary> @@ -14,6 +19,7 @@ [RoutePrefix("PumpRun")] public class PumpRunController : ApiController { + bool isdebug = true; /// <summary> /// 鑾峰彇娉靛疄闄呰繍琛屽弬鏁�(涓�澶�) /// </summary> @@ -21,13 +27,8 @@ /// <returns></returns> [Route("GetByOneDay")] [HttpGet] - public IStation.Dto.ApiResult GetByOneDay(string startday) + public async Task< IStation.Dto.ApiResult> GetByOneDay(string startday) { - List<RealScadaData> PumpState = new List<RealScadaData>(); - List<RealScadaData> TotalWater = new List<RealScadaData>(); - List<RealScadaData> PumpTotalElecty = new List<RealScadaData>(); - - Model.RunParasData runParasData = new Model.RunParasData(); if (startday == null) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" }; @@ -37,56 +38,58 @@ { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; } - // PumpState = await ZyConnectHelper.GetPumpOpenStatusBySingleDay(d); //鑾峰彇娉电殑寮�鏈烘儏鍐� - // totalWater = await ZyConnectHelper.GetTotalWaterByDayRange_In(d, d); - // pumpRunParasDay.TotalWater = totalWater; - // PumpTotalElecty = await ZyConnectHelper.GetPumpTotalElectricity(d, d); //鑾峰彇鏌愭鏃堕棿鐨勭敤鐢甸噺 - - var debug = Common.PumpRunParasHelper.ReadPumpRunParas(d.AddDays(-15)); - if (debug != null) + if (d > DateTime.Now.AddDays(1)) { - debug.Electric = Math.Round(debug.Electric, 2); - debug.Money = Math.Round(debug.Money, 2); - debug.FlowIn = Math.Round(debug.FlowIn, 2); - if (debug.Pump1.Count != 0) + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "澶╂暟涓嶆纭�" }; + } + RunParasData result = null; + PumpRunParasHelper pumpRunParasHelper = new PumpRunParasHelper(); + result = Common.PumpRunParasHelper.ReadPumpRunParas(d); + string geterroer=null; + if (result != null&& isdebug) + { + result.Electric = Math.Round(result.Electric, 2); + result.Money = Math.Round(result.Money, 2); + result.FlowIn = Math.Round(result.FlowIn, 2); + if (result.Pump1.Count != 0) { - foreach (var item in debug.Pump1) + foreach (var item in result.Pump1) { item.Electric = Math.Round(item.Electric, 2); item.Money = Math.Round(item.Money, 2); item.FlowIn = Math.Round(item.FlowIn, 2); } } - if (debug.Pump2.Count != 0) + if (result.Pump2.Count != 0) { - foreach (var item in debug.Pump2) + foreach (var item in result.Pump2) { item.Electric = Math.Round(item.Electric, 2); item.Money = Math.Round(item.Money, 2); item.FlowIn = Math.Round(item.FlowIn, 2); } } - if (debug.Pump3.Count != 0) + if (result.Pump3.Count != 0) { - foreach (var item in debug.Pump3) + foreach (var item in result.Pump3) { item.Electric = Math.Round(item.Electric, 2); item.Money = Math.Round(item.Money, 2); item.FlowIn = Math.Round(item.FlowIn, 2); } } - if (debug.Pump4.Count != 0) + if (result.Pump4.Count != 0) { - foreach (var item in debug.Pump4) + foreach (var item in result.Pump4) { item.Electric = Math.Round(item.Electric, 2); item.Money = Math.Round(item.Money, 2); item.FlowIn = Math.Round(item.FlowIn, 2); } } - if (debug.Pump5.Count != 0) + if (result.Pump5.Count != 0) { - foreach (var item in debug.Pump5) + foreach (var item in result.Pump5) { item.Electric = Math.Round(item.Electric, 2); item.Money = Math.Round(item.Money, 2); @@ -94,8 +97,28 @@ } } } - else { return null; } - return new IStation.Dto.ApiResult<Model.RunParasData>(debug) { Code = ApiResultCode.Success, Message = "Success" }; + else + { + var PumpTotalElecty = await ZyConnectHelper.GetPumpTotalElectricity(d, d); //鑾峰彇鏌愭鏃堕棿鐨勭敤鐢甸噺 + var PumpState = await ZyConnectHelper.GetPumpOpenStatusBySingleDay(d); //鑾峰彇娉电殑寮�鏈烘儏鍐� + var TotalWater = await ZyConnectHelper.GetTotalWaterByDayTimeRange_In(d, d); //鍙栨按閲� + + /* PumpHistoryDataFileHelper pumpHistoryDataFileHelper=new PumpHistoryDataFileHelper(); + var TotalWater = pumpHistoryDataFileHelper.GetAllWaterData(); + var PumpState = pumpHistoryDataFileHelper.getpumpstate(); + var PumpTotalElecty = pumpHistoryDataFileHelper.GetAllEleData();*/ + result = pumpRunParasHelper.GetRunParasDatas(PumpState, TotalWater, PumpTotalElecty, d,out geterroer); + } + if (result != null) + { + pumpRunParasHelper.Save(result, out string error); + // LogHelper.Info(error); + } + if (geterroer != null) + { + LogHelper.Info(geterroer); + } + return new IStation.Dto.ApiResult<Model.RunParasData>(result) { Code = ApiResultCode.Success, Message = "Success" }; } /// <summary> @@ -301,5 +324,61 @@ var WaterParas = Common.PumpRunParasHelper.ReadPumpAllDayOutAccWater(Start, End); return new IStation.Dto.ApiResult<List<Model.OutTotalOneDayList>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" }; } + + + + + /// <summary> + /// 鑾峰彇缁欓娴嬫按浣嶇敤鐨勬暟鎹殑鍘嗗彶鍙栨按閲� (浠庝紬姣�) + /// </summary> + /// <param name="startday"></param> 寮�濮嬫棩鏈� + /// <param name="endday"></param> 缁撴潫鏃ユ湡 + /// <returns></returns> + [Route("GetPumpHistoryData")] + [HttpGet] + public async Task< IStation.Dto.ApiResult > GetPumpHistoryData(string startday, string endday) + { + if (startday == null || endday == null) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" }; + } + DateTime Start; + if (!DateTime.TryParse(startday, out Start)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; + } + DateTime d; + if (!DateTime.TryParse(endday, out d)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; + } + var TotalWater = await ZyConnectHelper.GetTotalWaterByDayTimeRange_In(d, d); //鍙栨按閲� + // ReadPumpAllDayOutAccWater + // var TotalWater = PumpRunParasHelper.ReadPumpAllDayOutAccWater(d, d.AddDays(1)); + var totalSumByTimePoint = TotalWater + .SelectMany(otdl => otdl.MonitorRecords) + .GroupBy(totalDay => totalDay.Time.TimeOfDay) // 鎸夌収灏忔椂鍜屽垎閽熻繘琛屽垎缁� + .Select(group => + { + var time = group.First().Time.TimeOfDay; // 浠庣粍涓幏鍙栨椂闂� + var totalSumForTimePoint = group.Sum(totalDay => totalDay.Value); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰 + return new { Time = time, Total = totalSumForTimePoint }; + }); + /* var totalSumByTimePoint = TotalWater + .SelectMany(otdl => otdl.pumpOutWater) + .GroupBy(totalDay => totalDay.DateTime.TimeOfDay) // 鎸夌収灏忔椂鍜屽垎閽熻繘琛屽垎缁� + .Select(group => + { + var time = group.First().DateTime.TimeOfDay; // 浠庣粍涓幏鍙栨椂闂� + var totalSumForTimePoint = group.Sum(totalDay => totalDay.Total); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰 + return new { Time = time, Total = totalSumForTimePoint }; + });*/ + List< TotalOneDay > totalOneDays = new List< TotalOneDay >(); + foreach (var item in totalSumByTimePoint) + { + totalOneDays.Add(new TotalOneDay() { DateTime = d + item.Time, Total = (double)item.Total }); + } + return new IStation.Dto.ApiResult<List<TotalOneDay>>(totalOneDays) { Code = ApiResultCode.Success, Message = "Success" }; + } } } -- Gitblit v1.9.3