|
@@ -17,6 +17,7 @@ using Hotline.Users;
|
|
using Hotline.Share.Dtos;
|
|
using Hotline.Share.Dtos;
|
|
using Hotline.Settings.Hotspots;
|
|
using Hotline.Settings.Hotspots;
|
|
using Hotline.Share.Dtos.FlowEngine;
|
|
using Hotline.Share.Dtos.FlowEngine;
|
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
namespace Hotline.Orders;
|
|
namespace Hotline.Orders;
|
|
|
|
|
|
@@ -190,7 +191,6 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
|
|
.Where(x => x.SchedulingTime == time && x.WorkingTime <= DateTime.Now.TimeOfDay && x.OffDutyTime >= DateTime.Now.TimeOfDay && x.AtWork == true)
|
|
.Where(x => x.SchedulingTime == time && x.WorkingTime <= DateTime.Now.TimeOfDay && x.OffDutyTime >= DateTime.Now.TimeOfDay && x.AtWork == true)
|
|
.OrderBy(x => x.SendOrderNum).FirstAsync(cancellationToken);
|
|
.OrderBy(x => x.SendOrderNum).FirstAsync(cancellationToken);
|
|
if (scheduling is null)
|
|
if (scheduling is null)
|
|
- //return new List<Kv> { new(OrderDefaults.SourceChannel.SendPoolId, "待派单池") };
|
|
|
|
return new FlowStepHandler
|
|
return new FlowStepHandler
|
|
{
|
|
{
|
|
Key = OrderDefaults.SourceChannel.SendPoolId,
|
|
Key = OrderDefaults.SourceChannel.SendPoolId,
|
|
@@ -198,13 +198,8 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
|
|
UserId = OrderDefaults.SourceChannel.SendPoolId,
|
|
UserId = OrderDefaults.SourceChannel.SendPoolId,
|
|
Username = "待派单池",
|
|
Username = "待派单池",
|
|
};
|
|
};
|
|
-
|
|
|
|
- //var user = await _userRepository.GetAsync(x => x.Id == scheduling.SchedulingUser.UserId, cancellationToken);
|
|
|
|
- //if (user is null)
|
|
|
|
- // throw new UserFriendlyException("无效用户编号");
|
|
|
|
scheduling.SendOrderNum++;
|
|
scheduling.SendOrderNum++;
|
|
await _schedulingRepository.UpdateAsync(scheduling, cancellationToken);
|
|
await _schedulingRepository.UpdateAsync(scheduling, cancellationToken);
|
|
- //return new List<Kv> { new(user.Id, user.Name) };
|
|
|
|
var user = scheduling.SchedulingUser;
|
|
var user = scheduling.SchedulingUser;
|
|
return new FlowStepHandler
|
|
return new FlowStepHandler
|
|
{
|
|
{
|
|
@@ -222,45 +217,36 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <param name="userId"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public async Task LogAverageOrder(string userId, CancellationToken cancellationToken)
|
|
|
|
|
|
+ public async Task LogAverageOrder(string userId, Scheduling scheduling, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
//1.获取默认派单员所属的工单
|
|
//1.获取默认派单员所属的工单
|
|
//2.获取今天上班的人员
|
|
//2.获取今天上班的人员
|
|
//3.给当前这个用户平均派单
|
|
//3.给当前这个用户平均派单
|
|
- 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()
|
|
var user = await _userRepository.Queryable()
|
|
.Includes(d => d.Organization)
|
|
.Includes(d => d.Organization)
|
|
.FirstAsync(d => d.Id == userId, cancellationToken);
|
|
.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)
|
|
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);
|
|
.Where(x => x.SchedulingTime == time && x.WorkingTime <= DateTime.Now.TimeOfDay && x.OffDutyTime >= DateTime.Now.TimeOfDay).CountAsync(cancellationToken);
|
|
-
|
|
|
|
if (schedulings > 0)
|
|
if (schedulings > 0)
|
|
{
|
|
{
|
|
- 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)
|
|
|
|
|
|
+ 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)>
|
|
{
|
|
{
|
|
- _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);
|
|
|
|
|
|
+ new(user.Id, user.Name, user.OrgId, user.Organization.Name, sendSteps)
|
|
|
|
+ }, cancellationToken);
|
|
scheduling.SendOrderNum += sendNum;
|
|
scheduling.SendOrderNum += sendNum;
|
|
- await _schedulingRepository.UpdateAsync(scheduling, cancellationToken);
|
|
|
|
- await _orderRepository.UpdateRangeAsync(orders, cancellationToken);
|
|
|
|
|
|
+ await _schedulingRepository.Updateable()
|
|
|
|
+ .SetColumns(s => new Scheduling() { SendOrderNum = scheduling.SendOrderNum, AtWork = scheduling.AtWork } )
|
|
|
|
+ .Where(s=> s.Id == scheduling.Id).ExecuteCommandAsync(cancellationToken);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -279,48 +265,30 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
|
|
|
|
|
|
if (schedulings.Any())
|
|
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)
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- 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)
|
|
|
|
|
|
+ var steps = await _workflowDomainService.GetStepsBelongsToAsync(OrderDefaults.SourceChannel.SendPoolId,
|
|
|
|
+ cancellationToken);
|
|
|
|
+ if (steps.Any())
|
|
{
|
|
{
|
|
- List<string> stepIds = new List<string>();
|
|
|
|
- for (int i = 0; i < sendNum; i++)
|
|
|
|
|
|
+ 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++)
|
|
{
|
|
{
|
|
- 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);
|
|
|
|
|
|
+ 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()));
|
|
|
|
+ scheduling.SendOrderNum += size;
|
|
|
|
+ await _schedulingRepository.Updateable()
|
|
|
|
+ .SetColumns(s => new Scheduling() { SendOrderNum = scheduling.SendOrderNum })
|
|
|
|
+ .Where(s => s.Id == scheduling.Id).ExecuteCommandAsync(cancellationToken);
|
|
|
|
+ }
|
|
|
|
+ if (handlers.Any())
|
|
|
|
+ await _workflowDomainService.ChangeHandlerBatchAsync(handlers, cancellationToken);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -403,12 +371,6 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
|
|
valid.Result = "标题或受理内容出现限制词,请检查!";
|
|
valid.Result = "标题或受理内容出现限制词,请检查!";
|
|
return valid;
|
|
return valid;
|
|
}
|
|
}
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region SchedulingSendOrder
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
#region private
|
|
#region private
|