65 lines
2.8 KiB
JavaScript
65 lines
2.8 KiB
JavaScript
|
|
/**
|
|
* 取得歷史資料 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) {
|
|
// _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);
|
|
// }
|
|
// }
|
|
// });
|
|
// });
|
|
// });
|
|
// }
|
|
|
|
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) {
|
|
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') + '"}';
|
|
_index++;
|
|
},
|
|
after: function () {
|
|
_result += '{' + '"count": ' + _index + ', "data":[';
|
|
_result += _ss;
|
|
_result += ']}';
|
|
if (typeof callback === 'function') {
|
|
callback(_result);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}
|