Browse Source

Merge branch 'dev_trial' of https://gitea.anxinyun.cn/free-sun/FS-IOT into dev_trial

release_1.1.2
wenlele 2 years ago
parent
commit
b53cd0ae4e
  1. 12
      code/VideoAccess-VCMP/api/app/lib/controllers/status/index.js
  2. 98
      code/VideoAccess-VCMP/api/app/lib/controllers/status/push.js
  3. 2
      code/VideoAccess-VCMP/api/app/lib/routes/status/index.js
  4. 62
      code/VideoAccess-VCMP/api/app/lib/utils/push.js
  5. 35
      code/VideoAccess-VCMP/api/config.js
  6. 2
      code/VideoAccess-VCMP/api/package.json

12
code/VideoAccess-VCMP/api/app/lib/controllers/status/index.js

@ -73,10 +73,20 @@ async function get (ctx) {
} }
if (paraphraseCustom) { if (paraphraseCustom) {
if (paraphraseCustom === 'true') { if (paraphraseCustom === 'true') {
findOption.where.paraphraseCustom = null findOption.where.paraphraseCustom = {
$or: [{
$eq: null
}, {
$eq: ''
}]
}
} else if (paraphraseCustom === 'false') { } else if (paraphraseCustom === 'false') {
findOption.where.paraphraseCustom = { findOption.where.paraphraseCustom = {
$and: [{
$ne: null $ne: null
}, {
$ne: ''
}]
} }
} }
} }

98
code/VideoAccess-VCMP/api/app/lib/controllers/status/push.js

