/// <summary>
 /// 获取指定版本号的流程模板对象
 /// </summary>
 /// <param name="workflowCode">流程模板编码</param>
 /// <param name="workflowVersion">流程模板版本号</param>
 /// <returns></returns>
 private OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplateHeader GetWorkflowTemplate(string workflowCode, int workflowVersion)
 {
     // 获取模板
     OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplateHeader workflowTemplate = this.Engine.WorkflowManager.GetPublishedTemplateHeader(
         workflowCode,
         workflowVersion);
     return(workflowTemplate);
 }
        public bool startWorkflow(
            string workflowCode,
            string userCode,
            bool finishStart,
            List <DataItemParam> paramValues)
        {
            //ValidateSoapHeader();
            string workItemID, keyItem, errorMessage;

            workItemID = keyItem = errorMessage = string.Empty;


            try
            {
                // 获取模板
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplateHeader workflowTemplate = GetWorkflowTemplate(workflowCode);
                if (workflowTemplate == null)
                {
                    return(false);
                }
                // 查找流程发起人
                OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as Organization.User;
                if (user == null)
                {
                    return(false);
                }

                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,
                    this.Engine.BizBus,
                    schema,
                    OThinker.Organization.User.AdministratorID,
                    OThinker.Organization.OrganizationUnit.DefaultRootID);

                if (paramValues != null)
                {
                    // 这里可以在创建流程的时候赋值
                    //foreach (DataItemParam param in paramValues)
                    //{

                    //    if (bo.Schema.ContainsField(param.ItemName))
                    //    {
                    //        bo[param.ItemName] = param.ItemValue;
                    //    }
                    //}
                    List <OThinker.H3.DataModel.BizObject> details = null;
                    foreach (DataItemParam param in paramValues)
                    {
                        if (!(details != null && details.Count > 0 && details[0].Schema.SchemaCode == param.ItemName))
                        {
                            details = new List <OThinker.H3.DataModel.BizObject>();
                        }
                        OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                        if (property == null)
                        {
                            continue;
                        }
                        SetItemValue(bo, property, param.ItemValue, details, param.ItemName);
                    }
                }

                bo.Create();

                // 创建流程实例
                string InstanceId = this.Engine.InstanceManager.CreateInstance(
                    bo.ObjectID,
                    workflowTemplate.WorkflowCode,
                    workflowTemplate.WorkflowVersion,
                    null,
                    null,
                    user.UnitID,
                    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,
                          null,
                          paramTables,
                          Instance.PriorityType.Normal,
                          true,
                          null,
                          false,
                          OThinker.H3.Instance.Token.UnspecifiedID,
                          null);
                Engine.InstanceManager.SendMessage(startInstanceMessage);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
示例#3
0
        /// <summary>
        /// 启动流程实例
        /// </summary>
        /// <param name="workflowCode"></param>
        /// <param name="userCode"></param>
        /// <param name="finishStart"></param>
        /// <param name="paramValues"></param>
        /// <returns></returns>
        public BPMServiceResult StartWorkflow(string workflowCode, string userCode, bool finishStart, List <DataItemParam> paramValues)
        {
            //ValidateSoapHeader();
            BPMServiceResult result = new BPMServiceResult();

            try
            {
                // 获取模板
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplateHeader workflowTemplate = GetWorkflowTemplate(workflowCode);
                if (workflowTemplate == null)
                {
                    return(new BPMServiceResult(false, "流程启动失败,流程模板不存在,模板编码:" + workflowCode + "。"));
                }
                // 查找流程发起人
                //OThinker.Organization.User user = Engine.Organization.GetUnitByCode(userCode) as Organization.User;
                string user = GetUserIDByCode(userCode);
                if (user == null)
                {
                    return(new BPMServiceResult(false, "流程启动失败,用户{" + userCode + "}不存在。"));
                }
                OThinker.H3.DataModel.BizObjectSchema schema = Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(Engine.Organization, Engine.MetadataRepository, Engine.BizObjectManager, null, schema, user);
                if (paramValues != null)
                {
                    // 这里可以在创建流程的时候赋值
                    foreach (DataItemParam param in paramValues)
                    {
                        if (bo.Schema.GetProperty(param.ItemName).LogicType == OThinker.H3.Data.DataLogicType.BizObjectArray)
                        {
                            var t = new List <OThinker.H3.DataModel.BizObject>();
                            foreach (List <DataItemParam> list in (IEnumerable)param.ItemValue)
                            {
                                var m = new OThinker.H3.DataModel.BizObject(Engine.Organization, Engine.MetadataRepository, Engine.BizObjectManager, null, schema.Fields.FirstOrDefault(x => x.ChildSchemaCode == param.ItemName).Schema, user);
                                foreach (DataItemParam item in list)
                                {
                                    if (m.Schema.ContainsField(item.ItemName))
                                    {
                                        m.SetValue(item.ItemName, item.ItemValue);
                                    }
                                }
                                t.Add(m);
                            }
                            bo[param.ItemName] = t.ToArray();
                        }
                        else 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,null, null, false, OThinker.H3.Instance.InstanceContext.UnspecifiedID,null,OThinker.H3.Instance.Token.UnspecifiedID);
                string InstanceId = this.Engine.InstanceManager.CreateInstanceByDefault(bo.ObjectID, workflowTemplate.WorkflowCode, null, user);
                // 设置紧急程度为普通
                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, null, paramTables, OThinker.H3.Instance.PriorityType.Normal, true, null, false,
                                                                                                                               OThinker.H3.Instance.Token.UnspecifiedID, null);
                Engine.InstanceManager.SendMessage(startInstanceMessage);
                result = new BPMServiceResult(true, InstanceId, null, "流程实例启动成功!", "");
            }
            catch (Exception ex)
            {
                result = new BPMServiceResult(false, "流程实例启动失败!错误:" + ex.Message);
            }
            return(result);
        }
        /// <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);
        }