public ResultModel Approve(string processCode, string sn, int loginId, string actionString, string memo, string jsonData, string apiKey)
        {
            Cat.GetProducer().NewTransaction("URL-WebService", "Approve");
            var a = Cat.GetManager().PeekTransaction;
            ResultModel result = null;

            try
            {
                if (APIKeyUtility.IsRightAPIKey(apiKey))
                {
                    result = WorkFlowTaskService.ApproveK2Process(processCode, sn, loginId, actionString, memo, jsonData);
                }
                else
                {
                    result = new ResultModel() { Code = ResultCode.Fail, Msg = "ApiKey错误" };
                }
                a.Status = "0";
            }
            catch (Exception ex)
            {
                Cat.GetProducer().LogError(ex);
                a.SetStatus(ex);
                throw ex;
            }
            finally
            {
                a.Complete();
            }
            return result;
        }
        public ResultModel StartProcess(string processCode, int loginId, string ObjectId, string Folio, string jsonData)
        {
            ResultModel result = new ResultModel();
            if (loginId == 0)
            {
                result.Code = Common.Enum.ResultCode.Fail;
                result.Msg = "LoginId错误";

                return result;
            }
            var originator = k2UserDomain.GetK2User(loginId);
            if (originator == null)
            {
                result.Code = Common.Enum.ResultCode.Fail;
                result.Msg = "发起人不存在" + loginId.ToString();

                return result;
            }
            var process = processInfoDomain.GetByProcessCode(new List<string>() { processCode });
            if (process == null || process.Count != 1)
            {

                result.Code = Common.Enum.ResultCode.Fail;
                result.Msg = string.Format("流程不存在:{0}", processCode);

                return result;
            }

            Dictionary<string, string> dataFields = new Dictionary<string, string>();
            try
            {
                k2UserDomain.GenerateApprovalUser(loginId, dataFields, processCode, "发起人");

                //更新业务数据
                if (!string.IsNullOrEmpty(jsonData))
                {
                    dataFields.Add("OBJECT", jsonData);
                }

                if (!dataFields.ContainsKey("dest_Creator"))
                {
                    dataFields.Add("dest_Creator", loginId.ToString());
                }

            }
            catch (Exception ex)
            {
                result.Code = Common.Enum.ResultCode.Fail;
                result.Msg = ex.Message;

                return result;
            }
            result = processInfoDomain.StartProcess(processCode, process[0].ProcessFullName, loginId, originator.UserDescription, ObjectId, Folio, dataFields);
            return result;
        }
        public void ProcessRequest(HttpContext context)
        {
            Cat.GetProducer().NewTransaction("URL-http", "ReAssign");
            var a = Cat.GetManager().PeekTransaction;

            context.Response.ContentType = "text/plain";
            ResultModel result = new ResultModel();
            try
            {
                string sn = context.Request.Params["sn"];
                int assignFromLoginId = 0;
                int.TryParse(context.Request.Params["assignFromLoginId"],out assignFromLoginId);
                string assignFromRealName = context.Request.Params["assignFromRealName"];
                int assignToLoginId = 0;
                int.TryParse(context.Request.Params["assignToLoginId"], out assignToLoginId);
                string assignToRealName = context.Request.Params["assignToRealName"];
                bool isAddLog = false;
                try
                {
                    isAddLog = Convert.ToBoolean(context.Request.Params["isAddLog"]);
                }
                catch { }

                string apiKey = context.Request.Params["apiKey"];

                if (APIKeyUtility.IsRightAPIKey(apiKey))
                {
                    result = WorkFlowTaskService.ReAssign(sn, assignFromLoginId, assignFromRealName, assignToLoginId, assignToRealName, isAddLog);
                }
                else
                {
                    result = new ResultModel() { Code = ResultCode.Fail, Msg = "ApiKey错误" };
                }

                a.Status = "0";
            }
            catch (Exception ex)
            {
                Cat.GetProducer().LogError(ex);
                a.SetStatus(ex);
                LogHelper.Error("ReAssign", ex.Message, ex, context.Request.Params.ToString());
                result = new ResultModel() { Code = ResultCode.Fail, Msg = ex.Message };
                context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            }
            finally
            {
                a.Complete();
            }
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
Exemple #4
0
        public void ProcessRequest(HttpContext context)
        {
            Cat.GetProducer().NewTransaction("URL-http", "Approve");
            var a = Cat.GetManager().PeekTransaction;

            context.Response.ContentType = "text/plain";
            ResultModel result = new ResultModel();
            try
            {
                string processCode = context.Request.Params["processCode"];
                int loginId = 0;
                int.TryParse(context.Request.Params["loginId"], out loginId);
                string sn = context.Request.Params["sn"];
                string actionString = context.Request.Params["actionString"];
                string memo = context.Request.Params["memo"];
                string jsonData = context.Request.Params["jsonData"];
                string apiKey = context.Request.Params["apiKey"];

                if (APIKeyUtility.IsRightAPIKey(apiKey))
                {
                    result = WorkFlowTaskService.ApproveK2Process(processCode, sn, loginId, actionString, memo, jsonData);
                }
                else
                {
                    result = new ResultModel() { Code = ResultCode.Fail, Msg = "ApiKey错误" };
                }
                a.Status = "0";

            }
            catch (Exception ex)
            {
                Cat.GetProducer().LogError(ex);
                a.SetStatus(ex);
                LogHelper.Error("Approve", ex.Message, ex, context.Request.Params.ToString());

                result = new ResultModel() { Code = ResultCode.Fail, Msg = ex.Message };
            }
            finally
            {
                a.Complete();
            }
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
        public ResultModel ApproveK2Process(string processCode, string sn, int loginId, string actionString, string memo, string jsonData)
        {
            ResultModel result = new ResultModel();
            int procInstid = 0;
            if (loginId == 0)
            {
                result.Code =  ResultCode.Fail;
                result.Msg = "LoginId错误";
                return result;
            }
            if (string.IsNullOrEmpty(sn))
            {
                result.Code = ResultCode.Fail;
                result.Msg = "SN不能为空";
            }
            else
            {
                try
                {
                    procInstid = Convert.ToInt32(sn.Split('_')[0]);
                }
                catch (Exception ex)
                {
                    result.Code = ResultCode.Fail;
                    result.Msg = string.Format("SN格式错误:{0}", ex.Message);
                }
            }

            var approvalUser = k2UserDomain.GetK2User(loginId);
            if (approvalUser == null)
            {
                result.Code = Common.Enum.ResultCode.Fail;
                result.Msg = string.Format("人员不存在:{0}", loginId.ToString());

                return result;
            }

            Dictionary<string, string> dataFields = new Dictionary<string, string>();
            try
            {
                //如果流程打回重新发起,审批人会清空,所以需要重新获取审批人
                if (actionString == "拒绝" || actionString == "结束流程")
                {
                }
                else
                {
                    if (!string.IsNullOrEmpty(processCode))
                    {
                        //取发起人,如果出异常,不处理,保持原有发起人
                        try
                        {
                            var procInst = ProcessInfoDomain.GetProcInstById(procInstid);
                            if (procInst != null)
                            {
                                int originatorLoginId = int.Parse(procInst.Originator.Replace("K2SQL:", ""));
                                k2UserDomain.GenerateApprovalUser(originatorLoginId, dataFields, processCode, "");
                            }
                        }
                        catch { }
                    }
                }
            }
            catch { }
            //更新业务数据
            if (!string.IsNullOrEmpty(jsonData))
            {
                dataFields.Add("OBJECT", jsonData);
            }

            return MyTaskDomain.ApproveK2Process(processCode, sn, loginId, approvalUser.UserDescription, actionString, memo, dataFields);
        }
        public ResultModel ReAssign(string sn, int assignFromLoginId, string assignFromRealName, int assignToLoginId, string assignToRealName, bool isAddLog)
        {
            ResultModel jr = new ResultModel() { Code = ResultCode.Fail };

            if (sn.IndexOf('_') <= 0)
            {
                jr.Msg = "sn格式错误";
            }
            else if (assignFromLoginId == 0 || assignToLoginId == 0)
            {
                jr.Msg = "LoginId错误";
            }
            else if (isAddLog && (string.IsNullOrEmpty(assignFromRealName) || string.IsNullOrEmpty(assignToRealName)))
            {
                jr.Msg = "姓名错误";
            }
            else
            {
                jr = MyTaskDomain.ReAssign(sn, assignFromLoginId, assignFromRealName, assignToLoginId, assignToRealName, isAddLog);

                if (jr.Code == ResultCode.Sucess)
                {
                    jr.Msg = "ReAssign成功";
                }
            }

            return jr;
        }
        public ResultModel ApproveK2Process(string sn, int loginId, string actionString, string memo, Dictionary<string, string> dataFields, out string activityName, out string processCode, out int procInstID)
        {
            Connection k2Connect = null;
            WorklistItem workList = null;
            ResultModel jr = new ResultModel() { Code = ResultCode.Fail };
            activityName = string.Empty;
            processCode = string.Empty;
            procInstID = 0;
             try
            {
                k2Connect = new Connection();
                k2Connect.Open(ConfigurationManager.AppSettings["K2Server"], ConfigurationManager.AppSettings["K2LoginString"]);
                k2Connect.ImpersonateUser(SecurityLable(loginId.ToString()));

                workList = k2Connect.OpenWorklistItem(sn);
                if (workList != null)
                {
                    #region 更新Datafield
                    if (dataFields != null && dataFields.Count > 0)
                    {
                        ProcessInstance CurrentProcessInst = workList.ProcessInstance;
                        //更新Datafields
                        foreach (string key in dataFields.Keys)
                        {
                            if (CurrentProcessInst.DataFields[key] != null)
                            {
                                if (CurrentProcessInst.DataFields[key].Value.ToString() != dataFields[key])
                                {
                                    CurrentProcessInst.DataFields[key].Value = dataFields[key];
                                }
                            }
                        }
                    }
                    #endregion

                    #region 审批任务
                    //批量审批没有actionString,默认第一个操作
                    if (string.IsNullOrEmpty(actionString))
                    {
                        if (workList.Actions[0].Name == REJECTACTION)
                        {
                            workList.GotoActivity("流程未通过");
                        }
                        else if (workList.Actions[0].Name == UNDOACTION)
                        {
                            workList.GotoActivity("流程撤销");
                        }
                        else
                        {
                            workList.Actions[0].Execute();
                        }
                    }
                    else
                    {
                        //执行匹配的操作
                        if (actionString == UNDOACTION)
                        {
                            workList.GotoActivity("流程撤销");
                        }
                        else if (actionString == REJECTACTION)
                        {
                            workList.GotoActivity("流程未通过");
                        }
                        else
                        {
                            bool isExcute = false;
                            for (int i = 0; i < workList.Actions.Count; i++)
                            {
                                if (workList.Actions[i].Name == actionString)
                                {
                                    workList.Actions[i].Execute();
                                    isExcute = true;
                                    break;
                                }
                            }
                            if (!isExcute)
                            {
                                jr.Code = ResultCode.Fail;
                                jr.Msg = string.Format("Action:{0}错误", actionString);
                                return jr;
                            }
                        }
                    }
                    #endregion

                    jr.Code = ResultCode.Sucess;
                    jr.Msg = "";
                    activityName = workList.ActivityInstanceDestination.Name;
                    processCode = workList.ProcessInstance.DataFields["ProcessCode"].Value.ToString();
                    procInstID = workList.ProcessInstance.ID;
                }
            }
             catch (Exception ex)
             {
                 jr.Msg = ex.Message;
             }
             finally
             {
                 if (workList != null)
                 {
                     if (workList.Status == WorklistStatus.Open)
                     {
                         try
                         {
                             k2Connect.RevertUser();
                             workList.Release();
                         }
                         catch { }
                     }
                 }
                 if (k2Connect != null)
                     k2Connect.Close();
             }

             return jr;
        }
        public ResultModel StartProcess(string processName, int loginId, string objectId, string folio, Dictionary<string, string> dataFields,out int procInstId)
        {
            Connection k2Connect = null;
            WorklistItem workList = null;
            ResultModel jr = new ResultModel() { Code = ResultCode.Fail };
            procInstId = 0;
            try
            {
                k2Connect = new Connection();
                k2Connect.Open(ConfigurationManager.AppSettings["K2Server"], ConfigurationManager.AppSettings["K2LoginString"]);
                k2Connect.ImpersonateUser(SecurityLable(loginId.ToString()));
                //创建实例
                ProcessInstance ProcessInst = k2Connect.CreateProcessInstance(processName);
                if (!string.IsNullOrEmpty(folio))
                {
                    ProcessInst.Folio = folio;
                }
                #region //赋值datafields
                foreach (string key in dataFields.Keys)
                {
                    if (ProcessInst.DataFields[key] != null)
                    {
                        ProcessInst.DataFields[key].Value = dataFields[key];
                    }
                }
                #endregion

                k2Connect.StartProcessInstance(ProcessInst);

                procInstId = ProcessInst.ID;
                jr.Code = ResultCode.Sucess;
                jr.Msg = procInstId.ToString();
            }
            catch (Exception ex)
            {
                jr.Msg = ex.Message;
            }
            finally
            {
                if (workList != null)
                {
                    if (workList.Status == WorklistStatus.Open)
                    {
                        try
                        {
                            k2Connect.RevertUser();
                            workList.Release();
                        }
                        catch { }
                    }
                }
                if (k2Connect != null)
                    k2Connect.Close();
            }
            return jr;
            //var result = (new K2Service.K2Service()).StartProcess(processCode, loginId, objectId, folio, jsonData, ConfigurationManager.AppSettings["APIKEY"]);
        }
        public ResultModel ReAssign(string sn, int assignFrom, int assignTo, out string activityName, out string processCode, out int procInstID)
        {
            Connection k2Connect = null;
            WorklistItem workList = null;
            ResultModel jr = new ResultModel() { Code = ResultCode.Fail };
            activityName = string.Empty;
            processCode = string.Empty;
            procInstID = 0;
            try
            {
                k2Connect = new Connection();
                k2Connect.Open(ConfigurationManager.AppSettings["K2Server"], ConfigurationManager.AppSettings["K2LoginString"]);
                k2Connect.ImpersonateUser(SecurityLable(assignFrom.ToString()));
                workList = k2Connect.OpenWorklistItem(sn);
                if (workList != null )
                {
                    workList.Redirect(SecurityLable(assignTo.ToString()));
                    jr.Code = ResultCode.Sucess;
                    jr.Msg = "";
                    activityName = workList.ActivityInstanceDestination.Name;
                    processCode = workList.ProcessInstance.DataFields["ProcessCode"].Value.ToString();
                    procInstID = workList.ProcessInstance.ID;

                }

            }
            catch (Exception ex)
            {
                jr.Msg = ex.Message;
            }
            finally
            {
                if (workList != null)
                {
                    if (workList.Status == WorklistStatus.Open)
                    {
                        try
                        {
                            k2Connect.RevertUser();
                            workList.Release();
                        }
                        catch { }
                    }
                }
                if (k2Connect != null)
                    k2Connect.Close();
            }
            return jr;
        }
        public ResultModel Start(string processCode, int loginId, string objectId, string folio, string jsonData, string apiKey)
        {
            Cat.GetProducer().NewTransaction("URL-WebService", "Start");
            var a = Cat.GetManager().PeekTransaction;
            ResultModel result = null;

            try
            {
                if (APIKeyUtility.IsRightAPIKey(apiKey))
                {
                    result = WorkFlowProcessService.StartProcess(processCode, loginId, objectId, folio, jsonData); ;
                }
                else
                {
                    result = new ResultModel() { Code = ResultCode.Fail, Msg = "ApiKey错误" };
                }
                a.Status = "0";
            }
            catch (Exception ex)
            {

                //Cat.GetProducer().LogEvent("Start", "Arguments", "0", string.Format);

                Cat.GetProducer().LogError(ex);
                a.SetStatus(ex);
                throw ex;
            }
            finally {
                a.Complete();
            }
            return result;
        }
        public ResultModel ReAssignTask(string sn, int assignFromLoginId, string assignFromRealName, int assignToLoginId, string assignToRealName, bool isAddLog, string apiKey)
        {
            Cat.GetProducer().NewTransaction("URL-WebService", "ReAssignTask");
            var a = Cat.GetManager().PeekTransaction;
            ResultModel result = null;

            try
            {
                if (APIKeyUtility.IsRightAPIKey(apiKey))
                {
                    result = WorkFlowTaskService.ReAssign(sn, assignFromLoginId, assignFromRealName, assignToLoginId, assignToRealName, isAddLog);
                }
                else
                {
                    result = new ResultModel() { Code = ResultCode.Fail, Msg = "ApiKey错误" };
                }
                a.Status = "0";
            }
            catch (Exception ex)
            {
                Cat.GetProducer().LogError(ex);
                a.SetStatus(ex);
                throw ex;
            }
            finally
            {
                a.Complete();
            }
            return result;
        }