private List <Item> GetItemNames(ObjectSchemaAssociationViewModel model) { List <Item> list = new List <Item>(); OThinker.H3.DataModel.BizObjectSchema associatedSchema = this.Engine.BizObjectManager.GetDraftSchema(model.WorkflowID); if (associatedSchema == null) { return(list); } OThinker.H3.DataModel.BizObjectAssociation asso = new DataModel.BizObjectAssociation( model.RelationName ?? "", model.DisplayName ?? "", (H3.DataModel.AssociationType)Enum.Parse(typeof(AssociationType), model.Type ?? ""), associatedSchema, model.FilterMethod ?? ""); OThinker.H3.DataModel.DataMap[] maps = asso.Maps.ToArray(); ServiceMethodMap[] methodMaps = associatedSchema.GetMethod("GetList").MethodMaps; if (methodMaps != null && methodMaps.Length > 0) { DataMapCollection paramMaps = associatedSchema.GetMethod("GetList").MethodMaps[0].ParamMaps; string[] paramNames = paramMaps.GetParamNames(); foreach (string propertyName in paramNames) { DataMap map = paramMaps.GetMap(propertyName); string mapProperty = map.MapTo; if (!string.IsNullOrEmpty(mapProperty)) { DataModel.PropertySchema item = associatedSchema.GetProperty(map.ItemName); if (item != null) { list.Add(new Item(item.FullName, item.Name)); } } } } else { foreach (OThinker.H3.DataModel.DataMap map in maps) { DataModel.PropertySchema item = associatedSchema.GetProperty(map.ItemName); list.Add(new Item(item.FullName, item.Name)); } } return(list); }
/// <summary> /// 保存表单数据 /// </summary> /// <param name="workItem"></param> /// <param name="user"></param> /// <param name="boolMatchValue"></param> /// <param name="paramValues"></param> private void SaveBizObject(OThinker.H3.WorkItem.WorkItem workItem, OThinker.Organization.User user, OThinker.Data.BoolMatchValue boolMatchValue, List <DataItemParam> paramValues) { InstanceContext InstanceContext = this.Engine.InstanceManager.GetInstanceContext(workItem.InstanceId); string bizObjectId = InstanceContext == null ? string.Empty : InstanceContext.BizObjectId; OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(InstanceContext.BizObjectSchemaCode); OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject(this.Engine, schema, workItem.Participant); bo.ObjectID = bizObjectId; bo.Load(); // 设置数据项的值 foreach (DataItemParam param in paramValues) { OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName); if (property.LogicType == DataLogicType.Comment) {// 审核意见 CommentParam comment = JSSerializer.Deserialize <CommentParam>(param.ItemValue + string.Empty); this.Engine.BizObjectManager.AddComment(new Comment() { BizObjectId = bo.ObjectID, BizObjectSchemaCode = schema.SchemaCode, InstanceId = workItem.InstanceId, TokenId = workItem.TokenId, Approval = boolMatchValue, Activity = workItem.ActivityCode, DataField = property.Name, UserID = user.ObjectID, SignatureId = comment.SignatureId, Text = comment.Text }); } else { new BPM().SetItemValue(bo, property, param.ItemValue); } } bo.Update(); }
/// <summary> /// 启动H3流程实例(包含子表) /// </summary> /// <typeparam name="T">实体类-泛型</typeparam> /// <param name="workflowCode">流程模板编码</param> /// <param name="userCode">启动流程的用户编码</param> /// <param name="finishStart">是否结束第一个活动</param> /// <param name="EntityParamValues">流程实例启动初始化数据项实体类集合</param> /// <returns></returns> private BPMServiceResult startWorkflowByEntityTrinsJson( string workflowCode, string userCode, bool finishStart, object EntityParamValues) { 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 = OThinker.H3.Controllers.AppUtility.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User; string user = "******";// GetUserIDByCode(userCode); //"18f923a7-5a5e-426d-94ae-a55ad1a4b239"; // if (user == null) { result = new BPMServiceResult(false, "流程启动失败,用户{" + userCode + "}不存在。"); return(result); } OThinker.H3.DataModel.BizObjectSchema schema = OThinker.H3.Controllers.AppUtility.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode); OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject( OThinker.H3.Controllers.AppUtility.Engine.Organization, OThinker.H3.Controllers.AppUtility.Engine.MetadataRepository, OThinker.H3.Controllers.AppUtility.Engine.BizObjectManager, OThinker.H3.Controllers.AppUtility.Engine.BizBus, schema, OThinker.Organization.User.AdministratorID, OThinker.Organization.OrganizationUnit.DefaultRootID); if (EntityParamValues != null) { Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(EntityParamValues.ToString()); foreach (KeyValuePair <string, Newtonsoft.Json.Linq.JToken> jo in jObject) { //如果字段是GTAttachment则是附件 if (bo.Schema.ContainsField(jo.Key)) { if (bo.Schema.GetLogicType(jo.Key) == OThinker.H3.Data.DataLogicType.Comment) { continue; } //判断是否子表 else if (bo.Schema.GetLogicType(jo.Key) != OThinker.H3.Data.DataLogicType.BizObjectArray) { //给对象赋值 bo[jo.Key] = jo.Value; } else { List <object> list = JSSerializer.Deserialize <List <object> >(Newtonsoft.Json.JsonConvert.SerializeObject(jo.Value) as string); //获取子表的属性 BizObjectSchema childSchema = schema.GetProperty(jo.Key).ChildSchema; BizObject[] bizObjects = new BizObject[list.Count]; int i = 0; foreach (object objT in list) { bizObjects[i] = new BizObject(OThinker.H3.Controllers.AppUtility.Engine, childSchema, userCode); foreach (KeyValuePair <string, object> t in (dynamic)objT) { if (childSchema.ContainsField(t.Key)) { //给对象赋值 bizObjects[i][t.Key] = t.Value; continue; } } i++; } //子表回写给流程子表 bo[jo.Key] = bizObjects; } } } } bo.Create(); // 创建流程实例 string InstanceId = OThinker.H3.Controllers.AppUtility.Engine.InstanceManager.CreateInstance( bo.ObjectID, workflowTemplate.WorkflowCode, workflowTemplate.WorkflowVersion, null, null, user, null, false, OThinker.H3.Instance.InstanceContext.UnspecifiedID, null, OThinker.H3.Instance.Token.UnspecifiedID); // 设置紧急程度为普通 OThinker.H3.Messages.MessageEmergencyType emergency = OThinker.H3.Messages.MessageEmergencyType.Normal; // 这里也可以在启动流程的时候赋值 Dictionary <string, object> paramTables = new Dictionary <string, object>(); // 启动流程的消息 OThinker.H3.Messages.StartInstanceMessage startInstanceMessage = new OThinker.H3.Messages.StartInstanceMessage( emergency, InstanceId, workItemID, paramTables, OThinker.H3.Instance.PriorityType.Normal, true, null, false, OThinker.H3.Instance.Token.UnspecifiedID, null); OThinker.H3.Controllers.AppUtility.Engine.InstanceManager.SendMessage(startInstanceMessage); result = new BPMServiceResult(true, InstanceId, workItemID, "流程实例启动成功!", ""); } catch (Exception ex) { result = new BPMServiceResult(false, "流程实例启动失败!错误:" + ex + string.Empty); } return(result); }