[Frontend] baja 函式: 訂閱各個系統的狀態,異常與否
This commit is contained in:
parent
a986a0abbe
commit
c90e3c320d
@ -2,6 +2,9 @@
|
||||
let baja_subscribe_end_device_callback_func; //設定BQL訂閱結束之後要回傳的Function
|
||||
let baja_my_user_account_func; //取得帳號資料要回傳的Function
|
||||
var ordPath; //當前點選選單的tag,用來抓出設備路徑,例如:旅館棟->H,消防偵煙器->F3
|
||||
let baja_subscribe_alarm_callback_func; //設定 alarm BQL訂閱之後要回傳的Function
|
||||
let baja_subscribe_end_alarm_callback_func; //設定 alarm BQL訂閱結束之後要回傳的Function
|
||||
var ordPathForAlarm; //當前點選選單的tag,用來抓出alarm路徑
|
||||
window.tolSubList = [];
|
||||
|
||||
var user_name = "";
|
||||
@ -26,6 +29,27 @@ function subscriptionDevices() {
|
||||
|
||||
}
|
||||
|
||||
function subscriptionAlarms() {
|
||||
// 用BQL的方式去訂閱
|
||||
this.setSubscribeAlarmsByBql = function (tempOrdPath) {
|
||||
ordPathForAlarm = tempOrdPath;
|
||||
BajaSubscribeAlarmsByBql();
|
||||
};
|
||||
// BQL去訂閱回傳的Function
|
||||
this.setSubscribeAlarmsCallBack = function (callBackFunc) {
|
||||
if (callBackFunc != undefined && callBackFunc != null) {
|
||||
baja_subscribe_alarm_callback_func = callBackFunc;
|
||||
}
|
||||
}
|
||||
// BQL訂閱結束回傳的Function
|
||||
this.setSubscribeAlarmEndCallBack = function (callBackFunc) {
|
||||
if (callBackFunc != undefined && callBackFunc != null) {
|
||||
baja_subscribe_end_alarm_callback_func = callBackFunc;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function MyBaja() {
|
||||
// 取得使用者帳號
|
||||
this.setMyUserAccount = function (callBackFunc = null) {
|
||||
@ -222,3 +246,87 @@ function BajaSubscribeDevicesByBql() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用者透過BQL指定路徑去訂閱Alarm
|
||||
*/
|
||||
function BajaSubscribeAlarmsByBql() {
|
||||
require(['baja!'], function (baja) {
|
||||
console.log("進入Function 準備執行BQL訂閱");
|
||||
var init_start = new Date(Date.now());
|
||||
var sub = new baja.Subscriber();
|
||||
|
||||
sub.attach('changed', function (prop) {
|
||||
if (prop.getName() === 'out') {
|
||||
var sourceState = (this.$map.$map.in10.$val.$map.$map.value.$display) == 'true' ? "Offnormal" : "Normal";
|
||||
var modify_target_device = {
|
||||
"system": "TPE_" + ordPathForAlarm.building_tag + "_" + ordPathForAlarm.system_tag + "_" + ordPathForAlarm.name_tag,
|
||||
"sourceState": sourceState ? sourceState : null
|
||||
}
|
||||
|
||||
if (baja_subscribe_alarm_callback_func != undefined && baja_subscribe_alarm_callback_func != null) {
|
||||
baja_subscribe_alarm_callback_func(modify_target_device);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//使用bql語法
|
||||
console.log(`local:|foxs:|alarm:|bql:select top 1 timestamp, sourceState, alarmData, alarmData.sourceName, normalTime where alarmData.sourceName like '%TPE_${ordPathForAlarm.building_tag}_${ordPathForAlarm.system_tag}_${ordPathForAlarm.name_tag}_%' order by timestamp desc`);
|
||||
baja.Ord.make(`local:|foxs:|alarm:|bql:select top 1 timestamp, sourceState, alarmData, alarmData.sourceName, normalTime where alarmData.sourceName like '%TPE_${ordPathForAlarm.building_tag}_${ordPathForAlarm.system_tag}_${ordPathForAlarm.name_tag}_%' order by timestamp desc`)
|
||||
.get(
|
||||
function (table) {
|
||||
var tableStart, tableFinish;
|
||||
var subStart, subFinish;
|
||||
var component_index = 0;
|
||||
var total_component_index = 0;
|
||||
var readBqlFinish = new Date(Date.now());
|
||||
console.log("讀取路徑完成-花費時間", (readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec");
|
||||
|
||||
table.cursor({
|
||||
before: function () {
|
||||
tableStart = new Date(Date.now());
|
||||
render_start = new Date(Date.now());
|
||||
},
|
||||
each: function (item, index) {
|
||||
if (index < 1) {
|
||||
subStart = new Date(Date.now());
|
||||
}
|
||||
total_component_index = index;
|
||||
|
||||
var sourceState = this.getDisplay("sourceState");
|
||||
var sourceNameArray = (item.$map.$map.alarmData$2esourceName.$display).split('_');
|
||||
var slotPath = sourceNameArray[0] + "/" + sourceNameArray[1] + "/" + sourceNameArray[2] + "/" + sourceNameArray[3] + "/" + sourceNameArray[4] + "/" + sourceNameArray[5] + "/" + sourceNameArray[6] + "/" + sourceNameArray[7] + "/" + sourceNameArray[8];
|
||||
var normalTime = this.getDisplay("normalTime");
|
||||
|
||||
var modify_target_device = {
|
||||
"system": "TPE_" + ordPathForAlarm.building_tag + "_" + ordPathForAlarm.system_tag + "_" + ordPathForAlarm.name_tag,
|
||||
"sourceState": sourceState ? sourceState : null
|
||||
}
|
||||
|
||||
//取得component當下就更新設備點位
|
||||
if (baja_subscribe_alarm_callback_func != undefined && baja_subscribe_alarm_callback_func != null) {
|
||||
baja_subscribe_alarm_callback_func(modify_target_device);
|
||||
}
|
||||
|
||||
baja.Ord.make("local:|foxs:|station:|slot:/" + slotPath)
|
||||
.get()
|
||||
.then(function (component) {
|
||||
component_index++;
|
||||
|
||||
sub.subscribe({
|
||||
comps: component,
|
||||
});
|
||||
|
||||
subFinish = new Date(Date.now());
|
||||
console.log("訂閱完成時間", (subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
|
||||
});
|
||||
},
|
||||
after: function () {
|
||||
tableFinish = new Date(Date.now());
|
||||
console.log("表格完成時間", (tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec");
|
||||
},
|
||||
limit: -1,
|
||||
offset: 0
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user