智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

206 lines
5.9 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\adminapi\controller\performance;
use core\base\BaseAdminController;
use app\service\core\performance\PerformanceConfigService;
/**
* 绩效配置管理控制器
* Class PerformanceConfig
* @package app\adminapi\controller\performance
*/
class PerformanceConfig extends BaseAdminController
{
/**
* 获取配置结构定义
* @return \think\Response
*/
public function getConfigStructure()
{
$configType = $this->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: '缓存清除成功');
}
}