|  | @ -1,5 +1,7 @@ | 
			
		
	
		
		
			
				
					|  |  | 'use strict'; |  |  | 'use strict'; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | const moment = require('moment') | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | async function createYingshi (ctx) { |  |  | async function createYingshi (ctx) { | 
			
		
	
		
		
			
				
					|  |  |    let errMsg = '添加萤石摄像头失败' |  |  |    let errMsg = '添加萤石摄像头失败' | 
			
		
	
		
		
			
				
					|  |  |    try { |  |  |    try { | 
			
		
	
	
		
		
			
				
					|  | @ -7,12 +9,14 @@ async function createYingshi (ctx) { | 
			
		
	
		
		
			
				
					|  |  |       const { userId, token } = ctx.fs.api |  |  |       const { userId, token } = ctx.fs.api | 
			
		
	
		
		
			
				
					|  |  |       const { utils: { token4yingshi } } = ctx.app.fs |  |  |       const { utils: { token4yingshi } } = ctx.app.fs | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |       const { id, name, cloudControl, highDefinition, memoryCard, |  |  |       const { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          voice, kindId, abilityId, rtmp, serialNo } = ctx.request.body; |  |  |          id, name, cloudControl, highDefinition, memoryCard, | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |          voice, kindId, abilityId, rtmp, serialNo, longitude, latitude, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       } = ctx.request.body; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       const serialNo_ = String(serialNo).toUpperCase() |  |  |       const serialNo_ = String(serialNo).toUpperCase() | 
			
		
	
		
		
			
				
					|  |  |       const secretRes = await models.SecretYingshi.findAll() |  |  |       const secretRes = await models.SecretYingshi.findAll() | 
			
		
	
		
		
			
				
					
					|  |  |       let cameraBeloneSecret = null |  |  |       let cameraBeloneSecretId = null | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       for (let s of secretRes) { |  |  |       for (let s of secretRes) { | 
			
		
	
		
		
			
				
					|  |  |          const tokenYingshi = await token4yingshi(s.dataValues) |  |  |          const tokenYingshi = await token4yingshi(s.dataValues) | 
			
		
	
		
		
			
				
					|  |  |          // 检测设备所属
 |  |  |          // 检测设备所属
 | 
			
		
	
	
		
		
			
				
					|  | @ -28,7 +32,7 @@ async function createYingshi (ctx) { | 
			
		
	
		
		
			
				
					|  |  |          } |  |  |          } | 
			
		
	
		
		
			
				
					|  |  |       } |  |  |       } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |       if (!cameraBeloneSecret) { |  |  |       if (!cameraBeloneSecretId) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |          errMsg = '请联系管理员核验或新增萤石云权限' |  |  |          errMsg = '请联系管理员核验或新增萤石云权限' | 
			
		
	
		
		
			
				
					|  |  |          throw errMsg |  |  |          throw errMsg | 
			
		
	
		
		
			
				
					|  |  |       } |  |  |       } | 
			
		
	
	
		
		
			
				
					|  | @ -36,17 +40,19 @@ async function createYingshi (ctx) { | 
			
		
	
		
		
			
				
					|  |  |       let storageData = { |  |  |       let storageData = { | 
			
		
	
		
		
			
				
					|  |  |          type: 'yingshi', name, cloudControl, highDefinition, memoryCard, |  |  |          type: 'yingshi', name, cloudControl, highDefinition, memoryCard, | 
			
		
	
		
		
			
				
					|  |  |          voice, longitude, latitude, kindId, abilityId, rtmp, |  |  |          voice, longitude, latitude, kindId, abilityId, rtmp, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          yingshiSecretId: cameraBeloneSecretId | 
			
		
	
		
		
			
				
					|  |  |       } |  |  |       } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       if (id) { |  |  |       if (id) { | 
			
		
	
		
		
			
				
					|  |  |          storageData.createTime = moment().format() |  |  |  | 
			
		
	
		
		
			
				
					|  |  |          storageData.createUserId = userId |  |  |  | 
			
		
	
		
		
			
				
					|  |  |          await models.Camera.update(storageData, { |  |  |          await models.Camera.update(storageData, { | 
			
		
	
		
		
			
				
					|  |  |             where: { |  |  |             where: { | 
			
		
	
		
		
			
				
					|  |  |                id, |  |  |                id, | 
			
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |          }) |  |  |          }) | 
			
		
	
		
		
			
				
					|  |  |       } else { |  |  |       } else { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          storageData.createTime = moment().format() | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          storageData.createUserId = userId | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          storageData.forbidden = false | 
			
		
	
		
		
			
				
					|  |  |          await models.Camera.create(storageData) |  |  |          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 = { |  |  | module.exports = { | 
			
		
	
		
		
			
				
					
					|  |  |    createYingshi |  |  |    createYingshi, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |    getNvrSteam, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |    createNvrCamera, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |    createIpcCamera, | 
			
		
	
		
		
			
				
					|  |  | }; |  |  | }; |