博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
单据自动转换并审核的方法示例
阅读量:6705 次
发布时间:2019-06-25

本文共 6087 字,大约阅读时间需要 20 分钟。

需求要点:在单据A的界面点击“自动转换”,则自动产生审核态的单据B;若单据B不满足审核条件,则维持“提交”态;若单据B不满足保存校验,则维持“暂存”态;若转换失败,给出界面提示。
实现思路:
1.通过转换规则来定义单据A到单据B的转换关系,便于扩展,也便于使用已有的插件和服务;
2.定义一个空操作“自动转换”,扩展AbstractOperationServicePlugIn,重写EndOperationTransaction方法,方便处理事务;
3.依次调用单据转换服务、暂存服务、保存服务、提交服务和审核服务,以保证当前服务失败时能维持前一服务的状态;
4.根据上述服务调用的结果构造“自动转换”的操作结果;
5.若需求变更,只能生成审核态的单据B,否则不予生成,就要调用删除服务将所有审核不通过的单据删除,再构造操作结果;也可以直接抛出异常throw new KDBusinessException("", string.Join("\n", innerResult.ValidationErrors.Select(o => o.Message)))。

代码示例:

public override void EndOperationTransaction(BOS.Core.DynamicForm.PlugIn.Args.EndOperationTransactionArgs e)    {    base.EndOperationTransaction(e);    // 转换 //    ConvertRuleElement ruleElement = AppServiceContext.ConvertService.GetConvertRules(this.Context, "srcFormId", "destFormId").Where(o => o.IsDefault == true).FirstOrDefault();    ListSelectedRowCollection rows = new ListSelectedRowCollection();    int i = 0;    foreach (var srcData in e.DataEntitys)    {    ListSelectedRow row = new ListSelectedRow(srcData.GetDynamicObjectItemValue
("Id"), string.Empty, i++,"srcFormId"); rows.Add(row); } OperateOption option = OperateOption.Create(); option.SetVariableValue(BOSConst.CST_ConvertValidatePermission, true); PushArgs pushArgs = new PushArgs(ruleElement, rows.ToArray()); // 转换生成目标单 ConvertOperationResult convResult = AppServiceContext.ConvertService.Push(this.Context, pushArgs, option); DynamicObject[] destObjs = convResult.TargetDataEntities.Select(r => r.DataEntity).ToArray(); // 目标单元数据 FormMetadata destFormMetadata = AppMetadataContext.LoadWithNoVerCheck(this.Context, "destFormId") as FormMetadata; // 操作选项 option = OperateOption.Create(); option.SetIgnoreWarning(false); // 上一步操作成功的目标单 List
lastSuccessIdLst = new List(); // 本操作成功的目标单 List successIdLst = new List(); // 操作失败的目标单 List
failedobjs = new List
(); // 操作结果 IOperationResult result = new OperationResult(); // 错误信息 List
errorLst = new List
(); // 暂存 // IDraftService service = Kingdee.BOS.Contracts.ServiceFactory.GetService
(this.Context); IOperationResult innerResult = service.Draft(this.Context, destFormMetadata.BusinessInfo, destObjs); // 暂存成功的目标单 successIdLst = innerResult.OperateResult.Select(o => o.PKValue).Distinct().ToList(); // 暂存不通过的目标单 failedobjs = destObjs.Where(o => !successIdLst.Contains(o.GetDynamicObjectItemValue
("Id"))).ToList(); if (failedobjs != null && !failedobjs.IsEmpty()) { errorLst.Add(new ValidationErrorInfo("", "Id", 0, 0, "DraftError", string.Format("{0}暂存失败:{1}", string.Join(",", failedobjs.Select(o => o.GetDynamicObjectItemValue
("BillNo"))), string.Join("\n", innerResult.ValidationErrors.Select(o => o.Message))), "", ErrorLevel.Error)); } // 暂存不通过,则操作失败 if (successIdLst.IsEmpty()) { result.IsSuccess = false; } e.DataEntitys = e.DataEntitys.Where(o => successIdLst.Contains(o.GetDynamicObjectItemValue
("Id"))).ToArray(); // 保存 // if (!successIdLst.IsEmpty()) { lastSuccessIdLst = successIdLst; innerResult = AppServiceContext.SaveService.Save(this.Context, destFormMetadata.BusinessInfo, destObjs.Where(o => successIdLst.Contains(o.GetDynamicObjectItemValue("Id"))).ToArray(), option); // 保存成功的目标单 successIdLst = innerResult.OperateResult.Select(o => o.PKValue).Distinct().ToList(); // 校验不通过的目标单 failedobjs = destObjs.Where(o => lastSuccessIdLst.Contains(o.GetDynamicObjectItemValue("Id")) && !successIdLst.Contains(o.GetDynamicObjectItemValue("Id"))).ToList(); if (failedobjs != null && !failedobjs.IsEmpty()) { errorLst.Add(new ValidationErrorInfo("", "Id", 0, 0, "SaveError", string.Format("{0}保存失败,已暂存:{1}", string.Join(",", failedobjs.Select(o => o.GetDynamicObjectItemValue
("BillNo"))), string.Join("\n", innerResult.ValidationErrors.Select(o => o.Message))), "", ErrorLevel.Error)); } } // 提交 // if (!successIdLst.IsEmpty()) { lastSuccessIdLst = successIdLst; innerResult = AppServiceContext.SubmitService.Submit(this.Context, destFormMetadata.BusinessInfo, successIdLst.ToArray(), "Submit", option); // 提交成功的目标单 successIdLst = innerResult.OperateResult.Select(o => o.PKValue).Distinct().ToList(); // 校验不通过的目标单 failedobjs = destObjs.Where(o => lastSuccessIdLst.Contains(o.GetDynamicObjectItemValue
("Id")) && !successIdLst.Contains(o.GetDynamicObjectItemValue("Id"))).ToList(); if (failedobjs != null && !failedobjs.IsEmpty()) { errorLst.Add(new ValidationErrorInfo("", "Id", 0, 0, "SubmitError", string.Format("{0}提交失败,已保存:{1}", string.Join(",", failedobjs.Select(o => o.GetDynamicObjectItemValue
("BillNo"))), string.Join("\n", innerResult.ValidationErrors.Select(o => o.Message))), "", ErrorLevel.Error)); } } // 审核 // if (!successIdLst.IsEmpty()) { lastSuccessIdLst = successIdLst; List
> pkIds = new List
>(); foreach (var o in successIdLst) { pkIds.Add(new KeyValuePair
(o, "")); } //审核 List
paraAudit = new List(); //1审核通过 paraAudit.Add("1"); //审核意见 paraAudit.Add(""); innerResult = AppServiceContext.SetStatusService.SetBillStatus(this.Context, destFormMetadata.BusinessInfo, pkIds, paraAudit, "Audit", option); // 审核成功的目标单 successIdLst = innerResult.OperateResult.Select(o => o.PKValue).Distinct().ToList(); // 审核不通过的目标单 failedobjs = destObjs.Where(o => lastSuccessIdLst.Contains(o.GetDynamicObjectItemValue("Id")) && !successIdLst.Contains(o.GetDynamicObjectItemValue("Id"))).ToList(); if (failedobjs != null && !failedobjs.IsEmpty()) { errorLst.Add(new ValidationErrorInfo("", "Id", 0, 0, "AuditError", string.Format("{0}审核失败,已提交:{1}", string.Join(",", failedobjs.Select(o => o.GetDynamicObjectItemValue
("BillNo"))), string.Join("\n", innerResult.ValidationErrors.Select(o => o.Message))), "", ErrorLevel.Error)); } } // 构造错误信息 // if (!errorLst.IsNullOrEmpty()) { result.ValidationErrors.AddRange(errorLst); } // 将操作结果合并到空操作结果中 this.OperationResult.IsSuccess = result.IsSuccess; if (!this.OperationResult.IsSuccess) { this.OperationResult.ValidationErrors.Add(new ValidationErrorInfo("", "Id", 0, 0, "Error", string.Format("自动转换失败"), "", ErrorLevel.Error)); } this.OperationResult.MergeResult(result); }
引用:

引用常用dll.jpg

转载于:https://www.cnblogs.com/fyq891014/p/8698041.html

你可能感兴趣的文章
CSS3的边框(四)
查看>>
openfire集群+nginx负载均衡
查看>>
性能测试规定——可靠性测试规定
查看>>
00031服务SAMBA
查看>>
html暑期实习笔记(二)
查看>>
针对手游业务亚马逊,首都在线,迅达云主机的IO Network 性能测试数据
查看>>
基于lamp+fastcgi+https搭建phpMyAdmin和wordpress
查看>>
win7下安装telnet
查看>>
CCNA-(3)-了解什么是网络
查看>>
blob数据输出到页面显示图片(都实证好用的代码)
查看>>
redis+keepalived 主从热备 实例
查看>>
Eclipse上通过Pydev使用python
查看>>
位图和SVG用法比较
查看>>
Linux 管理文件与目录
查看>>
使用jvisualvm 来优化eclipse启动
查看>>
杂了个谈(二)——Markdown简易教程
查看>>
【AngularJs错误】安全限制导致资源路径不可用
查看>>
正则表达式API
查看>>
IDEA-Create Git Repository
查看>>
elasticsearch-更新文档
查看>>