| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- 'use strict';
- const { Controller } = require('ee-core');
- const Log = require('ee-core/log');
- const Services = require('ee-core/services');
- const path = require('path');
- const fs = require('fs');
- const { getDeviceConfigs, getDeviceConfigDetail, removeConfig, saveDeviceConfig, resetDeviceConfig,updateSysConfigs,getSysConfig } = require('../api/setting');
- const errData = {
- msg :'请求失败,请联系管理员',
- code:999
- }
- /**
- * 设置控制器
- * @class
- */
- class SettingController extends Controller {
- constructor(ctx) {
- super(ctx);
- this.configPath = path.join(__dirname, '..', 'config', 'app.config.json');
- }
- /**
- * 获取设备配置列表
- */
- async getDeviceConfigList(args) {
- try {
- const result = await getDeviceConfigs(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('获取设备配置列表失败:', error);
- return errData;
- }
- }
- /**
- * 获取设备配置详情
- * @param {Object} args - 配置ID
- */
- async getDeviceConfigDetail(args) {
- try {
- const result = await getDeviceConfigDetail(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- return errData;
- }
- }
- /**
- * 删除设备配置
- * @param {Object} args - 配置ID
- */
- async removeDeviceConfig(args) {
- try {
- const result = await removeConfig(args)
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('删除设备配置失败:', error);
- return errData;
- }
- }
- /**
- * 保存设备配置
- * @param {Object} args - 配置内容
- */
- async saveDeviceConfig(args) {
- try {
- const result = await saveDeviceConfig(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('保存设备配置失败:', error);
- return errData;
- }
- }
- /**
- * 重置设备配置
- * @param {Object} args - 配置ID
- */
- async resetDeviceConfig(args) {
- try {
- const result = await resetDeviceConfig(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('重置设备配置失败:', error);
- return errData;
- }
- }
- /**
- * 读取配置
- * @param {Object} args - 配置ID
- */
- async getSysConfig(args) {
- try {
- const result = await getSysConfig(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('重置设备配置失败:', error);
- return errData;
- }
- }
- /**
- * 保存配置
- * @param {Object} args - 配置ID
- */
- async updateSysConfigs(args) {
- try {
- const result = await updateSysConfigs(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('保存配置:', error);
- return errData;
- }
- }
- }
- SettingController.toString = () => '[class SettingController]';
- module.exports = SettingController;
|