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
* /
2022-11-29 12:46:19 +08:00
// 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) {
// _ss += ', "' + _index + '": {"deviceName":"' + deviceName + '", "value":' + record.get('value') + ', "timestamp":"' + record.get('timestamp') + '"}';
// _index++;
// },
// after: function () {
// _result += '{' + '"count": ' + _index;
// _result += _ss;
// _result += '}';
// if (typeof callback === 'function') {
// callback(_result);
// }
// }
// });
// });
// });
// }
2022-11-16 13:31:09 +08:00
function getHistoryDataByBaja ( devicePath , startDate _millisecond , endDate _millisecond , deviceName , company , callback ) {
2023-03-06 11:37:01 +08:00
var _result = { } ;
var _ss = [ ] ;
var _index = 0 ;
2022-11-16 13:31:09 +08:00
2023-03-06 11:37:01 +08:00
require ( [ 'baja!' ] , function ( baja ) {
console . log ( 'local:|foxs:|history:/' + company + '/' + devicePath + '|bql:select * from control:ControlPoint where timestamp.millis > ' + startDate _millisecond + ' and timestamp.millis < ' + endDate _millisecond ) ;
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 ) {
console . log ( record . get ( 'timestamp' ) )
// if (_index == 0)
// _ss += '{"deviceName":"' + deviceName + '", "value":' + record.get('value') + ', "timestamp":"' + record.get('timestamp').$cEncStr
// + '"}';
// else
// _ss += ',{"deviceName":"' + deviceName + '", "value":' + record.get('value') + ', "timestamp":"' + record.get('timestamp').$cEncStr
// + '"}';
_ss . push ( { deviceName : deviceName , value : record . get ( 'value' ) , timestamp : record . get ( 'timestamp' ) . $cEncStr
} ) ;
_index ++ ;
} ,
after : function ( ) {
2023-07-17 15:23:13 +08:00
$ ( loadEle ) . Loading ( "close" ) ;
2023-03-06 11:37:01 +08:00
_result = { count : _index , data : _ss }
// _result += '{' + '"count": ' + _index + ', "data":[';
// _result += _ss;
// _result += ']}';
if ( typeof callback === 'function' ) {
// console.log(_result)
_result = JSON . stringify ( _result )
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} )
. catch ( ( ) => {
console . log ( "error" ) ;
2023-07-17 15:23:13 +08:00
$ ( loadEle ) . Loading ( "close" ) ;
2023-03-06 11:37:01 +08:00
// const res = JSON.stringify({count:0, data:[]})
callback ( )
} ) ;
} ) ;
2022-11-16 13:31:09 +08:00
}
2022-11-24 16:27:00 +08:00
function test3000p ( devicePath , startDate _millisecond , endDate _millisecond , deviceName , company , callback ) {
2023-03-06 11:37:01 +08:00
var _result = "" ;
var _ss = "" ;
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) {
"use strict" ;
baja . Ord . make ( 'local:|foxs:|history:/' + company + '/' + devicePath + '|bql:select * from control:ControlPoint where timestamp.millis > ' + startDate _millisecond + ' and timestamp.millis < ' + endDate _millisecond )
. get (
function ( table ) {
table . cursor ( {
each : function ( item ) {
console . log ( "item: " + item ) ;
if ( _index == 0 )
_ss += '{"deviceName":"' + deviceName + '", "value":' + item . $map . $map . value . $display + ', "timestamp":"' + item . $map . $map . timestamp . $val . $cEncStr + '"}' ;
else
_ss += ',{"deviceName":"' + deviceName + '", "value":' + item . $map . $map . value . $display + ', "timestamp":"' + item . $map . $map . timestamp . $val . $cEncStr + '"}' ;
_index ++ ;
} ,
after : function ( ) {
_result += '{' + '"count": ' + _index + ', "data":[' ;
_result += _ss ;
_result += ']}' ;
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} )
} ) ;
2022-11-24 16:27:00 +08:00
}