From cc2f8f6e805e903bc32409d24670fc532af2a539 Mon Sep 17 00:00:00 2001 From: wanli Date: Fri, 9 Dec 2022 17:49:01 +0800 Subject: [PATCH] =?UTF-8?q?[Frontend]=20[=E9=A6=96=E9=A0=81]=20baja?= =?UTF-8?q?=E8=AA=9E=E6=B3=95:=20=E8=A8=82=E9=96=B1=E7=89=B9=E5=AE=9A?= =?UTF-8?q?=E8=B7=AF=E5=BE=91=E7=9A=84=E8=A8=AD=E5=82=99=E9=BB=9E=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/js/n4js/bajatest.js | 172 +++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) diff --git a/Frontend/js/n4js/bajatest.js b/Frontend/js/n4js/bajatest.js index 94492f0..c89a906 100644 --- a/Frontend/js/n4js/bajatest.js +++ b/Frontend/js/n4js/bajatest.js @@ -6,6 +6,11 @@ var ordPath; //當前點選選單的tag,用來抓出設備路徑,例如:旅 let baja_subscribe_alarm_callback_func; //設定 alarm BQL訂閱之後要回傳的Function let baja_subscribe_end_alarm_callback_func; //設定 alarm BQL訂閱結束之後要回傳的Function var ordPathForAlarm; //當前點選選單的tag,用來抓出alarm路徑 + +let baja_subscribe_electricmeter_callback_func; +let baja_subscribe_end_electricmeter_callback_func; +var ordPathForElectricmeter; + var startPageLoading; // 開始 loading var endPageLoading; // 開始 loading //window.baja = null; @@ -57,6 +62,25 @@ function subscriptionAlarms() { } +function subscriptionElectricmeter() { + // 用BQL的方式去訂閱 + this.setSubscribeElectricmeterByBql = function (tempOrdPath) { + BajaSubscribeElectricmeterByBql(tempOrdPath); + }; + // BQL去訂閱回傳的Function + this.setSubscribeElectricmeterCallBack = function (callBackFunc) { + if (callBackFunc != undefined && callBackFunc != null) { + baja_subscribe_electricmeter_callback_func = callBackFunc; + } + } + // BQL訂閱結束回傳的Function + this.setSubscribeElectricmeterEndCallBack = function (callBackFunc) { + if (callBackFunc != undefined && callBackFunc != null) { + baja_subscribe_end_electricmeter_callback_func = callBackFunc; + } + } +} + function MyBaja() { // 取得使用者帳號 this.setMyUserAccount = function (callBackFunc = null) { @@ -351,6 +375,154 @@ function BajaSubscribeAlarmsByBql(ordPathForAlarm) { }); } +/** + * 使用者透過BQL指定路徑去訂閱 electricmeter + */ +function BajaSubscribeElectricmeterByBql(ordPathForElectricmeter) { + + + require(['baja!'], function (baja) { + //console.log("進入Function 準備執行BQL訂閱"); + startPageLoading ? startPageLoading() : "" + 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, + //"device_number_full": this.$parent.getSlotPath().$names.join("_"), + "point_name": point_name ? point_name : null, + "value": key + } + + if (baja_subscribe_electricmeter_callback_func != undefined && baja_subscribe_electricmeter_callback_func != null) { + baja_subscribe_electricmeter_callback_func(modify_target_device, true); //第2參數用在平面圖,刷新畫面 + } + } + }, function (err) { + console.log(err) + }); + + //使用bql語法 + console.log(`local:|foxs:|station:|slot:/${ordPathForElectricmeter.devicePath}|bql:select name, out, out.value, slotPath, facets from control:ControlPoint`); + baja.Ord.make(`local:|foxs:|station:|slot:/${ordPathForElectricmeter.devicePath}|bql:select name, out, out.value, slotPath, facets from control:ControlPoint`) + .get( + function (table) { + var tableStart, tableFinish; + var subStart, subFinish; + var component_index = 0; + var total_component_index = 0; + var totalTargetDevice = []; + var readBqlFinish = new Date(Date.now()); + //console.log("讀取路徑完成-花費時間", (readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec"); + table.cursor({ + before: function () { + totalTargetDevice = []; + 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[8]; + //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, + //"device_number_full": this.getDisplay("slotPath").split("slot:")[1].split('/').slice(1, -1).join("_"), + "point_name": point_name ? point_name : null, + "value": key + } + totalTargetDevice.push(modify_target_device); + //取得component當下就更新設備點位 + if (baja_subscribe_electricmeter_callback_func != undefined && baja_subscribe_electricmeter_callback_func != null) { + baja_subscribe_electricmeter_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(); + + sub.subscribe({ + comps: component, + }); + tolSubList.push(sub); + 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()); + if (baja_subscribe_end_electricmeter_callback_func != undefined && baja_subscribe_end_electricmeter_callback_func != null) { + baja_subscribe_end_electricmeter_callback_func(totalTargetDevice); + } + endPageLoading ? endPageLoading() : "" + //console.log("表格完成時間", (tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec"); + }, + limit: -1, + offset: 0 + }); + }); + }) +} + // function getAlarmCountByBaja(callback) { // var _result = ""; // var _index = 0;