From acb26732789334fe9949864e6444e171f1815b25 Mon Sep 17 00:00:00 2001 From: wanli Date: Thu, 1 Dec 2022 01:41:00 +0800 Subject: [PATCH] =?UTF-8?q?[Frontend]=20[=E9=A6=96=E9=A0=81]=20baja=20func?= =?UTF-8?q?tion=20:=20=E5=8F=96=E5=BE=97=E9=9B=BB=E9=8C=B6=E9=9B=BB?= =?UTF-8?q?=E9=87=8F=E3=80=81=E5=8D=B3=E6=99=82=E5=8A=9F=E7=8E=87=E3=80=81?= =?UTF-8?q?=E5=96=AE=E6=97=A5kwh=E3=80=81=E6=AF=8F=E5=91=A8kwh=E3=80=81?= =?UTF-8?q?=E5=90=84=E7=B3=BB=E7=B5=B1=E7=95=B6=E4=B8=8B=E7=8B=80=E6=85=8B?= =?UTF-8?q?(=E7=95=B0=E5=B8=B8=E8=88=87=E5=90=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/js/n4js/alarmbaja.js | 37 +++++++ Frontend/js/n4js/electricmeterbaja.js | 153 ++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) diff --git a/Frontend/js/n4js/alarmbaja.js b/Frontend/js/n4js/alarmbaja.js index d67a3f1..b78f869 100644 --- a/Frontend/js/n4js/alarmbaja.js +++ b/Frontend/js/n4js/alarmbaja.js @@ -226,3 +226,40 @@ function getOneSystemAlarmStateByBaja(systemPath, callback) { }); }); } + +/** + * 在單一系統下,取得各個系統的狀態 異常與否 + * @param {any} systemPath + * @param {any} callback + */ +function getOneSystemStateByBaja(systemPath, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) { + baja.Ord.make("local:|foxs:|alarm:|bql:select top 1 alarmData, alarmData.sourceName, sourceState where alarmData.sourceName like '%" + systemPath + "%' order by timestamp desc").get() + .then(function (table) { + return table.cursor({ + each: function (record) { + //if (_index == 0) + // _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; + //else + // _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; + _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} diff --git a/Frontend/js/n4js/electricmeterbaja.js b/Frontend/js/n4js/electricmeterbaja.js index 1e87e1c..92529a6 100644 --- a/Frontend/js/n4js/electricmeterbaja.js +++ b/Frontend/js/n4js/electricmeterbaja.js @@ -34,4 +34,157 @@ function getElectricMeterTotalByBaja(devicePath, timeType, callback) { }); }); }); +} + +/** + * 取得電表即時資料 by baja + * @param {any} devicePath + * @param {any} callback + */ +function getElectricMeterNoweDataByBaja(devicePath, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 + console.log('local:|foxs:|station:|slot:/' + devicePath + '|bql:select name, out, out.value from control:ControlPoint'); + baja.Ord.make('local:|foxs:|station:|slot:/' + devicePath + '|bql:select name, out, out.value from control:ControlPoint').get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"name":"' + record.get('name') + '", "value":' + record.get('out').get('value') + '"}'; + else + _ss += ',{"name":"' + record.get('name') + '", "value":' + record.get('out').get('value') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * 取得電表每小時資料 by baja + * @param {any} devicePath + * @param {any} startDate_millisecond + * @param {any} endDate_millisecond + * @param {any} callback + */ +function getElectricMeterHourDataByBaja(devicePath, startDate_millisecond, endDate_millisecond, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 + console.log('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond); + baja.Ord.make('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond).get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; + else + _ss += ',{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * 取得電表 單日kwh by baja + * @param {any} devicePath + * @param {any} date_millisecond + * @param {any} callback + */ +function getElectricMeterOneDayKwhByBaja(devicePath, date_millisecond, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 + console.log('transform:slot:/' + devicePath + '/History/TR_Month|bql: select * where timestamp.millis = ' + date_millisecond); + baja.Ord.make('transform:slot:/' + devicePath + '/History/TR_Month|bql: select * where timestamp.millis = ' + date_millisecond).get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"timestamp":"' + record.get('timestamp') + '", "value":' + record.get('kwh1') + '"}'; + else + _ss += ',{"timestamp":"' + record.get('timestamp') + '", "value":' + record.get('kwh1') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * 取得電表每周資料 by baja + * @param {any} devicePath + * @param {any} startDate_millisecond + * @param {any} endDate_millisecond + * @param {any} callback + */ +function getElectricMeterWeekDataByBaja(devicePath, startDate_millisecond, endDate_millisecond, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 + console.log('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis >= ' + startDate_millisecond + ' and timestamp.millis <= ' + endDate_millisecond); + baja.Ord.make('transform:slot:/' + devicePath + '/History/TR_Month|bql: select * where timestamp.millis >= ' + startDate_millisecond + ' and timestamp.millis <= ' + endDate_millisecond).get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; + else + _ss += ',{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); } \ No newline at end of file