duheng
2024-03-27 dc97e187c607119bbd2945b9a277db8da15f8dc0
WebApi/Controllers/PumpRunController.cs
@@ -1,7 +1,10 @@
using 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" };
        }