コード例 #1
0
        public IActionResult backFlow(string systemcode, string flowid, string groupid, string taskid, string instanceid, string senderid, string tasktitle, string comment, int formtype)
        {
            Dictionary <string, object> r = new Dictionary <string, object>();
            DataTable firsttesp           = new DataTable();

            RoadFlow.Business.FlowTask flowTask = new RoadFlow.Business.FlowTask();
            //var taskid = string.Empty;
            #region 获取流程第一步步骤
            using (RoadFlow.Mapper.DataContext context = new RoadFlow.Mapper.DataContext())
            {
                firsttesp = context.GetDataTable("select top 1 * from RF_FlowTask where groupId='" + groupid + "' and InstanceId = '" + instanceid + "' ORDER BY ReceiveTime desc");
            }
            //if (firsttesp!=null&& firsttesp.Rows.Count==1)
            //{
            //    taskid = firsttesp.Rows[0]["Id"].ToString();
            //}
            var flowRunModel = new RoadFlow.Business.Flow().GetFlowRunModel(new Guid(flowid));
            if (null == flowRunModel)
            {
                r["code"]    = -1;
                r["message"] = "未找到流程运行时";
                return(Json(r));
            }
            JArray jArray     = new JArray();
            Guid   groupId    = Guid.Empty;
            string instanceId = string.Empty;

            foreach (DataRow step in firsttesp.Rows)
            {
                JObject jObject1 = new JObject
                {
                    { "id", step["StepId"].ToString() },
                    { "name", step["StepName"].ToString() },
                    { "users", "u_" + step["SenderId"].ToString() },
                    { "note", step["Note"].ToString() }
                };
                jArray.Add(jObject1);
            }
            #endregion
            #region 发送流程
            JArray steps = jArray;
            if (!flowid.IsGuid(out Guid flowGuid))
            {
                r["code"]    = -1;
                r["message"] = "参数flowid不是Guid";
                return(Json(r));
            }
            if (!senderid.IsGuid(out Guid senderGuid))
            {
                r["code"]    = -1;
                r["message"] = "参数senderid不是Guid";
                return(Json(r));
            }
            RoadFlow.Business.User     user     = new RoadFlow.Business.User();
            RoadFlow.Business.Organize organize = new RoadFlow.Business.Organize();
            var sender = user.Get(senderGuid);
            if (null == sender)
            {
                r["code"]    = -1;
                r["message"] = "未找到发送人";
                return(Json(r));
            }
            //RoadFlow.Business.FlowTask flowTask = new RoadFlow.Business.FlowTask();
            RoadFlow.Model.FlowTask currentTask = null;
            if (taskid.IsGuid(out Guid taskGuid2))
            {
                currentTask = flowTask.Get(taskGuid2);
            }

            RoadFlow.Model.FlowRunModel.Execute executeModel = new RoadFlow.Model.FlowRunModel.Execute();
            executeModel.Comment     = comment;
            executeModel.ExecuteType = flowTask.GetExecuteType("back");
            executeModel.FlowId      = flowGuid;
            executeModel.InstanceId  = instanceid;
            executeModel.Sender      = sender;
            executeModel.Title       = tasktitle;
            if (null != currentTask)
            {
                executeModel.GroupId = currentTask.GroupId;
                executeModel.StepId  = currentTask.StepId;
                executeModel.TaskId  = currentTask.Id;
                if (instanceId.IsNullOrWhiteSpace())
                {
                    instanceId = currentTask.InstanceId;
                }
                if (tasktitle.IsNullOrWhiteSpace())
                {
                    tasktitle = currentTask.Title;
                }
            }
            else
            {
                var flowRunModel2 = new RoadFlow.Business.Flow().GetFlowRunModel(flowGuid);
                if (null == flowRunModel2)
                {
                    r["code"]    = -1;
                    r["message"] = "未找到流程运行时";
                    return(Json(r));
                }
                executeModel.StepId = flowRunModel.FirstStepId;
            }
            if (null != steps)
            {
                List <(Guid, string, Guid?, int?, List <RoadFlow.Model.User>, DateTime?)> nextSteps = new List <(Guid, string, Guid?, int?, List <RoadFlow.Model.User>, DateTime?)>();
                foreach (JObject step in steps)
                {
                    string id     = step["id"].ToString();
                    Guid   stepId = id.ToGuid();
                    //string stepName = step.Value<string>("name");
                    //string beforeStepId = step.Value<string>("beforestepid");//原步骤ID(动态步骤的原步骤ID)
                    //string parallelorserial = step.Value<string>("parallelorserial");//0并且 1串行
                    //List<RoadFlow.Model.User> users = organize.GetAllUsers(step.Value<string>("users"));
                    string stepName                  = step["name"].ToString();
                    string beforeStepId              = step["beforestepid"] == null ? null : step["beforestepid"].ToString();         //原步骤ID(动态步骤的原步骤ID)
                    string parallelorserial          = step["parallelorserial"] == null ? null : step["parallelorserial"].ToString(); //0并且 1串行
                    List <RoadFlow.Model.User> users = organize.GetAllUsers(step["users"].ToString());
                    string datetTime                 = step.Value <string>("completedtime");
                    nextSteps.Add((stepId, stepName,
                                   beforeStepId.IsGuid(out Guid beforeStepGuid) ? new Guid?(beforeStepGuid) : new Guid?(),
                                   parallelorserial.IsInt(out int parallelorserialInt) ? new int?(parallelorserialInt) : new int?(),
                                   users, datetTime.IsDateTime(out DateTime dateTime) ? dateTime : new DateTime?()));
                }
                executeModel.Steps = nextSteps;
            }
            RoadFlow.Model.FlowRunModel.ExecuteResult executeResult = flowTask.Execute(executeModel);
            int    errCode = executeResult.IsSuccess ? 0 : 2001;
            string errMsg  = executeResult.Messages;
            //r["code"] = errCode;
            //r["message"] = errMsg;
            //r["data"] = JObject.FromObject(executeResult);
            if (errCode == 0)
            {
                DBTool db = new DBTool("");
                if (formtype == 0)
                {
                    string sql    = "UPDATE jy_cbjh set PROCESS_STATE={0} where XMBH='" + instanceid + "'";
                    int    status = 3;

                    sql = string.Format(sql, status);
                    if (db.ExecutByStringResult(sql) == "")
                    {
                        r["code"]    = 2000;
                        r["message"] = "审批已退回!";
                    }
                    else
                    {
                        r["code"]    = -1;
                        r["message"] = "失败!";
                    }
                }
                else if (formtype == 1)
                {
                    string sql    = "UPDATE jy_fybx set PROCESS_STATE={0} where BXDH='" + instanceid + "'";
                    int    status = 3;
                    sql = string.Format(sql, status);
                    if (db.ExecutByStringResult(sql) == "")
                    {
                        r["code"]    = 2000;
                        r["message"] = "审批已退回!";
                    }
                    else
                    {
                        r["code"]    = -1;
                        r["message"] = "失败!";
                    }
                }
                else if (formtype == 2)
                {
                    string sql    = "UPDATE jy_clbx set PROCESS_STATE={0} where CLBH='" + instanceid + "'";
                    int    status = 3;
                    sql = string.Format(sql, status);
                    if (db.ExecutByStringResult(sql) == "")
                    {
                        r["code"]    = 2000;
                        r["message"] = "审批已退回!";
                    }
                    else
                    {
                        r["code"]    = -1;
                        r["message"] = "失败!";
                    }
                }
            }
            else
            {
                r["code"]    = errCode;
                r["message"] = errMsg;
            }
            return(Json(r));

            #endregion
        }
