/// <summary> /// 结束工作任务 /// </summary> /// <param name="MvcPost">MVC表单传递过来的值</param> /// <param name="Approval">审核结果</param> /// <param name="ActionEventType">事件类型</param> /// <param name="ActionButtonType">按钮类型</param> public void ForwardWorkItem( List <DataItemParam> paramList, string code, string schemaCode, string instanceId, string workItemCode) { OThinker.H3.Instance.InstanceContext ic = this.Engine.InstanceManager.GetInstanceContext(instanceId); OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(schemaCode); OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject(Engine, schema, code); OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemCode); bo.ObjectID = ic.BizObjectId; bo.Load();//装载流程数据; if (paramList != null) { // 这里可以在创建流程的时候赋值 foreach (DataItemParam param in paramList) { if (bo.Schema.ContainsField(param.ItemName)) { bo[param.ItemName] = param.ItemValue; } } } bo.Update(); if (!string.IsNullOrEmpty(workItemCode)) { // 结束工作项 this.Engine.WorkItemManager.FinishWorkItem( workItemCode, code, OThinker.H3.WorkItem.AccessPoint.ExternalSystem, null, OThinker.Data.BoolMatchValue.True, string.Empty, null, OThinker.H3.WorkItem.ActionEventType.Forward, (int)OThinker.H3.Controllers.SheetButtonType.Submit); // 需要通知实例事件管理器结束事件 Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage( Messages.MessageEmergencyType.Normal, instanceId, item.ActivityCode, item.TokenId, OThinker.Data.BoolMatchValue.True, false, OThinker.Data.BoolMatchValue.True, true, null); this.Engine.InstanceManager.SendMessage(endMessage); } }
/// <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) { Instance.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 { this.SetItemValue(bo, property, param.ItemValue); } } bo.Update(); }
/// <summary> /// 提交工作项 /// </summary> /// <param name="workflowCode"></param> /// <param name="instanceId"></param> /// <param name="workItemId"></param> /// <param name="approval"></param> /// <param name="commentText"></param> /// <param name="userId"></param> /// <param name="values"></param> /// <returns></returns> private BPMServiceResult SubmitItem(string workflowCode, string instanceId, string workItemId, OThinker.Data.BoolMatchValue approval, string commentText, string userId, List <DataItemParam> values) { BPMServiceResult result = new BPMServiceResult(); try { string user = GetUserIDByCode(userId); if (user == null) { return(new BPMServiceResult(false, "流程启动失败,用户{" + userId + "}不存在。")); } OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = Engine.WorkflowManager.GetDefaultWorkflow(workflowCode); InstanceContext ic = Engine.InstanceManager.GetInstanceContext(instanceId); if (ic == null) { return(new BPMServiceResult(false, "InstanceID错误,此ID在H3系统中不存在,请检查")); } 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); bo.ObjectID = ic.BizObjectId; bo.Load(); foreach (DataItemParam value in values) { OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(value.ItemName); if (property.LogicType == OThinker.H3.Data.DataLogicType.BizObjectArray) { var t = new List <OThinker.H3.DataModel.BizObject>(); foreach (List <DataItemParam> list in (IEnumerable)value.ItemValue) { var m = new OThinker.H3.DataModel.BizObject(Engine.Organization, Engine.MetadataRepository, Engine.BizObjectManager, null, property.ChildSchema, bo.OwnerId); foreach (DataItemParam dataItem in list) { if (m.Schema.ContainsField(dataItem.ItemName)) { m.SetValue(dataItem.ItemName, dataItem.ItemValue); } } t.Add(m); } bo[value.ItemName] = t.ToArray(); } else if (bo.Schema.ContainsField(value.ItemName)) { bo[value.ItemName] = value.ItemValue; } } bo.Update(); // 获取工作项 OThinker.H3.WorkItem.WorkItem item = Engine.WorkItemManager.GetWorkItem(workItemId); OThinker.H3.Instance.InstanceContext instance = Engine.InstanceManager.GetInstanceContext(item.InstanceId); // 结束工作项 Engine.WorkItemManager.FinishWorkItem(item.ObjectID, userId, OThinker.H3.WorkItem.AccessPoint.ExternalSystem, null, approval, commentText, null, OThinker.H3.WorkItem.ActionEventType.Forward, (int)OThinker.H3.Controllers.SheetButtonType.Submit); // 需要通知实例事件管理器结束事件 OThinker.H3.Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(OThinker.H3.Messages.MessageEmergencyType.Normal, item.InstanceId, item.ActivityCode, item.TokenId, approval, false, approval, true, null); Engine.InstanceManager.SendMessage(endMessage); result = new BPMServiceResult(true, "", null, "流程实例启动成功!", ""); } catch (Exception ex) { result = new BPMServiceResult(false, "流程实例启动失败!错误:" + ex.Message); } return(result); }
public RestfulResult StartWorkflow_Base(string USER_CODE, string WORKFLOW_CODE, bool FINISH_START, string INSTANCE_ID, string PARAM_VALUES) { Engine.LogWriter.Write("Restful 服务,方法:StartWorkflow,参数:USER_CODE-->" + USER_CODE + ",WORKFLOW_CODE-->" + WORKFLOW_CODE + ",FINISH_START-->" + FINISH_START + ",INSTANCE_ID-->" + INSTANCE_ID + ",PARAM_VALUES-->" + JsonConvert.SerializeObject(PARAM_VALUES)); RestfulResult result = new RestfulResult(); Dictionary <string, object> listParams = JsonConvert.DeserializeObject <Dictionary <string, object> >(PARAM_VALUES); string workItemID, keyItem, errorMessage; workItemID = keyItem = errorMessage = string.Empty; try { #region 参数校验 OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = this.Engine.WorkflowManager.GetDefaultWorkflow(WORKFLOW_CODE); if (workflowTemplate == null) { result.INSTANCE_ID = ""; result.MESSAGE = "流程模板不存在,模板编码:" + WORKFLOW_CODE + "。"; result.STATUS = "0"; result.WORKFLOW_CODE = WORKFLOW_CODE; result.USER_CODE = USER_CODE; return(result); } // 查找流程发起人 OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(USER_CODE); if (user == null) { result.INSTANCE_ID = ""; result.MESSAGE = "用户{" + USER_CODE + "}不存在。"; result.STATUS = "0"; result.WORKFLOW_CODE = WORKFLOW_CODE; result.USER_CODE = USER_CODE; return(result); } #endregion #region 流程实例ID为空:发起新流程 if (string.IsNullOrEmpty(INSTANCE_ID)) { OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode); OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject( this.Engine.Organization, this.Engine.MetadataRepository, this.Engine.BizObjectManager, null, schema, user.ObjectID, user.ParentID); if (listParams != null) { // 这里可以在创建流程的时候赋值 foreach (KeyValuePair <string, object> param in listParams) { OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key); if (property == null) { continue; } SetItemValue(bo, property, param.Value); } } bo.Create(); // 创建流程实例 string InstanceId = this.Engine.InstanceManager.CreateInstance( bo.ObjectID, workflowTemplate.WorkflowCode, workflowTemplate.WorkflowVersion, null, null, user.UnitID, null, false, InstanceContext.UnspecifiedID, null, Token.UnspecifiedID); if (listParams != null) { // 这里可以在创建流程的时候赋值 foreach (KeyValuePair <string, object> param in listParams) { OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key); if (property == null) { continue; } if (property.LogicType == DataLogicType.Comment) {// 审核意见 CommentParam comment = JsonConvert.DeserializeObject <CommentParam>(JsonConvert.SerializeObject(param.Value)); this.Engine.BizObjectManager.AddComment(new Comment() { BizObjectId = bo.ObjectID, BizObjectSchemaCode = schema.SchemaCode, InstanceId = InstanceId, Activity = workflowTemplate.StartActivityCode, TokenId = 1, Approval = OThinker.Data.BoolMatchValue.True, DataField = property.Name, UserID = user.ObjectID, UserName = user.Name, SignatureId = comment.SignatureId, Text = comment.Text }); } } } // 启动流程的消息 OThinker.H3.Messages.StartInstanceMessage startInstanceMessage = new OThinker.H3.Messages.StartInstanceMessage( MessageEmergencyType.Normal, InstanceId, workItemID, null, PriorityType.Normal, FINISH_START, null, false, OThinker.H3.Instance.Token.UnspecifiedID, null); Engine.InstanceManager.SendMessage(startInstanceMessage); result.INSTANCE_ID = InstanceId; result.MESSAGE = "流程实例启动成功!"; result.BIZOBJECTID = bo.ObjectID; result.STATUS = "2"; result.WORKFLOW_CODE = WORKFLOW_CODE; result.USER_CODE = USER_CODE; } #endregion #region 流程实例ID不为空:更新流程数据; else { InstanceContext ic = this.Engine.InstanceManager.GetInstanceContext(INSTANCE_ID); if (ic == null) { result.INSTANCE_ID = INSTANCE_ID; result.MESSAGE = "InstanceID错误,此ID在H3系统中不存在,请检查"; result.STATUS = "0"; result.WORKFLOW_CODE = WORKFLOW_CODE; result.USER_CODE = USER_CODE; return(result); } OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode); OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject( this.Engine.Organization, this.Engine.MetadataRepository, this.Engine.BizObjectManager, null, schema, user.ObjectID, user.ParentID); bo.ObjectID = ic.BizObjectId; bo.Load();//装载流程数据; if (listParams != null) { // 这里可以在创建流程的时候赋值 foreach (KeyValuePair <string, object> param in listParams) { OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key); if (property == null) { continue; } SetItemValue(bo, property, param.Value); } } bo.Update(); #region 提交当前任务,往下流转 if (FINISH_START) { string sql = "SELECT ObjectID FROM OT_WorkItem WHERE InstanceId='{0}' ORDER BY TokenId desc"; sql = string.Format(sql, INSTANCE_ID); string workItemId = this.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteScalar(sql) + string.Empty; if (workItemId != "") { // 获取工作项 OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemId); // 结束工作项 this.Engine.WorkItemManager.FinishWorkItem( item.ObjectID, user.UnitID, OThinker.H3.WorkItem.AccessPoint.ExternalSystem, null, OThinker.Data.BoolMatchValue.True, string.Empty, null, OThinker.H3.WorkItem.ActionEventType.Forward, 11); // 需要通知实例事件管理器结束事件 AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage( MessageEmergencyType.Normal, item.InstanceId, item.ActivityCode, item.TokenId, OThinker.Data.BoolMatchValue.True, false, OThinker.Data.BoolMatchValue.True, true, null); this.Engine.InstanceManager.SendMessage(endMessage); } } #endregion result.INSTANCE_ID = INSTANCE_ID; result.MESSAGE = "流程实例启动成功!(更新数据项的值)"; result.BIZOBJECTID = ic.BizObjectId; result.STATUS = "2"; result.WORKFLOW_CODE = WORKFLOW_CODE; result.USER_CODE = USER_CODE; } #endregion } catch (Exception ex) { result = new RestfulResult(); result.INSTANCE_ID = ""; result.BIZOBJECTID = ""; result.MESSAGE = "接口异常:" + ex.ToString(); result.STATUS = "0"; result.WORKFLOW_CODE = WORKFLOW_CODE; result.USER_CODE = USER_CODE; } return(result); }
/// <summary> /// 设置数据项的值 /// </summary> /// <param name="bo"></param> /// <param name="property"></param> /// <param name="itemValue"></param> public void SetItemValue(OThinker.H3.DataModel.BizObject bo, OThinker.H3.DataModel.PropertySchema property, object itemValue) { if (property.LogicType == DataLogicType.DateTime) { DateTime d = DateTime.Now; DateTime.TryParse(itemValue + string.Empty, out d); bo[property.Name] = d; } else if (property.LogicType == DataLogicType.Bool) { bool b = false; bool.TryParse(itemValue + string.Empty, out b); bo[property.Name] = b; } else if (property.LogicType == DataLogicType.TimeSpan) {// 时间段 TimeSpan t = new TimeSpan(0, 0, 0); TimeSpan.TryParse(itemValue + string.Empty, out t); bo[property.Name] = t; } else if (property.LogicType == DataLogicType.SingleParticipant) {// 参与者单人:传入用户登录名 if (itemValue != null) { try { var user = this.Engine.Organization.GetUserByCode(itemValue + string.Empty); bo[property.Name] = user == null ? "" : user.ObjectID; } catch (Exception ex) { bo[property.Name] = null; this.Engine.LogWriter.Write("字段:" + property.Name + "赋值异常-->" + ex.ToString()); } } } else if (property.LogicType == DataLogicType.MultiParticipant) {// 参与者多人:传入用户登录名 if (itemValue != null) { try { List <string> retUserIDs = new List <string>(); List <string> UserCodes = JsonConvert.DeserializeObject <List <string> >(JsonConvert.SerializeObject(itemValue)); if (UserCodes == null) { bo[property.Name] = null; } else { foreach (String code in UserCodes) { var user = this.Engine.Organization.GetUserByCode(code + string.Empty); if (user != null) { retUserIDs.Add(user.ObjectID); } } bo[property.Name] = retUserIDs.ToArray(); } } catch (Exception ex) { bo[property.Name] = null; this.Engine.LogWriter.Write("字段:" + property.Name + "赋值异常-->" + ex.ToString()); } } } else if (property.LogicType == DataLogicType.BizObjectArray) {// 子表 if (property.ChildSchema == null) { return; } List <OThinker.H3.DataModel.BizObject> details = new List <OThinker.H3.DataModel.BizObject>(); List <Dictionary <string, object> > gridView = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(JsonConvert.SerializeObject(itemValue)); if (gridView == null) { return; } foreach (Dictionary <string, object> row in gridView) { OThinker.H3.DataModel.BizObject subBo = new OThinker.H3.DataModel.BizObject(this.Engine, property.ChildSchema, bo.OwnerId); foreach (KeyValuePair <string, object> item in row) { OThinker.H3.DataModel.PropertySchema childProperty = property.ChildSchema.GetProperty(item.Key); if (childProperty == null) { continue; } this.SetItemValue(subBo, childProperty, item.Value); } details.Add(subBo); } bo[property.Name] = details.ToArray(); } else if (property.LogicType == DataLogicType.Attachment) {// 附件 //List<List<DataItemParam>> attachments = JSSerializer.Deserialize<List<List<DataItemParam>>>(JSSerializer.Serialize(itemValue)); List <AttachmentParamNew> attachments = JsonConvert.DeserializeObject <List <AttachmentParamNew> >(JsonConvert.SerializeObject(itemValue)); //先清理掉当前流程实例的所有附件(在更新的情况下) this.Engine.BizObjectManager.RemoveAttachments(bo.Schema.SchemaCode, bo.ObjectID, property.Name); if (attachments != null) { foreach (AttachmentParamNew attachment in attachments) { OThinker.H3.Data.Attachment attach = new Attachment() { FileName = attachment.FileName, BizObjectId = bo.ObjectID, DataField = property.Name, Downloadable = true, DownloadUrl = attachment.DownloadUrl, Content = attachment.Content, BizObjectSchemaCode = bo.Schema.SchemaCode, ContentLength = attachment.Content == null ? attachment.ContentLength : attachment.Content.Length, ContentType = attachment.ContentType }; this.Engine.BizObjectManager.AddAttachment(attach); } } } //if (property.LogicType == DataLogicType.String // || property.LogicType == DataLogicType.ShortString // || property.LogicType == DataLogicType.Int // || property.LogicType == DataLogicType.Long // || property.LogicType == DataLogicType.Decimal // || property.LogicType == DataLogicType.Html // || property.LogicType == DataLogicType.Double) else {// 短文本、长文本、整数、数值、HTML bo[property.Name] = itemValue; } }
/// <summary> /// 设置数据项的值 /// </summary> /// <param name="bo"></param> /// <param name="property"></param> /// <param name="itemValue"></param> private void SetItemValue(OThinker.H3.DataModel.BizObject bo, OThinker.H3.DataModel.PropertySchema property, object itemValue) { if (property.LogicType == DataLogicType.String || property.LogicType == DataLogicType.ShortString || property.LogicType == DataLogicType.Int || property.LogicType == DataLogicType.Long || property.LogicType == DataLogicType.Decimal || property.LogicType == DataLogicType.Html || property.LogicType == DataLogicType.SingleParticipant) {// 短文本、长文本、整数、数值、HTML、参与者单人 bo[property.Name] = itemValue; } else if (property.LogicType == DataLogicType.DateTime) { DateTime d = DateTime.Now; DateTime.TryParse(itemValue + string.Empty, out d); bo[property.Name] = d; } else if (property.LogicType == DataLogicType.Bool) { bool b = false; bool.TryParse(itemValue + string.Empty, out b); bo[property.Name] = b; } else if (property.LogicType == DataLogicType.TimeSpan) {// 时间段 TimeSpan t = new TimeSpan(0, 0, 0); TimeSpan.TryParse(itemValue + string.Empty, out t); bo[property.Name] = t; } else if (property.LogicType == DataLogicType.MultiParticipant) {// 参与者多人 if (itemValue != null) bo[property.Name] = itemValue; } else if (property.LogicType == DataLogicType.BizObjectArray) {// 子表 if (property.ChildSchema == null) return; List<OThinker.H3.DataModel.BizObject> details = new List<OThinker.H3.DataModel.BizObject>(); List<List<DataItemParam>> gridView = JSSerializer.Deserialize<List<List<DataItemParam>>>(itemValue + string.Empty); if (gridView == null) return; foreach (List<DataItemParam> row in gridView) { OThinker.H3.DataModel.BizObject subBo = new OThinker.H3.DataModel.BizObject(this.Engine, property.ChildSchema, bo.OwnerId); foreach (DataItemParam item in row) { OThinker.H3.DataModel.PropertySchema childProperty = property.ChildSchema.GetProperty(item.ItemName); if (childProperty == null) continue; this.SetItemValue(subBo, childProperty, item.ItemValue); } details.Add(subBo); } bo[property.Name] = details.ToArray(); } else if (property.LogicType == DataLogicType.Attachment) {// 附件 List<AttachmentParam> attachments = JSSerializer.Deserialize<List<AttachmentParam>>(itemValue + string.Empty); if (attachments != null) { foreach (AttachmentParam attachment in attachments) { OThinker.H3.Data.Attachment attach = new Attachment() { FileName = attachment.FileName, BizObjectId = bo.ObjectID, DataField = property.Name, Content = attachment.Content, BizObjectSchemaCode = bo.Schema.SchemaCode, ContentLength = attachment.Content.Length, ContentType = attachment.ContentType, DownloadUrl = attachment.DownloadUrl }; this.Engine.BizObjectManager.AddAttachment(attach); } } } }
public System.Web.Mvc.ActionResult StartWorkflow(string appId, string pwd, string userCode, string workflowCode, bool finishStart, string paramValues) { BPMServiceResult result = new BPMServiceResult(); List<DataItemParam> listParams = JSSerializer.Deserialize<List<DataItemParam>>(paramValues); string workItemID, keyItem, errorMessage; workItemID = keyItem = errorMessage = string.Empty; try { OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = this.Engine.WorkflowManager.GetDefaultWorkflow(workflowCode); if (workflowTemplate == null) { result = new BPMServiceResult(false, "流程模板不存在,模板编码:" + workflowCode + "。"); return Json(result); } // 查找流程发起人 OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User; if (user == null) { result = new BPMServiceResult(false, "用户{" + userCode + "}不存在。"); return Json(result); } OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode); OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject( this.Engine.Organization, this.Engine.MetadataRepository, this.Engine.BizObjectManager, null, schema, user.ObjectID, user.ParentID); if (listParams != null) { // 这里可以在创建流程的时候赋值 foreach (DataItemParam param in listParams) { OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName); if (property == null) continue; SetItemValue(bo, property, param.ItemValue); } } bo.Create(); // 创建流程实例 string InstanceId = this.Engine.InstanceManager.CreateInstance( bo.ObjectID, workflowTemplate.WorkflowCode, workflowTemplate.WorkflowVersion, null, null, user.UnitID, null, false, InstanceContext.UnspecifiedID, null, Token.UnspecifiedID); if (listParams != null) { // 这里可以在创建流程的时候赋值 foreach (DataItemParam param in listParams) { OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName); if (property == null) continue; 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 = InstanceId, Activity = workflowTemplate.StartActivityCode, TokenId = 1, Approval = OThinker.Data.BoolMatchValue.True, DataField = property.Name, UserID = user.ObjectID, SignatureId = comment.SignatureId, Text = comment.Text }); } } } // 启动流程的消息 OThinker.H3.Messages.StartInstanceMessage startInstanceMessage = new OThinker.H3.Messages.StartInstanceMessage( MessageEmergencyType.Normal, InstanceId, workItemID, null, PriorityType.Normal, true, null, false, OThinker.H3.Instance.Token.UnspecifiedID, null); Engine.InstanceManager.SendMessage(startInstanceMessage); result = new BPMServiceResult(true, InstanceId, workItemID, "流程实例启动成功!", string.Empty); } catch (Exception ex) { result = new BPMServiceResult(false, ex.ToString()); } return Json(result, JsonRequestBehavior.AllowGet); }
/// <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); }
public bool ReturnItem(string userId, string workItemId, string activityCode, string SchemaCode, double xbzjye, string state, DateTime bzjyedysj, string userName, string PassState, double yzzfbzj) { Organization.User user = this.Engine.Organization.GetUnit(userId) as Organization.User; if (user == null) { return(false); } // 获取工作项 OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(SchemaCode); OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemId); OThinker.H3.Instance.InstanceContext context = this.Engine.InstanceManager.GetInstanceContext(item.InstanceId); OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject(Engine, schema, userId); bo.ObjectID = context.BizObjectId; bo.Load(); //装载流程数据; if (bo.Schema.ContainsField("BZJYE")) //保证金余额 { bo["BZJYE"] = xbzjye; } if (bo.Schema.ContainsField("LCZT")) { bo["LCZT"] = state; } if (bo.Schema.ContainsField("BZJYEDYSJ")) { bo["BZJYEDYSJ"] = bzjyedysj; } if (bo.Schema.ContainsField("CWCLR")) { bo["CWCLR"] = userName; } if (bo.Schema.ContainsField("CWSPRID")) { bo["CWSPRID"] = userId; } //this.AppendComment(item.InstanceId, item, OThinker.Data.BoolMatchValue.Unspecified, "现保证金余额x钱,应再支付X保证金"); // 结束工作项 if (PassState == "TG") {//财务通过 this.Engine.WorkItemManager.FinishWorkItem( item.ObjectID, user.ObjectID, H3.WorkItem.AccessPoint.ExternalSystem, null, OThinker.Data.BoolMatchValue.True, string.Empty, null, H3.WorkItem.ActionEventType.Backward, (int)OThinker.H3.Controllers.SheetButtonType.Return); if (bo.Schema.ContainsField("CWSPYJDX")) { bo["CWSPYJDX"] = "通过"; } this.AppendComment(context, item, OThinker.Data.BoolMatchValue.True, "通过");//财务部通过后,显示通过 } else {//财务驳回 this.Engine.WorkItemManager.FinishWorkItem( item.ObjectID, user.ObjectID, H3.WorkItem.AccessPoint.ExternalSystem, null, OThinker.Data.BoolMatchValue.False, string.Empty, null, H3.WorkItem.ActionEventType.Backward, (int)OThinker.H3.Controllers.SheetButtonType.Return); var info = "现保证金余额" + string.Format("{0:N2}", xbzjye) + "元,应再支付" + string.Format("{0:N2}", yzzfbzj) + "保证金"; this.AppendComment(context, item, OThinker.Data.BoolMatchValue.False, info); if (bo.Schema.ContainsField("CWSPYJDX")) { bo["CWSPYJDX"] = "驳回"; } try { MessageClass ms = new MessageClass(); string sql = @"select distinct a.PARTICIPANT,b.code, d.objectid , d.code jxsuserCode, e.JXS,e.JXSCODE from Ot_Workitemfinished a join Ot_User b on a.PARTICIPANT = b.objectid join Ot_Instancecontext c on c.objectid = a.instanceid join OT_User d on d.objectid = c.ORIGINATOR join I_DealerLoan e on e.objectid = c.bizobjectid where ACTIVITYCODE='Activity3' and c.workFlowCode = 'DealerLoan' and instanceid='" + item.InstanceId + "'"; DataTable dt = OThinker.H3.Controllers.AppUtility.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable(sql); string msstr1 = dt.Rows[0]["JXS"].ToString() + "(" + dt.Rows[0]["JXSCODE"].ToString() + ") 还需要支付<font color=\"red\">" + string.Format("{0:N2}", yzzfbzj) + "</font> 元 保证金金额才可以进行本次贷款申请,现保证金账户余额 " + string.Format("{0:N2}", xbzjye) + " 元"; string msstr2 = "您的账户还需要支付<font color=\"red\">" + string.Format("{0:N2}", yzzfbzj) + "</font> 元 保证金金额才可以进行本次贷款申请,现保证金账户余额 " + string.Format("{0:N2}", xbzjye) + "元"; if (dt != null && dt.Rows != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ms.InsertMSG(dt.Rows[i]["PARTICIPANT"].ToString(), dt.Rows[i]["code"].ToString(), msstr1, true, 0, ""); } } ms.InsertMSG(dt.Rows[0]["objectid"].ToString(), dt.Rows[0]["jxsCode"].ToString(), msstr2, false, 0, ""); } catch (Exception e) { } } bo.Update(); // 准备触发后面Activity的消息 OThinker.H3.Messages.ActivateActivityMessage activateMessage = new OThinker.H3.Messages.ActivateActivityMessage( OThinker.H3.Messages.MessageEmergencyType.Normal, item.InstanceId, activityCode, OThinker.H3.Instance.Token.UnspecifiedID, null, new int[] { item.TokenId }, false, H3.WorkItem.ActionEventType.Backward); // 通知该Activity已经完成 OThinker.H3.Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage( OThinker.H3.Messages.MessageEmergencyType.Normal, item.InstanceId, item.ActivityCode, item.TokenId, OThinker.Data.BoolMatchValue.False, true, OThinker.Data.BoolMatchValue.False, false, activateMessage); this.Engine.InstanceManager.SendMessage(endMessage); return(true); }
/// <summary> /// 结束工作任务 /// </summary> public void ENDWorkItem(string UpdateUserId, string schemaCode, string workItemID, string STATE) { OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemID); if (!string.IsNullOrEmpty(schemaCode)) { OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(schemaCode); OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject(Engine, schema, UpdateUserId); OThinker.H3.Instance.InstanceContext ic = this.Engine.InstanceManager.GetInstanceContext(item.InstanceId); if (!string.IsNullOrEmpty(workItemID)) { bo.ObjectID = ic.BizObjectId; bo.Load();//装载流程数据; if (!string.IsNullOrEmpty(STATE)) { if (bo.Schema.ContainsField("LCZT")) { bo["LCZT"] = STATE; } if (bo.Schema.ContainsField("OperationStates")) { bo["OperationStates"] = STATE; } if (bo.Schema.ContainsField("states")) { bo["states"] = STATE; } } bo.Update(); } } // 结束工作项 this.Engine.WorkItemManager.FinishWorkItem( workItemID, UpdateUserId, OThinker.H3.WorkItem.AccessPoint.ExternalSystem, null, OThinker.Data.BoolMatchValue.True, string.Empty, null, OThinker.H3.WorkItem.ActionEventType.Forward, (int)OThinker.H3.Controllers.SheetButtonType.Submit); // 需要通知实例事件管理器结束事件 Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage( Messages.MessageEmergencyType.Normal, item.InstanceId, item.ActivityCode, item.TokenId, OThinker.Data.BoolMatchValue.True, false, OThinker.Data.BoolMatchValue.True, true, null); this.Engine.InstanceManager.SendMessage(endMessage); }