BootupNotificationHandler.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using CallCenter.Caches;
  2. using CallCenter.Devices;
  3. using CallCenter.Ivrs;
  4. using CallCenter.Repository.SqlSugar;
  5. using CallCenter.Share.Notifications;
  6. using CallCenter.Tels;
  7. using MediatR;
  8. using NewRock.Sdk.Control.Request.Base;
  9. using Newtonsoft.Json.Serialization;
  10. namespace CallCenter.Application.Handlers.System
  11. {
  12. public class BootupNotificationHandler : INotificationHandler<BootupNotification>
  13. {
  14. private readonly ITelGroupRepository _telGroupRepository;
  15. private readonly IIvrRepository _ivrRepository;
  16. private readonly IDeviceManager _deviceManager;
  17. private readonly IUserCacheManager _userCacheManager;
  18. public BootupNotificationHandler(ITelGroupRepository telGroupRepository, IDeviceManager deviceManager, IUserCacheManager userCacheManager, IIvrRepository ivrRepository)
  19. {
  20. _telGroupRepository = telGroupRepository;
  21. _deviceManager = deviceManager;
  22. _userCacheManager = userCacheManager;
  23. _ivrRepository = ivrRepository;
  24. }
  25. public async Task Handle(BootupNotification notification, CancellationToken cancellationToken)
  26. {
  27. #region 还原所有分机组配置
  28. //查询所有分机组
  29. var list = await _telGroupRepository.QueryExtAsync(d => true, d => d.Includes(x => x.Tels));
  30. foreach (var groupItem in list)
  31. {
  32. List<string> exts = new List<string>();
  33. foreach (var ext in groupItem.Tels)
  34. {
  35. var iswork = await _userCacheManager.IsWorkingByTelAsync(ext.No, cancellationToken);
  36. if (iswork)
  37. exts.Add(ext.No);
  38. }
  39. //轮循还原设备分机组信息
  40. await _deviceManager.AssginConfigGroupAsync(groupItem.No, groupItem.Distribution, exts, groupItem.Voice,
  41. cancellationToken);
  42. }
  43. #endregion
  44. #region 还原所有语音菜单配置
  45. //查询所有IVR
  46. var ivrlist = await _ivrRepository.QueryAsync();
  47. foreach (var item in ivrlist)
  48. {
  49. await _deviceManager.AssginConfigMenuAsync(item.No, item.Voice, item.Repeat.ToString(), item.InfoLength.ToString(), item.Exit, cancellationToken);
  50. }
  51. #endregion
  52. //TODO 有新还原的设置加在后面
  53. }
  54. }
  55. }