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.
162 lines
4.4 KiB
162 lines
4.4 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\adminapi\controller\document;
|
|
|
|
use core\base\BaseAdminController;
|
|
use app\service\admin\document\DocumentDataSourceService;
|
|
use think\Response;
|
|
|
|
/**
|
|
* 文档数据源配置控制器
|
|
* Class DocumentDataSource
|
|
* @package app\adminapi\controller\document
|
|
*/
|
|
class DocumentDataSource extends BaseAdminController
|
|
{
|
|
/**
|
|
* 获取数据源配置列表
|
|
* @return Response
|
|
*/
|
|
public function lists(): Response
|
|
{
|
|
$data = $this->request->params([
|
|
['contract_id', 0],
|
|
['placeholder', ''],
|
|
['table_name', ''],
|
|
['field_name', ''],
|
|
['page', 1],
|
|
['limit', 20]
|
|
]);
|
|
|
|
return success((new DocumentDataSourceService())->getPage($data));
|
|
}
|
|
|
|
/**
|
|
* 获取数据源配置详情
|
|
* @param int $id
|
|
* @return Response
|
|
*/
|
|
public function info(int $id): Response
|
|
{
|
|
return success((new DocumentDataSourceService())->getInfo($id));
|
|
}
|
|
|
|
/**
|
|
* 添加数据源配置
|
|
* @return Response
|
|
*/
|
|
public function add(): Response
|
|
{
|
|
$data = $this->request->params([
|
|
['contract_id', 0],
|
|
['placeholder', ''],
|
|
['table_name', ''],
|
|
['field_name', ''],
|
|
['field_type', 'string'],
|
|
['is_required', 0],
|
|
['default_value', '']
|
|
]);
|
|
|
|
$this->validate($data, 'app\validate\document\DocumentDataSource.add');
|
|
|
|
$id = (new DocumentDataSourceService())->add($data);
|
|
return success('ADD_SUCCESS', ['id' => $id]);
|
|
}
|
|
|
|
/**
|
|
* 编辑数据源配置
|
|
* @param int $id
|
|
* @return Response
|
|
*/
|
|
public function edit(int $id): Response
|
|
{
|
|
$data = $this->request->params([
|
|
['contract_id', 0],
|
|
['placeholder', ''],
|
|
['table_name', ''],
|
|
['field_name', ''],
|
|
['field_type', 'string'],
|
|
['is_required', 0],
|
|
['default_value', '']
|
|
]);
|
|
|
|
$this->validate($data, 'app\validate\document\DocumentDataSource.edit');
|
|
|
|
(new DocumentDataSourceService())->edit($id, $data);
|
|
return success('EDIT_SUCCESS');
|
|
}
|
|
|
|
/**
|
|
* 删除数据源配置
|
|
* @param int $id
|
|
* @return Response
|
|
*/
|
|
public function del(int $id): Response
|
|
{
|
|
(new DocumentDataSourceService())->del($id);
|
|
return success('DELETE_SUCCESS');
|
|
}
|
|
|
|
/**
|
|
* 批量配置数据源
|
|
* @return Response
|
|
*/
|
|
public function batchConfig(): Response
|
|
{
|
|
$data = $this->request->params([
|
|
['contract_id', 0],
|
|
['configs', []]
|
|
]);
|
|
|
|
$this->validate($data, 'app\validate\document\DocumentDataSource.batchConfig');
|
|
|
|
(new DocumentDataSourceService())->batchConfig($data['contract_id'], $data['configs']);
|
|
return success('CONFIG_SUCCESS');
|
|
}
|
|
|
|
/**
|
|
* 获取可用数据表列表
|
|
* @return Response
|
|
*/
|
|
public function getAvailableTables(): Response
|
|
{
|
|
return success((new DocumentDataSourceService())->getAvailableTables());
|
|
}
|
|
|
|
/**
|
|
* 获取数据表字段列表
|
|
* @return Response
|
|
*/
|
|
public function getTableFields(): Response
|
|
{
|
|
$tableName = $this->request->param('table_name', '');
|
|
if (empty($tableName)) {
|
|
return fail('TABLE_NAME_REQUIRED');
|
|
}
|
|
|
|
return success((new DocumentDataSourceService())->getTableFields($tableName));
|
|
}
|
|
|
|
/**
|
|
* 预览数据源配置效果
|
|
* @return Response
|
|
*/
|
|
public function preview(): Response
|
|
{
|
|
$data = $this->request->params([
|
|
['contract_id', 0],
|
|
['sample_data', []]
|
|
]);
|
|
|
|
return success((new DocumentDataSourceService())->preview($data['contract_id'], $data['sample_data']));
|
|
}
|
|
}
|
|
|