diff --git a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/ReportTemplateController.java b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/ReportTemplateController.java index 06cf3df39..38b74102a 100644 --- a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/ReportTemplateController.java +++ b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/ReportTemplateController.java @@ -12,6 +12,7 @@ import com.bstek.ureport.utils.StringUtils; import com.cf.imes.framework.common.exception.ServiceException; import com.cf.imes.framework.common.pojo.CommonResult; import com.cf.imes.framework.common.util.object.BeanUtils; +import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateCommonPreviewReqVO; import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplatePreviewReqVO; import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateReqVO; import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateRespVO; @@ -114,6 +115,12 @@ public class ReportTemplateController { return success(templateService.preview(reqVO)); } + @PostMapping("/template/preview/common/") + @Operation(summary = "模板通用预览") + public CommonResult commonPreview(@RequestBody ReportTemplateCommonPreviewReqVO reqVO) { + return success(templateService.commonPreview(reqVO)); + } + @PostMapping("/template/print") @Operation(summary = "模板预览打印") @PreAuthorize("@ss.hasPermission('report:preview')") diff --git a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/vo/ReportTemplateCommonPreviewReqVO.java b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/vo/ReportTemplateCommonPreviewReqVO.java new file mode 100644 index 000000000..f1f94fd03 --- /dev/null +++ b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/controller/admin/template/vo/ReportTemplateCommonPreviewReqVO.java @@ -0,0 +1,47 @@ +package com.cf.imes.module.report.controller.admin.template.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.Map; + +/** + * @author Gqr + * @since 2024/7/19 9:22 + */ +@Data +@Schema(description = "管理后台 - 报表模板通用预览请求参数 Request VO") +public class ReportTemplateCommonPreviewReqVO { + @Schema(description = "页码",example = "1") + @Min(value = 1, message = "页码最小值为 1") + private int pageIndex; + + @Schema(description = "报表模板编号") + @NotNull(message = "报表模板编号不能为空") + private Long templateId; + + /** + * 表单参数 + */ + @Schema(description = "表单参数") + @Size(max = 30, message = "表单参数数量不能超过30个") + private Map query; + + /** + * 表单对应组件唯一标识 + */ + @Schema(description = "表单对应组件唯一标识") + @Size(max = 30, message = "表单对应组件唯一标识数量不能超过30个") + private Map component; + + /** + * 图表图片目前用于PDF导出 + */ + @Schema(description = "图表图片") + @Size(max = 30, message = "图表图片数量不能超过30个") + private Map chartImages; + +} \ No newline at end of file diff --git a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateService.java b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateService.java index 88fce28ea..6630644ef 100644 --- a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateService.java +++ b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateService.java @@ -2,6 +2,7 @@ package com.cf.imes.module.report.service.template; import com.bstek.designer.bean.ReportDefinitionWrapper; import com.bstek.ureport.export.html.HtmlReport; +import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateCommonPreviewReqVO; import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplatePreviewReqVO; import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateReqVO; import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateRespVO; @@ -30,6 +31,7 @@ public interface ReportTemplateService { /** * 复制报表模版 + * * @param createReqVO * @return */ @@ -81,6 +83,16 @@ public interface ReportTemplateService { */ HtmlReport preview(ReportTemplatePreviewReqVO reqVO); + + /** + * 模板通用预览 + * 通过模板id+query参数获取预览界面 + * + * @param reqVO + * @return + */ + HtmlReport commonPreview(ReportTemplateCommonPreviewReqVO reqVO); + /** * 模版预览打印 */ diff --git a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateServiceImpl.java b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateServiceImpl.java index cef2e3949..ff01391b8 100644 --- a/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateServiceImpl.java +++ b/cf-module-report/cf-module-report-biz/src/main/java/com/cf/imes/module/report/service/template/ReportTemplateServiceImpl.java @@ -45,6 +45,7 @@ import com.cf.imes.framework.organ.core.aop.OrganIgnore; import com.cf.imes.framework.organ.core.context.OrganContextHolder; import com.cf.imes.framework.security.core.LoginUser; import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils; +import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateCommonPreviewReqVO; import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplatePreviewReqVO; import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateReqVO; import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateRespVO; @@ -86,6 +87,7 @@ import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_IMPORT import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_NAME_UNIQE_ERROR; import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_NOT_EXISTS; import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_PREIVEW_QUERYPARAM_EMPTY; +import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_PREVIEW_TEMPLATE_CONTENT_EMPTY_ERROR; /** * 报表模板信息 Service 实现类 @@ -424,9 +426,40 @@ public class ReportTemplateServiceImpl implements ReportTemplateService { HtmlProducer htmlProducer = new HtmlProducer(); ReportRender reportRender = new ReportRender(); - ReportDefinition reportDefinition = getReportDefinition(reportRender, params); - Map parameters = params.getQuery(); + ReportDefinition reportDefinition = getReportDefinition(reportRender, params, true); + // 增加多租户参数 + Map parameters = params.getQuery(); + tenantParamsUtils.prepareTenantParam(parameters); + Report report = reportRender.render(reportDefinition, parameters); + return htmlProducer.produce(reportDefinition, report); + } + + @Override + public HtmlReport commonPreview(ReportTemplateCommonPreviewReqVO reqVO) { + // 检查查询参数中的空值 + checkQueryNotEmpty(reqVO.getQuery()); + // 查询模板 + ReportTemplateDO reportTemplateDO = templateMapper.selectById(reqVO.getTemplateId()); + if (ObjectUtil.isNull(reportTemplateDO)) { + throw exception(TEMPLATE_NOT_EXISTS); + } + // 检查模板内容 + String content = reportTemplateDO.getContent(); + if (StringUtils.isEmpty(content)) { + throw exception(TEMPLATE_PREVIEW_TEMPLATE_CONTENT_EMPTY_ERROR); + } + // 自定义请求vo转ureport对象 + PreviewParameters params = BeanUtils.toBean(reqVO, PreviewParameters.class); + params.setContent(content); + + // 生成html + HtmlProducer htmlProducer = new HtmlProducer(); + ReportRender reportRender = new ReportRender(); + ReportDefinition reportDefinition = getReportDefinition(reportRender, params, false); + + // 增加多租户参数 + Map parameters = params.getQuery(); tenantParamsUtils.prepareTenantParam(parameters); Report report = reportRender.render(reportDefinition, parameters); return htmlProducer.produce(reportDefinition, report); @@ -439,7 +472,7 @@ public class ReportTemplateServiceImpl implements ReportTemplateService { long start = System.currentTimeMillis(); ReportRender reportRender = new ReportRender(); - ReportDefinition reportDefinition = getReportDefinition(reportRender, params); + ReportDefinition reportDefinition = getReportDefinition(reportRender, params, true); Map query = params.getQuery(); // 增加多租户参数 tenantParamsUtils.prepareTenantParam(query); @@ -471,7 +504,7 @@ public class ReportTemplateServiceImpl implements ReportTemplateService { PreviewParameters params = BeanUtils.toBean(reqVO, PreviewParameters.class); ReportRender reportRender = new ReportRender(); - ReportDefinition reportDefinition = getReportDefinition(reportRender, params); + ReportDefinition reportDefinition = getReportDefinition(reportRender, params, true); Map query = params.getQuery(); // 增加多租户参数 tenantParamsUtils.prepareTenantParam(query); @@ -545,7 +578,7 @@ public class ReportTemplateServiceImpl implements ReportTemplateService { getSelf().validateTemplateNameUnique(createReqVO, isSuperAdmin); // 复制信息 String content = jsonObject.getString("content"); - if(StringUtils.isEmpty(content)) { + if (StringUtils.isEmpty(content)) { throw new ServiceException(TEMPLATE_IMPORT_CONTENT_EMPTY_ERROR); } // 生成id @@ -572,12 +605,22 @@ public class ReportTemplateServiceImpl implements ReportTemplateService { } } - private ReportDefinition getReportDefinition(ReportRender reportRender, PreviewParameters params) { + /** + * 获取报表定义 + * + * @param reportRender 报表渲染器 + * @param params 预览参数 + * @param needDecode 是否需要解码(从前端直接拿来的需要url解码) + * @return + */ + private ReportDefinition getReportDefinition(ReportRender reportRender, PreviewParameters params, boolean needDecode) { ReportDefinition reportDefinition; String content = params.getContent(); if (StringUtils.isNotBlank(content)) { - content = URLUtil.decode(content); + if (needDecode) { + content = URLUtil.decode(content); + } reportDefinition = reportRender.getReportDefinition(content, "utf-8"); } else { throw new ReportComputeException("模版文件不能为空");