diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index cbe0548..cbf58c0 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -216,8 +216,21 @@ namespace FrontendWebApi.ApiControllers string sqlWhere = ""; string sqlGroup = ""; string sqlAvgRawData = ""; + string buildingSql = ""; + string tag_quantity = await backendRepository.GetOneAsync("select system_value from variable where system_type = 'obixConfig' and system_key = 'tag_quantity' and deleted = 0"); + + if (tag_quantity == "5") + buildingSql = " and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag "; + else + buildingSql = " and SUBSTRING_INDEX(SUBSTRING_INDEX(device_number, '_', 2), '_', -1) = @building_tag "; + if (input.floor_tag.Count > 0) - sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag "; + { + if (tag_quantity == "5") + sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag "; + else + sqlWhere = $@" and substring_index(substring_index(device_number, '_', 5), '_', -1) in @floor_tag "; + } if (input.tableType == "year") { @@ -242,7 +255,7 @@ namespace FrontendWebApi.ApiControllers ( select device_number from {table} - where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'RCV' and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag + where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'RCV' {buildingSql} {sqlWhere} group by device_number ) dn @@ -251,7 +264,7 @@ namespace FrontendWebApi.ApiControllers left join ( select device_number, {sqlAvgRawData} from {table} - where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'RCV' and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag + where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'RCV' {buildingSql} {sqlWhere} {sqlGroup} ) aemm on aemm.start_timestamp >= fd.date and aemm.end_timestamp < DATE_ADD(fd.date, INTERVAL +1 {input.tableType}) and aemm.device_number = fd.device_number order by fd.device_number, fd.date";