From b4189107397fb4e2da2bd9343d0eb85d44918932 Mon Sep 17 00:00:00 2001 From: duheng <2784771470@qq.com> Date: 星期三, 29 五月 2024 09:18:10 +0800 Subject: [PATCH] 更新预测方案 --- WebApi/Controllers/PumpRunController.cs | 368 ++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 298 insertions(+), 70 deletions(-) diff --git a/WebApi/Controllers/PumpRunController.cs b/WebApi/Controllers/PumpRunController.cs index c9bee91..0aa14be 100644 --- a/WebApi/Controllers/PumpRunController.cs +++ b/WebApi/Controllers/PumpRunController.cs @@ -1,11 +1,17 @@ -锘縰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.IO; +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,8 +20,10 @@ [RoutePrefix("PumpRun")] public class PumpRunController : ApiController { + private bool isdebug = true; + /// <summary> - /// 鑾峰彇鏌愪竴澶╁疄闄呭弬鏁� + /// 鑾峰彇娉靛疄闄呰繍琛屽弬鏁�(涓�澶�) /// </summary> /// <param name="day"></param> /// <returns></returns> @@ -23,11 +31,6 @@ [HttpGet] 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,74 +40,97 @@ { 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); //鑾峰彇鏌愭鏃堕棿鐨勭敤鐢甸噺 + 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); + 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 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); //鍙栨按閲� - var debug = Common.PumpRunParasHelper.ReadPumpRunParas(d.AddDays(-15)); - if (debug == null) - { + /* 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); } - 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) + if (result != null) { - foreach (var item in debug.Pump1) - { - item.Electric = Math.Round(item.Electric, 2); - item.Money = Math.Round(item.Money, 2); - item.FlowIn = Math.Round(item.FlowIn, 2); - } + pumpRunParasHelper.Save(result, out string error); + // LogHelper.Info(error); } - if (debug.Pump2.Count != 0) + if (geterroer != null) { - foreach (var item in debug.Pump2) - { - item.Electric = Math.Round(item.Electric, 2); - item.Money = Math.Round(item.Money, 2); - item.FlowIn = Math.Round(item.FlowIn, 2); - } + LogHelper.Info(geterroer); } - if (debug.Pump3.Count != 0) - { - foreach (var item in debug.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) - { - foreach (var item in debug.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) - { - foreach (var item in debug.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>(debug) { Code = ApiResultCode.Success, Message = "Success" }; + return new IStation.Dto.ApiResult<Model.RunParasData>(result) { 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) + public IStation.Dto.ApiResult GetByHistoryOneDay(string day) { if (day == null) { @@ -116,10 +142,9 @@ return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; } - var history = Common.PumpRunParasHelper.ReadPumpRunParas(d); + 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); @@ -171,12 +196,14 @@ 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 async Task<IStation.Dto.ApiResult> GetOneDayData(string day) + public IStation.Dto.ApiResult GetOneDayPumpWaterData(string day) { if (day == null) { @@ -187,8 +214,209 @@ { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day 鏍煎紡涓嶆纭�" }; } + var WaterParas = Common.PumpRunParasHelper.ReadPumpWaterParas(d); - return new IStation.Dto.ApiResult<Model.RunParasData>() { Code = ApiResultCode.Success, Message = "Success" }; + 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" }; + } + + /// <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.GetTotalWaterByTimeRange_Out(Start, d, "1h"); //鍙栨按閲� + /* var one = TotalWater + .SelectMany(otdl => otdl.MonitorRecords); + var two = one.GroupBy(totalDay => totalDay.Time); + var three = two.Select(group => + { + var time = group.First().Time; // 浠庣粍涓幏鍙栨椂闂� + var totalSumForTimePoint = group.Sum(totalDay => totalDay.Value); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰 + return new { Time = time, Total = totalSumForTimePoint }; + });*/ + var totalSumByTimePoint = TotalWater + .SelectMany(otdl => otdl.MonitorRecords) + .GroupBy(totalDay => totalDay.Time) // 鎸夌収灏忔椂鍜屽垎閽熻繘琛屽垎缁� + .Select(group => + { + var time = group.First().Time; // 浠庣粍涓幏鍙栨椂闂� + 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<SSAData> totalOneDays = new List<SSAData>(); + foreach (var item in totalSumByTimePoint) + { + totalOneDays.Add(new SSAData() { DateTime = item.Time, Total = (double)item.Total }); + } + return new IStation.Dto.ApiResult<List<SSAData>>(totalOneDays) { Code = ApiResultCode.Success, Message = "Success" }; + } + + /// <summary> + /// 鑾峰彇渚涙按寮�鏈虹姸鎬� + /// </summary> + /// <param name="startday"></param> 寮�濮嬫棩鏈� + /// <param name="endday"></param> 缁撴潫鏃ユ湡 + /// <returns></returns> + [Route("GetPumpOpenState")] + [HttpGet] + public async Task<IStation.Dto.ApiResult> GetPumpOpenState(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 result = await ZyConnectHelper.GetPumpOpenStatusDay(Start, d, "1h"); + var totalSumByTimePoint = result + .SelectMany(otdl => otdl.MonitorRecords) + .GroupBy(totalDay => totalDay.Time) // 鎸夌収灏忔椂鍜屽垎閽熻繘琛屽垎缁� + .Select(group => + { + var time = group.First().Time; // 浠庣粍涓幏鍙栨椂闂� + var totalSumForTimePoint = group.Sum(totalDay => totalDay.Value); // 鍦ㄦ椂闂寸偣鍒嗙粍涓绠楁�诲拰 + return new { Time = time, Total = totalSumForTimePoint }; + }); + List<SSAData> totalOneDays = new List<SSAData>(); + foreach (var item in totalSumByTimePoint) + { + totalOneDays.Add(new SSAData() { DateTime = item.Time, Total = (double)item.Total }); + } + return new IStation.Dto.ApiResult<List<SSAData>>(totalOneDays) { Code = ApiResultCode.Success, Message = "Success" }; } } -} +} \ No newline at end of file -- Gitblit v1.9.3