|
|
|
module.exports = function (app, opts) {
|
|
|
|
async function getGbCameraLevel3ByStreamId ({ streamId }) {
|
|
|
|
const { models } = app.fs.dc
|
|
|
|
if (!streamId) {
|
|
|
|
let errMsg = '参数错误'
|
|
|
|
throw errMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
const streamIdArr = [streamId]
|
|
|
|
|
|
|
|
const findChild = async (streamIdArr) => {
|
|
|
|
const childRes = await models.GbCamera.findAll({
|
|
|
|
where: {
|
|
|
|
parent: { $in: streamIdArr },
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (!childRes.length || childRes.some(c => c.level == 2)) {
|
|
|
|
return childRes
|
|
|
|
} else {
|
|
|
|
const nextLevelStreamIds = childRes.map(level => level.streamid)
|
|
|
|
return findChild(nextLevelStreamIds)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const cameraRes = await findChild(streamIdArr)
|
|
|
|
|
|
|
|
return cameraRes
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getGbCameraLevel1ByStreamId ({ streamId, where = {} }) {
|
|
|
|
const { models } = app.fs.dc
|
|
|
|
if (!streamId) {
|
|
|
|
let errMsg = '参数错误'
|
|
|
|
throw errMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
const findParent = async (streamId) => {
|
|
|
|
const parentRes = await models.GbCamera.findOne({
|
|
|
|
where: {
|
|
|
|
streamid: streamId,
|
|
|
|
...where
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (!parentRes || parentRes.level == 0) {
|
|
|
|
return parentRes
|
|
|
|
} if (!parentRes.parent) {
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
const lastLevelStreamId = parentRes.parent
|
|
|
|
return findParent(lastLevelStreamId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const deviceRes = await findParent(streamId)
|
|
|
|
|
|
|
|
return deviceRes
|
|
|
|
}
|
|
|
|
|
|
|
|
async function verifyYingshiInfo ({ serialNo } = {}) {
|
|
|
|
const { varifyYingshiBelongSecretBySerialNo } = app.fs.utils
|
|
|
|
const beloneSecret = await varifyYingshiBelongSecretBySerialNo(serialNo)
|
|
|
|
if (!beloneSecret) {
|
|
|
|
let errMsg = '请联系管理员核验或新增萤石云权限'
|
|
|
|
throw errMsg
|
|
|
|
}
|
|
|
|
return beloneSecret
|
|
|
|
}
|
|
|
|
|
|
|
|
async function verifyIpcInfo ({ serialNo } = {}) {
|
|
|
|
const { models } = app.fs.dc
|
|
|
|
const gbCameraRes = await models.GbCamera.findOne({
|
|
|
|
where: {
|
|
|
|
streamid: serialNo,
|
|
|
|
// ipctype: 'ipc'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (!gbCameraRes) {
|
|
|
|
let errMsg = '没有找到已接入的 IPC 服务信息'
|
|
|
|
throw errMsg
|
|
|
|
}
|
|
|
|
return gbCameraRes.dataValues
|
|
|
|
}
|
|
|
|
|
|
|
|
async function verifyCascadeInfo ({ sip } = {}) {
|
|
|
|
const { models } = app.fs.dc
|
|
|
|
const gbCameraRes = await models.GbCamera.findOne({
|
|
|
|
where: {
|
|
|
|
sipip: sip,
|
|
|
|
level: 0,
|
|
|
|
ipctype: '级联'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (!gbCameraRes) {
|
|
|
|
let errMsg = '没有找到已接入的级联摄像头服务信息'
|
|
|
|
throw errMsg
|
|
|
|
}
|
|
|
|
return gbCameraRes.dataValues
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
getGbCameraLevel1ByStreamId,
|
|
|
|
getGbCameraLevel3ByStreamId,
|
|
|
|
verifyYingshiInfo,
|
|
|
|
verifyIpcInfo,
|
|
|
|
verifyCascadeInfo,
|
|
|
|
}
|
|
|
|
}
|