[Backend]改善同步timeout、是否顯示歷史資料問題

This commit is contained in:
張家睿 2024-10-04 18:14:14 +08:00
parent 5766931a1f
commit f5d08d9fa9

View File

@ -254,7 +254,8 @@ CREATE TABLE `import_niagara_item` (
row.device_point_name + "', '" +
row.parent_path + "', '" +
row.full_name + "'," +
row.isHistory + ", now() " +
"true" + ", now() " +
//row.isHistory + ", now() " +
");";
sb.Append(ss);
}
@ -293,10 +294,9 @@ CREATE TABLE `import_niagara_item` (
using (IDbConnection conn = GetDbConnection())
{
conn.Open();
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
try
{
//改成每次都新增
string sql = @"SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
@ -307,6 +307,7 @@ SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `import_niagara_item_history`;
CREATE TABLE `import_niagara_item_history` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`device_number` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT ' TagName ',
`device_area_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
`device_building_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
`device_system_tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
@ -321,11 +322,15 @@ CREATE TABLE `import_niagara_item_history` (
`full_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
`check_status` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 271 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_device_number` (`device_number`)
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;";
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
await conn.ExecuteAsync(sql);
}
#region import_niagara_item資料表中選取的棟別
//foreach (var b in building)
@ -336,14 +341,20 @@ SET FOREIGN_KEY_CHECKS = 1;";
//}
#endregion
StringBuilder sb = new StringBuilder();
int count = 0;
#region import_niagara_item資料表
string ss = string.Empty;
foreach (var row in ds)
{
string ss = $@" insert import_niagara_item_history(device_area_tag, device_building_tag, device_system_tag, device_name_tag,
device_floor_tag, device_master_tag, device_last_name_tag, device_serial_tag, device_point_name, parent_path, full_name, is_history, created_at)
values('" +
if (count == 0)
{
ss = @"insert import_niagara_item_history(device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_floor_tag, device_master_tag,
device_last_name_tag, device_serial_tag, device_point_name, parent_path, full_name, is_history, created_at) values";
}
ss += $@" ('" +
row.device_area_tag + "', '" +
row.device_building_tag + "', '" +
row.device_system_tag + "', '" +
@ -355,13 +366,37 @@ device_floor_tag, device_master_tag, device_last_name_tag, device_serial_tag, d
row.device_point_name + "', '" +
row.parent_path + "', '" +
row.full_name + "'," +
row.isHistory + ", now() " +
");";
"true" + ", now() " +
")";
count++;
if (count == 100)
{
ss += ";";
sb.Append(ss);
}
if (sb.Length > 0)
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
await conn.ExecuteAsync(sb.ToString());
}
sb.Clear();
ss = string.Empty;
count = 0;
}
else
ss += ",";
}
sb.Append(ss);
if (sb.Length > 0)
{
sb.Clear();
ss = ss.Remove(ss.Length - 1);
ss += ";";
sb.Append(ss);
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
await conn.ExecuteAsync(sb.ToString());
}
sb.Clear();
}
#endregion
@ -376,7 +411,6 @@ device_floor_tag, device_master_tag, device_last_name_tag, device_serial_tag, d
}
}
}
}
/// <summary>
/// 比對 device
/// </summary>