setting.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. 'use strict';
  2. const { Controller } = require('ee-core');
  3. const Log = require('ee-core/log');
  4. const Services = require('ee-core/services');
  5. const path = require('path');
  6. const fs = require('fs');
  7. const { getDeviceConfigs, getDeviceConfigDetail, removeConfig, saveDeviceConfig, resetDeviceConfig,updateSysConfigs,getSysConfig } = require('../api/setting');
  8. const errData = {
  9. msg :'请求失败,请联系管理员',
  10. code:999
  11. }
  12. /**
  13. * 设置控制器
  14. * @class
  15. */
  16. class SettingController extends Controller {
  17. constructor(ctx) {
  18. super(ctx);
  19. this.configPath = path.join(__dirname, '..', 'config', 'app.config.json');
  20. }
  21. /**
  22. * 获取设备配置列表
  23. */
  24. async getDeviceConfigList(args) {
  25. try {
  26. const result = await getDeviceConfigs(args);
  27. if(result.data) return result.data
  28. return errData;
  29. } catch (error) {
  30. Log.error('获取设备配置列表失败:', error);
  31. return errData;
  32. }
  33. }
  34. /**
  35. * 获取设备配置详情
  36. * @param {Object} args - 配置ID
  37. */
  38. async getDeviceConfigDetail(args) {
  39. try {
  40. const result = await getDeviceConfigDetail(args);
  41. if(result.data) return result.data
  42. return errData;
  43. } catch (error) {
  44. return errData;
  45. }
  46. }
  47. /**
  48. * 删除设备配置
  49. * @param {Object} args - 配置ID
  50. */
  51. async removeDeviceConfig(args) {
  52. try {
  53. const result = await removeConfig(args)
  54. if(result.data) return result.data
  55. return errData;
  56. } catch (error) {
  57. Log.error('删除设备配置失败:', error);
  58. return errData;
  59. }
  60. }
  61. /**
  62. * 保存设备配置
  63. * @param {Object} args - 配置内容
  64. */
  65. async saveDeviceConfig(args) {
  66. try {
  67. const result = await saveDeviceConfig(args);
  68. if(result.data) return result.data
  69. return errData;
  70. } catch (error) {
  71. Log.error('保存设备配置失败:', error);
  72. return errData;
  73. }
  74. }
  75. /**
  76. * 重置设备配置
  77. * @param {Object} args - 配置ID
  78. */
  79. async resetDeviceConfig(args) {
  80. try {
  81. const result = await resetDeviceConfig(args);
  82. if(result.data) return result.data
  83. return errData;
  84. } catch (error) {
  85. Log.error('重置设备配置失败:', error);
  86. return errData;
  87. }
  88. }
  89. /**
  90. * 读取配置
  91. * @param {Object} args - 配置ID
  92. */
  93. async getSysConfig(args) {
  94. try {
  95. const result = await getSysConfig(args);
  96. if(result.data) return result.data
  97. return errData;
  98. } catch (error) {
  99. Log.error('重置设备配置失败:', error);
  100. return errData;
  101. }
  102. }
  103. /**
  104. * 保存配置
  105. * @param {Object} args - 配置ID
  106. */
  107. async updateSysConfigs(args) {
  108. try {
  109. const result = await updateSysConfigs(args);
  110. if(result.data) return result.data
  111. return errData;
  112. } catch (error) {
  113. Log.error('保存配置:', error);
  114. return errData;
  115. }
  116. }
  117. }
  118. SettingController.toString = () => '[class SettingController]';
  119. module.exports = SettingController;