Browse Source

短信模板

release_1.1.2
巴林闲侠 3 years ago
parent
commit
0380240df0
  1. 52
      code/VideoAccess-VCMP/api/app/lib/schedule/cameraStatePush.js

52
code/VideoAccess-VCMP/api/app/lib/schedule/cameraStatePush.js

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

Loading…
Cancel
Save