[前台] 告警系統 維修單新增及顯示 | 取得 N4 資料 Ord 修正

This commit is contained in:
Celeste 2023-02-15 16:05:59 +08:00
parent 0da4c4cdd7
commit b6f7ff0b75
2 changed files with 1214 additions and 1204 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
function addzero(num) { function addzero(num) {
return num < 10 ? '0' + num : num; return num < 10 ? '0' + num : num;
} }
/** /**
@ -85,45 +85,46 @@ function addzero(num) {
// }); // });
// } // }
function getAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, alarmClass, callback) { function getAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, alarmClass, callback) {
let _sourceTmp; let _sourceTmp;
var _result = ""; var _result = "";
var _ss = []; var _ss = [];
var _bfName = ""; var _bfName = "";
var _sourceName = ""; var _sourceName = "";
var _index = 0; var _index = 0;
var _recoverState = isRecover ? "!= null" : "= null"; var _recoverState = isRecover ? "!= null" : "= null";
var _ackState = isAck ? "= 'acked'" : "= 'unacked'"; var _ackState = isAck ? "= 'acked'" : "= 'unacked'";
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 alarmClass = '" + alarmClass + "' and timestamp.millis > " + startDate_millisecond + " and timestamp.millis < " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp asc") 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 where alarmClass = '" + alarmClass + "' and timestamp.millis > " + startDate_millisecond + " and timestamp.millis < " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp asc")
require(['baja!'], function (baja) { require(['baja!'], function (baja) {
baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackTime, 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() baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackTime, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime where alarmClass = '" + alarmClass + "' and timestamp.millis > " + startDate_millisecond + " and timestamp.millis < " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp asc").get()
.then(function (table) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
const alarmDisplayName = record.get('alarmData').get('sourceName').split(":")[1] ?? record.get('alarmData').get('sourceName').split(":")[0] // console.log(record)
//console.log(alarmDisplayName) const alarmDisplayName = record.get('alarmData').get('sourceName').split(":")[1] ?? record.get('alarmData').get('sourceName').split(":")[0]
_sourceTmp = alarmDisplayName.split('_'); //console.log(alarmDisplayName)
_bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; _sourceTmp = alarmDisplayName.split('_');
_sourceName = _sourceTmp.slice(0, 8).join("_"); _bfName = _sourceTmp[1] + "-" + _sourceTmp[4];
_sourceTmp = _sourceTmp[7] + "-" + _sourceTmp[8]; _sourceName = _sourceTmp.slice(0, 8).join("_");
if (!_sourceTmp.includes("undefined")) { _sourceTmp = _sourceTmp[7] + "-" + _sourceTmp[8];
_ss.push({ buildingFloorName_zh: _bfName, uuid: record.get('uuid'), timestamp: record.get('timestamp').$cEncStr, alarmClass: record.get('alarmClass'), sourceName_zh: _sourceName, sourceTmp: _sourceTmp, msgText: record.get('alarmData').get('msgText'), ackState: record.get('ackState'), normalTime: record.get('normalTime'), ackedTime: record.get('ackTime').$cEncStr }) if (!_sourceTmp.includes("undefined")) {
} _ss.push({ buildingFloorName_zh: _bfName, uuid: record.get('uuid'), timestamp: record.get('timestamp').$cEncStr, alarmClass: record.get('alarmClass'), sourceName_zh: _sourceName, sourceTmp: _sourceTmp, msgText: record.get('alarmData').get('msgText'), ackState: record.get('ackState'), normalTime: record.get('normalTime'), ackedTime: record.get('ackTime').$cEncStr })
_index++ }
}, _index++
after: function () { },
_result = { count: _index, data: _ss } after: function () {
_result = { count: _index, data: _ss }
//console.log(552, _result); //console.log(552, _result);
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }
/** /**
@ -161,45 +162,45 @@ function getAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, i
// }); // });
// } // }
function getOneDeviceAlarmTop10ByBaja(devicePath, callback) { function getOneDeviceAlarmTop10ByBaja(devicePath, callback) {
var _result = {}; var _result = {};
var _ss = []; var _ss = [];
var _occurrenceTime = ""; var _occurrenceTime = "";
var _normalTime = ""; var _normalTime = "";
var _index = 0; 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": "燈泡故障" }]} //{ "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) { 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() 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) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
_occurrenceTime = ""; _occurrenceTime = "";
_normalTime = ""; _normalTime = "";
// console.log(record.get('timestamp'),record.get('normalTime') ) // console.log(record.get('timestamp'),record.get('normalTime') )
var _resultUuid = record.get('uuid').toString().split("-");//43dc7846-bd96-4be2-ab35-f11aec729c60 var _resultUuid = record.get('uuid').toString().split("-");//43dc7846-bd96-4be2-ab35-f11aec729c60
var _occurrenceTime = new Date(record.get('timestamp').$cEncStr).toLocaleString('zh-tw', { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" }); var _occurrenceTime = new Date(record.get('timestamp').$cEncStr).toLocaleString('zh-tw', { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
// _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(); // _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 _occurrenceTime = _timestamp.format("yyyy-MM-dd hh:mm:ss");//.toLocaleString(); //var _occurrenceTime = _timestamp.format("yyyy-MM-dd hh:mm:ss");//.toLocaleString();
var _normalTime = new Date(record.get('normalTime').$cEncStr).toLocaleString('zh-tw', { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" }); var _normalTime = new Date(record.get('normalTime').$cEncStr).toLocaleString('zh-tw', { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
// _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(); // _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 _msgText = record.get('alarmData').get('msgText');// == 1 ? _occurrenceTime : "未確認";
var _ackText = record.get('ackState') == 1 ? _occurrenceTime : "未確認"; var _ackText = record.get('ackState') == 1 ? _occurrenceTime : "未確認";
_ss.push({ uuid: _resultUuid[0], msgText: _msgText, ackState: _ackText, timestamp: _occurrenceTime, normalTime: _normalTime }) _ss.push({ uuid: _resultUuid[0], msgText: _msgText, ackState: _ackText, timestamp: _occurrenceTime, normalTime: _normalTime })
_index++; _index++;
}, },
after: function () { after: function () {
_result = JSON.stringify({ count: _index, data: _ss }) _result = JSON.stringify({ count: _index, data: _ss })
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }
/** /**
@ -233,34 +234,34 @@ function getOneDeviceAlarmTop10ByBaja(devicePath, callback) {
// }); // });
// } // }
function getOneSystemAlarmStateByBaja(systemPath, callback) { function getOneSystemAlarmStateByBaja(systemPath, callback) {
var _result = ""; var _result = "";
var _ss = ""; var _ss = "";
var _index = 0; var _index = 0;
/* console.log("local:|foxs:|alarm:|bql:select alarmData, alarmData.sourceName, sourceState, uuid where alarmData.sourceName like '%" + systemPath + "%' order by timestamp desc")*/ /* console.log("local:|foxs:|alarm:|bql:select alarmData, alarmData.sourceName, sourceState, uuid where alarmData.sourceName like '%" + systemPath + "%' order by timestamp desc")*/
require(['baja!'], function (baja) { 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() 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) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
if (_index == 0) if (_index == 0)
_ss += '{"uuid":"' + record.get('uuid') + '", "sourceName":"' + record.get('alarmData').get('sourceName') + '", "sourceState":"' + record.get('sourceState') + '"}'; _ss += '{"uuid":"' + record.get('uuid') + '", "sourceName":"' + record.get('alarmData').get('sourceName') + '", "sourceState":"' + record.get('sourceState') + '"}';
else else
_ss += ',{"uuid":"' + record.get('uuid') + '", "sourceName":"' + record.get('alarmData').get('sourceName') + '", "sourceState":"' + record.get('sourceState') + '"}'; _ss += ',{"uuid":"' + record.get('uuid') + '", "sourceName":"' + record.get('alarmData').get('sourceName') + '", "sourceState":"' + record.get('sourceState') + '"}';
_index++; _index++;
}, },
after: function () { after: function () {
_result += '{' + '"count": ' + _index + ', "data":['; _result += '{' + '"count": ' + _index + ', "data":[';
_result += _ss; _result += _ss;
_result += ']}'; _result += ']}';
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }
/** /**
@ -269,35 +270,35 @@ function getOneSystemAlarmStateByBaja(systemPath, callback) {
* @param {any} callback * @param {any} callback
*/ */
function getOneSystemStateByBaja(systemPath, callback) { function getOneSystemStateByBaja(systemPath, callback) {
var _result = ""; var _result = "";
var _ss = ""; var _ss = "";
var _index = 0; var _index = 0;
require(['baja!'], function (baja) { 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() 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) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
//if (_index == 0) //if (_index == 0)
// _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; // _ss += '{"sourceState":"' + record.get('sourceState') + '"}';
//else //else
// _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; // _ss += '{"sourceState":"' + record.get('sourceState') + '"}';
_ss += '{"sourceState":"' + record.get('sourceState') + '"}'; _ss += '{"sourceState":"' + record.get('sourceState') + '"}';
_index++; _index++;
}, },
after: function () { after: function () {
_result += '{' + '"count": ' + _index + ', "data":['; _result += '{' + '"count": ' + _index + ', "data":[';
_result += _ss; _result += _ss;
_result += ']}'; _result += ']}';
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }
/** /**
@ -305,27 +306,27 @@ function getOneSystemStateByBaja(systemPath, callback) {
* @param {any} callback * @param {any} callback
*/ */
function getAlarmCountByBaja(callback) { function getAlarmCountByBaja(callback) {
var _result = { count: 0 }; var _result = { count: 0 };
var _index = 0; var _index = 0;
require(['baja!'], function (baja) { require(['baja!'], function (baja) {
baja.Ord.make("local:|foxs:|alarm:|bql:select sourceState where sourceState = 'offnormal'").get() baja.Ord.make("local:|foxs:|alarm:|bql:select sourceState where sourceState = 'offnormal'").get()
.then(function (table) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
_index++; _index++;
}, },
after: function () { after: function () {
_result.count = _index; _result.count = _index;
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }
/** /**
@ -333,27 +334,27 @@ function getAlarmCountByBaja(callback) {
* @param {any} callback * @param {any} callback
*/ */
function getRecoverCountByBaja(callback) { function getRecoverCountByBaja(callback) {
var _result = { count: 0 }; var _result = { count: 0 };
var _index = 0; var _index = 0;
require(['baja!'], function (baja) { require(['baja!'], function (baja) {
baja.Ord.make("local:|foxs:|alarm:|bql:select normalTime where normalTime != null").get() baja.Ord.make("local:|foxs:|alarm:|bql:select normalTime where normalTime != null").get()
.then(function (table) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
_index++; _index++;
}, },
after: function () { after: function () {
_result.count = _index; _result.count = _index;
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }
/** /**
@ -361,27 +362,27 @@ function getRecoverCountByBaja(callback) {
* @param {any} callback * @param {any} callback
*/ */
function getCheckedAckedCountByBaja(callback) { function getCheckedAckedCountByBaja(callback) {
var _result = { count: 0 }; var _result = { count: 0 };
var _index = 0; var _index = 0;
require(['baja!'], function (baja) { require(['baja!'], function (baja) {
baja.Ord.make("local:|foxs:|alarm:|bql:select ackState from openAlarms where ackState ='acked'").get() baja.Ord.make("local:|foxs:|alarm:|bql:select ackState from openAlarms where ackState ='acked'").get()
.then(function (table) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
_index++; _index++;
}, },
after: function () { after: function () {
_result.count = _index; _result.count = _index;
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }
/** /**
@ -389,27 +390,27 @@ function getCheckedAckedCountByBaja(callback) {
* @param {any} callback * @param {any} callback
*/ */
function getUnCheckedAckedCountByBaja(callback) { function getUnCheckedAckedCountByBaja(callback) {
var _result = { count: 0 }; var _result = { count: 0 };
var _index = 0; var _index = 0;
require(['baja!'], function (baja) { require(['baja!'], function (baja) {
baja.Ord.make("local:|foxs:|alarm:|bql:select ackState from openAlarms where ackState ='unacked'").get() baja.Ord.make("local:|foxs:|alarm:|bql:select ackState from openAlarms where ackState ='unacked'").get()
.then(function (table) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
_index++; _index++;
}, },
after: function () { after: function () {
_result.count = _index; _result.count = _index;
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }
/** /**
@ -417,32 +418,32 @@ function getUnCheckedAckedCountByBaja(callback) {
* @param {any} callback * @param {any} callback
*/ */
function getSystemAlarmByBaja(callback) { function getSystemAlarmByBaja(callback) {
var _result = { count: 0, data: [] }; var _result = { count: 0, data: [] };
var _index = 0; var _index = 0;
require(['baja!'], function (baja) { 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 where isAlarm").get() //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() baja.Ord.make("local:|foxs:|alarm:|bql:select alarmClass where isAlarm").get()
.then(function (table) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
let main = {}; let main = {};
main.alarmClass = record.get('alarmClass'); main.alarmClass = record.get('alarmClass');
_result.data.push(main); _result.data.push(main);
_index++; _index++;
}, },
after: function () { after: function () {
_result.count = _index; _result.count = _index;
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }
// /** // /**
@ -523,150 +524,160 @@ function getSystemAlarmByBaja(callback) {
* @param {any} callback * @param {any} callback
*/ */
function getOneDeviceAlarmByBaja(devicePath, callback) { function getOneDeviceAlarmByBaja(devicePath, callback) {
let _sourceTmp; let _sourceTmp;
var _result = ""; var _result = "";
var _ss = []; var _ss = [];
var _bfName = ""; var _bfName = "";
var _sourceName = ""; var _sourceName = "";
var _index = 0; var _index = 0;
require(['baja!'], function (baja) { 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 + "%' order by timestamp desc");*/ /* 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() 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) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
_sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_'); _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_');
_bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; _bfName = _sourceTmp[1] + "-" + _sourceTmp[4];
_sourceName = _sourceTmp[7] + "-" + _sourceTmp[8]; _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8];
_ss.push({ 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.push({ 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++ _index++
}, },
after: function () { after: function () {
_result = { count: _index, data: _ss } _result = { count: _index, data: _ss }
//console.log(552, _result); //console.log(552, _result);
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }
function getAllDeviceAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, callback) { function getAllDeviceAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, callback) {
var _result = { count: 0, data: [] }; var _result = { count: 0, data: [] };
var _index = 0; var _index = 0;
var _recoverState = isRecover ? "!= null" : "= null"; var _recoverState = isRecover ? "!= null" : "= null";
var _ackState = isAck ? "= 'acked'" : "= 'unacked'"; var _ackState = isAck ? "= 'acked'" : "= 'unacked'";
let startUrl = ""; let startUrl = "";
if (startDate_millisecond) { if (startDate_millisecond) {
startUrl = "timestamp.millis >= " + startDate_millisecond + " and "; startUrl = "timestamp.millis >= " + startDate_millisecond + " and ";
} }
// console.log("local:|foxs:|alarm:|bql:select timestamp, ackTime, priority ,ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where " + startUrl + "timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc"); console.log("local:|foxs:|alarm:|bql:select timestamp, ackTime, priority ,ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime where " + startUrl + "timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc");
require(['baja!'], function (baja) { require(['baja!'], function (baja) {
baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackTime, priority ,ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where " + startUrl + "timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get() baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackTime, priority ,ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime where " + startUrl + "timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get()
.then(function (table) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
// console.log(record,record.get('alarmData').get('sourceName').split(':')) // console.log(record)
let main = {}; let main = {};
// console.log(record.get('alarmData').get('sourceName'),record.get('timestamp').$cEncStr) // console.log(record.get('alarmData').get('sourceName'),record.get('timestamp').$cEncStr)
const alarmDisplayName = record.get('alarmData').get('sourceName').split(":")[1] ?? record.get('alarmData').get('sourceName').split(":")[0] const alarmDisplayName = record.get('alarmData').get('sourceName').split(":")[1] ?? record.get('alarmData').get('sourceName').split(":")[0]
//console.log(alarmDisplayName) //console.log(alarmDisplayName)
_sourceTmp = alarmDisplayName.split('_'); _sourceTmp = alarmDisplayName.split('_');
let _bfName = _sourceTmp[1] + "-" + _sourceTmp[4] let _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]
let _sourceName = _sourceTmp.slice(0, 8).join("_"); let _sourceName = _sourceTmp.slice(0, 8).join("_");
_sourceTmp = _sourceTmp[7] + "-" + _sourceTmp[8]; _sourceTmp = _sourceTmp[7] + "-" + _sourceTmp[8];
main.buildingFloorName_zh = _bfName; main.buildingFloorName_zh = _bfName;
main.sourceName_zh = _sourceName; main.sourceName_zh = _sourceName;
main.uuid = record.get('uuid').$val; main.uuid = record.get('uuid').$val;
main.timestamp = record.get('timestamp').$cEncStr; main.timestamp = record.get('timestamp').$cEncStr;
main.alarmClass = record.get('alarmClass'); main.alarmClass = record.get('alarmClass');
main.point = _sourceTmp; main.point = _sourceTmp;
main.sourceTmp = _sourceTmp; main.sourceTmp = _sourceTmp;
main.devicePath = _sourceName; main.devicePath = _sourceName;
main.msgText = record.get('alarmData').get('msgText'); main.msgText = record.get('alarmData').get('msgText');
main.normalTime = record.get('normalTime'); main.normalTime = record.get('normalTime');
main.priority = record.get('priority'); main.priority = record.get('priority');
main.ackedTime = record.get('ackTime').$cEncStr; main.ackedTime = record.get('ackTime').$cEncStr;
if (!_sourceTmp.includes("undefined")) { main.ackState = record.get('ackState').$ordinal
_result.data.push(main); if (!_sourceTmp.includes("undefined")) {
} // console.log(main.ackState)
_index++; _result.data.push(main);
}, }
after: function () { _index++;
_result.count = _index; },
if (typeof callback === 'function') { after: function () {
//console.log(_result) _result.count = _index;
callback(_result); if (typeof callback === 'function') {
} //console.log(_result)
}, callback(_result);
limit: -1, }
offset: 0 },
}); limit: -1,
}); offset: 0
}); });
});
});
} }
function getDeviceAlarmCardByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, callback) { function getDeviceAlarmCardByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, callback) {
var _result = { count: 0, data: [] }; var _result = { count: 0, data: [] };
var _index = 0; var _index = 0;
var _recoverState = isRecover ? "!= null" : "= null"; var _recoverState = isRecover ? "!= null" : "= null";
var _ackState = isAck ? "= 'acked'" : "= 'unacked'"; var _ackState = isAck ? "= 'acked'" : "= 'unacked'";
require(['baja!'], function (baja) {
let startUrl = ""; let startUrl = "";
if (startDate_millisecond) { if (startDate_millisecond) {
startUrl = "timestamp.millis >= " + startDate_millisecond + " and "; startUrl = "timestamp.millis >= " + startDate_millisecond + " and ";
} }
/* console.log("local:|foxs:|alarm:|bql:select timestamp, ackTime, priority ,ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where " + startUrl + "timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc");*/ // console.log("首頁","local:|foxs:|alarm:|bql:select timestamp, ackTime, priority ,ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where " + startUrl + "timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc");
require(['baja!'], function (baja) {
baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackTime, priority ,ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where " + startUrl + "timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get() baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackTime, priority ,ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime where " + startUrl + "timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get()
.then(function (table) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
let main = {}; // console.log(record)
//console.log(record.get('alarmData').get('sourceName')) let main = {};
_sourcePoint = (record.get('alarmData').get('sourceName')).toString().split(':')[1]; // console.log(record.get('alarmData').get('sourceName'),record.get('timestamp').$cEncStr)
//console.log(_sourcePoint) const alarmDisplayName = record.get('alarmData').get('sourceName').split(":")[1] ?? record.get('alarmData').get('sourceName').split(":")[0]
_sourceTmp = _sourcePoint.split("_"); //console.log(alarmDisplayName)
_sourceTmp = alarmDisplayName.split('_');
let _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]
let _sourceName = _sourceTmp.slice(0, 8).join("_");
_sourceTmp = _sourceTmp[7] + "-" + _sourceTmp[8];
let _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; main.buildingFloorName_zh = _bfName;
let _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8]; main.sourceName_zh = _sourceName;
main.buildingFloorName_zh = _bfName; main.uuid = record.get('uuid').$val;
main.sourceName_zh = _sourceName; main.timestamp = record.get('timestamp').$cEncStr;
main.uuid = record.get('uuid').$val; main.alarmClass = record.get('alarmClass');
main.timestamp = record.get('timestamp'); main.point = _sourceTmp;
main.alarmClass = record.get('alarmClass'); main.sourceTmp = _sourceTmp;
main.point = _sourcePoint; main.devicePath = _sourceName;
main.devicePath = _sourceTmp.slice(0, 8).join("_");; main.msgText = record.get('alarmData').get('msgText');
main.msgText = record.get('alarmData').get('msgText'); main.normalTime = record.get('normalTime');
main.normalTime = record.get('normalTime'); main.priority = record.get('priority');
main.priority = record.get('priority'); main.ackedTime = record.get('ackTime').$cEncStr;
main.ackedTime = record.get('ackTime').$cEncStr; main.ackState = record.get('ackState').$ordinal
_result.data.push(main); if (!_sourceTmp.includes("undefined")) {
_index++; // console.log(main.ackState)
}, _result.data.push(main);
after: function () { }
_result.count = _index; _index++;
if (typeof callback === 'function') { },
callback(_result); after: function () {
} _result.count = _index;
}, if (typeof callback === 'function') {
limit: -1, //console.log(_result)
offset: 0 callback(_result);
}); }
}); },
}); limit: -1,
offset: 0
});
});
});
} }
/** /**
@ -674,32 +685,32 @@ function getDeviceAlarmCardByBaja(startDate_millisecond, endDate_millisecond, is
* @param {any} callback * @param {any} callback
*/ */
function getAlarmForChartDataByBaja(callback) { function getAlarmForChartDataByBaja(callback) {
var _result = ""; var _result = "";
var _ss = ""; var _ss = "";
var _index = 0; var _index = 0;
require(['baja!'], function (baja) { require(['baja!'], function (baja) {
baja.Ord.make("local:|foxs:|alarm:|bql:select alarmClass, ackState, normalTime where isAlarm").get() baja.Ord.make("local:|foxs:|alarm:|bql:select alarmClass, ackState, normalTime where isAlarm").get()
.then(function (table) { .then(function (table) {
return table.cursor({ return table.cursor({
each: function (record) { each: function (record) {
if (_index == 0) if (_index == 0)
_ss += '{"alarmClass":"' + record.get('alarmClass') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; _ss += '{"alarmClass":"' + record.get('alarmClass') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
else else
_ss += ',{"alarmClass":"' + record.get('alarmClass') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; _ss += ',{"alarmClass":"' + record.get('alarmClass') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
_index++; _index++;
}, },
after: function () { after: function () {
_result += '{' + '"count": ' + _index + ', "data":['; _result += '{' + '"count": ' + _index + ', "data":[';
_result += _ss; _result += _ss;
_result += ']}'; _result += ']}';
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(_result); callback(_result);
} }
}, },
limit: -1, limit: -1,
offset: 0 offset: 0
}); });
}); });
}); });
} }