niagara import 照明 node 處理

This commit is contained in:
GiteaAdmin 2023-03-28 13:48:30 +08:00
parent 707ae51080
commit e309b167a5
13 changed files with 3951 additions and 3738 deletions

View File

@ -763,7 +763,12 @@ namespace Backend.Controllers
if (post.Count > 0)
{
//清空device_node資料表
await backendRepository.TruncateTable("device_node");
//await backendRepository.TruncateTable("device_node");
//清空 3D 坐標
await backendRepository.ExecuteSql("update device set device_coordinate_3d = '';");
await backendRepository.ExecuteSql("update device_node set device_node_coordinate_3d = '';");
//await backendRepository.UpdateOneByCustomTable(deviceForLight, "device", $@" device_guid = '{device_guid}'");
int node_priority = 1;
@ -780,12 +785,12 @@ namespace Backend.Controllers
continue;
}
if (device_guid.ToString() != device_guid_record)
if (device_guid.ToString() != device_guid_record && !string.IsNullOrEmpty(idfc.node.device_coordinate_3d)) // 如果跟前一筆不同,才需要 update device.forge_dbid 與坐標
{
device_guid_record = device_guid.ToString();
node_priority = 1;
Dictionary<string, object> deviceForLight = new Dictionary<string, object>();
deviceForLight.Add("@device_coordinate_3d", idfc.device_coordinate_3d);
deviceForLight.Add("@device_coordinate_3d", idfc.node.device_coordinate_3d);
deviceForLight.Add("@forge_dbid", idfc.forge_dbid);
deviceForLight.Add("@room_name", idfc.room_name);
deviceForLight.Add("@updated_at", DateTime.Now);
@ -793,18 +798,19 @@ namespace Backend.Controllers
}
Dictionary<string, object> device = new Dictionary<string, object>();
device.Add("@device_node_guid", Guid.NewGuid());
device.Add("@deleted", 0);
device.Add("@device_guid", device_guid);
// device.Add("@device_node_guid", Guid.NewGuid());
//device.Add("@deleted", 0);
device.Add("@device_guid", device_guid); // 父層由 forge 提供
device.Add("@device_node_coordinate_3d", (idfc.node == null) ? idfc.device_coordinate_3d: idfc.node.device_coordinate_3d);
device.Add("@forge_dbid", (idfc.node == null) ? idfc.forge_dbid: idfc.node.forge_dbid);
device.Add("@device_number", (idfc.node == null) ? idfc.device_number : idfc.node.device_number);
//device.Add("@device_number", (idfc.node == null) ? idfc.device_number : idfc.node.device_number);
device.Add("@priority", node_priority);
device.Add("@created_by", myUserInfo.Userinfo_guid);
device.Add("@created_at", DateTime.Now);
//device.Add("@created_by", myUserInfo.Userinfo_guid);
//device.Add("@created_at", DateTime.Now);
node_priority++;
await backendRepository.AddOneByCustomTableReturnId(device, "device_node", false);
await backendRepository.UpdateOneByCustomTable(device, "device_node", $@" device_number = '{idfc.node.device_number}'");
// await backendRepository.AddOneByCustomTableReturnId(device, "device_node", false);
}
else
{

View File

@ -81,8 +81,9 @@ namespace Backend.Controllers
try
{
var building = ds.FirstOrDefault().building;
await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building);
await niagaraDataSynchronizeRepository.DeviceComparison();
string LightSwitchLevel = await niagaraDataSynchronizeRepository.getLightSwitchLevel(); //獲取照明開關 是否在 device or device_node
await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building); // 匯入 MySQL table: import_niagara_tag
await niagaraDataSynchronizeRepository.DeviceComparison(LightSwitchLevel);
await niagaraDataSynchronizeRepository.CheckDiffFullNameAndCover();
await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName();
await niagaraDataSynchronizeRepository.InsertBuildingMenu();
@ -144,10 +145,10 @@ namespace Backend.Controllers
try
{
var building = ds.FirstOrDefault().device_building_tag;
await niagaraDataSynchronizeRepository.InsertItemFromNiagara(ds, building);
await niagaraDataSynchronizeRepository.DeviceItemComparison();
await niagaraDataSynchronizeRepository.CheckItemDiffFullNameAndCover();
await niagaraDataSynchronizeRepository.ItemCheckFullNameEmptyReplaceByDeviceName();
await niagaraDataSynchronizeRepository.InsertItemFromNiagara(ds, building); // insert 暫存table import_niagara_item
await niagaraDataSynchronizeRepository.DeviceItemComparison(); //insert device_item
await niagaraDataSynchronizeRepository.CheckItemDiffFullNameAndCover(); // update device_item.fullname
await niagaraDataSynchronizeRepository.ItemCheckFullNameEmptyReplaceByDeviceName(); // 檢查device_item內FullName為空的值以points取代
await niagaraDataSynchronizeRepository.CheckItemIsShowHistory();
result = true;

View File

@ -105,6 +105,13 @@ namespace Backend.Services.Implement
return result;
}
/// <summary>
/// 獲取 niagara history 中的點位
/// </summary>
/// <param name="bqlUrlString"></param>
/// <param name="urlString"></param>
/// <param name="slot"></param>
/// <returns></returns>
public List<ImpNiaItem> obixHisQuery(string bqlUrlString, string urlString, string slot)
{
String username = "obixUser";
@ -202,7 +209,16 @@ namespace Backend.Services.Implement
} else if (tagName.Split('_').Length == 6)
{ //巨蛋 tag 5 段版本
ImpNiaItem row = new ImpNiaItem();
row.device_building_tag = tagName.Split('_')[0];
row.device_system_tag = tagName.Split('_')[1];
//row.device_floor_tag = tagName.Split('_')[4];
row.device_name_tag = tagName.Split('_')[3];
row.device_point_name = tagName.Split('_')[8];
row.parent_path = stationName;
//full_name 其實是點位名稱 point_name
row.full_name = conPoint.Where(x => x.name == tagName).Select(x => x.displayName).FirstOrDefault();
}
}
}

