From dc97e187c607119bbd2945b9a277db8da15f8dc0 Mon Sep 17 00:00:00 2001 From: duheng <2784771470@qq.com> Date: 星期三, 27 三月 2024 13:51:36 +0800 Subject: [PATCH] 重新优化接口调取数据 --- WebApi/Controllers/PumpRunController.cs | 89 ++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 84 insertions(+), 5 deletions(-) diff --git a/WebApi/Controllers/PumpRunController.cs b/WebApi/Controllers/PumpRunController.cs index fddc42e..148bbb1 100644 --- a/WebApi/Controllers/PumpRunController.cs +++ b/WebApi/Controllers/PumpRunController.cs @@ -1,7 +1,10 @@ 锘縰sing IStation.Dto; using System; +using System.Collections.Generic; +using System.Security.Policy; using System.Threading.Tasks; using System.Web.Http; +using static IStation.Common.PumpHistoryDataFileHelper; namespace IStation.WebApi.Controllers { @@ -12,7 +15,7 @@ public class PumpRunController : ApiController { - Dto.PumpRunParasDays pumpRunParasDay = new Dto.PumpRunParasDays(); + /// <summary> /// 鑾峰彇鏌愪竴澶╁弬鏁� /// </summary> @@ -20,10 +23,15 @@ /// <returns></returns> [Route("GetByOneDay")] [HttpGet] - public async Task<IStation.Dto.ApiResult> GetByOneDay(DateTime startday) + public async Task<IStation.Dto.ApiResult> GetByOneDay(string startday) { - - var PumpState = await ZyConnectHelper.GetPumpIsopen(startday,startday); + DateTime d; + if (!DateTime.TryParse(startday, out d)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; + } + Dto.PumpRunParasDays pumpRunParasDay = new Dto.PumpRunParasDays(); + var PumpState = await ZyConnectHelper.GetPumpOpenStatusBySingleDay(d); // var totalWater = await ZyConnectHelper.GetTotalWaterByDayRange_In(startday, startday); // pumpRunParasDay.TotalWater = totalWater; // var PumpTotalElecty = await ZyConnectHelper.GetPumpTotalElectricity(startday, startday); @@ -37,8 +45,79 @@ return new IStation.Dto.ApiResult<Dto.PumpRunParasDays>(pumpRunParasDay) { Code = ApiResultCode.Success, Message = "Success" }; } + /// <summary> + /// + /// </summary> + /// <param name="day"></param> + /// <returns></returns> + [Route("GetByHistoryOneDay")] + [HttpGet] + public async Task<IStation.Dto.ApiResult> GetByHistoryOneDay(string day) + { + if (day == null) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" }; + } + DateTime d; + if (!DateTime.TryParse(day, out d)) + { + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; + } - + var history = Common.PumpRunParasHelper.GetPumpRunParas(d); + if (history == null) + { + } + history.Electric = Math.Round(history.Electric, 2); + history.Money = Math.Round(history.Money, 2); + history.FlowIn = Math.Round(history.FlowIn, 2); + if (history.Pump1.Count != 0) + { + foreach (var item in history.Pump1) + { + item.Electric = Math.Round( item.Electric,2); + item.Money = Math.Round(item.Money, 2); + item.FlowIn = Math.Round(item.FlowIn, 2); + } + } + if (history.Pump2.Count != 0) + { + foreach (var item in history.Pump2) + { + item.Electric = Math.Round(item.Electric, 2); + item.Money = Math.Round(item.Money, 2); + item.FlowIn = Math.Round(item.FlowIn, 2); + } + } + if (history.Pump3.Count != 0) + { + foreach (var item in history.Pump3) + { + item.Electric = Math.Round(item.Electric, 2); + item.Money = Math.Round(item.Money, 2); + item.FlowIn = Math.Round(item.FlowIn, 2); + } + } + if (history.Pump4.Count != 0) + { + foreach (var item in history.Pump4) + { + item.Electric = Math.Round(item.Electric, 2); + item.Money = Math.Round(item.Money, 2); + item.FlowIn = Math.Round(item.FlowIn, 2); + } + } + if (history.Pump5.Count != 0) + { + foreach (var item in history.Pump5) + { + item.Electric = Math.Round(item.Electric, 2); + item.Money = Math.Round(item.Money, 2); + item.FlowIn = Math.Round(item.FlowIn, 2); + } + } + return new IStation.Dto.ApiResult<Common.PumpRunParasHelper.RunParasData>(history) { Code = ApiResultCode.Success, Message = "Success" }; + } -- Gitblit v1.9.3