This commit is contained in:
dev01 2023-09-20 17:58:12 +08:00
commit 23bd391c5d
8 changed files with 292 additions and 198 deletions

View File

@ -389,6 +389,17 @@ namespace Backend.Controllers
ORDER BY bm.priority, mv.system_priority ASC, sv.system_priority ASC, sv.created_at DESC ", ORDER BY bm.priority, 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 }); new { building_tag = post.building_tag, MainList = post.MainList, main_system_type = main_system_type, sub_system_type = sub_system_type });
if (buildMenuTables.Any())
{
var data = buildMenuTables.Where(x => x.main_system_tag == "S" && x.sub_system_tag.Contains("CA")).ToList();
foreach (var d in data)
{
if (d.sub_system_tag.Length == 3 && !(d.building_tag[0] == d.sub_system_tag[0]))
{
buildMenuTables.Remove(d);
}
}
}
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = buildMenuTables; apiResult.Data = buildMenuTables;
} }

View File

@ -557,21 +557,33 @@ namespace Backend.Controllers
} }
else else
{ {
Dictionary<string, object> Device_itemDic = new Dictionary<string, object>() var sql = $@"SELECT di.id FROM device_item di
{ WHERE di.deleted = 0 AND device_system_tag = @device_system_tag and device_name_tag = @device_name_tag and points = @points";
{ "@full_name", device_Item.full_name},
{ "@points", device_Item.points},
{ "@unit", device_Item.unit},
{ "@is_show", device_Item.is_show},
{ "@is_show_riserDiagram", device_Item.is_show_riserDiagram},
{ "@is_controll", device_Item.is_controll},
{ "@is_bool", device_Item.is_bool},
{ "@is_show_history", device_Item.is_show_history},
{ "@updated_by", myUserInfo.Userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
};
await backendRepository.UpdateOneByCustomTable(Device_itemDic, "device_item", "id='" + device_Item.id + "'"); var deviceItemId = await backendRepository.GetAllAsync<int>(sql,
new { points = device_Item.points, device_system_tag = main_tag, device_name_tag = sub_tag });
if (deviceItemId.Count() > 0)
{
foreach (var id in deviceItemId)
{
Dictionary<string, object> Device_itemDic = new Dictionary<string, object>()
{
{ "@full_name", device_Item.full_name},
{ "@points", device_Item.points},
{ "@unit", device_Item.unit},
{ "@is_show", device_Item.is_show},
{ "@is_show_riserDiagram", device_Item.is_show_riserDiagram},
{ "@is_controll", device_Item.is_controll},
{ "@is_bool", device_Item.is_bool},
{ "@is_show_history", device_Item.is_show_history},
{ "@updated_by", myUserInfo.Userinfo_guid},
{ "@updated_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
};
await backendRepository.UpdateOneByCustomTable(Device_itemDic, "device_item", "id='" + id + "'");
}
}
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "修改成功"; apiResult.Msg = "修改成功";
@ -652,7 +664,7 @@ namespace Backend.Controllers
{ {
string sWhere = @$"deleted = @Deleted AND id = @id"; string sWhere = @$"deleted = @Deleted AND id = @id";
object param = new { Deleted = 0, id = id}; object param = new { Deleted = 0, id = id };
var device_Item = await backendRepository.GetOneAsync<Device_item>("device_item", sWhere, param); var device_Item = await backendRepository.GetOneAsync<Device_item>("device_item", sWhere, param);
@ -663,7 +675,9 @@ namespace Backend.Controllers
return apiResult; return apiResult;
} }
await backendRepository.DeleteOne(id.ToString(), "device_item", "id"); string sql = $@"update device_item set deleted = 1 where device_system_tag = '{device_Item.device_system_tag}' and device_name_tag = '{device_Item.device_name_tag}' and deleted = 0
and points = '{device_Item.points}'";
await backendRepository.ExecuteSql(sql);
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Msg = "刪除成功"; apiResult.Msg = "刪除成功";

View File

@ -520,7 +520,7 @@ namespace Backend.Controllers
{ {
buildingGuid = $" AND ap.building_tag = '{post.SelectedBuild}'"; buildingGuid = $" AND ap.building_tag = '{post.SelectedBuild}'";
} }
var sqlString = @$" SELECT ap.AuthCode, ap.MainName, ap.SubName FROM auth_page ap var sqlString = @$" SELECT ap.AuthCode, ap.MainName, ap.SubName, ap.ShowView FROM auth_page ap
WHERE ap.AuthType='{post.SelectedAuthType}' WHERE ap.AuthType='{post.SelectedAuthType}'
{buildingGuid} {buildingGuid}
AND ap.AuthCode NOT IN ( AND ap.AuthCode NOT IN (
@ -531,6 +531,23 @@ namespace Backend.Controllers
AND ap.AuthType='{post.SelectedAuthType}' AND ap.AuthType='{post.SelectedAuthType}'
)"; )";
authPage = await backendRepository.GetAllAsync<AuthPage>(sqlString); authPage = await backendRepository.GetAllAsync<AuthPage>(sqlString);
if (authPage.Any())
{
var sub_system = await backendRepository.GetAllAsync<VariableInfo>($@"select * from variable where system_type = 'device_system_category_layer3' and system_value LIKE '%CA'
and LENGTH(system_value) = 3 and system_value != '{post.SelectedBuild[0]}CA'");
if (sub_system.Any())
{
foreach (var d in sub_system)
{
var ap = authPage.Where(x => x.ShowView.Equals(d.id.ToString())).FirstOrDefault();
if (authPage != null)
{
authPage.Remove(ap);
}
}
}
}
} }
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = authPage; apiResult.Data = authPage;

View File

@ -121,6 +121,7 @@ namespace Backend.Models
public string AuthCode { get; set; } public string AuthCode { get; set; }
public string MainName { get; set; } public string MainName { get; set; }
public string SubName { get; set; } public string SubName { get; set; }
public string ShowView { get; set; }
} }
public class PostSaveRoleAuth public class PostSaveRoleAuth

View File

@ -235,24 +235,23 @@ namespace Backend.Services.Implement
result.Add(row); result.Add(row);
} }
else if (tagName.Split('_').Length == 6) else if (tagName.Split('_').Length == 7)
{ //巨蛋 tag 5 段版本 { //巨蛋 tag 5 段版本
ImpNiaItem row = new ImpNiaItem(); ImpNiaItem row = new ImpNiaItem();
if (tagName.Split('_')[1] == "S") //for security system if (tagName.Split('_')[2] == "S" || tagName.Split('_')[2] == "B" || tagName.Split('_')[2] == "CWB") //for security system and parking system
{ {
row.device_building_tag = tagName.Split('_')[0]; row.device_building_tag = tagName.Split('_')[1];
row.device_system_tag = tagName.Split('_')[1]; row.device_system_tag = tagName.Split('_')[2];
row.device_floor_tag = tagName.Split('_')[2]; row.device_floor_tag = tagName.Split('_')[3];
row.device_name_tag = tagName.Split('_')[3]; row.device_name_tag = tagName.Split('_')[4];
row.device_point_name = tagName.Split('_')[5]; row.device_point_name = tagName.Split('_')[6];
} }
else //for normal else //for normal
{ {
row.device_building_tag = tagName.Split('_')[0]; row.device_building_tag = tagName.Split('_')[1];
//row.device_system_tag = tagName.Split('_')[1]; row.device_floor_tag = tagName.Split('_')[3];
row.device_floor_tag = tagName.Split('_')[2]; row.device_name_tag = tagName.Split('_')[2];
row.device_name_tag = tagName.Split('_')[1]; row.device_point_name = tagName.Split('_')[6];
row.device_point_name = tagName.Split('_')[5];
} }
row.parent_path = stationName; row.parent_path = stationName;
@ -288,7 +287,7 @@ namespace Backend.Services.Implement
} }
else if (n.name.Split('/').Length == 7) // Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/Summery else if (n.name.Split('/').Length == 7) // Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/Summery
{ {
if (n.name.Split('/')[3] == "S" || n.name.Split('/')[3] == "CWB") //for security system and CWB system if (n.name.Split('/')[2] == "S" || n.name.Split('/')[2] == "B" || n.name.Split('/')[2] == "CWB") //for security system and CWB system
{ {
result.Add(new ImpNiaItem { result.Add(new ImpNiaItem {
device_building_tag = n.name.Split('/')[1], device_building_tag = n.name.Split('/')[1],

View File

@ -22,9 +22,9 @@
//"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel //"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel
//"Database": "iuaY0h0+TWkir44/eZLDqw==", //tpe_dome_office //"Database": "iuaY0h0+TWkir44/eZLDqw==", //tpe_dome_office
//"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut //"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut
//"Database": "+5RAiFLJVU+LRyDxF1K/pcLZaoZa4k/thZqF6xKoCag=", //dome_online_0821 "Database": "+5RAiFLJVU+LRyDxF1K/pcLZaoZa4k/thZqF6xKoCag=", //dome_online_0821
//"Database": "2U+9jYGy0dCbMzLaguBXow==", //tpe_dome_mall //"Database": "2U+9jYGy0dCbMzLaguBXow==", //tpe_dome_mall
"Database": "FbHCCU4CapG9UryANXC1W+iMe403Bd82RnA7bCNVbL0=", //ibms_dome_cinema, //"Database": "FbHCCU4CapG9UryANXC1W+iMe403Bd82RnA7bCNVbL0=", //ibms_dome_cinema,
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==", "Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
"Password": "FVAPxztxpY4gJJKQ/se4bQ==" "Password": "FVAPxztxpY4gJJKQ/se4bQ=="
}, },

View File

@ -585,7 +585,7 @@ namespace FrontendWebApi.ApiControllers
left join floor f on d.device_floor_tag = f.full_name and f.deleted = 0 left join floor f on d.device_floor_tag = f.full_name and f.deleted = 0
{disasterjoinsql} {disasterjoinsql}
LEFT JOIN building_menu bm ON d.device_building_tag = bm.building_tag AND d.device_system_tag = bm.main_system_tag AND d.device_name_tag = bm.sub_system_tag LEFT JOIN building_menu bm ON d.device_building_tag = bm.building_tag AND d.device_system_tag = bm.main_system_tag AND d.device_name_tag = bm.sub_system_tag
where d.deleted = 0 and d.device_building_tag = '{post.building_tag}' {sWhere} where d.deleted = 0 and d.is_link = 1 and d.device_building_tag = '{post.building_tag}' {sWhere}
order by d.priority ASC, left(device_serial_tag, LENGTH(device_serial_tag) - 1) ASC"; order by d.priority ASC, left(device_serial_tag, LENGTH(device_serial_tag) - 1) ASC";
var devicelist = await backendRepository.GetAllAsync<DeviceFloor>(sql); var devicelist = await backendRepository.GetAllAsync<DeviceFloor>(sql);

View File

@ -283,7 +283,7 @@ namespace Repository.BackendRepository.Implement
sb.Append($@" update import_niagara_item a join dic_system b sb.Append($@" update import_niagara_item a join dic_system b
on a.device_name_tag COLLATE utf8mb4_0900_ai_ci = b.s2_code COLLATE utf8mb4_0900_ai_ci 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 set device_system_tag = b.s1_code
where (device_system_tag <> 'S' and device_system_tag <> 'CWB');"); where (device_system_tag <> 'S' and device_system_tag <> 'CWB' and device_system_tag <> 'B');");
} }
sb.Append($@" update import_niagara_item set full_name = device_point_name where full_name = '' or full_name is null;"); sb.Append($@" update import_niagara_item set full_name = device_point_name where full_name = '' or full_name is null;");
@ -315,200 +315,236 @@ namespace Repository.BackendRepository.Implement
using (IDbConnection conn = GetDbConnection()) using (IDbConnection conn = GetDbConnection())
{ {
conn.Open(); conn.Open();
using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled)) try
try {
List<NiagaraTags> result;
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
sb.Append($@"SELECT m.*
FROM import_niagara_tag m
WHERE NOT EXISTS (
SELECT 1
FROM device d
WHERE m.niagara_tags = d.device_number
);");
result = (await conn.QueryAsync<NiagaraTags>(sb.ToString())).ToList<NiagaraTags>();
sb.Clear();
#region device, device_kind
//新增至device, is_link = 1
if (result.Count > 0)
{ {
List<NiagaraTags> result; var result2 = result.GroupBy(x => new
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
sb.Append($@"SELECT m.*
FROM import_niagara_tag m
WHERE NOT EXISTS (
SELECT 1
FROM device d
WHERE m.niagara_tags = d.device_number
);");
result = (await conn.QueryAsync<NiagaraTags>(sb.ToString())).ToList<NiagaraTags>();
sb.Clear();
#region device, device_kind
//新增至device, is_link = 1
if (result.Count > 0)
{ {
var result2 = result.GroupBy(x => new device_building_tag2 = x.device_building_tag,
{ device_system_tag2 = x.device_system_tag,
device_building_tag2 = x.device_building_tag, device_name_tag2 = x.device_name_tag
device_system_tag2 = x.device_system_tag, }).Select(x => new Device_item8
device_name_tag2 = x.device_name_tag {
}).Select(x => new Device_item8 device_building_tag = x.Key.device_building_tag2,
{ device_system_tag = x.Key.device_system_tag2,
device_building_tag = x.Key.device_building_tag2, device_name_tag = x.Key.device_name_tag2
device_system_tag = x.Key.device_system_tag2, });
device_name_tag = x.Key.device_name_tag2
});
int count = 0; int count = 0;
foreach (var data in result) foreach (var data in result)
{
//開關控制在個別燈具(device_node層) and 小類為二線式照明系統 and tag第八段開頭不是 G
if (LightSwitchLevel == "node" && data.device_name_tag == "L1" && data.device_serial_tag.Substring(0, 1) != "G")
{ {
//開關控制在個別燈具(device_node層) and 小類為二線式照明系統 and tag第八段開頭不是 G // 燈具新增 device_node
if (LightSwitchLevel == "node" && data.device_name_tag == "L1" && data.device_serial_tag.Substring(0, 1) != "G") continue;
}
else {
sb.Append($@" insert device(device_guid, deleted, status, priority, is_link, device_area_tag,
device_building_tag, device_system_tag, device_name_tag, full_name, device_floor_tag, device_master,
device_last_name, device_serial_tag, device_number, device_system_category_layer3, visible, created_at, updated_at)
values(uuid(), 0, 1, 0, 1, '" +
data.device_area_tag + "', '" +
data.device_building_tag + "', '" +
data.device_system_tag + "', '" +
data.device_name_tag + "', '" +
data.device_full_name + "', '" +
data.device_floor_tag + "', '" +
data.device_master_tag + "', '" +
data.device_last_name_tag + "', '" +
data.device_serial_tag + "', '" +
data.niagara_tags + "', '" +
data.device_system_tag + "', 1, now(), now() );");
count += 1;
if (count >= 100)
{ {
// 燈具新增 device_node using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled))
continue;
}
else {
sb.Append($@" insert device(device_guid, deleted, status, priority, is_link, device_area_tag,
device_building_tag, device_system_tag, device_name_tag, full_name, device_floor_tag, device_master,
device_last_name, device_serial_tag, device_number, device_system_category_layer3, visible, created_at, updated_at)
values(uuid(), 0, 1, 0, 1, '" +
data.device_area_tag + "', '" +
data.device_building_tag + "', '" +
data.device_system_tag + "', '" +
data.device_name_tag + "', '" +
data.device_full_name + "', '" +
data.device_floor_tag + "', '" +
data.device_master_tag + "', '" +
data.device_last_name_tag + "', '" +
data.device_serial_tag + "', '" +
data.niagara_tags + "', '" +
data.device_system_tag + "', 1, now(), now() );");
count += 1;
if (count >= 100)
{ {
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
sb.Clear();
count = 0;
} }
} sb.Clear();
} count = 0;
}
}
}
count = 0; count = 0;
foreach (var data in result2) foreach (var data in result2)
{
var sqlString = new StringBuilder();
sqlString.Append("select * from device_kind where device_building_tag = '" + data.device_building_tag + "' and device_system_tag = '" + data.device_system_tag + "' and device_name_tag = '" + data.device_name_tag + "'");
var dk = (await conn.QueryAsync<device_kind>(sqlString.ToString())).ToList<device_kind>();
if (dk.Count == 0)
{ {
var sqlString = new StringBuilder(); sb2.Append($@"INSERT device_kind (device_kind_guid, device_building_tag, device_system_tag, device_name_tag,
sqlString.Append("select * from device_kind where device_building_tag = '" + data.device_building_tag + "' and device_system_tag = '" + data.device_system_tag + "' and device_name_tag = '" + data.device_name_tag + "'"); device_normal_flashing, device_close_flashing, device_error_flashing, device_error_independent,
var dk = (await conn.QueryAsync<device_kind>(sqlString.ToString())).ToList<device_kind>(); created_by, created_at)
VALUES (uuid(), '" + data.device_building_tag + "', '" + data.device_system_tag + "', '" + data.device_name_tag +
if (dk.Count == 0) "', 0, 0, 1, 0, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());");
count += 1;
if (count >= 100)
{ {
sb2.Append($@"INSERT device_kind (device_kind_guid, device_building_tag, device_system_tag, device_name_tag, using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled))
device_normal_flashing, device_close_flashing, device_error_flashing, device_error_independent,
created_by, created_at)
VALUES (uuid(), '" + data.device_building_tag + "', '" + data.device_system_tag + "', '" + data.device_name_tag +
"', 0, 0, 1, 0, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());");
count += 1;
if (count >= 100)
{ {
await conn.ExecuteAsync(sb2.ToString()); await conn.ExecuteAsync(sb2.ToString());
sb2.Clear();
count = 0;
} }
sb2.Clear();
count = 0;
} }
} }
}
if (sb.Length > 0) if (sb.Length > 0)
{
using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled))
{ {
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
await conn.ExecuteAsync(sb2.ToString()); await conn.ExecuteAsync(sb2.ToString());
sb.Clear();
sb2.Clear();
} }
sb.Clear();
sb2.Clear();
} }
#endregion }
#endregion
#region device_node #region device_node
sb.Append($@" SELECT m.* sb.Append($@" SELECT m.*
FROM import_niagara_tag m FROM import_niagara_tag m
WHERE NOT EXISTS ( WHERE NOT EXISTS (
SELECT 1 SELECT 1
FROM device_node d FROM device_node d
WHERE m.niagara_tags COLLATE utf8mb4_0900_ai_ci = d.device_number COLLATE utf8mb4_0900_ai_ci WHERE m.niagara_tags COLLATE utf8mb4_0900_ai_ci = d.device_number COLLATE utf8mb4_0900_ai_ci
);"); );");
result = (await conn.QueryAsync<NiagaraTags>(sb.ToString())).ToList<NiagaraTags>(); result = (await conn.QueryAsync<NiagaraTags>(sb.ToString())).ToList<NiagaraTags>();
sb.Clear(); sb.Clear();
if (result.Count > 0) if (result.Count > 0)
{
var result2 = result.GroupBy(x => new
{ {
var result2 = result.GroupBy(x => new device_building_tag2 = x.device_building_tag,
{ device_system_tag2 = x.device_system_tag,
device_building_tag2 = x.device_building_tag, device_name_tag2 = x.device_name_tag
device_system_tag2 = x.device_system_tag, }).Select(x => new Device_item8
device_name_tag2 = x.device_name_tag {
}).Select(x => new Device_item8 device_building_tag = x.Key.device_building_tag2,
{ device_system_tag = x.Key.device_system_tag2,
device_building_tag = x.Key.device_building_tag2, device_name_tag = x.Key.device_name_tag2
device_system_tag = x.Key.device_system_tag2, });
device_name_tag = x.Key.device_name_tag2
});
int count = 0; int count = 0;
foreach (var data in result) foreach (var data in result)
{
//開關控制在個別燈具(device_node層) and 小類為二線式照明系統 and tag第八段開頭不是 G
if (LightSwitchLevel == "node" && data.device_name_tag == "L1" && data.device_serial_tag.Substring(0, 1) != "G")
{ {
//開關控制在個別燈具(device_node層) and 小類為二線式照明系統 and tag第八段開頭不是 G // 燈具新增 device_node
if (LightSwitchLevel == "node" && data.device_name_tag == "L1" && data.device_serial_tag.Substring(0, 1) != "G") sb.Append($@"INSERT INTO device_node(device_node_guid, deleted, device_guid, device_number, full_name, created_by, created_at, updated_at)
VALUES (uuid(), 0, '' " + //device_guid 父層需要 forge 那邊提供
",'" + data.niagara_tags + // device_number
"', '" + data.device_full_name + //full_name
"','B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now(), now());");
count += 1;
if (count >= 100)
{ {
// 燈具新增 device_node using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled))
sb.Append($@"INSERT INTO device_node(device_node_guid, deleted, device_guid, device_number, full_name, created_by, created_at, updated_at)
VALUES (uuid(), 0, '' " + //device_guid 父層需要 forge 那邊提供
",'" + data.niagara_tags + // device_number
"', '" + data.device_full_name + //full_name
"','B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now(), now());");
count += 1;
if (count >= 100)
{ {
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
sb.Clear();
count = 0;
} }
sb.Clear();
count = 0;
} }
} }
}
if (sb.Length > 0) if (sb.Length > 0)
{
using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled))
{ {
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
sb.Clear();
} }
sb.Clear();
} }
#endregion }
#endregion
//device有niagara沒有is_link 更新成 0 //device有niagara有is_link 更新成 1
sb.Append($@" SET SQL_SAFE_UPDATES = 0; sb.Append($@" SET SQL_SAFE_UPDATES = 0;
UPDATE device d UPDATE device d
JOIN (
SELECT niagara_tags
FROM import_niagara_tag
LIMIT 100000
) i ON d.device_number = i.niagara_tags
SET d.is_link = 1");
using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled))
{
await conn.ExecuteAsync(sb.ToString());
}
sb.Clear();
//device有niagara沒有is_link 更新成 0
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
UPDATE device d
left JOIN (
SELECT niagara_tags
FROM import_niagara_tag
LIMIT 100000
) i ON d.device_number = i.niagara_tags
SET d.is_link = 0
WHERE d.is_link = 1 and i.niagara_tags is null;");
using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled))
{
await conn.ExecuteAsync(sb.ToString());
}
sb.Clear();
// device_node 有, niagara沒有, is_link 更新成 0
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
UPDATE device_node dn
left JOIN ( left JOIN (
SELECT niagara_tags SELECT niagara_tags
FROM import_niagara_tag FROM import_niagara_tag
LIMIT 100000 LIMIT 100000
) i ON d.device_number = i.niagara_tags ) i ON dn.device_number COLLATE utf8mb4_0900_ai_ci = i.niagara_tags COLLATE utf8mb4_0900_ai_ci
SET d.is_link = 0 SET dn.is_link = 0
WHERE d.is_link = 1 and i.niagara_tags is null;"); WHERE dn.is_link = 1 and i.niagara_tags is null;");
await conn.ExecuteAsync(sb.ToString());
sb.Clear(); using (TransactionScope scope = new TransactionScope((TransactionScopeOption)TransactionScopeAsyncFlowOption.Enabled))
{
// device_node 有, niagara沒有, is_link 更新成 0
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
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()); await conn.ExecuteAsync(sb.ToString());
} }
catch (Exception exception)
{
//throw exception;
throw;
}
finally
{
conn.Close();
}
{
} }
catch (Exception exception)
{
//throw exception;
throw;
}
finally
{
conn.Close();
}
} }
} }
@ -956,27 +992,43 @@ namespace Repository.BackendRepository.Implement
using (IDbConnection conn = GetDbConnection()) using (IDbConnection conn = GetDbConnection())
{ {
conn.Open(); conn.Open();
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) try
{ {
try StringBuilder sb = new StringBuilder();
//先全部關閉
sb.Append("update device_item set is_show_history=0;");
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{ {
StringBuilder sb = new StringBuilder();
//先全部關閉
//sb.Append("update device_item set is_show_history=0;");
sb.Append("update device_item set is_show_history = 0 " +
"WHERE(device_system_tag, device_name_tag, points, full_name, is_show_history) NOT IN " +
"(select distinct device_system_tag, device_name_tag, device_point_name, full_name, is_history From import_niagara_item where is_history = 1);");
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
} }
catch (Exception exception)
sb.Clear();
sb.Append($@"SET SQL_SAFE_UPDATES = 0;
update device_item di
JOIN (
select distinct device_system_tag, device_name_tag, device_point_name, full_name, device_building_tag from import_niagara_item where is_history = 1 limit 100000
) niagara
ON di.device_system_tag = niagara.device_system_tag
AND di.device_name_tag = niagara.device_name_tag
AND di.points = niagara.device_point_name
AND di.full_name = niagara.full_name
AND di.device_building_tag = niagara.device_building_tag
set di.is_show_history = 1");
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{ {
throw exception; await conn.ExecuteAsync(sb.ToString());
}
finally
{
conn.Close();
} }
} }
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
} }
} }