@ -19,7 +19,7 @@ async function edit (ctx) {
name, pushWay, noticeWay, timing name, pushWay, noticeWay, timing
} }
if (configId) { if (configId) {
const configRes = await models.CameraStatusConfig.findOne({ const configRes = await models.CameraStatusPushConfig.findOne({
where: { where: {
id: configId id: configId
} }
@ -93,30 +93,54 @@ async function get (ctx) {
const sequelize = ctx.fs.dc.ORM; const sequelize = ctx.fs.dc.ORM;
let findOption = { let findOption = {
attributes: {
include: [
[sequelize.fn('COUNT', sequelize.col('cameraStatusPushMonitors.id')), 'monitorCount'],
[sequelize.fn('COUNT', sequelize.col('cameraStatusPushLogs.id')), 'logCount']
],
},
where: {}, where: {},
order: [ order: [
[orderBy || 'id', orderDirection || 'DESC'] [orderBy || 'id', orderDirection || 'DESC']
]
}
if (limit) {
findOption.limit = limit
}
if (page && limit) {
findOption.offset = page * limit
}
if (keyword) {
findOption.where['$or'] = {
name: {
$like: `%${keyword}%`
},
}
}
const configLimitRes = await models.CameraStatusPushConfig.findAll(findOption)
delete findOption.limit
delete findOption.offset
const configIds = configLimitRes.map(c => c.id)
findOption.where.id = { $in: configIds }
findOption.attributes = {
include: [
[sequelize.fn('COUNT', sequelize.col('cameraStatusPushMonitors.id')), 'monitorCount'],
[sequelize.fn('COUNT', sequelize.col('cameraStatusPushLogs.id')), 'logCount']
], ],
distinct: true, }
subQuery: false, findOption.distinct = true
group: [ findOption.subQuery = false
findOption.group = [
'cameraStatusPushConfig.id', 'cameraStatusPushConfig.id',
'cameraStatusPushMonitors.id', 'cameraStatusPushMonitors.id',
'cameraStatusPushLogs.id', 'cameraStatusPushLogs.id',
'cameraStatusPushReceivers.id', 'cameraStatusPushReceivers.id',
], ]
include: [ findOption.order = [
[orderBy || 'id', orderDirection || 'DESC']
]
findOption.include = [
{ {
model: models.CameraStatusPushMonitor, model: models.CameraStatusPushMonitor,
attributes: ['cameraId'], attributes: ['cameraId'],
required: false, required: false,
duplicating: true duplicating: true,
}, },
{ {
model: models.CameraStatusPushLog, model: models.CameraStatusPushLog,
@ -130,26 +154,23 @@ async function get (ctx) {
duplicating: false, duplicating: false,
required: false, required: false,
}, },
], ]
}
if (limit) {
findOption.limit = limit
}
if (page && limit) {
findOption.offset = page * limit
}
if (keyword) {
findOption.where['$or'] = {
name: {
$like: `%${keyword}%`
},
}
}
const configRes = await models.CameraStatusPushConfig.findAll(findOption) const configRes = await models.CameraStatusPushConfig.findAll(findOption)
delete findOption.attributes
delete findOption.group
delete findOption.order
delete findOption.distinct
delete findOption.subQuery
delete findOption.include
delete findOption.where.id
const count = await models.CameraStatusPushConfig.count(findOption)
ctx.status = 200; ctx.status = 200;
ctx.body = configRes ctx.body = {
count: count,
rows: configRes
}
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
@ -255,11 +276,11 @@ async function copy (ctx) {
let copyConfig = JSON.parse(JSON.stringify(configRes.dataValues)) let copyConfig = JSON.parse(JSON.stringify(configRes.dataValues))
let returnConfig = JSON.parse(JSON.stringify(configRes.dataValues)) let returnConfig = JSON.parse(JSON.stringify(configRes.dataValues))
delete copyConfig.id delete copyConfig.id
delete copyConfig.id
let cameraStatusPushMonitors = copyConfig.cameraStatusPushMonitors let cameraStatusPushMonitors = copyConfig.cameraStatusPushMonitors
let cameraStatusPushReceiver = copyConfig.cameraStatusPushReceivers let cameraStatusPushReceiver = copyConfig.cameraStatusPushReceivers
delete copyConfig.cameraStatusPushMonitors delete copyConfig.cameraStatusPushMonitors
delete copyConfig.cameraStatusPushReceivers delete copyConfig.cameraStatusPushReceivers
copyConfig.name += '-副本'
copyConfig.createUser = userId copyConfig.createUser = userId
let newConfig = await models.CameraStatusPushConfig.create(copyConfig, { let newConfig = await models.CameraStatusPushConfig.create(copyConfig, {
transaction transaction
@ -316,6 +337,23 @@ async function pushLog (ctx) {
order: [['time', 'DESC']], order: [['time', 'DESC']],
}) })
let cameraIds = new Set()
for (let lr of logRes) {
for (let c of lr.camera) {
cameraIds.add(c)
}
}
let cameraRes = await models.Camera.findAll({
attributes: ['id', 'name'],
where: {
id: { $in: Array.from(cameraIds) }
}
})
for (let lr of logRes) {
let camera = cameraRes.filter(c => lr.camera.some(lrc => lrc == c.id))
lr.camera = camera
}
ctx.status = 200; ctx.status = 200;
ctx.body = logRes ctx.body = logRes
} catch (error) { } catch (error) {

2
code/VideoAccess-VCMP/api/app/lib/routes/status/index.js

@ -24,7 +24,7 @@ module.exports = function (app, router, opts) {
// 信鸽推送 // 信鸽推送
app.fs.api.logAttr['PUT/status/push'] = { content: '编辑推送配置', visible: false }; app.fs.api.logAttr['PUT/status/push'] = { content: '编辑推送配置', visible: false };
router.put('/sasdtatus/push', push.edit); router.put('/status/push', push.edit);
app.fs.api.logAttr['GET/status/push'] = { content: '获取推送配置', visible: false }; app.fs.api.logAttr['GET/status/push'] = { content: '获取推送配置', visible: false };
router.get('/status/push', push.get); router.get('/status/push', push.get);

62
code/VideoAccess-VCMP/api/app/lib/utils/push.js

@ -0,0 +1,62 @@
'use strict';
const moment = require('moment')
const Core = require('@alicloud/pop-core');
const nodemailer = require('nodemailer')
module.exports = function (app, opts) {
const pushBySms = async ({ phone = [] } = {}) => {
try {
if (phone.length) {
const client = new Core({
accessKeyId: opts.sms.accessKey,
accessKeySecret: opts.sms.accessSecret,
endpoint: 'http://dysmsapi.aliyuncs.com',//固定
apiVersion: '2017-05-25'//固定
});
const SendSmsRes = await client.request('SendSms', {
"PhoneNumbers": `${phone.join(',')}`,//接收短信的手机号码。
"SignName": "安心云",//短信签名名称。必须是已添加、并通过审核的短信签名。
"TemplateCode": "SMS_216403225",//短信模板ID。必须是已添加、并通过审核的短信签名;且发送国际/港澳台消息时,请使用国际/港澳台短信模版。
"TemplateParam": `{"code":${code}}`//短信模板变量对应的实际值,JSON格式。
}, {
method: 'POST'
});
return SendSmsRes
}
} catch (error) {
throw error
}
}
const pushByEmail = async () => {
try {
let transporter = nodemailer.createTransport({
host: opts.email.host,
port: opts.email.port,
secure: true,
auth: {
user: opts.email.sender.address,
pass: opts.email.sender.password,
}
});
// send mail with defined transport object
await transporter.sendMail({
from: 'grazing-stars@qq.com', // sender address
to: email, // list of receivers 逗号分隔字符串
subject: title, // Subject line
text: text, // plain text body
html: html, // html body
attachments: attachments
});
} catch (error) {
throw error
}
}
return {
pushByEmail,
pushBySms,
}
}

35
code/VideoAccess-VCMP/api/config.js

@ -35,20 +35,29 @@ const flags = args.parse(process.argv);
const IOT_VIDEO_ACCESS_DB = process.env.IOT_VIDEO_ACCESS_DB || flags.pg; const IOT_VIDEO_ACCESS_DB = process.env.IOT_VIDEO_ACCESS_DB || flags.pg;
const IOT_VIDEO_ACCESS_LOCAL_SVR_ORIGIN = process.env.IOT_VIDEO_ACCESS_LOCAL_SVR_ORIGIN || flags.fileHost; const IOT_VIDEO_ACCESS_LOCAL_SVR_ORIGIN = process.env.IOT_VIDEO_ACCESS_LOCAL_SVR_ORIGIN || flags.fileHost;
// Redis 参数
const IOTA_REDIS_SERVER_HOST = process.env.IOTA_REDIS_SERVER_HOST || flags.redisHost || "localhost";//redis IP const IOTA_REDIS_SERVER_HOST = process.env.IOTA_REDIS_SERVER_HOST || flags.redisHost || "localhost";//redis IP
const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redisPort || "6379";//redis 端口 const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redisPort || "6379";//redis 端口
const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码 const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码
// 鉴权 api
const IOT_AUTH_API = process.env.IOT_AUTH_API || flags.iotAuthApi; const IOT_AUTH_API = process.env.IOT_AUTH_API || flags.iotAuthApi;
// 安心云api
const AXY_API_URL = process.env.AXY_API_URL || flags.axyApiUrl; const AXY_API_URL = process.env.AXY_API_URL || flags.axyApiUrl;
// 高德地图的参数
const GOD_URL = process.env.GOD_URL || flags.godUrl || 'https://restapi.amap.com/v3'; const GOD_URL = process.env.GOD_URL || flags.godUrl || 'https://restapi.amap.com/v3';
const GOD_KEY = process.env.GOD_KEY || flags.godKey; const GOD_KEY = process.env.GOD_KEY || flags.godKey;
// 萤石服务的地址
const YINGSHI_URL = process.env.YINGSHI_URL || flags.yingshiUrl || 'https://open.ys7.com/api'; const YINGSHI_URL = process.env.YINGSHI_URL || flags.yingshiUrl || 'https://open.ys7.com/api';
const MQTT_VIDEO_SERVER = process.env.MQTT_VIDEO_SERVER || flags.mqttVideoServer; // 视频后台服务的地址
const IOT_VIDEO_SERVER_URL = process.env.IOT_VIDEO_SERVER_URL || flags.iotVideoServerUrl const IOT_VIDEO_SERVER_URL = process.env.IOT_VIDEO_SERVER_URL || flags.iotVideoServerUrl
// 视频后台 mqtt 信息推送地址
const MQTT_VIDEO_SERVER = process.env.MQTT_VIDEO_SERVER || flags.mqttVideoServer;
// 几种国标摄像头播放地址前缀
const CAMERA_PLAY_WS_HOST = process.env.CAMERA_PLAY_WS_HOST || flags.cameraPlayWsHost; const CAMERA_PLAY_WS_HOST = process.env.CAMERA_PLAY_WS_HOST || flags.cameraPlayWsHost;
const CAMERA_PLAY_HTTP_FLV_HOST = process.env.CAMERA_PLAY_HTTP_FLV_HOST || flags.cameraPlayHttpFlvHost; const CAMERA_PLAY_HTTP_FLV_HOST = process.env.CAMERA_PLAY_HTTP_FLV_HOST || flags.cameraPlayHttpFlvHost;
const CAMERA_PLAY_HLS_HOST = process.env.CAMERA_PLAY_HLS_HOST || flags.cameraPlayHlsHost; const CAMERA_PLAY_HLS_HOST = process.env.CAMERA_PLAY_HLS_HOST || flags.cameraPlayHlsHost;
@ -100,6 +109,30 @@ const product = {
rtmp: CAMERA_PLAY_RTMP_HOST, rtmp: CAMERA_PLAY_RTMP_HOST,
rtsp: CAMERA_PLAY_RTSP_HOST, rtsp: CAMERA_PLAY_RTSP_HOST,
}, },
sms: {
///阿里云-安心云
accessKey: 'LTAI5tAFdjz7j38aNF2C9Qe8',
accessSecret: '1trYkmiqfBtvZL6BxkNH2uQcQQPs0S'
},
email: {
// enabled: true,
// host: 'smtp.exmail.qq.com',
// port: 465,
// sender: {
// name: '知物云',
// address: 'no-reply@zhiwucloud.com',
// password: 'Zwy123456_'
// },
// enabled: true,
// host: 'smtp.exmail.qq.com',
// port: 465,
// sender: {
// name: '知物云',
// address: 'no-reply@zhiwucloud.com',
// password: 'Zwy123456_'
// }
},
pssaRequest: [ pssaRequest: [
{// name 会作为一个 request 出现在 ctx.app.fs {// name 会作为一个 request 出现在 ctx.app.fs
name: 'authRequest', name: 'authRequest',

2
code/VideoAccess-VCMP/api/package.json

@ -13,6 +13,7 @@
"license": "MIT", "license": "MIT",
"repository": {}, "repository": {},
"dependencies": { "dependencies": {
"@alicloud/pop-core": "^1.7.12",
"@fs/attachment": "^1.0.0", "@fs/attachment": "^1.0.0",
"args": "^3.0.7", "args": "^3.0.7",
"better-xlsx": "^0.7.6", "better-xlsx": "^0.7.6",
@ -25,6 +26,7 @@
"moment": "^2.24.0", "moment": "^2.24.0",
"mqtt": "^4.3.7", "mqtt": "^4.3.7",
"node-schedule": "^2.1.0", "node-schedule": "^2.1.0",
"nodemailer": "^6.7.7",
"path": "^0.12.7", "path": "^0.12.7",
"path-to-regexp": "^3.0.0", "path-to-regexp": "^3.0.0",
"pg": "^7.9.0", "pg": "^7.9.0",

Loading…
Cancel
Save