From 97270e48e35dbce006263f6dc5fa6b6d8f81d0f5 Mon Sep 17 00:00:00 2001 From: tangxu <tangxu76880903> Date: 星期五, 02 八月 2024 10:44:48 +0800 Subject: [PATCH] 123 --- WebApi/Controllers/TotalWaterInController.cs | 75 +++++++++++++++---------------------- 1 files changed, 31 insertions(+), 44 deletions(-) diff --git a/WebApi/Controllers/TotalWaterInController.cs b/WebApi/Controllers/TotalWaterInController.cs index 3fa0bef..a68c2fd 100644 --- a/WebApi/Controllers/TotalWaterInController.cs +++ b/WebApi/Controllers/TotalWaterInController.cs @@ -1,7 +1,7 @@ 锘縰sing IStation.Common; using IStation.Dto; -using IStation.ZyDto; -using Microsoft.Ajax.Utilities; +using IStation.Untity; +using IStation.ZyModel; using System; using System.Collections.Generic; using System.Linq; @@ -12,9 +12,7 @@ using System.Threading; using System.Threading.Tasks; using System.Web; -using System.Web.Http; -using System.Web.UI.WebControls; -using static IStation.ZyConnectHelper; +using System.Web.Http; namespace IStation.WebApi.Controllers { @@ -25,33 +23,33 @@ public class TotalWaterInController : ApiController { /// <summary> - /// + /// /// </summary> /// <param name="day"></param> /// <returns></returns> [Route("Test1")] [HttpGet] public async Task<IStation.Dto.ApiResult> Test1() - { + { var sum = await ZyConnectHelper.async_debug(); return new IStation.Dto.ApiResult<double>(sum); } /// <summary> - /// + /// /// </summary> /// <param name="day"></param> /// <returns></returns> [Route("Test2")] [HttpGet] - public IStation.Dto.ApiResult Test2() + public IStation.Dto.ApiResult Test2() { - var sum = ZyConnectHelper.async_debug().GetAwaiter().GetResult() ; + var sum = ZyConnectHelper.async_debug().GetAwaiter().GetResult(); return new IStation.Dto.ApiResult<double>(sum); } /// <summary> - /// + /// /// </summary> /// <param name="day"></param> /// <returns></returns> @@ -59,6 +57,8 @@ [HttpGet] public IStation.Dto.ApiResult GetByDayDebug(string day) { + if (ZyConnectHelper.isDebug) + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "Debug is Unacess " }; if (day == null) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" }; @@ -85,6 +85,8 @@ [HttpGet] public async Task<IStation.Dto.ApiResult> GetByDay(string day) { + if (ZyConnectHelper.isDebug) + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "Debug is Unacess " }; if (day == null) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" }; @@ -107,27 +109,22 @@ { var tagDict = new Dictionary<string, string> { - { "_0402010204012103002", "浜屽彇姘�1鍙锋车绱娴侀噺" }, - { "_0402010204012203002", "浜屽彇姘�2鍙锋车绱娴侀噺" }, - { "_0402010204012303002", "浜屽彇姘�3鍙锋车绱娴侀噺" }, - { "_0402010204012403002", "浜屽彇姘�4鍙锋车绱娴侀噺" }, - { "_0402010204012503002", "浜屽彇姘�5鍙锋车绱娴侀噺" }, + { "1#", "浜屽彇姘�1鍙蜂富姘存车.绱娴侀噺" }, + { "2#", "浜屽彇姘�2鍙蜂富姘存车.绱娴侀噺" }, + { "3#", "浜屽彇姘�3鍙蜂富姘存车.绱娴侀噺" }, + { "4#", "浜屽彇姘�4鍙蜂富姘存车.绱娴侀噺" }, + { "5#", "浜屽彇姘�5鍙蜂富姘存车.绱娴侀噺" }, }; - var input = new ScadaDispatchInput - { - search = "history", - starttime = new DateTime(dayD.Year, dayD.Month, dayD.Day, 0, 0, 0).ToString("G"), - endtime = new DateTime(dayD.Year, dayD.Month, dayD.Day, 23, 59, 59).ToString("G"), - Resolution = "300", - taglist = tagDict.Select(x => x.Key).ToArray() - }; + var starttime = new DateTime(dayD.Year, dayD.Month, dayD.Day, 0, 0, 0).ToString("G"); + var endtime = new DateTime(dayD.Year, dayD.Month, dayD.Day, 23, 59, 59).ToString("G"); if (dayD == DateTime.Today) { - input.endtime = DateTime.Now.AddMinutes(-5).ToString("G"); + endtime = DateTime.Now.AddMinutes(-5).ToString("G"); } - sum = 0; - var realScadaDataList = await GetRealScadaResult(input); + string joinedValues = string.Join(",", tagDict.Values); + var result = HttpClientHelper.Get<List<DataPoint>>(ZyConnectHelper.ZyApiUrl, starttime, endtime, "first", "300s", joinedValues); + var realScadaDataList = ZyConnectHelper.GetScadaData(result); if (realScadaDataList != null && realScadaDataList.Any()) { foreach (var r in realScadaDataList) @@ -152,8 +149,6 @@ return new IStation.Dto.ApiResult<double>(sum / 10000); } - - /// <summary> /// 鑾峰彇鏈�杩戜笁澶╃殑鍙栨按鎬婚噺 /// </summary> @@ -163,12 +158,13 @@ [HttpGet] public async Task<IStation.Dto.ApiResult> GetLastDay3() { + if (ZyConnectHelper.isDebug) + return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "Debug is Unacess " }; DateTime yest1 = DateTime.Today.AddDays(-1); var sum1 = TotalWaterInHelper.Read(yest1); if (sum1 < 0) { - sum1 = await ZyConnectHelper.GetTotalWaterByDay_In(yest1);//.GetAwaiter().GetResult(); - + sum1 = await ZyConnectHelper.GetTotalWaterByDay_In(yest1);//.GetAwaiter().GetResult(); TotalWaterInHelper.Save(yest1, sum1); } @@ -176,8 +172,7 @@ var sum2 = TotalWaterInHelper.Read(yest2); if (sum2 < 0) { - sum2 = await ZyConnectHelper.GetTotalWaterByDay_In(yest2) ;//.GetAwaiter().GetResult(); - + sum2 = await ZyConnectHelper.GetTotalWaterByDay_In(yest2);//.GetAwaiter().GetResult(); TotalWaterInHelper.Save(yest2, sum2); } @@ -192,9 +187,6 @@ return new IStation.Dto.ApiResult<List<double>>(new List<double> { sum1 / 10000, sum2 / 10000, sum3 / 10000 }); } - - - /// <summary> /// 鑾峰彇web瀹㈡埛绔痠p @@ -254,9 +246,8 @@ return userIP; } - - private string _url = "ws://192.168.201.17:40001"; + private async Task<List<ZyModel.RealScadaData>> Get(string inputJson) { if (string.IsNullOrEmpty(inputJson)) @@ -277,7 +268,7 @@ { IStation.LogHelper.Info("ws.SendAsync"); List<byte> outputBytes = new List<byte>();//鍏ㄩ儴娑堟伅瀹瑰櫒 - var buffer = new byte[1024 * 4];//缂撳啿鍖� + var buffer = new byte[1024 * 4];//缂撳啿鍖� var result = ws.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None).Result; //鐩戝惉Socket淇℃伅 while (!result.CloseStatus.HasValue) //鏄惁鍏抽棴 { @@ -341,9 +332,5 @@ } return realScadaDataList; } - - - - } -} +} \ No newline at end of file -- Gitblit v1.9.3