yuan_yi
3 years ago
10 changed files with 360 additions and 89 deletions
@ -0,0 +1,77 @@ |
|||||
|
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 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 { |
||||
|
getGbCameraLevel3ByStreamId, |
||||
|
verifyYingshiInfo, |
||||
|
verifyIpcInfo, |
||||
|
verifyCascadeInfo, |
||||
|
} |
||||
|
} |
@ -1,33 +0,0 @@ |
|||||
module.exports = function (app, opts) { |
|
||||
async function getCameraLevel3ByStreamId ({ streamId, errMsg = '' }) { |
|
||||
const { models } = app.fs.dc |
|
||||
if (!streamId) { |
|
||||
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 |
|
||||
} |
|
||||
|
|
||||
return { |
|
||||
getCameraLevel3ByStreamId |
|
||||
} |
|
||||
} |
|
Loading…
Reference in new issue