mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 12:52:07 +08:00
报表基础模块:新增通用预览模块,基于模版id+查询参数预览
This commit is contained in:
+7
@@ -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<HtmlReport> commonPreview(@RequestBody ReportTemplateCommonPreviewReqVO reqVO) {
|
||||
return success(templateService.commonPreview(reqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/template/print")
|
||||
@Operation(summary = "模板预览打印")
|
||||
@PreAuthorize("@ss.hasPermission('report:preview')")
|
||||
|
||||
+47
@@ -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<String, Object> query;
|
||||
|
||||
/**
|
||||
* 表单对应组件唯一标识
|
||||
*/
|
||||
@Schema(description = "表单对应组件唯一标识")
|
||||
@Size(max = 30, message = "表单对应组件唯一标识数量不能超过30个")
|
||||
private Map<String, String> component;
|
||||
|
||||
/**
|
||||
* 图表图片目前用于PDF导出
|
||||
*/
|
||||
@Schema(description = "图表图片")
|
||||
@Size(max = 30, message = "图表图片数量不能超过30个")
|
||||
private Map<String, String> chartImages;
|
||||
|
||||
}
|
||||
+12
@@ -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);
|
||||
|
||||
/**
|
||||
* 模版预览打印
|
||||
*/
|
||||
|
||||
+50
-7
@@ -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<String, Object> parameters = params.getQuery();
|
||||
ReportDefinition reportDefinition = getReportDefinition(reportRender, params, true);
|
||||
|
||||
// 增加多租户参数
|
||||
Map<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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("模版文件不能为空");
|
||||
|
||||
Reference in New Issue
Block a user