merged and change insert flow

This commit is contained in:
dev02 2023-11-16 14:47:34 +08:00
commit 8417a9ed62
4 changed files with 109 additions and 23 deletions

38
.gitignore vendored
View File

@ -1,3 +1,4 @@
# ---> VisualStudio
## Ignore Visual Studio temporary files, build results, and ## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons. ## files generated by popular Visual Studio add-ons.
## ##
@ -91,6 +92,7 @@ StyleCopReport.xml
*.tmp_proj *.tmp_proj
*_wpftmp.csproj *_wpftmp.csproj
*.log *.log
*.tlog
*.vspscc *.vspscc
*.vssscc *.vssscc
.builds .builds
@ -294,6 +296,17 @@ node_modules/
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw *.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output # Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts **/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts
@ -350,6 +363,9 @@ ASALocalRun/
# Local History for Visual Studio # Local History for Visual Studio
.localhistory/ .localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database # BeatPulse healthcheck temp database
healthchecksdb healthchecksdb
@ -361,5 +377,27 @@ MigrationBackup/
# Fody - auto-generated XML schema # Fody - auto-generated XML schema
FodyWeavers.xsd FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml
/Backend/wwwroot/upload/floor_map.zip /Backend/wwwroot/upload/floor_map.zip
*.nwd *.nwd

View File

