request->get('config_type', ''); if (empty($configType)) { return fail('配置类型不能为空'); } $performanceConfigService = new PerformanceConfigService(); $structure = $performanceConfigService->getConfigStructure($configType); if (!$structure) { return fail('未找到配置类型'); } return success(data: $structure); } /** * 获取配置数据 * @return \think\Response */ public function getConfigData() { $configType = $this->request->get('config_type', ''); if (empty($configType)) { return fail('配置类型不能为空'); } $performanceConfigService = new PerformanceConfigService(); $configData = $performanceConfigService->getConfigData($configType); return success(data: [ 'config_type' => $configType, 'data' => $configData ]); } /** * 保存配置数据 * @return \think\Response */ public function saveConfigData() { $data = $this->request->params([ ['config_type', ''], ['config_data', []], ]); if (empty($data['config_type'])) { return fail('配置类型不能为空'); } if (empty($data['config_data'])) { return fail('配置数据不能为空'); } try { $performanceConfigService = new PerformanceConfigService(); $result = $performanceConfigService->saveConfigData( $data['config_type'], $data['config_data'], $this->request->uid() ); if ($result) { return success(msg: '配置保存成功'); } else { return fail('配置保存失败'); } } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 获取所有可用配置类型 * @return \think\Response */ public function getConfigTypes() { $performanceConfigService = new PerformanceConfigService(); $types = $performanceConfigService->getAvailableConfigTypes(); return success(data: $types); } /** * 重置配置为默认值 * @return \think\Response */ public function resetToDefault() { $configType = $this->request->get('config_type', ''); if (empty($configType)) { return fail('配置类型不能为空'); } try { $performanceConfigService = new PerformanceConfigService(); $result = $performanceConfigService->resetConfigToDefault($configType, $this->request->uid()); if ($result) { return success(msg: '配置已重置为默认值'); } else { return fail('配置重置失败'); } } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 导出配置 * @return \think\Response */ public function exportConfig() { $configType = $this->request->get('config_type', ''); if (empty($configType)) { return fail('配置类型不能为空'); } try { $performanceConfigService = new PerformanceConfigService(); $exportData = $performanceConfigService->exportConfig($configType); return success(data: $exportData); } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 导入配置 * @return \think\Response */ public function importConfig() { $data = $this->request->params([ ['import_data', []], ]); if (empty($data['import_data'])) { return fail('导入数据不能为空'); } try { $performanceConfigService = new PerformanceConfigService(); $result = $performanceConfigService->importConfig($data['import_data'], $this->request->uid()); if ($result) { return success(msg: '配置导入成功'); } else { return fail('配置导入失败'); } } catch (\Exception $e) { return fail($e->getMessage()); } } /** * 清除配置缓存 * @return \think\Response */ public function clearCache() { $configType = $this->request->get('config_type', ''); $performanceConfigService = new PerformanceConfigService(); $performanceConfigService->clearConfigCache($configType ?: null); return success(msg: '缓存清除成功'); } }