update:完善文档模板导出功能

This commit is contained in:
hewencai
2025-11-11 09:27:22 +08:00
parent b4540badbb
commit 34ca30bb8b
44 changed files with 2134 additions and 45 deletions

View File

@@ -7,15 +7,19 @@ import com.zt.plat.module.base.controller.admin.doctemplate.vo.DocTemplateInstan
import com.zt.plat.module.base.controller.admin.doctemplate.vo.DocTemplateInstanceSaveReqVO;
import com.zt.plat.module.base.service.doctemplate.DocTemplateInstanceService;
import com.zt.plat.module.base.service.doctemplate.DocTemplateRenderService;
import com.zt.plat.module.base.service.doctemplate.DocumentRenderApiService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
@@ -38,6 +42,9 @@ public class DocTemplateInstanceController {
@Resource
private DocTemplateRenderService renderService;
@Resource
private DocumentRenderApiService documentRenderApiService;
@PostMapping("/create")
@Operation(summary = "创建模板实例")
@PreAuthorize("@ss.hasPermission('base:template-instance:create')")
@@ -104,4 +111,35 @@ public class DocTemplateInstanceController {
return success(true);
}
@PostMapping("/render-and-export-word")
@Operation(summary = "渲染实例并导出为Word")
@PreAuthorize("@ss.hasPermission('base:template-instance:query')")
public ResponseEntity<byte[]> renderAndExportToWord(
@Parameter(name = "instanceId", description = "实例ID", required = true) @RequestParam("instanceId") Long instanceId,
@Parameter(name = "fileName", description = "文件名") @RequestParam(value = "fileName", required = false) String fileName,
@Parameter(name = "dataMap", description = "数据Map") @RequestBody(required = false) Map<String, Object> dataMap) {
byte[] fileContent = documentRenderApiService.renderAndExportToWord(instanceId, dataMap, fileName);
String actualFileName = (fileName != null ? fileName : "document") + ".docx";
String encodedFileName = URLEncoder.encode(actualFileName, StandardCharsets.UTF_8).replace("+", "%20");
return ResponseEntity.ok()
.header("Content-Disposition", "attachment; filename=\"document.docx\"; filename*=UTF-8''" + encodedFileName)
.header("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
.body(fileContent);
}
@PostMapping("/export-html-to-word")
@Operation(summary = "导出HTML为Word文档")
@PreAuthorize("@ss.hasPermission('base:template-instance:query')")
public ResponseEntity<byte[]> exportHtmlToWord(
@Parameter(name = "html", description = "HTML内容", required = true) @RequestBody String html,
@Parameter(name = "fileName", description = "文件名") @RequestParam(value = "fileName", required = false) String fileName) {
byte[] fileContent = documentRenderApiService.exportToWord(html, fileName);
String actualFileName = (fileName != null ? fileName : "document") + ".docx";
String encodedFileName = URLEncoder.encode(actualFileName, StandardCharsets.UTF_8).replace("+", "%20");
return ResponseEntity.ok()
.header("Content-Disposition", "attachment; filename=\"document.docx\"; filename*=UTF-8''" + encodedFileName)
.header("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
.body(fileContent);
}
}

View File

@@ -0,0 +1,19 @@
package com.zt.plat.module.base.controller.admin.doctemplate.render.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BusinessExportRequest {
private Long templateInstanceId;
private String businessType;
private Long businessId;
private Map<String, String> fieldMappings;
}

View File

@@ -0,0 +1,19 @@
package com.zt.plat.module.base.controller.admin.doctemplate.render.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BusinessPreviewRequest {
private Long templateInstanceId;
private String businessType;
private Long businessId;
private Map<String, String> fieldMappings;
}

View File

@@ -0,0 +1,17 @@
package com.zt.plat.module.base.controller.admin.doctemplate.render.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CustomExportRequest {
private Long templateInstanceId;
private Map<String, Object> customData;
}

View File

@@ -0,0 +1,17 @@
package com.zt.plat.module.base.controller.admin.doctemplate.render.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CustomPreviewRequest {
private Long templateInstanceId;
private Map<String, Object> customData;
}

View File

@@ -34,9 +34,21 @@ public class DocTemplateCategoryRespVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
@Schema(description = "创建人", example = "admin")
@Schema(description = "创建人ID", example = "1")
private String creator;
@Schema(description = "创建人名称", example = "管理员")
private String creatorName;
@Schema(description = "更新时间")
private LocalDateTime updateTime;
@Schema(description = "更新人ID", example = "1")
private String updater;
@Schema(description = "更新人名称", example = "管理员")
private String updaterName;
@Schema(description = "子分类列表")
private List<DocTemplateCategoryRespVO> children;

View File

@@ -42,6 +42,24 @@ public class DocTemplateInstanceRespVO {
@Schema(description = "状态", example = "draft")
private String status;
@Schema(description = "SQL配置JSON格式", example = "{}")
private String sqlConfig;
@Schema(description = "数据源标识", example = "default")
private String dataSource;
@Schema(description = "分类ID", example = "1")
private Long categoryId;
@Schema(description = "图标", example = "icon-file")
private String icon;
@Schema(description = "描述", example = "采购合同模板实例")
private String description;
@Schema(description = "版本号", example = "v1.0")
private String version;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

View File

@@ -33,8 +33,7 @@ public class DocTemplateInstanceSaveReqVO {
@Schema(description = "业务关联标签", example = "PC-2025-001")
private String businessLabel;
@Schema(description = "用户编辑后的内容", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "内容不能为空")
@Schema(description = "用户编辑后的内容(创建时可为空,将自动从模板复制)")
private String editedContent;
@Schema(description = "渲染后的最终内容")
@@ -46,4 +45,22 @@ public class DocTemplateInstanceSaveReqVO {
@Schema(description = "状态", example = "draft")
private String status;
@Schema(description = "SQL配置JSON格式", example = "{}")
private String sqlConfig;
@Schema(description = "数据源标识", example = "default")
private String dataSource;
@Schema(description = "分类ID", example = "1")
private Long categoryId;
@Schema(description = "图标", example = "icon-file")
private String icon;
@Schema(description = "描述", example = "采购合同模板实例")
private String description;
@Schema(description = "版本号", example = "v1.0")
private String version;
}

View File

@@ -23,11 +23,8 @@ public class DocTemplatePageReqVO extends PageParam {
@Schema(description = "模板编码", example = "PO_CONTRACT_001")
private String tmplCode;
@Schema(description = "所属", example = "1")
private Long bigCategoryId;
@Schema(description = "所属小类", example = "11")
private Long smallCategoryId;
@Schema(description = "所属", example = "1")
private Long categoryId;
@Schema(description = "状态1=启用0=停用2=草稿)", example = "1")
private String enabled;

Some files were not shown because too many files have changed in this diff Show More