From 188dc425a6553cb60f1197ed939ba486295e4296 Mon Sep 17 00:00:00 2001 From: dev02 Date: Fri, 12 May 2023 11:06:55 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B0=B4=E9=9B=BB=E8=A1=A8=E5=8F=83=E6=95=B8=E8=BC=B8=E5=85=A5?= =?UTF-8?q?,=20=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=A9=A2sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/HydroMeterController.cs | 18 ++++++++++-------- FrontendWebApi/Models/HydroMeter.cs | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index 6782602..41eb223 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -55,15 +55,16 @@ namespace FrontendWebApi.ApiControllers { var startTime = input.tableType == "day" || input.tableType == "week" ? input.startTime + "-01" - : input.tableType == "month" ? input.startTime + "-01-01" - : null; ; + : input.tableType == "month" || input.tableType == "year" ? input.startTime + "-01-01" + : null; var endTime = input.tableType == "day" || input.tableType == "week" ? input.startTime.Split("-")[0] + "-" + (Int32.Parse(input.startTime.Split("-")[1]) + 1).ToString().PadLeft(2, '0') + "-01" : input.tableType == "month" ? (Int32.Parse(input.startTime.Split("-")[0]) + 1) + "-01-01" + : input.tableType == "year" ? input.endTime + "-01-01" : null; string sqlWhere = ""; - if (input.floor_tag != null) - sqlWhere = $@" and substring_index(device_number, '_', 3) = @floor_tag"; + if (input.floor_tag.Count > 0) + sqlWhere = $@" and substring_index(device_number, '_', 3) in @floor_tag"; var table = "archive_electric_meter_" + input.tableType; var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : input.tableType == "year" ? "%Y" : null; var sql = $@"select device_number, avg_rawdata, DATE_FORMAT(start_timestamp, @dateFormat) as timeStamp @@ -139,15 +140,16 @@ namespace FrontendWebApi.ApiControllers { var startTime = input.tableType == "day" || input.tableType == "week" ? input.startTime + "-01" - : input.tableType == "month" ? input.startTime + "-01-01" - : null; ; + : input.tableType == "month" || input.tableType == "month" ? input.startTime + "-01-01" + : null; var endTime = input.tableType == "day" || input.tableType == "week" ? input.startTime.Split("-")[0] + "-" + (Int32.Parse(input.startTime.Split("-")[1]) + 1).ToString().PadLeft(2, '0') + "-01" : input.tableType == "month" ? (Int32.Parse(input.startTime.Split("-")[0]) + 1) + "-01-01" + : input.tableType == "year" ? input.endTime + "-01-01" : null; string sqlWhere = ""; - if (input.floor_tag != null) - sqlWhere = $@" and substring_index(device_number, '_', 3) = @floor_tag"; + if (input.floor_tag.Count > 0) + sqlWhere = $@" and substring_index(device_number, '_', 3) in @floor_tag"; var table = "archive_water_meter_" + input.tableType; var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : null; var sql = $@"select device_number, avg_rawdata, DATE_FORMAT(start_timestamp, @dateFormat) as timeStamp diff --git a/FrontendWebApi/Models/HydroMeter.cs b/FrontendWebApi/Models/HydroMeter.cs index f130d28..3c63bc5 100644 --- a/FrontendWebApi/Models/HydroMeter.cs +++ b/FrontendWebApi/Models/HydroMeter.cs @@ -12,8 +12,9 @@ namespace FrontendWebApi.Models { public string tableType { get; set; } //day, week, month public string building_tag { get; set; } - public string floor_tag { get; set; } + public List floor_tag { get; set; } public string startTime { get; set; } + public string endTime { get; set; } } public class HydroMeterOutput