From ec1512d4700582a868516f9992fea5263b5f5b79 Mon Sep 17 00:00:00 2001 From: dev02 Date: Fri, 4 Aug 2023 11:52:36 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E5=8F=B0]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=BE=8C=E5=8F=B0=E5=9B=9E=E5=A0=B1=E9=8C=AF=E8=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Controllers/BuildInfoController.cs | 11 ++- .../Controllers/SystemCategoryController.cs | 15 ++++ Backend/Controllers/UserInfoController.cs | 10 ++- Backend/Controllers/VariableController.cs | 9 +++ Backend/appsettings.Development.json | 4 +- FrontendWebApi/appsettings.Development.json | 4 +- .../NiagaraDataSynchronizeRepository.cs | 80 ++++++++++++------- 7 files changed, 99 insertions(+), 34 deletions(-) diff --git a/Backend/Controllers/BuildInfoController.cs b/Backend/Controllers/BuildInfoController.cs index c03565a..8f580ce 100644 --- a/Backend/Controllers/BuildInfoController.cs +++ b/Backend/Controllers/BuildInfoController.cs @@ -495,6 +495,15 @@ namespace Backend.Controllers try { + var check = await backendRepository.GetOneAsync($@"select floor_guid from variable where floor_guid != {post.Floor_guid} and building_tag = '{post.Building_tag}' and + full_name = '{post.Full_name}';"); + if (!string.IsNullOrEmpty(check)) + { + apiResult.Code = "9998"; + apiResult.Msg = "已有相同樓層"; + return apiResult; + } + string sWhere = @$"deleted = @Deleted AND floor_guid = @Guid"; object param = new { Deleted = 0, Guid = post.Floor_guid }; @@ -680,7 +689,7 @@ namespace Backend.Controllers ssf.main_system_tag, ssf.sub_system_tag FROM sub_system_floor ssf - WHERE ssf.deleted = 0 AND ssf.floor_tag = @floor_tag + WHERE ssf.deleted = 0 AND ssf.floor_tag = @floor_tag and ssf.building_tag = '{buildFloor.Building_tag}' ) ssf LEFT JOIN building b ON ssf.building_tag = b.building_tag AND b.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 diff --git a/Backend/Controllers/SystemCategoryController.cs b/Backend/Controllers/SystemCategoryController.cs index 9246230..350acdb 100644 --- a/Backend/Controllers/SystemCategoryController.cs +++ b/Backend/Controllers/SystemCategoryController.cs @@ -99,6 +99,13 @@ namespace Backend.Controllers object param = new { Deleted = 0, id = post.id }; + var check = await backendRepository.GetOneAsync($"select id from variable where id != {post.id} and system_type = '{main_system_type}' and system_value = '{post.system_value}';"); + if (!string.IsNullOrEmpty(check)) + { + apiResult.Code = "9998"; + apiResult.Msg = "已有相同大類"; + return apiResult; + } var systemMain = await backendRepository.GetOneAsync("variable", sWhere, param); if (systemMain == null) @@ -310,6 +317,14 @@ namespace Backend.Controllers try { + var check = await backendRepository.GetOneAsync($"select id from variable where id != {post.id} and system_type = '{sub_system_type}' and system_value = '{post.system_value}';"); + if (!string.IsNullOrEmpty(check)) + { + apiResult.Code = "9998"; + apiResult.Msg = "已有相同小類"; + return apiResult; + } + string sWhere = @$"deleted = @Deleted AND id = @id"; object param = new { Deleted = 0, id = post.id }; diff --git a/Backend/Controllers/UserInfoController.cs b/Backend/Controllers/UserInfoController.cs index 08e0517..5572c93 100644 --- a/Backend/Controllers/UserInfoController.cs +++ b/Backend/Controllers/UserInfoController.cs @@ -314,6 +314,14 @@ namespace Backend.Controllers try { + var check = await backendRepository.GetOneAsync($"select role_guid from role where role_guid != '{post.Id}' and full_name = '{post.Name}';"); + if (!string.IsNullOrEmpty(check)) + { + apiResult.Code = "9998"; + apiResult.Msg = "已有相同角色"; + return apiResult; + } + roleManager = await backendRepository.GetOneAsync("role", $"role_guid='{post.Id.ToString()}'"); if (roleManager == null) @@ -475,7 +483,7 @@ namespace Backend.Controllers FROM role_auth A LEFT JOIN role B ON A.role_guid=B.role_guid AND B.deleted=0 INNER JOIN auth_page C ON A.AuthCode=C.AuthCode - LEFT JOIN building D ON C.building_guid=D.building_guid AND D.deleted=0 + LEFT JOIN building D ON C.building_tag=D.building_tag AND D.deleted=0 WHERE A.role_guid='{post.SelectedRoleId}' ORDER BY A.created_at DESC"; roleAuthList = await backendRepository.GetAllAsync(sqlString); diff --git a/Backend/Controllers/VariableController.cs b/Backend/Controllers/VariableController.cs index 39eccc0..83afaf8 100644 --- a/Backend/Controllers/VariableController.cs +++ b/Backend/Controllers/VariableController.cs @@ -128,6 +128,15 @@ namespace Backend.Controllers try { + var check = await backendRepository.GetOneAsync($@"select id from variable where id != {post.id} and system_type = '{post.System_type}' and system_value = '{post.system_value}' + and system_key = '{post.System_key}';"); + if (!string.IsNullOrEmpty(check)) + { + apiResult.Code = "9998"; + apiResult.Msg = "已有相同系統變數"; + return apiResult; + } + string sWhere = @$"deleted = 0 AND id = @Id"; object param = new { Id = post.id }; diff --git a/Backend/appsettings.Development.json b/Backend/appsettings.Development.json index 61c00b1..060577f 100644 --- a/Backend/appsettings.Development.json +++ b/Backend/appsettings.Development.json @@ -16,9 +16,9 @@ "MySqlDBConfig": { "Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201 "Port": "js2LutKe+rdjzdxMPQUrvQ==", - "Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 + //"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp - //"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome + "Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome //"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel //"Database": "iuaY0h0+TWkir44/eZLDqw==", //tpe_dome_office //"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut diff --git a/FrontendWebApi/appsettings.Development.json b/FrontendWebApi/appsettings.Development.json index 9a5504c..f976969 100644 --- a/FrontendWebApi/appsettings.Development.json +++ b/FrontendWebApi/appsettings.Development.json @@ -16,9 +16,9 @@ "MySqlDBConfig": { "Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201 "Port": "js2LutKe+rdjzdxMPQUrvQ==", - "Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 + //"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp - //"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome + "Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome //"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel //"Database": "iuaY0h0+TWkir44/eZLDqw==", //tpe_dome_office //"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //MCUT diff --git a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs index ae5a5a8..0e529aa 100644 --- a/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs +++ b/Repository/BackendRepository/Implement/NiagaraDataSynchronizeRepository.cs @@ -55,7 +55,7 @@ namespace Repository.BackendRepository.Implement `atDateTime` datetime(1) DEFAULT NULL, `is_used` smallint(1) DEFAULT 0, PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;"; await conn.ExecuteAsync(sql); sql = "delete from import_niagara_tag where device_building_tag = '" + b + "' limit 10000"; await conn.ExecuteAsync(sql); @@ -198,7 +198,7 @@ namespace Repository.BackendRepository.Implement `parent_path` varchar(50) DEFAULT NULL, `full_name` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) - ) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"; + ) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;"; await conn.ExecuteAsync(sql); sql = "delete from import_niagara_item where device_building_tag = '" + b + "' limit 10000;"; await conn.ExecuteAsync(sql); @@ -249,8 +249,8 @@ namespace Repository.BackendRepository.Implement if (isDome == "ibms_dome_dome/D2" || isDome == "ibms_dome_hotel/H") { sb.Append($@" update import_niagara_item a join dic_system b - on a.device_name_tag COLLATE utf8mb4_general_ci = b.s2_code - set device_system_tag = b.s1_code + on a.device_name_tag COLLATE utf8mb4_0900_ai_ci = b.s2_code COLLATE utf8mb4_0900_ai_ci + set device_system_tag = b.s1_code where (device_system_tag <> 'S' and device_system_tag <> 'CWB');"); } @@ -373,7 +373,7 @@ namespace Repository.BackendRepository.Implement WHERE NOT EXISTS ( SELECT 1 FROM device_node d - WHERE m.niagara_tags = d.device_number + WHERE m.niagara_tags COLLATE utf8mb4_0900_ai_ci = d.device_number COLLATE utf8mb4_0900_ai_ci );"); result = (await conn.QueryAsync(sb.ToString())).ToList(); sb.Clear(); @@ -416,18 +416,28 @@ namespace Repository.BackendRepository.Implement //device有,niagara沒有,is_link 更新成 0 sb.Append($@" SET SQL_SAFE_UPDATES = 0; - UPDATE device - SET is_link = 0 - WHERE is_link = 1 AND device_number NOT IN (SELECT niagara_tags FROM import_niagara_tag);"); + UPDATE device d + left JOIN ( + SELECT niagara_tags + FROM import_niagara_tag + LIMIT 100000 + ) i ON d.device_number COLLATE utf8mb4_0900_ai_ci = i.niagara_tags COLLATE utf8mb4_0900_ai_ci + SET d.is_link = 0 + WHERE d.is_link = 1 and i.niagara_tags is null;"); await conn.ExecuteAsync(sb.ToString()); sb.Clear(); // device_node 有, niagara沒有, is_link 更新成 0 sb.Append($@" SET SQL_SAFE_UPDATES = 0; - UPDATE device_node - SET is_link = 0 - WHERE is_link = 1 AND device_number NOT IN (SELECT niagara_tags FROM import_niagara_tag);"); + UPDATE device_node dn + left JOIN ( + SELECT niagara_tags + FROM import_niagara_tag + LIMIT 100000 + ) i ON dn.device_number COLLATE utf8mb4_0900_ai_ci = i.niagara_tags COLLATE utf8mb4_0900_ai_ci + SET dn.is_link = 0 + WHERE dn.is_link = 1 and i.niagara_tags is null;"); await conn.ExecuteAsync(sb.ToString()); } catch (Exception exception) @@ -571,7 +581,9 @@ namespace Repository.BackendRepository.Implement group by device_building_tag, device_system_tag, device_name_tag ) AS a LEFT JOIN building_menu b - ON a.device_building_tag = b.device_building_tag and a.device_system_tag = b.device_system_tag and a.device_name_tag = b.sub_system_tag + ON a.device_building_tag COLLATE utf8mb4_0900_ai_ci = b.device_building_tag COLLATE utf8mb4_0900_ai_ci and + a.device_system_tag COLLATE utf8mb4_0900_ai_ci = b.device_system_tag COLLATE utf8mb4_0900_ai_ci and + a.device_name_tag COLLATE utf8mb4_0900_ai_ci = b.sub_system_tag COLLATE utf8mb4_0900_ai_ci WHERE b.device_building_tag IS NULL"); result = (await conn.QueryAsync(sb.ToString())).ToList(); #endregion @@ -609,8 +621,8 @@ namespace Repository.BackendRepository.Implement select device_building_tag, device_system_tag, device_name_tag from import_niagara_tag group by device_building_tag, device_system_tag, device_name_tag - ) AS a ON b.building_tag = a.device_building_tag - and a.device_system_tag = b.main_system_tag and a.device_name_tag = b.sub_system_tag + ) AS a ON b.building_tag COLLATE utf8mb4_0900_ai_ci = a.device_building_tag COLLATE utf8mb4_0900_ai_ci + and a.device_system_tag COLLATE utf8mb4_0900_ai_ci = b.main_system_tag COLLATE utf8mb4_0900_ai_ci and a.device_name_tag COLLATE utf8mb4_0900_ai_ci = b.sub_system_tag COLLATE utf8mb4_0900_ai_ci SET b.is_link = 0 WHERE b.building_tag IS NULL"); await conn.ExecuteAsync(sb.ToString()); @@ -649,7 +661,10 @@ namespace Repository.BackendRepository.Implement group by device_building_tag, device_system_tag, device_name_tag, device_floor_tag ) AS a LEFT JOIN sub_system_floor b - ON a.device_building_tag = b.building_tag and a.device_system_tag = b.main_system_tag and a.device_name_tag = b.sub_system_tag and a.device_floor_tag = b.floor_tag + ON a.device_building_tag COLLATE utf8mb4_0900_ai_ci = b.building_tag COLLATE utf8mb4_0900_ai_ci and + a.device_system_tag COLLATE utf8mb4_0900_ai_ci = b.main_system_tag COLLATE utf8mb4_0900_ai_ci and + a.device_name_tag COLLATE utf8mb4_0900_ai_ci = b.sub_system_tag COLLATE utf8mb4_0900_ai_ci and + a.device_floor_tag COLLATE utf8mb4_0900_ai_ci = b.floor_tag COLLATE utf8mb4_0900_ai_ci WHERE b.building_tag IS NULL"); result = (await conn.QueryAsync(sb.ToString())).ToList(); #endregion @@ -682,8 +697,10 @@ namespace Repository.BackendRepository.Implement select device_building_tag, device_system_tag, device_name_tag, device_floor_tag from import_niagara_tag group by device_building_tag, device_system_tag, device_name_tag, device_floor_tag - ) AS a ON b.building_tag = a.device_building_tag - and b.main_system_tag = a.device_system_tag and b.sub_system_tag = a.device_name_tag and b.floor_tag = a.device_floor_tag + ) AS a ON b.building_tag COLLATE utf8mb4_0900_ai_ci = a.device_building_tag COLLATE utf8mb4_0900_ai_ci + and b.main_system_tag COLLATE utf8mb4_0900_ai_ci = a.device_system_tag COLLATE utf8mb4_0900_ai_ci + and b.sub_system_tag COLLATE utf8mb4_0900_ai_ci = a.device_name_tag COLLATE utf8mb4_0900_ai_ci + and b.floor_tag COLLATE utf8mb4_0900_ai_ci = a.device_floor_tag COLLATE utf8mb4_0900_ai_ci SET b.is_link = 0 WHERE b.building_tag IS NULL"); await conn.ExecuteAsync(sb.ToString()); @@ -774,15 +791,18 @@ namespace Repository.BackendRepository.Implement try { StringBuilder sb = new StringBuilder(); - sb.Append(@"UPDATE device d - INNER JOIN import_niagara_tag m ON m.niagara_tags = d.device_number + sb.Append(@"SET SQL_SAFE_UPDATES = 0; + update device d + JOIN ( + select niagara_tags, device_full_name from import_niagara_tag limit 100000 + ) m ON m.niagara_tags COLLATE utf8mb4_0900_ai_ci = d.device_number COLLATE utf8mb4_0900_ai_ci + LEFT JOIN ( + SELECT niagara_tags, device_full_name + FROM import_niagara_tag + LIMIT 100000 + ) m2 ON m2.niagara_tags COLLATE utf8mb4_0900_ai_ci = d.device_number COLLATE utf8mb4_0900_ai_ci AND m2.device_full_name COLLATE utf8mb4_0900_ai_ci = d.full_name COLLATE utf8mb4_0900_ai_ci SET d.full_name = m.device_full_name - WHERE NOT EXISTS ( - SELECT 1 - FROM import_niagara_tag m2 - WHERE m2.niagara_tags = d.device_number - AND m2.device_full_name = d.full_name - );"); + WHERE m2.niagara_tags IS NULL;"); await conn.ExecuteAsync(sb.ToString()); } catch (Exception exception) @@ -819,7 +839,7 @@ namespace Repository.BackendRepository.Implement inner JOIN import_niagara_item m ON m.device_system_tag = d.device_system_tag and m.device_name_tag = d.device_name_tag and - m.device_point_name = d.points + m.device_point_name = d.points set d.full_name=m.full_name where d.full_name<>m.full_name;"); await conn.ExecuteAsync(sb.ToString()); @@ -964,7 +984,9 @@ namespace Repository.BackendRepository.Implement group by device_building_tag, device_floor_tag ) AS tag LEFT JOIN floor f - ON tag.device_building_tag = f.building_tag and tag.device_floor_tag = f.full_name and f.deleted = 0 + ON tag.device_building_tag COLLATE utf8mb4_0900_ai_ci = f.building_tag COLLATE utf8mb4_0900_ai_ci + and tag.device_floor_tag COLLATE utf8mb4_0900_ai_ci = f.full_name COLLATE utf8mb4_0900_ai_ci + and f.deleted = 0 WHERE f.building_tag IS NULL;"); result = (await conn.QueryAsync(sb.ToString())).ToList(); #endregion @@ -1009,7 +1031,9 @@ namespace Repository.BackendRepository.Implement group by device_building_tag, device_floor_tag ) AS tag LEFT JOIN floor f - ON tag.device_building_tag = f.building_tag and tag.device_floor_tag = f.full_name and f.deleted = 0 + ON tag.device_building_tag COLLATE utf8mb4_0900_ai_ci = f.building_tag COLLATE utf8mb4_0900_ai_ci + and tag.device_floor_tag COLLATE utf8mb4_0900_ai_ci = f.full_name COLLATE utf8mb4_0900_ai_ci + and f.deleted = 0 ) as f2 on f1.floor_guid = f2.floor_guid where f2.floor_guid is null and f1.deleted = 0;")).ToList();