2022-11-16 13:31:09 +08:00
/ * *
* 取得歷史資料 by baja
* @ param { any } devicePath
* @ param { any } startDate _millisecond
* @ param { any } endDate _millisecond
* @ param { any } deviceName
* @ param { any } company
* @ param { any } callback
* /
function getHistoryDataByBaja ( devicePath , startDate _millisecond , endDate _millisecond , deviceName , company , callback ) {
var _result = "" ;
var _ss = "" ;
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) {
baja . Ord . make ( 'local:|foxs:|history:/' + company + '/' + devicePath + '|bql:select * from control:ControlPoint where timestamp.millis > ' + startDate _millisecond + ' and timestamp.millis < ' + endDate _millisecond ) . get ( )
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
2022-11-21 14:46:25 +08:00
if ( _index == 0 )
_ss += '{"deviceName":"' + deviceName + '", "value":' + record . get ( 'value' ) + ', "timestamp":"' + record . get ( 'timestamp' ) + '"}' ;
else
_ss += ',{"deviceName":"' + deviceName + '", "value":' + record . get ( 'value' ) + ', "timestamp":"' + record . get ( 'timestamp' ) + '"}' ;
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 ) ;
}
}
} ) ;
} ) ;
} ) ;
}