Ejemplo n.º 1
0
        public DataResult SubimtFlow(SubmitData submitData)
        {
            #region
            //submitData = new SubmitData();
            //StringBuilder sb2 = new StringBuilder();
            //sb2.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            //sb2.AppendLine("<System>");
            //sb2.AppendLine("  <Name>OA</Name>");
            //sb2.AppendLine("  <Version>1.0</Version>");
            //sb2.AppendLine("  <System>");
            //sb2.AppendLine("    <Function Description=\"事项审批\" Address=\"SmtOAPersonOffice.svc\" FuncName=\"CallApplicationService\" Binding=\"customBinding\" SplitChar=\"Г\">");
            //sb2.AppendLine("      <ParaStr>");
            //sb2.AppendLine("        <Para TableName=\"T_OA_APPROVALINFO\" Name=\"APPROVALID\" Description=\"报批件ID\" Value=\"\"></Para>");
            //sb2.AppendLine("      </ParaStr>");
            //sb2.AppendLine("    </Function>");
            //sb2.AppendLine("  </System>");
            //sb2.AppendLine("  <MsgOpen>");
            //sb2.AppendLine("    <AssemblyName>SMT.SaaS.OA.UI</AssemblyName>");
            //sb2.AppendLine("    <PublicClass>SMT.SaaS.OA.UI.Utility</PublicClass>");
            //sb2.AppendLine("    <ProcessName>CreateFormFromEngine</ProcessName>");
            //sb2.AppendLine("    <PageParameter>SMT.SaaS.OA.UI.UserControls.ApprovalForm_aud</PageParameter>");
            //sb2.AppendLine("    <ApplicationOrder>{APPROVALID}</ApplicationOrder>");
            //sb2.AppendLine("    <FormTypes>Audit</FormTypes>");
            //sb2.AppendLine("  </MsgOpen>");
            //sb2.AppendLine("  <Object Name=\"T_OA_APPROVALINFO\" Description=\"事项审批\" Key=\"APPROVALID\" id=\"ea454559-3810-4fa2-8500-b20c480dd4bd\">");
            //sb2.AppendLine("    <Attribute Name=\"CURRENTEMPLOYEENAME\" LableResourceID=\"CURRENTEMPLOYEENAME\" Description=\"提交者\" DataType=\"string\" DataValue=\"\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"APPROVALID\" LableResourceID=\"APPROVALID\" Description=\"报批件ID\" DataType=\"string\" DataValue=\"ea454559-3810-4fa2-8500-b20c480dd4bd\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"APPROVALCODE\" LableResourceID=\"CODINGMATTERS\" Description=\"事项编码\" DataType=\"string\" DataValue=\"BPJ201205050001\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"APPROVALTITLE\" LableResourceID=\"TITLEMATTERS\" Description=\"事项标题\" DataType=\"string\" DataValue=\"旧流程数据到新流程数据过度测试\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"TEL\" LableResourceID=\"TEL\" Description=\"电话\" DataType=\"string\" DataValue=\"88997744\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"ISCHARGE\" LableResourceID=\"ISCHARGE\" Description=\"是否有费用\" DataType=\"string\" DataValue=\"1\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"CHARGEMONEY\" LableResourceID=\"Fees\" Description=\"费用\" DataType=\"decimal\" DataValue=\"500\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"CHECKSTATE\" LableResourceID=\"CHECKSTATE\" Description=\"审批状态\" DataType=\"string\" DataValue=\"0\" DataText=\"审核中\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"OWNERID\" LableResourceID=\"OWNERID\" Description=\"所属员工\" DataType=\"string\" DataValue=\"1bc4b78a-d178-4499-b948-16e18a9d73d3\" DataText=\"人事001-人事经理-人力资源部-模拟测试公司\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"OWNERNAME\" LableResourceID=\"OWNERNAME\" Description=\"当事人\" DataType=\"string\" DataValue=\"人事001\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"OWNERCOMPANYID\" LableResourceID=\"OWNERCOMPANYID\" Description=\"所属公司\" DataType=\"string\" DataValue=\"491d6eac-3bae-47ca-8998-89d39fc6faea\" DataText=\"模拟测试公司\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"OWNERDEPARTMENTID\" LableResourceID=\"OWNERDEPARTMENTID\" Description=\"所属部门\" DataType=\"string\" DataValue=\"4b146209-9442-489a-b19d-b70bd6a720d6\" DataText=\"人力资源部\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"OWNERPOSTID\" LableResourceID=\"OWNERPOSTID\" Description=\"所属岗位\" DataType=\"string\" DataValue=\"6d438cb1-92a8-4a07-a2ab-49926c68d1cd\" DataText=\"人事经理\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"CREATEUSERID\" LableResourceID=\"CREATEUSERID\" Description=\"创建人\" DataType=\"string\" DataValue=\"1bc4b78a-d178-4499-b948-16e18a9d73d3\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"CREATEUSERNAME\" LableResourceID=\"CREATEUSERNAME\" Description=\"创建人\" DataType=\"string\" DataValue=\"人事001\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"CREATECOMPANYID\" LableResourceID=\"CREATECOMPANYID\" Description=\"创建公司\" DataType=\"string\" DataValue=\"491d6eac-3bae-47ca-8998-89d39fc6faea\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"CREATEDEPARTMENTID\" LableResourceID=\"CREATEDEPARTMENTID\" Description=\"创建人部门\" DataType=\"string\" DataValue=\"4b146209-9442-489a-b19d-b70bd6a720d6\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"CREATEPOSTID\" LableResourceID=\"CREATEPOSTID\" Description=\"创建人岗位\" DataType=\"string\" DataValue=\"6d438cb1-92a8-4a07-a2ab-49926c68d1cd\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"CREATEDATE\" LableResourceID=\"CREATEDATE\" Description=\"创建日期\" DataType=\"DateTime\" DataValue=\"2012/5/5 15:42:27\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"UPDATEUSERID\" LableResourceID=\"UPDATEUSERID\" Description=\"修改人\" DataType=\"string\" DataValue=\"\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"UPDATEUSERNAME\" LableResourceID=\"UPDATEUSERNAME\" Description=\"修改人名\" DataType=\"string\" DataValue=\"\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"UPDATEDATE\" LableResourceID=\"UPDATEDATE\" Description=\"修改时间\" DataType=\"DateTime\" DataValue=\"\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"CONTENT\" LableResourceID=\"CONTENT\" Description=\"内容\" DataType=\"RTF\" DataValue=\"ea454559-3810-4fa2-8500-b20c480dd4bd\" DataText=\"ea454559-3810-4fa2-8500-b20c480dd4bd\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"AttachMent\" LableResourceID=\"AttachMent\" Description=\"附件\" DataType=\"attachmentlist\" DataValue=\"ea454559-3810-4fa2-8500-b20c480dd4bd\" DataText=\"ea454559-3810-4fa2-8500-b20c480dd4bd\" />");
            //sb2.AppendLine("    <Attribute Name=\"POSTLEVEL\" LableResourceID=\"POSTLEVEL\" Description=\"岗位级别\" DataType=\"string\" DataValue=\"15\" DataText=\"15\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"TYPEAPPROVAL\" LableResourceID=\"TYPEAPPROVAL\" Description=\"事项类型\" DataType=\"string\" DataValue=\"5\" DataText=\"公司制度修改\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"TYPEAPPROVALONE\" LableResourceID=\"TYPEAPPROVALONE\" Description=\"上级事项审批类型\" DataType=\"string\" DataValue=\"0\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"TYPEAPPROVALTWO\" LableResourceID=\"TYPEAPPROVALTWO\" Description=\"上上级事项审批类型\" DataType=\"string\" DataValue=\"\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("    <Attribute Name=\"TYPEAPPROVALTHREE\" LableResourceID=\"TYPEAPPROVALTHREE\" Description=\"上上上级事项审批类型\" DataType=\"string\" DataValue=\"\" DataText=\"\"></Attribute>");
            //sb2.AppendLine("  </Object>");
            //sb2.AppendLine("</System>");

            //submitData.FlowSelectType = FlowSelectType.FixedFlow;
            //submitData.FormID = "ea454559-3810-4fa2-8500-b20c480dd4bd";
            //submitData.ModelCode = "T_OA_APPROVALINFO";
            //submitData.ApprovalUser = new UserInfo();
            //submitData.ApprovalUser.CompanyID = "491d6eac-3bae-47ca-8998-89d39fc6faea";
            //submitData.ApprovalUser.DepartmentID = "4b146209-9442-489a-b19d-b70bd6a720d6";
            //submitData.ApprovalUser.PostID = "6d438cb1-92a8-4a07-a2ab-49926c68d1cd";
            //submitData.ApprovalUser.UserID = "1bc4b78a-d178-4499-b948-16e18a9d73d3";
            //submitData.ApprovalUser.UserName = "******";
            //submitData.NextStateCode = "";
            //submitData.NextApprovalUser = new UserInfo();
            //submitData.NextApprovalUser.CompanyID = "";
            //submitData.NextApprovalUser.DepartmentID = "";
            //submitData.NextApprovalUser.PostID = "";
            //submitData.NextApprovalUser.UserID = "";
            //submitData.NextApprovalUser.UserName = "";
            //submitData.SubmitFlag = SubmitFlag.New;
            //submitData.XML = sb2.ToString();
            //submitData.FlowType = FlowType.Approval;
            //submitData.ApprovalResult = ApprovalResult.Pass;
            //submitData.ApprovalContent = "提交";
            #endregion
            //调试外网 st = new 调试外网();
            //return st.SubimtFlow(submitData);
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("submitData.FlowSelectType =\"" + submitData.FlowSelectType + "\";");
            sb.AppendLine("submitData.FormID = \"" + submitData.FormID + "\";");
            sb.AppendLine("submitData.ModelCode = \"" + submitData.ModelCode + "\";");
            sb.AppendLine("submitData.ApprovalUser.CompanyID = \"" + submitData.ApprovalUser.CompanyID + "\";");
            sb.AppendLine("submitData.ApprovalUser.DepartmentID = \"" + submitData.ApprovalUser.DepartmentID + "\";");
            sb.AppendLine("submitData.ApprovalUser.PostID = \"" + submitData.ApprovalUser.PostID + "\";");
            sb.AppendLine("submitData.ApprovalUser.UserID = \"" + submitData.ApprovalUser.UserID + "\";");
            sb.AppendLine("submitData.ApprovalUser.UserName = \"" + submitData.ApprovalUser.UserName + "\";");
            sb.AppendLine("submitData.NextStateCode = \"" + (submitData.NextStateCode != null ? submitData.NextStateCode : "空") + "\";");
            sb.AppendLine("submitData.NextApprovalUser = \"" + submitData.NextApprovalUser + "\";");
            sb.AppendLine("submitData.NextApprovalUser.CompanyID = \"" + (submitData.NextApprovalUser != null ? submitData.NextApprovalUser.CompanyID : "空") + "\";");
            sb.AppendLine("submitData.NextApprovalUser.DepartmentID = \"" + (submitData.NextApprovalUser != null ? submitData.NextApprovalUser.DepartmentID : "空") + "\";");
            sb.AppendLine("submitData.NextApprovalUser.PostID = \"" + (submitData.NextApprovalUser != null ? submitData.NextApprovalUser.PostID : "空") + "\";");
            sb.AppendLine("submitData.NextApprovalUser.UserID = \"" + (submitData.NextApprovalUser != null ? submitData.NextApprovalUser.UserID : "空") + "\";");
            sb.AppendLine("submitData.NextApprovalUser.UserName = \"" + (submitData.NextApprovalUser != null ? submitData.NextApprovalUser.UserName : "******") + "\";");
            sb.AppendLine("submitData.SubmitFlag = \"" + submitData.SubmitFlag + "\";");
            // sb.AppendLine("submitData.XML = \"" + submitData.XML + "\";");
            sb.AppendLine("submitData.FlowType = \"" + submitData.FlowType.ToString() + "\";");
            sb.AppendLine("submitData.ApprovalResult = \"" + submitData.ApprovalResult.ToString() + "\";");
            sb.AppendLine("submitData.ApprovalContent = \"" + submitData.ApprovalContent + "\";");
            LogHelper.WriteLog("提交审核的信息:\r\n" + sb.ToString() + "\r\n");
            LogHelper.WriteLog("流程引擎的XML数据", "SubimtFlow入口处:" + submitData.ApprovalContent + " FormID=" + submitData.FormID + ";ModelCode=" + submitData.ModelCode + " \r\n submitData.XML:\r\n" + submitData.XML);
            LogHelper.WriteLog("***********************************************开始" + DateTime.Now.ToString() + "***********************************************");
            string msg = "";

            // MsOracle.BeginTransaction(con);

            DateTime dtStart = DateTime.Now;
            DateTime dtEngineStart = DateTime.Now;
            DateTime dtEnd = DateTime.Now;
            DateTime dtCheckData = DateTime.Now;
            //using (TransactionScope ts = new TransactionScope())
            //设置2分钟超时时间
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(DateTime.Now.AddMinutes(2).Ticks)))
            {
                OracleConnection con = ADOHelper.GetOracleConnection();
                #region 事务处理

                //System.Threading.Thread.Sleep(60000);
                DataResult dataResult = new DataResult();
                FlowBLL2 Flowbill = new FlowBLL2();
                string AppCompanyID = "";  //申请公司
                string MessageUserID = ""; //申请人ID
                string MessageUserName = ""; //申请人名
                dataResult.FlowResult = FlowResult.SUCCESS;
                try
                {
                    #region 检查流程数据是否规范
                    if (!FlowBLL2.CheckFlowData(submitData, ref dataResult))
                    {
                        dataResult.FlowResult = FlowResult.FAIL;
                        {
                            //ts.Complete();
                            return dataResult;
                        }
                    }
                    #endregion
                    submitData.ApprovalResult = submitData.SubmitFlag == SubmitFlag.New ? ApprovalResult.Pass : submitData.ApprovalResult;
                    submitData.FlowSelectType = submitData.FlowSelectType == null ? FlowSelectType.FixedFlow : submitData.FlowSelectType;
                    #region
                    #region 检查是否已提交流程(对数据库操作)
                    msg += "检查是否已提交流程" + DateTime.Now.ToString() + "\r\n";
                    LogHelper.WriteLog("检查是否已提交流程FormID = " + submitData.FormID);
                    OracleConnection ocon = ADOHelper.GetOracleConnection();
                    CheckResult CheckFlowResult = Flowbill.CheckFlow2(ocon, submitData, dataResult);//对数据库操作                    
                    msg += "检查是否已提交流程完成" + DateTime.Now.ToString() + "\r\n";
                    LogHelper.WriteLog("检查是否已提交流程完成FormID =" + submitData.FormID);
                    dtCheckData = DateTime.Now;
                    dataResult = CheckFlowResult.APPDataResult;
                    if (CheckFlowResult.Flag == 0)//已审批:1,未审批:0
                    {
                        //ts.Complete();
                        //return dataResult;
                    }
                    if (ocon.State == ConnectionState.Open)
                    {
                        ocon.Close();
                    }

                    #endregion
                    dataResult.AppState = submitData.NextStateCode;
                    //提交新流程
                    if (submitData.SubmitFlag == SubmitFlag.New)
                    {
                        #region 新增
                        AppCompanyID = submitData.ApprovalUser.CompanyID;
                        if (submitData.FlowSelectType == FlowSelectType.FreeFlow)
                            //自选流程
                            dataResult = Flowbill.AddFreeFlow(con, submitData, dataResult);//对数据库操作
                        else
                        {
                            //固定流程
                            msg += "固定流程" + DateTime.Now.ToString() + "\r\n";
                            LogHelper.WriteLog("固定流程.Flowbill.AddFlow2");
                            dataResult = Flowbill.AddFlow2(con, submitData, dataResult, ref msg);//对数据库操作
                            msg += "固定流程完成" + DateTime.Now.ToString() + "\r\n";
                        }
                        #endregion

                    }
                    else if (submitData.SubmitFlag == SubmitFlag.Cancel)
                    {
                        #region 撤单
                        if (!string.IsNullOrEmpty(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT))
                        {
                            submitData.XML = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT;
                        }
                        submitData.ApprovalContent = "";
                        dataResult = Flowbill.CancelFlow(submitData, dataResult, CheckFlowResult.fd);
                        dataResult.SubmitFlag = submitData.SubmitFlag;
                        #endregion
                    }

                    //审批流程
                    else
                    {
                        msg += "审核" + DateTime.Now.ToString() + "\r\n";
                        #region  审核
                        if (!string.IsNullOrEmpty(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT))
                        {
                            submitData.XML = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT;
                        }
                        //引擎消息数据
                        AppCompanyID = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID;
                        MessageUserID = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATEUSERID;
                        MessageUserName = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME;
                        submitData.ApprovalUser.CompanyID = CheckFlowResult.fd[0].EDITCOMPANYID;
                        submitData.ApprovalUser.DepartmentID = CheckFlowResult.fd[0].EDITDEPARTMENTID;
                        submitData.ApprovalUser.PostID = CheckFlowResult.fd[0].EDITPOSTID;
                        submitData.FlowSelectType = (FlowSelectType)Convert.ToInt32(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.FLOWSELECTTYPE);
                        if (submitData.FlowSelectType == FlowSelectType.FreeFlow)
                            dataResult = Flowbill.ApprovalFreeFlow(con, submitData, dataResult, CheckFlowResult.fd);//对数据库操作、对服务操作
                        else
                            dataResult = Flowbill.ApprovalFlow2(con, submitData, dataResult, CheckFlowResult.fd, ref msg);
                        #endregion
                        msg += "审核完成" + DateTime.Now.ToString() + "\r\n";
                    }

                    #endregion
                    ModelInfo modelinfo = FlowBLL2.GetSysCodeByModelCode(con, submitData.ModelCode);//对数据库操作
                    if (dataResult.FlowResult == FlowResult.MULTIUSER)
                    {//如果检出有多个审核人时,返回界面让用户选择一个人进行审核
                        string users = "检出有多个审核人\r\n";
                        foreach (var u in dataResult.UserInfo)
                        {
                            users += "CompanyID      =" + u.CompanyID + "\r\n";
                            users += "DepartmentID   = " + u.DepartmentID + "\r\n";
                            users += "PostID         = " + u.PostID + "\r\n";
                            users += "serID          = " + u.UserID + "\r\n";
                            users += "UserName       = "******"\r\n";
                            users += "------------------------------------\r\n";
                        }
                        LogHelper.WriteLog(users + "检出有多个审核人,返回界面让用户选择一个人进行审核 FormID =" + submitData.FormID);
                        return dataResult;
                    }
                    //return dataResult;//测试检查流程用的,不能提交事务
                    LogHelper.WriteLog("模块名称:submitData.ModelCode=" + submitData.ModelCode + ";modelinfo.ModelName=" + modelinfo.ModelName);
                    //ts.Complete(); //提交事务                           
                    if (string.IsNullOrEmpty(strIsFlowEngine) || strIsFlowEngine.ToLower() == "true")
                    {
                        msg += "发送审批消息(调用引擎服务)" + DateTime.Now.ToString() + "\r\n";
                        #region 发送审批消息(调用引擎服务)
                        LogHelper.WriteLog("开始(调用引擎服务):SubmitEngineService");
                        SubmitEngineService(con, submitData, dataResult, modelinfo, CheckFlowResult, Flowbill, AppCompanyID, MessageUserID, MessageUserName, ref msg);
                        LogHelper.WriteLog("结束(调用引擎服务):SubmitEngineService");
                        #endregion
                        msg += "发送审批消息(调用引擎服务)完成" + DateTime.Now.ToString() + "\r\n";
                    }
                    dtEnd = DateTime.Now;
                    dataResult.SubmitFlag = submitData.SubmitFlag;
                    msg += "开始时间" + dtStart.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "\r\n";
                    msg += "结束时间" + dtEnd.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "\r\n";
                    msg += "完成时间" + DateDiff(dtEnd, dtStart);
                    ts.Complete();//提交事务
                    MsOracle.Close(con);//关闭数据库  
                    LogHelper.WriteLog("执行流程成功:FormID=" + submitData.FormID);
                    //LogHelper.WriteLog(msg);
                    return dataResult;
                }
                catch (Exception ex)
                {
                    ts.Dispose();
                    if (con.State == System.Data.ConnectionState.Open)
                    {
                        con.Close();
                        con.Dispose();
                    }
                    dataResult.RunTime += "---FlowEnd:" + DateTime.Now.ToString();
                    dataResult.FlowResult = FlowResult.FAIL;
                    // Flowbill              = null;
                    dataResult.Err = ex.Message;
                    // Tracer.Debug("FlowService: -" + submitData.FormID + "--submitDataXML:" + submitData.XML + "-" + ex.InnerException + ex.Message);
                    LogHelper.WriteLog("执行流程失败:FormID=" + submitData.FormID + " 异常信息:" + ex.Message);
                    return dataResult;
                }
                finally
                {
                    if (Flowbill.workflowRuntime != null && Flowbill.workflowRuntime.IsStarted)
                    {
                        Flowbill.workflowRuntime.Dispose();
                    }
                    if (con.State == System.Data.ConnectionState.Open)
                    {
                        con.Close();
                        con.Dispose();
                    }
                    dataResult = null;
                    // Tracer.Debug("-------Trace--FormID:" + submitData.FormID + "DateTime: Start:" + dtStart.ToString()  + "  EngineStart:" + dtEngineStart.ToString() + "  End:" + dtEnd.ToString() + "\n");

                }
                #endregion
            }

        }
