2022-11-16 13:31:09 +08:00
2022-11-22 13:33:49 +08:00
function addzero ( num ) {
return num < 10 ? '0' + num : num ;
}
2022-11-16 13:31:09 +08:00
/ * *
* 取得異常資料 by baja
* @ param { any } startDate _millisecond
* @ param { any } endDate _millisecond
* @ param { any } isRecover
* @ param { any } isAck
* @ param { any } alarmClass
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
// function getAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, alarmClass, callback) {
// let _sourceTmp;
// var _result = "";
// var _ss = "";
// var _bfName = "";
// var _sourceName = "";
// var _index = 0;
// var _recoverState = isRecover ? "!= null" : "= null";
// var _ackState = isAck ? "= 1" : "!= 1";
// require(['baja!'], function (baja) {
// baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmClass = '" + alarmClass + "' and timestamp.millis > " + startDate_millisecond + " and timestamp.millis < " + endDate_millisecond + " and normalTime " + _recoverState + " order by timestamp asc").get()
// .then(function (table) {
// return table.cursor({
// each: function (record) {
// _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_');
// _bfName = _sourceTmp[1] + "-" + _sourceTmp[4];
// _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8];
// _ss += ', "' + _index + '": {"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
// _index++;
// },
// after: function () {
// _result += '{' + '"count": ' + _index;
// _result += _ss;
// _result += '}';
// if (typeof callback === 'function') {
// callback(_result);
// }
// }
// });
// });
// });
// }
// function getAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, alarmClass, callback) {
// let _sourceTmp;
// var _result = "";
// var _ss = "";
// var _bfName = "";
// var _sourceName = "";
// var _index = 0;
// var _recoverState = isRecover ? "!= null" : "= null"
// var _ackState = isAck ? "= 1" : "!= 1";
// require(['baja!'], function (baja) {
// baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmClass = '" + alarmClass + "' and timestamp.millis > " + startDate_millisecond + " and timestamp.millis < " + endDate_millisecond + " and normalTime " + _recoverState + " order by timestamp asc").get()
// .then(function (table) {
// return table.cursor({
// each: function (record) {
// _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_');
// _bfName = _sourceTmp[1] + "-" + _sourceTmp[4];
// _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8];
// if (_index == 0)
// _ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
// else
// _ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
// _index++;
// },
// after: function () {
// _result += '{' + '"count": ' + _index + ', "data":[';
// _result += _ss;
// _result += ']}';
// if (typeof callback === 'function') {
// callback(_result);
// }
// },
// limit: -1,
// offset: 0
// });
// });
// });
// }
2022-11-16 13:31:09 +08:00
function getAlarmByBaja ( startDate _millisecond , endDate _millisecond , isRecover , isAck , alarmClass , callback ) {
let _sourceTmp ;
var _result = "" ;
var _ss = "" ;
var _bfName = "" ;
var _sourceName = "" ;
var _index = 0 ;
2022-12-08 10:50:51 +08:00
var _recoverState = isRecover ? "!= null" : "= null" ;
var _ackState = isAck ? "= 'acked'" : "= 'unacked'" ;
2022-11-16 13:31:09 +08:00
require ( [ 'baja!' ] , function ( baja ) {
2022-12-08 10:50:51 +08:00
baja . Ord . make ( "local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmClass = '" + alarmClass + "' and timestamp.millis > " + startDate _millisecond + " and timestamp.millis < " + endDate _millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp asc" ) . get ( )
2022-11-16 13:31:09 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
_sourceTmp = ( record . get ( 'alarmData' ) . get ( 'sourceName' ) ) . toString ( ) . split ( '_' ) ;
_bfName = _sourceTmp [ 1 ] + "-" + _sourceTmp [ 4 ] ;
_sourceName = _sourceTmp [ 7 ] + "-" + _sourceTmp [ 8 ] ;
2022-11-21 14:46:25 +08:00
if ( _index == 0 )
_ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record . get ( 'uuid' ) + '", "timestamp":"' + record . get ( 'timestamp' ) + '", "alarmClass":"' + record . get ( 'alarmClass' ) + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record . get ( 'alarmData' ) . get ( 'msgText' ) + '", "ackState":"' + record . get ( 'ackState' ) + '", "normalTime":"' + record . get ( 'normalTime' ) + '"}' ;
else
_ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record . get ( 'uuid' ) + '", "timestamp":"' + record . get ( 'timestamp' ) + '", "alarmClass":"' + record . get ( 'alarmClass' ) + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record . get ( 'alarmData' ) . get ( 'msgText' ) + '", "ackState":"' + record . get ( 'ackState' ) + '", "normalTime":"' + record . get ( 'normalTime' ) + '"}' ;
2022-11-16 13:31:09 +08:00
_index ++ ;
} ,
after : function ( ) {
2022-11-21 14:46:25 +08:00
_result += '{' + '"count": ' + _index + ', "data":[' ;
2022-11-16 13:31:09 +08:00
_result += _ss ;
2022-11-21 14:46:25 +08:00
_result += ']}' ;
2022-11-16 13:31:09 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
2022-11-24 17:55:52 +08:00
} ,
limit : - 1 ,
offset : 0
2022-11-16 13:31:09 +08:00
} ) ;
} ) ;
} ) ;
}
/ * *
* 取得單一設備最新10筆異常資料 by baja
* @ param { any } devicePath
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
// function getOneDeviceAlarmTop10ByBaja(devicePath, callback) {
// var _result = "";
// var _ss = "";
// var _index = 0;
// //{ "count":2,"data": [{ "time": "2022/11/14 15:00:00", "errId": "0001", "ackCheck": "未確認", "errReason": "燈泡故障" }, { "time": "2022/11/14 15:00:00", "errId": "0002", "ackCheck": "未確認", "errReason": "燈泡故障" }]}
// require(['baja!'], function (baja) {
// baja.Ord.make("local:|foxs:|alarm:|bql:select top 10 timestamp, ackState, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc").get()
// .then(function (table) {
// return table.cursor({
// each: function (record) {
// if (_index == 0)
// _ss += '{"uuid":"' + record.get('uuid') + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "timestamp":"' + record.get('timestamp') + '"}';
// else
// _ss += ',{"uuid":"' + record.get('uuid') + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "timestamp":"' + record.get('timestamp') + '"}';
// _index++;
// },
// after: function () {
// _result += '{' + '"count": ' + _index +', "data":[';
// _result += _ss+']';
// _result += '}';
// if (typeof callback === 'function') {
// callback(_result);
// }
// }
// });
// });
// });
// }
2022-11-16 13:31:09 +08:00
function getOneDeviceAlarmTop10ByBaja ( devicePath , callback ) {
var _result = "" ;
var _ss = "" ;
2022-11-22 13:33:49 +08:00
var _occurrenceTime = "" ;
var _normalTime = "" ;
2022-11-16 13:31:09 +08:00
var _index = 0 ;
2022-11-17 09:36:53 +08:00
//{ "count":2,"data": [{ "time": "2022/11/14 15:00:00", "errId": "0001", "ackCheck": "未確認", "errReason": "燈泡故障" }, { "time": "2022/11/14 15:00:00", "errId": "0002", "ackCheck": "未確認", "errReason": "燈泡故障" }]}
2022-11-16 13:31:09 +08:00
require ( [ 'baja!' ] , function ( baja ) {
baja . Ord . make ( "local:|foxs:|alarm:|bql:select top 10 timestamp, ackState, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc" ) . get ( )
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
2022-11-22 13:33:49 +08:00
_occurrenceTime = "" ;
_normalTime = "" ;
var _resultUuid = record . get ( 'uuid' ) . toString ( ) . split ( "-" ) ; //43dc7846-bd96-4be2-ab35-f11aec729c60
var _timestampTemp = new Date ( record . get ( 'timestamp' ) . toString ( ) ) ;
_occurrenceTime += _timestampTemp . getFullYear ( ) . toString ( ) + "-" + addzero ( _timestampTemp . getMonth ( ) + 1 ) . toString ( ) + "-" + addzero ( _timestampTemp . getDate ( ) ) . toString ( ) + " " + addzero ( _timestampTemp . getHours ( ) ) . toString ( ) + ":" + addzero ( _timestampTemp . getMinutes ( ) ) . toString ( ) + ":" + addzero ( _timestampTemp . getSeconds ( ) ) . toString ( ) ;
2022-11-24 16:27:00 +08:00
//var _occurrenceTime = _timestamp.format("yyyy-MM-dd hh:mm:ss");//.toLocaleString();
2022-11-22 13:33:49 +08:00
var _normaltime = new Date ( record . get ( 'normalTime' ) . toString ( ) ) ;
_normalTime += _normaltime . getFullYear ( ) . toString ( ) + "-" + addzero ( _normaltime . getMonth ( ) + 1 ) . toString ( ) + "-" + addzero ( _normaltime . getDate ( ) ) . toString ( ) + " " + addzero ( _normaltime . getHours ( ) ) . toString ( ) + ":" + addzero ( _normaltime . getMinutes ( ) ) . toString ( ) + ":" + addzero ( _normaltime . getSeconds ( ) ) . toString ( ) ;
2022-11-24 16:27:00 +08:00
var _msgText = record . get ( 'alarmData' ) . get ( 'msgText' ) ; // == 1 ? _occurrenceTime : "未確認";
2022-11-23 11:11:40 +08:00
var _ackText = record . get ( 'ackState' ) == 1 ? _occurrenceTime : "未確認" ;
2022-11-22 13:33:49 +08:00
2022-11-17 09:36:53 +08:00
if ( _index == 0 )
2022-11-23 11:11:40 +08:00
_ss += '{"uuid":"' + _resultUuid [ 0 ] + '", "msgText":"' + _msgText + '", "ackState":"' + _ackText + '", "timestamp":"' + _occurrenceTime + '", "normalTime":"' + _normalTime + '"}' ;
2022-11-17 09:36:53 +08:00
else
2022-11-23 11:11:40 +08:00
_ss += ',{"uuid":"' + _resultUuid [ 0 ] + '", "msgText":"' + _msgText + '", "ackState":"' + _ackText + '", "timestamp":"' + _occurrenceTime + '", "normalTime":"' + _normalTime + '"}' ;
2022-11-16 13:31:09 +08:00
_index ++ ;
} ,
after : function ( ) {
2022-11-18 21:27:25 +08:00
_result += '{' + '"count": ' + _index + ', "data":[' ;
_result += _ss + ']' ;
2022-11-16 13:31:09 +08:00
_result += '}' ;
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
2022-11-24 17:55:52 +08:00
} ,
limit : - 1 ,
offset : 0
2022-11-16 13:31:09 +08:00
} ) ;
} ) ;
} ) ;
}
2022-12-07 17:39:42 +08:00
/ * *
2022-12-09 18:20:41 +08:00
* 在單一系統下 , 取得各個設備的異常狀態
* @ param { any } systemPath
2022-12-08 10:50:51 +08:00
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
// function getOneSystemAlarmStateByBaja(systemPath, callback) {
// var _result = "";
// var _ss = "";
// var _index = 0;
// require(['baja!'], function (baja) {
// baja.Ord.make("local:|foxs:|alarm:|bql:select alarmData, alarmData.sourceName, sourceState, uuid where alarmData.sourceName like '%" + systemPath + "%' order by timestamp desc").get()
// .then(function (table) {
// return table.cursor({
// each: function (record) {
// _ss += ', "' + _index + '": {"uuid":"' + record.get('uuid') + '", "sourceName":"' + record.get('alarmData').get('sourceName') + '", "sourceState":"' + record.get('sourceState') + '"}';
// _index++;
// },
// after: function () {
// _result += '{' + '"count": ' + _index;
// _result += _ss;
// _result += '}';
// if (typeof callback === 'function') {
// callback(_result);
// }
// }
// });
// });
// });
// }
function getOneSystemAlarmStateByBaja ( systemPath , callback ) {
2022-12-08 10:50:51 +08:00
var _result = "" ;
var _ss = "" ;
var _index = 0 ;
2022-12-09 18:20:41 +08:00
2022-12-08 10:50:51 +08:00
require ( [ 'baja!' ] , function ( baja ) {
2022-12-09 18:20:41 +08:00
baja . Ord . make ( "local:|foxs:|alarm:|bql:select alarmData, alarmData.sourceName, sourceState, uuid where alarmData.sourceName like '%" + systemPath + "%' order by timestamp desc" ) . get ( )
2022-12-08 10:50:51 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
if ( _index == 0 )
2022-12-09 18:20:41 +08:00
_ss += '{"uuid":"' + record . get ( 'uuid' ) + '", "sourceName":"' + record . get ( 'alarmData' ) . get ( 'sourceName' ) + '", "sourceState":"' + record . get ( 'sourceState' ) + '"}' ;
2022-12-08 10:50:51 +08:00
else
2022-12-09 18:20:41 +08:00
_ss += ',{"uuid":"' + record . get ( 'uuid' ) + '", "sourceName":"' + record . get ( 'alarmData' ) . get ( 'sourceName' ) + '", "sourceState":"' + record . get ( 'sourceState' ) + '"}' ;
2022-12-08 10:50:51 +08:00
_index ++ ;
} ,
after : function ( ) {
_result += '{' + '"count": ' + _index + ', "data":[' ;
2022-12-09 18:20:41 +08:00
_result += _ss ;
_result += ']}' ;
2022-12-08 10:50:51 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
}
/ * *
2022-12-09 18:20:41 +08:00
* 在單一系統下 , 取得各個系統的狀態 異常與否
* @ param { any } systemPath
2022-12-07 17:39:42 +08:00
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
function getOneSystemStateByBaja ( systemPath , callback ) {
2022-12-07 17:39:42 +08:00
var _result = "" ;
var _ss = "" ;
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) {
2022-12-09 18:20:41 +08:00
baja . Ord . make ( "local:|foxs:|alarm:|bql:select top 1 alarmData, alarmData.sourceName, sourceState where alarmData.sourceName like '%" + systemPath + "%' order by timestamp desc" ) . get ( )
2022-12-07 17:39:42 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
2022-12-09 18:20:41 +08:00
//if (_index == 0)
// _ss += '{"sourceState":"' + record.get('sourceState') + '"}';
//else
// _ss += '{"sourceState":"' + record.get('sourceState') + '"}';
_ss += '{"sourceState":"' + record . get ( 'sourceState' ) + '"}' ;
2022-12-07 17:39:42 +08:00
_index ++ ;
} ,
after : function ( ) {
_result += '{' + '"count": ' + _index + ', "data":[' ;
2022-12-09 18:20:41 +08:00
_result += _ss ;
_result += ']}' ;
2022-12-07 17:39:42 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
}
2022-11-16 13:31:09 +08:00
/ * *
2022-12-09 18:20:41 +08:00
* [ 首頁 ] 查詢異常數量
2022-11-16 13:31:09 +08:00
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
function getAlarmCountByBaja ( callback ) {
var _result = { count : 0 } ;
2022-11-16 13:31:09 +08:00
var _index = 0 ;
2022-12-09 18:20:41 +08:00
2022-11-16 13:31:09 +08:00
require ( [ 'baja!' ] , function ( baja ) {
2022-12-09 18:20:41 +08:00
baja . Ord . make ( "local:|foxs:|alarm:|bql:select sourceState where sourceState = 'offnormal'" ) . get ( )
2022-11-16 13:31:09 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
_index ++ ;
} ,
after : function ( ) {
2022-12-09 18:20:41 +08:00
_result . count = _index ;
2022-11-16 13:31:09 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
2022-11-24 17:55:52 +08:00
} ,
limit : - 1 ,
offset : 0
2022-11-16 13:31:09 +08:00
} ) ;
} ) ;
} ) ;
}
2022-12-01 01:41:00 +08:00
/ * *
2022-12-09 18:20:41 +08:00
* [ 首頁 ] 查詢復歸數量
2022-12-01 01:41:00 +08:00
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
function getRecoverCountByBaja ( callback ) {
var _result = { count : 0 } ;
2022-12-01 01:41:00 +08:00
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) {
2022-12-09 18:20:41 +08:00
baja . Ord . make ( "local:|foxs:|alarm:|bql:select normalTime where normalTime != null" ) . get ( )
2022-12-01 01:41:00 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
_index ++ ;
} ,
after : function ( ) {
2022-12-09 18:20:41 +08:00
_result . count = _index ;
2022-12-01 01:41:00 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
}
2022-12-05 01:28:24 +08:00
/ * *
2022-12-09 18:20:41 +08:00
* [ 首頁 ] 查詢已確認異常數量
2022-12-05 01:28:24 +08:00
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
function getCheckedAckedCountByBaja ( callback ) {
2022-12-06 14:34:04 +08:00
var _result = { count : 0 } ;
2022-12-05 01:28:24 +08:00
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) {
2022-12-09 18:20:41 +08:00
baja . Ord . make ( "local:|foxs:|alarm:|bql:select ackState from openAlarms where ackState ='acked'" ) . get ( )
2022-12-05 01:28:24 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
_index ++ ;
} ,
after : function ( ) {
2022-12-06 14:34:04 +08:00
_result . count = _index ;
2022-12-05 01:28:24 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
}
/ * *
2022-12-09 18:20:41 +08:00
* [ 首頁 ] 查詢未確認異常數量
2022-12-05 01:28:24 +08:00
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
function getUnCheckedAckedCountByBaja ( callback ) {
2022-12-06 14:34:04 +08:00
var _result = { count : 0 } ;
2022-12-05 01:28:24 +08:00
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) {
2022-12-09 18:20:41 +08:00
baja . Ord . make ( "local:|foxs:|alarm:|bql:select ackState from openAlarms where ackState ='unacked'" ) . get ( )
2022-12-05 01:28:24 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
_index ++ ;
} ,
after : function ( ) {
2022-12-06 14:34:04 +08:00
_result . count = _index ;
2022-12-05 01:28:24 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
}
/ * *
2022-12-09 18:20:41 +08:00
* [ 首頁 ] 取得現在是異常的系統 ( 較快 )
2022-12-05 01:28:24 +08:00
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
function getSystemAlarmByBaja ( callback ) {
var _result = { count : 0 , data : [ ] } ;
2022-12-05 01:28:24 +08:00
var _index = 0 ;
2022-12-09 18:20:41 +08:00
2022-12-05 01:28:24 +08:00
require ( [ 'baja!' ] , function ( baja ) {
2022-12-09 18:20:41 +08:00
//baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime where isAlarm").get()
baja . Ord . make ( "local:|foxs:|alarm:|bql:select alarmClass where isAlarm" ) . get ( )
2022-12-05 01:28:24 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
2022-12-09 18:20:41 +08:00
let main = { } ;
main . alarmClass = record . get ( 'alarmClass' ) ;
_result . data . push ( main ) ;
2022-12-05 01:28:24 +08:00
_index ++ ;
} ,
after : function ( ) {
2022-12-06 14:34:04 +08:00
_result . count = _index ;
2022-12-05 01:28:24 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
}
2022-12-09 18:20:41 +08:00
// /**
// * 取得單一設備異常
// * @param {any} callback
// */
// //(devicePath, callback)
// function getOneDeviceAlarmByBaja(devicePath, startDate_millisecond, endDate_millisecond, isRecover, isAck, callback) {
// // var _result = "";
// // var _ss = "";
// // var _occurrenceTime = "";
// // var _normalTime = "";
// // var _index = 0;
// let _sourceTmp;
// var _result = "";
// var _ss = "";
// var _bfName = "";
// var _sourceName = "";
// var _index = 0;
// var _recoverState = isRecover ? "!= null" : "= null";
// //local:|foxs:|alarm:|bql:select ackState from openAlarms where ackState ='acked'
// var _ackState = isAck ? "= 'acked'" : "= 'unacked'";
// //{ "count":2,"data": [{ "time": "2022/11/14 15:00:00", "errId": "0001", "ackCheck": "未確認", "errReason": "燈泡故障" }, { "time": "2022/11/14 15:00:00", "errId": "0002", "ackCheck": "未確認", "errReason": "燈泡故障" }]}
// require(['baja!'], function (baja) {
// console.log("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' and timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc");
// baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' and timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get()
// // console.log("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' and alarmClass = '" + alarmClass + "' and timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc");
// // baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' and alarmClass = '" + alarmClass + "' and timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get()
// //baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc").get()
// .then(function (table) {
// return table.cursor({
// each: function (record) {
// _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_');
// _bfName = _sourceTmp[1] + "-" + _sourceTmp[4];
// _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8];
// // _occurrenceTime = "";
// // _normalTime = "";
// //var _resultUuid = record.get('uuid').toString().split("-");//43dc7846-bd96-4be2-ab35-f11aec729c60
// // var _timestampTemp = new Date(record.get('timestamp').toString());
// // _occurrenceTime += _timestampTemp.getFullYear().toString() + "-" + addzero(_timestampTemp.getMonth() + 1).toString() + "-" + addzero(_timestampTemp.getDate()).toString() + " " + addzero(_timestampTemp.getHours()).toString() + ":" + addzero(_timestampTemp.getMinutes()).toString() + ":" + addzero(_timestampTemp.getSeconds()).toString();
// // var _normaltime = new Date(record.get('normalTime').toString());
// // _normalTime += _normaltime.getFullYear().toString() + "-" + addzero(_normaltime.getMonth() + 1).toString() + "-" + addzero(_normaltime.getDate()).toString() + " " + addzero(_normaltime.getHours()).toString() + ":" + addzero(_normaltime.getMinutes()).toString() + ":" + addzero(_normaltime.getSeconds()).toString();
// // var _msgText = record.get('alarmData').get('msgText');// == 1 ? _occurrenceTime : "未確認";
// // var _ackText = record.get('ackState') == 1 ? _occurrenceTime : "未確認";
// //_ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
// if (_index == 0)
// _ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
// //_ss += '{"uuid":"' + record.get('uuid') + '", "msgText":"' + _msgText + '", "ackState":"' + _ackText + '", "timestamp":"' + _occurrenceTime + '", "normalTime":"' + _normalTime + '"}';
// else
// _ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
// _index++;
// },
// after: function () {
// _result += '{' + '"count": ' + _index + ', "data":[';
// _result += _ss + ']';
// _result += '}';
// if (typeof callback === 'function') {
// callback(_result);
// }
// },
// limit: -1,
// offset: 0
// });
// });
// });
// }
2022-12-05 01:28:24 +08:00
/ * *
2022-12-09 18:20:41 +08:00
* 取得單一設備異常
* @ param { any } devicePath
2022-12-05 01:28:24 +08:00
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
function getOneDeviceAlarmByBaja ( devicePath , callback ) {
let _sourceTmp ;
var _result = "" ;
var _ss = "" ;
var _bfName = "" ;
var _sourceName = "" ;
2022-12-05 01:28:24 +08:00
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) {
2022-12-09 18:20:41 +08:00
console . log ( "local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc" ) ;
baja . Ord . make ( "local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc" ) . get ( )
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
_sourceTmp = ( record . get ( 'alarmData' ) . get ( 'sourceName' ) ) . toString ( ) . split ( '_' ) ;
_bfName = _sourceTmp [ 1 ] + "-" + _sourceTmp [ 4 ] ;
_sourceName = _sourceTmp [ 7 ] + "-" + _sourceTmp [ 8 ] ;
if ( _index == 0 )
_ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record . get ( 'uuid' ) + '", "timestamp":"' + record . get ( 'timestamp' ) + '", "alarmClass":"' + record . get ( 'alarmClass' ) + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record . get ( 'alarmData' ) . get ( 'msgText' ) + '", "ackState":"' + record . get ( 'ackState' ) + '", "normalTime":"' + record . get ( 'normalTime' ) + '"}' ;
else
_ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record . get ( 'uuid' ) + '", "timestamp":"' + record . get ( 'timestamp' ) + '", "alarmClass":"' + record . get ( 'alarmClass' ) + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record . get ( 'alarmData' ) . get ( 'msgText' ) + '", "ackState":"' + record . get ( 'ackState' ) + '", "normalTime":"' + record . get ( 'normalTime' ) + '"}' ;
_index ++ ;
} ,
after : function ( ) {
_result += '{' + '"count": ' + _index + ', "data":[' ;
_result += _ss + ']' ;
_result += '}' ;
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
}
function getAllDeviceAlarmByBaja ( startDate _millisecond , endDate _millisecond , isRecover , isAck , callback ) {
let _sourceTmp ;
var _result = "" ;
var _ss = "" ;
var _bfName = "" ;
var _sourceName = "" ;
var _index = 0 ;
var _recoverState = isRecover ? "!= null" : "= null" ;
var _ackState = isAck ? "= 'acked'" : "= 'unacked'" ;
require ( [ 'baja!' ] , function ( baja ) {
console . log ( "local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where timestamp.millis >= " + startDate _millisecond + " and timestamp.millis <= " + endDate _millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc" ) ;
baja . Ord . make ( "local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where timestamp.millis >= " + startDate _millisecond + " and timestamp.millis <= " + endDate _millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc" ) . get ( )
2022-12-05 01:28:24 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
2022-12-09 18:20:41 +08:00
_sourceTmp = ( record . get ( 'alarmData' ) . get ( 'sourceName' ) ) . toString ( ) . split ( '_' ) ;
_bfName = _sourceTmp [ 1 ] + "-" + _sourceTmp [ 4 ] ;
_sourceName = _sourceTmp [ 7 ] + "-" + _sourceTmp [ 8 ] ;
if ( _index == 0 )
_ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record . get ( 'uuid' ) + '", "timestamp":"' + record . get ( 'timestamp' ) + '", "alarmClass":"' + record . get ( 'alarmClass' ) + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record . get ( 'alarmData' ) . get ( 'msgText' ) + '", "ackState":"' + record . get ( 'ackState' ) + '", "normalTime":"' + record . get ( 'normalTime' ) + '"}' ;
else
_ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record . get ( 'uuid' ) + '", "timestamp":"' + record . get ( 'timestamp' ) + '", "alarmClass":"' + record . get ( 'alarmClass' ) + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record . get ( 'alarmData' ) . get ( 'msgText' ) + '", "ackState":"' + record . get ( 'ackState' ) + '", "normalTime":"' + record . get ( 'normalTime' ) + '"}' ;
2022-12-05 01:28:24 +08:00
_index ++ ;
} ,
after : function ( ) {
2022-12-09 18:20:41 +08:00
_result += '{' + '"count": ' + _index + ', "data":[' ;
_result += _ss + ']' ;
_result += '}' ;
2022-12-05 01:28:24 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
2022-12-05 18:45:24 +08:00
}
2022-12-06 22:56:13 +08:00
/ * *
2022-12-09 18:20:41 +08:00
* [ 首頁 ] 圓餅圖資料 - 全部的異常
2022-12-06 22:56:13 +08:00
* @ param { any } callback
* /
2022-12-09 18:20:41 +08:00
function getAlarmForChartDataByBaja ( callback ) {
var _result = "" ;
var _ss = "" ;
2022-12-06 22:56:13 +08:00
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) {
2022-12-09 18:20:41 +08:00
baja . Ord . make ( "local:|foxs:|alarm:|bql:select alarmClass, ackState, normalTime where isAlarm" ) . get ( )
2022-12-06 22:56:13 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
2022-12-09 18:20:41 +08:00
if ( _index == 0 )
_ss += '{"alarmClass":"' + record . get ( 'alarmClass' ) + '", "ackState":"' + record . get ( 'ackState' ) + '", "normalTime":"' + record . get ( 'normalTime' ) + '"}' ;
else
_ss += ',{"alarmClass":"' + record . get ( 'alarmClass' ) + '", "ackState":"' + record . get ( 'ackState' ) + '", "normalTime":"' + record . get ( 'normalTime' ) + '"}' ;
2022-12-06 22:56:13 +08:00
_index ++ ;
} ,
after : function ( ) {
2022-12-09 18:20:41 +08:00
_result += '{' + '"count": ' + _index + ', "data":[' ;
_result += _ss ;
_result += ']}' ;
2022-12-06 22:56:13 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
2022-12-09 18:20:41 +08:00
}