public InvokeResult ReFlowTo(FlowAction flowAction)
        {
            InvokeResult result = new InvokeResult {
                Success = true
            };

            string strConnectId = GetHttpHeader("ConnectId");

            flowAction.FlowType = 1;

            result = ExecFlowAction(flowAction, strConnectId);
            return(result);
        }
        private InvokeResult ExecFlowAction(FlowAction flowAction, string strConnectId)
        {
            InvokeResult result = new InvokeResult {
                Success = true
            };

            string[] bIds = flowAction.BIZ_IDs.Split('|');
            //流转状态  0-正流,1-逆流  默认正流,正流(当前状态加上当前操作);逆流(当前状态)
            int iAction = 0;

            if (flowAction.FlowType == 0)
            {
                //默认正向流转
                iAction += flowAction.ProcessAction;
            }

            try
            {
                FlowDefineMapping flowDefineMapping = BuilderFactory.DefaultBulder(strConnectId).List <FlowDefineMapping>(new { MappingType = flowAction.MappingType, MappingColumn = flowAction.MappingColumn, MappingId = flowAction.MappingId }.ToStringObjectDictionary()).FirstOrDefault();
                if (flowDefineMapping != null && !string.IsNullOrEmpty(flowDefineMapping.FlowName))
                {
                    flowAction.FlowName = flowDefineMapping.FlowName;
                }

                //找出当前流程的最高去处和默认去处
                IList <FlowDefine> flowDefineList = BuilderFactory.DefaultBulder(strConnectId).List <FlowDefine>(new { FlowName = flowAction.FlowName, TableName = flowAction.TableName, TableColumn = flowAction.TableColumn, Status = 1, OrderByClause = " FlowTo ,CurrentState " }.ToStringObjectDictionary());

                //如果是流程到了最顶级的话或者未进入流程或者切换流程则跳回当前流程默认的最低级别,以达到重新开始流转效果
                string sql = "insert into PUB_Flow (FlowId,OperatedBy,OperatedOn,BIZ_ID,TableName,FlowDefineId," +
                             " FlowFrom,FlowTo,ProcessResult,ProcessComment,ProcessTitle )";
                sql += "select NEWID(),'" + NormalSession.UserId + "',GETDATE(),t.{0},k.TableName,k.FlowDefineId,k.CurrentState," +
                       " k.FlowTo,k.ProcessAction,'" + flowAction.ProcessComment + "',k.ProcessorTitle From  (select x.{0}," +
                       " (case when isnull(z.FlowName,'') <>'{2}' or y.FlowTo is null or y.FlowTo={4} then {3} else y.FlowTo end)  as prevState, " +
                       " (case when  isnull(z.FlowName,'') <>'{2}' then '{2}' else z.FlowName end) FlowName ," +
                       " isnull(z.TableColumn,'{0}') TableColumn, isnull(z.TableName,'{1}') TableName From " +
                       " (select a.{0},MAX(b.Id) as FId From {1} a left join Pub_Flow b  on a.{0}=b.BIZ_ID ";
                if (bIds.Length > 0 && bIds[0] != "")
                {
                    //去掉空值,并给每个值加上'',以逗号隔开(支持部分批量)
                    sql += " where a.{0} in( '" + string.Join("','", bIds.Where(s => !string.IsNullOrEmpty(s)).ToArray()) + "' )";
                }
                else
                {
                    //按区域进行过滤  以到达批量的效果
                    sql += " where a." + flowAction.MappingColumn + "= '" + flowAction.MappingId + "' ";
                    if (!string.IsNullOrEmpty(flowAction.WhereClause))
                    {
                        sql += " and " + flowAction.WhereClause;
                    }
                }
                sql += " group by a.{0} ) x left join Pub_Flow y on x.FId=y.Id left join Pub_FlowDefine z on " +
                       " y.FlowDefineId=z.FlowDefineId ) t left join Pub_FlowDefine k on k.CurrentState=t.prevState+{5}  " +
                       " and k.ProcessAction={5} and k.FlowName=t.FlowName and k.TableName=t.TableName and k.TableColumn=t.TableColumn" +
                       " where k.CurrentState={6} and k.ProcessAction={5} and k.FlowName='{2}' and k.TableName='{1}' and k.TableColumn='{0}'";

                string statements = string.Format(sql, flowAction.TableColumn, flowAction.TableName, flowAction.FlowName,
                                                  flowDefineList.First().FlowTo, flowDefineList.Last().FlowTo, iAction, flowAction.ProcessState + iAction);

                BuilderFactory.DefaultBulder(strConnectId).ExecuteNativeSqlNoneQuery(statements);

                //是否流到最顶级。是的话返回true
                FlowDefine flowdefine = flowDefineList.FirstOrDefault(s => (s.CurrentState == flowAction.ProcessState + iAction) && (s.ProcessAction == flowAction.ProcessAction));
                if (flowdefine != null && flowDefineList.Last() != null && flowdefine.FlowTo == flowDefineList.Last().FlowTo)
                {
                    result.ErrorMessage = "true";
                }
            }
            catch (Exception ex) {
                result.Success      = false;
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }