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.
151 lines
4.0 KiB
151 lines
4.0 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\DocumentGenerateService;
|
|
use think\Response;
|
|
|
|
/**
|
|
* 文档生成控制器
|
|
* Class DocumentGenerate
|
|
* @package app\adminapi\controller\document
|
|
*/
|
|
class DocumentGenerate extends BaseAdminController
|
|
{
|
|
/**
|
|
* 获取生成记录列表
|
|
* @return Response
|
|
*/
|
|
public function lists(): Response
|
|
{
|
|
$data = $this->request->params([
|
|
['template_id', 0],
|
|
['user_id', 0],
|
|
['user_type', ''],
|
|
['status', ''],
|
|
['page', 1],
|
|
['limit', 20]
|
|
]);
|
|
|
|
return success((new DocumentGenerateService())->getPage($data));
|
|
}
|
|
|
|
/**
|
|
* 获取生成记录详情
|
|
* @param int $id
|
|
* @return Response
|
|
*/
|
|
public function info(int $id): Response
|
|
{
|
|
return success((new DocumentGenerateService())->getInfo($id));
|
|
}
|
|
|
|
/**
|
|
* 生成文档
|
|
* @return Response
|
|
*/
|
|
public function generate(): Response
|
|
{
|
|
$data = $this->request->params([
|
|
['template_id', 0],
|
|
['user_type', 1],
|
|
['user_id', 0],
|
|
['fill_data', []],
|
|
['output_filename', '']
|
|
]);
|
|
|
|
$this->validate($data, 'app\validate\document\DocumentGenerate.generate');
|
|
|
|
$result = (new DocumentGenerateService())->generate($data);
|
|
return success('GENERATE_SUCCESS', $result);
|
|
}
|
|
|
|
/**
|
|
* 重新生成文档
|
|
* @param int $id
|
|
* @return Response
|
|
*/
|
|
public function regenerate(int $id): Response
|
|
{
|
|
$result = (new DocumentGenerateService())->regenerate($id);
|
|
return success('REGENERATE_SUCCESS', $result);
|
|
}
|
|
|
|
/**
|
|
* 下载生成的文档
|
|
* @param int $id
|
|
* @return Response
|
|
*/
|
|
public function download(int $id): Response
|
|
{
|
|
$result = (new DocumentGenerateService())->download($id);
|
|
|
|
if (!$result['success']) {
|
|
return fail($result['error']);
|
|
}
|
|
|
|
return download($result['file_path'], $result['file_name']);
|
|
}
|
|
|
|
/**
|
|
* 删除生成记录
|
|
* @param int $id
|
|
* @return Response
|
|
*/
|
|
public function del(int $id): Response
|
|
{
|
|
(new DocumentGenerateService())->del($id);
|
|
return success('DELETE_SUCCESS');
|
|
}
|
|
|
|
/**
|
|
* 批量删除生成记录
|
|
* @return Response
|
|
*/
|
|
public function batchDel(): Response
|
|
{
|
|
$ids = $this->request->param('ids', []);
|
|
if (empty($ids)) {
|
|
return fail('请选择要删除的记录');
|
|
}
|
|
|
|
(new DocumentGenerateService())->batchDel($ids);
|
|
return success('BATCH_DELETE_SUCCESS');
|
|
}
|
|
|
|
/**
|
|
* 获取生成统计信息
|
|
* @return Response
|
|
*/
|
|
public function getStats(): Response
|
|
{
|
|
$templateId = $this->request->param('template_id', 0);
|
|
return success((new DocumentGenerateService())->getStats($templateId));
|
|
}
|
|
|
|
/**
|
|
* 预览文档数据
|
|
* @return Response
|
|
*/
|
|
public function preview(): Response
|
|
{
|
|
$data = $this->request->params([
|
|
['template_id', 0],
|
|
['fill_data', []]
|
|
]);
|
|
|
|
$this->validate($data, 'app\validate\document\DocumentGenerate.preview');
|
|
|
|
return success((new DocumentGenerateService())->preview($data['template_id'], $data['fill_data']));
|
|
}
|
|
}
|
|
|