From 8e7f0d994e882f9ec5995069c8d45c136eaf1f28 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Thu, 3 Nov 2022 12:34:02 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=8E=A8=E9=80=81=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/VideoAccess-VCMP/api/.vscode/launch.json | 5 ++-- .../api/app/lib/controllers/status/push.js | 23 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/code/VideoAccess-VCMP/api/.vscode/launch.json b/code/VideoAccess-VCMP/api/.vscode/launch.json index 1445146..e812e78 100644 --- a/code/VideoAccess-VCMP/api/.vscode/launch.json +++ b/code/VideoAccess-VCMP/api/.vscode/launch.json @@ -15,12 +15,13 @@ "args": [ "-p 4000", "-f http://localhost:4000", - // "-g postgres://postgres:123@10.8.30.166:5432/video_access", - "-g postgres://postgres:123@10.8.30.166:5432/video_access-dev", + "-g postgres://postgres:123@10.8.30.166:5432/video-access", + // "-g postgres://postgres:123@10.8.30.166:5432/video_access-dev", "--redisHost 10.8.30.112", "--redisPort 6379", "--axyApiUrl http://127.0.0.1:4100", "--iotAuthApi http://127.0.0.1:4200", + "--pomsApiUrl http://127.0.0.1:4600", "--godUrl https://restapi.amap.com/v3", "--godKey 21c2d970e1646bb9a795900dd00093ce", "--mqttVideoServer mqtt://10.8.30.71:30883", diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/status/push.js b/code/VideoAccess-VCMP/api/app/lib/controllers/status/push.js index 92ef8d1..07200c7 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/status/push.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/status/push.js @@ -122,6 +122,7 @@ async function edit (ctx) { async function getStatusPushList (ctx) { try { const models = ctx.fs.dc.models; + const sequelize = ctx.fs.dc.ORM; const { userId, token } = ctx.fs.api const { limit, page, orderBy, orderDirection, name, pushWay } = ctx.query @@ -157,6 +158,7 @@ async function getStatusPushList (ctx) { findOption.order = [ [orderBy || 'id', orderDirection || 'DESC'] ] + findOption.include = [ { model: models.CameraStatusPushMonitor, @@ -168,12 +170,6 @@ async function getStatusPushList (ctx) { attributes: ['name'], }] }, - { - model: models.CameraStatusPushLog, - attributes: ['id'], - duplicating: false, - required: false, - }, { model: models.CameraStatusPushReceiver, attributes: ['receiver'], @@ -189,9 +185,22 @@ async function getStatusPushList (ctx) { delete findOption.where.id const count = await models.CameraStatusPushConfig.count(findOption) + // 获取所有id + const pushLogCountRes = await models.CameraStatusPushLog.findAll({ + attributes: [ + 'pushConfigId', + [sequelize.fn('COUNT', sequelize.col('id')), 'count'] + ], + where: { + pushConfigId: { $in: configIds } + }, + group: ['pushConfigId'] + }) + for (let { dataValues: c } of configRes) { c.monitorCount = c.cameraStatusPushMonitors.length; - c.logCount = c.cameraStatusPushLogs.length; + let corLofCount = pushLogCountRes.find(p => p.dataValues.pushConfigId == c.id) + c.logCount = corLofCount ? corLofCount.dataValues.count : 0 delete c.cameraStatusPushLogs }