1.業務場景:用戶登錄,收到消息通知,審批業務,根據配置的流程繼續流轉,最終審核發送回給申請人(終審同意結束,終審不同意申請人可以繼續修改提交)。 2.思路過程: 3..資料庫設計: 4.代碼過程: ...
1.業務場景:用戶登錄,收到消息通知,審批業務,根據配置的流程繼續流轉,最終審核發送回給申請人(終審同意結束,終審不同意申請人可以繼續修改提交)。
2.思路過程:
--用戶登錄首先獲取未處理的消息記錄,提醒處理預審批記錄。
--1.配置流程主表和關聯的步驟明細表(根據序號流轉)
--2.提交業務審批的時候創建預審批記錄(關聯流程和步驟),發送消息到第一步驟的評審人,修改業務主表狀態,
--3.步驟評審人同意:更新這個節點所有人的審批記錄、如果流程明細還有下一步審批則繼續發送消息給下一個,創建下一個預審批記錄,修改業務主表狀態,更新自己和這個節點所有人的消息記錄狀態
--4.步驟評審人不同意:終止發送下一個,發送回給申請人,更新自己和這個節點所有人的消息記錄狀態和審批記錄
-- 每一個節點可以配置多個審批人,第一個審批節點必須是同一個部門的才可以審批(可以配置多個部門領導,但是申請發送的時候只發送給同部門的領導)
-- 登錄人審批要根據預審批記錄表查詢是否有要審批的記錄和判斷是否有下一個步驟,審批完成後繼續向下一個發送
3..資料庫設計:
-------------------流程審批設計--------------------------創建流程表 Flow:ID、編號、流程名稱、類別、制定人、制定日期、狀態(是否啟用)、備註 SELECT * FROM [dbo].[Flow] --創建流程審批明細表(關聯流程表,一對多) FlowDetail:ID、流程主表編號、序號、步驟名稱、評審人賬號(多個)、評審人名字(多個)、狀態(是否啟用)、 select * from FlowDetail --創建審批記錄表 FlowRecords:ID、流程主表編號、流程步驟序號、業務編號、評審人賬號、評審人名字、審批狀態(1同意,2不同意,3審核中)、審批日期、備註、 select * from FlowRecords where BusinessNum='4C4CED8E3F8D42C997E2424D83C447B8' --創建消息通知表 Message :ID、標題、內容、業務編號、接收人賬號、接收人名字、發送人賬號、發送人名字、發送時間、狀態(1未處理,2已處理) select * from FlowMessage where BusinessNum='4C4CED8E3F8D42C997E2424D83C447B8' --業務主表 (增加欄位關聯審批流程:流程主表編號、流程明細序號)
4.代碼過程:
/// <summary> /// 審核單據 /// </summary> /// <param name="entity"></param> /// <returns></returns> public override string Audite(ReceiveOrderEntity entity) { using (TransactionScope ts = new TransactionScope()) { //1.獲取自己當前業務需要審核的記錄,沒有則不能審核 FlowRecordsEntity record = new FlowRecordsEntity(); record.IncludeAll(); record.Where(a => a.BusinessNum == entity.SnNum).And(a => a.ApproverUserNum == entity.UserName); var myRecord = this.FlowRecords.GetList(record).FirstOrDefault(); if (myRecord == null) return "1003"; if(myRecord.ApproverResult!=3) return "1004"; //2.獲取是否有下一步的流程步驟 FlowProvider provider = new FlowProvider(CompanyID); List<FlowDetailEntity> FlowDetails = provider .GetFlowDetail(new FlowDetailEntity {FlowSnNum = entity.FlowSnNum}).OrderBy(x => x.Seq).ToList(); FlowDetailEntity nextFlowDeail = null; int line = 0; if (FlowDetails != null && FlowDetails.Count > 0) { int count = 0; foreach (var obj in FlowDetails) { if (obj.Seq == myRecord.FlowDtlSeq) break; else count++; } //是否有下一步的流程 if (FlowDetails.Count > count && FlowDetails.Count!=count+1) { nextFlowDeail = FlowDetails[count + 1]; } } #region 不同意流程 if (entity.Status == (int) EAudite.NotPass) { entity.FlowDtlSeq = myRecord.FlowDtlSeq; entity.IncludeStatus(true).IncludeReason(true).IncludeFlowDtlSeq(true) .Where(a => a.SnNum == entity.SnNum) .And(a => a.CompanyID == this.CompanyID) ; line += this.ReceiveOrder.Update(entity); //1.更新自己的審批記錄 myRecord.ApproverResult = 2; myRecord.ApproverDate = DateTime.Now; myRecord.IncludeApproverResult(true).IncludeApproverDate(true); line += this.FlowRecords.Update(myRecord); //2.更新自己(這一個步驟所有人)的消息記錄 FlowMessageEntity msg = new FlowMessageEntity(); msg.Status = 2; msg.IncludeStatus(true); msg.Where(a => a.BusinessNum == entity.SnNum).And(a => a.FlowSnNum == entity.FlowSnNum) .And(a => a.FlowDtlSeq == myRecord.FlowDtlSeq); line += this.FlowMessage.Update(msg); //3.只發送消息回給申請人 FlowMessageEntity nextMsg = new FlowMessageEntity() { SendUserNum = entity.UserName, SendUserName = entity.RealName, AcceptUserNum = entity.CusNum, AcceptUserName = entity.CusName, BusinessNum = entity.SnNum, FlowSnNum = entity.FlowSnNum, FlowDtlSeq = myRecord.FlowDtlSeq, Status = 1, SendDate = DateTime.Now, Title = "物品領用申請審核", Notice = "您的編號為:"+entity.OrderNum+"的物品領用申審核已被拒絕!" }; nextMsg.IncludeAll(); line += this.FlowMessage.Add(nextMsg); ts.Complete(); return line > 0 ? "1000" : string.Empty; } #endregion #region 同意流程 else if (entity.Status == (int) EAudite.Pass) { //1.更新自己的審批記錄 myRecord.ApproverResult = 1; myRecord.ApproverDate = DateTime.Now; myRecord.IncludeApproverResult(true).IncludeApproverDate(true); line += this.FlowRecords.Update(myRecord); //2.更新自己(這一個步驟所有人)的消息記錄 FlowMessageEntity msg = new FlowMessageEntity(); msg.Status = 2; msg.IncludeStatus(true); msg.Where(a => a.BusinessNum == entity.SnNum).And(a => a.FlowSnNum == entity.FlowSnNum) .And(a => a.FlowDtlSeq == myRecord.FlowDtlSeq); line += this.FlowMessage.Update(msg); //如果有下一步的審核 if (nextFlowDeail != null) { //1.修改業務狀態 entity.Status = 5; //2.獲取下一步驟的審批人賬號列表 var users = nextFlowDeail.ApproverUserNum.Split(',') .Where(x => string.IsNullOrEmpty(x) == false).ToList(); List<AdminEntity> sendUser = new List<AdminEntity>(); users.ForEach(x => { AdminEntity model = new AdminEntity(); model.IncludeAll(); model.Where(a => a.IsDelete == (int)EIsDelete.NotDelete).And(item => item.UserName == x); var user = this.Admin.GetSingle(model); if (user != null) { sendUser.Add(user); } }); foreach (var user in sendUser) { //3.創建下一個審批人的預審批記錄 FlowRecordsEntity nextRecord = new FlowRecordsEntity() { ApproverUserName = user.RealName, ApproverUserNum = user.UserName, BusinessNum = entity.SnNum, FlowSnNum = entity.FlowSnNum, FlowDtlSeq = nextFlowDeail.Seq, ApproverResult = 3 }; nextRecord.IncludeAll(); line += this.FlowRecords.Add(nextRecord); //4.發送下一個審批人的消息通知 FlowMessageEntity nextMsg = new FlowMessageEntity() { SendUserNum = entity.UserName, SendUserName = entity.RealName, AcceptUserNum = user.UserName, AcceptUserName = user.RealName, BusinessNum = entity.SnNum, FlowSnNum = entity.FlowSnNum, FlowDtlSeq = nextFlowDeail.Seq, Status = 1, SendDate = DateTime.Now, Title = "物品領用申請審核", Notice = "有編號為:" + entity.OrderNum + "的物品領用申請需要您審核!" }; nextMsg.IncludeAll(); line += this.FlowMessage.Add(nextMsg); } } else { //流程結束 entity.Status = (int) EAudite.Pass; //發送消息回給申請人 FlowMessageEntity fristMsg = new FlowMessageEntity() { SendUserNum = entity.UserName, SendUserName = entity.RealName, AcceptUserNum = entity.CusNum, AcceptUserName = entity.CusName, BusinessNum = entity.SnNum, FlowSnNum = entity.FlowSnNum, FlowDtlSeq = myRecord.FlowDtlSeq, Status = 1, SendDate = DateTime.Now, Title = "物品領用申請審核", Notice = "您的編號為:" + entity.OrderNum + "的物品領用申審核已經通過!" }; fristMsg.IncludeAll(); line += this.FlowMessage.Add(fristMsg); } entity.FlowDtlSeq = myRecord.FlowDtlSeq; entity.AuditeTime = DateTime.Now; entity.Include(a => new {a.Status, a.AuditUser, a.AuditeTime, a.Reason, a.Remark,a.FlowDtlSeq}); entity.Where(a => a.SnNum == entity.SnNum).And(a => a.CompanyID == this.CompanyID); line += this.ReceiveOrder.Update(entity); ts.Complete(); return line > 0 ? EnumHelper.GetEnumDesc<EReturnStatus>(EReturnStatus.Success) : string.Empty; } #endregion } return string.Empty; }