|
|
@@ -0,0 +1,82 @@
|
|
|
+'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 } = require('../api/setting');
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 设置控制器
|
|
|
+ * @class
|
|
|
+ */
|
|
|
+class SettingController extends Controller {
|
|
|
+
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx);
|
|
|
+ this.configPath = path.join(__dirname, '..', 'config', 'app.config.json');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取设备配置列表
|
|
|
+ */
|
|
|
+ async getDeviceConfigList(args) {
|
|
|
+ try {
|
|
|
+ console.log(2)
|
|
|
+ const result = await getDeviceConfigs(args);
|
|
|
+ console.log(result)
|
|
|
+ return result;
|
|
|
+ } catch (error) {
|
|
|
+ Log.error('获取设备配置列表失败:', error);
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取设备配置详情
|
|
|
+ * @param {Object} args - 配置ID
|
|
|
+ */
|
|
|
+ async getDeviceConfigDetail(args) {
|
|
|
+ try {
|
|
|
+ const result = await getDeviceConfigDetail(args);
|
|
|
+ return result;
|
|
|
+ } catch (error) {
|
|
|
+ Log.error('获取设备配置详情失败:', error);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除设备配置
|
|
|
+ * @param {Object} args - 配置ID
|
|
|
+ */
|
|
|
+ async removeDeviceConfig(args) {
|
|
|
+ try {
|
|
|
+ const result = await removeConfig(args);
|
|
|
+ return result;
|
|
|
+ } catch (error) {
|
|
|
+ Log.error('删除设备配置失败:', error);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存设备配置
|
|
|
+ * @param {Object} args - 配置内容
|
|
|
+ */
|
|
|
+ async saveDeviceConfig(args) {
|
|
|
+ try {
|
|
|
+ const result = await saveDeviceConfig(args);
|
|
|
+ return result;
|
|
|
+ } catch (error) {
|
|
|
+ Log.error('保存设备配置失败:', error);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+SettingController.toString = () => '[class SettingController]';
|
|
|
+module.exports = SettingController;
|