View File

@ -16,8 +16,8 @@
"MySqlDBConfig": {
"Server": "FYlY+w0XDIz+jmF2rlZWJw==", //0.201
"Port": "js2LutKe+rdjzdxMPQUrvQ==",
"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
//"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
"Password": "FVAPxztxpY4gJJKQ/se4bQ=="
}

View File

@ -276,9 +276,9 @@
//launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dmVnb29nemNhdmNia2l0aHl2bHJzdnJjdGg2dHR3eWgtMjAyMzAyX2libXMvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU2JUE4JUExJUU1JUJDJThGK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8lRTklOUIlQkIlRTYlQTIlQUYlRTclQjQlQjAlRTclQUYlODAlRTclODklODhfMDIyNC5ud2Q")
// 0303
launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dmVnb29nemNhdmNia2l0aHl2bHJzdnJjdGg2dHR3eWgtMjAyMzAyX2libXMvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU2JUE4JUExJUU1JUJDJThGK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8lRTklOUIlQkIlRTYlQTIlQUYlRTclQjQlQjAlRTclQUYlODAlRTclODklODhfMDMwMy5ud2Q")
//launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dmVnb29nemNhdmNia2l0aHl2bHJzdnJjdGg2dHR3eWgtMjAyMzAyX2libXMvJUUzJTgwJTkwJUU1JThGJUIwJUU1JThDJTk3JUU0JUI4JUFEJUU4JThGJUIxJUU1JUE0JUE3JUU2JUE4JTkzJUUzJTgwJTkxQVJDJUU5JTlCJTk5JUU2JUE4JUExJUU1JUJDJThGK01FUCVFNiU4QiU4NiVFNyVCMyVCQiVFNyVCNSVCMV8lRTklOUIlQkIlRTYlQTIlQUYlRTclQjQlQjAlRTclQUYlODAlRTclODklODhfMDMwMy5ud2Q")
// 0221 WSP
//launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dmVnb29nemNhdmNia2l0aHl2bHJzdnJjdGg2dHR3eWgtMjAyMzAyX2libXMvQmFucWlhbyUyMFRhaXBlaSUyME1haW4lMjBPZmZpY2UtQUxMXzAyMjEubndk")
launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dmVnb29nemNhdmNia2l0aHl2bHJzdnJjdGg2dHR3eWgtMjAyMzAyX2libXMvQmFucWlhbyUyMFRhaXBlaSUyME1haW4lMjBPZmZpY2UtQUxMXzAyMjEubndk")
});
function move1Floor() {

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 124 KiB

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 143 KiB

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 222 KiB

View File

@ -263,7 +263,7 @@ namespace FrontendWebApi.ApiControllers
ApiResult<List<FloorList>> apiResult = new ApiResult<List<FloorList>>();
//是否顯示DeviceNode
string sqlStringqueryModuleLightNodeDisplay = $"SELECT system_value FROM variable WHERE system_type = 'module' AND system_key = 'displaynode'";
string sqlStringqueryModuleLightNodeDisplay = $"SELECT system_value FROM variable WHERE system_type = 'module_light_switch' AND system_key = 'displaynode'";
string displayNode = await backendRepository.GetOneAsync<string>(sqlStringqueryModuleLightNodeDisplay);
if (string.IsNullOrEmpty(fd.sub_system_tag))
{
@ -310,6 +310,8 @@ namespace FrontendWebApi.ApiControllers
dn.device_guid,
dn.full_name AS Device_node_full_name,
dn.device_node_coordinate,
dn.device_node_coordinate_3d,
dn.device_number,
dn.priority,
dn.forge_dbid
FROM device_node dn
@ -768,12 +770,12 @@ namespace FrontendWebApi.ApiControllers
dn.full_name AS Device_node_full_name,
dn.device_node_coordinate,
dn.device_node_coordinate_3d,
dn.device_number,
dn.priority,
dn.forge_dbid
FROM device_node dn
WHERE dn.deleted = 0 AND dn.device_guid = @device_guid
ORDER BY dn.priority ASC";
d.Device_nodes = await backendRepository.GetAllAsync<DeviceNode>(sql_node, new { device_guid = d.device_guid });
}
@ -927,10 +929,12 @@ namespace FrontendWebApi.ApiControllers
try
{
var sqlString = $@" SELECT * FROM floor WHERE
priority = (SELECT MIN(priority) FROM floor WHERE priority > (SELECT priority FROM floor WHERE floor_guid = @floor_guid)
AND building_tag = (SELECT building_tag FROM floor WHERE floor_guid = @floor_guid))
AND building_tag = (SELECT building_tag FROM floor WHERE floor_guid = @floor_guid)";
//var sqlString = $@" SELECT * FROM floor WHERE
// priority = (SELECT MIN(priority) FROM floor WHERE priority > (SELECT priority FROM floor WHERE floor_guid = @floor_guid)
// AND building_tag = (SELECT building_tag FROM floor WHERE floor_guid = @floor_guid))
// AND building_tag = (SELECT building_tag FROM floor WHERE floor_guid = @floor_guid)";
var sqlString = $@" SELECT * FROM floor WHERE floor_guid = @floor_guid;";
var param = new { @floor_guid = f.floor_guid };
var fr = await backendRepository.GetOneAsync<Floor>(sqlString, param);

View File

@ -863,6 +863,7 @@ namespace FrontendWebApi.ApiControllers
try
{
// User 權限可見的系統
var dbsub = await frontendRepository.GetAllAsync<HistoryDBMainSub>(
@$"select distinct v1.system_key main_name, v1.system_value main_system_tag, v2.system_key sub_name, v2.system_value sub_system_tag, v1.system_priority, v2.system_priority,
d.device_number, d.full_name as device_full_name, d.device_serial_tag, b.AuthCode
@ -871,9 +872,10 @@ namespace FrontendWebApi.ApiControllers
join userinfo c on c.role_guid = a.role_guid
join variable v2 on b.ShowView = v2.id and v2.system_type = @sub_system_type
join variable v1 on v1.id = v2.system_parent_id and v1.system_type = @main_system_type
join device d on v1.system_value = d.device_system_tag and v2.system_value = d.device_name_tag and d.deleted = 0
left join device d on v1.system_value = d.device_system_tag and v2.system_value = d.device_name_tag and d.deleted = 0
where c.account = @account
order by v1.system_priority, v2.system_priority", new { @account = myUser.account, @sub_system_type = sub_system_type, @main_system_type = main_system_type });
// User
var dbbuilding = await frontendRepository.GetAllAsync<History_Build>(
@$"select distinct d.building_guid,d.full_name,d.priority from role_auth a
join auth_page b on a.AuthCode = b.AuthCode

View File

@ -207,6 +207,7 @@ namespace FrontendWebApi.Models
public string Device_node_full_name { get; set; }
public string Device_node_coordinate { get; set; }
public string Device_node_coordinate_3D { get; set; }
public string Device_number { get; set; }
public int Priority { get; set; }
public int forge_dbid { get; set; }
}

View File

@ -73,21 +73,22 @@ namespace Repository.BackendRepository.Implement
if (string.IsNullOrEmpty(row.tag_name)) continue;
string[] arrTag = row.tag_name.Split('_');
if (arrTag.Length == 8)
{
sb.Append($@" insert into import_niagara_tag(niagara_tags, 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_full_name, atDateTime) values('" +
row.tag_name + "', '" +
arrTag[0] + "', '" +
arrTag[1] + "', '" +
arrTag[2] + "', '" +
arrTag[3] + "', '" +
arrTag[4] + "', '" +
arrTag[5] + "', '" +
arrTag[6] + "', '" +
arrTag[7] + "', '" +
row.displayName + "', " +
"now());");
row.tag_name + "', '" + //niagara_tags
arrTag[0] + "', '" + //device_area_tag
arrTag[1] + "', '" + //device_building_tag
arrTag[2] + "', '" + //device_system_tag
arrTag[3] + "', '" + //device_name_tag
arrTag[4] + "', '" + //device_floor_tag
arrTag[5] + "', '" + //device_master_tag
arrTag[6] + "', '" + //device_last_name_tag
arrTag[7] + "', '" + //device_serial_tag
row.displayName + "', " + //device_full_name
"now());"); //atDateTime
}
}
if (sb.Length > 0)
@ -108,11 +109,28 @@ namespace Repository.BackendRepository.Implement
}
}
/// <summary>
/// 獲取照明開關 是否在 device_node 層
/// </summary>
/// <returns></returns>
public async Task<string> getLightSwitchLevel()
{
using (IDbConnection conn = GetDbConnection())
{
conn.Open();
var sql = "select system_value from variable where system_type = 'module_light_switch' ";
var module_light_switch = conn.QueryAsync<string>(sql).Result.FirstOrDefault();
conn.Close();
return module_light_switch;
}
}
/// <summary>
/// 更新import_niagara_tag資料表
/// </summary>
/// <param name="ds"></param>
/// <param name="building"></param>
/// <returns></returns>
public async Task InsertItemFromNiagara(List<ImpNiaItem> ds, string building)
{
@ -179,7 +197,7 @@ namespace Repository.BackendRepository.Implement
/// 比對 device
/// </summary>
/// <returns></returns>
public async Task DeviceComparison()
public async Task DeviceComparison(string LightSwitchLevel)
{
using (IDbConnection conn = GetDbConnection())
{
@ -199,6 +217,7 @@ namespace Repository.BackendRepository.Implement
result = (await conn.QueryAsync<NiagaraTags>(sb.ToString())).ToList<NiagaraTags>();
sb.Clear();
#region device, device_kind
//新增至device, is_link = 1
if (result.Count > 0)
{
@ -216,21 +235,29 @@ namespace Repository.BackendRepository.Implement
foreach (var data in result)
{
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() );");
//開關控制在個別燈具(device_node層) and 小類為二線式照明系統 and tag第八段開頭不是 G
if (LightSwitchLevel == "node" && data.device_name_tag == "L1" && data.device_serial_tag.Substring(0, 1) != "G")
{
// 燈具新增 device_node
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() );");
}
}
foreach (var data in result2)
@ -253,18 +280,69 @@ namespace Repository.BackendRepository.Implement
{
await conn.ExecuteAsync(sb.ToString());
await conn.ExecuteAsync(sb2.ToString());
sb.Clear();
sb2.Clear();
}
}
#endregion
//device有niagara沒有is_link 更新成 0
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
#region device_node
sb.Append($@" SELECT m.* FROM import_niagara_tag m
LEFT JOIN device_node d ON m.niagara_tags = d.device_number
WHERE d.device_number IS NULL");
result = (await conn.QueryAsync<NiagaraTags>(sb.ToString())).ToList<NiagaraTags>();
sb.Clear();
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_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_name_tag = x.Key.device_name_tag2
});
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
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());");
}
}
if (sb.Length > 0)
{
await conn.ExecuteAsync(sb.ToString());
sb.Clear();
}
}
#endregion
//device有niagara沒有is_link 更新成 0
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
UPDATE device d LEFT JOIN import_niagara_tag m ON d.device_number = m.niagara_tags
SET d.is_link = 0
WHERE m.niagara_tags IS NULL");
WHERE m.niagara_tags IS NULL;");
await conn.ExecuteAsync(sb.ToString());
// device_node 有, niagara沒有, is_link 更新成 0
sb.Append($@" SET SQL_SAFE_UPDATES = 0;
UPDATE device_node d LEFT JOIN import_niagara_tag m ON d.device_number = m.niagara_tags
SET d.is_link = 0
WHERE m.niagara_tags IS NULL;");
await conn.ExecuteAsync(sb.ToString());
}
catch (Exception exception)
{
@ -628,13 +706,13 @@ namespace Repository.BackendRepository.Implement
try
{
StringBuilder sb = new StringBuilder();
sb.Append("update device_item d " +
"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 " +
"set d.full_name=m.full_name " +
"where d.full_name<>m.full_name;");
sb.Append($@"update device_item d
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
set d.full_name=m.full_name
where d.full_name<>m.full_name;");
await conn.ExecuteAsync(sb.ToString());
}
catch (Exception exception)
@ -650,7 +728,7 @@ namespace Repository.BackendRepository.Implement
}
/// <summary>
/// 先將device_ite的is_show_history全部關掉
/// 先將device_item 的is_show_history全部關掉
/// 根據niagara輸入資料來決定要開哪些點
/// </summary>
/// <returns></returns>

View File

@ -13,6 +13,14 @@ namespace Repository.BackendRepository.Interface
/// <param name="building"></param>
/// <returns></returns>
Task InsertNiagaraTagList(List<Device_value> ds, string building);
/// <summary>
/// 獲取照明開關 是否在 device_node 層
/// </summary>
/// <returns></returns>
Task<string> getLightSwitchLevel();
/// <summary>
/// 同步N4至資料表 import_niagara_item
/// </summary>
@ -24,7 +32,7 @@ namespace Repository.BackendRepository.Interface
/// 比對 device
/// </summary>
/// <returns></returns>
Task DeviceComparison();
Task DeviceComparison(string LightSwitchLevel);
/// <summary>
///檢查Device與import_niagara_tag 的Full_Name是否相同 不同則Full_Name從import_niagara_tag 覆蓋至device
/// </summary>