报表标准插件扩展方案原创
4人赞赏了该文章
1,949次浏览
编辑于2023年12月01日 17:41:22
关键词:附件、附件模板
一、需求
标准应用模块开发了下面的采购订单报表,二开扩展报表,并添加各个物料对应的采购总数量。
二、思路与方案
首先,看报表列表插件的query方法是否支持继承,如支持继承,可以直接继承报表列表插件,并获取父类的DataSet结果集进行合并,生成新的结果集返回给query方法,如不支持继承插件,则通过装饰者模式在不必改变原类文件和使用继承的情况下,动态地扩展一个对象。
三、实现过程
1、直接继承插件
/** * 标准报表取数插件 */ public class OrderReportListDataPlugin extends AbstractReportListDataPlugin implements Plugin { @Override public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable { QFilter qFilter1 = new QFilter("kded_entryentity.kded_materielfield", QCP.large_than,0); QFilter qFilter2 = new QFilter("kded_entryentity.kded_amountfield", QCP.is_notnull,null); DataSet kded_oderbill = QueryServiceHelper.queryDataSet(this.getClass().getName(), "kded_oderbill", "kded_entryentity.kded_materielfield as kded_mater,kded_entryentity.kded_amountfield as kded_amount", new QFilter[]{qFilter1,qFilter2},null); DataSet resultDS = kded_oderbill.groupBy(new String[]{"kded_mater"}).sum("kded_amount").finish(); return resultDS; } }
二开扩展时,直接继承源插件OrderReportListDataPlugin
//二开扩展插件 public class OrderReportListDataEXTPlugin extends OrderReportListDataPlugin implements Plugin { @Override public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable { QFilter qFilter1 = new QFilter("kded_entryentity.kded_materielfield", QCP.large_than,0); QFilter qFilter2 = new QFilter("kded_entryentity.kded_qtyfield", QCP.is_notnull,null); //查询数据 DataSet kded_oderbill = QueryServiceHelper.queryDataSet(this.getClass().getName(), "kded_oderbill", "kded_entryentity.kded_materielfield as kded_mater,kded_entryentity.kded_qtyfield as kded_qty", new QFilter[]{qFilter1,qFilter2},null); DataSet qtyDs = kded_oderbill.groupBy(new String[]{"kded_mater"}).sum("kded_qty").finish(); //获取父类查询数据 DataSet superDs = super.query(reportQueryParam, o); //join连接上本次查询的数据 DataSet resultDS = superDs.join(qtyDs).on("kded_mater", "kded_mater").select(new String[]{"kded_mater","kded_amount"},new String[]{"kded_qty"}).finish(); return resultDS; } }
添加一个整数字段,并把二开继承插件注册到报表列表的查询插件中
2、装饰者模式扩展插件对象
如下,当标准报表插件的query方法为final类型时,无法通过继承的模式去重写父类query方法
/** * 标准采购订单报表查询插件 */ public class OrderReportListDataFinalPlugin extends AbstractReportListDataPlugin implements Plugin { @Override public final DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable { QFilter qFilter1 = new QFilter("kded_entryentity.kded_materielfield", QCP.large_than,0); QFilter qFilter2 = new QFilter("kded_entryentity.kded_amountfield", QCP.is_notnull,null); DataSet kded_oderbill = QueryServiceHelper.queryDataSet(this.getClass().getName(), "kded_oderbill", "kded_entryentity.kded_materielfield as kded_mater,kded_entryentity.kded_amountfield as kded_amount", new QFilter[]{qFilter1,qFilter2},null); DataSet resultDS = kded_oderbill.groupBy(new String[]{"kded_mater"}).sum("kded_amount").finish(); return resultDS; } }
只能通过装饰者模式直接new一个对象去调用query方法获取原有的查询结果集
/** * 报表取数 */ public class OrderReportListDataFinalEXTPlugin extends AbstractReportListDataPlugin implements Plugin { @Override public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable { QFilter qFilter1 = new QFilter("kded_entryentity.kded_materielfield", QCP.large_than,0); QFilter qFilter2 = new QFilter("kded_entryentity.kded_qtyfield", QCP.is_notnull,null); //查询数据 DataSet kded_oderbill = QueryServiceHelper.queryDataSet(this.getClass().getName(), "kded_oderbill", "kded_entryentity.kded_materielfield as kded_mater,kded_entryentity.kded_qtyfield as kded_qty", new QFilter[]{qFilter1,qFilter2},null); DataSet qtyDs = kded_oderbill.groupBy(new String[]{"kded_mater"}).sum("kded_qty").finish(); AbstractReportListDataPlugin abstractReportListDataPlugin = new OrderReportListDataFinalPlugin(); //通过装饰者模式获取父类查询数据 DataSet superDs = abstractReportListDataPlugin.query(reportQueryParam,o); //join连接上本次查询的数据 DataSet resultDS = superDs.join(qtyDs).on("kded_mater", "kded_mater").select(new String[]{"kded_mater","kded_amount"},new String[]{"kded_qty"}).finish(); return resultDS; } }
四、效果图
预览报表,如下申请数量已添加到报表中
五、开发环境版本
V5.0.002
六、参考资料
demoj.zip(3.14KB)
kded_mycloud-kded_reqord-20230 …(23.14KB)
赞 4
4人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读