diff --git a/Backend/Controllers/DeviceManageController.cs b/Backend/Controllers/DeviceManageController.cs index 8254c88..6d10dd5 100644 --- a/Backend/Controllers/DeviceManageController.cs +++ b/Backend/Controllers/DeviceManageController.cs @@ -46,45 +46,46 @@ namespace Backend.Controllers //取得區域選單 var sql = $@"SELECT - bm.*, - b.full_name AS bFull_name, - b.priority AS bPriority, - ms.full_name AS mFull_name, - ms.priority AS mPriority, - ss.full_name AS sFull_name, - ss.priority AS sPriority + bm.*, + b.full_name AS bFull_name, + b.priority AS bPriority, + mv.system_key AS mFull_name, + mv.system_priority AS mPriority, + sv.system_key AS sFull_name, + sv.system_priority AS sPriority FROM building_menu bm - LEFT JOIN building b ON bm.building_guid = b.building_guid AND b.deleted = 0 - LEFT JOIN main_system ms ON bm.main_system_guid = ms.main_system_guid AND ms.deleted = 0 - LEFT JOIN sub_system ss ON bm.sub_system_guid = ss.sub_system_guid AND ss.deleted = 0"; + LEFT JOIN building b ON bm.building_tag = b.building_tag AND b.deleted = 0 + LEFT JOIN variable mv ON bm.main_system_tag = mv.system_value AND mv.deleted = 0 + LEFT JOIN variable sv ON bm.sub_system_tag = sv.system_value AND sv.deleted = 0"; if (!string.IsNullOrEmpty(filter)) { sql += $@" WHERE ( b.full_name LIKE CONCAT('%', @Filter, '%') - OR ms.full_name LIKE CONCAT('%', @Filter, '%') - OR ss.full_name LIKE CONCAT('%', @Filter, '%') + OR mv.system_key LIKE CONCAT('%', @Filter, '%') + OR sv.system_key LIKE CONCAT('%', @Filter, '%') )"; } - sql += $@" ORDER BY b.priority, ms.priority, ss.priority, ss.created_at DESC"; + sql += $@" ORDER BY b.priority, mv.system_priority, sv.system_priority, sv.created_at DESC"; var buildingMenuRawDatas = await backendRepository.GetAllAsync(sql, new { Filter = filter }); //取得系統小類樓層 var sub_sql = $@"SELECT - ssf.*, - f.full_name AS fFull_name, - f.InitMapName, - f.floor_map_name, - f.priority AS fPriority + ssf.*, + f.full_name AS fFull_name, + f.InitMapName, + f.floor_map_name, + f.priority AS fPriority FROM sub_system_floor ssf - LEFT JOIN floor f ON ssf.floor_guid = f.floor_guid AND f.deleted = 0 + LEFT JOIN floor f ON ssf.floor_tag = f.full_name AND ssf.building_tag = f.building_tag AND f.deleted = 0 WHERE ssf.deleted = 0 - ORDER BY f.priority, f.created_at"; + ORDER BY f.priority, f.created_at +"; var subSystemFloorRawDatas = await backendRepository.GetAllAsync(sub_sql); - var buildingMenu_Group_Building_guid = buildingMenuRawDatas.GroupBy(x => x.Building_guid).ToList(); + var buildingMenu_Group_Building_guid = buildingMenuRawDatas.GroupBy(x => x.building_tag).ToList(); List buildingCollapses = new List(); foreach (var buildingMenus_Building_guid in buildingMenu_Group_Building_guid) @@ -95,7 +96,7 @@ namespace Backend.Controllers buildingCollapse.Full_name = buildingMenus_Building_guid.First().bFull_name; buildingCollapse.Main_systems = new List(); - var buildingMenus_Group_Main_system_guid = buildingMenus_Building_guid.GroupBy(x => x.Main_system_guid).ToList(); + var buildingMenus_Group_Main_system_guid = buildingMenus_Building_guid.GroupBy(x => x.main_system_tag).ToList(); foreach (var buildingMenus_Main_system_guid in buildingMenus_Group_Main_system_guid) { @@ -104,7 +105,7 @@ namespace Backend.Controllers main_System.Full_name = buildingMenus_Main_system_guid.First().mFull_name; main_System.Sub_systems = new List(); - var buildingMenus_Group_Sub_system_guid = buildingMenus_Main_system_guid.GroupBy(x => x.Sub_system_guid).ToList(); + var buildingMenus_Group_Sub_system_guid = buildingMenus_Main_system_guid.GroupBy(x => x.sub_system_tag).ToList(); foreach (var buildingMenus_Sub_system_guid in buildingMenus_Group_Sub_system_guid) { @@ -113,9 +114,9 @@ namespace Backend.Controllers sub_System.Full_name = buildingMenus_Sub_system_guid.First().sFull_name; sub_System.Floors = new List(); - var floorRawDatas = subSystemFloorRawDatas.Where(x => x.Building_guid == buildingCollapse.Building_guid - && x.Main_system_guid == main_System.Main_system_guid - && x.Sub_system_guid == sub_System.Sub_system_guid).ToList(); + var floorRawDatas = subSystemFloorRawDatas.Where(x => x.building_tag == buildingCollapse.Building_guid + && x.main_system_tag == main_System.Main_system_guid + && x.sub_system_tag == sub_System.Sub_system_guid).ToList(); foreach (var floorRawData in floorRawDatas) { @@ -164,46 +165,41 @@ namespace Backend.Controllers { var sql = $@"SELECT - d.*, - d.full_name AS Device_full_name, - b.full_name AS Building_full_name, - ms.full_name AS Main_system_full_name, - ss.full_name AS Sub_system_full_name, - f.full_name AS Floor_full_name, - dk.device_image, - CONCAT('{baseURL}', '{deviceKindFilePath}', dk.device_image) AS device_image_url, - dk.device_close_color, - dk.device_normal_color, - dk.device_error_color, - dk.device_normal_flashing, - dk.device_close_flashing, - dk.device_error_flashing, - (SELECT - GROUP_CONCAT( IFNULL(system_key, ' '), ',') - FROM device_disaster dd - JOIN variable v ON v.deleted = 0 AND v.system_type = 'disaster' AND v.system_value = dd.device_system_value - WHERE dd.device_guid = d.device_guid - ) AS Device_disaster_type_text - FROM ( - SELECT * - FROM device d - WHERE - d.building_guid = @Building_guid - AND d.main_system_guid = @Main_system_guid - AND d.sub_system_guid = @Sub_system_guid - AND d.floor_guid = @Floor_guid - AND d.deleted = 0 - ) d - JOIN building b ON d.building_guid = b.building_guid - JOIN main_system ms ON d.main_system_guid = ms.main_system_guid - JOIN sub_system ss ON d.sub_system_guid = ss.sub_system_guid - JOIN floor f ON d.floor_guid = f.floor_guid - LEFT JOIN device_kind dk ON dk.device_building_tag = d.device_building_tag - AND dk.device_system_tag = d.device_system_tag - -- AND dk.device_floor_tag = d.device_floor_tag - AND dk.device_name_tag = d.device_name_tag - ORDER BY d.priority ASC, d.device_number ASC - "; + d.*, + d.device_last_name AS Device_full_name, + b.full_name AS Building_full_name, + mv.system_key AS Main_system_full_name, + sv.system_key AS Sub_system_full_name, + f.full_name AS Floor_full_name, + dk.device_image, + CONCAT('{baseURL}', '{deviceKindFilePath}', dk.device_image) AS device_image_url, + dk.device_close_color, + dk.device_normal_color, + dk.device_error_color, + dk.device_normal_flashing, + dk.device_close_flashing, + dk.device_error_flashing, + (SELECT + GROUP_CONCAT( IFNULL(system_key, ' '), ',') + FROM device_disaster dd + JOIN variable v ON v.deleted = 0 AND v.system_type = 'disaster' AND v.system_value = dd.device_system_value + WHERE dd.device_guid = d.device_guid + ) AS Device_disaster_type_text + FROM ( + SELECT * + FROM device d + WHERE d.device_building_tag = @building_tag + AND d.device_system_tag = @main_system_tag + AND d.device_name_tag = @sub_system_tag + AND d.device_floor_tag = @floor_tag + AND d.deleted = 0 + ) d + JOIN building b ON d.device_building_tag = b.building_tag + JOIN variable mv ON d.device_system_tag = mv.system_value AND mv.system_type = @main_system_type + JOIN variable sv ON d.device_name_tag = sv.system_value AND sv.system_type = @sub_system_type + JOIN floor f ON d.device_floor_tag = f.full_name AND d.device_building_tag = f.building_tag + LEFT JOIN device_kind dk ON dk.device_building_tag = d.device_building_tag AND dk.device_system_tag = d.device_system_tag AND dk.device_name_tag = d.device_name_tag + ORDER BY d.priority ASC, d.device_number ASC"; var devices = await backendRepository.GetAllAsync(sql, post); @@ -929,55 +925,54 @@ namespace Backend.Controllers { var sql = $@"SELECT - dk.device_kind_guid, - dd.device_building_tag, - dd.device_system_tag, - -- dd.device_floor_tag, - dd.device_name_tag, - dk.device_image, - dk.device_normal_text, - dk.device_normal_point_name, - dk.device_normal_point_col, - dk.device_normal_point_value, - dk.device_normal_color, - dk.device_normal_flashing, - dk.device_close_text, - dk.device_close_point_name, - dk.device_close_point_col, - dk.device_close_point_value, - dk.device_close_color, - dk.device_close_flashing, - dk.device_error_text, - dk.device_error_point_name, - dk.device_error_point_col, - dk.device_error_point_value, - dk.device_error_color, - dk.device_error_flashing, - dk.device_error_independent - FROM ( SELECT - d.device_building_tag, - d.device_system_tag, - -- d.device_floor_tag, - d.device_name_tag - FROM ( - SELECT * - FROM device d - WHERE - d.building_guid = @Building_guid - AND d.main_system_guid = @Main_system_guid - AND d.sub_system_guid = @Sub_system_guid - -- AND d.floor_guid = @Floor_guid - AND d.deleted = 0 - ) d - GROUP BY d.device_building_tag, - d.device_system_tag, - -- d.device_floor_tag, - d.device_name_tag) dd - LEFT JOIN device_kind dk ON dd.device_building_tag = dk.device_building_tag - AND dd.device_system_tag = dk.device_system_tag - -- AND dd.device_floor_tag = dk.device_floor_tag - AND dd.device_name_tag = dk.device_name_tag - "; + dk.device_kind_guid, + dd.device_building_tag, + dd.device_system_tag, + -- dd.device_floor_tag, + dd.device_name_tag, + dk.device_image, + dk.device_normal_text, + dk.device_normal_point_name, + dk.device_normal_point_col, + dk.device_normal_point_value, + dk.device_normal_color, + dk.device_normal_flashing, + dk.device_close_text, + dk.device_close_point_name, + dk.device_close_point_col, + dk.device_close_point_value, + dk.device_close_color, + dk.device_close_flashing, + dk.device_error_text, + dk.device_error_point_name, + dk.device_error_point_col, + dk.device_error_point_value, + dk.device_error_color, + dk.device_error_flashing, + dk.device_error_independent + FROM ( SELECT + d.device_building_tag, + d.device_system_tag, + -- d.device_floor_tag, + d.device_name_tag + FROM ( + SELECT * + FROM device d + WHERE + d.device_building_tag = @building_tag + AND d.device_system_tag = @main_system_tag + AND d.device_name_tag = @sub_system_tag + -- AND d.floor_guid = @Floor_guid + AND d.deleted = 0 + ) d + GROUP BY d.device_building_tag, + d.device_system_tag, + -- d.device_floor_tag, + d.device_name_tag) dd + LEFT JOIN device_kind dk ON dd.device_building_tag = dk.device_building_tag + AND dd.device_system_tag = dk.device_system_tag + -- AND dd.device_floor_tag = dk.device_floor_tag + AND dd.device_name_tag = dk.device_name_tag"; var deviceKinds = await backendRepository.GetAllAsync(sql, post); @@ -1335,30 +1330,28 @@ namespace Backend.Controllers try { var sql = $@"SELECT - dm.device_master_guid, - dd.device_building_tag, - dd.device_name_tag, - dm.device_master_number, - dm.device_master_full_name, - dm.device_master_icon - FROM ( SELECT - d.device_building_tag, - d.device_name_tag - FROM ( - SELECT * - FROM device d - WHERE - d.building_guid = @Building_guid - AND d.main_system_guid = @Main_system_guid - AND d.sub_system_guid = @Sub_system_guid - AND d.floor_guid = @Floor_guid - AND d.deleted = 0 - ) d - GROUP BY d.device_building_tag, - d.device_name_tag) dd - LEFT JOIN device_master dm ON dd.device_building_tag = dm.device_building_tag - AND dd.device_name_tag = dm.device_name_tag - "; + dm.device_master_guid, + dd.device_building_tag, + dd.device_name_tag, + dm.device_master_number, + dm.device_master_full_name, + dm.device_master_icon + FROM ( SELECT + d.device_building_tag, + d.device_name_tag + FROM ( + SELECT * + FROM device d + WHERE + d.device_building_tag = @building_tag + AND d.device_system_tag = @main_system_tag + AND d.device_name_tag = @sub_system_tag + AND d.device_floor_tag = @floor_tag + AND d.deleted = 0 + ) d + GROUP BY d.device_building_tag, d.device_name_tag) dd + LEFT JOIN device_master dm ON dd.device_building_tag = dm.device_building_tag + AND dd.device_name_tag = dm.device_name_tag"; var deviceMasters = await backendRepository.GetAllAsync(sql, post); diff --git a/Backend/Models/BuildingCollapse.cs b/Backend/Models/BuildingCollapse.cs index e559632..d7f17df 100644 --- a/Backend/Models/BuildingCollapse.cs +++ b/Backend/Models/BuildingCollapse.cs @@ -7,13 +7,13 @@ namespace Backend.Models { public class BuildingMenuRawData { - public string Building_guid { get; set; } + public string building_tag { get; set; } public string bFull_name { get; set; } public int bPriority { get; set; } - public string Main_system_guid { get; set; } + public string main_system_tag { get; set; } public string mFull_name { get; set; } public int mPriority { get; set; } - public string Sub_system_guid { get; set; } + public string sub_system_tag { get; set; } public string sFull_name { get; set; } public int sPriority { get; set; } } @@ -56,10 +56,10 @@ namespace Backend.Models public class SubSystemFloorRawData { - public string Sub_system_floor_guid { get; set; } - public string Building_guid { get; set; } - public string Main_system_guid { get; set; } - public string Sub_system_guid { get; set; } + public string id { get; set; } + public string building_tag { get; set; } + public string main_system_tag { get; set; } + public string sub_system_tag { get; set; } public string Floor_guid { get; set; } public string fFull_name { get; set; } public string InitMapName { get; set; } diff --git a/Backend/Models/Device.cs b/Backend/Models/Device.cs index f41df96..1956829 100644 --- a/Backend/Models/Device.cs +++ b/Backend/Models/Device.cs @@ -8,10 +8,10 @@ namespace Backend.Models { public class PostDeviceFilter { - public string Building_guid { get; set; } - public string Main_system_guid { get; set; } - public string Sub_system_guid { get; set; } - public string Floor_guid { get; set; } + public string building_tag { get; set; } + public string device_system_tag { get; set; } + public string device_name_tag { get; set; } + public string device_floor_tag { get; set; } } public class PostDeviceInfoAdd