|
@@ -1,6 +1,7 @@
|
|
|
using DotNetCore.CAP;
|
|
|
using Hotline.Application.Orders;
|
|
|
using Hotline.Caching.Interfaces;
|
|
|
+using Hotline.Configurations;
|
|
|
using Hotline.FlowEngine.Workflows;
|
|
|
using Hotline.Orders;
|
|
|
using Hotline.Push;
|
|
@@ -18,6 +19,7 @@ using Hotline.Users;
|
|
|
using MapsterMapper;
|
|
|
using MediatR;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
using StackExchange.Redis;
|
|
|
using XF.Domain.Authentications;
|
|
@@ -39,8 +41,9 @@ namespace Hotline.Application.Subscribers
|
|
|
private readonly IWorkflowDomainService _workflowDomainService;
|
|
|
private readonly ICalcExpireTime _expireTime;
|
|
|
private readonly IMapper _mapper;
|
|
|
+ private readonly IOptionsSnapshot<AppConfiguration> _appOptions;
|
|
|
|
|
|
- public InternalCapSubscriber(
|
|
|
+ public InternalCapSubscriber(
|
|
|
IOrderRepository orderRepository,
|
|
|
IMediator mediator,
|
|
|
IRepository<User> userRepository,
|
|
@@ -52,7 +55,8 @@ namespace Hotline.Application.Subscribers
|
|
|
IWorkflowDomainService workflowDomainService,
|
|
|
ICalcExpireTime expireTime,
|
|
|
IMapper mapper
|
|
|
- )
|
|
|
+,
|
|
|
+ IOptionsSnapshot<AppConfiguration> appOptions)
|
|
|
{
|
|
|
_orderRepository = orderRepository;
|
|
|
_mediator = mediator;
|
|
@@ -65,7 +69,8 @@ namespace Hotline.Application.Subscribers
|
|
|
_workflowDomainService = workflowDomainService;
|
|
|
_expireTime = expireTime;
|
|
|
_mapper = mapper;
|
|
|
- }
|
|
|
+ _appOptions = appOptions;
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 工单即将超期短信发送(延迟消息)
|
|
@@ -240,117 +245,186 @@ namespace Hotline.Application.Subscribers
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
/// <returns></returns>
|
|
|
[CapSubscribe(EventNames.HotlineOrderAutomaticDelay)]
|
|
|
- public async Task AutomaticDelay(PublishAutomaticDelayDto dto, CancellationToken cancellationToken)
|
|
|
+ public async Task AutomaticDelay(PublishAutomaticDelayDto dto, CancellationToken cancellationToken)
|
|
|
{
|
|
|
var enabled = _systemSettingCacheManager.GetSetting(SettingConstants.EnabledAutomaticDelay)?.SettingValue[0];
|
|
|
if (bool.Parse(enabled))
|
|
|
{
|
|
|
- var order = await _orderRepository.GetAsync(dto.OrderId, cancellationToken);
|
|
|
- var expiredTime = DateTime.Now.AddHours(2);
|
|
|
- if (order != null && order.Status < EOrderStatus.Filed && order.ExpiredTime >= DateTime.Now)
|
|
|
- {
|
|
|
- if (order.ExpiredTime <= expiredTime)
|
|
|
- {
|
|
|
- var delayAny = await _orderDelayRepository.Queryable().Where(x => x.OrderId == order.Id && x.DelayState == EDelayState.Examining).AnyAsync();
|
|
|
- if (!delayAny)
|
|
|
- {
|
|
|
- var delays = await _orderDelayRepository.Queryable().Where(x => x.OrderId == order.Id && x.AutomaticDelayNum > 0).ToListAsync(cancellationToken);
|
|
|
- var delay = new OrderDelay();
|
|
|
- if (delays.Any())
|
|
|
- {
|
|
|
- delay = delays.First();
|
|
|
+ var order = await _orderRepository.GetAsync(dto.OrderId, cancellationToken);
|
|
|
+ var expiredTime = DateTime.Now.AddHours(2);
|
|
|
+ if (order != null && order.Status < EOrderStatus.Filed && order.ExpiredTime >= DateTime.Now)
|
|
|
+ {
|
|
|
+ if (order.ExpiredTime <= expiredTime)
|
|
|
+ {
|
|
|
+ var delayAny = await _orderDelayRepository.Queryable().Where(x => x.OrderId == order.Id && x.DelayState == EDelayState.Examining).AnyAsync();
|
|
|
+ if (!delayAny)
|
|
|
+ {
|
|
|
+ var delays = await _orderDelayRepository.Queryable().Where(x => x.OrderId == order.Id && x.AutomaticDelayNum > 0).ToListAsync(cancellationToken);
|
|
|
+ var delay = new OrderDelay();
|
|
|
+ if (delays.Any())
|
|
|
+ {
|
|
|
+ delay = delays.First();
|
|
|
var startTime = DateTime.Now;
|
|
|
if (order.CenterToOrgTime.HasValue)
|
|
|
{
|
|
|
startTime = order.CenterToOrgTime.Value;
|
|
|
}
|
|
|
- delay.AfterDelay = (await _expireTime
|
|
|
- .CalcEndTime(delay.BeforeDelay.Value,startTime, delay.DelayUnit, delay.DelayNum, order.AcceptTypeCode))?.EndTime; //todo
|
|
|
- await _orderDelayRepository.Updateable().SetColumns(x => new OrderDelay() { AutomaticDelayNum = x.AutomaticDelayNum + 1, ApplyDelayTime = DateTime.Now, AfterDelay = delay.AfterDelay })
|
|
|
- .Where(x => x.Id == delay.Id).ExecuteCommandAsync(cancellationToken);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- delay.OrderId = order.Id;
|
|
|
- delay.EmployeeId = "";
|
|
|
- delay.EmployeeName = "系统自动延期";
|
|
|
- delay.ApplyOrgName = OrgSeedData.CenterName;
|
|
|
- delay.ApplyOrgCode = OrgSeedData.CenterId;
|
|
|
- delay.DelayApplyType = EDelayApplyType.LocalApply;
|
|
|
- delay.BeforeDelay = order.ExpiredTime;
|
|
|
- delay.DelayState = EDelayState.Pass;
|
|
|
- delay.DelayReason = "系统自动延期";
|
|
|
- delay.ApplyDelayTime = DateTime.Now;
|
|
|
- delay.No = order.No;
|
|
|
- delay.AutomaticDelayNum = 1;
|
|
|
- delay.DelayNum = 1;
|
|
|
- delay.DelayUnit = Share.Enums.Settings.ETimeType.WorkDay;
|
|
|
- delay.IsProDelay = false;
|
|
|
- delay.CreatorOrgId = OrgSeedData.CenterId;
|
|
|
- delay.CreatorOrgName = OrgSeedData.CenterName;
|
|
|
- delay.CreatorName = "系统自动延期";
|
|
|
+ var beforeDelay = DateTime.Now;
|
|
|
+ if (!_appOptions.Value.IsYiBin)
|
|
|
+ {
|
|
|
+ beforeDelay = order.ExpiredTime.Value;
|
|
|
+ }
|
|
|
+ delay.AfterDelay = (await _expireTime
|
|
|
+ .CalcEndTime(beforeDelay, startTime, delay.DelayUnit, delay.DelayNum, order.AcceptTypeCode))?.EndTime; //todo
|
|
|
+ await _orderDelayRepository.Updateable().SetColumns(x => new OrderDelay() { AutomaticDelayNum = x.AutomaticDelayNum + 1, ApplyDelayTime = DateTime.Now, AfterDelay = delay.AfterDelay })
|
|
|
+ .Where(x => x.Id == delay.Id).ExecuteCommandAsync(cancellationToken);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ delay.OrderId = order.Id;
|
|
|
+ delay.EmployeeId = "";
|
|
|
+ delay.EmployeeName = "系统自动延期";
|
|
|
+ delay.ApplyOrgName = OrgSeedData.CenterName;
|
|
|
+ delay.ApplyOrgCode = OrgSeedData.CenterId;
|
|
|
+ delay.DelayApplyType = EDelayApplyType.LocalApply;
|
|
|
+ delay.BeforeDelay = order.ExpiredTime;
|
|
|
+ delay.DelayState = EDelayState.Pass;
|
|
|
+ delay.DelayReason = "系统自动延期";
|
|
|
+ delay.ApplyDelayTime = DateTime.Now;
|
|
|
+ delay.No = order.No;
|
|
|
+ delay.AutomaticDelayNum = 1;
|
|
|
+ delay.DelayNum = 1;
|
|
|
+ delay.DelayUnit = Share.Enums.Settings.ETimeType.WorkDay;
|
|
|
+ delay.IsProDelay = false;
|
|
|
+ delay.CreatorOrgId = OrgSeedData.CenterId;
|
|
|
+ delay.CreatorOrgName = OrgSeedData.CenterName;
|
|
|
+ delay.CreatorName = "系统自动延期";
|
|
|
var startTime = DateTime.Now;
|
|
|
if (order.CenterToOrgTime.HasValue)
|
|
|
{
|
|
|
startTime = order.CenterToOrgTime.Value;
|
|
|
}
|
|
|
- if (delay.BeforeDelay != null)
|
|
|
- {
|
|
|
- delay.AfterDelay = (await _expireTime
|
|
|
- .CalcEndTime(delay.BeforeDelay.Value,startTime, delay.DelayUnit, delay.DelayNum, order.AcceptTypeCode))?.EndTime; //todo
|
|
|
- }
|
|
|
- await _orderDelayRepository.AddAsync(delay, false, cancellationToken);
|
|
|
- }
|
|
|
- //处理工单延期
|
|
|
- await _orderApplication.DelayOrderExpiredTimeAsync(order.Id, delay.DelayNum,
|
|
|
- delay.DelayUnit, delay.IsProDelay, cancellationToken);
|
|
|
- //发送短信
|
|
|
- var workflow = await _workflowDomainService.GetWorkflowAsync(order.WorkflowId, withSteps: true, cancellationToken: cancellationToken);
|
|
|
- var steps = workflow.Steps.Where(x => x.Status == EWorkflowStepStatus.WaitForAccept || x.Status == EWorkflowStepStatus.WaitForHandle).ToList();
|
|
|
- if (steps.Any())
|
|
|
- {
|
|
|
- foreach (var step in steps)
|
|
|
- {
|
|
|
- var setting = step.HandlerOrgId == OrgSeedData.CenterId ? SettingConstants.AutomaticDelayCenterRoles : SettingConstants.AutomaticDelayDepartmentRoles;
|
|
|
- var roleIds = _systemSettingCacheManager.GetSetting(setting)?.SettingValue;
|
|
|
- if (step.HandlerOrgId == OrgSeedData.CenterId && string.IsNullOrEmpty(step.RoleId))
|
|
|
- {
|
|
|
- roleIds.Add(step.RoleId);
|
|
|
- }
|
|
|
- var userList = await _userRepository.Queryable().Where(x => x.OrgId == step.HandlerOrgId && x.Roles.Any(r => roleIds.Contains(r.Name))).ToListAsync(cancellationToken);
|
|
|
- foreach (var user in userList)
|
|
|
- {
|
|
|
- if (!string.IsNullOrEmpty(user.PhoneNo))
|
|
|
- {
|
|
|
- //发送短信
|
|
|
- var messageDto = new Share.Dtos.Push.MessageDto
|
|
|
- {
|
|
|
- PushBusiness = EPushBusiness.AutomaticDelay,
|
|
|
- ExternalId = order.Id,
|
|
|
- OrderId = order.Id,
|
|
|
- PushPlatform = EPushPlatform.Sms,
|
|
|
- Remark = order.Title,
|
|
|
- Name = user.Name,
|
|
|
- TemplateCode = "1015",
|
|
|
- Params = new List<string>() { order.No },
|
|
|
- TelNumber = user.PhoneNo,
|
|
|
- };
|
|
|
- await _mediator.Publish(new PushMessageNotify(messageDto), cancellationToken);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- order = await _orderRepository.GetAsync(dto.OrderId, cancellationToken);
|
|
|
- _capPublisher.PublishDelay(order.ExpiredTime.Value - DateTime.Now.AddHours(1), EventNames.HotlineOrderAutomaticDelay, new PublishAutomaticDelayDto() { OrderId = order.Id });
|
|
|
- var orderDto = _mapper.Map<OrderDto>(order);
|
|
|
- await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderExpiredTimeUpdate, orderDto,
|
|
|
- cancellationToken: cancellationToken);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ if (delay.BeforeDelay != null)
|
|
|
+ {
|
|
|
+ delay.AfterDelay = (await _expireTime
|
|
|
+ .CalcEndTime(delay.BeforeDelay.Value, startTime, delay.DelayUnit, delay.DelayNum, order.AcceptTypeCode))?.EndTime; //todo
|
|
|
+ }
|
|
|
+ await _orderDelayRepository.AddAsync(delay, false, cancellationToken);
|
|
|
+ }
|
|
|
+ //处理工单延期
|
|
|
+ await _orderApplication.DelayOrderExpiredTimeAsync(order.Id, delay.DelayNum, delay.DelayUnit, delay.IsProDelay, cancellationToken);
|
|
|
+
|
|
|
+ // 自贡任务 320调整“延期催办短信”发送的时间,将短信发送时间提前2个小时,所以拆分出去
|
|
|
+ ////发送短信
|
|
|
+ //var workflow = await _workflowDomainService.GetWorkflowAsync(order.WorkflowId, withSteps: true, cancellationToken: cancellationToken);
|
|
|
+ //var steps = workflow.Steps.Where(x => x.Status == EWorkflowStepStatus.WaitForAccept || x.Status == EWorkflowStepStatus.WaitForHandle).ToList();
|
|
|
+ //if (steps.Any())
|
|
|
+ //{
|
|
|
+ // foreach (var step in steps)
|
|
|
+ // {
|
|
|
+ // var setting = step.HandlerOrgId == OrgSeedData.CenterId ? SettingConstants.AutomaticDelayCenterRoles : SettingConstants.AutomaticDelayDepartmentRoles;
|
|
|
+ // var roleIds = _systemSettingCacheManager.GetSetting(setting)?.SettingValue;
|
|
|
+ // if (step.HandlerOrgId == OrgSeedData.CenterId && string.IsNullOrEmpty(step.RoleId))
|
|
|
+ // {
|
|
|
+ // roleIds.Add(step.RoleId);
|
|
|
+ // }
|
|
|
+ // var userList = await _userRepository.Queryable().Where(x => x.OrgId == step.HandlerOrgId && x.Roles.Any(r => roleIds.Contains(r.Name))).ToListAsync(cancellationToken);
|
|
|
+ // foreach (var user in userList)
|
|
|
+ // {
|
|
|
+ // if (!string.IsNullOrEmpty(user.PhoneNo))
|
|
|
+ // {
|
|
|
+ // //发送短信
|
|
|
+ // var messageDto = new Share.Dtos.Push.MessageDto
|
|
|
+ // {
|
|
|
+ // PushBusiness = EPushBusiness.AutomaticDelay,
|
|
|
+ // ExternalId = order.Id,
|
|
|
+ // OrderId = order.Id,
|
|
|
+ // PushPlatform = EPushPlatform.Sms,
|
|
|
+ // Remark = order.Title,
|
|
|
+ // Name = user.Name,
|
|
|
+ // TemplateCode = "1015",
|
|
|
+ // Params = new List<string>() { order.No },
|
|
|
+ // TelNumber = user.PhoneNo,
|
|
|
+ // };
|
|
|
+ // await _mediator.Publish(new PushMessageNotify(messageDto), cancellationToken);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order = await _orderRepository.GetAsync(dto.OrderId, cancellationToken);
|
|
|
+ _capPublisher.PublishDelay(order.ExpiredTime.Value - DateTime.Now.AddHours(1), EventNames.HotlineOrderAutomaticDelay, new PublishAutomaticDelayDto() { OrderId = order.Id });
|
|
|
+ var orderDto = _mapper.Map<OrderDto>(order);
|
|
|
+ await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderExpiredTimeUpdate, orderDto,
|
|
|
+ cancellationToken: cancellationToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 延期催办短信(延迟消息,自动延期前2小时发送)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [CapSubscribe(EventNames.HotlineOrderAutomaticSendSmsDelay)]
|
|
|
+ public async Task AutomaticDelaySendSms(PublishAutomaticDelayDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var enabled = _systemSettingCacheManager.GetSetting(SettingConstants.EnabledAutomaticDelay)?.SettingValue[0];
|
|
|
+ if (bool.Parse(enabled))
|
|
|
+ {
|
|
|
+ var order = await _orderRepository.GetAsync(dto.OrderId, cancellationToken);
|
|
|
+ var expiredTime = DateTime.Now.AddHours(2);
|
|
|
+ if (order != null && order.Status < EOrderStatus.Filed && order.ExpiredTime >= DateTime.Now)
|
|
|
+ {
|
|
|
+ if (order.ExpiredTime <= expiredTime)
|
|
|
+ {
|
|
|
+ var delayAny = await _orderDelayRepository.Queryable().Where(x => x.OrderId == order.Id && x.DelayState == EDelayState.Examining).AnyAsync();
|
|
|
+ if (!delayAny)
|
|
|
+ {
|
|
|
+ //发送短信
|
|
|
+ var workflow = await _workflowDomainService.GetWorkflowAsync(order.WorkflowId, withSteps: true, cancellationToken: cancellationToken);
|
|
|
+ var steps = workflow.Steps.Where(x => x.Status == EWorkflowStepStatus.WaitForAccept || x.Status == EWorkflowStepStatus.WaitForHandle).ToList();
|
|
|
+ if (steps.Any())
|
|
|
+ {
|
|
|
+ foreach (var step in steps)
|
|
|
+ {
|
|
|
+ var setting = step.HandlerOrgId == OrgSeedData.CenterId ? SettingConstants.AutomaticDelayCenterRoles : SettingConstants.AutomaticDelayDepartmentRoles;
|
|
|
+ var roleIds = _systemSettingCacheManager.GetSetting(setting)?.SettingValue;
|
|
|
+ if (step.HandlerOrgId == OrgSeedData.CenterId && string.IsNullOrEmpty(step.RoleId))
|
|
|
+ {
|
|
|
+ roleIds.Add(step.RoleId);
|
|
|
+ }
|
|
|
+ var userList = await _userRepository.Queryable().Where(x => x.OrgId == step.HandlerOrgId && x.Roles.Any(r => roleIds.Contains(r.Name))).ToListAsync(cancellationToken);
|
|
|
+ foreach (var user in userList)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(user.PhoneNo))
|
|
|
+ {
|
|
|
+ //发送短信
|
|
|
+ var messageDto = new Share.Dtos.Push.MessageDto
|
|
|
+ {
|
|
|
+ PushBusiness = EPushBusiness.AutomaticDelay,
|
|
|
+ ExternalId = order.Id,
|
|
|
+ OrderId = order.Id,
|
|
|
+ PushPlatform = EPushPlatform.Sms,
|
|
|
+ Remark = order.Title,
|
|
|
+ Name = user.Name,
|
|
|
+ TemplateCode = "1015",
|
|
|
+ Params = new List<string>() { order.No },
|
|
|
+ TelNumber = user.PhoneNo,
|
|
|
+ };
|
|
|
+ await _mediator.Publish(new PushMessageNotify(messageDto), cancellationToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量发送短信
|