diff --git a/Backend/Controllers/BuildInfoController.cs b/Backend/Controllers/BuildInfoController.cs index f4e4265..9372572 100644 --- a/Backend/Controllers/BuildInfoController.cs +++ b/Backend/Controllers/BuildInfoController.cs @@ -19,8 +19,6 @@ namespace Backend.Controllers { private readonly IBackendRepository backendRepository; private string mapFileSaveAsPath = ""; - private string main_system_name = "device_system_category_layer2"; - private string sub_system_name = "device_system_category_layer1"; public BuildInfoController(IBackendRepository backendRepository) { @@ -546,7 +544,7 @@ namespace Backend.Controllers //判斷區域選單是否還有使用該樓層 var sub_system_where = $@"SELECT - CONCAT(b.full_name, ' - ', v1.system_key, ' - ', v2.system_key) + CONCAT(b.full_name, ' - ', mv.system_key, ' - ', sv.system_key) FROM ( SELECT ssf.building_tag, @@ -556,10 +554,10 @@ namespace Backend.Controllers WHERE ssf.deleted = 0 AND ssf.floor_tag = @floor_tag ) ssf LEFT JOIN building b ON ssf.building_tag = b.building_tag AND b.deleted = 0 - LEFT JOIN variable v1 ON ssf.main_system_tag = v1.system_value AND v1.system_type = @main_system_type AND v1.deleted = 0 - LEFT JOIN variable v2 ON ssf.sub_system_tag = v2.system_value AND v2.system_type = @sub_system_type AND v2.deleted = 0"; + LEFT JOIN variable mv ON ssf.main_system_tag = mv.system_value AND mv.system_type = @main_system_type AND mv.deleted = 0 + LEFT JOIN variable sv ON ssf.sub_system_tag = sv.system_value AND sv.system_type = @sub_system_type AND sv.deleted = 0"; - var sub_system_floors = await backendRepository.GetAllAsync(sub_system_where, new { floor_tag = buildFloor.Full_name, main_system_type = main_system_name, sub_system_type = sub_system_name }); + var sub_system_floors = await backendRepository.GetAllAsync(sub_system_where, new { floor_tag = buildFloor.Full_name, main_system_type = main_system_type, sub_system_type = sub_system_type }); if (sub_system_floors.Count > 0) { apiResult.Code = "9997"; diff --git a/Backend/Controllers/BuildMenuController.cs b/Backend/Controllers/BuildMenuController.cs index 22bdc87..0cf4590 100644 --- a/Backend/Controllers/BuildMenuController.cs +++ b/Backend/Controllers/BuildMenuController.cs @@ -29,7 +29,7 @@ namespace Backend.Controllers try { - var sqlString = @$"select building_guid as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY a.priority ASC, a.created_at DESC"; + var sqlString = @$"select building_tag as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY a.priority ASC, a.created_at DESC"; KeyValue = await backendRepository.GetAllAsync(sqlString); apiResult.Code = "0000"; @@ -45,15 +45,22 @@ namespace Backend.Controllers return apiResult; } [HttpPost] - public async Task>> MainListBybuild(string build) + public async Task>> MainListBybuild(string building_tag) { ApiResult> apiResult = new ApiResult>(); List KeyValue = new List(); try { - var sqlString = @$"select ms.main_system_guid value, ms.full_name name from (select main_system_guid from building_menu bm where bm.building_guid = '{build}' group by bm.main_system_guid ) bm left join main_system ms on ms.main_system_guid = bm.main_system_guid ORDER BY ms.priority ASC"; - KeyValue = await backendRepository.GetAllAsync(sqlString); + var sqlString = @$"select v.system_value value, v.system_key name + from ( + select main_system_tag from building_menu bm where bm.building_tag = @building_tag group by bm.main_system_tag + ) bm + left join variable v on v.system_value = bm.main_system_tag AND v.system_type = @main_system_type and v.deleted = 0 + ORDER BY v.system_priority ASC"; + + var param = new { building_tag = building_tag, main_system_type = main_system_type }; + KeyValue = await backendRepository.GetAllAsync(sqlString, param); apiResult.Code = "0000"; apiResult.Data = KeyValue; @@ -74,8 +81,13 @@ namespace Backend.Controllers List KeyValue = new List(); try { - var sqlString = @$"select ms.full_name Name,ms.main_system_guid Value from main_system ms where ms.deleted = 0 and ms.status = 0 ORDER BY ms.priority ASC"; - KeyValue = await backendRepository.GetAllAsync(sqlString); + var sqlString = @$"select system_key Name, system_value Value + from variable + where deleted = 0 and system_type = @main_system_type + ORDER BY system_priority ASC"; + + var param = new { main_system_type = main_system_type }; + KeyValue = await backendRepository.GetAllAsync(sqlString, param); apiResult.Code = "0000"; apiResult.Data = KeyValue; @@ -96,14 +108,16 @@ namespace Backend.Controllers List KeyValue = new List(); try { + var mainList = await backendRepository.GetAllAsync("select id from variable where system_value = @main_system_tag and system_type = @main_system_type", new { main_system_tag = post.main_system_tag, main_system_type = main_system_type}); var sqlString = @$"select - ss.sub_system_guid value,ss.full_name name - from sub_system ss - left join ( - select * from building_menu bm where bm.building_guid = '{post.build}') bm - on ss.sub_system_guid = bm.sub_system_guid - where bm.sub_system_guid is null and ss.deleted = 0 and ss.status = 0 and ss.main_system_guid = @guid ORDER BY ss.priority ASC, ss.created_at DESC"; - KeyValue = await backendRepository.GetAllAsync(sqlString, new { guid = post.main }); + sv.system_value value, sv.system_key name + from variable sv + left join ( + select * from building_menu bm where bm.building_tag = @building_tag + ) bm + on sv.system_value = bm.sub_system_tag + where bm.sub_system_tag is null and sv.deleted = 0 and sv.system_parent_id in @mainList ORDER BY sv.system_priority ASC, sv.created_at DESC"; + KeyValue = await backendRepository.GetAllAsync(sqlString, new { building_tag = post.building_tag, mainList = mainList}); apiResult.Code = "0000"; apiResult.Data = KeyValue; @@ -125,14 +139,16 @@ namespace Backend.Controllers ApiResult apiResult = new ApiResult(); try { - var get = await backendRepository.GetOneAsync("building_menu", $"building_guid = '{buildMenu.building_guid}' and main_system_guid = '{buildMenu.main_system_guid}' and sub_system_guid = '{buildMenu.sub_system_guid}'"); + var get = await backendRepository.GetOneAsync("building_menu", $"building_tag = '{buildMenu.building_tag}' and main_system_tag = '{buildMenu.main_system_tag}' and sub_system_tag = '{buildMenu.sub_system_tag}'"); if (get == null) { + var subV = await backendRepository.GetOneAsync("variable", "system_value = @sub_tag and system_type = @sub_system_type", new { sub_tag = buildMenu.sub_system_tag, sub_system_type = sub_system_type }); + var dictionary = new Dictionary() { - {"@building_guid", buildMenu.building_guid}, - {"@main_system_guid",buildMenu.main_system_guid }, - {"@sub_system_guid", buildMenu.sub_system_guid}, + {"@building_tag", buildMenu.building_tag}, + {"@main_system_tag",buildMenu.main_system_tag }, + {"@sub_system_tag", buildMenu.sub_system_tag}, {"@drawing",buildMenu.drawing }, {"@created_by",myUserInfo.Userinfo_guid }, {"@planimetric_click",buildMenu.planimetric_click} @@ -143,8 +159,8 @@ namespace Backend.Controllers if (buildMenu.system_url != null && buildMenu.system_url.CompareTo("http://") < 0 && buildMenu.system_url.CompareTo("https://") < 0) { //未包含http || https 抓該棟ip + port - var building_where = @"deleted = 0 AND building_guid = @Building_guid"; - var building = await backendRepository.GetOneAsync("building", building_where, new { Building_guid = buildMenu.building_guid }); + var building_where = @"deleted = 0 AND building_tag = @Building_tag"; + var building = await backendRepository.GetOneAsync("building", building_where, new { Building_tag = buildMenu.building_tag }); buildMenu.system_url = string.Format("http://{0}:{1}{2}", building.Ip_address, building.Ip_port, buildMenu.system_url); } @@ -156,8 +172,8 @@ namespace Backend.Controllers if (buildMenu.system_url != null && buildMenu.system_url.CompareTo("http://") < 0 && buildMenu.system_url.CompareTo("https://") < 0) { //未包含http || https 抓該棟ip + port - var building_where = @"deleted = 0 AND building_guid = @Building_guid"; - var building = await backendRepository.GetOneAsync("building", building_where, new { Building_guid = buildMenu.building_guid }); + var building_where = @"deleted = 0 AND building_tag = @Building_tag"; + var building = await backendRepository.GetOneAsync("building", building_where, new { Building_tag = buildMenu.building_tag }); buildMenu.system_url = string.Format("http://{0}:{1}{2}", building.Ip_address, building.Ip_port, buildMenu.system_url); } @@ -175,8 +191,14 @@ namespace Backend.Controllers await backendRepository.AddOneByCustomTable(dictionary, "building_menu"); - var max = await backendRepository.GetOneAsync("select Max(CONVERT(int,SUBSTRING(AuthCode,2,5))) AuthCode from auth_page ap where ap.AuthCode like 'F%'"); - var page = await backendRepository.GetOneAsync($"select ss.full_name SubName,ms.full_name MainName from sub_system ss left join main_system ms on ms.main_system_guid = ss.main_system_guid where ss.sub_system_guid = '{buildMenu.sub_system_guid}' and ms.main_system_guid = '{buildMenu.main_system_guid}'"); + var max = await backendRepository.GetOneAsync("select Max(CONVERT(SUBSTRING(AuthCode,2,5), SIGNED)) AuthCode from auth_page ap where ap.AuthCode like 'F%'"); + + var pageSql = $@"select sv.system_key SubName, mv.system_key MainName + from variable sv + left join variable mv on sv.system_parent_id = mv.id + where (sv.system_value = @sub_system_tag and sv.system_type = @sub_system_type) and (mv.system_value = @main_system_tag and mv.system_type = @main_system_type)"; + var pageParam = new { sub_system_tag = buildMenu.sub_system_tag, main_system_tag = buildMenu.main_system_tag, sub_system_type = sub_system_type, main_system_type = main_system_type}; + var page = await backendRepository.GetOneAsync(pageSql, pageParam); var pagedictionary = new Dictionary() { @@ -184,42 +206,26 @@ namespace Backend.Controllers {"@AuthType", 1 }, {"@MainName", page.MainName}, {"@SubName",page.SubName}, - {"@building_guid",buildMenu.building_guid}, - {"@ShowView",buildMenu.sub_system_guid} + {"@building_tag",buildMenu.building_tag}, + {"@ShowView",subV.id} }; await backendRepository.AddOneByCustomTable(pagedictionary, "auth_page"); + var param = new { main_system_type = main_system_type, sub_system_type = sub_system_type }; await backendRepository.ExecuteSql(@"DELETE FROM auth_page - WHERE auth_page.AuthCode like 'F%'; - INSERT INTO auth_page (AuthCode,AuthType,MainName,SubName,building_guid,ShowView) - SELECT 'F' + CONVERT(varchar,ROW_NUMBER() OVER(ORDER BY bm.building_guid ASC)) AuthCode,'1' AuthType,ms.full_name MainName,ss.full_name SubName,bm.building_guid,bm.sub_system_guid ShowView FROM building_menu bm - left join main_system ms on ms.main_system_guid = bm.main_system_guid - left join sub_system ss on ss.sub_system_guid = bm.sub_system_guid"); + WHERE auth_page.AuthCode like 'F%'; + INSERT INTO auth_page (AuthCode,AuthType,MainName,SubName,building_tag,ShowView) + SELECT concat('F', CONVERT(ROW_NUMBER() OVER(ORDER BY bm.building_tag ASC), nchar)) AuthCode, '1' as AuthType, + mv.system_key MainName, sv.system_key SubName, bm.building_tag, sv.id ShowView + FROM building_menu bm + LEFT JOIN variable mv ON bm.main_system_tag = mv.system_value AND mv.system_type = @main_system_type + LEFT JOIN variable sv ON bm.sub_system_tag = sv.system_value AND sv.system_type = @sub_system_type", param); await backendRepository.ExecuteSql(@"delete a from role_auth a join role b on a.role_guid = b.role_guid where b.layer = 0; INSERT INTO role_auth (role_guid,AuthCode,created_by) SELECT r.role_guid,ap.AuthCode,'0' created_by FROM auth_page ap,role r WHERE r.layer = 0;"); - #region 新增至派送資料表 - var sql = $@"SELECT ra.* FROM role_auth ra join role r on ra.role_guid = r.role_guid where r.layer = 0"; - var role_auths = await backendRepository.GetAllAsync(sql); - - List> role_auth_dicts = new List>(); - foreach (var role_auth in role_auths) - { - Dictionary role_auth_dict = new Dictionary() - { - { "role_guid", role_auth.Role_guid}, - { "@AuthCode", role_auth.AuthCode}, - }; - - role_auth_dicts.Add(role_auth_dict); - } - - await backendRepository.ManualInsertBackgroundServiceTask("", "", "role_auth", "purge_specify_insert", role_auth_dicts); - #endregion - apiResult.Code = "0000"; apiResult.Msg = "儲存成功"; } @@ -237,8 +243,8 @@ namespace Backend.Controllers if (buildMenu.system_url != null && buildMenu.system_url.CompareTo("http://") < 0 && buildMenu.system_url.CompareTo("https://") < 0) { //未包含http || https 抓該棟ip + port - var building_where = @"deleted = 0 AND building_guid = @Building_guid"; - var building = await backendRepository.GetOneAsync("building", building_where, new { Building_guid = buildMenu.building_guid }); + var building_where = @"deleted = 0 AND building_tag = @Building_tag"; + var building = await backendRepository.GetOneAsync("building", building_where, new { Building_tag = buildMenu.building_tag }); buildMenu.system_url = string.Format("http://{0}:{1}{2}", building.Ip_address, building.Ip_port, buildMenu.system_url); } @@ -250,8 +256,8 @@ namespace Backend.Controllers if (buildMenu.system_url != null && buildMenu.system_url.CompareTo("http://") < 0 && buildMenu.system_url.CompareTo("https://") < 0) { //未包含http || https 抓該棟ip + port - var building_where = @"deleted = 0 AND building_guid = @Building_guid"; - var building = await backendRepository.GetOneAsync("building", building_where, new { Building_guid = buildMenu.building_guid }); + var building_where = @"deleted = 0 AND building_tag = @Building_tag"; + var building = await backendRepository.GetOneAsync("building", building_where, new { Building_tag = buildMenu.building_tag }); buildMenu.system_url = string.Format("http://{0}:{1}{2}", building.Ip_address, building.Ip_port, buildMenu.system_url); } @@ -267,7 +273,7 @@ namespace Backend.Controllers dictionary.Add("@planimetric_floor_guid", buildMenu.planimetric_floor_guid); } - await backendRepository.UpdateOneByCustomTable(dictionary, "building_menu", $"building_guid = '{buildMenu.building_guid}' and main_system_guid = '{buildMenu.main_system_guid}' and sub_system_guid = '{buildMenu.sub_system_guid}'"); + await backendRepository.UpdateOneByCustomTable(dictionary, "building_menu", $"building_tag = '{buildMenu.building_tag}' and main_system_tag = '{buildMenu.main_system_tag}' and sub_system_tag = '{buildMenu.sub_system_tag}'"); apiResult.Code = "0000"; apiResult.Msg = "儲存成功"; @@ -291,15 +297,16 @@ namespace Backend.Controllers try { buildMenuTables = await backendRepository.GetAllAsync($@"select bm.*, - case drawing when 1 then '樓層平面圖' when 2 then '系統圖' when 4 then '昇位圖' end drawing_name, - case icon_click when 1 then '開' when 0 then '關' end icon_click_name, - case planimetric_click when 1 then '開' when 0 then '關' end planimetric_click_name, - ms.full_name main_system_guid_name, ss.full_name sub_system_guid_name,ff.full_name floor_guid_name - from building_menu bm - left join main_system ms on ms.main_system_guid = bm.main_system_guid - left join sub_system ss on ss.sub_system_guid = bm.sub_system_guid - left join floor ff on ff.floor_guid = bm.planimetric_floor_guid - where bm.building_guid = '{post.build}' and bm.main_system_guid in @MainList ORDER BY ms.priority ASC, ss.priority ASC, ss.created_at DESC ", new { MainList = post.MainList }); + case drawing when 1 then '樓層平面圖' when 2 then '系統圖' when 4 then '昇位圖' end drawing_name, + case icon_click when 1 then '開' when 0 then '關' end icon_click_name, + case planimetric_click when 1 then '開' when 0 then '關' end planimetric_click_name, + mv.system_key main_system_guid_name, sv.system_key sub_system_guid_name,ff.full_name floor_guid_name + from building_menu bm + left join variable mv on bm.main_system_tag = mv.system_value and mv.system_type = @main_system_type and mv.deleted = 0 + left join variable sv on bm.sub_system_tag = sv.system_value and sv.system_type = @sub_system_type and sv.deleted = 0 + left join floor ff on ff.floor_guid = bm.planimetric_floor_guid + where bm.building_tag = @building_tag and bm.main_system_tag in @MainList ORDER BY mv.system_priority ASC, sv.system_priority ASC, sv.created_at DESC ", + new { building_tag = post.building_tag, MainList = post.MainList, main_system_type = main_system_type, sub_system_type = sub_system_type }); apiResult.Code = "0000"; apiResult.Data = buildMenuTables; @@ -324,9 +331,11 @@ namespace Backend.Controllers try { var BuildMenu = await backendRepository.GetOneAsync( - $@"select *,ss.full_name sub_system_guid_name from building_menu bm - left join sub_system ss on bm.sub_system_guid = ss.sub_system_guid - where bm.building_guid = @bg and bm.main_system_guid = @msg and bm.sub_system_guid = @ssg", new { bg = post.build, msg = post.main, ssg = post.sub }); + $@"select *, sv.system_key sub_system_guid_name + from building_menu bm + left join variable sv on bm.sub_system_tag = sv.system_value and sv.system_type = @sub_system_type + where bm.building_tag = @building_tag and bm.main_system_tag = @main_system_tag and bm.sub_system_tag = @sub_system_tag" + , new { building_tag = post.building_tag, main_system_tag = post.main_system_tag, sub_system_tag = post.sub_system_tag, sub_system_type = sub_system_type }); apiResult.Code = "0000"; apiResult.Data = BuildMenu; } @@ -346,8 +355,9 @@ namespace Backend.Controllers ApiResult apiResult = new ApiResult(); try { - await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("building_menu", $"building_guid = '{post.build}' and main_system_guid = '{post.main}' and sub_system_guid = '{post.sub}'"); - var authcode = await backendRepository.GetOneAsync(@$"select AuthCode from auth_page where building_guid = '{post.build}' and ShowView = '{post.sub}'"); + await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("building_menu", $"building_tag = '{post.building_tag}' and main_system_tag = '{post.main_system_tag}' and sub_system_tag = '{post.sub_system_tag}'"); + var subV = await backendRepository.GetOneAsync(@$"select * from variable where system_value = @sub_system_tag and system_type = sub_system_type and deleted = 0", new { sub_system_tag = post.sub_system_tag, sub_system_type = sub_system_type }); + var authcode = await backendRepository.GetOneAsync(@$"select AuthCode from auth_page where building_tag = @building_tag and ShowView = @sub_id", new {post.building_tag, subV.id}); if (authcode != null) { await backendRepository.PurgeOneByGuidWithCustomDBNameAndTable("role_auth", $" AuthCode = '{authcode}'"); @@ -356,25 +366,6 @@ namespace Backend.Controllers INSERT INTO role_auth (role_guid,AuthCode,created_by) SELECT r.role_guid,ap.AuthCode,'0' created_by FROM auth_page ap,role r WHERE r.layer = 0;"); - - #region 新增至派送資料表 - var sql = $@"SELECT ra.* FROM role_auth ra join role r on ra.role_guid = r.role_guid where r.layer = 0"; - var role_auths = await backendRepository.GetAllAsync(sql); - - List> role_auth_dicts = new List>(); - foreach (var role_auth in role_auths) - { - Dictionary role_auth_dict = new Dictionary() - { - { "role_guid", role_auth.Role_guid}, - { "@AuthCode", role_auth.AuthCode}, - }; - - role_auth_dicts.Add(role_auth_dict); - } - - await backendRepository.ManualInsertBackgroundServiceTask("", "", "role_auth", "purge_specify_insert", role_auth_dicts); - #endregion } apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -396,13 +387,18 @@ namespace Backend.Controllers ApiResult> apiResult = new ApiResult>(); try { + var param = new { building_tag = post.building_tag, main_system_tag = post.main_system_tag, sub_system_tag = post.sub_system_tag, main_system_type = main_system_type, sub_system_type = sub_system_type }; buildMenuFloorTables = await backendRepository.GetAllAsync($@" - select f.full_name floor_guid_name,sf.*,ms.full_name main_system_guid_name,ss.full_name sub_system_guid_name - from (select * from sub_system_floor ssf where ssf.building_guid = '{post.build}' and ssf.main_system_guid = '{post.main}' and ssf.sub_system_guid = '{post.sub}' and deleted = 0 and status = 0) sf - left join floor f on sf.floor_guid = f.floor_guid - left join main_system ms on ms.main_system_guid = sf.main_system_guid - left join sub_system ss on ss.sub_system_guid = sf.sub_system_guid - ORDER BY ms.priority, ss.priority, f.priority"); + select sf.id sub_system_floor_id, f.full_name floor_guid_name, sf.*, mv.system_key main_system_guid_name, sv.system_key sub_system_guid_name + from ( + select * + from sub_system_floor ssf + where ssf.building_tag = @building_tag and ssf.main_system_tag = @main_system_tag and ssf.sub_system_tag = @sub_system_tag and deleted = 0 and status = 0 + ) sf + left join floor f on sf.floor_tag = f.full_name + left join variable mv on sf.main_system_tag = mv.system_value and mv.system_type = @main_system_type and mv.deleted = 0 + left join variable sv on sf.sub_system_tag = sv.system_value and sv.system_type = @sub_system_type and sv.deleted = 0 + ORDER BY mv.system_priority, sv.system_priority, f.priority", param); apiResult.Code = "0000"; apiResult.Data = buildMenuFloorTables; } @@ -426,12 +422,17 @@ namespace Backend.Controllers List KeyValue = new List(); try { - var sqlString = @$"select fg.floor_guid value, fg.full_name name from - (select * from floor fg where fg.building_guid = '{post.build}' and fg.deleted = 0 and fg.status = 0 ) fg - left join (select * from sub_system_floor where building_guid = '{post.build}' and main_system_guid = '{post.main}' and sub_system_guid = '{post.sub}' and deleted = 0 and status = 0) ssf - on ssf.floor_guid = fg.floor_guid - where ssf.floor_guid is null ORDER BY fg.priority"; - KeyValue = await backendRepository.GetAllAsync(sqlString); + var param = new { building_tag = post.building_tag, main_system_tag = post.main_system_tag, sub_system_tag = post.sub_system_tag }; + var sqlString = @$"select f.floor_guid value, f.full_name name + from ( + select * from floor f where f.building_tag = @building_tag and f.deleted = 0 and f.status = 0 + ) f + left join ( + select * from sub_system_floor where building_tag = @building_tag and main_system_tag = @main_system_tag and sub_system_tag = @sub_system_tag and deleted = 0 and status = 0 + ) ssf + on ssf.floor_tag = f.full_name + where ssf.floor_tag is null ORDER BY f.priority"; + KeyValue = await backendRepository.GetAllAsync(sqlString, param); apiResult.Code = "0000"; apiResult.Data = KeyValue; @@ -457,11 +458,11 @@ namespace Backend.Controllers { var dictionary = new Dictionary() { - {"@sub_system_floor_guid", Guid.NewGuid()}, - {"@building_guid",menuInfloor.build}, - {"@main_system_guid", menuInfloor.main}, - {"@sub_system_guid",menuInfloor.sub}, - {"@floor_guid",a}, + {"@building_tag", menuInfloor.building_tag}, + {"@main_system_tag", menuInfloor.main_system_tag}, + {"@sub_system_tag",menuInfloor.sub_system_tag}, + {"@floor_tag", a}, + {"@is_link", 1}, {"@created_by", myUserInfo.Userinfo_guid} }; listdictionary.Add(dictionary); @@ -481,32 +482,32 @@ namespace Backend.Controllers return apiResult; } [HttpPost] - public async Task> DeleteBuildFloorMenu(string subfloorguid) + public async Task> DeleteBuildFloorMenu(string sub_system_floor_id) { ApiResult apiResult = new ApiResult(); try { //檢查該樓層底下是否有設備 - var sql = $@" - SELECT - CONCAT(b.full_name, ' - ', ms.full_name, ' - ', ss.full_name , ' - ', f.full_name) - FROM device d - LEFT JOIN ( - SELECT * - FROM sub_system_floor ssf - WHERE ssf.deleted = 0 AND ssf.sub_system_floor_guid = @Guid) ssf - ON d.deleted = 0 - AND d.building_guid = ssf.building_guid - AND d.main_system_guid = ssf.main_system_guid - AND d.sub_system_guid = ssf.sub_system_guid - AND d.floor_guid = ssf.floor_guid - LEFT JOIN building b ON b.deleted = 0 AND d.building_guid = b.building_guid - LEFT JOIN main_system ms ON ms.deleted = 0 AND d.main_system_guid = ms.main_system_guid - LEFT JOIN sub_system ss ON ss.deleted = 0 AND d.sub_system_guid = ss.sub_system_guid - LEFT JOIN floor f ON f.deleted = 0 AND d.floor_guid = f.floor_guid - WHERE ssf.sub_system_floor_guid = @Guid"; + var sql = $@"SELECT + CONCAT(b.full_name, ' - ', mv.system_key, ' - ', sv.system_key, ' - ', f.full_name) + FROM device d + LEFT JOIN ( + SELECT * + FROM sub_system_floor ssf + WHERE ssf.deleted = 0 AND ssf.id = @sub_system_floor_id + ) ssf + ON d.deleted = 0 + AND d.device_building_tag = ssf.building_tag + AND d.device_system_tag = ssf.main_system_tag + AND d.device_name_tag = ssf.sub_system_tag + AND d.device_floor_tag = ssf.floor_tag + LEFT JOIN building b ON b.deleted = 0 AND d.device_building_tag = b.building_tag + LEFT JOIN variable mv on mv.deleted = 0 AND d.device_system_tag = mv.system_value AND mv.system_type = @main_system_type and mv.deleted = 0 + LEFT JOIN variable sv on sv.deleted = 0 AND d.device_name_tag = sv.system_value AND sv.system_type = @sub_system_type and sv.deleted = 0 + LEFT JOIN floor f ON f.deleted = 0 AND d.full_name = f.full_name + WHERE ssf.id = @sub_system_floor_id"; - var sub_system_floors = await backendRepository.GetAllAsync(sql, new { Guid = subfloorguid }); + var sub_system_floors = await backendRepository.GetAllAsync(sql, new { sub_system_floor_id = sub_system_floor_id, main_system_type = main_system_type, sub_system_type = sub_system_type }); if (sub_system_floors.Count > 0) { apiResult.Code = "9997"; @@ -514,7 +515,7 @@ namespace Backend.Controllers return apiResult; } - await backendRepository.DeleteOne(subfloorguid, "sub_system_floor", "sub_system_floor_guid"); + await backendRepository.DeleteOne(sub_system_floor_id, "sub_system_floor", "id"); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; } @@ -522,7 +523,7 @@ namespace Backend.Controllers { apiResult.Code = "9999"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - string json = System.Text.Json.JsonSerializer.Serialize(subfloorguid); + string json = System.Text.Json.JsonSerializer.Serialize(sub_system_floor_id); Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } @@ -536,10 +537,12 @@ namespace Backend.Controllers List KeyValue = new List(); try { - var sqlString = @$"select floor.floor_guid Value,floor.full_name Name from sub_system_floor sf left join floor on sf.floor_guid = floor.floor_guid - where sf.deleted = 0 and sf.status = 0 and sf.building_guid = '{post.build}' and sf.main_system_guid = '{post.main}' and sf.sub_system_guid = '{post.sub}' - ORDER BY floor.priority, floor.created_at"; - KeyValue = await backendRepository.GetAllAsync(sqlString); + var sqlString = @$"select f.floor_guid Value, f.full_name Name + from sub_system_floor sf + left join floor f on sf.floor_tag = f.full_name + where sf.deleted = 0 and sf.status = 0 and sf.building_tag = @building_tag and sf.main_system_tag = @main_system_tag and sf.sub_system_tag = @sub_system_tag + ORDER BY f.priority, f.created_at"; + KeyValue = await backendRepository.GetAllAsync(sqlString, new { building_tag = post.building_tag, main_system_tag = post.main_system_tag, sub_system_type = post.sub_system_tag }); apiResult.Code = "0000"; apiResult.Data = KeyValue; diff --git a/Backend/Controllers/MybaseController.cs b/Backend/Controllers/MybaseController.cs index 700dbbb..13ea16b 100644 --- a/Backend/Controllers/MybaseController.cs +++ b/Backend/Controllers/MybaseController.cs @@ -31,6 +31,9 @@ namespace Backend.Controllers protected MyUserInfo myUserInfo = null; public string controllerName; public string actionName; + public string main_system_type = "device_system_category_layer2"; + public string sub_system_type = "device_system_category_layer3"; + public MybaseController() { } public override void OnActionExecuting(ActionExecutingContext filterContext) { diff --git a/Backend/Controllers/SystemCategoryController.cs b/Backend/Controllers/SystemCategoryController.cs index a907bbe..70ffcde 100644 --- a/Backend/Controllers/SystemCategoryController.cs +++ b/Backend/Controllers/SystemCategoryController.cs @@ -13,8 +13,6 @@ namespace Backend.Controllers { private readonly IBackendRepository backendRepository; - private string main_system_name = "device_system_category_layer2"; - private string sub_system_name = "device_system_category_layer1"; public SystemCategoryController(IBackendRepository backendRepository) { @@ -39,7 +37,7 @@ namespace Backend.Controllers { var sWhere = "deleted = 0 AND system_type = @System_type"; - var param = new { System_type = main_system_name }; + var param = new { System_type = main_system_type }; var systemMainList = await backendRepository.GetAllAsync("variable", sWhere, param, "system_priority ASC, created_at DESC"); @@ -108,13 +106,13 @@ namespace Backend.Controllers //新增 //獲取最新的大類 sWhere = @$"deleted = @Deleted AND system_type = @System_type"; - param = new { Deleted = 0, System_type = main_system_name }; + param = new { Deleted = 0, System_type = main_system_type }; var sOrder = @"id DESC LIMIT 1"; var latestVariable = await backendRepository.GetOneAsync("variable", sWhere, param, sOrder); Dictionary variableMainDic = new Dictionary() { - { "@system_type", main_system_name}, + { "@system_type", main_system_type}, { "@system_key", post.System_key}, { "@system_value", post.system_value}, { "@system_remark", "系統類別(第2層)"}, @@ -142,8 +140,8 @@ namespace Backend.Controllers var AuthCodes = await backendRepository.GetAllAsync( @$"select AuthCode from auth_page ap - join variable sv on ap.ShowView = sv.system_value and sv.system_type = 'device_system_category_layer1' - where sv.id = '{systemMain.id}'"); + join variable sv on ap.ShowView = sv.id and sv.system_type = 'device_system_category_layer1' + where sv.system_parent_id = '{systemMain.id}'"); if(AuthCodes.Count > 0) { @@ -324,17 +322,17 @@ namespace Backend.Controllers //產生一組GUID //獲取最新的大類 sWhere = @$"deleted = @Deleted AND system_type = @System_type"; - param = new { Deleted = 0, System_type = sub_system_name }; + param = new { Deleted = 0, System_type = sub_system_type }; var sOrder = @"id DESC LIMIT 1"; var latestVariable = await backendRepository.GetOneAsync("variable", sWhere, param, sOrder); Dictionary systemSubDic = new Dictionary() { - { "@system_type", sub_system_name}, + { "@system_type", sub_system_type}, { "@system_key", post.System_key}, { "@system_value", post.system_value}, { "@system_parent_id", post.system_parent_id}, - { "@system_remark", "系統類別(第1層)"}, + { "@system_remark", "系統類別(第3層)"}, { "@system_priority", latestVariable.system_priority + 1}, { "@created_by", myUserInfo.Userinfo_guid}, { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} @@ -411,12 +409,12 @@ namespace Backend.Controllers //檢查是否有未刪除的區域選單 var sbuildMenu = $@"SELECT - CONCAT(b.full_name, ' - ', v2.system_key) + CONCAT(b.full_name, ' - ', sv.system_key) FROM building_menu bm LEFT JOIN building b ON bm.building_tag = b.building_tag AND b.deleted = 0 - LEFT JOIN variable v1 ON bm.sub_system_tag = v1.system_value AND v1.deleted = 0 - LEFT JOIN variable v2 ON v1.system_parent_id = v2.id AND v1.deleted = 0 - WHERE v1.id = @id"; + LEFT JOIN variable sv ON bm.sub_system_tag = sv.system_value AND sv.deleted = 0 + LEFT JOIN variable mv ON sv.system_parent_id = mv.id AND mv.deleted = 0 + WHERE sv.id = @id"; var buildMenus = await backendRepository.GetAllAsync(sbuildMenu, new { id = id }); if (buildMenus.Count > 0) @@ -429,13 +427,13 @@ namespace Backend.Controllers //檢查是否有未刪除的系統小類樓層 var ssubSystemFloor = $@"SELECT - CONCAT(b.full_name, ' - ', v1.full_name, ' - ', v2.full_name, ' - ', f.full_name) + CONCAT(b.full_name, ' - ', mv.full_name, ' - ', sv.full_name, ' - ', f.full_name) FROM sub_system_floor ssf LEFT JOIN building b ON ssf.building_tag = b.building_tag AND b.deleted = 0 - LEFT JOIN variable v2 ON v2.system_value = ssf.sub_system_tag AND v2.deleted = 0 - LEFT JOIN variable v1 ON v1.system_parent_id = v1.id AND v1.deleted = 0 + LEFT JOIN variable sv ON sv.system_value = ssf.sub_system_tag AND sv.deleted = 0 + LEFT JOIN variable mv ON sv.system_parent_id = mv.id AND mv.deleted = 0 LEFT JOIN floor f ON ssf.floor_guid = f.floor_guid AND f.deleted = 0 - WHERE v2.id = @id AND ssf.deleted = 0"; + WHERE sv.id = @id AND ssf.deleted = 0"; var subSystemFloor = await backendRepository.GetAllAsync(sbuildMenu, new { id = id }); if (subSystemFloor.Count > 0) @@ -450,8 +448,8 @@ namespace Backend.Controllers var sdeviceItem = $@"SELECT di.full_name FROM device_item di - INNER JOIN variable v on di.device_name_tag = v.system_value - WHERE v.deleted = 0 AND v.id = @id AND di.deleted = 0"; + INNER JOIN variable sv on di.device_name_tag = sv.system_value + WHERE v.deleted = 0 AND sv.id = @id AND di.deleted = 0"; var deviceItems = await backendRepository.GetAllAsync(sdeviceItem, new { id = id }); if (deviceItems.Count > 0) @@ -568,9 +566,9 @@ namespace Backend.Controllers var sql = @"SELECT di.* FROM device_item di - JOIN variable v1 ON di.device_name_tag = v1.system_value - JOIN variable v2 ON v1.system_parent_id = v2.id AND di.device_system_tag = v2.system_value - WHERE v1.id = @id AND di.deleted = @Deleted"; + JOIN variable sv ON di.device_name_tag = sv.system_value + JOIN variable mv ON sv.system_parent_id = mv.id AND di.device_system_tag = mv.system_value + WHERE sv.id = @id AND di.deleted = @Deleted"; object param = new { Deleted = 0, id = id }; @@ -720,13 +718,13 @@ namespace Backend.Controllers unionsql += " union "; } } - var sql = @$"select v1.system_key msname, b.full_name bname, v2.system_key subname,de.device_last_name as device_name_tag from + var sql = @$"select mv.system_key msname, b.full_name bname, sv.system_key subname,de.device_last_name as device_name_tag from ({unionsql}) de - left join variable v1 on v1.system_value = de.device_system_tag and v1.system_type = @main_system_type + left join variable mv on mv.system_value = de.device_system_tag and mv.system_type = @main_system_type left join building b on b.building_tag = de.building_tag - left join variable v2 on v2.system_value = de.device_name_tag and v1.system_type = @sub_system_type"; + left join variable sv on sv.system_value = de.device_name_tag and sv.system_type = @sub_system_type"; - var param = new { main_system_type = main_system_name, sub_system_type = sub_system_name}; + var param = new { main_system_type = main_system_type, sub_system_type = sub_system_type}; var names = await backendRepository.GetAllAsync(sql, param); var count = 0; foreach (var name in names) diff --git a/Backend/Models/BuildMenu.cs b/Backend/Models/BuildMenu.cs index f677e56..4173361 100644 --- a/Backend/Models/BuildMenu.cs +++ b/Backend/Models/BuildMenu.cs @@ -7,9 +7,9 @@ namespace Backend.Models { public class BuildMenu : Actor { - public string building_guid { get; set; } - public string main_system_guid { get; set; } - public string sub_system_guid { get; set; } + public string building_tag { get; set; } + public string main_system_tag { get; set; } + public string sub_system_tag { get; set; } public byte drawing { get; set; } public byte icon_click { get; set; } public string icon_click_url { get; set; } @@ -27,11 +27,13 @@ namespace Backend.Models public class SubListIn { public string main { get; set; } + public string main_system_tag { get; set; } public string build { get; set; } + public string building_tag { get; set; } } public class BuildMenuTablePost { - public string build { get; set; } + public string building_tag { get; set; } public List MainList { get; set; } } public class BuildMenuTable: BuildMenu @@ -46,6 +48,7 @@ namespace Backend.Models public class MenuIn : SubListIn { public string sub { get; set; } + public string sub_system_tag { get; set; } } public class BuildMenuFloor : Actor { @@ -60,6 +63,7 @@ namespace Backend.Models public class BuildMenuFloorTable : BuildMenuFloor { + public string sub_system_floor_id { get; set; } public string main_system_guid_name { get; set; } public string sub_system_guid_name { get; set; } public string floor_guid_name { get; set; } diff --git a/Backend/Views/BuildMenu/Index.cshtml b/Backend/Views/BuildMenu/Index.cshtml index 9aee64f..a116028 100644 --- a/Backend/Views/BuildMenu/Index.cshtml +++ b/Backend/Views/BuildMenu/Index.cshtml @@ -443,7 +443,7 @@ buildMenuTable = $("#buildMenu_table").DataTable({ "columns": [ { - "data": "building_guid", + "data": "building_tag", "render": function (data, type, row, meta) { return meta.row + 1; } @@ -482,9 +482,9 @@ } ], 'createdRow': function (row, data, dataIndex) { - $(row).attr('bg-guid', data.building_guid); - $(row).attr('ms-guid', data.main_system_guid); - $(row).attr('ss-guid', data.sub_system_guid); + $(row).attr('bg-guid', data.building_tag); + $(row).attr('ms-guid', data.main_system_tag); + $(row).attr('ss-guid', data.sub_system_tag); $(row).attr('ms-name', data.main_system_guid_name); $(row).attr('ss-name', data.sub_system_guid_name); }, @@ -492,8 +492,8 @@ "url": "/BuildMenu/BuildMenuTable", "type": "POST", "data": function (d) { - d.build = SelectBuild, - d.MainList = SelectMainList + d.building_tag = SelectBuild, + d.MainList = SelectMainList }, "dataSrc": function (rel) { if (rel.code == "9999") { @@ -523,7 +523,7 @@ buildMenuFloorTable = $("#buildMenu_floor_table").DataTable({ "columns": [ { - "data": "sub_system_floor_guid", + "data": "sub_system_floor_id", "render": function (data, type, row, meta) { return meta.row + 1; } @@ -543,15 +543,15 @@ } ], 'createdRow': function (row, data, dataIndex) { - $(row).attr('ssf-guid', data.sub_system_floor_guid); + $(row).attr('ssf-guid', data.sub_system_floor_id); }, "ajax": { "url": "/BuildMenu/BuildMenuFloorTable", "type": "POST", "data": function (d) { - d.build = SelectBuild, - d.main = SelectMainSys, - d.sub = SelectSubSys + d.building_tag = SelectBuild, + d.main_system_tag = SelectMainSys, + d.sub_system_tag = SelectSubSys }, "dataSrc": function (rel) { if (rel.code == "9999") { @@ -617,10 +617,10 @@ //#endregion var submain = new Array(0); //#region 以棟別找系統大類 - function GetMainlistByBuild(build) { + function GetMainlistByBuild(building_tag) { var url = "/BuildMenu/MainListBybuild"; var send_data = { - build: build + building_tag: building_tag }; $.post(url, send_data, function (rel) { if (rel.code != "0000") { @@ -683,8 +683,8 @@ function GetSubList(main) { var url = "/BuildMenu/SubListNotAdd"; var send_data = { - main: main, - build: SelectBuild + main_system_tag: main, + building_tag: SelectBuild }; $.post(url, send_data, function (rel) { if (rel.code != "0000") { @@ -791,9 +791,9 @@ var url = "/BuildMenu/SavebuildMenuModal"; var send_data = { - building_guid: $('#build_menu_building_modal').val(), - main_system_guid: $('#build_menu_main_modal').val(), - sub_system_guid: $('#build_menu_sub_modal').val(), + building_tag: $('#build_menu_building_modal').val(), + main_system_tag: $('#build_menu_main_modal').val(), + sub_system_tag: $('#build_menu_sub_modal').val(), drawing: $('input[name="drawing"]:checked').val(), system_url: $('#build_menu_systemurl_modal').val(), icon_click: icon_click, @@ -822,22 +822,22 @@ $('#buildMenu_table').on("click", "button.edit-btn", function () { var url = "/BuildMenu/GetBuildMenu"; var send_data = { - build: $(this).parents('tr').attr('bg-guid'), - main: $(this).parents('tr').attr('ms-guid'), - sub: $(this).parents('tr').attr('ss-guid') + building_tag: $(this).parents('tr').attr('bg-guid'), + main_system_tag: $(this).parents('tr').attr('ms-guid'), + sub_system_tag: $(this).parents('tr').attr('ss-guid') }; $.post(url, send_data, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); } else { - $('#build_menu_building_modal').val(rel.data.building_guid); - $('#build_menu_main_modal').val(rel.data.main_system_guid); + $('#build_menu_building_modal').val(rel.data.building_tag); + $('#build_menu_main_modal').val(rel.data.main_system_tag); $('#build_menu_building_modal').attr('disabled', true); $('#build_menu_main_modal').attr('disabled', true); $('#build_menu_sub_modal').attr('disabled', true); - $('#build_menu_sub_modal').append($("