コード例 #2
0
        public IActionResult sendFlow(string systemcode, string stepid, string flowid, string taskid, string instanceid, string senderid, string tasktitle, string comment, string type, bool isFreeSend, int formtype)
        {
            Dictionary <string, object> r = new Dictionary <string, object>();

            #region 获取流程步骤
            if (systemcode == null || systemcode.Length == 0)
            {
                r["code"]    = -1;
                r["message"] = "参数systemcode为空";
                return(Json(r));
            }
            var flowRunModel = new RoadFlow.Business.Flow().GetFlowRunModel(new Guid(flowid));
            if (null == flowRunModel)
            {
                r["code"]    = -1;
                r["message"] = "未找到流程运行时";
                return(Json(r));
            }
            if (!stepid.IsGuid(out Guid stepGuid))
            {
                stepGuid = flowRunModel.FirstStepId;
            }
            RoadFlow.Business.FlowTask flowTask = new RoadFlow.Business.FlowTask();
            Guid   groupId    = Guid.Empty;
            string instanceId = string.Empty;
            bool   isMobile   = false;
            if (taskid.IsGuid(out Guid taskGuid))
            {
                var task = flowTask.Get(taskGuid);
                if (null != task)
                {
                    groupId    = task.GroupId;
                    instanceId = task.InstanceId;
                }
            }

            var(html, message, sendSteps) = flowTask.GetNextSteps(flowRunModel, stepGuid, groupId, taskGuid, instanceId, senderid.ToGuid(), isFreeSend, isMobile);
            JObject jObject = RoadFlow.Mvc.ApiTools.GetJObject();
            JArray  jArray  = new JArray();
            foreach (var step in sendSteps)
            {
                JObject jObject1 = new JObject
                {
                    { "id", step.Id },
                    { "name", step.Name },
                    { "users", step.RunDefaultMembers },
                    { "note", step.Note }
                };
                jArray.Add(jObject1);
            }
            #endregion
            #region 发送流程
            JArray steps = jArray;
            if (!flowid.IsGuid(out Guid flowGuid))
            {
                r["code"]    = -1;
                r["message"] = "参数flowid不是Guid";
                return(Json(r));
            }
            if (!senderid.IsGuid(out Guid senderGuid))
            {
                r["code"]    = -1;
                r["message"] = "参数senderid不是Guid";
                return(Json(r));
            }
            RoadFlow.Business.User     user     = new RoadFlow.Business.User();
            RoadFlow.Business.Organize organize = new RoadFlow.Business.Organize();
            var sender = user.Get(senderGuid);
            if (null == sender)
            {
                r["code"]    = -1;
                r["message"] = "未找到发送人";
                return(Json(r));
            }
            //RoadFlow.Business.FlowTask flowTask = new RoadFlow.Business.FlowTask();
            RoadFlow.Model.FlowTask currentTask = null;
            if (taskid.IsGuid(out Guid taskGuid2))
            {
                currentTask = flowTask.Get(taskGuid2);
            }

            RoadFlow.Model.FlowRunModel.Execute executeModel = new RoadFlow.Model.FlowRunModel.Execute();
            executeModel.Comment     = comment;
            executeModel.ExecuteType = flowTask.GetExecuteType(type);
            executeModel.FlowId      = flowGuid;
            executeModel.InstanceId  = instanceid;
            executeModel.Sender      = sender;
            executeModel.Title       = tasktitle;
            if (null != currentTask)
            {
                executeModel.GroupId = currentTask.GroupId;
                executeModel.StepId  = currentTask.StepId;
                executeModel.TaskId  = currentTask.Id;
                if (instanceId.IsNullOrWhiteSpace())
                {
                    instanceId = currentTask.InstanceId;
                }
                if (tasktitle.IsNullOrWhiteSpace())
                {
                    tasktitle = currentTask.Title;
                }
            }
            else
            {
                var flowRunModel2 = new RoadFlow.Business.Flow().GetFlowRunModel(flowGuid);
                if (null == flowRunModel2)
                {
                    r["code"]    = -1;
                    r["message"] = "未找到流程运行时";
                    return(Json(r));
                }
                executeModel.StepId = flowRunModel.FirstStepId;
            }
            if (null != steps)
            {
                List <(Guid, string, Guid?, int?, List <RoadFlow.Model.User>, DateTime?)> nextSteps = new List <(Guid, string, Guid?, int?, List <RoadFlow.Model.User>, DateTime?)>();
                foreach (JObject step in steps)
                {
                    string id     = step["id"].ToString();
                    Guid   stepId = id.ToGuid();
                    //string stepName = step.Value<string>("name");
                    //string beforeStepId = step.Value<string>("beforestepid");//原步骤ID(动态步骤的原步骤ID)
                    //string parallelorserial = step.Value<string>("parallelorserial");//0并且 1串行
                    //List<RoadFlow.Model.User> users = organize.GetAllUsers(step.Value<string>("users"));
                    string stepName                  = step["name"].ToString();
                    string beforeStepId              = step["beforestepid"] == null ? null : step["beforestepid"].ToString();         //原步骤ID(动态步骤的原步骤ID)
                    string parallelorserial          = step["parallelorserial"] == null ? null : step["parallelorserial"].ToString(); //0并且 1串行
                    List <RoadFlow.Model.User> users = organize.GetAllUsers(step["users"].ToString());
                    string datetTime                 = step.Value <string>("completedtime");
                    nextSteps.Add((stepId, stepName,
                                   beforeStepId.IsGuid(out Guid beforeStepGuid) ? new Guid?(beforeStepGuid) : new Guid?(),
                                   parallelorserial.IsInt(out int parallelorserialInt) ? new int?(parallelorserialInt) : new int?(),
                                   users, datetTime.IsDateTime(out DateTime dateTime) ? dateTime : new DateTime?()));
                }
                executeModel.Steps = nextSteps;
            }
            RoadFlow.Model.FlowRunModel.ExecuteResult executeResult = flowTask.Execute(executeModel);
            int    errCode = executeResult.IsSuccess ? 0 : 2001;
            string errMsg  = executeResult.Messages;
            //r["code"] = errCode;
            //r["message"] = errMsg;
            //r["data"] = JObject.FromObject(executeResult);
            if (errCode == 0)
            {
                DBTool db = new DBTool("");
                if (formtype == 0)
                {
                    string sql    = "UPDATE jy_cbjh set PROCESS_STATE={0} where XMBH='" + instanceid + "'";
                    int    status = 0;
                    if (steps.Count != 0)
                    {
                        status = 1;
                    }
                    else
                    {
                        status = 2;
                    }
                    sql = string.Format(sql, status);
                    if (db.ExecutByStringResult(sql) == "")
                    {
                        r["code"]    = 2000;
                        r["message"] = "流程流转成功!";
                    }
                    else
                    {
                        r["code"]    = -1;
                        r["message"] = "失败!";
                    }
                }
                else if (formtype == 1)
                {
                    string sql    = "UPDATE jy_fybx set PROCESS_STATE={0} where BXDH='" + instanceid + "'";
                    int    status = 0;
                    if (steps.Count != 0)
                    {
                        status = 1;
                    }
                    else
                    {
                        status = 2;
                    }
                    sql = string.Format(sql, status);
                    if (db.ExecutByStringResult(sql) == "")
                    {
                        r["code"]    = 2000;
                        r["message"] = "流程流转成功!";
                    }
                    else
                    {
                        r["code"]    = -1;
                        r["message"] = "失败!";
                    }
                }
                else
                {
                    string sql    = "UPDATE jy_clbx set PROCESS_STATE={0} where CLBH='" + instanceid + "'";
                    int    status = 0;
                    if (steps.Count != 0)
                    {
                        status = 1;
                    }
                    else
                    {
                        status = 2;
                    }
                    sql = string.Format(sql, status);
                    if (db.ExecutByStringResult(sql) == "")
                    {
                        r["code"]    = 2000;
                        r["message"] = "流程流转成功!";
                    }
                    else
                    {
                        r["code"]    = -1;
                        r["message"] = "失败!";
                    }
                }
            }
            else
            {
                r["code"]    = errCode;
                r["message"] = errMsg;
            }
            return(Json(r));

            #endregion
        }