From 8840d501ed503e9d6fceab867f99f3bb1b7a55be Mon Sep 17 00:00:00 2001 From: dev02 Date: Wed, 17 May 2023 10:41:47 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=88=A4=E6=96=B7table=E5=AD=98=E5=9C=A8=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/HistoryController.cs | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index 52199d9..d72c193 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -1148,21 +1148,24 @@ namespace FrontendWebApi.ApiControllers { var device_number = hi.Device_number_point.Split(":")[0]; var point = hi.Device_number_point.Split(":")[1]; - //var tableName = await backgroundServiceMsSqlRepository.GetAllAsync($"select table_name from INFORMATION_SCHEMA.TABLES where table_name like '%{device_number}%'"); - var device_item_infos = await frontendRepository.GetAllAsync(sqlDeviceItemInfo, new { Device_number = hi.Device_number_point }); + var tableName = await backgroundServiceMsSqlRepository.GetOneAsync($"select table_name from INFORMATION_SCHEMA.TABLES where table_name like '%{device_number}_{point}%'"); + if (!string.IsNullOrEmpty(tableName)) + { + var device_item_infos = await frontendRepository.GetAllAsync(sqlDeviceItemInfo, new { Device_number = hi.Device_number_point }); - var device_item_info = device_item_infos.Where(x => x.Device_number == device_number && x.Points == point).FirstOrDefault(); + var device_item_info = device_item_infos.Where(x => x.Device_number == device_number && x.Points == point).FirstOrDefault(); - var sql = $@"select '{device_item_info.Building_name}' as Building_name, '{device_item_info.Main_system_name}' as Main_system_name, - '{device_item_info.Sub_system_name}' as Sub_system_name', {device_item_info.Device_number}' as Device_number, - '{device_item_info.Device_name}' as Device_name, '{device_item_info.Item_name}' as Item_name, '{device_item_info.Points}' as Points, - '{device_item_info.Unit}' as Unit, timestamp as Timestamp, round(value, 2) as Value - from FIC_CENTER_{device_number}_{point} - where replace(convert(varchar, [timestamp], 111), '/', '-') >= @startTime - and replace(convert(varchar, [timestamp], 111), '/', '-') <= @endTime order by timestamp"; - apiResult.Data.AddRange( - await backgroundServiceMsSqlRepository.GetAllAsync(sql, new { startTime = input.Start_timestamp, endTime = input.End_timestamp }) - ); + var sql = $@"select '{device_item_info.Building_name}' as Building_name, '{device_item_info.Main_system_name}' as Main_system_name, + '{device_item_info.Sub_system_name}' as Sub_system_name', {device_item_info.Device_number}' as Device_number, + '{device_item_info.Device_name}' as Device_name, '{device_item_info.Item_name}' as Item_name, '{device_item_info.Points}' as Points, + '{device_item_info.Unit}' as Unit, timestamp as Timestamp, round(value, 2) as Value + from FIC_CENTER_{device_number}_{point} + where replace(convert(varchar, [timestamp], 111), '/', '-') >= @startTime + and replace(convert(varchar, [timestamp], 111), '/', '-') <= @endTime order by timestamp"; + apiResult.Data.AddRange( + await backgroundServiceMsSqlRepository.GetAllAsync(sql, new { startTime = input.Start_timestamp, endTime = input.End_timestamp }) + ); + } //foreach (var tn in tableName) //{ //}