阅读:5828
回复:3
|
[技术实例]V9.2.7BPMService.asmx修改,可调用发起流程-带子表
参考帖子:http://bbs.h3bpm.com/read.php?tid=1789&fid=8&page=1
这个帖子里T大神提供过相关方法,但是用到项目中后存在问题,自己进行了修改可以使用。 使用方法:当然是不一定非要写到WebService中,我现在10上放在Controller中使用也是没问题的。 图片:8_4509_c11254350930d00.png 主要是这部门代码:全部代码在附件 //==============================================================================// //重写方法 /// <summary> /// 启动H3流程实例(带明细表) /// </summary> /// <param name="workflowCode">流程模板编码</param> /// <param name="userCode">启动流程的用户编码</param> /// <param name="finishStart">是否结束第一个活动</param> /// <param name="jsonData">流程数据,json格式。</param> /// <returns></returns> [System.Web.Services.Protocols.SoapHeader("authentication")] [WebMethod(Description = "启动H3流程实例带明细表")] public BPMServiceResult startWorkflowWithDtl( string workflowCode, string userCode, bool finishStart, string jsonData) { ValidateSoapHeader(); string workItemID, keyItem, errorMessage; workItemID = keyItem = errorMessage = string.Empty; BPMServiceResult result; try { // 获取模板 OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplateHeader workflowTemplate = GetWorkflowTemplate(workflowCode); if (workflowTemplate == null) { result = new BPMServiceResult(false, "流程启动失败,流程模板不存在,模板编码:" + workflowCode + "。"); return result; } // 查找流程发起人 OThinker.Organization.User user = this.Engine.Organization.GetUnitByCode(userCode) as Organization.User; if (user == null) { result = new BPMServiceResult(false, "流程启动失败,用户{" + userCode + "}不存在。"); return result; } OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode); OThinker.H3.DataModel.BizObject bo = new DataModel.BizObject( this.Engine.Organization, this.Engine.MetadataRepository, this.Engine.BizObjectManager, schema, OThinker.Organization.User.SystemUserID, OThinker.Organization.Company.DefaultCompanyId); //带着子表的获取 把传递过来的json数据转换成List<DataItemParam> List<DataItemParam> paramValues = GetDataValuesWithDtl(bo, user, jsonData); if (paramValues != null) { // 这里可以在创建流程的时候赋值 foreach (DataItemParam param in paramValues) { if (bo.Schema.ContainsField(param.ItemName)) { bo[param.ItemName] = param.ItemValue; } } } bo.Create(); // 创建流程实例 string InstanceId = this.Engine.InstanceManager.CreateInstance( bo.ObjectID, workflowTemplate.WorkflowCode, workflowTemplate.WorkflowVersion, null, null, user.UnitID, null, null, false, Instance.InstanceContext.UnspecifiedID, null, Instance.Token.UnspecifiedID); // 设置紧急程度为普通 OThinker.H3.Messages.MessageEmergencyType emergency = Messages.MessageEmergencyType.Normal; // 这里也可以在启动流程的时候赋值 Dictionary<string, object> paramTables = new Dictionary<string, object>(); // 启动流程的消息 OThinker.H3.Messages.StartInstanceMessage startInstanceMessage = new OThinker.H3.Messages.StartInstanceMessage( emergency, InstanceId, paramTables, Instance.PriorityType.Normal, true, null, false, OThinker.H3.Instance.Token.UnspecifiedID, null); Engine.InstanceManager.SendMessage(startInstanceMessage); result = new BPMServiceResult(true, InstanceId, workItemID, "流程实例启动成功!", ""); } catch (Exception ex) { result = new BPMServiceResult(false, "流程实例启动失败!错误:" + ex.ToString()); } return result; } // ------------------------------ // 获取Json中业务属性的值,赋值到BO对象上 private List<DataItemParam> GetDataValuesWithDtl(OThinker.H3.DataModel.BizObject bo, OThinker.Organization.User user, string jsonData) { List<DataItemParam> paramValues = new List<DataItemParam>(); var jt = JToken.Parse(jsonData);//jt是主表的数据项,包括字表 foreach (JProperty jp in jt) { if (jp.Value is JArray) { //业务对象数组 var childBoList = new List<DataModel.BizObject>(); var prosch = bo.Schema.GetProperty(jp.Name); if (prosch.ChildSchema != null) { foreach (JToken ja in (JArray)jp.Value)//遍历字表的数据 { OThinker.H3.DataModel.BizObject childBo = new DataModel.BizObject( this.Engine.Organization, this.Engine.MetadataRepository, this.Engine.BizObjectManager, prosch.ChildSchema, user.ObjectID, user.ParentID); foreach (JProperty jpt in ja) { string dataKeyChild = jpt.Name; string dataValueChild = jpt.Value.ToString(); if (childBo.Schema.GetProperty(dataKeyChild) == null) continue; if (string.IsNullOrEmpty(dataValueChild)) continue; childBo.SetValue(dataKeyChild, dataValueChild); } childBoList.Add(childBo); } paramValues.Add(new DataItemParam() { ItemName = jp.Name, ItemValue = childBoList.ToArray() }); } else { //多人参与者赋值 转换成数组 传递过来的应该是一个List集合 var arr = jp.Value; paramValues.Add(new DataItemParam() { ItemName = jp.Name, //由 ToArray 改为了 ToString ItemValue = arr.ToArray() }); } } else { paramValues.Add(new DataItemParam() { ItemName = jp.Name, ItemValue = jp.Value }); } } return paramValues; } //==============================================================================// |
|
1楼#
发布于:2018-08-13 13:12
@xuanyun 不好意思,最近很忙,现在整理出来。你参考这个即可
|
|
|
2楼#
发布于:2018-08-14 10:42
|
|
|
3楼#
发布于:2018-08-15 08:44
|
|
|