@ -27,6 +27,7 @@ namespace Backend.Controllers
private Stopwatch stopwatch = new Stopwatch(); private Stopwatch stopwatch = new Stopwatch();
private Stopwatch stopwatchSection = new Stopwatch(); private Stopwatch stopwatchSection = new Stopwatch();
private Stopwatch syncStopWatch = new Stopwatch(); private Stopwatch syncStopWatch = new Stopwatch();
private static long syncWatchTime = 0;
public NiagaraDataSynchronizeController(IBackendRepository backendRepository, INiagaraDataSynchronizeRepository niagaraDataSynchronizeRepository,IBackEndConfigHelper backEndConfig) public NiagaraDataSynchronizeController(IBackendRepository backendRepository, INiagaraDataSynchronizeRepository niagaraDataSynchronizeRepository,IBackEndConfigHelper backEndConfig)
{ {
@ -103,7 +104,9 @@ namespace Backend.Controllers
[HttpPost] [HttpPost]
public async Task<ApiResult<bool>> CompareData([FromBody] List<Device_value> ds) public async Task<ApiResult<bool>> CompareData([FromBody] List<Device_value> ds)
{ {
syncStopWatch = new Stopwatch();
syncStopWatch.Start(); syncStopWatch.Start();
syncWatchTime = 0;
stopwatch = new Stopwatch(); stopwatch = new Stopwatch();
stopwatch.Start(); stopwatch.Start();
bool result = false; bool result = false;
@ -199,6 +202,10 @@ namespace Backend.Controllers
stopwatch.Stop(); stopwatch.Stop();
await niagaraDataSynchronizeRepository.KeepTimeLog("CompareData", stopwatch.ElapsedMilliseconds); await niagaraDataSynchronizeRepository.KeepTimeLog("CompareData", stopwatch.ElapsedMilliseconds);
syncStopWatch.Stop();
syncWatchTime += syncStopWatch.ElapsedMilliseconds;
return apiResult; return apiResult;
} }
@ -209,6 +216,8 @@ namespace Backend.Controllers
[HttpPost] [HttpPost]
public Task<ApiResult<List<ImpNiaItem>>> RawDataDevItemList([FromBody] Device_value building) public Task<ApiResult<List<ImpNiaItem>>> RawDataDevItemList([FromBody] Device_value building)
{ {
syncStopWatch = new Stopwatch();
syncStopWatch.Start();
ApiResult<List<ImpNiaItem>> apiResult = new ApiResult<List<ImpNiaItem>>(); ApiResult<List<ImpNiaItem>> apiResult = new ApiResult<List<ImpNiaItem>>();
stopwatch = new Stopwatch(); stopwatch = new Stopwatch();
stopwatch.Start(); stopwatch.Start();
@ -260,6 +269,9 @@ namespace Backend.Controllers
//return apiResult; //return apiResult;
stopwatch.Stop(); stopwatch.Stop();
niagaraDataSynchronizeRepository.KeepTimeLog("RawDataDevItemList", stopwatch.ElapsedMilliseconds); niagaraDataSynchronizeRepository.KeepTimeLog("RawDataDevItemList", stopwatch.ElapsedMilliseconds);
syncStopWatch.Stop();
syncWatchTime += syncStopWatch.ElapsedMilliseconds;
return Task.FromResult(apiResult); return Task.FromResult(apiResult);
} }
@ -270,6 +282,8 @@ namespace Backend.Controllers
[HttpPost] [HttpPost]
public async Task<ApiResult<bool>> DevIteComData([FromBody] List<ImpNiaItem> ds) public async Task<ApiResult<bool>> DevIteComData([FromBody] List<ImpNiaItem> ds)
{ {
syncStopWatch = new Stopwatch();
syncStopWatch.Start();
stopwatch = new Stopwatch(); stopwatch = new Stopwatch();
stopwatch.Start(); stopwatch.Start();
bool result = false; bool result = false;
@ -366,7 +380,8 @@ namespace Backend.Controllers
await niagaraDataSynchronizeRepository.KeepTimeLog("DevIteComData", stopwatch.ElapsedMilliseconds); await niagaraDataSynchronizeRepository.KeepTimeLog("DevIteComData", stopwatch.ElapsedMilliseconds);
syncStopWatch.Stop(); syncStopWatch.Stop();
await niagaraDataSynchronizeRepository.KeepTimeLog("Full sync usage record", syncStopWatch.ElapsedMilliseconds); syncWatchTime += syncStopWatch.ElapsedMilliseconds;
await niagaraDataSynchronizeRepository.KeepTimeLog("Full sync usage record", syncWatchTime);
return apiResult; return apiResult;
} }

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# ibms
智慧建築, 智慧工廠

View File

@ -1574,38 +1574,54 @@ SET FOREIGN_KEY_CHECKS = 1;";
#region import_niagara_item資料表 #region import_niagara_item資料表
stopwatchSection = new Stopwatch(); stopwatchSection = new Stopwatch();
stopwatchSection.Start(); stopwatchSection.Start();
string ss = string.Empty;
foreach (var row in ds) foreach (var row in ds)
{ {
string ss = $@" insert import_niagara_item_history(device_area_tag, device_building_tag, device_system_tag, device_name_tag, if (count == 0)
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 = @"insert import_niagara_item_history(device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_floor_tag, device_master_tag,
row.device_area_tag + "', '" + device_last_name_tag, device_serial_tag, device_point_name, parent_path, full_name, is_history, created_at) values";
row.device_building_tag + "', '" + }
row.device_system_tag + "', '" +
row.device_name_tag + "', '" + ss += $@" ('" +
row.device_floor_tag + "', '" + row.device_area_tag + "', '" +
row.device_master_tag + "', '" + row.device_building_tag + "', '" +
row.device_last_name_tag + "', '" + row.device_system_tag + "', '" +
row.device_serial_tag + "', '" + row.device_name_tag + "', '" +
row.device_point_name + "', '" + row.device_floor_tag + "', '" +
row.parent_path + "', '" + row.device_master_tag + "', '" +
row.full_name + "'," + row.device_last_name_tag + "', '" +
row.isHistory + ", now() " + row.device_serial_tag + "', '" +
");"; row.device_point_name + "', '" +
sb.Append(ss); row.parent_path + "', '" +
row.full_name + "'," +
row.isHistory + ", now() " +
")";
count++; count++;
if (count == 100) if (count == 100)
{ {
ss += ";";
sb.Append(ss);
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{ {
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
} }
sb.Clear(); sb.Clear();
ss = string.Empty;
count = 0; count = 0;
} }
else
ss += ",";
} }
sb.Append(ss);
if (sb.Length > 0) if (sb.Length > 0)
{ {
sb.Clear();
ss = ss.Remove(ss.Length - 1);
ss += ";";
sb.Append(ss);
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{ {
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
@ -1717,23 +1733,37 @@ device_floor_tag, device_master_tag, device_last_name_tag, device_serial_tag, d
stopwatchSection.Start(); stopwatchSection.Start();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int count = 0; int count = 0;
sql = string.Empty;
foreach (var data in dcp) foreach (var data in dcp)
{ {
sql = $@" insert into import_niagara_device_control_point(name, displayName, device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_floor_tag, if (count == 0)
device_number, device_point_name) {
values ('{data.name}', '{data.displayName}', '{data.device_area_tag}', '{data.device_building_tag}', '{data.device_system_tag}', '{data.device_name_tag}', sql = @"insert into import_niagara_device_control_point(name, displayName, device_area_tag, device_building_tag, device_system_tag, device_name_tag, device_floor_tag,
'{data.device_floor_tag}', '{data.device_number}', '{data.device_point_name}');"; device_number, device_point_name) values";
sb.Append(sql); }
sql += $@" ('{data.name}', '{data.displayName}', '{data.device_area_tag}', '{data.device_building_tag}', '{data.device_system_tag}', '{data.device_name_tag}',
'{data.device_floor_tag}', '{data.device_number}', '{data.device_point_name}')";
count++; count++;
if (count.Equals(100)) if (count.Equals(100))
{ {
sql += ";";
sb.Append(sql);
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
sb.Clear(); sb.Clear();
sql = string.Empty;
count = 0; count = 0;
} }
else
sql += ",";
} }
sb.Append(sql);
if (sb.Length > 0) if (sb.Length > 0)
{ {
sb.Clear();
sql = sql.Remove(sql.Length - 1);
sql += ";";
sb.Append(sql);
await conn.ExecuteAsync(sb.ToString()); await conn.ExecuteAsync(sb.ToString());
sb.Clear(); sb.Clear();
} }