From b5a95f5b338e1bb8b999d37f7d2b677688639762 Mon Sep 17 00:00:00 2001 From: wenlele Date: Thu, 11 Aug 2022 13:44:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=A0=E9=99=A4=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/lib/controllers/application/index.js | 163 +++++++++++++----- .../api/app/lib/routes/application/index.js | 16 +- .../application/actions/application.js | 42 +++++ .../src/sections/application/actions/index.js | 5 +- 4 files changed, 178 insertions(+), 48 deletions(-) create mode 100644 code/VideoAccess-VCMP/web/client/src/sections/application/actions/application.js diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js index 3e363ba..b6fbcd1 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js @@ -4,53 +4,132 @@ const moment = require('moment') const uuid = require('uuid'); async function edit (ctx, next) { - let errMsg = '创建应用失败' - const transaction = await ctx.fs.dc.orm.transaction(); - try { - const { models } = ctx.fs.dc; - const { userId } = ctx.fs.api - const data = ctx.request.body; - - if (data.id) { - // 修改 - const storageData = Object.assign({}, data,) - await models.Application.update(storageData, { - where: { - id: data.id - }, - transaction - }) - } else { - - // 添加 - const storageData = Object.assign({}, data, { - appKey: uuid.v4(), - appSecret: uuid.v4(), - createUserId: userId, - createTime: moment().format(), - forbidden: true - - }) - await models.Application.create(storageData, { 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 = { - message: errMsg - } - } + let errMsg = '创建应用失败' + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const { models } = ctx.fs.dc; + const { userId } = ctx.fs.api + const data = ctx.request.body; + + if (data.id) { + // 修改 + const storageData = Object.assign({}, data,) + await models.Application.update(storageData, { + where: { + id: data.appId + }, + transaction + }) + } else { + + // 添加 + const storageData = Object.assign({}, data, { + appKey: uuid.v4(), + appSecret: uuid.v4(), + createUserId: userId, + createTime: moment().format(), + forbidden: true + + }) + await models.Application.create(storageData, { 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 = { + message: errMsg + } + } } +async function get (ctx) { + try { + const models = ctx.fs.dc.models; + const { userId } = ctx.fs.api + const { limit, page, orderBy, orderDirection } = ctx.query + let findOption = { + where: { + createUserId: userId, + }, + order: [ + [orderBy || 'id', orderDirection || 'DESC'] //查询排序 + ], + } + + if (limit) { + findOption.limit = limit + } + if (page && limit) { + findOption.offset = page * limit + } + const nvrRes = await models.Application.findAndCountAll(findOption) + + ctx.status = 200; + ctx.body = { + total: nvrRes.count, + data: nvrRes.rows + } + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = {} + } +} +async function put (ctx) { + try { + const { models } = ctx.fs.dc; + const data = ctx.request.body; + // TODO 向视频服务发送通知 + // 库记录 + await models.Application.update({ + forbidden: data.forbidden + }, { + where: { + id: data.appId + } + }) + + ctx.status = 204; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = {} + } +} + +async function del (ctx, next) { + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const models = ctx.fs.dc.models; + const { appId } = ctx.params + + await models.Application.destroy({ + where: { + id: appId + }, + 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 = {} + } +} module.exports = { - edit, - get, + edit, + get, + put, + del }; \ No newline at end of file diff --git a/code/VideoAccess-VCMP/api/app/lib/routes/application/index.js b/code/VideoAccess-VCMP/api/app/lib/routes/application/index.js index 2f688b1..846346a 100644 --- a/code/VideoAccess-VCMP/api/app/lib/routes/application/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/routes/application/index.js @@ -5,10 +5,16 @@ const application = require('../../controllers/application'); module.exports = function (app, router, opts) { - // app.fs.api.logAttr['GET/application'] = { content: '获取应用信息', visible: false }; - // router.get('/application', application.get); + app.fs.api.logAttr['GET/application'] = { content: '获取应用信息', visible: false }; + router.get('/application', application.get); + + app.fs.api.logAttr['POST/application'] = { content: '创建/修改应用', visible: false }; + router.post('/application', application.edit); + + app.fs.api.logAttr['PUT/application'] = { content: '禁用应用', visible: false } + router.put('/application', application.put); + + app.fs.api.logAttr['DEL/application/:appId'] = { content: '删除应用', visible: false }; + router.del('/application/:appId', application.del); - app.fs.api.logAttr['POST/application'] = { content: '创建/修改应用', visible: false }; - router.post('/application', application.edit); - }; diff --git a/code/VideoAccess-VCMP/web/client/src/sections/application/actions/application.js b/code/VideoAccess-VCMP/web/client/src/sections/application/actions/application.js new file mode 100644 index 0000000..e884e54 --- /dev/null +++ b/code/VideoAccess-VCMP/web/client/src/sections/application/actions/application.js @@ -0,0 +1,42 @@ +"use strict"; + +import { basicAction } from "@peace/utils"; +import { ApiTable } from "$utils"; + +export function getCamera(query) { + return (dispatch) => + basicAction({ + type: "get", + dispatch: dispatch, + actionType: "GET_APPLICATION", + query: query, + url: `${ApiTable.getCamera}`, + msg: { option: "获取摄像头列表信息" }, + reducer: { name: "applicationData", params: { noClear: true } }, + }); +} + +export function putForbidden(data, forbidden) { + return (dispatch) => + basicAction({ + type: "put", + dispatch: dispatch, + actionType: "PUT_APPLICATION", + data, + url: `${ApiTable.putForbidden}`, + msg: { option: forbidden ? "启用" : "禁用" }, //禁用摄像头 + reducer: {}, + }); +} + +export function delCamera(orgId) { + return (dispatch) => + basicAction({ + type: "del", + dispatch: dispatch, + actionType: "DEL_APPLICATION", + url: `${ApiTable.delCamera.replace("{cameraId}", orgId)}`, + msg: { option: "设备会被存放在“设备回收站”中,删除" }, //删除摄像头 + reducer: {}, + }); +} \ No newline at end of file diff --git a/code/VideoAccess-VCMP/web/client/src/sections/application/actions/index.js b/code/VideoAccess-VCMP/web/client/src/sections/application/actions/index.js index 7ed1088..0a0ac1f 100644 --- a/code/VideoAccess-VCMP/web/client/src/sections/application/actions/index.js +++ b/code/VideoAccess-VCMP/web/client/src/sections/application/actions/index.js @@ -1,5 +1,8 @@ 'use strict'; -export default { +import * as application from './application' + +export default { + ...application } \ No newline at end of file