Browse Source

ipc 摄像头添加

release_0.0.2
yuan_yi 2 years ago
parent
commit
9d1096583e
  1. 92
      code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js
  2. 1
      code/VideoAccess-VCMP/api/app/lib/index.js
  3. 142
      code/VideoAccess-VCMP/api/app/lib/models/gb_camera.js
  4. 9
      code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js
  5. 33
      code/VideoAccess-VCMP/api/app/lib/utils/gbCamera.js
  6. 2
      code/VideoAccess-VCMP/api/sequelize-automate.config.js

92
code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js

@ -67,30 +67,107 @@ async function createYingshi (ctx) {
}
async function getNvrSteam (ctx) {
let errMsg = '获取 NVR 视频流失败'
try {
const { models } = ctx.fs.dc
const { userId, token } = ctx.fs.api
const { streamId } = ctx.query
const { utils: { getCameraLevel3ByStreamId } } = ctx.app.fs
const cameraRes = await getCameraLevel3ByStreamId({ streamId, errMsg })
ctx.status = 200;
ctx.body = {}
ctx.body = cameraRes
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
ctx.body = {
message: errMsg
}
}
}
async function createNvrCamera (ctx) {
let errMsg = '添加 NVR 摄像头失败'
const transaction = await ctx.fs.dc.orm.transaction();
try {
const { models } = ctx.fs.dc
const { userId, token } = ctx.fs.api
const { utils: { getCameraLevel3ByStreamId } } = ctx.app.fs
const data = ctx.request.body
const { data: camera, serialNo } = data
if (!serialNo || !camera) {
errMsg = '参数错误'
throw errMsg
}
ctx.status = 200;
ctx.body = {}
const nvrRes = await models.Nvr.findOne({
where: {
serialNo
}
})
if (!nvrRes) {
errMsg = '尚未添加相应的 NVR 设备'
throw errMsg
}
const addedCameraRes = await models.Camera.findAll({
where: {
nvrId: nvrRes.id
}
})
const allCameraRes = await getCameraLevel3ByStreamId({ streamId: serialNo })
let createData = []
let updateData = []
for (let c of camera) {
const corCamera = allCameraRes.find(ac => ac.streamid == c.streamid)
if (corCamera) {
const addedData = addedCameraRes.find(ac => ac.serialNo == c.streamid)
if (addedData) {
updateData.push({
...addedData.dataValues,
serialNo: c.streamid,
name: c.name,
sip: corCamera.sipip,
cloudControl: c.cloudControl
})
} else {
createData.push({
serialNo: c.streamid,
name: c.name,
sip: corCamera.sipip,
cloudControl: c.cloudControl,
createTime: moment().format(),
createUserId: userId,
forbidden: false,
})
}
} else {
errMsg = '参数错误'
throw errMsg
}
}
if (createData.length) {
await models.Camera.bulkCreate(createData, {
transaction
})
}
if (updateData.length) {
for (let u of updateData) {
await models.Camera.update(u, {
transaction
})
}
}
await transaction.commit();
ctx.status = 204;
} catch (error) {
await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
ctx.body = {
message: errMsg
}
}
}
@ -98,7 +175,6 @@ async function createIpcCamera (ctx) {
try {
const { models } = ctx.fs.dc
const { userId, token } = ctx.fs.api
const { utils: { token4yingshi } } = ctx.app.fs
const {
id, name, cloudControl, memoryCard,

1
code/VideoAccess-VCMP/api/app/lib/index.js

@ -42,5 +42,6 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
require('./models/nvr')(dc);
require('./models/vender')(dc);
require('./models/secret_yingshi')(dc);
require('./models/gb_camera')(dc);
require('./models/ax_project')(dc);
};

142
code/VideoAccess-VCMP/api/app/lib/models/gb_camera.js

@ -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;
};

9
code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js

@ -9,6 +9,15 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['POST/camera/create/yingshi'] = { content: '创建萤石摄像头', visible: false };
router.post('/camera/create/yingshi', cameraCreate.createYingshi);
app.fs.api.logAttr['GET/camera/nvr_stream'] = { content: '获取NVR视频流', visible: false };
router.get('/camera/nvr_stream', cameraCreate.getNvrSteam);
app.fs.api.logAttr['POST/camera/create/nvr'] = { content: '记录NVR摄像头', visible: false };
router.post('/camera/create/nvr', cameraCreate.createNvrCamera);
app.fs.api.logAttr['POST/camera/create/ipc'] = { content: '创建IPC摄像头', visible: false };
router.post('/camera/create/ipc', cameraCreate.createIpcCamera);
// 摄像头创建 END
app.fs.api.logAttr['GET/camera/project'] = { content: '获取摄像头列表及项目绑定信息', visible: false };

33
code/VideoAccess-VCMP/api/app/lib/utils/gbCamera.js

@ -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
}
}

2
code/VideoAccess-VCMP/api/sequelize-automate.config.js

@ -26,7 +26,7 @@ module.exports = {
dir: './app/lib/models', // 指定输出 models 文件的目录
typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义
emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir`
tables: ['secret_yingshi'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性
tables: ['gbCamera'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性
skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性
tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中
ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面

Loading…
Cancel
Save