|
@@ -227,40 +227,53 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
|
|
|
//1.获取默认派单员所属的工单
|
|
|
//2.获取今天上班的人员
|
|
|
//3.给当前这个用户平均派单
|
|
|
- var steps = await _workflowDomainService.GetUnhandleStepIdsFromSendPoolAsync(OrderDefaults.SourceChannel.SendPoolId, cancellationToken);
|
|
|
- var stepsList = steps.ToList();
|
|
|
+ //var steps = await _workflowDomainService.GetUnhandleStepIdsFromSendPoolAsync(OrderDefaults.SourceChannel.SendPoolId, cancellationToken);
|
|
|
+ //var stepsList = steps.ToList();
|
|
|
+
|
|
|
+ var steps = await _workflowDomainService.GetStepsBelongsToAsync(OrderDefaults.SourceChannel.SendPoolId,
|
|
|
+ cancellationToken);
|
|
|
|
|
|
var user = await _userRepository.Queryable()
|
|
|
.Includes(d => d.Organization)
|
|
|
.FirstAsync(d => d.Id == userId, cancellationToken);
|
|
|
- DateTime time = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
|
|
|
+ var 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);
|
|
|
|
|
|
if (schedulings > 0)
|
|
|
{
|
|
|
- List<string> stepIds = new List<string>();
|
|
|
- var sendNum = stepsList.Count() / schedulings;
|
|
|
- for (int i = 0; i < sendNum; i++)
|
|
|
+ var sendNum = steps.Count / schedulings;
|
|
|
+ if (sendNum <= 0) return;
|
|
|
+ var sendSteps = steps.Take(sendNum).ToList();
|
|
|
+ await _workflowDomainService.ChangeHandlerBatchAsync(new List<(string userId, string username, string orgId, string orgName, ICollection<WorkflowStep> steps)>
|
|
|
{
|
|
|
- stepIds.Add(stepsList[0]);
|
|
|
- stepsList.Remove(stepsList[0]);
|
|
|
- }
|
|
|
- List<(string, string, string, string, IReadOnlyList<string> stepIds)> handlers = new();
|
|
|
- ; handlers.Add(new ValueTuple<string, string, string, string, IReadOnlyList<string>>(user.Id, user.Name, user.OrgId, user.Organization.Name, stepIds));
|
|
|
- var workflowIds = await _workflowDomainService.ChangeHandlerRangeAsync(OrderDefaults.SourceChannel.SendPoolId, handlers, cancellationToken);
|
|
|
- var orders = await _orderRepository.Queryable().Includes(d => d.Workflow).Where(d => workflowIds.Contains(d.WorkflowId))
|
|
|
- .ToListAsync(cancellationToken);
|
|
|
- foreach (var order in orders)
|
|
|
- {
|
|
|
- _mapper.Map(order.Workflow, order);
|
|
|
- }
|
|
|
+ new(user.Id, user.Name, user.OrgId, user.Organization.Name, sendSteps)
|
|
|
+ }, cancellationToken);
|
|
|
+
|
|
|
+
|
|
|
+ //List<string> stepIds = new List<string>();
|
|
|
+ //var sendNum = stepsList.Count() / schedulings;
|
|
|
+ //for (int i = 0; i < sendNum; i++)
|
|
|
+ //{
|
|
|
+ // stepIds.Add(stepsList[0]);
|
|
|
+ // stepsList.Remove(stepsList[0]);
|
|
|
+ //}
|
|
|
+ //List<(string, string, string, string, IReadOnlyList<string> stepIds)> handlers = new();
|
|
|
+ //handlers.Add(new ValueTuple<string, string, string, string, IReadOnlyList<string>>(user.Id, user.Name, user.OrgId, user.Organization.Name, stepIds));
|
|
|
+ //var workflowIds = await _workflowDomainService.ChangeHandlerRangeAsync(OrderDefaults.SourceChannel.SendPoolId, handlers, cancellationToken);
|
|
|
+ //var orders = await _orderRepository.Queryable().Includes(d => d.Workflow).Where(d => workflowIds.Contains(d.WorkflowId))
|
|
|
+ // .ToListAsync(cancellationToken);
|
|
|
+ //foreach (var order in orders)
|
|
|
+ //{
|
|
|
+ // _mapper.Map(order.Workflow, order);
|
|
|
+ //}
|
|
|
var scheduling = await _schedulingRepository.Queryable().Includes(x => x.SchedulingUser)
|
|
|
.Where(x => x.SchedulingTime == time && x.WorkingTime <= DateTime.Now.TimeOfDay && x.OffDutyTime >= DateTime.Now.TimeOfDay && x.SchedulingUser.UserId == userId).FirstAsync(cancellationToken);
|
|
|
scheduling.SendOrderNum += sendNum;
|
|
|
await _schedulingRepository.UpdateAsync(scheduling, cancellationToken);
|
|
|
- await _orderRepository.UpdateRangeAsync(orders, cancellationToken);
|
|
|
+ //await _orderRepository.UpdateRangeAsync(orders, cancellationToken);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -279,49 +292,75 @@ 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, string orgId, string orgName, IReadOnlyList<string> stepIds)> handlers = new();
|
|
|
- if (sendNum > 0)
|
|
|
+ var steps = await _workflowDomainService.GetStepsBelongsToAsync(OrderDefaults.SourceChannel.SendPoolId,
|
|
|
+ cancellationToken);
|
|
|
+ if (steps.Any())
|
|
|
{
|
|
|
-
|
|
|
- foreach (var scheduling in schedulings)
|
|
|
+ List<(string userId, string username, string orgId, string orgName, ICollection<WorkflowStep> steps)> handlers = new();
|
|
|
+ var avg = steps.Count / schedulings.Count;
|
|
|
+ var remaining = steps.Count % schedulings.Count;
|
|
|
+ for (var i = 0; i < schedulings.Count; i++)
|
|
|
{
|
|
|
- List<string> stepIds = new List<string>();
|
|
|
- for (int i = 0; i < sendNum; i++)
|
|
|
- {
|
|
|
- stepIds.Add(stepsList[0]);
|
|
|
- stepsList.Remove(stepsList[0]);
|
|
|
- }
|
|
|
- handlers.Add(new ValueTuple<string, string, string, string, IReadOnlyList<string>>(scheduling.SchedulingUser.UserId, scheduling.SchedulingUser.UserName, scheduling.SchedulingUser.OrgId, scheduling.SchedulingUser.OrgIdName, stepIds));
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- sendNum = steps.Count() % schedulings.Count();
|
|
|
- if (sendNum > 0)
|
|
|
- {
|
|
|
- List<string> stepIds = new List<string>();
|
|
|
- for (int i = 0; i < sendNum; i++)
|
|
|
- {
|
|
|
- stepIds.Add(stepsList[0]);
|
|
|
- stepsList.Remove(stepsList[0]);
|
|
|
- }
|
|
|
- handlers.Add(new ValueTuple<string, string, string, string, IReadOnlyList<string>>(schedulings[0].SchedulingUser.UserId, schedulings[0].SchedulingUser.UserName, schedulings[0].SchedulingUser.OrgId, schedulings[0].SchedulingUser.OrgIdName, stepIds));
|
|
|
- }
|
|
|
- if (handlers.Any())
|
|
|
- {
|
|
|
- var workflowIds = await _workflowDomainService.ChangeHandlerRangeAsync(OrderDefaults.SourceChannel.SendPoolId, handlers, cancellationToken);
|
|
|
- var orders = await _orderRepository.Queryable().Includes(d => d.Workflow).Where(d => workflowIds.Contains(d.WorkflowId))
|
|
|
- .ToListAsync(cancellationToken);
|
|
|
- foreach (var order in orders)
|
|
|
- {
|
|
|
- _mapper.Map(order.Workflow, order);
|
|
|
+ var scheduling = schedulings[i];
|
|
|
+ var size = avg + (i < remaining ? 1 : 0);
|
|
|
+ handlers.Add(new(
|
|
|
+ scheduling.SchedulingUser.UserId,
|
|
|
+ scheduling.SchedulingUser.UserName,
|
|
|
+ scheduling.SchedulingUser.OrgId,
|
|
|
+ scheduling.SchedulingUser.OrgIdName,
|
|
|
+ steps.Take(size).ToList()));
|
|
|
}
|
|
|
|
|
|
- await _orderRepository.UpdateRangeAsync(orders, cancellationToken);
|
|
|
+ if (handlers.Any())
|
|
|
+ await _workflowDomainService.ChangeHandlerBatchAsync(handlers, cancellationToken);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ////
|
|
|
+ //var steps = await _workflowDomainService.GetUnhandleStepIdsFromSendPoolAsync(OrderDefaults.SourceChannel.SendPoolId, cancellationToken);
|
|
|
+ //var stepsList = steps.ToList();
|
|
|
+
|
|
|
+ //var sendNum = steps.Count() / schedulings.Count();
|
|
|
+ //List<(string userId, string username, string orgId, string orgName, IReadOnlyList<string> stepIds)> handlers = new();
|
|
|
+ //if (sendNum > 0)
|
|
|
+ //{
|
|
|
+
|
|
|
+ // foreach (var scheduling in schedulings)
|
|
|
+ // {
|
|
|
+ // List<string> stepIds = new List<string>();
|
|
|
+ // for (int i = 0; i < sendNum; i++)
|
|
|
+ // {
|
|
|
+ // stepIds.Add(stepsList[0]);
|
|
|
+ // stepsList.Remove(stepsList[0]);
|
|
|
+ // }
|
|
|
+ // handlers.Add(new ValueTuple<string, string, string, string, IReadOnlyList<string>>(scheduling.SchedulingUser.UserId, scheduling.SchedulingUser.UserName, scheduling.SchedulingUser.OrgId, scheduling.SchedulingUser.OrgIdName, stepIds));
|
|
|
+
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //sendNum = steps.Count() % schedulings.Count();
|
|
|
+ //if (sendNum > 0)
|
|
|
+ //{
|
|
|
+ // List<string> stepIds = new List<string>();
|
|
|
+ // for (int i = 0; i < sendNum; i++)
|
|
|
+ // {
|
|
|
+ // stepIds.Add(stepsList[0]);
|
|
|
+ // stepsList.Remove(stepsList[0]);
|
|
|
+ // }
|
|
|
+ // handlers.Add(new ValueTuple<string, string, string, string, IReadOnlyList<string>>(schedulings[0].SchedulingUser.UserId, schedulings[0].SchedulingUser.UserName, schedulings[0].SchedulingUser.OrgId, schedulings[0].SchedulingUser.OrgIdName, stepIds));
|
|
|
+ //}
|
|
|
+ //if (handlers.Any())
|
|
|
+ //{
|
|
|
+ // var workflowIds = await _workflowDomainService.ChangeHandlerRangeAsync(OrderDefaults.SourceChannel.SendPoolId, handlers, cancellationToken);
|
|
|
+ // var orders = await _orderRepository.Queryable().Includes(d => d.Workflow).Where(d => workflowIds.Contains(d.WorkflowId))
|
|
|
+ // .ToListAsync(cancellationToken);
|
|
|
+ // foreach (var order in orders)
|
|
|
+ // {
|
|
|
+ // _mapper.Map(order.Workflow, order);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // await _orderRepository.UpdateRangeAsync(orders, cancellationToken);
|
|
|
+ //}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|