public class EntrySelectedPrintPlugin extends AbstractPrintPlugin { //单据体标识 private static final String ENTRY_FIELD = "entryentity"; @Override public void afterLoadData(AfterLoadDataEvent evt) { super.afterLoadData(evt); final PrtDataSource dataSource; //数据源为主数据源类型 if (!((dataSource = evt.getDataSource()) instanceof MainDataSource)) { return; } String pageId; // pageId不可以为空 if (StringUtils.isBlank(pageId = ((MainDataSource)dataSource).getPageId())) { return; } int[] selectRows; final EntryGrid entryEntity = SessionManager.getCurrent().getView(pageId).getControl(ENTRY_FIELD); //分录控件存在,且所选分录至少勾选一行 if (entryEntity == null || (selectRows = entryEntity.getSelectRows()).length <= 0) { return; } //移除未勾选的分录行 for (DataRowSet row : evt.getDataRowSets()) { List<DataRowSet> entryRows = row.getCollectionField(ENTRY_FIELD).getValue(); List<DataRowSet> moveRows = new ArrayList<>(selectRows.length); Arrays.stream(selectRows).forEach(index -> moveRows.add(entryRows.get(index))); row.getCollectionField(ENTRY_FIELD).setValue(moveRows); } } } |