操作插件--自动下推服务后实现提交和审核原创
68人赞赏了该文章
919次浏览
编辑于2024年06月24日 17:49:52
一、说明:
操作上挂了自动下推服务,自动下推服务是在操作的事务内执行的,跟操作的成功保持一致性,但可能是暂存或保存成功,下面插件代码是在保存成功前提下。产生下游单据后通过操作插件实现提交和审核,大概过程:
1、取目标单据内码
2、调用提交和审核操作
二、操作插件代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Data; using Kingdee.BOS.Contracts; using Kingdee.BOS.Core; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Util; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Core.Metadata.EntityElement; using Kingdee.BOS.App.Data; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.App.Core; using Kingdee.BOS.App.Core.Query; using Kingdee.BOS.Core.Metadata.FieldElement; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Orm; using Kingdee.BOS.WebApi.FormService; using Kingdee.BOS.JSON; using Newtonsoft.Json.Linq; namespace Kingdee.BOS.TestPlugIn.FormOperationPlugIn { [HotUpdate] [Description("单据操作插件")] public class BillAOperationPlugIn : AbstractOperationServicePlugIn { /// <summary> /// 操作事务后事件 /// </summary> /// <param name="e"></param> public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e) { base.AfterExecuteOperationTransaction(e); //这个有值代表操作成功了 if (e.DataEntitys.IsEmpty() == false) { var thisPkValue = ObjectUtils.Object2Int64(e.DataEntitys[0][0]); //得到下游单据内码, 通过LK表连接分录表得到 var sql = @"select top 1 t1.FId from UNW_t_Cust_Entry100274_LK t0 inner join UNW_t_Cust_Entry100274 t1 on t1.FEntryId = t0.FEntryId where t0.FSBillId=@thisPkValue"; List<SqlParam> listParam = new List<SqlParam>(); listParam.Add(new SqlParam("@thisPkValue", KDDbType.Int64, thisPkValue)); long targetPkValue = 0; using (IDataReader reader = DBUtils.ExecuteReader(this.Context, sql, listParam)) { while (reader.Read()) { targetPkValue = ObjectUtils.Object2Int64(reader["FId"]); break; } } if (targetPkValue > 0) { var targetFormId = "UNW_B"; IMetaDataService service = new MetaDataService(); var targetBusinessInfo = ((FormMetadata)service.Load(this.Context, targetFormId)).BusinessInfo; //不需要考虑工作流的情况,app层直接提交 SubmitService bdService = new SubmitService(); OperateOption option = OperateOption.Create(); var submitResult = bdService.Submit(this.Context, targetBusinessInfo, new object[] { targetPkValue }, "Submit", option); if (submitResult.IsSuccess) { List<object> paras = new List<object>() { "1" };//审核所需参数 var billPk = new List<KeyValuePair<object, object>>(); billPk.Add(new KeyValuePair<object, object>(targetPkValue, "")); SetStatusService statusService = new SetStatusService(); var auditResult = statusService.SetBillStatus(this.Context, targetBusinessInfo, billPk, paras, "Audit", option.Copy()); } //或者 //需要考虑工作流,建议使用API接口 JSONObject jobj = new JSONObject(); jobj.Add("Ids", targetPkValue); var apiResult = WebApiServiceCall.Submit(this.Context, targetFormId, jobj.ToString()); var joResult = JObject.Parse(apiResult.ToString()); var isSuccuess = joResult["Result"]["ResponseStatus"]["IsSuccess"].Value<bool>(); if (isSuccuess) { List<object> paras = new List<object>() { "1" };//审核所需参数 var billPk = new List<KeyValuePair<object, object>>(); billPk.Add(new KeyValuePair<object, object>(targetPkValue, "")); SetStatusService statusService = new SetStatusService(); var auditResult = statusService.SetBillStatus(this.Context, targetBusinessInfo, billPk, paras, "Audit", option.Copy()); } } } } } }
赞 68
68人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读