public void Execute(Quartz.IJobExecutionContext context) { Common.ScheduleService.Log.Instance.Info("合并流程服务,开始执行"); DateTime datetime = StaticResource.Instance.GetReportDateTime(); finMonth = datetime.Month; finYear = datetime.Year; //string[] array = System.Configuration.ConfigurationManager.AppSettings["GroupTypes"].Split(new char[] { ','},StringSplitOptions.RemoveEmptyEntries); var array = StaticResource.Instance.SystemList.Where(x => !string.IsNullOrEmpty(x.GroupType)); foreach (var c_System in array) { bool _WFStarts = true; Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程服务,读取批次表里是否有合适的数据Stare!"); B_SystemBatch batchModel = B_SystemBatchOperator.Instance.GetSystemBatchByDraft(c_System.GroupType, finYear, finMonth); if (batchModel == null) { continue; } if (batchModel != null) { Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "读取数据成功!" + batchModel.FinYear + "年" + batchModel.FinMonth + "月"); BatchRptList = JsonConvert.DeserializeObject <List <V_SubReport> >(batchModel.SubReport); int n = BatchRptList.Count(x => !x.IsReady); _WFStarts = n == 0; } Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程服务,读取批次表里是否有合适的数据End!"); if (_WFStarts) { string ProcessKey = c_System.Configuration.Element("ProcessCode").Value + "-HB"; //string ProcessKey = "YY_ZBGK-FDCHZ"; Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程服务,有符合条件的的数据!"); this.ProcessKey = ProcessKey; this.BusinessID = batchModel.ID.ToString(); Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程服务,有符合条件的的数据BusinessID=" + this.BusinessID + "!"); //添加日志 B_MonthlyReportAction _bMonthlyReportAction = new B_MonthlyReportAction(); _bMonthlyReportAction.SystemID = Guid.Empty; _bMonthlyReportAction.MonthlyReportID = batchModel.ID; _bMonthlyReportAction.FinYear = batchModel.FinYear; _bMonthlyReportAction.FinMonth = batchModel.FinMonth; _bMonthlyReportAction.Action = EnumHelper.GetEnumDescription(typeof(MonthlyReportLogActionType), (int)MonthlyReportLogActionType.Submit); _bMonthlyReportAction.Operator = this.CurrentUser; _bMonthlyReportAction.OperatorTime = DateTime.Now; _bMonthlyReportAction.ModifierName = this.CurrentUser; _bMonthlyReportAction.CreatorName = this.CurrentUser; B_MonthlyReportActionOperator.Instance.AddMonthlyReportAction(_bMonthlyReportAction); Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程服务,准备启动合并流程数据!"); try { if (!WFClientSDK.Exist(BusinessID)) //判断业务ID是否存在 { //开启流程 CallMethed("startprocess", c_System.GroupType); Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程服务,合并流程数据启动完成!"); } else { Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程服务,有错误!!!!!!"); //当汇总后流程退回,再次发起用该方法 if (batchModel.WFBatchStatus == "Draft") { #region 该方法只能在草稿状态的时候启动 try { string FinYear = batchModel.FinYear.ToString() + "年"; string FinMonth = batchModel.FinMonth.ToString("D2"); //string _Title = "项目系统(南、中、北、大项目)" + FinYear + FinMonth + "月度报告"; string _Title = c_System.SystemName + FinYear + FinMonth + "汇总月度报告"; Dictionary <string, string> Dic = new Dictionary <string, string>(); Dic["ReportName"] = _Title; Dic["ProcessKey"] = ProcessKey; #region 记录审批日志的Json Common.ScheduleService.Log.Instance.Info("合并流程再次启动开始!"); string opiniontext = string.Empty; //重新在批次表中,获取数据 BatchRptList = JsonConvert.DeserializeObject <List <V_SubReport> >(batchModel.SubReport); List <BPF.Workflow.Object.ProcessLog> _list = new List <ProcessLog>(); if (BatchRptList.Count > 0) { BatchRptList.ForEach(BR => { //B_MonthlyReport bm = B_MonthlyreportOperator.Instance.GetMonthlyreport(BR.ReportID); _list.AddRange(BPF.Workflow.Client.WFClientSDK.GetProcessLogList(BR.ReportID.ToString())); }); } batchModel.Opinions = JsonConvert.SerializeObject(_list.OrderByDescending(p => p.FinishDateTime)); #endregion WorkflowContext workflow = WFClientSDK.GetProcess(null, this.BusinessID, new UserInfo() { UserCode = "$VirtualUserCode$" + this.CurrentUser }); Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程,获取流程成功!"); //先启动流程,流程能启动了,在写入数据库流程审批日志 Dictionary <string, object> formParams = new Dictionary <string, object>(); formParams.Add("ReportName", _Title); formParams.Add("ProcessKey", ProcessKey); var DynamicRoleUserList = JsonUser.GetDynamicRoleUserList(ProcessKey); BizContext bizContext = new BizContext(); bizContext.NodeInstanceList = workflow.NodeInstanceList; bizContext.ProcessRunningNodeID = workflow.ProcessInstance.RunningNodeID; bizContext.BusinessID = BusinessID; bizContext.FlowCode = ProcessKey; bizContext.ApprovalContent = "各区域数据已经汇总完成,请领导审批"; bizContext.CurrentUser = new UserInfo() { UserCode = "$VirtualUserCode$" + this.CurrentUser }; bizContext.ProcessURL = "/BusinessReport/TargetApprove.aspx?ProType=Batch"; bizContext.FormParams = formParams; bizContext.DynamicRoleUserList = DynamicRoleUserList; bizContext.ExtensionCommond = new Dictionary <string, string>(); bizContext.ExtensionCommond.Add("RejectNode", Guid.Empty.ToString()); Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程,流程参数配置成功!"); WorkflowContext wfc = WFClientSDK.ExecuteMethod("SubmitProcess", bizContext); Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程,流程提交成功!"); OperationType = 1; //ProcessExecute(); //先启动流程,流程能启动了,在写入数据库流程审批日志 //ProcessResponse r = ClientProcess.MoveTo(BusinessID, "南、北、中、文旅项目已经汇总完成,请领导审批", Dic, "", true); //将批次的审批状态改变 ExceptionHelper.TrueThrow(batchModel == null, string.Format("cannot find the report data which id={0}", BusinessID)); batchModel.WFBatchStatus = "Progress"; //batchModel.Description = GetDescription(c_System.ID, batchModel.FinYear, batchModel.FinMonth); //获取流程导航 List <NavigatActivity1> listna = GetProcessIntance(wfc); if (listna.Count > 0) { batchModel.ReportApprove = JsonConvert.SerializeObject(listna); } B_SystemBatchOperator.Instance.UpdateSystemBatch(batchModel); Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程服务,再次合并流程数据启动完成!"); } catch (Exception ex) { Common.ScheduleService.Log.Instance.Error(c_System.SystemName + "合并流程再次启动失败!,错误信息:" + ex.ToString()); } #endregion } } } catch (Exception ex) { Common.ScheduleService.Log.Instance.Error("合并流程启动失败!,错误信息:" + ex.ToString()); } } else { Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程服务,没有查找到符合条件合并流程!"); } } }
protected void StartProcess(string groupType) { Dictionary <string, object> formParams = new Dictionary <string, object>(); var c_System = StaticResource.Instance.SystemList.Where(x => x.GroupType == groupType).FirstOrDefault(); string ProcessKey = c_System.Configuration.Element("ProcessCode").Value + "-HB"; //string ProcessKey = "YY_ZBGK-FDCHZ"; //系统2014年7月月报 B_SystemBatch batch = B_SystemBatchOperator.Instance.GetSystemBatch(Guid.Parse(BusinessID)); string FinYear = batch.FinYear.ToString() + "年"; string FinMonth = batch.FinMonth.ToString("D2"); string _Title = c_System.SystemName + FinYear + FinMonth + "汇总月度报告"; formParams.Add("ReportName", _Title); formParams.Add("ProcessKey", ProcessKey); Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程服务,合并流程启动, 上报年:" + FinYear + ",上报月:" + FinMonth); Dictionary <string, string> Dic = new Dictionary <string, string>(); Dic["ReportName"] = _Title; Dic["ProcessKey"] = ProcessKey; WorkflowContext wfc = null; try { Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程启动开始!"); var dynamicRoleUserList = JsonUser.GetDynamicRoleUserList(ProcessKey); var starup = new BPF.Workflow.Client.WFStartupParameter() { FlowCode = ProcessKey, BusinessID = this.BusinessID, CurrentUser = new UserInfo() { UserCode = "$VirtualUserCode$" + this.CurrentUser }, FormParams = formParams, DynamicRoleUserList = dynamicRoleUserList, }; string opiniontext = string.Empty; //重新在批次表中,获取数据 BatchRptList = JsonConvert.DeserializeObject <List <V_SubReport> >(batch.SubReport); List <BPF.Workflow.Object.ProcessLog> _list = new List <ProcessLog>(); if (BatchRptList.Count > 0) { BatchRptList.ForEach(BR => { //B_MonthlyReport bm = B_MonthlyreportOperator.Instance.GetMonthlyreport(BR.ReportID); _list.AddRange(BPF.Workflow.Client.WFClientSDK.GetProcessLogList(BR.ReportID.ToString())); }); } batch.Opinions = JsonConvert.SerializeObject(_list); WorkflowContext workflow = WFClientSDK.CreateProcess(null, starup); Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "项目系统合并流程启动中!"); BizContext bizContext = new BizContext(); bizContext.NodeInstanceList = workflow.NodeInstanceList; bizContext.ProcessRunningNodeID = workflow.ProcessInstance.RunningNodeID; bizContext.BusinessID = BusinessID; bizContext.FlowCode = ProcessKey; bizContext.ApprovalContent = c_System.SystemName + "各区域数据已经汇总完成,请领导审批"; // bizContext.CurrentUser = new UserInfo() { UserCode = "$VirtualUserCode$项目汇总服务" }; bizContext.CurrentUser = new UserInfo() { UserCode = "$VirtualUserCode$" + this.CurrentUser }; bizContext.ProcessURL = "/BusinessReport/TargetApprove.aspx?ProType=Batch"; bizContext.FormParams = formParams; bizContext.ExtensionCommond = new Dictionary <string, string>(); bizContext.ExtensionCommond.Add("RejectNode", Guid.Empty.ToString()); bizContext.DynamicRoleUserList = dynamicRoleUserList; wfc = WFClientSDK.ExecuteMethod("SubmitProcess", bizContext); if (wfc.StatusCode != 0) { throw new Exception(wfc.StatusMessage + "; BusinessID = " + BusinessID); } //提交操作状态为1 OperationType = 1; Common.ScheduleService.Log.Instance.Info(c_System.SystemName + "合并流程启动结束!"); } catch (Exception ex) { Common.ScheduleService.Log.Instance.Error(c_System.SystemName + "合并流程启动失败!,错误信息:" + ex.ToString()); batch = null; } //将批次的审批状态改变 ExceptionHelper.TrueThrow(batch == null, string.Format("cannot find the report data which id={0}", BusinessID)); batch.WFBatchStatus = "Progress"; //跟新后面两个大老板的状态 //var AP = ProcessResponse.GetProcess(batch.ID.ToString(), null); //List<NavigatActivity> APlist = AP.Navigat; //string Json = Newtonsoft.Json.JsonConvert.SerializeObject(APlist); //batch.ReportApprove = Json; //获取流程导航 List <NavigatActivity1> listna = GetProcessIntance(wfc); if (listna.Count > 0) { batch.ReportApprove = JsonConvert.SerializeObject(listna); } //batch.Description = GetDescription(c_System.ID, batch.FinYear, batch.FinMonth); //修改批次数据 B_SystemBatchOperator.Instance.UpdateSystemBatch(batch); }