全自动选单跳过选单界面原创
11人赞赏了该文章
2,201次浏览
编辑于2021年08月24日 13:36:18
跳过选择转换规则与选单数据界面通过代码赋值
public class DrawBillPlugin extends AbstractBillPlugIn { @Override public void beforeDoOperation(BeforeDoOperationEventArgs args) { super.beforeDoOperation(args); AbstractOperate draw = (AbstractOperate)args.getSource(); if(StringUtils.equals("draw",draw.getOperateKey())){ ConvertOpParameter convertOpParameter = buildParameter(draw); ListSelectedRowCollection srcRows = new ListSelectedRowCollection(); ListSelectedRow row = new ListSelectedRow("pkValue", true); row.setBillNo("单据编号"); row.setBillStatus("单据状态 B"); row.setMainOrgId("组织ID"); row.setBillTypeID(0L); row.setRowKey(0); row.setPageIndex(0); srcRows.add(row); doDraw(convertOpParameter,srcRows); args.setCancel(true); } } @Override public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) { super.afterDoOperation(afterDoOperationEventArgs); } /** * 构建下推操作参数 * @return */ protected ConvertOpParameter buildParameter(AbstractOperate draw){ ConvertOpParameter opParameter = new ConvertOpParameter(); opParameter.setOpType(ConvertOpType.Draw); String entityNumber = this.getView().getEntityId(); opParameter.setEntityNumber(entityNumber); opParameter.setTargetBillPageId(this.getView().getPageId()); opParameter.setDefSourceBill("源单编码"); opParameter.setDefRuleId("默认转换规则"); opParameter.getClearEntrys().addAll(new ArrayList()); // 直接选单,跳过选单界面:判断指定的源单、规则是否存在、启用 List<ConvertRuleElement> rules = this.loadRules("源单编码", entityNumber); ConvertRuleElement defRule = null; for(ConvertRuleElement rule : rules) { if (!rule.isEnabled()) { continue; } if (StringUtils.equals(rule.getId(), "默认编码规则")) { defRule = rule; break; } } if (defRule != null) { ConvertBill bill = new ConvertBill(); bill.setEntityNumber("源单编码"); bill.setEntityName("源单编码"); ConvertOpRule opRule = new ConvertOpRule(); opRule.setRuleId(defRule.getId()); bill.getRules().add(opRule); opParameter.getBills().add(bill); } // 自定义参数 if (draw.getOption() != null) { opParameter.getCustomParams().putAll(draw.getOption().getVariables()); } return opParameter; } private List<ConvertRuleElement> loadRules(String sourceEntityNumber, String targetEntityNumber) { List<ConvertRuleElement> rules = ConvertRuleCache.loadRules(sourceEntityNumber, targetEntityNumber); List<ConvertRuleElement> enableRules = new ArrayList(); Iterator var5 = rules.iterator(); while(var5.hasNext()) { ConvertRuleElement rule = (ConvertRuleElement)var5.next(); if (rule.isEnabled()) { enableRules.add(rule); } } return enableRules; } public void doDraw( ConvertOpParameter opParameter, ListSelectedRowCollection srcRows) { if (srcRows != null && srcRows.size() != 0) { String sourceEntityNumber = opParameter.getDefSourceBill(); String ruleId = opParameter.getDefRuleId(); DrawArgs args = new DrawArgs(); args.setSourceEntityNumber(sourceEntityNumber); args.setTargetEntityNumber(opParameter.getEntityNumber()); args.addCustomParam("botp_requiredatamutex", String.valueOf(true)); args.getSelectedRows().addAll(srcRows); args.setTargetPageId(opParameter.getTargetBillPageId()); args.setRuleId(ruleId); args.setBuildConvReport(true); args.getClearEntrys().addAll(opParameter.getClearEntrys()); args.getCustomParams().putAll(opParameter.getCustomParams()); ConvertOperationResult result = ConvertServiceHelper.draw(args); if (result.isSuccess() && result.getCachePageIds().size() != 0) { IRefrencedataProvider refProvider = new IRefrencedataProvider() { @Override public void fillReferenceData(Object[] dataEntitys, IDataEntityType type) { BusinessDataReader.loadRefence(dataEntitys, type); } }; List<DynamicObject> dataEntitys = result.loadTargetDataObjects(refProvider,this.getView().getModel().getDataEntityType()); ((IBillModel)this.getView().getModel()).push(dataEntitys.get(0)); this.getView().updateView(); result.release(refProvider, this.getView().getModel().getDataEntityType()); } else { Push.showReport(this.getView(), args, result); } } } }