编写报表页面插件 extends AbstractReportFormPlugin
给查询条件加默认值 afterCreateNewData{}
验证查询 verifyQuery(ReportQueryParam queryParam){}:判断查询条件是否合理(比如为空),合理则返回true,否则false
private void buildRptParam(ReportQueryParam queryParam) {
FilterInfo filter = queryParam.getFilter();
this.quotaProParam.setOrg(org);
DynamicObjectCollection objs = (DynamicObjectCollection) filter.getFilterItem(QuotaProConstant.ZHNY_MATERIAL).getValue();
if (objs != null && !objs.isEmpty()){
for (DynamicObject obj : objs) {
quotaProParam.addMtls((Long) obj.getPkValue());
Date effBeginDate = filter.getDate(QuotaProConstant.ZHNY_EFFBEGINDATE);
quotaProParam.setEffBeginDate(effBeginDate);
Date effEndDate = filter.getDate(QuotaProConstant.ZHNY_EFFENDDATE);
quotaProParam.setEffEndDate(effEndDate);
Date expBeginDate = filter.getDate(QuotaProConstant.ZHNY_EXPBEGINDATE);
quotaProParam.setExpBeginDate(expBeginDate);
Date expEndDate = filter.getDate(QuotaProConstant.ZHNY_EXPENDDATE);
quotaProParam.setExpEndDate(expEndDate);
getParams(filter, QuotaProConstant.ZHNY_SUPPLIER);
getParams(filter, QuotaProConstant.ZHNY_OPERATORGROUP);
getParams(filter, QuotaProConstant.ZHNY_OPERATOR);
this.getQueryParam().getCustomParam().put(QuotaProParam.class.getName(), quotaProParam);
数据查询前,进行上下文设置,处理过滤条件 注意:这里过滤的报表页面数据,所以使用报表页面字段
public void setupCtx(ReportDataCtx ctx) {
IReportDataHandle.super.setupCtx(ctx);
this.quotaProParam = ctx.getParam(QuotaProParam.class.getName());
QFilter filter = new QFilter(QuotaProConstant.ZHNY_ORG, QCP.equals, quotaProParam.getOrg());
public void modifyBlocks(List<SrcBlockConf> blockCollector, ReportDataCtx ctx) {
IReportDataHandle.super.modifyBlocks(blockCollector, ctx);
this.quotaProParam = ctx.getParam(QuotaProParam.class.getName());
for (SrcBlockConf blockConf : blockCollector){
String entity = blockConf.getSrcEntity();
if (blockConf.getDataFs() == null){
blockConf.setDataFs(new QFilter("1" ,QCP.equals,"1"));
filter = new QFilter("org", QCP.equals,quotaProParam.getOrg());
filter.and("material.masterid",QCP.in,quotaProParam.getMtls());
blockConf.getDataFs().and(filter);
public void transformResult(List<IDataTransform> transCollector, ReportDataCtx ctx) {
transCollector.add(new SrcDataSupPur(this.supPurRptParam));(e)
public void handleBigtableCols(Set<String> repoColFilter, ReportDataCtx ctx) {
IReportDataHandle.super.handleBigtableCols(repoColFilter, ctx);
public List<AbstractReportColumn> buildShowColumn(List<AbstractReportColumn> cols, ReportDataCtx ctx) {
return IReportDataHandle.super.buildShowColumn(cols, ctx);
数据处理类 SrcDataSupPur implements IDataTransform
public DataSet doTransform(DataSet srcData) {}
如果是基础资料类型的字段,就可以用维度,然后关闭默认显示,这样也能拼接
其他类型用维度,就算关闭默认显示,如果拼接还是会报已经存在这个字段的错误
public List<QFilter> getHeadFilters() {
public void setHeadFilters(List<QFilter> headFilters) {
this.headFilters = headFilters;
public void setSortAndFilter(List<SortAndFilterEvent> allColumns) {
super.setSortAndFilter(allColumns);
for (SortAndFilterEvent column : allColumns) {
String columnName = column.getColumnName();
if (!"zhny_deliverygroup".equals(columnName) && !"zhny_deliverygroup_ref_name".equals(columnName)){
public class Grp2StationRptListQuery extends AbstractReportQuery {
public ReportQueryParam getQueryParam() {
ReportQueryParam queryParam = super.getQueryParam();
Grp2StationRptParam rptParam = (Grp2StationRptParam) queryParam.getCustomParam().get("param");
rptParam.setHeadFilters(queryParam.getFilter().getHeadFilters());
public void setupCtx(ReportDataCtx ctx) {
IReportDataHandle.super.setupCtx(ctx);
this.param = ctx.getParam("param");
Set<String> cols = RptHeadFilterHelper.getMapCols(ctx);
RptHeadFilterHelper.setHeadFilter(ctx, param.getHeadFilters(), cols);
public static Set<String> getMapCols(ReportDataCtx ctx) {
List<SrcBlockConf> confList = ctx.getReportConf().getSrcBlockConf();
Set<String> keys = new HashSet<>(16);
for (SrcBlockConf conf : confList) {
Map<String, String> colMap = conf.getRepoColSrcColMap();
public DataSet doTransform(DataSet srcData) {
private DataSet doFilter(DataSet srcData){
Set<String> cols = getMapCols(ctx);
List<QFilter> headFilters = this.param.getHeadFilters();
List<QFilter> newFilters = headFilters.stream().filter(hf -> !cols.contains(hf.getProperty().split("\\.")[0]))
.collect(Collectors.toList());
for (QFilter headFilter : newFilters) {
srcData = srcData.filter(headFilter.toString());//普通过滤可直接添加
if ("zhny_recorddate".equals(headFilter.getProperty())){
Map<String, Object> params = new HashMap<>(16);
String filter = getDateFilter(headFilter, params);
srcData = srcData.filter(filter, params);
headFilter.__setValue(new BigDecimal((String) headFilter.getValue()));
headFilter.__setValue(Long.parseLong((String) headFilter.getValue()));
public static String getDateFilter(QFilter headFilter, Map<String, Object> params) {
StringBuilder filter = new StringBuilder();
Date date = (Date) headFilter.getValue();
filter.append(headFilter.getProperty()).append(" ").append(headFilter.getCP()).append(" ").append("date1").append(" ");
List<QFilter.QFilterNest> nests = headFilter.getNests(true);
for (QFilter.QFilterNest nest : nests) {
QFilter qFilter = nest.getFilter();
Date date2 = (Date) qFilter.getValue();
params.put("date" + (i + 1), date2);
filter.append(nest.getOp()).append(" ").append(qFilter.getProperty()).append(" ")
.append(qFilter.getCP()).append(" ").append("date").append(i + 1).append(" ");
注意事项:启用了字段映射必须填写至少一个字段的映射,否则报错
标签:报表,步骤,ctx,filter,急速,过滤,headFilter,数据源,append From: https://www.cnblogs.com/lcyyds/p/17514093.html