diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index 718a374..884e997 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -516,21 +516,25 @@ namespace FrontendWebApi.ApiControllers var wheres_str = string.Join(" AND ", wheres); - var sql = $@"SELECT + var sql = $@"SELECT DISTINCT a.device_guid, - b.full_name building_name, + c.full_name building_name, v1.system_key main_name, v2.system_key sub_name, a.full_name device_name, a.device_number from (SELECT * FROM device d - WHERE {wheres_str} - ) a - join building b on b.building_tag = a.device_building_tag + WHERE {wheres_str} + ) a + join device_item b on b.device_system_tag = a.device_system_tag + and b.device_building_tag COLLATE utf8mb4_unicode_ci = a.device_building_tag + and b.device_name_tag COLLATE utf8mb4_unicode_ci = a.device_name_tag + join building c on c.building_tag = a.device_building_tag join variable v1 on v1.system_value = a.device_system_tag and v1.deleted = 0 and v1.system_type = 'device_system_category_layer2' join variable v2 on v2.system_value = a.device_name_tag and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3' - order by b.priority,v1.system_priority,v2.system_priority,a.priority"; + where a.deleted = 0 and b.deleted = 0 and v2.deleted = 0 and v1.deleted = 0 and b.is_link = 1 and b.is_show_history = 1 + order by c.priority,v1.system_priority,v2.system_priority,a.priority"; var dbDevice = await backendRepository.GetAllAsync(sql, new { builds = postDevice.SelectBuildings, floor_tag = postDevice.SelectFloors, syss = postDevice.SelectSub, device_name = postDevice.Device_name }); apiResult.Data = dbDevice; @@ -572,7 +576,7 @@ namespace FrontendWebApi.ApiControllers join variable v1 on v1.system_value = b.device_system_tag and v1.deleted = 0 and v1.system_type = 'device_system_category_layer2' join variable v2 on v2.system_value = b.device_name_tag and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3' where a.deleted = 0 and b.deleted = 0 and v2.deleted = 0 and v1.deleted = 0 - and a.unit is not null and b.device_number in @Device_number and a.is_link = 1 and a.is_show_history = 1 + and b.device_number in @Device_number and a.is_link = 1 and a.is_show_history = 1 order by c.priority,b.priority;" , new { Device_number = postDevice.select_data.Select(a => a.device_number).ToList() } );