6 changed files with 270 additions and 9 deletions
@ -0,0 +1,142 @@ |
|||||
|
/* eslint-disable*/ |
||||
|
'use strict'; |
||||
|
|
||||
|
module.exports = dc => { |
||||
|
const DataTypes = dc.ORM; |
||||
|
const sequelize = dc.orm; |
||||
|
const GbCamera = sequelize.define("gbCamera", { |
||||
|
id: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: true, |
||||
|
field: "id", |
||||
|
autoIncrement: true, |
||||
|
unique: "gbcamera_id_uindex" |
||||
|
}, |
||||
|
level: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "level", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
parent: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "parent", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
streamid: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "streamid", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
registerTime: { |
||||
|
type: DataTypes.DATEONLY, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "registerTime", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
updateTime: { |
||||
|
type: DataTypes.DATEONLY, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "updateTime", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
online: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "online", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
manufactuer: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "manufactuer", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
model: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "model", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
civilCode: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "civilCode", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
adddress: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "adddress", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
name: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "name", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
addr: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "Addr", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
sipip: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "Sipip", |
||||
|
autoIncrement: false |
||||
|
} |
||||
|
}, { |
||||
|
tableName: "gbCamera", |
||||
|
comment: "", |
||||
|
indexes: [] |
||||
|
}); |
||||
|
dc.models.GbCamera = GbCamera; |
||||
|
return GbCamera; |
||||
|
}; |
@ -0,0 +1,33 @@ |
|||||
|
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