2022-11-02 17:26:18 +08:00
|
|
|
|
@{
|
|
|
|
|
ViewData["MainNum"] = "2";
|
|
|
|
|
ViewData["SubNum"] = "3";
|
|
|
|
|
ViewData["Title"] = "Niagara資料同步";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<ol class="breadcrumb page-breadcrumb">
|
|
|
|
|
<li class="breadcrumb-item"><a href="javascript:void(0);">首頁</a></li>
|
|
|
|
|
<li class="breadcrumb-item">設備管理</li>
|
|
|
|
|
<li class="breadcrumb-item active">Niagara資料同步</li>
|
|
|
|
|
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
|
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col-xl-12">
|
|
|
|
|
<div id="panel-5" class="panel">
|
|
|
|
|
<div class="panel-container show">
|
|
|
|
|
<div class="panel-content">
|
|
|
|
|
|
|
|
|
|
<div class="form-row align-items-center">
|
|
|
|
|
<div class="col-12 mb-3">
|
|
|
|
|
<div class="custom-control custom-radio custom-control-inline">
|
|
|
|
|
<input type="radio" id="Building_B" name="Building" value="B" class="custom-control-input">
|
2023-04-21 17:40:18 +08:00
|
|
|
|
<label class="custom-control-label" for="Building_B"></label>
|
2022-11-02 17:26:18 +08:00
|
|
|
|
</div>
|
|
|
|
|
@*<div class="custom-control custom-radio custom-control-inline">
|
|
|
|
|
<input type="radio" id="Building_O" name="Building" value="O" class="custom-control-input">
|
|
|
|
|
<label class="custom-control-label" for="Building_O">辦公棟</label>
|
|
|
|
|
</div>*@
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="form-row align-items-center">
|
|
|
|
|
<button id="loadDataBtn" type="button" class="btn btn-primary" onclick="LoadData()">載入資料</button>
|
|
|
|
|
<button id="synchornizeDataBtn" type="button" class="btn btn-dark" onclick="SynchronizeData()">同步資料</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
<div class="form-row align-items-center">
|
|
|
|
|
<p id="loadDataText"></p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="mb-5">
|
|
|
|
|
<div class="card p-3 w-100">
|
|
|
|
|
<div class="card-header d-flex align-items-center flex-wrap">
|
|
|
|
|
<div class="card-title">
|
|
|
|
|
Niagara資料
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-body row">
|
|
|
|
|
<div class="col-12">
|
|
|
|
|
<!-- datatable start -->
|
|
|
|
|
<table id="niagara_data_table" class="table table-bordered table-hover m-0 text-center">
|
|
|
|
|
<thead class="thead-themed">
|
|
|
|
|
<tr>
|
|
|
|
|
<th>value</th>
|
|
|
|
|
<th>tag_name</th>
|
|
|
|
|
<th>point_name</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
@section Scripts {
|
|
|
|
|
<script>
|
|
|
|
|
var buildingId, building;
|
|
|
|
|
var rawDataImportTable;
|
|
|
|
|
var ds;
|
|
|
|
|
|
|
|
|
|
var today = new Date();
|
|
|
|
|
var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
|
|
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
|
ds = null;
|
|
|
|
|
document.getElementById("Building_B").checked = true;
|
|
|
|
|
|
2023-04-21 17:40:18 +08:00
|
|
|
|
projectName();
|
2022-11-02 17:26:18 +08:00
|
|
|
|
rawDataImportTable = $("#niagara_data_table").DataTable({
|
|
|
|
|
"columns": [
|
|
|
|
|
{
|
|
|
|
|
"data": "value"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": "tag_name"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": "point_name"
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
"ajax": {
|
|
|
|
|
"url": "/NiagaraDataSynchronize/RawDataList",
|
|
|
|
|
"type": "POST",
|
|
|
|
|
"dataSrc": function (rel) {
|
|
|
|
|
if (rel.code == "9999") {
|
|
|
|
|
toast_error(rel.msg);
|
|
|
|
|
document.getElementById('loadDataText').innerText = "載入資料出錯了!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = rel.data;
|
|
|
|
|
ds = data;
|
2023-01-04 09:13:59 +08:00
|
|
|
|
console.log(ds)
|
2022-11-02 17:26:18 +08:00
|
|
|
|
if (data == null || data.length == 0) {
|
|
|
|
|
this.data = [];
|
|
|
|
|
document.getElementById('loadDataText').innerText = "";
|
|
|
|
|
}
|
|
|
|
|
else if(data.length > 0) {
|
|
|
|
|
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
|
|
|
|
|
var dateTime = date + ' ' + time;
|
|
|
|
|
document.getElementById('loadDataText').innerText = "共 " + rel.data.length + " 筆資料 \n" + dateTime;
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//#region 載入Niagara資料
|
|
|
|
|
function LoadData() {
|
|
|
|
|
document.getElementById('loadDataText').innerText = "Loading...";
|
|
|
|
|
buildingId = document.querySelector('input[name="Building"]:checked').value;
|
|
|
|
|
if (buildingId == "B") {
|
2023-04-21 17:40:18 +08:00
|
|
|
|
//building = "B1";
|
2022-11-02 17:26:18 +08:00
|
|
|
|
rawDataImportTable.ajax.reload();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
function SynchronizeData() {
|
|
|
|
|
if (ds.length > 0) {
|
2023-07-19 11:42:55 +08:00
|
|
|
|
document.getElementById('loadDataText').innerText = "同步中...";
|
|
|
|
|
showSpinner();
|
2022-11-02 17:26:18 +08:00
|
|
|
|
//比對資料,有差異的話,再同步到device等資料表
|
|
|
|
|
var url_synchronize_data = "/NiagaraDataSynchronize/CompareData/";
|
|
|
|
|
|
2022-12-31 16:49:47 +08:00
|
|
|
|
$.each(ds, function (i, v) {
|
|
|
|
|
v.building = building;
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
method: "POST",
|
|
|
|
|
url: url_synchronize_data,
|
|
|
|
|
data: JSON.stringify(ds),
|
|
|
|
|
cache: false,
|
2023-07-18 11:10:38 +08:00
|
|
|
|
async: true,
|
2022-12-31 16:49:47 +08:00
|
|
|
|
contentType: "application/json; charset=UTF-8",
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
success: function (rel) {
|
|
|
|
|
if (rel.code != "0000") {
|
2023-07-18 14:08:43 +08:00
|
|
|
|
hideSpinner();
|
2023-07-19 11:42:55 +08:00
|
|
|
|
toast_error(rel.msg);
|
2022-12-31 16:49:47 +08:00
|
|
|
|
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-07-19 11:42:55 +08:00
|
|
|
|
|
2023-01-13 17:28:23 +08:00
|
|
|
|
SyncDevItem();
|
|
|
|
|
//var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
|
|
|
|
|
//var dateTime = date + ' ' + time;
|
|
|
|
|
//document.getElementById('loadDataText').innerText = "比對完成 \n" + dateTime;
|
2022-12-31 16:49:47 +08:00
|
|
|
|
},
|
2023-07-19 11:42:55 +08:00
|
|
|
|
error: function () {
|
|
|
|
|
hideSpinner();
|
|
|
|
|
}
|
2022-12-31 16:49:47 +08:00
|
|
|
|
});
|
2022-11-02 17:26:18 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
document.getElementById('loadDataText').innerText = "查無資料 無法比對!";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 17:28:23 +08:00
|
|
|
|
function SyncDevItem()
|
|
|
|
|
{
|
|
|
|
|
//比對資料,有差異的話,再同步到device等資料表
|
|
|
|
|
var url_synchronize_data = "/NiagaraDataSynchronize/RawDataDevItemList/";
|
2024-01-15 15:29:23 +08:00
|
|
|
|
var url_synchronize_data_device_item = "/NiagaraDataSynchronize/DevItemInsert/";
|
|
|
|
|
|
2023-04-21 17:40:18 +08:00
|
|
|
|
let object = {};
|
2024-01-15 15:29:23 +08:00
|
|
|
|
let dataLength = 0;
|
|
|
|
|
let curData = {};
|
|
|
|
|
let asyncSendData = [];
|
|
|
|
|
let contentLength = 5000;
|
2023-04-21 17:40:18 +08:00
|
|
|
|
object.building = building;
|
2024-01-15 15:29:23 +08:00
|
|
|
|
|
|
|
|
|
//device async
|
|
|
|
|
$.ajax({
|
2023-01-13 17:28:23 +08:00
|
|
|
|
method: "POST",
|
|
|
|
|
url: url_synchronize_data,
|
2023-04-21 17:40:18 +08:00
|
|
|
|
cache: false,
|
|
|
|
|
async: false,
|
|
|
|
|
contentType: "application/json; charset=UTF-8",
|
|
|
|
|
data: JSON.stringify(object),
|
|
|
|
|
dataType: 'json',
|
2023-01-13 17:28:23 +08:00
|
|
|
|
success: function (rel) {
|
|
|
|
|
if (rel.code != "0000") {
|
2023-07-19 11:42:55 +08:00
|
|
|
|
hideSpinner();
|
2023-01-13 17:28:23 +08:00
|
|
|
|
toast_error(rel.msg);
|
|
|
|
|
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-01-15 15:29:23 +08:00
|
|
|
|
|
|
|
|
|
//history async
|
|
|
|
|
$.ajax({
|
2023-01-13 17:28:23 +08:00
|
|
|
|
method: "POST",
|
2024-01-15 15:29:23 +08:00
|
|
|
|
url: '/NiagaraDataSynchronize/GetHistoryData/',
|
2023-01-13 17:28:23 +08:00
|
|
|
|
cache: false,
|
|
|
|
|
async: false,
|
|
|
|
|
contentType: "application/json; charset=UTF-8",
|
2024-01-15 15:29:23 +08:00
|
|
|
|
success: function (res) {
|
|
|
|
|
if (res.code != "0000") {
|
2023-07-18 14:08:43 +08:00
|
|
|
|
hideSpinner();
|
2024-01-15 15:29:23 +08:00
|
|
|
|
toast_error(res.msg);
|
2023-01-13 17:28:23 +08:00
|
|
|
|
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-15 15:29:23 +08:00
|
|
|
|
curData = rel.data;
|
|
|
|
|
let relDataLength = curData.length;
|
|
|
|
|
$.each(rel.data, function (index, val) {
|
|
|
|
|
if (relDataLength > 0) {
|
|
|
|
|
//push data, counting
|
|
|
|
|
asyncSendData.push(val);
|
|
|
|
|
dataLength++;
|
|
|
|
|
relDataLength--;
|
|
|
|
|
|
|
|
|
|
if (dataLength >= contentLength || relDataLength <= 0) {
|
|
|
|
|
//device_item async-insert
|
|
|
|
|
$.ajax({
|
|
|
|
|
method: "POST",
|
|
|
|
|
url: url_synchronize_data_device_item,
|
|
|
|
|
data: JSON.stringify(asyncSendData),
|
|
|
|
|
cache: false,
|
|
|
|
|
async: false,
|
|
|
|
|
contentType: "application/json; charset=UTF-8",
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
success: function (rel) {
|
|
|
|
|
if (rel.code != "0000") {
|
|
|
|
|
toast_error(rel.msg);
|
|
|
|
|
hideSpinner();
|
|
|
|
|
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//reset variable
|
|
|
|
|
dataLength = 0;
|
|
|
|
|
asyncSendData = [];
|
|
|
|
|
|
|
|
|
|
//device_item async-compare
|
|
|
|
|
if (relDataLength <= 0) {
|
|
|
|
|
$.ajax({
|
|
|
|
|
method: "POST",
|
|
|
|
|
url: '/NiagaraDataSynchronize/DevIteComData/',
|
|
|
|
|
cache: false,
|
|
|
|
|
async: false,
|
|
|
|
|
contentType: "application/json; charset=UTF-8",
|
|
|
|
|
success: function (rel) {
|
|
|
|
|
if (rel.code != "0000") {
|
|
|
|
|
toast_error(rel.msg);
|
|
|
|
|
hideSpinner();
|
|
|
|
|
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hideSpinner();
|
|
|
|
|
console.log(rel);
|
|
|
|
|
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
|
|
|
|
|
var dateTime = date + ' ' + time;
|
|
|
|
|
document.getElementById('loadDataText').innerText = "比對完成 \n" + dateTime;
|
|
|
|
|
},
|
|
|
|
|
error: function () {
|
|
|
|
|
hideSpinner();
|
|
|
|
|
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error: function () {
|
|
|
|
|
hideSpinner();
|
|
|
|
|
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-01-13 17:28:23 +08:00
|
|
|
|
},
|
2023-07-19 11:42:55 +08:00
|
|
|
|
error: function () {
|
|
|
|
|
hideSpinner();
|
2024-01-15 15:29:23 +08:00
|
|
|
|
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
|
|
|
|
|
return;
|
2023-07-19 11:42:55 +08:00
|
|
|
|
}
|
2023-01-13 17:28:23 +08:00
|
|
|
|
})
|
2024-01-15 15:29:23 +08:00
|
|
|
|
|
2023-01-13 17:28:23 +08:00
|
|
|
|
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
|
|
|
|
|
var dateTime = date + ' ' + time;
|
|
|
|
|
document.getElementById('loadDataText').innerText = "比對完成 \n" + dateTime;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-04-21 17:40:18 +08:00
|
|
|
|
|
|
|
|
|
function projectName()
|
|
|
|
|
{
|
|
|
|
|
$.post("/Variable/ProjectName", null, function (rel) {
|
|
|
|
|
building = "B1";
|
|
|
|
|
if (rel.code != "0000") {
|
|
|
|
|
toast_error(rel.msg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rel.data != null) {
|
|
|
|
|
building = rel.data.system_value.split('/')[1];
|
|
|
|
|
$(`label[for='Building_B']`).html(rel.data.system_key + building);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$(`label[for='Building_B']`).html('三菱B1');
|
|
|
|
|
}
|
|
|
|
|
}, 'json');
|
|
|
|
|
}
|
2022-11-02 17:26:18 +08:00
|
|
|
|
</script>
|
|
|
|
|
}
|