From 68da658e90864f503d97bc58a2a97f80d8e71065 Mon Sep 17 00:00:00 2001
From: tangxu <tangxu76880903>
Date: 星期五, 12 四月 2024 10:52:03 +0800
Subject: [PATCH] 添加众毅 接口日志

---
 WebApi/Controllers/PumpRunController.cs |  296 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 269 insertions(+), 27 deletions(-)

diff --git a/WebApi/Controllers/PumpRunController.cs b/WebApi/Controllers/PumpRunController.cs
index 35440b4..2d593a0 100644
--- a/WebApi/Controllers/PumpRunController.cs
+++ b/WebApi/Controllers/PumpRunController.cs
@@ -1,10 +1,12 @@
-锘縰sing IStation.Dto;
+锘縰sing IStation.Common;
+using IStation.Dto;
+using IStation.Model;
+using IStation.ZyModel;
 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
 {
     /// <summary>
@@ -13,45 +15,111 @@
     [RoutePrefix("PumpRun")]
     public class PumpRunController : ApiController
     {
-
-
-         /// <summary>
-        ///  鑾峰彇鏌愪竴澶╁弬鏁�
+        bool isdebug = true;
+        /// <summary>
+        ///  鑾峰彇娉靛疄闄呰繍琛屽弬鏁�(涓�澶�)
         /// </summary>
         /// <param name="day"></param>
         /// <returns></returns>
         [Route("GetByOneDay")]
         [HttpGet]
-        public async Task<IStation.Dto.ApiResult> GetByOneDay(string  startday)
+        public   async   Task< IStation.Dto.ApiResult>  GetByOneDay(string startday)
         {
+            if (startday == null)
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" };
+            }
             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);
-        //    pumpRunParasDay.Totalelectricity = PumpTotalElecty;
-            pumpRunParasDay.PumpRunTotalTime1 = PumpState[0];
-            pumpRunParasDay.PumpRunTotalTime2 = PumpState[0];
-            pumpRunParasDay.PumpRunTotalTime3 = PumpState[0];
-            pumpRunParasDay.PumpRunTotalTime4 = PumpState[0];
-            pumpRunParasDay.PumpRunTotalTime5 = PumpState[0];
+            if (d > DateTime.Now.AddDays(1))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "澶╂暟涓嶆纭�" };
+            }
+            RunParasData result = null;
+            PumpRunParasHelper pumpRunParasHelper = new PumpRunParasHelper();
+            result =   Common.PumpRunParasHelper.ReadPumpRunParas(d);
+            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 result.Pump1)
+                    {
+                        item.Electric = Math.Round(item.Electric, 2);
+                        item.Money = Math.Round(item.Money, 2);
+                        item.FlowIn = Math.Round(item.FlowIn, 2);
+                    }
+                }
+                if (result.Pump2.Count != 0)
+                {
+                    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 (result.Pump3.Count != 0)
+                {
+                    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 (result.Pump4.Count != 0)
+                {
+                    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 (result.Pump5.Count != 0)
+                {
+                    foreach (var item in result.Pump5)
+                    {
+                        item.Electric = Math.Round(item.Electric, 2);
+                        item.Money = Math.Round(item.Money, 2);
+                        item.FlowIn = Math.Round(item.FlowIn, 2);
+                    }
+                }
+            }
+            else 
+            {
+                var PumpTotalElecty = await ZyConnectHelper.GetPumpTotalElectricity(d, d);    //鑾峰彇鏌愭鏃堕棿鐨勭敤鐢甸噺
+                var PumpState = await ZyConnectHelper.GetPumpOpenStatusBySingleDay(d);  //鑾峰彇娉电殑寮�鏈烘儏鍐�             
+                var TotalWater = await ZyConnectHelper.GetTotalWaterByDayTimeRange_In(d, d);    //鍙栨按閲�
 
-            return new IStation.Dto.ApiResult<Dto.PumpRunParasDays>(pumpRunParasDay) { Code = ApiResultCode.Success, Message = "Success" };
+                /*        PumpHistoryDataFileHelper pumpHistoryDataFileHelper=new PumpHistoryDataFileHelper();
+                        var TotalWater = pumpHistoryDataFileHelper.GetAllWaterData();
+                        var PumpState = pumpHistoryDataFileHelper.getpumpstate();
+                        var PumpTotalElecty = pumpHistoryDataFileHelper.GetAllEleData();*/
+                result = pumpRunParasHelper.GetRunParasDatas(PumpState, TotalWater, PumpTotalElecty, d);
+             }
+            if (result != null)
+            {
+                pumpRunParasHelper.Save(result, out string error);
+              //  LogHelper.Info(error);
+            }
+            return new IStation.Dto.ApiResult<Model.RunParasData>(result) { Code = ApiResultCode.Success, Message = "Success" };
         }
 
-    /*    /// <summary>
-        /// 
+        /// <summary>
+        /// 鑾峰彇娉靛巻鍙茶繍琛屽弬鏁�
         /// </summary>
         /// <param name="day"></param>
         /// <returns></returns>
         [Route("GetByHistoryOneDay")]
         [HttpGet]
-        public async Task<IStation.Dto.ApiResult> GetByHistoryOneDay(string  day)
+        public  IStation.Dto.ApiResult  GetByHistoryOneDay(string day)
         {
             if (day == null)
             {
@@ -61,17 +129,191 @@
             if (!DateTime.TryParse(day, out d))
             {
                 return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
-            } 
+            }
 
-            var history = Common.PumpHistoryDataFileHelper.GetHistoryData(d);
-            return new IStation.Dto.ApiResult<List<RunParasData>>(history) { Code = ApiResultCode.Success, Message = "Success" };
+            var history =    Common.PumpRunParasHelper.ReadPumpRunParas(d);
+            if (history == null)
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "Data 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<Model.RunParasData>(history) { Code = ApiResultCode.Success, Message = "Success" };
         }
-*/
 
 
 
+        /// <summary>
+        /// 涓�澶╁唴鐨勬�诲彇姘撮噺鍜岀敤鐢甸噺
+        /// </summary>
+        /// <param name="day"></param>
+        /// <returns></returns>
+        [Route("GetOneDayData")]
+        [HttpGet]
+        public  IStation.Dto.ApiResult  GetOneDayPumpWaterData(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 WaterParas = Common.PumpRunParasHelper.ReadPumpWaterParas(d);
+
+            return new IStation.Dto.ApiResult<List<Model.PumpWater>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
+        }
 
 
 
+        /// <summary>
+        /// 鑾峰彇鏃堕棿娈靛唴鐨勫崟绠¢亾渚涙按鏁版嵁
+        /// </summary>
+        /// <param name="startday"></param>
+        /// <param name="endday"></param>
+        /// <param name="sign"></param>
+        /// <returns></returns>
+        [Route("GetPumpOutDayWater")]
+        [HttpGet]
+        public IStation.Dto.ApiResult  GetPumpOutWater(string startday,string endday,int sign)
+        {
+            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 End;
+            if (!DateTime.TryParse(endday, out End))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            var WaterParas = Common.PumpRunParasHelper.ReadPumpOutWater(Start,End, sign);
+
+            return new IStation.Dto.ApiResult<List<Model.OutList>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
+        }
+
+
+
+        /// <summary>
+        /// 鑾峰彇鎵�鏈夌殑鏈堝悎璁℃暟鎹�(鍗曠閬�)
+        /// </summary>
+        /// <returns></returns>
+        [Route("GetPumpOutMonthWater")]
+        [HttpGet]
+        public  IStation.Dto.ApiResult  GetPumpOutMonthWater()
+        {
+            var WaterParas = Common.PumpRunParasHelper.ReadPumpMonthOutWater();
+             return new IStation.Dto.ApiResult<List<Model.PumpOutWater>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
+        }
+
+
+
+        /// <summary>
+        /// 鑾峰彇澶╃殑鍚堝苟渚涙按鐬椂鏁版嵁(鎬荤)
+        /// </summary>
+        /// <param name="startday"></param> 寮�濮嬫棩鏈�
+        /// <param name="endday"></param> 缁撴潫鏃ユ湡
+        /// <returns></returns>
+        [Route("GetPumpTotalDayOutWater")]
+        [HttpGet]
+        public  IStation.Dto.ApiResult  GetPumpTotalDayOutWater(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 End;
+            if (!DateTime.TryParse(endday, out End))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            var WaterParas = Common.PumpRunParasHelper.ReadPumpAllDayOutWater(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("GetPumpTotalDayAccOutWater")]
+        [HttpGet]
+        public IStation.Dto.ApiResult  GetPumpTotalDayAccOutWater(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 End;
+            if (!DateTime.TryParse(endday, out End))
+            {
+                return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" };
+            }
+            var WaterParas = Common.PumpRunParasHelper.ReadPumpAllDayOutAccWater(Start, End);
+            return new IStation.Dto.ApiResult<List<Model.OutTotalOneDayList>>(WaterParas) { Code = ApiResultCode.Success, Message = "Success" };
+        }
     }
 }

--
Gitblit v1.9.3