ibms-dome/Backend/Views/NiagaraDataSynchronize/Index.cshtml

260 lines
11 KiB
Plaintext
Raw Normal View History

@{
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>
</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();
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)
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";
rawDataImportTable.ajax.reload();
}
}
//#endregion
function SynchronizeData() {
if (ds.length > 0) {
document.getElementById('loadDataText').innerText = "同步中...";
showSpinner();
//比對資料有差異的話再同步到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,
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") {
hideSpinner();
toast_error(rel.msg);
2022-12-31 16:49:47 +08:00
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
return;
}
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
},
error: function () {
hideSpinner();
}
2022-12-31 16:49:47 +08:00
});
}
else {
document.getElementById('loadDataText').innerText = "查無資料 無法比對!";
}
}
2023-01-13 17:28:23 +08:00
function SyncDevItem()
{
//比對資料有差異的話再同步到device等資料表
var url_synchronize_data = "/NiagaraDataSynchronize/RawDataDevItemList/";
var url_synchronize_data_device_item = "/NiagaraDataSynchronize/DevIteComData/";
2023-04-21 17:40:18 +08:00
let object = {};
object.building = building;
2023-01-13 17:28:23 +08:00
$.ajax({
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") {
hideSpinner();
2023-01-13 17:28:23 +08:00
toast_error(rel.msg);
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
return;
}
2023-01-13 17:28:23 +08:00
$.ajax({
method: "POST",
url: url_synchronize_data_device_item,
data: JSON.stringify(rel.data),
cache: false,
async: false,
contentType: "application/json; charset=UTF-8",
dataType: 'json',
success: function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
hideSpinner();
2023-01-13 17:28:23 +08:00
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
return;
}
hideSpinner();
2023-01-13 17:28:23 +08:00
console.log(rel);
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date + ' ' + time;
document.getElementById('loadDataText').innerText = "比對完成 \n" + dateTime;
},
error: function () {
hideSpinner();
}
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');
}
</script>
}