ibms-dome/Frontend/js/n4js/bajatest.js

192 lines
9.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let baja_subscribe_device_callback_func; //設定BQL訂閱之後要回傳的Function
var ordPath; //當前點選選單的tag用來抓出設備路徑例如:旅館棟->H消防偵煙器->F3
function subscriptionDevices() {
// 用BQL的方式去訂閱
this.setSubscribeDevicesByBql = function (tempOrdPath) {
ordPath = tempOrdPath;
BajaSubscribeDevicesByBql();
};
// BQL去訂閱回傳的Function
this.setSubscribeDevicesCallBack = function (callBackFunc) {
if (callBackFunc != undefined && callBackFunc != null) {
baja_subscribe_device_callback_func = callBackFunc;
}
}
}
/**
* 使用者透過BQL指定路徑去訂閱設備點位
*/
function BajaSubscribeDevicesByBql() {
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 out_value = this.getOutDisplay();
var target_device_number = this.$parent.getDisplayName().split('_').slice(0, 5).join('_');
var point_name = this.getDisplayName();
//依據Facets判斷回傳的內容值為何
var facets_split = this.getFacets1().$cEncStr.split('|');
var facets_arr = [];
facets_split.forEach(function (item, index) {
facets_arr.push(item.split('=s:'));
});
var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
var point_out_split = this.getOutDisplay().split(' ');
let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
if (key == undefined) {
key = point_out_split[0];
}
var modify_target_device = {
"device_number": target_device_number ? target_device_number : null,
"point_name": point_name ? point_name : null,
"value": key
}
if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
baja_subscribe_device_callback_func(modify_target_device, true); //第2參數用在平面圖刷新畫面
}
}
});
//使用bql語法
// var building_tag = "H";
// var system_tag = "M10";
// baja.Ord.make(`ip:greencloud.fic.com.tw|foxs:|station:|slot:/Arena/${building_tag}/${system_tag}|bql:select name, displayname, slotPath, out.value, out from control:ControlPoint`)
console.log(`local:|foxs:|station:|slot:/TPE/${ordPath.building_tag}/${ordPath.system_tag}/${ordPath.name_tag}|bql:select name, displayname, slotPath, out.value, out, facets from control:ControlPoint`);
baja.Ord.make(`local:|foxs:|station:|slot:/TPE/${ordPath.building_tag}/${ordPath.system_tag}/${ordPath.name_tag}|bql:select name, displayname, slotPath, out.value, out, facets from control:ControlPoint`)
.get(
function (table) {
var tableStart, tableFinish;
var subStart, subFinish;
var component_index = 0;
var total_component_index = 0;
var readBqlFinish = new Date(Date.now());
// $("#readPath-finish-timestamp").html(readBqlFinish.toISOString());
// $("#readPath-finish-time").html((readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec");
console.log("讀取路徑完成-花費時間", (readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec");
table.cursor({
before: function () {
tableStart = new Date(Date.now());
$("#table-start-timestamp").html(tableStart.toISOString());
render_start = new Date(Date.now());
},
each: function (item, index) {
if (index < 1) {
subStart = new Date(Date.now());
$("#sub-start").html(subStart.toISOString());
}
$("#sub-number").html(index + 1);
total_component_index = index;
var target_device_number_split = this.getDisplay("slotPath").split('/');
var target_device_number = target_device_number_split[target_device_number_split.length - 2];
//console.log(target_device_number);
var point_name = this.getDisplay("name");
var facets = this.getDisplay("facets");
//依據Facets判斷回傳的內容值為何
var facets_split = facets.split(',');
var facets_arr = [];
facets_split.forEach(function (item, index) {
facets_arr.push(item.split('='));
});
facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
var point_out_split = this.getDisplay("out").split(' ');
let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
if (key == undefined) {
key = point_out_split[0];
}
var modify_target_device = {
"device_number": target_device_number ? target_device_number : null,
"point_name": point_name ? point_name : null,
"value": key
}
//取得component當下就更新設備點位
if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
baja_subscribe_device_callback_func(modify_target_device);
}
baja.Ord.make("local:|foxs:|station:|" + this.getDisplay("slotPath"))
.get()
.then(function (component) {
component_index++;
var target_device_number = component.$parent.getDisplayName().split('_').slice(0, 5).join('_');
var point_name = component.getDisplayName();
// //依據Facets判斷回傳的內容值為何
// var facets_split = component.getFacets1().$cEncStr.split('|');
// var facets_arr = [];
// facets_split.forEach(function (item, index) {
// facets_arr.push(item.split('=s:'));
// });
// var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
// var point_out_split = component.getOutDisplay().split(' ');
// let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
// if (key == undefined) {
// key = point_out_split[0];
// }
// var modify_target_device = {
// "device_number": target_device_number ? target_device_number : null,
// "point_name": point_name ? point_name : null,
// "value": key
// }
// //取得component當下就更新設備點位
// if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
// if (component_index == total_component_index) {
// baja_subscribe_device_callback_func(modify_target_device, true);
// }
// else {
// baja_subscribe_device_callback_func(modify_target_device);
// }
// }
sub.subscribe({
comps: component,
});
subFinish = new Date(Date.now());
$("#sub-end").html(subFinish.toISOString());
$("#sub-time").html((subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
// console.log("訂閱完成時間", (subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
});
},
after: function () {
tableFinish = new Date(Date.now());
// $("#table-finish-timestamp").html(tableFinish.toISOString());
// $("#table-time").html((tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec");
console.log("表格完成時間", (tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec");
},
limit: -1,
offset: 0
});
});
});
}