Browse Source

平均派单

田爽 1 year ago
parent
commit
f415b19d3d
1 changed files with 13 additions and 7 deletions
  1. 13 7
      src/Hotline/Orders/OrderDomainService.cs

+ 13 - 7
src/Hotline/Orders/OrderDomainService.cs

@@ -207,8 +207,9 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
 		//2.获取今天上班的人员
 		//3.给当前这个用户平均派单
 		var steps = await _workflowDomainService.GetUnhandleStepIdsFromSendPoolAsync(OrderDefaults.SourceChannel.SendPoolId, cancellationToken);
-       
-        var user = await  _userRepository.GetAsync(userId,cancellationToken);
+        var stepsList = steps.ToList();
+
+		var user = await  _userRepository.GetAsync(userId,cancellationToken);
 		DateTime time = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
 		var schedulings = await _schedulingRepository.Queryable().Includes(x => x.SchedulingUser)
 			.Where(x => x.SchedulingTime == time && x.WorkingTime <= DateTime.Now.TimeOfDay && x.OffDutyTime >= DateTime.Now.TimeOfDay).CountAsync(cancellationToken);
@@ -216,11 +217,12 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
         if (schedulings > 0)
         {
 			List<string> stepIds = new List<string>();
-			var sendNum = steps.Count() / schedulings;
+			var sendNum = stepsList.Count() / schedulings;
             for (int i = 0; i < sendNum; i++)
             {
-                stepIds.Add(steps[i]);
-            }
+                stepIds.Add(stepsList[i]);
+                stepsList.Remove(stepsList[i]);
+			}
             List<(string userId, string username, IReadOnlyList<string> stepIds)> handlers = new();
 ;           handlers.Add(new ValueTuple<string, string, IReadOnlyList<string>>(user.Id, user.Name, stepIds));
 		   await  _workflowDomainService.ChangeHandlerRangeAsync(OrderDefaults.SourceChannel.SendPoolId ,handlers, cancellationToken);
@@ -244,6 +246,8 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
 		if (schedulings.Any())
 		{
 			var steps = await _workflowDomainService.GetUnhandleStepIdsFromSendPoolAsync(OrderDefaults.SourceChannel.SendPoolId, cancellationToken);
+			var stepsList = steps.ToList();
+
 			var sendNum = steps.Count() / schedulings.Count();
 			List<(string userId, string username, IReadOnlyList<string> stepIds)> handlers = new();
 			if (sendNum > 0)
@@ -254,7 +258,8 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
 					List<string> stepIds = new List<string>();
 					for (int i = 0; i < sendNum; i++)
 					{
-						stepIds.Add(steps[i]);
+						stepIds.Add(stepsList[i]);
+						stepsList.Remove(stepsList[i]);
 					}
 					handlers.Add(new ValueTuple<string, string, IReadOnlyList<string>>(scheduling.SchedulingUser.UserId, scheduling.SchedulingUser.UserName, stepIds));
 
@@ -266,7 +271,8 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
 				List<string> stepIds = new List<string>();
 				for (int i = 0; i < sendNum; i++)
 				{
-					stepIds.Add(steps[i]);
+					stepIds.Add(stepsList[i]);
+					stepsList.Remove(stepsList[i]);
 				}
 				handlers.Add(new ValueTuple<string, string, IReadOnlyList<string>>(schedulings[0].SchedulingUser.UserId, schedulings[0].SchedulingUser.UserName, stepIds));