/// <summary> /// 初始化 BPMServiceInfo /// </summary> /// <param name="sourceId"></param> /// <param name="requestMessage"></param> /// <param name="k2Id"></param> /// <returns></returns> public BPMServiceModel InitBPMServiceInfo(string sourceId, string requestMessage, string k2Id = "") { System.Diagnostics.StackTrace ss = new System.Diagnostics.StackTrace(true); System.Reflection.MethodBase mb = ss.GetFrame(1).GetMethod(); var interfaceName = mb.Name; //父方法名 父方法类名(mb.DeclaringType.Name) var logId = Guid.NewGuid().ToString(); BPMServiceModel BPMServiceInfo = new BPMServiceModel() { ResponseInfo = new ResponseResultModel() { logId = logId }, InterfaceLog = new PrcServer_BPMInterfaceLog() { LogID = logId, SourceId = sourceId, K2ID = k2Id, InterfaceName = interfaceName, RequestMessage = requestMessage, RequestTime = DateTime.Now } }; return(BPMServiceInfo); }
/// <summary> /// 错误返回信息,并记录日志 /// </summary> /// <param name="serviceInfo"></param> /// <param name="proStartInfo"></param> /// <param name="errorCodeType"></param> /// <param name="returnStatus"></param> public void ProStartAddErrorInfo(BPMServiceModel serviceInfo, ProcessStartArgs proStartInfo, int errorCodeType = 1) { serviceInfo.ResponseInfo.returnStatus = 500; serviceInfo.ResponseInfo.returnMsg = errorCodeType == 0 ? "requestInfo参数缺失." : serviceInfo.ResponseInfo.returnMsg; serviceInfo.ResponseInfo.returnCode = errorCodeType == 999 ? "E0999" : "E000" + errorCodeType; if (proStartInfo != null) { serviceInfo.InterfaceLog.BizID = proStartInfo.bizId; serviceInfo.InterfaceLog.ProcessCode = proStartInfo.processCode; } //记录日志 _interfaceLogService.AddBPMInterfaceLogInfo(serviceInfo); }
/// <summary> /// 流程发起 /// </summary> /// <param name="serviceInfo"></param> /// <param name="requestInfo">发起接口Model数据</param> /// <returns></returns> public ResponseResultModel ProcessStart(BPMServiceModel serviceInfo, ProcessStartArgs requestInfo) { //校验参数数据正确性 serviceInfo.ResponseInfo.returnMsg = VerifyArgsData(requestInfo); if (!string.IsNullOrWhiteSpace(serviceInfo.ResponseInfo.returnMsg)) { ProStartAddErrorInfo(serviceInfo, requestInfo, 2); return(serviceInfo.ResponseInfo); } //获取流程发起信息 var processInfo = _processBusService.GetProcessStartInfo(requestInfo); if (!string.IsNullOrWhiteSpace(processInfo.ResultInfo.Message)) { serviceInfo.ResponseInfo.returnMsg = processInfo.ResultInfo.Message; ProStartAddErrorInfo(serviceInfo, requestInfo, 2); return(serviceInfo.ResponseInfo); } var processStartInfo = processInfo.ProStartInfo; var data = new ProcessStartResponseModel() { k2Id = processStartInfo.K2ID }; if (requestInfo.startMode == ProcessStartModeEnum.Default.ToString())//直接提交(一步法) { stopwatch.Reset(); stopwatch.Start(); //处理一步法逻辑(模拟表单提交) processStartInfo.FormId = _workFlowService.NewTaskStart(processStartInfo); stopwatch.Stop(); timespan = stopwatch.Elapsed; _logger.Debug("StartProcess", $"NewTaskStart 执行时间:{ timespan.TotalMilliseconds } ms");//方法计时记录日志系统 //获取表单查看URL data.formUrl = _processBusService.GetFormViewUrl(processStartInfo.FormId); } else//需要弹出表单确认(二步法) { data.formUrl = _processBusService.GetFormPreStartuptUrl(processStartInfo.SplitProcessCode, processStartInfo.K2ID); } serviceInfo.ResponseInfo.data = data; ProStartAddSuccessLog(serviceInfo, processStartInfo);//发起添加成功日志 return(serviceInfo.ResponseInfo); }
/// <summary> /// 添加BPM接口日志 /// </summary> /// <param name="serviceInfo"></param> public void AddBPMInterfaceLogInfo(BPMServiceModel serviceInfo) { if (serviceInfo.InterfaceLog != null) { if (serviceInfo.ResponseInfo != null) { serviceInfo.InterfaceLog.Status = serviceInfo.ResponseInfo.returnStatus; serviceInfo.InterfaceLog.ResponseMessage = JsonConvert.SerializeObject(serviceInfo.ResponseInfo); serviceInfo.InterfaceLog.ResponseTime = DateTime.Now; } if (serviceInfo.FormInstanceInfo != null) { serviceInfo.InterfaceLog.FormID = serviceInfo.FormInstanceInfo.Id; serviceInfo.InterfaceLog.K2ID = serviceInfo.FormInstanceInfo.Folio; serviceInfo.InterfaceLog.ProcessCode = serviceInfo.FormInstanceInfo.ProcessCode; } AddBPMInterfaceLog(serviceInfo.InterfaceLog); } }
/// <summary> /// 发起接口调用成功添加日志 /// </summary> /// <param name="serviceInfo"></param> /// <param name="proStartInfo"></param> private void ProStartAddSuccessLog(BPMServiceModel serviceInfo, ProcessStartInfo proStartInfo) { if (proStartInfo != null) { if (serviceInfo.ResponseInfo != null) { serviceInfo.InterfaceLog.Status = serviceInfo.ResponseInfo.returnStatus; serviceInfo.InterfaceLog.ResponseMessage = JsonConvert.SerializeObject(serviceInfo.ResponseInfo); serviceInfo.InterfaceLog.ResponseTime = DateTime.Now; } serviceInfo.InterfaceLog.BizID = proStartInfo.BizId; serviceInfo.InterfaceLog.ProcessCode = proStartInfo.ProcessCode; serviceInfo.InterfaceLog.K2ID = proStartInfo.K2ID; serviceInfo.InterfaceLog.FormID = proStartInfo.FormId; serviceInfo.InterfaceLog.SplitProcessCode = proStartInfo.SplitProcessCode; //记录日志 _interfaceLogService.AddBPMInterfaceLog(serviceInfo.InterfaceLog); } }