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