通过插件调用botp生成目标单并提交审核原创
159次浏览
编辑于2024年05月16日 16:33:29
public static void doPush(DynamicObjectCollection objects, String ruleId,String sourceBill,String targetBill) { // 创建下推参数 PushArgs pushArgs = new PushArgs(); pushArgs.setSourceEntityNumber(sourceBill); // 必选,源单标识 pushArgs.setTargetEntityNumber(targetBill); // 必选,目标单标识 //pushArgs.setHasRight(false); // 可选,传入true,不检查目标单新增权 //pushArgs.setAppId(""); // 可选,传入目标单验权使用的应用编码 //pushArgs.setDefOrgId(0L); // 可选,传入目标单主组织默认值 pushArgs.setRuleId(ruleId); // 可选,传入本次下推使用的转换规则id;传入空值,由系统自动寻找合适的转换规则 pushArgs.setBuildConvReport(true); // 是否输出详细错误报告 // 设置需要下推的单据,或分录行 if (!objects.isEmpty() && objects.size() > 0) { List<ListSelectedRow> selectedRows = new ArrayList<>(); for (DynamicObject obj : objects) { ListSelectedRow row = new ListSelectedRow(); row.setPrimaryKeyValue(obj.getLong("id")); row.setEntryEntityKey("billentry"); row.setEntryPrimaryKeyValue(obj.getLong("entryid")); selectedRows.add(row); } pushArgs.setSelectedRows(selectedRows); // 必选,设置需要下推的源单及分录内码 // 调用下推引擎,下推目标单 ConvertOperationResult pushResult = ConvertServiceHelper.push(pushArgs); // 判断下推是否成功,如果失败,提炼失败消息输出 if (!pushResult.isSuccess()) { String failMessage = pushResult.getBillReports().get(0).getFailMessage(); throw new KDBizException("下推失败:" + failMessage); } // 获取生成的目标单数据包 MainEntityType targetMainType = EntityMetadataCache.getDataEntityType(targetBill); List<DynamicObject> targetBillObjs = pushResult.loadTargetDataObjects(new IRefrencedataProvider() { @Override public void fillReferenceData(Object[] objs, IDataEntityType dType) { BusinessDataReader.loadRefence(objs, dType); } }, targetMainType); // 设置保存参数,调用目标单保存服务,保存目标单(保存时自动反写源单) OperateOption saveOption = OperateOption.create(); saveOption.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(true)); // 不执行警告级别校验器 saveOption.setVariableValue(OperateOptionConst.IGNOREINTERACTION, String.valueOf(true)); // 不显示交互提示,自动执行到底 saveOption.setVariableValue(OperateOptionConst.STRICTVALIDATION, String.valueOf(true)); // 全部校验通过才保存 OperationResult saveResult = SaveServiceHelper.saveOperate( BillEntity.KEY_ENTITY_FINAPBILL, targetBillObjs.toArray(new DynamicObject[0]), saveOption); // 判断保存结果 if (saveResult.isSuccess()) { List<Object> successPkIds = saveResult.getSuccessPkIds(); //继续提交 OperationResult submit = getOperationResult("submit", targetBill, successPkIds.toArray()); if(submit.isSuccess()){ List<Object> auditSuccessPkIds = saveResult.getSuccessPkIds(); //继续审核 OperationResult audit = getOperationResult("audit", targetBill, auditSuccessPkIds.toArray()); if(!audit.isSuccess()){ throw new KDBizException("审核失败:" + getOperationResultErrorInfos(audit)); } }else{ throw new KDBizException("提交失败:" + getOperationResultErrorInfos(submit)); } } else { throw new KDBizException("保存失败:" + getOperationResultErrorInfos(saveResult)); } } } public static OperationResult getOperationResult(String optkey,String targetBill,Object[] ids) { OperateOption oOperateOption = OperateOption.create(); // 不执行警告级别校验器 oOperateOption.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(true)); // 不显示交互提示,自动执行到底 oOperateOption.setVariableValue(OperateOptionConst.IGNOREINTERACTION, String.valueOf(true)); // 全部校验通过才保存 oOperateOption.setVariableValue(OperateOptionConst.STRICTVALIDATION, String.valueOf(true)); OperationResult fkunauditResult = OperationServiceHelper.executeOperate(optkey,targetBill, ids, oOperateOption); return fkunauditResult; } public static String getOperationResultErrorInfos(OperationResult operationResult){ StringBuilder stringBuilder = new StringBuilder(); List<IOperateInfo> errorInfos = operationResult.getAllErrorOrValidateInfo(); //String errMessage = operationResult.getMessage(); // 错误摘要 stringBuilder.append("错误摘要:"+operationResult.getMessage()+"\n"+"详细信息:"); // 提取保存详细错误 for(IOperateInfo errInfo: errorInfos) { stringBuilder.append(errInfo.getMessage()); } return stringBuilder.toString(); }
推荐阅读