[後端] 修改niagara同步
This commit is contained in:
parent
100a5bdc07
commit
060dc97391
@ -120,6 +120,7 @@ namespace Backend.Controllers
|
|||||||
await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName();
|
await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName();
|
||||||
await niagaraDataSynchronizeRepository.InsertBuildingMenu();
|
await niagaraDataSynchronizeRepository.InsertBuildingMenu();
|
||||||
await niagaraDataSynchronizeRepository.InsertSubSystemFloor();
|
await niagaraDataSynchronizeRepository.InsertSubSystemFloor();
|
||||||
|
await niagaraDataSynchronizeRepository.InsertFloor();
|
||||||
await this.DeviceDisasterAsync();
|
await this.DeviceDisasterAsync();
|
||||||
result = true;
|
result = true;
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@
|
|||||||
"Port": "js2LutKe+rdjzdxMPQUrvQ==",
|
"Port": "js2LutKe+rdjzdxMPQUrvQ==",
|
||||||
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
|
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
|
||||||
//"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
|
//"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
|
||||||
//"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome
|
"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome
|
||||||
//"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": "2U+9jYGy0dCbMzLaguBXow==", //tpe_dome_mall
|
//"Database": "2U+9jYGy0dCbMzLaguBXow==", //tpe_dome_mall
|
||||||
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
|
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
|
||||||
"Password": "FVAPxztxpY4gJJKQ/se4bQ=="
|
"Password": "FVAPxztxpY4gJJKQ/se4bQ=="
|
||||||
|
@ -453,7 +453,7 @@ namespace Repository.BackendRepository.Implement
|
|||||||
sb.Append($@" SELECT m.*
|
sb.Append($@" SELECT m.*
|
||||||
FROM import_niagara_item m
|
FROM import_niagara_item m
|
||||||
LEFT JOIN device_item d
|
LEFT JOIN device_item d
|
||||||
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
|
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 and m.device_building_tag collate utf8mb4_0900_ai_ci = d.device_building_tag
|
||||||
WHERE d.points IS NULL");
|
WHERE d.points IS NULL");
|
||||||
result = (await conn.QueryAsync<NiagaraTagsForItem>(sb.ToString())).ToList<NiagaraTagsForItem>();
|
result = (await conn.QueryAsync<NiagaraTagsForItem>(sb.ToString())).ToList<NiagaraTagsForItem>();
|
||||||
|
|
||||||
@ -913,5 +913,101 @@ namespace Repository.BackendRepository.Implement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// InsertFloor
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task InsertFloor()
|
||||||
|
{
|
||||||
|
using (IDbConnection conn = GetDbConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<NiagaraTags> result;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
#region comparison floor and sub_system_floor
|
||||||
|
sb.Append($@" select tag.*
|
||||||
|
from (
|
||||||
|
select device_building_tag, device_floor_tag
|
||||||
|
from import_niagara_tag
|
||||||
|
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
|
||||||
|
WHERE f.building_tag IS NULL;");
|
||||||
|
result = (await conn.QueryAsync<NiagaraTags>(sb.ToString())).ToList<NiagaraTags>();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
sb.Clear();
|
||||||
|
#region insert floor
|
||||||
|
if (result.Count > 0)
|
||||||
|
{
|
||||||
|
Dictionary<string, int> floorPriority = new Dictionary<string, int>();
|
||||||
|
foreach (var data in result)
|
||||||
|
{
|
||||||
|
FloorPriority fp = (await conn.QueryAsync<FloorPriority>($@"select building_tag, max(priority) as priority from floor
|
||||||
|
where building_tag = '{data.device_building_tag}' and deleted = 0 group by building_tag;")).FirstOrDefault();
|
||||||
|
int priority = 0;
|
||||||
|
|
||||||
|
if (fp == null && floorPriority.GetValueOrDefault(data.device_building_tag) == 0)
|
||||||
|
floorPriority.Add(data.device_building_tag, 0);
|
||||||
|
else if (fp != null && floorPriority.GetValueOrDefault(fp.building_tag) == 0)
|
||||||
|
floorPriority.Add(fp.building_tag, fp.Priority);
|
||||||
|
|
||||||
|
priority = ++floorPriority[data.device_building_tag];
|
||||||
|
|
||||||
|
sb.Append($@"insert into floor(floor_guid, building_tag, deleted, status, full_name, priority, created_by, created_at)
|
||||||
|
VALUES (uuid(), '{data.device_building_tag}', 0, 1, '{data.device_floor_tag}', {priority}, 'B43E3CA7-96DD-4FC7-B6E6-974ACC3B0878', now());");
|
||||||
|
}
|
||||||
|
if (sb.Length > 0)
|
||||||
|
{
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
sb.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region update unuse floor with niagara data
|
||||||
|
var floor = (await conn.QueryAsync<BuildFloor>($@"select f1.*
|
||||||
|
from floor as f1
|
||||||
|
left join (
|
||||||
|
select f.floor_guid
|
||||||
|
from (
|
||||||
|
select device_building_tag, device_floor_tag
|
||||||
|
from import_niagara_tag
|
||||||
|
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
|
||||||
|
) as f2 on f1.floor_guid = f2.floor_guid
|
||||||
|
where f2.floor_guid is null and f1.deleted = 0;")).ToList<BuildFloor>();
|
||||||
|
|
||||||
|
if (floor.Count > 0)
|
||||||
|
{
|
||||||
|
sb.Clear();
|
||||||
|
foreach (var f in floor)
|
||||||
|
{
|
||||||
|
sb.Append($"update floor set deleted = 1 where floor_guid = '{f.Floor_guid}';");
|
||||||
|
}
|
||||||
|
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,5 +71,10 @@ namespace Repository.BackendRepository.Interface
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task InsertSubSystemFloor();
|
Task InsertSubSystemFloor();
|
||||||
Task DeviceDisasterAysnc(List<Device_value_disaster> dv);
|
Task DeviceDisasterAysnc(List<Device_value_disaster> dv);
|
||||||
|
/// <summary>
|
||||||
|
/// InsertFloor
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task InsertFloor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,5 +65,6 @@ namespace Repository.Models
|
|||||||
{
|
{
|
||||||
public string Floor_guid { get; set; } //樓層GUID
|
public string Floor_guid { get; set; } //樓層GUID
|
||||||
public int Priority { get; set; }
|
public int Priority { get; set; }
|
||||||
|
public string building_tag { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user