|
|
@ -4,7 +4,7 @@ module.exports = function (app, opts) { |
|
|
|
const cameraOnlinePush = app.fs.scheduleInit( |
|
|
|
{ |
|
|
|
interval: '* */15 * * * *', |
|
|
|
// interval: '*/15 * * * * *',
|
|
|
|
interval: '*/15 * * * * *', |
|
|
|
immediate: false, |
|
|
|
proRun: true, |
|
|
|
}, |
|
|
@ -39,9 +39,10 @@ module.exports = function (app, opts) { |
|
|
|
const offlineStatusRes = await models.CameraStatusOfflineLog.findAll({ |
|
|
|
where: { |
|
|
|
cameraId: { $in: cameraIds }, |
|
|
|
time: { |
|
|
|
$between: [moment(timeNow).subtract(15, 'minutes').format(), timeNow] |
|
|
|
} |
|
|
|
|
|
|
|
// time: {
|
|
|
|
// $between: [moment(timeNow).subtract(15, 'minutes').format(), timeNow]
|
|
|
|
// }
|
|
|
|
}, |
|
|
|
include: [{ |
|
|
|
model: models.Camera, |
|
|
@ -57,7 +58,7 @@ module.exports = function (app, opts) { |
|
|
|
// 只要出现一次上线 就做上线推送
|
|
|
|
for (let s of offlineStatusRes) { |
|
|
|
if (cameraStatusMap[s.cameraId]) { |
|
|
|
cameraStatusMap.status.push({ |
|
|
|
cameraStatusMap[s.cameraId].status.push({ |
|
|
|
status: s.status, |
|
|
|
time: s.time, |
|
|
|
}) |
|
|
@ -121,7 +122,7 @@ module.exports = function (app, opts) { |
|
|
|
if (offArr.length && c.noticeWay && c.noticeWay.includes('offline')) { |
|
|
|
if (c.pushWay == 'email') { |
|
|
|
// 邮件
|
|
|
|
let text = `【${corUser[0].namePresent}】账号下的设备,截止【${moment(timeNow).format('MM月DD日 HH时mm分')}】,有${offArr.length}个设备掉线:\n` |
|
|
|
let text = `【${corUser[0].username}】账号下的设备,截止【${moment(timeNow).format('MM月DD日 HH时mm分')}】,有${offArr.length}个设备掉线:\n` |
|
|
|
text += offArr.map(o => `【${o.name}】于【${o.time}】掉线,`).join('\n') |
|
|
|
text += `\n请及时处理!` |
|
|
|
await pushByEmail({ |
|
|
@ -133,10 +134,10 @@ module.exports = function (app, opts) { |
|
|
|
} else if (c.pushWay == 'phone') { |
|
|
|
// 短信
|
|
|
|
let templateParam = { |
|
|
|
name: corUser[0].namePresent, |
|
|
|
name: corUser[0].username, |
|
|
|
} |
|
|
|
let useTempCode = 'SMS_247900122' |
|
|
|
// let text = `【${corUser[0].namePresent}】账号下的`
|
|
|
|
// let text = `【${corUser[0].username}】账号下的`
|
|
|
|
if (offArr.length == 1) { |
|
|
|
// text += `【${offArr[0].name}】离线,请及时处理!【${moment(offArr[0].time).format('MM月DD日 HH时mm分')}】`
|
|
|
|
templateParam.deviceName = `【${offArr[0].name}】` |
|
|
@ -191,7 +192,7 @@ module.exports = function (app, opts) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let text = `【${corUser[0].namePresent}】账号下的设备:\n` |
|
|
|
let text = `【${corUser[0].username}】账号下的设备:\n` |
|
|
|
text += onArr.map(o => `【${o.name}】于【${moment(o.offTime).format('MM月DD日HH时mm分')}】掉线,【${moment(o.time).format('MM月DD日HH时mm分')}】已恢复`).join('\n') |
|
|
|
await pushByEmail({ |
|
|
|
email: receiver, |
|
|
@ -201,9 +202,9 @@ module.exports = function (app, opts) { |
|
|
|
await models.CameraStatusPushLog.create({ ...logData, pushWay: 'email', noticeWay: ['online'], camera: onArr.map(o => o.cameraId) }) |
|
|
|
} else if (c.pushWay == 'phone') { |
|
|
|
// 短信
|
|
|
|
// let text = `【${corUser[0].namePresent}】账号下的`
|
|
|
|
// let text = `【${corUser[0].username}】账号下的`
|
|
|
|
let templateParam = { |
|
|
|
name: corUser[0].namePresent, |
|
|
|
name: corUser[0].username, |
|
|
|
} |
|
|
|
let useTempCode = 'SMS_247820204' |
|
|
|
if (onArr.length == 1) { |
|
|
@ -245,6 +246,7 @@ module.exports = function (app, opts) { |
|
|
|
interval: '* */5 * * * *', |
|
|
|
// interval: '*/10 * * * * *', // dev
|
|
|
|
immediate: false, |
|
|
|
proRun: false, |
|
|
|
proRun: true, |
|
|
|
}, |
|
|
|
async () => { |
|
|
@ -258,6 +260,7 @@ module.exports = function (app, opts) { |
|
|
|
noticeWay: { |
|
|
|
$contains: ['timing'] |
|
|
|
}, |
|
|
|
// !!! 此时此刻
|
|
|
|
timing: moment(timeNow).format('HH:mm') |
|
|
|
}, |
|
|
|
include: [ |
|
|
@ -321,7 +324,7 @@ module.exports = function (app, opts) { |
|
|
|
group: ['cameraId'], |
|
|
|
}) |
|
|
|
if (offlineTimeRes.length) { |
|
|
|
let text = `【${corUser[0].namePresent}】账号下的设备,截止${moment(timeNow).format('MM月DD日 HH时mm分')},有${offlineRes.length}个设备掉线:\n` |
|
|
|
let text = `【${corUser[0].username}】账号下的设备,截止${moment(timeNow).format('MM月DD日 HH时mm分')},有${offlineRes.length}个设备掉线:\n` |
|
|
|
text += offlineTimeRes.map(o => { |
|
|
|
let corCamera = offlineRes.find(c => c.id == o.cameraId) |
|
|
|
if (corCamera) { |
|
|
@ -339,15 +342,15 @@ module.exports = function (app, opts) { |
|
|
|
} |
|
|
|
} else if (c.pushWay == 'phone') { |
|
|
|
// 短信
|
|
|
|
// let text = `【${corUser[0].namePresent}】账号下截止${moment(timeNow).format('YYYY年MM月DD日 HH时')},有${offlineRes.length}个设备掉线,请及时处理!`
|
|
|
|
// let text = `【${corUser[0].username}】账号下截止${moment(timeNow).format('YYYY年MM月DD日 HH时')},有${offlineRes.length}个设备掉线,请及时处理!`
|
|
|
|
await pushBySms({ |
|
|
|
phone: receiver, |
|
|
|
templateCode: 'SMS_247785195', |
|
|
|
templateParam: JSON.stringify({ |
|
|
|
name: corUser[0].namePresent, |
|
|
|
templateCode: 'SMS_248095009', |
|
|
|
templateParam: { |
|
|
|
name: corUser[0].username, |
|
|
|
time: moment(timeNow).format('YYYY年MM月DD日 HH时'), |
|
|
|
deviceCount: offlineRes.length, |
|
|
|
}), |
|
|
|
}, |
|
|
|
}) |
|
|
|
await models.CameraStatusPushLog.create({ ...logData, pushWay: 'phone', noticeWay: ['timing'] }) |
|
|
|
} |
|
|
|