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.
241 lines
6.2 KiB
241 lines
6.2 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\DocumentTemplateService;
|
|
use think\facade\Request;
|
|
|
|
/**
|
|
* Word文档模板解析控制器
|
|
* Class DocumentTemplate
|
|
* @package app\adminapi\controller\document
|
|
*/
|
|
class DocumentTemplate extends BaseAdminController
|
|
{
|
|
/**
|
|
* 获取模板列表
|
|
* @return \think\Response
|
|
*/
|
|
public function lists()
|
|
{
|
|
$data = $this->request->params([
|
|
["contract_status", ""],
|
|
["contract_type", ""],
|
|
["contract_name", ""],
|
|
["created_at", ["", ""]]
|
|
]);
|
|
return success((new DocumentTemplateService())->getPage($data));
|
|
}
|
|
|
|
/**
|
|
* 模板详情
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
public function info(int $id)
|
|
{
|
|
return success((new DocumentTemplateService())->getInfo($id));
|
|
}
|
|
|
|
/**
|
|
* 上传Word模板文件
|
|
* @return \think\Response
|
|
*/
|
|
public function uploadTemplate()
|
|
{
|
|
try {
|
|
$file = Request::file('file');
|
|
if (!$file) {
|
|
return fail('FILE_UPLOAD_REQUIRED');
|
|
}
|
|
|
|
$result = (new DocumentTemplateService())->uploadTemplate($file);
|
|
return success('UPLOAD_SUCCESS', $result);
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 解析Word模板占位符
|
|
* @return \think\Response
|
|
*/
|
|
public function parsePlaceholder()
|
|
{
|
|
$data = $this->request->params([
|
|
["template_path", ""],
|
|
["template_id", 0]
|
|
]);
|
|
|
|
try {
|
|
$result = (new DocumentTemplateService())->parsePlaceholder($data);
|
|
return success('PARSE_SUCCESS', $result);
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 保存占位符配置
|
|
* @return \think\Response
|
|
*/
|
|
public function savePlaceholderConfig()
|
|
{
|
|
$data = $this->request->params([
|
|
["template_id", 0],
|
|
["placeholder_config", []]
|
|
]);
|
|
|
|
$this->validate($data, 'app\validate\document\DocumentTemplate.savePlaceholderConfig');
|
|
|
|
try {
|
|
(new DocumentTemplateService())->savePlaceholderConfig($data);
|
|
return success('SAVE_SUCCESS');
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取可用数据源列表(安全白名单)
|
|
* @return \think\Response
|
|
*/
|
|
public function getDataSources()
|
|
{
|
|
try {
|
|
$result = (new DocumentTemplateService())->getDataSources();
|
|
return success('SUCCESS', $result);
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 生成Word文档
|
|
* @return \think\Response
|
|
*/
|
|
public function generateDocument()
|
|
{
|
|
$data = $this->request->params([
|
|
["template_id", 0],
|
|
["fill_data", []],
|
|
["output_filename", ""]
|
|
]);
|
|
|
|
$this->validate($data, 'app\validate\document\DocumentTemplate.generateDocument');
|
|
|
|
try {
|
|
$result = (new DocumentTemplateService())->generateDocument($data);
|
|
return success('GENERATE_SUCCESS', $result);
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 下载生成的文档
|
|
* @param int $log_id
|
|
* @return \think\Response
|
|
*/
|
|
public function downloadDocument(int $log_id)
|
|
{
|
|
try {
|
|
return (new DocumentTemplateService())->downloadDocument($log_id);
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取文档生成记录
|
|
* @return \think\Response
|
|
*/
|
|
public function getGenerateLog()
|
|
{
|
|
$data = $this->request->params([
|
|
["template_id", 0],
|
|
["user_id", 0],
|
|
["status", ""],
|
|
["created_at", ["", ""]]
|
|
]);
|
|
|
|
return success((new DocumentTemplateService())->getGenerateLog($data));
|
|
}
|
|
|
|
/**
|
|
* 预览模板内容
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
public function previewTemplate(int $id)
|
|
{
|
|
try {
|
|
$result = (new DocumentTemplateService())->previewTemplate($id);
|
|
return success('SUCCESS', $result);
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除模板
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
public function delete(int $id)
|
|
{
|
|
try {
|
|
(new DocumentTemplateService())->delete($id);
|
|
return success('DELETE_SUCCESS');
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 复制模板
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
public function copy(int $id)
|
|
{
|
|
try {
|
|
$result = (new DocumentTemplateService())->copy($id);
|
|
return success('COPY_SUCCESS', $result);
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 批量删除生成记录
|
|
* @return \think\Response
|
|
*/
|
|
public function batchDeleteLog()
|
|
{
|
|
$data = $this->request->params([
|
|
["ids", []]
|
|
]);
|
|
|
|
if (empty($data['ids'])) {
|
|
return fail('PARAM_ERROR');
|
|
}
|
|
|
|
try {
|
|
(new DocumentTemplateService())->batchDeleteLog($data['ids']);
|
|
return success('DELETE_SUCCESS');
|
|
} catch (\Exception $e) {
|
|
return fail($e->getMessage());
|
|
}
|
|
}
|
|
}
|