From 330b1964f2d31e951952d6077a29f57dbea09125 Mon Sep 17 00:00:00 2001 From: dev02 Date: Thu, 8 Jun 2023 11:39:17 +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=A8api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/HydroMeterController.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index caa4637..cbe0548 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -75,9 +75,21 @@ namespace FrontendWebApi.ApiControllers string sqlGroup = ""; string sqlAvgRawData = ""; string dbDateName = startTime.Split("-")[0].ToString().PadLeft(4, '0') + startTime.Split("-")[1].ToString().PadLeft(2, '0'); + 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") { @@ -104,7 +116,7 @@ namespace FrontendWebApi.ApiControllers ( select device_number from {table} - where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag + where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' {buildingSql} {sqlWhere} group by device_number ) dn @@ -113,7 +125,7 @@ namespace FrontendWebApi.ApiControllers left join ( select device_number, {sqlAvgRawData} from {table} - where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag + where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' {buildingSql} {sqlWhere} {sqlGroup} ) aemm on aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} and aemm.device_number = fd.device_number order by fd.device_number, fd.date";