Browse Source

萤石状态推送

release_0.0.2
巴林闲侠 3 years ago
parent
commit
4a3946d4cc
  1. 196
      code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js

196
code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js

@ -7,107 +7,107 @@ module.exports = function (app, opts) {
'*/1 * * * *', '*/1 * * * *',
async () => { async () => {
// try { try {
// const startTime = moment() const startTime = moment()
// const { models } = app.fs.dc const { models } = app.fs.dc
// const { token4yingshi } = app.fs.utils const { token4yingshi } = app.fs.utils
// const secretRes = await models.SecretYingshi.findAll() const secretRes = await models.SecretYingshi.findAll()
// let deviceList = [] let deviceList = []
// for (let s of secretRes) { for (let s of secretRes) {
// const tokenYingshi = await token4yingshi(s.dataValues) const tokenYingshi = await token4yingshi(s.dataValues)
// // 查询所有设备 // 查询所有设备
// let pageStart = 0 let pageStart = 0
// while (pageStart >= 0) { while (pageStart >= 0) {
// const deviceRes = await app.fs.yingshiRequest.post('lapp/device/list', { const deviceRes = await app.fs.yingshiRequest.post('lapp/device/list', {
// query: { query: {
// accessToken: tokenYingshi, accessToken: tokenYingshi,
// pageStart, pageStart,
// pageSize: 50 pageSize: 50
// } }
// }) })
// if (deviceRes.code == 200) { if (deviceRes.code == 200) {
// if (deviceRes.data.length) { if (deviceRes.data.length) {
// deviceList = deviceList.concat.apply(deviceList, deviceRes.data) deviceList = deviceList.concat.apply(deviceList, deviceRes.data)
// for (let d of deviceRes.data) { for (let d of deviceRes.data) {
// const existD = await models.GbCamera.findOne({ const existD = await models.GbCamera.findOne({
// where: { where: {
// streamid: d.deviceSerial streamid: d.deviceSerial
// } }
// }) })
// let storageD = { let storageD = {
// level: 0, level: 0,
// ipctype: 'yingshi', ipctype: 'yingshi',
// streamid: d.deviceSerial, streamid: d.deviceSerial,
// online: d.status ? 'ON' : 'OFF', online: d.status ? 'ON' : 'OFF',
// name: d.deviceName, name: d.deviceName,
// } }
// if (existD) { if (existD) {
// if (existD.online != storageD.online) { if (existD.online != storageD.online) {
// // 状态更新 // 状态更新
// await models.GbCamera.update(storageD, { await models.GbCamera.update(storageD, {
// where: { where: {
// id: existD.id id: existD.id
// } }
// }) })
// // 状态推送 // 状态推送
// // const { connected } = app.socket.sockets const { connected } = app.socket.sockets
// // const roomId = 'ROOM_' + Math.random() + '_' + d.deviceSerial const roomId = 'ROOM_' + Math.random() + '_' + d.deviceSerial
// // let cameraName = '' let cameraName = ''
// // if (connected) { if (connected) {
// // for (let c in connected) { for (let c in connected) {
// // const { client: { conn: { request: { _query } } } } = connected[c] const { client: { conn: { request: { _query } } } } = connected[c]
// // if (_query && _query.token) { if (_query && _query.token) {
// // let userInfo = await app.redis.hget(_query.token, 'userInfo'); let userInfo = await app.redis.hget(_query.token, 'userInfo');
// // if (userInfo) { if (userInfo) {
// // userInfo = JSON.parse(userInfo) userInfo = JSON.parse(userInfo)
// // const corCameraRes = await models.Camera.findOne({ const corCameraRes = await models.Camera.findOne({
// // where: { where: {
// // gbId: existD.id, gbId: existD.id,
// // createUserId: userInfo.id createUserId: userInfo.id
// // } }
// // }) })
// // // TODO 管理员判断 // TODO 管理员判断
// // if (corCameraRes) { if (corCameraRes) {
// // cameraName = corCameraRes.name cameraName = corCameraRes.name
// // connected[c].join(roomId) connected[c].join(roomId)
// // } }
// // } }
// // } }
// // } }
// // app.socket.to(roomId).emit('CAMERA_ONLINE', { app.socket.to(roomId).emit('CAMERA_ONLINE', {
// // ipctype: 'yingshi', ipctype: 'yingshi',
// // online: storageD.online, online: storageD.online,
// // gbId: existD.id, gbId: existD.id,
// // name: cameraName name: cameraName
// // }) })
// // } }
// } }
// } else { } else {
// const yingshiRes = await models.GbCamera.create(storageD) const yingshiRes = await models.GbCamera.create(storageD)
// await models.Camera.update({ await models.Camera.update({
// gbId: yingshiRes.id gbId: yingshiRes.id
// }, { }, {
// where: { where: {
// serialNo: d.deviceSerial serialNo: d.deviceSerial
// } }
// }) })
// } }
// } }
// pageStart++ pageStart++
// } else { } else {
// pageStart = -1 pageStart = -1
// } }
// } }
// } }
// } }
// // console.log(deviceList); // console.log(deviceList);
// console.info(`萤石状态查询用时 ${moment().diff(startTime, 'seconds')} s`) console.info(`萤石状态查询用时 ${moment().diff(startTime, 'seconds')} s`)
// } catch (error) { } catch (error) {
// app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`); app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`);
// } }
}); });
return { return {

Loading…
Cancel
Save