예제 #1
0
        public IActionResult revokeFlow(string instanceid, string senderid, 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;

            using (RoadFlow.Mapper.DataContext context = new RoadFlow.Mapper.DataContext())
            {
                firsttesp = context.GetDataTable("select top 1 * from RF_FlowTask where Status =2 and InstanceId = '" + instanceid + "' and ReceiveId='" + senderid + "' ORDER BY ReceiveTime desc");
            }
            if (firsttesp != null && firsttesp.Rows.Count == 1)
            {
                taskid = firsttesp.Rows[0]["Id"].ToString();
            }

            if (!string.IsNullOrEmpty(taskid) && !string.IsNullOrEmpty(instanceid))
            {
                DBTool db   = new DBTool("");
                string flag = db.GetString("select  count(1) from RF_FlowTask where previd = '" + taskid + "' and Status in(0,1) "); //判断是否可以撤回
                if (!string.IsNullOrEmpty(flag) && flag != "0")                                                                      //只允许发起人撤回下一步未审批的流程
                //if (!string.IsNullOrEmpty(flag))//发起人可撤回任意状态的流程
                {
                    string updateSql = string.Empty;
                    string revokeSql = "delete from  RF_FlowTask where InstanceId = '" + instanceid + "' and (previd ='" + taskid + "' or id='" + taskid + "')";//只允许发起人撤回下一步未审批的流程
                    //string revokeSql = "delete from  RF_FlowTask where InstanceId = '" + instanceid + "'";//发起人可撤回任意状态的流程
                    if (formtype == 0)
                    {
                        updateSql = "UPDATE jy_cbjh set PROCESS_STATE=0 where XMBH='" + instanceid + "'";
                    }
                    else if (formtype == 1)
                    {
                        updateSql = "UPDATE jy_fybx set PROCESS_STATE=0 where BXDH='" + instanceid + "'";
                    }
                    else
                    {
                        updateSql = "UPDATE jy_clbx set PROCESS_STATE=0 where CLBH='" + instanceid + "'";
                    }
                    List <string> list = new List <string>();
                    list.Add(revokeSql);
                    list.Add(updateSql);
                    string result = db.Executs(list);
                    if (result == "")
                    {
                        r["code"]    = 2000;
                        r["message"] = "审批已撤回!";
                    }
                }
                else
                {
                    r["code"]    = -1;
                    r["message"] = "撤销失败!流程已被审批!";
                }
            }
            else
            {
                r["code"]    = -1;
                r["message"] = "撤销失败!参数异常!";
            }

            return(Json(r));
        }
예제 #2
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
        }