public class PrintRefBillImagePlugin extends AbstractPrintPlugin {
//主数据源标识(采购订单formId) private static final String MAIN_DS = "kd_cgdd"; //自定义数据源标识 private static final String CUSTOM_DS = "imageDs"; //关联上游单据formId(采购申请单formId) private static final String REF_BILL = "kd_cgsqd";
@Override public void beforeLoadData(BeforeLoadDataEvent evt) { PrtDataSource dataSource = evt.getDataSource(); //在加载主数据数据之前,添加查询字段,这样后续的主数据源DataRowSet中将会查询出源单ID字段 if (MAIN_DS.equals(dataSource.getDsName()) && dataSource instanceof MainDataSource) { MainDataSource mainDataSource = (MainDataSource) dataSource; //查询字段添加源单ID mainDataSource.getQueryField().add("sourcebill"); } }
@Override public void loadCustomData(CustomDataLoadEvent evt) { final List<DataRowSet> customDataRows = evt.getCustomDataRows(); //加载自定义数据源,根据关联关系查询出上游单据中图片地址,构造自定义数据源数据包 if (CUSTOM_DS.equals(evt.getDataSource().getDsName())) { //获取主数据源数据 DataRowSet mainRowSet = this.getMainDataVisitor().getDataRowSet(); //拿到源单ID Object sourceBill = mainRowSet.getField("sourcebill").getValue(); //根据源单ID查询图片地址信息 DynamicObject refBillObj = BusinessDataServiceHelper.loadSingleFromCache(REF_BILL, "id,entryentity.recpayimage", new QFilter[]{new QFilter("id", QCP.equals, sourceBill)}); //该案例中图片地址在源单的分录中,故先获取分录数据 DynamicObjectCollection entryEntity = refBillObj.getDynamicObjectCollection("entryentity"); //遍历分类行,拿到其中图片地址信息,构造数据包 for (DynamicObject entryObj : entryEntity) { String imageUrl = entryObj.getString("recpayimage"); if (StringUtils.isNotBlank(imageUrl)) { DataRowSet dataRowSet = new DataRowSet(); //根据图片地址信息构造图片字段,图片字段使用ImageField dataRowSet.put("imageUrl", new ImageField(imageUrl)); customDataRows.add(dataRowSet); } } } }
} |