|
@ -5,7 +5,7 @@ module.exports = function (app, opts) { |
|
|
{ |
|
|
{ |
|
|
interval: '0 */15 * * * *', |
|
|
interval: '0 */15 * * * *', |
|
|
// interval: '* */1 * * * *',
|
|
|
// interval: '* */1 * * * *',
|
|
|
// interval: '* */5 * * * *',
|
|
|
// interval: '*/5 * * * * *',
|
|
|
immediate: false, |
|
|
immediate: false, |
|
|
proRun: true, |
|
|
proRun: true, |
|
|
}, |
|
|
}, |
|
@ -40,10 +40,10 @@ module.exports = function (app, opts) { |
|
|
const offlineStatusRes = await models.CameraStatusOfflineLog.findAll({ |
|
|
const offlineStatusRes = await models.CameraStatusOfflineLog.findAll({ |
|
|
where: { |
|
|
where: { |
|
|
cameraId: { $in: cameraIds }, |
|
|
cameraId: { $in: cameraIds }, |
|
|
|
|
|
// !!! 時間限制
|
|
|
// time: {
|
|
|
time: { |
|
|
// $between: [moment(timeNow).subtract(15, 'minutes').format(), timeNow]
|
|
|
$between: [moment(timeNow).subtract(15, 'minutes').format(), timeNow] |
|
|
// }
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
include: [{ |
|
|
include: [{ |
|
|
model: models.Camera, |
|
|
model: models.Camera, |
|
@ -121,22 +121,22 @@ module.exports = function (app, opts) { |
|
|
} |
|
|
} |
|
|
// 离线推送
|
|
|
// 离线推送
|
|
|
console.log('object'); |
|
|
console.log('object'); |
|
|
if (offArr.length && c.noticeWay && c.noticeWay.includes('offline')) { |
|
|
if (offArr.length && c.noticeWay && c.noticeWay.includes('offline') && receiver.length) { |
|
|
if (c.pushWay == 'email') { |
|
|
if (c.pushWay == 'email') { |
|
|
// 邮件
|
|
|
// 邮件
|
|
|
let text = `【${corUser[0].username}】账号下的设备,截止【${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}】于【${moment(o.time).format('MM月DD日 HH时mm分')}】掉线,`).join('\n') |
|
|
text += offArr.map(o => `【${o.name}】于【${moment(o.time).format('MM月DD日 HH时mm分')}】掉线,`).join('\n') |
|
|
text += `\n请及时处理!` |
|
|
text += `\n请及时处理!` |
|
|
await pushByEmail({ |
|
|
// await pushByEmail({
|
|
|
email: receiver, |
|
|
// email: receiver,
|
|
|
title: '尚视设备离线通知', |
|
|
// title: '尚视设备离线通知',
|
|
|
text, |
|
|
// text,
|
|
|
}) |
|
|
// })
|
|
|
await models.CameraStatusPushLog.create({ ...logData, pushWay: 'email', noticeWay: ['offline'], camera: offArr.map(o => o.cameraId) }) |
|
|
// await models.CameraStatusPushLog.create({ ...logData, pushWay: 'email', noticeWay: ['offline'], camera: offArr.map(o => o.cameraId) })
|
|
|
} else if (c.pushWay == 'phone') { |
|
|
} else if (c.pushWay == 'phone') { |
|
|
// 短信
|
|
|
// 短信
|
|
|
let templateParam = { |
|
|
let templateParam = { |
|
|
name: corUser[0].username, |
|
|
name: `【${corUser[0].username}】`, |
|
|
} |
|
|
} |
|
|
let useTempCode = 'SMS_248205074' |
|
|
let useTempCode = 'SMS_248205074' |
|
|
// let text = `【${corUser[0].username}】账号下的`
|
|
|
// let text = `【${corUser[0].username}】账号下的`
|
|
@ -167,7 +167,7 @@ module.exports = function (app, opts) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 上线推送
|
|
|
// 上线推送
|
|
|
if (onArr.length && c.noticeWay && c.noticeWay.includes('online')) { |
|
|
if (onArr.length && c.noticeWay && c.noticeWay.includes('online') && receiver.length) { |
|
|
if (c.pushWay == 'email') { |
|
|
if (c.pushWay == 'email') { |
|
|
// 邮件
|
|
|
// 邮件
|
|
|
const outTimeCameraOff = onArr.filter(a => !a.offTime) |
|
|
const outTimeCameraOff = onArr.filter(a => !a.offTime) |
|
@ -196,19 +196,19 @@ module.exports = function (app, opts) { |
|
|
|
|
|
|
|
|
let text = `【${corUser[0].username}】账号下的设备:\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') |
|
|
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({ |
|
|
// await pushByEmail({
|
|
|
email: receiver, |
|
|
// email: receiver,
|
|
|
title: '尚视设备上线通知', |
|
|
// title: '尚视设备上线通知',
|
|
|
text, |
|
|
// text,
|
|
|
}) |
|
|
// })
|
|
|
await models.CameraStatusPushLog.create({ ...logData, pushWay: 'email', noticeWay: ['online'], camera: onArr.map(o => o.cameraId) }) |
|
|
// await models.CameraStatusPushLog.create({ ...logData, pushWay: 'email', noticeWay: ['online'], camera: onArr.map(o => o.cameraId) })
|
|
|
} else if (c.pushWay == 'phone') { |
|
|
} else if (c.pushWay == 'phone') { |
|
|
// 短信
|
|
|
// 短信
|
|
|
// let text = `【${corUser[0].username}】账号下的`
|
|
|
// let text = `【${corUser[0].username}】账号下的`
|
|
|
let templateParam = { |
|
|
let templateParam = { |
|
|
name: corUser[0].username, |
|
|
name: `【${corUser[0].username}】`, |
|
|
} |
|
|
} |
|
|
let useTempCode = 'SMS_248120080' |
|
|
let useTempCode = 'SMS_248250073' |
|
|
if (onArr.length == 1) { |
|
|
if (onArr.length == 1) { |
|
|
// text += `【${onArr[0].name}】已恢复上线,请及时处理!【${moment(onArr[0].time).format('MM月DD日 HH时mm分')}】`
|
|
|
// text += `【${onArr[0].name}】已恢复上线,请及时处理!【${moment(onArr[0].time).format('MM月DD日 HH时mm分')}】`
|
|
|
templateParam.deviceName = `【${onArr[0].name}】` |
|
|
templateParam.deviceName = `【${onArr[0].name}】` |
|
@ -216,15 +216,17 @@ module.exports = function (app, opts) { |
|
|
} else { |
|
|
} else { |
|
|
let text = '' |
|
|
let text = '' |
|
|
text += onArr.map(o => `【${o.name}】`).join('') |
|
|
text += onArr.map(o => `【${o.name}】`).join('') |
|
|
|
|
|
let timeRange = `【${moment().format('MM月DD日HH时mm分')}-${moment(timeNow).subtract(15, 'minutes').format('MM月DD日HH时mm分')}】!` |
|
|
if (text.length > 35) { |
|
|
if (text.length > 35) { |
|
|
text = text.substring(0, 35) + '...' |
|
|
text = text.substring(0, 35) + '...' |
|
|
// text += `等${onArr.length}个摄像头已恢复上线!`
|
|
|
// text += `等${onArr.length}个摄像头已恢复上线!`
|
|
|
templateParam.deviceCount = onArr.length |
|
|
templateParam.deviceCount = onArr.length |
|
|
useTempCode = 'SMS_248120080' |
|
|
useTempCode = 'SMS_248120080' |
|
|
|
|
|
templateParam.timeRange = timeRange |
|
|
|
|
|
} else { |
|
|
|
|
|
templateParam.date = timeRange |
|
|
} |
|
|
} |
|
|
templateParam.deviceName = text |
|
|
templateParam.deviceName = text |
|
|
// text += `【${moment().format('MM月DD日HH时mm分')}-${moment(timeNow).subtract(15, 'minutes').format('MM月DD日HH时mm分')}】!`
|
|
|
|
|
|
templateParam.timeRange = `【${moment().format('MM月DD日HH时mm分')}-${moment(timeNow).subtract(15, 'minutes').format('MM月DD日HH时mm分')}】!` |
|
|
|
|
|
} |
|
|
} |
|
|
await pushBySms({ |
|
|
await pushBySms({ |
|
|
phone: receiver, |
|
|
phone: receiver, |
|
@ -248,7 +250,7 @@ module.exports = function (app, opts) { |
|
|
interval: '0 */5 * * * *', |
|
|
interval: '0 */5 * * * *', |
|
|
// interval: '*/10 * * * * *', // dev
|
|
|
// interval: '*/10 * * * * *', // dev
|
|
|
immediate: false, |
|
|
immediate: false, |
|
|
immediate: true, // dev
|
|
|
// immediate: true, // dev
|
|
|
proRun: true, |
|
|
proRun: true, |
|
|
}, |
|
|
}, |
|
|
async () => { |
|
|
async () => { |
|
|