public System.Web.Mvc.ActionResult RejectWorkItem(string appId, string pwd, string userCode, string workItemId, string rejectToActivity, string paramValues)
        {
            // 获取工作项
            OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            if (item == null) throw new Exception("工作任务不存在");
            OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User;
            if (user == null) throw new Exception("用户不存在");
            List<DataItemParam> listParamValues = JSSerializer.Deserialize<List<DataItemParam>>(paramValues);
            // 保存数据项
            SaveBizObject(item, user, OThinker.Data.BoolMatchValue.True, listParamValues);

            // 获取驳回节点
            if (string.IsNullOrEmpty(rejectToActivity))
            {// 目标节点为空,则判断当前节点允许驳回的环节 
                PublishedWorkflowTemplate template = this.Engine.WorkflowManager.GetPublishedTemplate(item.WorkflowCode, item.WorkflowVersion);
                ParticipativeActivity activity = template.GetActivityByCode(item.ActivityCode) as ParticipativeActivity;
                if (activity == null) throw new Exception("当前环节不允许驳回");
                if (activity.PermittedActions.RejectToStart) rejectToActivity = template.StartActivityCode; // 驳回到开始
                else if (activity.PermittedActions.RejectToFixed || activity.PermittedActions.RejectToAny)
                {
                    if (activity.PermittedActions.RejectToActivityCodes != null && activity.PermittedActions.RejectToActivityCodes.Length > 0)
                    {
                        rejectToActivity = activity.PermittedActions.RejectToActivityCodes[0];
                    }
                }
                else if (activity.PermittedActions.Reject)
                {// 驳回上一步 
                    InstanceContext context = this.Engine.InstanceManager.GetInstanceContext(item.InstanceId);
                    int[] tokens = context.GetToken(item.TokenId).PreTokens;
                    if (tokens != null && tokens.Length > 0)
                    {
                        rejectToActivity = context.GetToken(tokens[0]).Activity;
                    }
                }

                if (string.IsNullOrEmpty(rejectToActivity))
                {
                    rejectToActivity = template.StartActivityCode;
                }
            }

            // 结束工作项
            this.Engine.WorkItemManager.FinishWorkItem(
                  item.ObjectID,
                  user.ObjectID,
                  H3.WorkItem.AccessPoint.ExternalSystem,
                  null,
                  OThinker.Data.BoolMatchValue.False,
                  string.Empty,
                  null,
                  H3.WorkItem.ActionEventType.Backward,
                  10);
            // 准备触发后面Activity的消息
            OThinker.H3.Messages.ActivateActivityMessage activateMessage
                = new OThinker.H3.Messages.ActivateActivityMessage(
                OThinker.H3.Messages.MessageEmergencyType.Normal,
                item.InstanceId,
                rejectToActivity,
                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 Json(new
            {
                Result = true,
                Message = string.Empty
            });
        }
Exemplo n.º 2
0
        public JsonResult StartInstance(string paramString)
        {
            ActionResult result = new ActionResult(false, "");
            Dictionary <string, string> dicParams = JsonConvert.DeserializeObject <Dictionary <string, string> >(paramString);
            string WorkflowCode = string.Empty, SchemaCode = string.Empty, InstanceName = string.Empty; int WorkflowVersion = WorkflowTemplate.WorkflowDocument.NullWorkflowVersion; bool IsMobile = false;
            string SheetCode = string.Empty; string LoginName = string.Empty; string MobileToken = string.Empty;
            string WechatCode = string.Empty; string EngineCode = string.Empty;
            Dictionary <string, string> dicOtherParams = new Dictionary <string, string>();

            //读取URL参数
            foreach (string key in dicParams.Keys)
            {
                if (key == Param_WorkflowCode)
                {
                    WorkflowCode = dicParams[key]; continue;
                }
                if (key == Param_SchemaCode)
                {
                    SchemaCode = dicParams[key]; continue;
                }
                if (key == Param_WorkflowVersion)
                {
                    int.TryParse(dicParams[key], out WorkflowVersion); continue;
                }
                if (key == Param_IsMobile)
                {
                    bool.TryParse(dicParams[key], out IsMobile); continue;
                }
                if (key == Param_SheetCode)
                {
                    SheetCode = dicParams[key]; continue;
                }
                if (key == Param_InstanceName)
                {
                    InstanceName = dicParams[key]; continue;
                }
                if (key.ToLower() == "loginname")
                {
                    LoginName = dicParams[key]; continue;
                }
                if (key.ToLower() == "mobiletoken")
                {
                    MobileToken = dicParams[key]; continue;
                }
                if (key.ToLower() == "code")
                {
                    WechatCode = dicParams[key];
                }
                if (key.ToLower() == "state")
                {
                    EngineCode = dicParams[key];
                }
                dicOtherParams.Add(key, dicParams[key]);
            }
            //TODO:微信不需要做单点登录
            ////实现微信单点登录
            //if (!string.IsNullOrEmpty(WechatCode) && !string.IsNullOrEmpty(EngineCode)
            //    && System.Web.HttpContext.Current.Session[Sessions.GetUserValidator()] != null)
            //{
            //    IsMobile = true;
            //    UserValidatorFactory.LoginAsWeChat(EngineCode, WechatCode);
            //}
            //APP打开表单验证
            if (!string.IsNullOrEmpty(LoginName) && !string.IsNullOrEmpty(MobileToken) && this.UserValidator == null)
            {
                if (!SSOopenSheet(LoginName, MobileToken))
                {
                    result = new ActionResult(false, "登录超时!", null, ExceptionCode.NoAuthorize);
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            else if (this.UserValidator == null)
            {
                result = new ActionResult(false, "登录超时!", null, ExceptionCode.NoAuthorize);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            //计算 WorkflowCode
            if (WorkflowCode == string.Empty && !string.IsNullOrEmpty(SchemaCode))
            {
                WorkflowClause[] clauses = this.Engine.WorkflowManager.GetClausesBySchemaCode(SchemaCode);
                if (clauses != null)
                {
                    foreach (WorkflowClause clause in clauses)
                    {
                        if (clause.DefaultVersion > 0)
                        {
                            WorkflowCode = clause.WorkflowCode;
                        }
                    }
                }
            }
            //流程版本号
            if (WorkflowVersion == WorkflowTemplate.WorkflowDocument.NullWorkflowVersion || WorkflowVersion == 0)
            {
                WorkflowVersion = this.Engine.WorkflowManager.GetWorkflowDefaultVersion(WorkflowCode);
            }

            //流程优先级
            OThinker.H3.Instance.PriorityType Priority = OThinker.H3.Instance.PriorityType.Normal;
            if (dicParams.ContainsKey(Param_Priority))
            {
                string strPriority = dicParams[Param_Priority];

                Priority = (OThinker.H3.Instance.PriorityType)Enum.Parse(typeof(OThinker.H3.Instance.PriorityType), strPriority);
            }

            try
            {
                if (string.IsNullOrEmpty(WorkflowCode))
                {
                    result.Message = "StartInstance.StartInstance_Msg0";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                // 获得工作流模板
                PublishedWorkflowTemplate workflow = this.Engine.WorkflowManager.GetPublishedTemplate(WorkflowCode, WorkflowVersion);
                if (workflow == null)
                {
                    result.Message = "StartInstance.StartInstance_Msg1";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflow.BizObjectSchemaCode);
                // 开始节点
                ClientActivity startActivity = null;
                // 开始的表单
                BizSheet startSheet = null;
                System.Text.StringBuilder instanceParamBuilder = new System.Text.StringBuilder();
                if (dicOtherParams.Count > 0)
                {
                    foreach (string key in dicOtherParams.Keys)
                    {
                        instanceParamBuilder.Append(string.Format("&{0}={1}", key, dicOtherParams[key]));
                    }
                }

                startActivity = workflow.GetActivityByCode(workflow.StartActivityCode) as ClientActivity;
                if (!string.IsNullOrEmpty(SheetCode))
                {
                    startSheet = this.Engine.BizSheetManager.GetBizSheetByCode(SheetCode);
                }
                if (startSheet == null)
                {
                    if (!string.IsNullOrEmpty(startActivity.SheetCode))
                    {
                        startSheet = this.Engine.BizSheetManager.GetBizSheetByCode(startActivity.SheetCode);
                    }
                    else
                    {
                        BizSheet[] sheets = this.Engine.BizSheetManager.GetBizSheetBySchemaCode(workflow.BizObjectSchemaCode);
                        if (sheets != null && sheets.Length > 0)
                        {
                            startSheet = sheets[0];
                        }
                    }
                }

                if (workflow.StartWithSheet &&
                    startActivity != null &&
                    startSheet != null)
                {
                    string url = this.GetSheetBaseUrl(
                        SheetMode.Originate,
                        IsMobile,
                        startSheet);
                    url = url +
                          SheetEnviroment.Param_Mode + "=" + SheetMode.Originate + "&" +
                          Param_WorkflowCode + "=" + System.Web.HttpUtility.UrlEncode(workflow.WorkflowCode) + "&" +
                          Param_WorkflowVersion + "=" + workflow.WorkflowVersion +
                          //(string.IsNullOrEmpty(SheetCode)?"":("&"+Param_SheetCode+"="+SheetCode))+
                          (instanceParamBuilder.Length == 0 ? string.Empty : ("&" + instanceParamBuilder.ToString()));
                    //URL
                    result.Message = url;
                }
                else
                {
                    // 发起流程
                    string instanceId = Guid.NewGuid().ToString().ToLower();
                    string workItemId = null;
                    string error      = null;
                    OThinker.H3.DataModel.BizObject bo = new DataModel.BizObject(this.UserValidator.Engine, schema, this.UserValidator.UserID);
                    bo.Create();

                    if (!SheetUtility.OriginateInstance(
                            this.Engine,
                            bo.ObjectID,
                            workflow,
                            schema,
                            ref instanceId,
                            this.UserValidator.UserID,
                            null,
                            null,
                            OThinker.H3.Instance.PriorityType.Unspecified,
                            null,
                            null,
                            null,
                            ref workItemId,
                            ref error, false))
                    {
                        result.Message = error;
                    }
                    string startInstanceUrl = this.GetInstanceUrl(instanceId, workItemId);
                    startInstanceUrl += (instanceParamBuilder.Length == 0 ? null : ("&" + instanceParamBuilder.ToString()));
                    result.Message    = startInstanceUrl;
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            result.Success = true;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }