'use strict'; const MainService = require('../main'); class CameraService extends MainService { constructor(ctx) { super(ctx); const _noNeedLogin = ''; const _noNeedRight = 'list,detail,setOsd,ptzControl,ptzStop,ptzPresetGoto,ptzPresetSet'; const _noNeedLog = '*'; const _noNeedAuth = 'list,detail,setOsd,ptzControl,ptzStop,ptzPresetGoto,ptzPresetSet'; this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth); } async list(data) { try { const result = await this.service.systems.camera.list(data || {}); return this.success('获取成功', result); } catch (e) { return this.fail(e.message); } } async detail(data) { try { const { id } = data || {}; if (!id) return this.fail('ID不能为空'); return this.success('获取成功', await this.service.systems.camera.detail(parseInt(id))); } catch (e) { return this.fail(e.message); } } async create(data) { try { return this.success('创建成功', await this.service.systems.camera.create(data)); } catch (e) { return this.fail(e.message); } } async update(data) { try { const { id, ...fields } = data || {}; if (!id) return this.fail('ID不能为空'); return this.success('更新成功', await this.service.systems.camera.update(parseInt(id), fields)); } catch (e) { return this.fail(e.message); } } async setOsd(data) { try { return this.success('设置成功', await this.service.systems.camera.setOsd(data)); } catch (e) { return this.fail(e.message); } } /** * 云台方向控制(按下) * @param {Object} data - 入参 * @param {number} data.id - 摄像头ID(必填) * @param {number|string} data.computerId - 打印电脑ID(必填) * @param {string} data.action - 云台方向(8 个位置,必填) * @param {number} [data.speed] - 云台转速(1-7,默认 4) * @return {Promise} 统一响应 */ async ptzControl(data) { try { return this.success('云台控制成功', await this.service.systems.camera.ptzControl(data)); } catch (e) { return this.fail(e.message); } } /** * 云台停止(松手) * @param {Object} data - 入参 * @param {number} data.id - 摄像头ID(必填) * @param {number|string} data.computerId - 打印电脑ID(必填) * @param {string} data.action - 云台方向(必须与按下时一致,必填) * @return {Promise} 统一响应 */ async ptzStop(data) { try { return this.success('云台已停止', await this.service.systems.camera.ptzStop(data)); } catch (e) { return this.fail(e.message); } } /** * 云台预置点跳转 * @param {Object} data - 入参 * @param {number} data.id - 摄像头ID(必填) * @param {number|string} data.computerId - 打印电脑ID(必填) * @param {number|string} data.presetId - 预置点编号(1-256,必填) * @return {Promise} 统一响应 */ async ptzPresetGoto(data) { try { return this.success('预置点跳转成功', await this.service.systems.camera.ptzPresetGoto(data)); } catch (e) { return this.fail(e.message); } } /** * 云台预置点设置 * @param {Object} data - 入参 * @param {number} data.id - 摄像头ID(必填) * @param {number|string} data.presetId - 预置点编号(1-256,必填) * @return {Promise} 统一响应 */ async ptzPresetSet(data) { try { return this.success('预置点设置成功', await this.service.systems.camera.ptzPresetSet(data)); } catch (e) { return this.fail(e.message); } } async delete(data) { try { const { id } = data || {}; if (!id) return this.fail('ID不能为空'); await this.service.systems.camera.delete(parseInt(id)); return this.success('删除成功'); } catch (e) { return this.fail(e.message); } } } module.exports = CameraService;