|
@@ -19,6 +19,8 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
|
|
|
private readonly IWorkflowDomainService _workflowDomainService;
|
|
|
private readonly IWorkflowRepository _workflowRepository;
|
|
|
private readonly IWorkflowAssignRepository _workflowAssignRepository;
|
|
|
+ private readonly IUserRepository _userRepository;
|
|
|
+ private readonly IAccountRepository _accountRepository;
|
|
|
private readonly IUserDomainService _userDomainService;
|
|
|
private readonly IAccountDomainService _accountDomainService;
|
|
|
private readonly ISessionContext _sessionContext;
|
|
@@ -28,16 +30,16 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
|
|
|
IWorkflowDomainService workflowDomainService,
|
|
|
IWorkflowRepository workflowRepository,
|
|
|
IWorkflowAssignRepository workflowAssignRepository,
|
|
|
- IUserDomainService userDomainService,
|
|
|
- IAccountDomainService accountDomainService,
|
|
|
+ IUserRepository userRepository,
|
|
|
+ IAccountRepository accountRepository,
|
|
|
ISessionContext sessionContext)
|
|
|
{
|
|
|
_definitionDomainService = definitionDomainService;
|
|
|
_workflowDomainService = workflowDomainService;
|
|
|
_workflowRepository = workflowRepository;
|
|
|
_workflowAssignRepository = workflowAssignRepository;
|
|
|
- _userDomainService = userDomainService;
|
|
|
- _accountDomainService = accountDomainService;
|
|
|
+ _userRepository = userRepository;
|
|
|
+ _accountRepository = accountRepository;
|
|
|
_sessionContext = sessionContext;
|
|
|
}
|
|
|
|
|
@@ -55,22 +57,56 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
|
|
|
await _workflowDomainService.StartAsync(workflow, dto, nextStepBoxDefine, cancellationToken);
|
|
|
|
|
|
//更新接办部门(详情页面展示)
|
|
|
+ await AddOrUpdateAssignAsync(workflow, dto, nextStepBoxDefine, cancellationToken);
|
|
|
+
|
|
|
+ return workflow.Id;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 流转至下一节点(节点办理)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task NextAsync(NextWorkflowDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var workflow = await _workflowDomainService.GetWorkflowAsync(dto.WorkflowId, true, true, cancellationToken: cancellationToken);
|
|
|
+ var nextStepBoxDefine = _workflowDomainService.GetStepBoxDefine(workflow.Definition, dto.NextStepCode);
|
|
|
+ var isOutOfCallCenter =
|
|
|
+ await CheckIfFlowOutOfCallCenterAsync(nextStepBoxDefine, dto.NextMainHandler, cancellationToken);
|
|
|
+ var isStartCountersign = nextStepBoxDefine.IsStartCountersign(dto.Handlers.Count);
|
|
|
+ await _workflowDomainService.NextAsync(workflow, dto, nextStepBoxDefine, isOutOfCallCenter, isStartCountersign, cancellationToken);
|
|
|
+
|
|
|
+ //更新接办部门(详情页面展示)
|
|
|
+ await AddOrUpdateAssignAsync(workflow, dto, nextStepBoxDefine, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ #region private
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 更新接办部门
|
|
|
+ /// </summary>
|
|
|
+ private async Task AddOrUpdateAssignAsync(Workflow workflow, BasicWorkflowDto dto, StepDefine nextStepBoxDefine, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
if (nextStepBoxDefine.StepType is EStepType.Normal)
|
|
|
{
|
|
|
await _workflowAssignRepository.RemoveAsync(d =>
|
|
|
- d.WorkflowId == workflow.Id && d.OrgCode == _sessionContext.RequiredOrgCode, cancellationToken: cancellationToken);
|
|
|
+ d.WorkflowId == workflow.Id && d.OrgCode == _sessionContext.RequiredOrgCode,
|
|
|
+ cancellationToken: cancellationToken);
|
|
|
|
|
|
var assigns = new List<WorkflowAssign>();
|
|
|
switch (nextStepBoxDefine.HandlerType)
|
|
|
{
|
|
|
case EHandlerType.Role:
|
|
|
- //todo 1.选了handler,handler为userId 2.未选:如果配置为本部门办理,则为当前办理人orgCode, 非本部门办理??
|
|
|
if (dto.Handlers.Any())
|
|
|
{
|
|
|
//选了handler,handler为userId
|
|
|
- var users1 = await _userDomainService.QueryWithOrgsAsync(dto.Handlers.Select(d => d.Id),
|
|
|
- cancellationToken);
|
|
|
- assigns = users1.Select(d => WorkflowAssign.Create(workflow.Id, d.OrgCode, d.Organization.OrgName)).ToList();
|
|
|
+ var users1 = await _userRepository.Queryable()
|
|
|
+ .Includes(d => d.Organization)
|
|
|
+ .Where(d => dto.Handlers.Select(d => d.Id).Contains(d.Id))
|
|
|
+ .ToListAsync();
|
|
|
+ assigns = users1.Select(d => WorkflowAssign.Create(workflow.Id, d.OrgCode, d.Organization.OrgName))
|
|
|
+ .ToList();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -84,9 +120,15 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
+ var accounts = await _accountRepository.Queryable()
|
|
|
+ .Includes(d => d.User, d => d.Organization)
|
|
|
+ .Where(d => dto.Handlers.Select(d => d.Id).Contains(d.Name))
|
|
|
+ .ToListAsync();
|
|
|
+ assigns = accounts.Select(d => d.User.Organization).Select(d =>
|
|
|
+ WorkflowAssign.Create(workflow.Id, d.OrgCode, d.OrgName)).ToList();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
break;
|
|
|
|
|
|
case EHandlerType.OrgLevel:
|
|
@@ -97,39 +139,22 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
|
|
|
|
|
|
case EHandlerType.AssignUser:
|
|
|
//指定人所属部门
|
|
|
- var users = await _userDomainService.QueryWithOrgsAsync(dto.Handlers.Select(d => d.Id),
|
|
|
- cancellationToken);
|
|
|
+ var users = await _userRepository.Queryable()
|
|
|
+ .Includes(d => d.Organization)
|
|
|
+ .Where(d => dto.Handlers.Select(d => d.Id).Contains(d.Id))
|
|
|
+ .ToListAsync();
|
|
|
assigns = users.Select(d => WorkflowAssign.Create(workflow.Id, d.OrgCode, d.Organization.OrgName))
|
|
|
.ToList();
|
|
|
break;
|
|
|
default:
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
}
|
|
|
+
|
|
|
if (assigns.Any())
|
|
|
await _workflowAssignRepository.AddRangeAsync(assigns, cancellationToken);
|
|
|
}
|
|
|
-
|
|
|
- return workflow.Id;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 流转至下一节点(节点办理)
|
|
|
- /// </summary>
|
|
|
- /// <param name="dto"></param>
|
|
|
- /// <param name="cancellationToken"></param>
|
|
|
- /// <returns></returns>
|
|
|
- public async Task NextAsync(NextWorkflowDto dto, CancellationToken cancellationToken)
|
|
|
- {
|
|
|
- var workflow = await _workflowDomainService.GetWorkflowAsync(dto.WorkflowId, true, true, cancellationToken: cancellationToken);
|
|
|
- var nextStepBoxDefine = _workflowDomainService.GetStepBoxDefine(workflow.Definition, dto.NextStepCode);
|
|
|
- var isOutOfCallCenter =
|
|
|
- await CheckIfFlowOutOfCallCenterAsync(nextStepBoxDefine, dto.NextMainHandler, cancellationToken);
|
|
|
- var isStartCountersign = nextStepBoxDefine.IsStartCountersign(dto.Handlers.Count);
|
|
|
- await _workflowDomainService.NextAsync(workflow, dto, nextStepBoxDefine, isOutOfCallCenter, isStartCountersign, cancellationToken);
|
|
|
}
|
|
|
|
|
|
- #region private
|
|
|
-
|
|
|
private async Task<bool> CheckIfFlowOutOfCallCenterAsync(StepDefine nextStepBoxDefine, string mainHandler, CancellationToken CancellationToken)
|
|
|
{
|
|
|
//current is center & next is not center return true
|
|
@@ -145,7 +170,7 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
|
|
|
if (nextStepBoxDefine.HandlerType is EHandlerType.AssignUser or EHandlerType.Role)
|
|
|
{
|
|
|
//mainHandler is userId
|
|
|
- var handler = await _userDomainService.GetUserAsync(mainHandler, cancellationToken);
|
|
|
+ var handler = await _userRepository.GetAsync(mainHandler, cancellationToken);
|
|
|
if (handler == null)
|
|
|
throw new UserFriendlyException($"mainHandler未找到对应User, handler: {mainHandler}");
|
|
|
if (string.IsNullOrEmpty(handler.OrgCode))
|