From 4a3946d4cc5cfa1088db15acc7c55eb65cc5355a Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Fri, 24 Jun 2022 09:55:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=90=A4=E7=9F=B3=E7=8A=B6=E6=80=81=E6=8E=A8?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/app/lib/schedule/freshYingshiState.js | 196 +++++++++--------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js b/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js index 9b84f96..4db3167 100644 --- a/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js +++ b/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js @@ -7,107 +7,107 @@ module.exports = function (app, opts) { '*/1 * * * *', async () => { - // try { - // const startTime = moment() - // const { models } = app.fs.dc - // const { token4yingshi } = app.fs.utils - // const secretRes = await models.SecretYingshi.findAll() - // let deviceList = [] - // for (let s of secretRes) { - // const tokenYingshi = await token4yingshi(s.dataValues) - // // 查询所有设备 - // let pageStart = 0 - // while (pageStart >= 0) { - // const deviceRes = await app.fs.yingshiRequest.post('lapp/device/list', { - // query: { - // accessToken: tokenYingshi, - // pageStart, - // pageSize: 50 - // } - // }) - // if (deviceRes.code == 200) { - // if (deviceRes.data.length) { - // deviceList = deviceList.concat.apply(deviceList, deviceRes.data) - // for (let d of deviceRes.data) { - // const existD = await models.GbCamera.findOne({ - // where: { - // streamid: d.deviceSerial - // } - // }) + try { + const startTime = moment() + const { models } = app.fs.dc + const { token4yingshi } = app.fs.utils + const secretRes = await models.SecretYingshi.findAll() + let deviceList = [] + for (let s of secretRes) { + const tokenYingshi = await token4yingshi(s.dataValues) + // 查询所有设备 + let pageStart = 0 + while (pageStart >= 0) { + const deviceRes = await app.fs.yingshiRequest.post('lapp/device/list', { + query: { + accessToken: tokenYingshi, + pageStart, + pageSize: 50 + } + }) + if (deviceRes.code == 200) { + if (deviceRes.data.length) { + deviceList = deviceList.concat.apply(deviceList, deviceRes.data) + for (let d of deviceRes.data) { + const existD = await models.GbCamera.findOne({ + where: { + streamid: d.deviceSerial + } + }) - // let storageD = { - // level: 0, - // ipctype: 'yingshi', - // streamid: d.deviceSerial, - // online: d.status ? 'ON' : 'OFF', - // name: d.deviceName, - // } - // if (existD) { - // if (existD.online != storageD.online) { - // // 状态更新 - // await models.GbCamera.update(storageD, { - // where: { - // id: existD.id - // } - // }) + let storageD = { + level: 0, + ipctype: 'yingshi', + streamid: d.deviceSerial, + online: d.status ? 'ON' : 'OFF', + name: d.deviceName, + } + if (existD) { + if (existD.online != storageD.online) { + // 状态更新 + await models.GbCamera.update(storageD, { + where: { + id: existD.id + } + }) - // // 状态推送 - // // const { connected } = app.socket.sockets - // // const roomId = 'ROOM_' + Math.random() + '_' + d.deviceSerial - // // let cameraName = '' - // // if (connected) { - // // for (let c in connected) { - // // const { client: { conn: { request: { _query } } } } = connected[c] - // // if (_query && _query.token) { - // // let userInfo = await app.redis.hget(_query.token, 'userInfo'); - // // if (userInfo) { - // // userInfo = JSON.parse(userInfo) - // // const corCameraRes = await models.Camera.findOne({ - // // where: { - // // gbId: existD.id, - // // createUserId: userInfo.id - // // } - // // }) - // // // TODO 管理员判断 - // // if (corCameraRes) { - // // cameraName = corCameraRes.name - // // connected[c].join(roomId) - // // } - // // } - // // } - // // } + // 状态推送 + const { connected } = app.socket.sockets + const roomId = 'ROOM_' + Math.random() + '_' + d.deviceSerial + let cameraName = '' + if (connected) { + for (let c in connected) { + const { client: { conn: { request: { _query } } } } = connected[c] + if (_query && _query.token) { + let userInfo = await app.redis.hget(_query.token, 'userInfo'); + if (userInfo) { + userInfo = JSON.parse(userInfo) + const corCameraRes = await models.Camera.findOne({ + where: { + gbId: existD.id, + createUserId: userInfo.id + } + }) + // TODO 管理员判断 + if (corCameraRes) { + cameraName = corCameraRes.name + connected[c].join(roomId) + } + } + } + } - // // app.socket.to(roomId).emit('CAMERA_ONLINE', { - // // ipctype: 'yingshi', - // // online: storageD.online, - // // gbId: existD.id, - // // name: cameraName - // // }) - // // } - // } - // } else { - // const yingshiRes = await models.GbCamera.create(storageD) - // await models.Camera.update({ - // gbId: yingshiRes.id - // }, { - // where: { - // serialNo: d.deviceSerial - // } - // }) - // } - // } - // pageStart++ - // } else { - // pageStart = -1 - // } - // } - // } - // } - // // console.log(deviceList); - // console.info(`萤石状态查询用时 ${moment().diff(startTime, 'seconds')} s`) - // } catch (error) { - // app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`); - // } + app.socket.to(roomId).emit('CAMERA_ONLINE', { + ipctype: 'yingshi', + online: storageD.online, + gbId: existD.id, + name: cameraName + }) + } + } + } else { + const yingshiRes = await models.GbCamera.create(storageD) + await models.Camera.update({ + gbId: yingshiRes.id + }, { + where: { + serialNo: d.deviceSerial + } + }) + } + } + pageStart++ + } else { + pageStart = -1 + } + } + } + } + // console.log(deviceList); + console.info(`萤石状态查询用时 ${moment().diff(startTime, 'seconds')} s`) + } catch (error) { + app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`); + } }); return {