using System; using System.Threading.Tasks; using System.Web.UI.WebControls; using log4net; using UFIDA.U8.Audit.ServiceProxy; using UFIDA.U8.Framework.Api.ControlObject.Common; using UFIDA.U8.Framework.Api.ControlObject.Entity; using UFIDA.U8.Framework.Api.ControlObject.U8M; using UFSoft.U8.BO.BE; using UFSoft.U8.Framework.LoginContext; // ReSharper disable IdentifierTypo namespace UFIDA.U8.Framework.Api.ControlObject.Workflow { /// /// 工作流 /// public class ServiceProxy { private readonly ILog _logInfo = LogManager.GetLogger("logInfo"); /// /// #是否启用审批流# /// /// /// /// /// /// public bool IsFlowEnabled(BaseLogin login, string bizObjectId, string eventId) { var auditServiceProxy = new AuditServiceProxy(); var errMsg = ""; var res = auditServiceProxy.IsFlowEnabled(bizObjectId, eventId, login._productContext.calledContext, ref errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } return res; } /// /// #提交审批流# /// /// /// /// /// /// /// /// public async Task> SubmitApplicationMessage(BaseLogin login, string bizObjectId, string eventId, string voucherId,string voucherCode) { try { var auditServiceProxy = new AuditServiceProxy(); var isWfControled = false; var errMsg = ""; var res = auditServiceProxy.SubmitApplicationMessage(bizObjectId, eventId, voucherId, login._productContext.calledContext, ref isWfControled, ref errMsg); if (!res && !string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (!isWfControled && !string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (!isWfControled) { throw new Exception("当前单据无法进入工作流"); } if (!res) { throw new Exception("审批流发生异常"); } return new BaseResult { bSuccess = true, message = "提交成功", result = "提交成功", voucherId = voucherId, voucherCode = voucherCode }; } catch (Exception ex) { _logInfo.Error($"审批流异常:{ex.Message}", ex); await Task.Delay(1); return new BaseResult { bSuccess = false, message = "提交失败", voucherCode = voucherCode, voucherId = voucherId, result = ex.Message }; } } /// /// #提交审批流# /// /// /// /// /// /// /// /// public async Task> SubmitApplicationMessage(BaseLogin login, string cCardNum, string eventId, string voucherCode, bool bUAP = false) { var voucherId = ""; try { var vouchers = CommonHelper.GetVouchers(login.Connection, cCardNum); voucherId = $"{CommonHelper.GetVoucherId(login.Connection, voucherCode, vouchers)}"; var bizObjectId = cCardNum; if (bUAP) { bizObjectId = $"UAPFORM.{bizObjectId}"; } eventId = $"{cCardNum}.{eventId}"; return await SubmitApplicationMessage(login, bizObjectId, eventId, voucherId, voucherCode); } catch (Exception ex) { _logInfo.Error($"审批流异常:{ex.Message}", ex); await Task.Delay(1); return new BaseResult { bSuccess = false, message = "提交失败", voucherCode = voucherCode, voucherId = voucherId, result = ex.Message }; } } /// /// #提交审批流# /// /// /// /// /// /// /// /// public async Task> SubmitApplicationMessage(BaseLogin login, string cCardNum, string eventId, object voucherId, bool bUAP = false) { var voucherCode = ""; try { var vouchers = CommonHelper.GetVouchers(login.Connection, cCardNum); voucherCode = $"{CommonHelper.GetVoucherCode(login.Connection, voucherId, vouchers)}"; var bizObjectId = cCardNum; if (bUAP) { bizObjectId = $"UAPFORM.{bizObjectId}"; } eventId = $"{cCardNum}.{eventId}"; return await SubmitApplicationMessage(login, bizObjectId, eventId,$"{voucherId}" , voucherCode); } catch (Exception ex) { _logInfo.Error($"审批流异常:{ex.Message}", ex); await Task.Delay(1); return new BaseResult { bSuccess = false, message = "提交失败", voucherCode = voucherCode, voucherId = $"{voucherId}", result = ex.Message }; } } /// /// #单据审核# /// /// /// /// /// /// /// /// /// /// public async Task> Audit(BaseLogin login, string cCardNum, short action, short state, string opinion, string voucherId, string voucherCode) { try { var keySet = $@""; var auditServiceProxy = new AuditServiceProxy(); var errMsg = ""; var res = auditServiceProxy.Audit(keySet, action, state, opinion, login._productContext.calledContext, ref errMsg); if (!res && !string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (!string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (!res) { throw new Exception("审批流发生异常"); } return new BaseResult { bSuccess = true, message = "审核成功", result = "审核成功", voucherId = voucherId, voucherCode = voucherCode }; } catch (Exception ex) { _logInfo.Error($"审批流异常:{ex.Message}", ex); await Task.Delay(1); return new BaseResult { bSuccess = false, message = "审核失败", voucherCode = voucherCode, voucherId = voucherId, result = ex.Message }; } } /// /// #单据弃审# /// /// /// /// /// /// /// /// /// /// public async Task> Abandon(BaseLogin login, string cCardNum, short action, short state, string opinion, string voucherId, string voucherCode) { try { var keySet = $@""; var auditServiceProxy = new AuditServiceProxy(); var errMsg = ""; var res = auditServiceProxy.Abandon(keySet, opinion, state, login._productContext.calledContext, ref errMsg); if (!res && !string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (!string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (!res) { throw new Exception("审批流发生异常"); } return new BaseResult { bSuccess = true, message = "弃审成功", result = "弃审成功", voucherId = voucherId, voucherCode = voucherCode }; } catch (Exception ex) { _logInfo.Error($"审批流异常:{ex.Message}", ex); await Task.Delay(1); return new BaseResult { bSuccess = false, message = "审核失败", voucherCode = voucherCode, voucherId = voucherId, result = ex.Message }; } } /// /// #流程撤销# /// /// /// /// /// /// /// /// public async Task> RevokeAudition(BaseLogin login, string cCardNum, string bizObjectId, string eventId, string voucherId, string voucherCode) { try { var auditServiceProxy = new AuditServiceProxy(); var data = ""; var errMsg = ""; var res = auditServiceProxy.RevokeAudition(bizObjectId, eventId, voucherId, cCardNum,voucherCode,ref data,login._productContext.calledContext, ref errMsg); if (!res && !string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (!string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (!res) { throw new Exception("审批流发生异常"); } return new BaseResult { bSuccess = true, message = "撤销成功", result = "撤销成功", voucherId = voucherId, voucherCode = voucherCode }; } catch (Exception ex) { _logInfo.Error($"审批流异常:{ex.Message}", ex); await Task.Delay(1); return new BaseResult { bSuccess = false, message = "撤销失败", voucherCode = voucherCode, voucherId = voucherId, result = ex.Message }; } } /// /// #取得审批历史进程信息# /// /// /// /// /// /// /// public async Task> GetAuditedHistoryXml(BaseLogin login, string cCardNum, string voucherId, string voucherCode) { try { var auditServiceProxy = new AuditServiceProxy(); var res = auditServiceProxy.GetAuditedHistoryXml(voucherId, cCardNum, login._productContext.calledContext); if (string.IsNullOrWhiteSpace(res)) { throw new Exception("未能取得审批历史进程信息"); } return new BaseResult { bSuccess = true, message = "获取成功", result = res, voucherId = voucherId, voucherCode = voucherCode }; } catch (Exception ex) { _logInfo.Error($"审批流异常:{ex.Message}", ex); await Task.Delay(1); return new BaseResult { bSuccess = false, message = "获取失败", voucherCode = voucherCode, voucherId = voucherId, result = ex.Message }; } } /// /// #退回提交人后重新提交# /// /// /// /// /// /// public async Task> SubmitResubmitMessage(BaseLogin login, string cCardNum, string voucherId, string voucherCode) { try { var auditServiceProxy = new AuditServiceProxy(); var keySet = $@""; var errMsg = ""; var res = auditServiceProxy.SubmitResubmitMessage(keySet, login._productContext.calledContext,ref errMsg); if (!res && !string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (!string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (!res) { throw new Exception("审批流发生异常"); } return new BaseResult { bSuccess = true, message = "提交成功", result = "提交成功", voucherId = voucherId, voucherCode = voucherCode }; } catch (Exception ex) { _logInfo.Error($"审批流异常:{ex.Message}", ex); await Task.Delay(1); return new BaseResult { bSuccess = false, message = "提交失败", voucherCode = voucherCode, voucherId = voucherId, result = ex.Message }; } } /// /// #取得代办任务# /// /// /// /// public async Task> GetTasks(BaseLogin login, bool hasDone) { try { var auditServiceProxy = new AuditServiceProxy(); var errMsg = ""; var res = auditServiceProxy.GetTasks(hasDone, login._productContext.calledContext, ref errMsg); if (!string.IsNullOrWhiteSpace(errMsg)) { throw new Exception(errMsg); } if (string.IsNullOrWhiteSpace(res)) { throw new Exception("审批流发生异常"); } return new BaseResult { bSuccess = true, message = "提交成功", result = res }; } catch (Exception ex) { _logInfo.Error($"审批流异常:{ex.Message}", ex); await Task.Delay(1); return new BaseResult { bSuccess = false, message = "获取失败", result = ex.Message }; } } } }