[後端] 修改device_item獲取

This commit is contained in:
dev02 2023-09-08 18:48:13 +08:00
parent 16ef04ef80
commit fb1d03c994
2 changed files with 52 additions and 36 deletions

View File

@ -286,16 +286,16 @@ namespace Backend.Services.Implement
isHistory = n.isHistory isHistory = n.isHistory
}); });
} }
else if (n.name.Split('/').Length == 11) //Arena_D2_CWB_L110_CAP_D2_CWB_L110_CAP_MET1_ER else if (n.name.Split('/').Length == 7) // Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/Summery
{ {
if (n.name.Split('/')[6] == "S" || n.name.Split('/')[6] == "CWB") //for security system and CWB system if (n.name.Split('/')[3] == "S" || n.name.Split('/')[3] == "CWB") //for security system and CWB system
{ {
result.Add(new ImpNiaItem { result.Add(new ImpNiaItem {
device_building_tag = n.name.Split('/')[5], device_building_tag = n.name.Split('/')[1],
device_system_tag = n.name.Split('/')[6], device_system_tag = n.name.Split('/')[2],
device_floor_tag = n.name.Split('/')[7], device_floor_tag = n.name.Split('/')[3],
device_name_tag = n.name.Split('/')[8], device_name_tag = n.name.Split('/')[4],
device_point_name = n.name.Split('/')[10], device_point_name = n.name.Split('/')[6],
full_name = n.displayName, full_name = n.displayName,
parent_path = oneStationName, parent_path = oneStationName,
isHistory = n.isHistory isHistory = n.isHistory
@ -305,11 +305,11 @@ namespace Backend.Services.Implement
{ {
result.Add(new ImpNiaItem result.Add(new ImpNiaItem
{ {
device_building_tag = n.name.Split('/')[5], device_building_tag = n.name.Split('/')[1],
//device_system_tag = n.name.Split('/')[1], //device_system_tag = n.name.Split('/')[1],
device_floor_tag = n.name.Split('/')[7], device_floor_tag = n.name.Split('/')[3],
device_name_tag = n.name.Split('/')[6], device_name_tag = n.name.Split('/')[2],
device_point_name = n.name.Split('/')[10], device_point_name = n.name.Split('/')[6],
full_name = n.displayName, full_name = n.displayName,
parent_path = oneStationName, parent_path = oneStationName,
isHistory = n.isHistory isHistory = n.isHistory

View File

@ -565,28 +565,39 @@ namespace Repository.BackendRepository.Implement
//本次有匯入的 isLink 改為 1, 沒有的 isLink = 0 //本次有匯入的 isLink 改為 1, 沒有的 isLink = 0
sb.Append($@" SET SQL_SAFE_UPDATES = 0; sb.Append($@" SET SQL_SAFE_UPDATES = 0;
update UPDATE device_item d
device_item d LEFT JOIN (
LEFT JOIN import_niagara_item m SELECT device_system_tag, device_name_tag, device_point_name, full_name
FROM import_niagara_item
LIMIT 100000 -- Specify your desired limit here
) m
ON d.device_system_tag = m.device_system_tag ON d.device_system_tag = m.device_system_tag
and d.device_name_tag = m.device_name_tag AND d.device_name_tag = m.device_name_tag
and d.points = m.device_point_name AND d.points = m.device_point_name
and d.full_name = m.full_name AND d.full_name = m.full_name
SET d.is_link = case when device_point_name is null then 0 else 1 end; SET d.is_link = CASE WHEN m.device_point_name IS NULL THEN 0 ELSE 1 END;
update
device_item d
LEFT JOIN import_niagara_item m
ON d.device_system_tag = m.device_system_tag
and d.device_name_tag = m.device_name_tag
and d.points = m.device_point_name
and d.full_name = m.full_name
and d.is_show_history = m.is_history
SET d.is_show_history = case when device_point_name is null then 0 else 1 end
where (m.is_history = 1 or d.is_show_history);
"); ");
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
sb.Clear();
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
UPDATE device_item d
LEFT JOIN (
SELECT m.device_system_tag, m.device_name_tag, m.device_point_name, m.full_name
FROM import_niagara_item m
WHERE (m.is_history = 1)
LIMIT 100000 -- Specify your desired limit here
) AS subquery
ON d.device_system_tag = subquery.device_system_tag
AND d.device_name_tag = subquery.device_name_tag
AND d.points = subquery.device_point_name
AND d.full_name = subquery.full_name
SET d.is_show_history = CASE WHEN subquery.device_point_name IS NULL THEN 0 ELSE 1 END
WHERE (d.is_show_history);");
await conn.ExecuteAsync(sb.ToString());
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -876,13 +887,18 @@ namespace Repository.BackendRepository.Implement
try try
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append($@"update device_item d sb.Append($@"UPDATE device_item d
inner JOIN import_niagara_item m ON INNER JOIN (
m.device_system_tag = d.device_system_tag and SELECT m.device_system_tag, m.device_name_tag, m.device_point_name, m.full_name
m.device_name_tag = d.device_name_tag and FROM import_niagara_item m
m.device_point_name = d.points join device_item d
set d.full_name=m.full_name LIMIT 100000 -- Specify your desired limit here
where d.full_name<>m.full_name;"); ) AS subquery
ON d.device_system_tag = subquery.device_system_tag
AND d.device_name_tag = subquery.device_name_tag
AND d.points = subquery.device_point_name
SET d.full_name = subquery.full_name
WHERE d.full_name <> subquery.full_name");
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
} }
catch (Exception exception) catch (Exception exception)