diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js index 2f0ee29..a280496 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js @@ -1,5 +1,7 @@ 'use strict'; +const moment = require('moment') + async function createYingshi (ctx) { let errMsg = '添加萤石摄像头失败' try { @@ -7,12 +9,14 @@ async function createYingshi (ctx) { const { userId, token } = ctx.fs.api const { utils: { token4yingshi } } = ctx.app.fs - const { id, name, cloudControl, highDefinition, memoryCard, - voice, kindId, abilityId, rtmp, serialNo } = ctx.request.body; + const { + id, name, cloudControl, highDefinition, memoryCard, + voice, kindId, abilityId, rtmp, serialNo, longitude, latitude, + } = ctx.request.body; const serialNo_ = String(serialNo).toUpperCase() const secretRes = await models.SecretYingshi.findAll() - let cameraBeloneSecret = null + let cameraBeloneSecretId = null for (let s of secretRes) { const tokenYingshi = await token4yingshi(s.dataValues) // 检测设备所属 @@ -28,7 +32,7 @@ async function createYingshi (ctx) { } } - if (!cameraBeloneSecret) { + if (!cameraBeloneSecretId) { errMsg = '请联系管理员核验或新增萤石云权限' throw errMsg } @@ -36,17 +40,19 @@ async function createYingshi (ctx) { let storageData = { type: 'yingshi', name, cloudControl, highDefinition, memoryCard, voice, longitude, latitude, kindId, abilityId, rtmp, + yingshiSecretId: cameraBeloneSecretId } if (id) { - storageData.createTime = moment().format() - storageData.createUserId = userId await models.Camera.update(storageData, { where: { id, } }) } else { + storageData.createTime = moment().format() + storageData.createUserId = userId + storageData.forbidden = false await models.Camera.create(storageData) } @@ -60,6 +66,75 @@ async function createYingshi (ctx) { } } +async function getNvrSteam (ctx) { + try { + const { models } = ctx.fs.dc + const { userId, token } = ctx.fs.api + + ctx.status = 200; + ctx.body = {} + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = {} + } +} + +async function createNvrCamera (ctx) { + try { + const { models } = ctx.fs.dc + const { userId, token } = ctx.fs.api + + ctx.status = 200; + ctx.body = {} + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = {} + } +} + +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, + voice, longitude, latitude, rtmp, + serialNo, kindId, abilityId, + } = ctx.request.body; + + let storageData = { + type: 'ipc', name, cloudControl, memoryCard, + voice, longitude, latitude, rtmp, + serialNo, kindId, abilityId, + } + + if (id) { + await models.Camera.update(storageData, { + where: { + id, + } + }) + } else { + storageData.createTime = moment().format() + storageData.createUserId = userId + storageData.forbidden = false + await models.Camera.create(storageData) + } + ctx.status = 204; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = {} + } +} + module.exports = { - createYingshi + createYingshi, + getNvrSteam, + createNvrCamera, + createIpcCamera, }; \ No newline at end of file diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js index 12d3558..26f4f46 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js @@ -236,6 +236,36 @@ async function del (ctx) { } } +async function getAbility (ctx) { + try { + const { models } = ctx.fs.dc; + + const abilityRes = await models.CameraAbility.findAll() + + ctx.status = 200; + ctx.body = abilityRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = {} + } +} + +async function getKind (ctx) { + try { + const { models } = ctx.fs.dc; + + const kindRes = await models.CameraKind.findAll() + + ctx.status = 200; + ctx.body = kindRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = {} + } +} + module.exports = { getCameraProject, getCamera, @@ -243,4 +273,6 @@ module.exports = { detail, banned, del, + getAbility, + getKind, }; \ No newline at end of file diff --git a/code/VideoAccess-VCMP/api/app/lib/models/camera.js b/code/VideoAccess-VCMP/api/app/lib/models/camera.js index cbdcedb..ab32d09 100644 --- a/code/VideoAccess-VCMP/api/app/lib/models/camera.js +++ b/code/VideoAccess-VCMP/api/app/lib/models/camera.js @@ -157,7 +157,7 @@ module.exports = dc => { forbidden: { type: DataTypes.BOOLEAN, allowNull: false, - defaultValue: null, + defaultValue: false, comment: "是否禁用", primaryKey: false, field: "forbidden", @@ -184,7 +184,7 @@ module.exports = dc => { delete: { type: DataTypes.BOOLEAN, allowNull: false, - defaultValue: null, + defaultValue: false, comment: "是否彻底删除", primaryKey: false, field: "delete", @@ -246,6 +246,19 @@ module.exports = dc => { key: "id", model: "cameraAbility" } + }, + yingshiSecretId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "yingshi_secret_id", + autoIncrement: false, + references: { + key: "id", + model: "secretYingshi" + } } }, { tableName: "camera", diff --git a/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js b/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js index 088ed86..9157725 100644 --- a/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js @@ -6,8 +6,8 @@ const cameraCreate = require('../../controllers/camera/create') module.exports = function (app, router, opts) { // 摄像头创建 - app.fs.api.logAttr['POST/camera/yingshi'] = { content: '创建萤石摄像头', visible: false }; - router.post('/camera/yingshi', cameraCreate.createYingshi); + app.fs.api.logAttr['POST/camera/create/yingshi'] = { content: '创建萤石摄像头', visible: false }; + router.post('/camera/create/yingshi', cameraCreate.createYingshi); // 摄像头创建 END @@ -28,4 +28,10 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['DEL/camera'] = { content: '删除摄像头', visible: false }; router.delete('/camera', camera.del); + + app.fs.api.logAttr['GET/camera/ability'] = { content: '获取摄像头能力列表', visible: false }; + router.get('/camera/ability', camera.getAbility); + + app.fs.api.logAttr['GET/camera/kind'] = { content: '获取摄像头种类列表', visible: false }; + router.get('/camera/kind', camera.getKind); }; diff --git a/code/VideoAccess-VCMP/api/app/lib/service/socket.js b/code/VideoAccess-VCMP/api/app/lib/service/socket.js index e15f6ef..fca63f0 100644 --- a/code/VideoAccess-VCMP/api/app/lib/service/socket.js +++ b/code/VideoAccess-VCMP/api/app/lib/service/socket.js @@ -3,9 +3,9 @@ module.exports = async function factory (app, opts) { app.socket.on('connection', async (socket) => { - console.info('WEB_SOCKET ' + socket.handshake.query.token + ' 已连接:' + socket.id); + // console.info('WEB_SOCKET ' + socket.handshake.query.token + ' 已连接:' + socket.id); socket.on('disconnecting', async (reason) => { - console.info('WEB_SOCKET ' + socket.handshake.query.token + ' 已断开连接:' + reason); + // console.info('WEB_SOCKET ' + socket.handshake.query.token + ' 已断开连接:' + reason); }) })