Ejemplo n.º 2
0
        public DataResult SubimtFlow(SubmitData submitData)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("SubmitData.FlowSelectType =\"" + submitData.FlowSelectType + "\";");
            sb.AppendLine("SubmitData.FormID = \"" + submitData.FormID + "\";");
            sb.AppendLine("SubmitData.ModelCode = \"" + submitData.ModelCode + "\";");
            sb.AppendLine("SubmitData.ApprovalUser = \"" + submitData.ApprovalUser + "\";");
            sb.AppendLine("SubmitData.ApprovalUser.CompanyID = \"" + submitData.ApprovalUser.CompanyID + "\";");
            sb.AppendLine("SubmitData.ApprovalUser.DepartmentID = \"" + submitData.ApprovalUser.DepartmentID + "\";");
            sb.AppendLine("SubmitData.ApprovalUser.PostID = \"" + submitData.ApprovalUser.PostID + "\";");
            sb.AppendLine("SubmitData.ApprovalUser.UserID = \"" + submitData.ApprovalUser.UserID + "\";");
            sb.AppendLine("SubmitData.ApprovalUser.UserName = \"" + submitData.ApprovalUser.UserName + "\";");
            sb.AppendLine("SubmitData.NextStateCode = \"\";");
            sb.AppendLine("SubmitData.NextApprovalUser = \"" + submitData.NextApprovalUser + "\";");
            sb.AppendLine("SubmitData.NextApprovalUser.CompanyID = \"\";");
            sb.AppendLine("SubmitData.NextApprovalUser.DepartmentID = \"\";");
            sb.AppendLine("SubmitData.NextApprovalUser.PostID = \"\";");
            sb.AppendLine("SubmitData.NextApprovalUser.UserID = \"\";");
            sb.AppendLine("SubmitData.NextApprovalUser.UserName = \"\";");
            sb.AppendLine("SubmitData.SubmitFlag = \"" + submitData.SubmitFlag + "\";");
            //sb.AppendLine("SubmitData.XML = \"" + submitData.XML + "\";");
            sb.AppendLine("SubmitData.FlowType = \"" + submitData.FlowType + "\";");
            sb.AppendLine("SubmitData.ApprovalResult = \"" + submitData.ApprovalResult + "\";");
            sb.AppendLine("SubmitData.ApprovalContent = \"" + submitData .ApprovalContent+ "\";");


            LogHelper.WriteLog("***********************************************开始" + DateTime.Now.ToString() + "***********************************************\r\n");
            LogHelper.WriteLog("提交审核的信息:\r\n" + sb.ToString() + "\r\n");
            string msg = "";
           
           // MsOracle.BeginTransaction(con);
           
            DateTime dtStart       = DateTime.Now;
            DateTime dtEngineStart = DateTime.Now;
            DateTime dtEnd         = DateTime.Now;
            DateTime dtCheckData   = DateTime.Now;
            //using (TransactionScope ts = new TransactionScope())
            //设置2分钟超时时间
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(DateTime.Now.AddMinutes(2).Ticks)))
            {
                OracleConnection con = ADOHelper.GetOracleConnection();
                #region 事务处理
             
                //System.Threading.Thread.Sleep(60000);
                DataResult dataResult  = new DataResult();
                FlowBLL2 Flowbill      = new FlowBLL2();                
                string AppCompanyID    = "";  //申请公司
                string MessageUserID   = ""; //申请人ID
                string MessageUserName = ""; //申请人名
                dataResult.FlowResult = FlowResult.SUCCESS;
                try
                {
                    #region 检查流程数据是否规范
                    if (!FlowBLL2.CheckFlowData(submitData, ref dataResult))
                    {
                        dataResult.FlowResult = FlowResult.FAIL;
                        {
                          //ts.Complete();
                            return dataResult;
                        }
                    }
                   
                    #endregion 
                    submitData.ApprovalResult = submitData.SubmitFlag == SubmitFlag.New ? ApprovalResult.Pass : submitData.ApprovalResult;
                    submitData.FlowSelectType = submitData.FlowSelectType == null ? FlowSelectType.FixedFlow : submitData.FlowSelectType;                    
                    #region 
                    #region 检查是否已提交流程(对数据库操作)
                    msg += "检查是否已提交流程"+DateTime.Now.ToString()+"\r\n";
                    LogHelper.WriteLog("检查是否已提交流程FormID = " + submitData.FormID);

                    OracleConnection ocon = ADOHelper.GetOracleConnection();
                    CheckResult CheckFlowResult = Flowbill.CheckFlow2(ocon, submitData, dataResult);//对数据库操作                    
                    msg += "检查是否已提交流程完成" + DateTime.Now.ToString() + "\r\n";
                    LogHelper.WriteLog("检查是否已提交流程完成FormID =" + submitData.FormID);
                    dtCheckData = DateTime.Now;
                    dataResult = CheckFlowResult.APPDataResult;
                    if (CheckFlowResult.Flag == 0)//已审批:1,未审批:0
                    {
                        //ts.Complete();
                        //return dataResult;
                    }
                    if (ocon.State == ConnectionState.Open)
                    {
                        ocon.Close();
                    }
                    #endregion 
                    dataResult.AppState = submitData.NextStateCode;
                  
                    //提交新流程
                    if (submitData.SubmitFlag == SubmitFlag.New)
                    {
                        LogHelper.WriteLog("新增(开始) FormID =" + submitData.FormID);
                        #region 新增
                        AppCompanyID = submitData.ApprovalUser.CompanyID;
                        if (submitData.FlowSelectType == FlowSelectType.FreeFlow)
                        {
                            //自选流程
                            LogHelper.WriteLog("自选流程.Flowbill.AddFlow2 FormID =" + submitData.FormID);
                            dataResult = Flowbill.AddFreeFlow(con, submitData, dataResult);//对数据库操作
                        }
                        else
                        {
                            //固定流程
                            msg += "固定流程" + DateTime.Now.ToString() + "\r\n";
                            LogHelper.WriteLog("固定流程.Flowbill.AddFlow2 FormID =" + submitData.FormID);
                            dataResult = Flowbill.AddFlow2(con, submitData, dataResult, ref msg);//对数据库操作
                            msg += "固定流程完成" + DateTime.Now.ToString() + "\r\n";
                        }
                        #endregion 
                        LogHelper.WriteLog("新增(结束) FormID =" + submitData.FormID);

                    }
                    else if (submitData.SubmitFlag == SubmitFlag.Cancel)
                    {
                        #region 撤单
                        LogHelper.WriteLog("撤单(开始) FormID =" + submitData.FormID);
                        if (!string.IsNullOrEmpty(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT))
                        {
                            submitData.XML = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT;
                        }
                        submitData.ApprovalContent = "";
                        dataResult                 = Flowbill.CancelFlow(submitData, dataResult, CheckFlowResult.fd);
                        dataResult.SubmitFlag      = submitData.SubmitFlag;
                        LogHelper.WriteLog("撤单(结束) FormID =" + submitData.FormID);
                        #endregion 
                    }
                    
                    //审批流程
                    else
                    {
                        msg += "审核" + DateTime.Now.ToString() + "\r\n";
                        LogHelper.WriteLog("审核(开始) FormID =" + submitData.FormID);
                        #region  审核
                        if (!string.IsNullOrEmpty(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT))
                        {
                            submitData.XML = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT;
                        }                        
                        //引擎消息数据
                        AppCompanyID                         = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID;
                        MessageUserID                        = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATEUSERID;
                        MessageUserName                      = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME;                        
                        submitData.ApprovalUser.CompanyID    = CheckFlowResult.fd[0].EDITCOMPANYID;
                        submitData.ApprovalUser.DepartmentID = CheckFlowResult.fd[0].EDITDEPARTMENTID;
                        submitData.ApprovalUser.PostID       = CheckFlowResult.fd[0].EDITPOSTID;
                        submitData.FlowSelectType            = (FlowSelectType)Convert.ToInt32(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.FLOWSELECTTYPE);
                        if (submitData.FlowSelectType == FlowSelectType.FreeFlow)
                            dataResult = Flowbill.ApprovalFreeFlow(con, submitData, dataResult, CheckFlowResult.fd);//对数据库操作、对服务操作
                        else
                            dataResult = Flowbill.ApprovalFlow2(con, submitData, dataResult, CheckFlowResult.fd, ref msg);
                        #endregion 
                        LogHelper.WriteLog("审核(结束) FormID =" + submitData.FormID);
                        msg += "审核完成" + DateTime.Now.ToString() + "\r\n";
                    }
                    
                    #endregion                  
                    ModelInfo modelinfo = FlowBLL2.GetSysCodeByModelCode(con, submitData.ModelCode);
                    #region 记录审核人日志信息
                    string loginfo = "===================================FormID=" + submitData.FormID + "============================================\r\n";
                   
                    if (dataResult.IsCountersign.ToString().ToLower() == "true")
                    {
                        loginfo += "是否会签=" + dataResult.IsCountersign.ToString() + "\r\n";
                        loginfo += "是否会签完成" + dataResult.IsCountersignComplete.ToString() + "\r\n";
                    }
                    loginfo += "模块关联流程ID=" + dataResult.ModelFlowRelationID + "\r\n";
                    loginfo += "子模块代码=" + dataResult.SubModelCode + "\r\n";
                    if (dataResult.AgentUserInfo != null)
                    {
                       
                        loginfo = "\r\n 代理审核人 \r\n";
                        loginfo += "代理公司ID=" + dataResult.AgentUserInfo.CompanyID + "\r\n";
                        loginfo += "代理部门ID=" + dataResult.AgentUserInfo.DepartmentID + "\r\n";
                        loginfo += "代理岗位ID" + dataResult.AgentUserInfo.PostID + "\r\n";
                        loginfo += "代理用户ID=" + dataResult.AgentUserInfo.UserID + "\r\n";
                        loginfo += "代理用户名称=" + dataResult.AgentUserInfo.UserName + "\r\n";
                    }                    
                    if (dataResult.UserInfo.Count > 0)
                    {
                        if (dataResult.FlowResult == FlowResult.MULTIUSER)
                        {//如果检出有多个审核人时,返回界面让用户选择一个人进行审核
                            loginfo = "\r\n 检出有多个审核人 \r\n";
                        }
                        loginfo += "dataResult.UserInfo 审核人员信息\r\n";
                        foreach (var u in dataResult.UserInfo)
                        {
                            loginfo += "公司ID=" + u.CompanyID + "\r\n";
                            loginfo += "部门ID= " + u.DepartmentID + "\r\n";
                            loginfo += "岗位ID= " + u.PostID + "\r\n";
                            loginfo += "用户ID= " + u.UserID + "\r\n";
                            loginfo += "用户名= " + u.UserName + "\r\n";
                            loginfo += "------------------------------------\r\n";
                        }
                    }     
                    loginfo += "模块代码 ModelCode=" + submitData.ModelCode + "\r\n";
                    loginfo += "模块名称 ModelName=" + modelinfo.ModelName + "\r\n";
                    loginfo += "下一审批人 公司ID=" + submitData.NextApprovalUser.CompanyID + "\r\n";
                    loginfo += "下一审批人 部门ID=" + submitData.NextApprovalUser.DepartmentID + "\r\n";
                    loginfo += "下一审批人 岗位ID=" + submitData.NextApprovalUser.PostID + "\r\n";
                    loginfo += "下一审批人 用户ID=" + submitData.NextApprovalUser.UserID + "\r\n";
                    loginfo += "下一审批人 用户名=" + submitData.NextApprovalUser.UserName + "\r\n";
                    loginfo += "下一审批状态 NextStateCode=" + submitData.NextStateCode + "\r\n";
                    loginfo += "使用流程类型 submitData.FlowSelectType=" + submitData.FlowSelectType + "\r\n";
                    loginfo += "业务数据 submitData.XML(AppXML)=" + submitData.XML + "\r\n";
                    loginfo += "================================================================================\r\n";           
                    LogHelper.WriteLog(loginfo);

                    #endregion
                    //return dataResult;//测试检查流程用的,不能提交事务
                    //ts.Complete(); //提交事务                           
                    if (string.IsNullOrEmpty(strIsFlowEngine) || strIsFlowEngine.ToLower() == "true")
                    {
                        msg += "发送审批消息(调用引擎服务)" + DateTime.Now.ToString() + "\r\n";
                        #region 发送审批消息(调用引擎服务)
                        LogHelper.WriteLog("开始(调用引擎服务):SubmitEngineService FormID =" + submitData.FormID);
                        SubmitEngineService(con, submitData,  dataResult,  modelinfo,  CheckFlowResult,  Flowbill,  AppCompanyID,  MessageUserID,  MessageUserName,ref msg);
                        LogHelper.WriteLog("结束(调用引擎服务):SubmitEngineService FormID =" + submitData.FormID);
                        #endregion     
                        msg += "发送审批消息(调用引擎服务)完成" + DateTime.Now.ToString() + "\r\n";
                    }
                    dtEnd = DateTime.Now;
                    dataResult.SubmitFlag = submitData.SubmitFlag;
                    msg += "开始时间" + dtStart.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "\r\n";
                    msg += "结束时间" + dtEnd.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "\r\n";
                    msg += "完成时间" + DateDiff(dtEnd, dtStart);
                    ts.Complete();//提交事务
                    MsOracle.Close(con);//关闭数据库  
                    LogHelper.WriteLog("执行流程成功:FormID=" + submitData.FormID);
                    //LogHelper.WriteLog(msg);
                    return dataResult;
                }
                catch (Exception ex)
                {                    
                    ts.Dispose();
                    if (con.State == System.Data.ConnectionState.Open)
                    {
                        con.Close();
                        con.Dispose();
                    }
                    dataResult.RunTime += "---FlowEnd:" + DateTime.Now.ToString();
                    dataResult.FlowResult = FlowResult.FAIL;                  
                    dataResult.Err        = ex.Message;
                    //Tracer.Debug("FlowService: -" + submitData.FormID + "--submitDataXML:" + submitData.XML + "-" + ex.InnerException + ex.Message);
                    LogHelper.WriteLog("执行流程失败:FormID=" + submitData.FormID+" 异常信息:"+ ex.ToString());
                    return dataResult;
                }
                finally
                {
                    if (Flowbill.workflowRuntime != null && Flowbill.workflowRuntime.IsStarted)
                    {
                        Flowbill.workflowRuntime.Dispose();
                    }
                   // LogHelper.WriteLog(msg);
                    if (con.State == System.Data.ConnectionState.Open)
                    {
                        con.Close();
                        con.Dispose();
                    }     
                    dataResult = null;                   
                    //Tracer.Debug("-------Trace--FormID:" + submitData.FormID + "DateTime: Start:" + dtStart.ToString()  + "  EngineStart:" + dtEngineStart.ToString() + "  End:" + dtEnd.ToString() + "\n");
                    
                }
                #endregion
            }
               
        }