From da19a2beccd5f9c968de81b6f1920f086357be0c Mon Sep 17 00:00:00 2001 From: dev02 Date: Thu, 20 Oct 2022 17:25:47 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E5=8F=B0]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=B3=BB=E7=B5=B1=E9=A1=9E=E5=88=A5=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/DeviceManageController.cs | 5 +- .../Controllers/SystemCategoryController.cs | 326 +++++++++--------- Backend/Models/BuildModel.cs | 1 + Backend/Models/Mybase.cs | 3 +- Backend/Models/SystemCategory.cs | 11 +- Backend/Views/BuildInfo/Index.cshtml | 16 +- Backend/Views/SystemCategory/Index.cshtml | 78 +++-- .../Views/SystemCategory/_SystemSub.cshtml | 13 + 8 files changed, 241 insertions(+), 212 deletions(-) diff --git a/Backend/Controllers/DeviceManageController.cs b/Backend/Controllers/DeviceManageController.cs index 4325c9a..a7b9d08 100644 --- a/Backend/Controllers/DeviceManageController.cs +++ b/Backend/Controllers/DeviceManageController.cs @@ -805,7 +805,7 @@ namespace Backend.Controllers try { - var rawDatas = await backendRepository.GetAllAsync("import_niagara_tag", null, null, "device_building_tag, device_system_tag, device_floor_tag, device_name_tag"); + var rawDatas = await backendRepository.GetAllAsync("import_niagara_tag", "ORDER BY device_building_tag, device_system_tag, device_floor_tag, device_name_tag"); var rawDatas_Group_Building_tag = rawDatas.GroupBy(x => x.Device_building_tag).ToList(); List tempFilters = new List(); @@ -877,7 +877,8 @@ namespace Backend.Controllers di.device_floor_tag, di.device_last_name_tag as device_name_tag, di.device_serial_tag, - 0 as device_disaster, + 0 as Device_disasters, + 0 as Device_disaster_type_text, di.niagara_tags as device_number FROM ( diff --git a/Backend/Controllers/SystemCategoryController.cs b/Backend/Controllers/SystemCategoryController.cs index 0daf22d..a907bbe 100644 --- a/Backend/Controllers/SystemCategoryController.cs +++ b/Backend/Controllers/SystemCategoryController.cs @@ -13,6 +13,8 @@ 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) { @@ -29,15 +31,17 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task>> SystemMainList() + public async Task>> SystemMainList() { - ApiResult> apiResult = new ApiResult>(); + ApiResult> apiResult = new ApiResult>(); try { - var sWhere = "deleted = 0"; + var sWhere = "deleted = 0 AND system_type = @System_type"; - var systemMainList = await backendRepository.GetAllAsync("main_system", sWhere, null, "priority ASC, created_at DESC"); + var param = new { System_type = main_system_name }; + + var systemMainList = await backendRepository.GetAllAsync("variable", sWhere, param, "system_priority ASC, created_at DESC"); apiResult.Code = "0000"; apiResult.Data = systemMainList; @@ -57,17 +61,17 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task> GetOneSystemMain(string guid) + public async Task> GetOneSystemMain(int id) { - ApiResult apiResult = new ApiResult(); + ApiResult apiResult = new ApiResult(); try { - string sWhere = @$"deleted = @Deleted AND main_system_guid = @Guid"; + string sWhere = @$"deleted = @Deleted AND id = @id"; - object param = new { Deleted = 0, Guid = guid }; + object param = new { Deleted = 0, id = id}; - var systemMain = await backendRepository.GetOneAsync("main_system", sWhere, param); + var systemMain = await backendRepository.GetOneAsync("variable", sWhere, param); apiResult.Code = "0000"; apiResult.Data = systemMain; @@ -87,81 +91,66 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task> SaveSystemMain(SystemMain post) + public async Task> SaveSystemMain(VariableInfo post) { ApiResult apiResult = new ApiResult(); try { - string sWhere = @$"deleted = @Deleted AND main_system_guid = @Guid"; + string sWhere = @$"deleted = @Deleted AND id = @id"; - object param = new { Deleted = 0, Guid = post.Main_system_guid }; + object param = new { Deleted = 0, id = post.id }; - var systemMain = await backendRepository.GetOneAsync("main_system", sWhere, param); + var systemMain = await backendRepository.GetOneAsync("variable", sWhere, param); if (systemMain == null) { //新增 - //產生一組GUID - var guid = Guid.NewGuid(); //系統大類GUID + //獲取最新的大類 + sWhere = @$"deleted = @Deleted AND system_type = @System_type"; + param = new { Deleted = 0, System_type = main_system_name }; + var sOrder = @"id DESC LIMIT 1"; + var latestVariable = await backendRepository.GetOneAsync("variable", sWhere, param, sOrder); - Dictionary systemMainDic = new Dictionary() + Dictionary variableMainDic = new Dictionary() { - { "@main_system_guid", guid}, - { "@full_name", post.Full_name}, - { "@code", post.Code}, - { "@created_by", myUserInfo.Userinfo_guid} + { "@system_type", main_system_name}, + { "@system_key", post.System_key}, + { "@system_value", post.system_value}, + { "@system_remark", "系統類別(第2層)"}, + { "@system_priority", latestVariable.system_priority + 1}, + { "@created_by", myUserInfo.Userinfo_guid}, + { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} }; - await backendRepository.AddOneByCustomTable(systemMainDic, "main_system"); + await backendRepository.AddOneByCustomTable(variableMainDic, "variable"); apiResult.Code = "0000"; apiResult.Msg = "新增成功"; } else { - Dictionary systemMainDic = new Dictionary() + Dictionary variableMainDic = new Dictionary() { - { "@full_name", post.Full_name}, - { "@code", post.Code}, + { "@system_key", post.System_key}, + { "@system_value", post.system_value}, { "@updated_by", myUserInfo.Userinfo_guid}, { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, }; - await backendRepository.UpdateOneByCustomTable(systemMainDic, "main_system", "main_system_guid='" + systemMain.Main_system_guid + "'"); + await backendRepository.UpdateOneByCustomTable(variableMainDic, "variable", "id='" + systemMain.id + "' AND deleted = 0"); var AuthCodes = await backendRepository.GetAllAsync( - @$"select AuthCode from auth_page ap - join sub_system ss on ss.sub_system_guid = ap.ShowView - join main_system ms on ms.main_system_guid = ss.main_system_guid - where ms.main_system_guid = '{systemMain.Main_system_guid}'"); + @$"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}'"); if(AuthCodes.Count > 0) { await backendRepository.ExecuteSql($@"UPDATE auth_page - SET MainName = '{post.Full_name}' + SET MainName = '{post.System_key}' WHERE AuthCode IN @authCode;",new { authCode = AuthCodes }); - } - - #region 新增至派送資料表 - var auth_Pages = await backendRepository.GetAllAsync("auth_page", ""); - List> authPagesDics = new List>(); - foreach (var auth_page in auth_Pages) - { - Dictionary authPagesDic = new Dictionary() - { - { "@AuthCode", auth_page.AuthCode}, - { "@AuthType", auth_page.AuthType}, - { "@MainName", auth_page.MainName}, - { "@SubName", auth_page.SubName}, - { "@building_guid", auth_page.building_guid}, - { "@ShowView", auth_page.ShowView}, - { "@created_at", auth_page.created_at}, - }; - - authPagesDics.Add(authPagesDic); - } - await backendRepository.ManualInsertBackgroundServiceTask("", "", "auth_page", "purge_all_insert", authPagesDics); - #endregion + } apiResult.Code = "0000"; apiResult.Msg = "修改成功"; @@ -185,17 +174,17 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task> DeleteOneSystemMain(string guid) + public async Task> DeleteOneSystemMain(int id) { ApiResult apiResult = new ApiResult(); try { - string sWhere = @$"deleted = @Deleted AND main_system_guid = @Guid"; + string sWhere = @$"deleted = @Deleted AND id = @id"; - object param = new { Deleted = 0, Guid = guid }; + object param = new { Deleted = 0, id = id }; - var systemMain = await backendRepository.GetOneAsync("main_system", sWhere, param); + var systemMain = await backendRepository.GetOneAsync("variable", sWhere, param); if (systemMain == null) { @@ -208,11 +197,11 @@ namespace Backend.Controllers var sbuildMenu = $@"SELECT b.full_name FROM building_menu bm - LEFT JOIN building b ON bm.building_guid = b.building_guid AND b.deleted = 0 - WHERE bm.main_system_guid = @Guid + LEFT JOIN building b ON bm.building_tag = b.building_tag AND b.deleted = 0 + WHERE bm.main_system_tag = @System_Value GROUP BY b.full_name"; - var buildMenus = await backendRepository.GetAllAsync(sbuildMenu, new { Guid = guid }); + var buildMenus = await backendRepository.GetAllAsync(sbuildMenu, new { System_Value = systemMain.system_value }); if (buildMenus.Count > 0) { apiResult.Code = "9997"; @@ -222,19 +211,20 @@ namespace Backend.Controllers } //檢查底下是否有未刪除的系統小類 - string sSubWhere = @$"deleted = @Deleted AND main_system_guid = @Guid"; - object sub_param = new { Deleted = 0, Guid = systemMain.Main_system_guid }; - var systemSubs = await backendRepository.GetAllAsync("sub_system", sWhere, param); + string sqlSub = @$"SELECT id FROM variable + WHERE deleted = @Deleted AND system_parent_id = @id"; + object sub_param = new { Deleted = 0, id = id }; + var v = await backendRepository.GetAllAsync(sqlSub, sub_param); - if (systemSubs.Count > 0) + if (v.Count > 0) { apiResult.Code = "9997"; apiResult.Msg = "系統小類中尚有小類正在使用系統大類,故無法刪除"; - apiResult.Data = string.Join("
", systemSubs.Select(x => x.Full_name).ToList()); + apiResult.Data = string.Join("
", v.Where(x => x.id == id).Select(x => x.System_key).ToList()); return apiResult; } - await backendRepository.DeleteOne(guid, "main_system", "main_system_guid"); + await backendRepository.DeleteOne(id.ToString(), "variable", "id"); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -243,7 +233,7 @@ namespace Backend.Controllers { apiResult.Code = "9999"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - Logger.LogError("【" + controllerName + "/" + actionName + "】" + "main_system_guid=" + guid); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "id=" + id); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } @@ -256,18 +246,17 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task>> SystemSubList(string main_system_guid) + public async Task>> SystemSubList(int id) { - ApiResult> apiResult = new ApiResult>(); + ApiResult> apiResult = new ApiResult>(); try { + var sWhere = @"deleted = @Deleted AND system_parent_id = @id"; - var sWhere = @"deleted = @Deleted AND main_system_guid = @Main_system_guid"; + object param = new { Deleted = 0, id = id}; - object param = new { Deleted = 0, Main_system_guid = main_system_guid }; - - var systemSubs = await backendRepository.GetAllAsync("sub_system", sWhere, param, "priority ASC, created_at DESC"); + var systemSubs = await backendRepository.GetAllAsync("variable", sWhere, param, "system_priority ASC, created_at DESC"); apiResult.Code = "0000"; apiResult.Data = systemSubs; @@ -287,17 +276,17 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task> GetOneSystemSub(string guid) + public async Task> GetOneSystemSub(int id) { - ApiResult apiResult = new ApiResult(); + ApiResult apiResult = new ApiResult(); try { - string sWhere = @$"deleted = @Deleted AND sub_system_guid = @Guid"; + string sWhere = @$"deleted = @Deleted AND id = @id"; - object param = new { Deleted = 0, Guid = guid }; + object param = new { Deleted = 0, id = id }; - var systemSub = await backendRepository.GetOneAsync("sub_system", sWhere, param); + var systemSub = await backendRepository.GetOneAsync("variable", sWhere, param); apiResult.Code = "0000"; apiResult.Data = systemSub; @@ -317,32 +306,40 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task> SaveSystemSub(SystemSub post) + public async Task> SaveSystemSub(VariableInfo post) { ApiResult apiResult = new ApiResult(); try { - string sWhere = @$"deleted = @Deleted AND sub_system_guid = @Guid"; + string sWhere = @$"deleted = @Deleted AND id = @id"; - object param = new { Deleted = 0, Guid = post.Sub_system_guid }; + object param = new { Deleted = 0, id = post.id }; - var systemSub = await backendRepository.GetOneAsync("sub_system", sWhere, param); + var systemSub = await backendRepository.GetOneAsync("variable", sWhere, param); if (systemSub == null) { //新增 //產生一組GUID - var guid = Guid.NewGuid(); //GUID + //獲取最新的大類 + sWhere = @$"deleted = @Deleted AND system_type = @System_type"; + param = new { Deleted = 0, System_type = sub_system_name }; + var sOrder = @"id DESC LIMIT 1"; + var latestVariable = await backendRepository.GetOneAsync("variable", sWhere, param, sOrder); Dictionary systemSubDic = new Dictionary() { - { "@sub_system_guid", guid}, - { "@main_system_guid", post.Main_system_guid}, - { "@full_name", post.Full_name}, - { "@created_by", myUserInfo.Userinfo_guid} + { "@system_type", sub_system_name}, + { "@system_key", post.System_key}, + { "@system_value", post.system_value}, + { "@system_parent_id", post.system_parent_id}, + { "@system_remark", "系統類別(第1層)"}, + { "@system_priority", latestVariable.system_priority + 1}, + { "@created_by", myUserInfo.Userinfo_guid}, + { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} }; - await backendRepository.AddOneByCustomTable(systemSubDic, "sub_system"); + await backendRepository.AddOneByCustomTable(systemSubDic, "variable"); apiResult.Code = "0000"; apiResult.Msg = "新增成功"; @@ -351,45 +348,26 @@ namespace Backend.Controllers { Dictionary systemSubDic = new Dictionary() { - { "@full_name", post.Full_name}, + + { "@system_key", post.System_key}, + { "@system_value", post.system_value}, { "@updated_by", myUserInfo.Userinfo_guid}, { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, }; - await backendRepository.UpdateOneByCustomTable(systemSubDic, "sub_system", "sub_system_guid='" + systemSub.Sub_system_guid + "'"); + await backendRepository.UpdateOneByCustomTable(systemSubDic, "variable", "id='" + systemSub.id + "'"); var AuthCodes = await backendRepository.GetAllAsync( @$"select AuthCode from auth_page ap - where ap.ShowView = '{systemSub.Sub_system_guid}'"); + where ap.ShowView = '{systemSub.id}'"); if (AuthCodes.Count > 0) { await backendRepository.ExecuteSql($@"UPDATE auth_page - SET SubName = '{post.Full_name}' + SET SubName = '{post.System_key}' WHERE AuthCode IN @authCode;", new { authCode = AuthCodes }); } - #region 新增至派送資料表 - var auth_Pages = await backendRepository.GetAllAsync("auth_page", ""); - List> authPagesDics = new List>(); - foreach (var auth_page in auth_Pages) - { - Dictionary authPagesDic = new Dictionary() - { - { "@AuthCode", auth_page.AuthCode}, - { "@AuthType", auth_page.AuthType}, - { "@MainName", auth_page.MainName}, - { "@SubName", auth_page.SubName}, - { "@building_guid", auth_page.building_guid}, - { "@ShowView", auth_page.ShowView}, - { "@created_at", auth_page.created_at}, - }; - - authPagesDics.Add(authPagesDic); - } - await backendRepository.ManualInsertBackgroundServiceTask("", "", "auth_page", "purge_all_insert", authPagesDics); - #endregion - apiResult.Code = "0000"; apiResult.Msg = "修改成功"; } @@ -412,17 +390,17 @@ namespace Backend.Controllers /// /// [HttpPost] - public async Task> DeleteOneSystemSub(string guid) + public async Task> DeleteOneSystemSub(string id) { ApiResult apiResult = new ApiResult(); try { - string sWhere = @$"deleted = @Deleted AND sub_system_guid = @Guid"; + string sWhere = @$"deleted = @Deleted AND id = @id"; - object param = new { Deleted = 0, Guid = guid }; + object param = new { Deleted = 0, id = id }; - var systemSub = await backendRepository.GetOneAsync("sub_system", sWhere, param); + var systemSub = await backendRepository.GetOneAsync("variable", sWhere, param); if (systemSub == null) { @@ -433,13 +411,14 @@ namespace Backend.Controllers //檢查是否有未刪除的區域選單 var sbuildMenu = $@"SELECT - CONCAT(b.full_name, ' - ', ms.full_name) + CONCAT(b.full_name, ' - ', v2.system_key) 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 - WHERE bm.sub_system_guid = @Guid"; + 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"; - var buildMenus = await backendRepository.GetAllAsync(sbuildMenu, new { Guid = guid }); + var buildMenus = await backendRepository.GetAllAsync(sbuildMenu, new { id = id }); if (buildMenus.Count > 0) { apiResult.Code = "9997"; @@ -450,16 +429,15 @@ namespace Backend.Controllers //檢查是否有未刪除的系統小類樓層 var ssubSystemFloor = $@"SELECT - CONCAT(b.full_name, ' - ', ms.full_name, ' - ', ss.full_name, ' - ', f.full_name) + CONCAT(b.full_name, ' - ', v1.full_name, ' - ', v2.full_name, ' - ', f.full_name) FROM sub_system_floor ssf - LEFT JOIN building b ON ssf.building_guid = b.building_guid AND b.deleted = 0 - LEFT JOIN main_system ms ON ssf.main_system_guid = ms.main_system_guid AND ms.deleted = 0 - LEFT JOIN sub_system ss ON ssf.sub_system_guid = ss.sub_system_guid AND ss.deleted = 0 + 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 floor f ON ssf.floor_guid = f.floor_guid AND f.deleted = 0 - WHERE ssf.sub_system_guid = @Guid - AND ssf.deleted = 0"; + WHERE v2.id = @id AND ssf.deleted = 0"; - var subSystemFloor = await backendRepository.GetAllAsync(sbuildMenu, new { Guid = guid }); + var subSystemFloor = await backendRepository.GetAllAsync(sbuildMenu, new { id = id }); if (subSystemFloor.Count > 0) { apiResult.Code = "9997"; @@ -470,12 +448,12 @@ namespace Backend.Controllers //檢查是否有未刪除的設備項目 var sdeviceItem = $@"SELECT - di.full_name + di.full_name FROM device_item di - WHERE di.deleted = 0 - AND di.sub_system_guid = @Guid"; + INNER JOIN variable v on di.device_name_tag = v.system_value + WHERE v.deleted = 0 AND v.id = @id AND di.deleted = 0"; - var deviceItems = await backendRepository.GetAllAsync(sdeviceItem, new { Guid = guid }); + var deviceItems = await backendRepository.GetAllAsync(sdeviceItem, new { id = id }); if (deviceItems.Count > 0) { apiResult.Code = "9997"; @@ -484,7 +462,7 @@ namespace Backend.Controllers return apiResult; } - await backendRepository.DeleteOne(guid, "sub_system", "sub_system_guid"); + await backendRepository.DeleteOne(id, "variable", "id"); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -493,7 +471,7 @@ namespace Backend.Controllers { apiResult.Code = "9999"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - Logger.LogError("【" + controllerName + "/" + actionName + "】" + "sub_system_guid=" + guid); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "id=" + id); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } @@ -510,10 +488,10 @@ namespace Backend.Controllers //檢查是否有未刪除的區域選單 if(device_Item.is_show_riserDiagram == 1) { - var sql_show_riserDiagram = $@"SELECT * FROM device_item di - WHERE di.sub_system_guid = @SubSystemGuid AND di.deleted = 0 AND is_show_riserDiagram = 1"; + var sql_show_riserDiagram = $@"SELECT * FROM device_item di + WHERE di.id = @id AND di.deleted = 0 AND is_show_riserDiagram = 1"; - var is_show_riserDiagram = await backendRepository.GetAllAsync(sql_show_riserDiagram, new { SubSystemGuid = device_Item.sub_system_guid }); + var is_show_riserDiagram = await backendRepository.GetAllAsync(sql_show_riserDiagram, new { id = device_Item.id }); if (is_show_riserDiagram.Count() > 0) { @@ -523,16 +501,15 @@ namespace Backend.Controllers } } - if (device_Item.device_item_guid == null) + if (device_Item.id == 0) { + var main_tag = await backendRepository.GetOneAsync($@"SELECT system_value FROM variable WHERE id = @id", new { id = device_Item.device_system_tag }); + var sub_tag = await backendRepository.GetOneAsync($@"SELECT system_value FROM variable WHERE id = @id", new { id = device_Item.device_name_tag }); //新增 - //產生一組GUID - var guid = Guid.NewGuid(); //GUID - Dictionary Device_itemDic = new Dictionary() { - { "@device_item_guid", guid}, - { "@sub_system_guid", device_Item.sub_system_guid}, + { "@device_system_tag", main_tag}, + { "@device_name_tag", sub_tag}, { "@full_name", device_Item.full_name}, { "@points", device_Item.points}, { "@unit", device_Item.unit}, @@ -540,6 +517,7 @@ namespace Backend.Controllers { "@is_show_riserDiagram", device_Item.is_show_riserDiagram}, { "@is_controll", device_Item.is_controll}, { "@is_bool", device_Item.is_bool}, + { "@is_link", device_Item.is_link}, { "@created_by", myUserInfo.Userinfo_guid}, }; await backendRepository.AddOneByCustomTable(Device_itemDic, "device_item"); @@ -551,7 +529,6 @@ namespace Backend.Controllers { Dictionary Device_itemDic = new Dictionary() { - { "@sub_system_guid", device_Item.sub_system_guid}, { "@full_name", device_Item.full_name}, { "@points", device_Item.points}, { "@unit", device_Item.unit}, @@ -559,11 +536,12 @@ namespace Backend.Controllers { "@is_show_riserDiagram", device_Item.is_show_riserDiagram}, { "@is_controll", device_Item.is_controll}, { "@is_bool", device_Item.is_bool}, + { "@is_link", device_Item.is_link}, { "@updated_by", myUserInfo.Userinfo_guid}, { "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, }; - await backendRepository.UpdateOneByCustomTable(Device_itemDic, "device_item", "device_item_guid='" + device_Item.device_item_guid + "'"); + await backendRepository.UpdateOneByCustomTable(Device_itemDic, "device_item", "id='" + device_Item.id + "'"); apiResult.Code = "0000"; apiResult.Msg = "修改成功"; @@ -582,17 +560,21 @@ namespace Backend.Controllers } [HttpPost] - public async Task>> DeviceItemTable(string sub_system_guid) + public async Task>> DeviceItemTable(int id) { ApiResult> apiResult = new ApiResult>(); try { - var sWhere = @"deleted = @Deleted AND sub_system_guid = @Sub_system_guid"; + 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"; - object param = new { Deleted = 0, Sub_system_guid = sub_system_guid }; + object param = new { Deleted = 0, id = id }; - var systemSubs = await backendRepository.GetAllAsync("device_item", sWhere, param, "created_at DESC"); + var systemSubs = await backendRepository.GetAllAsync(sql, param); apiResult.Code = "0000"; apiResult.Data = systemSubs; @@ -607,15 +589,15 @@ namespace Backend.Controllers } [HttpPost] - public async Task> GetOneDeviceItem(string guid) + public async Task> GetOneDeviceItem(int id) { ApiResult apiResult = new ApiResult(); try { - string sWhere = @$"deleted = @Deleted AND device_item_guid = @Guid"; + string sWhere = @$"deleted = @Deleted AND id = @id"; - object param = new { Deleted = 0, Guid = guid }; + object param = new { Deleted = 0, id = id }; var Deviceitem = await backendRepository.GetOneAsync("device_item", sWhere, param); @@ -632,15 +614,15 @@ namespace Backend.Controllers } [HttpPost] - public async Task> DeleteOneSystemSubDeviceItem(string guid) + public async Task> DeleteOneSystemSubDeviceItem(int id) { ApiResult apiResult = new ApiResult(); try { - string sWhere = @$"deleted = @Deleted AND device_item_guid = @Guid"; + string sWhere = @$"deleted = @Deleted AND id = @id"; - object param = new { Deleted = 0, Guid = guid }; + object param = new { Deleted = 0, id = id}; var device_Item = await backendRepository.GetOneAsync("device_item", sWhere, param); @@ -651,7 +633,7 @@ namespace Backend.Controllers return apiResult; } - await backendRepository.DeleteOne(guid, "device_item", "device_item_guid"); + await backendRepository.DeleteOne(id.ToString(), "device_item", "id"); apiResult.Code = "0000"; apiResult.Msg = "刪除成功"; @@ -660,7 +642,7 @@ namespace Backend.Controllers { apiResult.Code = "9999"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - Logger.LogError("【" + controllerName + "/" + actionName + "】" + "device_item_guid=" + guid); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "id=" + id); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } @@ -672,7 +654,13 @@ namespace Backend.Controllers ApiResult apiResult = new ApiResult(); try { - var point = await backendRepository.GetOneAsync("device_item", $" sub_system_guid = '{post.sub_system_guid}' and points = '{post.points}' and device_item_guid != '{post.device_item_guid}' and deleted = 0"); + var sql = $@"SELECT * + FROM device_item di + INNER JOIN variable v ON di.device_name_tag = v.system_value + WHERE v.id = @SubId AND di.id != @Id AND points = @Points"; + + var param = new { SubId = post.subId, Points = post.points, id = post.id }; + var point = await backendRepository.GetOneAsync(sql, param); if (point != null) { apiResult.Data = true; @@ -700,9 +688,9 @@ namespace Backend.Controllers try { var tags = await backendRepository.GetAllAsync( - @$"select * from (select dk.device_building_tag ,dk.device_name_tag,dk.device_system_tag from device_kind dk where dk.device_normal_point_guid = '{post.guid}') dkn - union(select dk.device_building_tag, dk.device_name_tag, dk.device_system_tag from device_kind dk where dk.device_close_point_guid = '{post.guid}') - union(select dk.device_building_tag, dk.device_name_tag, dk.device_system_tag from device_kind dk where dk.device_error_point_guid = '{post.guid}')"); + @$"select * from (select dk.device_building_tag ,dk.device_name_tag,dk.device_system_tag from device_kind dk where dk.device_normal_point_id = @id) dkn + union(select dk.device_building_tag, dk.device_name_tag, dk.device_system_tag from device_kind dk where dk.device_close_point_id = @id) + union(select dk.device_building_tag, dk.device_name_tag, dk.device_system_tag from device_kind dk where dk.device_error_point_id = @id)", new { id = post.guid}); if (tags.Count == 0) { @@ -722,20 +710,24 @@ namespace Backend.Controllers }; var unionsql = ""; var last = tags.Last(); + var sub_system = await backendRepository.GetOneAsync($@"SELECT * FROM variable WHERE id = @id", new { id = post.subguid }); foreach (var tag in tags) { - unionsql += $@"select d.building_guid,d.main_system_guid,d.sub_system_guid,d.device_name_tag from device d where d.sub_system_guid = '{post.subguid}' and d.device_building_tag = '{tag.device_building_tag}' and d.device_system_tag = '{tag.device_system_tag}' and d.device_name_tag = '{tag.device_name_tag}' group by d.building_guid,d.main_system_guid,d.sub_system_guid,d.device_name_tag"; + unionsql += $@"select d.building_tag,d.device_system_tag,d.device_name_tag,d.device_last_name from device d where d.device_name_tag = '{sub_system.system_value}' + and d.device_building_tag = '{tag.device_building_tag}' and d.device_system_tag = '{tag.device_system_tag}' and d.device_name_tag = '{tag.device_name_tag}' group by d.building_guid,d.main_system_guid,d.sub_system_guid,d.device_name_tag"; if (!last.Equals(tag)) { unionsql += " union "; } } - var sql = @$"select ms.full_name msname,b.full_name bname,s.full_name subname,de.device_name_tag from + var sql = @$"select v1.system_key msname, b.full_name bname, v2.system_key subname,de.device_last_name as device_name_tag from ({unionsql}) de - left join main_system ms on ms.main_system_guid = de.main_system_guid - left join building b on b.building_guid = de.building_guid - left join sub_system s on s.sub_system_guid = de.sub_system_guid"; - var names = await backendRepository.GetAllAsync(sql); + left join variable v1 on v1.system_value = de.device_system_tag and v1.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"; + + var param = new { main_system_type = main_system_name, sub_system_type = sub_system_name}; + var names = await backendRepository.GetAllAsync(sql, param); var count = 0; foreach (var name in names) { diff --git a/Backend/Models/BuildModel.cs b/Backend/Models/BuildModel.cs index 9c0358d..25e47bd 100644 --- a/Backend/Models/BuildModel.cs +++ b/Backend/Models/BuildModel.cs @@ -9,6 +9,7 @@ namespace Backend.Models public class BuildInfo : Actor { public int Priority { get; set; } + public string building_tag { get; set; } public string Building_guid { get; set; } //區域GUID public string Full_name { get; set; } //區域名稱 public string Ip_address { get; set; } //監控主機 IP diff --git a/Backend/Models/Mybase.cs b/Backend/Models/Mybase.cs index 74fe5db..bdc8b69 100644 --- a/Backend/Models/Mybase.cs +++ b/Backend/Models/Mybase.cs @@ -53,11 +53,12 @@ namespace Backend.Models public string Logo { get; set; } } - public class Variable + public class Variable : Actor { public string System_type { get; set; } public string System_key { get; set; } public string system_value { get; set; } + } public class VariableInfo : Variable diff --git a/Backend/Models/SystemCategory.cs b/Backend/Models/SystemCategory.cs index c51c19e..c6b9151 100644 --- a/Backend/Models/SystemCategory.cs +++ b/Backend/Models/SystemCategory.cs @@ -30,8 +30,12 @@ namespace Backend.Models public class Device_item : Actor { + public int id { get; set; } public string device_item_guid { get; set; } - public string sub_system_guid { get; set; } + public string device_area_tag { get; set; } + public string device_building_tag { get; set; } + public string device_system_tag { get; set; } + public string device_name_tag { get; set; } public string full_name { get; set; } public string points { get; set; } public string unit { get; set; } @@ -39,13 +43,14 @@ namespace Backend.Models public byte is_show_riserDiagram { get; set; } public byte is_controll { get; set; } public byte is_bool { get; set; } + public byte is_link { get; set; } } public class Checksame { - public string sub_system_guid { get; set; } + public int id { get; set; } + public string subId { get; set; } public string points { get; set; } - public string device_item_guid { get; set; } } public class Tags diff --git a/Backend/Views/BuildInfo/Index.cshtml b/Backend/Views/BuildInfo/Index.cshtml index 238ca27..956fd36 100644 --- a/Backend/Views/BuildInfo/Index.cshtml +++ b/Backend/Views/BuildInfo/Index.cshtml @@ -55,7 +55,7 @@ }, "columns": [ { - "data": "building_guid", + "data": "building_tag", "render": function (data, type, row, meta) { return meta.row + 1; } @@ -87,7 +87,7 @@ ], //"order": [[2, "desc"]], 'createdRow': function (row, data, dataIndex) { - $(row).attr('data-guid', data.building_guid); + $(row).attr('data-guid', data.building_tag); }, "ajax": { "url": "/BuildInfo/BuildInfoList", @@ -107,13 +107,13 @@ //樓層設定上方選單 $("#BuildList").empty(); $.each(data, function (key, value) { - $("#BuildList").append(``); + $("#BuildList").append(``); @*if (key == 0) { selected_build_guid_top_name = value.full_name; - $("#BuildList").append(``); + $("#BuildList").append(``); } else { - $("#BuildList").append(``); + $("#BuildList").append(``); }*@ }); @@ -129,7 +129,7 @@ var rowData = buildInfoTable.row(diff[i].node).data(); var obj = { - building_guid: rowData.building_guid, + building_tag: rowData.building_tag, priority: diff[i].newData } @@ -253,7 +253,7 @@ $("#save-building-btn").html('').attr("disabled", true); var url = "/BuildInfo/SaveBuildInfo"; var send_data = { - Building_guid: selected_build_guid, + building_tag: selected_build_guid, Full_name: $('#build_name_modal').val(), Ip_address: $('#ip_address_modal').val(), Ip_port: $('#ip_port_modal').val() @@ -557,7 +557,7 @@ maps = $('#map_file_modal')[0].files formData.append("Floor_guid", selected_floor_guid); - formData.append("Building_guid", selected_build_guid_top); + formData.append("building_tag", selected_build_guid_top); formData.append("Full_name", $('#floor_name_modal').val()); if (maps.length > 0) { diff --git a/Backend/Views/SystemCategory/Index.cshtml b/Backend/Views/SystemCategory/Index.cshtml index 6be25b6..e2940d2 100644 --- a/Backend/Views/SystemCategory/Index.cshtml +++ b/Backend/Views/SystemCategory/Index.cshtml @@ -53,10 +53,10 @@ } }, { - "data": "full_name" + "data": "system_key" }, { - "data": "code" + "data": "system_value" }, { "data": "created_at" @@ -67,7 +67,7 @@ } ], 'createdRow': function (row, data, dataIndex) { - $(row).attr('data-guid', data.main_system_guid); + $(row).attr('data-guid', data.id); }, //"order": [[2, "desc"]], "ajax": { @@ -89,12 +89,12 @@ $("#system-main-list").empty(); $.each(data, function (key, value) { if (key == 0) { - selected_system_main_guid_top_name = value.full_name; - $("#system-main-list").append(``); - $(`#${value.main_system_guid}`).trigger("click"); + selected_system_main_guid_top_name = value.system_key; + $("#system-main-list").append(``); + $(`#${value.id}`).trigger("click"); } else { - $("#system-main-list").append(``); + $("#system-main-list").append(``); } }); @@ -115,7 +115,7 @@ var url = "/SystemCategory/GetOneSystemMain"; var send_data = { - guid: selected_system_main_guid + id: selected_system_main_guid } $.post(url, send_data, function (rel) { @@ -129,8 +129,8 @@ return; } else { - $("#system_main_name_modal").val(rel.data.full_name); - $("#system_main_code_modal").val(rel.data.code); + $("#system_main_name_modal").val(rel.data.system_key); + $("#system_main_code_modal").val(rel.data.system_value); $("#system-main-modal").modal(); } @@ -157,7 +157,7 @@ if (result.value) { var url = "/SystemCategory/DeleteOneSystemMain"; var send_data = { - Guid: selected_system_main_guid + id: selected_system_main_guid } $.post(url, send_data, function (rel) { if (rel.code != "0000") { @@ -226,9 +226,9 @@ var url = "/SystemCategory/SaveSystemMain"; var send_data = { - Main_system_guid: selected_system_main_guid, - Full_name: $('#system_main_name_modal').val(), - Code: $('#system_main_code_modal').val() + id: selected_system_main_guid, + System_key: $('#system_main_name_modal').val(), + system_value : $('#system_main_code_modal').val() } $.post(url, send_data, function (rel) { @@ -278,7 +278,10 @@ } }, { - "data": "full_name" + "data": "system_key" + }, + { + "data": "system_value" }, { "data": "created_at" @@ -289,14 +292,14 @@ } ], 'createdRow': function (row, data, dataIndex) { - $(row).attr('data-guid', data.sub_system_guid); + $(row).attr('data-guid', data.id); }, //"order": [[2, "desc"]], "ajax": { "url": "/SystemCategory/SystemSubList", "type": "POST", "data": function (d) { - d.Main_system_guid = selected_system_main_guid + d.id = selected_system_main_guid }, "dataSrc": function (rel) { if (rel.code == "9999") { @@ -346,20 +349,23 @@ { "data": "is_bool" }, + { + "data": "is_link" + }, { "data": null, "defaultContent": ' ' } ], 'createdRow': function (row, data, dataIndex) { - $(row).attr('data-guid', data.device_item_guid); + $(row).attr('data-guid', data.id); }, //"order": [[2, "desc"]], "ajax": { "url": "/SystemCategory/DeviceItemTable", "type": "POST", "data": function (d) { - d.sub_system_guid = selected_system_sub_guid + d.id = selected_system_sub_guid }, "dataSrc": function (rel) { if (rel.code == "9999") { @@ -397,6 +403,12 @@ } else { rel.is_bool = "是" } + + if (rel.is_link == 0) { + rel.is_link = "否" + } else { + rel.is_link = "是" + } }); return data; @@ -416,7 +428,7 @@ var url = "/SystemCategory/GetOneSystemSub"; var send_data = { - guid: selected_system_sub_guid + id: selected_system_sub_guid } $.post(url, send_data, function (rel) { @@ -431,7 +443,8 @@ } else { $("#system_main_name").html(selected_system_main_guid_top_name) - $("#system_sub_name_modal").val(rel.data.full_name); + $("#system_sub_name_modal").val(rel.data.system_key); + $("#system_sub_code_modal").val(rel.data.system_value); $("#system-sub-modal").modal(); } @@ -458,7 +471,7 @@ if (result.value) { var url = "/SystemCategory/DeleteOneSystemSub"; var send_data = { - Guid: selected_system_sub_guid + id: selected_system_sub_guid } $.post(url, send_data, function (rel) { if (rel.code != "0000") { @@ -539,9 +552,10 @@ var url = "/SystemCategory/SaveSystemSub"; var send_data = { - Sub_system_guid: selected_system_sub_guid, - Main_system_guid: selected_system_main_guid, - Full_name: $('#system_sub_name_modal').val(), + id: selected_system_sub_guid, + system_parent_id: selected_system_main_guid, + system_key: $('#system_sub_name_modal').val(), + system_value: $('#system_sub_code_modal').val() } $.post(url, send_data, function (rel) { @@ -610,9 +624,9 @@ var uurl = "/SystemCategory/HaveSamePoints"; var ssend_data = { - sub_system_guid: selected_system_sub_guid, + subId: selected_system_sub_guid, + id: selected_system_device_item_guid, points: $('#device_sub_points_modal').val(), - device_item_guid: selected_system_device_item_guid, } $.post(uurl, ssend_data, function (rel) { if (rel.code != "0000") { @@ -633,8 +647,9 @@ else { var url = "/SystemCategory/Savedevice_item"; var send_data = { - device_item_guid: selected_system_device_item_guid, - sub_system_guid: selected_system_sub_guid, + id: selected_system_device_item_guid, + device_system_tag: selected_system_main_guid, + device_name_tag: selected_system_sub_guid, full_name: $('#device_sub_name_modal').val(), points: $('#device_sub_points_modal').val(), unit: $('#device_sub_unit_modal').val(), @@ -686,7 +701,7 @@ var url = "/SystemCategory/GetOneDeviceItem"; var send_data = { - guid: selected_system_device_item_guid + id: selected_system_device_item_guid } $.post(url, send_data, function (rel) { @@ -708,6 +723,7 @@ $("input[name='is_show_riserDiagram'][value='" + rel.data.is_show_riserDiagram + "']").prop("checked", true); $("input[name='is_controll'][value='" + rel.data.is_controll + "']").prop("checked", true); $("input[name='is_bool'][value='" + rel.data.is_bool + "']").prop("checked", true); + $("input[name='is_link'][value='" + rel.data.is_link+ "']").prop("checked", true); $("#device-sub-modal").modal(); } @@ -759,7 +775,7 @@ } else { var url = "/SystemCategory/DeleteOneSystemSubDeviceItem"; var send_data = { - guid: selected_system_device_item_guid + id: selected_system_device_item_guid } $.post(url, send_data, function (rel) { if (rel.code != "0000") { diff --git a/Backend/Views/SystemCategory/_SystemSub.cshtml b/Backend/Views/SystemCategory/_SystemSub.cshtml index 08e818a..7c918fb 100644 --- a/Backend/Views/SystemCategory/_SystemSub.cshtml +++ b/Backend/Views/SystemCategory/_SystemSub.cshtml @@ -17,6 +17,7 @@ 序 系統大類 系統小類名稱 + 系統小類代號 建立時間 功能 @@ -50,6 +51,7 @@ 是否顯示於昇位圖(僅可擇一顯示) 是否加入 - 設備燈號中的點位選單 是否為布林值 + 是否與N4同步 功能 @@ -84,6 +86,10 @@ +
+ + +
@@ -147,6 +153,13 @@ +
+
+ + +
+
+