| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using Admin.NET.Plugin.ApprovalFlow;
- using Admin.NET.Plugin.ApprovalFlow.Service;
- namespace Admin.NET.Plugin.AiDOP.Order;
- /// <summary>
- /// 合同评审审批业务回调(与流程定义 BizType = CONTRACT_REVIEW 一致)
- /// </summary>
- public class ContractReviewBizHandler : IFlowBizHandler, ITransient
- {
- public string BizType => "CONTRACT_REVIEW";
- private readonly SqlSugarRepository<ContractReview> _reviewRep;
- public ContractReviewBizHandler(SqlSugarRepository<ContractReview> reviewRep)
- {
- _reviewRep = reviewRep;
- }
- public async Task OnFlowStarted(long bizId, long instanceId)
- {
- var id = (int)bizId;
- var now = DateTime.Now;
- var row = await _reviewRep.GetByIdAsync(id);
- if (row == null) return;
- row.FlowStatus = "reviewing";
- row.CurrentStage = 1;
- row.CurrentDept = "审批流";
- row.UpdateTime = now;
- await _reviewRep.UpdateAsync(row);
- }
- public async Task OnFlowCompleted(long bizId, long instanceId, FlowInstanceStatusEnum finalStatus, long? lastApproverId)
- {
- var id = (int)bizId;
- var now = DateTime.Now;
- var row = await _reviewRep.GetByIdAsync(id);
- if (row == null) return;
- switch (finalStatus)
- {
- case FlowInstanceStatusEnum.Approved:
- row.FlowStatus = "completed";
- row.CurrentStage = 5;
- row.CurrentDept = "已完成";
- break;
- case FlowInstanceStatusEnum.Rejected:
- case FlowInstanceStatusEnum.Terminated:
- row.FlowStatus = "rejected";
- row.CurrentStage = 0;
- row.CurrentDept = null;
- break;
- case FlowInstanceStatusEnum.Cancelled:
- row.FlowStatus = "draft";
- row.CurrentStage = 0;
- row.CurrentDept = null;
- break;
- default:
- row.FlowStatus = "draft";
- row.CurrentStage = 0;
- row.CurrentDept = null;
- break;
- }
- row.UpdateTime = now;
- await _reviewRep.UpdateAsync(row);
- }
- public Task OnNodeCompleted(long bizId, long instanceId, string nodeId, string nodeName, long? approverUserId)
- {
- return Task.CompletedTask;
- }
- public async Task<Dictionary<string, object>> GetBizData(long bizId)
- {
- var row = await _reviewRep.GetByIdAsync((int)bizId);
- if (row == null) return new Dictionary<string, object>();
- var winRateLevel = row.WinRate switch
- {
- "高" => 3,
- "中" => 2,
- "低" => 1,
- _ => 0,
- };
- return new Dictionary<string, object>
- {
- ["currentStage"] = row.CurrentStage ?? 0,
- ["winRateLevel"] = winRateLevel,
- ["hasCrmNo"] = string.IsNullOrWhiteSpace(row.CrmNo) ? 0 : 1,
- };
- }
- }
|