admin 2 жил өмнө
parent
commit
a657e5a01a

+ 1 - 2
src/CallCenter.Api/Controllers/TestSdkController.cs

@@ -288,8 +288,7 @@ namespace CallCenter.Api.Controllers
                     Distribution = "sequential",
                     Ext = new List<string>()
                     {
-                        "209",
-                        "210"
+                        "8016",
                     }
                 }
             }, _options.Value.ReceiveKey,

+ 15 - 47
src/CallCenter.Application/Handlers/ExtState/IdleNotificationHandler.cs

@@ -2,6 +2,7 @@
 using CallCenter.Devices;
 using CallCenter.Notifications;
 using CallCenter.Realtimes;
+using CallCenter.Repository.SqlSugar;
 using CallCenter.Share.Enums;
 using CallCenter.Tels;
 using MediatR;
@@ -10,79 +11,46 @@ using NewRock.Sdk;
 using NewRock.Sdk.Control.Request;
 using NewRock.Sdk.Control.Response;
 using XF.Domain.Cache;
+using XF.Domain.Exceptions;
 
 namespace CallCenter.Application.Handlers
 {
     public class IdleNotificationHandler : INotificationHandler<IdleNotification>
     {
-        private readonly ITelRepository _telRepository;
         private readonly ITelCacheManager _telCacheManager;
         private readonly ITypedCache<Tel> _typedCache;
         private readonly IUserCacheManager _userCacheManager;
         private readonly IRealtimeService _realtimeService;
-        private readonly INewRockClient _newRockClient;
-        private readonly IOptionsSnapshot<DeviceConfigs> _options;
+        private readonly IDeviceManager _deviceManager;
+        private readonly ITelRestRepository _telRestRepository;
 
-        public IdleNotificationHandler(ITelRepository telRepository, ITelCacheManager telCacheManager, ITypedCache<Tel> typedCache, IUserCacheManager userCacheManager, IRealtimeService realtimeService,INewRockClient newRockClient,IOptionsSnapshot<DeviceConfigs> options)
+
+        public IdleNotificationHandler(ITelCacheManager telCacheManager, ITypedCache<Tel> typedCache, IUserCacheManager userCacheManager, IRealtimeService realtimeService, IDeviceManager deviceManager, ITelRestRepository telRestRepository)
         {
-            _telRepository = telRepository;
             _telCacheManager = telCacheManager;
             _typedCache = typedCache;
             _userCacheManager = userCacheManager;
             _realtimeService = realtimeService;
-            _newRockClient = newRockClient;
-            _options = options;
+            _deviceManager = deviceManager;
+            _telRestRepository = telRestRepository;
         }
 
         public async Task Handle(IdleNotification notification, CancellationToken cancellationToken)
         {
             var telModel = _telCacheManager.GetTel(notification.TelNo);
             telModel.TelStatus = Tels.ETelStatus.Ready;
-            //await _telRepository.UpdateAsync(telModel, cancellationToken);
             _typedCache.Set(notification.TelNo, telModel);
 
+            var iswork = await _userCacheManager.IsWorkingByTelAsync(notification.TelNo, cancellationToken);
+            if (!iswork)
+                throw new UserFriendlyException(notification.TelNo + "未查询到工作记录");
+            var restingTel = await _telRestRepository.GetAsync(d => d.TelId == telModel.Id && !d.EndTime.HasValue, cancellationToken);
+            if (restingTel !=null)
+                throw new UserFriendlyException("未查询到分机休息信息");
 
             foreach (var group in telModel.Groups)
             {
-                var result = await _newRockClient.QueryExtGroup(new QueryExtGroupRequest()
-                {
-                    Attribute = "Query",
-                    Group = new QueryExtGroup() { Id = group.No }
-                }, _options.Value.ReceiveKey,
-                _options.Value.Expired,
-                cancellationToken);
-
-                var exts = result.Group.First().Ext.Select(x=>x.Id).ToList();
-                exts.Add(notification.TelNo);
-
-                //更新
-                var groupModel = new Group()
-                {
-                    Id = group.No,
-                    Voicefile = group.Voice,
-                };
-                switch (group.Distribution)
-                {
-                    case EDistribution.Sequential:
-                        groupModel.Distribution = "sequential";
-                        break;
-                    case EDistribution.Group:
-                        groupModel.Distribution = "group";
-                        break;
-                    case EDistribution.Circular:
-                        groupModel.Distribution = "circular";
-                        break;
-                    default:
-                        break;
-                }
-
-                groupModel.Ext = exts;
-                await _newRockClient.ConfigExtGroup(
-                    new AssginConfigGroupRequest() { Attribute = "Assign", Group = groupModel, },
-                    _options.Value.ReceiveKey,
-                    _options.Value.Expired,
-                    cancellationToken
-                    );
+                await _deviceManager.AssginConfigGroupAsync(group.No, group.Distribution, new List<string>() { notification.TelNo },group.Voice,cancellationToken);
             }
 
 

+ 17 - 15
src/CallCenter.NewRock/DeviceManager.cs

@@ -400,22 +400,12 @@ namespace CallCenter.NewRock
             if (mId < 1 || mId > 50)
                 throw new UserFriendlyException("分机组只允许在1-50范围内");
 
-            #region 清除分机组设置
-
-            await _newRockClient.ConfigExtGroup(
-                new AssginConfigGroupRequest() { Attribute = "Assign", Group = new Group() { Id = groupId }, },
-                _options.Value.ReceiveKey,
-                _options.Value.Expired,
-                cancellationToken
-                );
-
-
-            #endregion
+           
 
 
             var list = await _telGroupRepository.QueryExtAsync(d =>d.No== groupId, d => d.Includes(x => x.Tels));
 
-            //检查是否上班和是否在空闲中
+            //检查是否上班
             List<string> exts = new List<string>();
             foreach (var ext in list[0].Tels)
             {
@@ -441,16 +431,28 @@ namespace CallCenter.NewRock
             }
 
             //优先加入空闲分机
+            List<string> groupExts = new List<string>();
             foreach (var ext in exts)
             {
                 var omExt = await _newRockClient.QueryExt(new QueryExtRequest() { Attribute = "Query", Ext = new Ext() { Id = ext } },_options.Value.ReceiveKey,_options.Value.Expired,cancellationToken);
-                if (omExt.Ext.State != "ready")
+                if (omExt != null && omExt.Ext.State == "ready")
                 {
-                    exts.Remove(ext);
+                    groupExts.Add(ext);
                 }
             }
 
 
+            #region 清除分机组设置
+
+            await _newRockClient.ConfigExtGroup(
+                new AssginConfigGroupRequest() { Attribute = "Assign", Group = new Group() { Id = groupId }, },
+                _options.Value.ReceiveKey,
+                _options.Value.Expired,
+                cancellationToken
+                );
+
+            #endregion
+
             //更新
             var groupModel = new Group()
             {
@@ -472,7 +474,7 @@ namespace CallCenter.NewRock
                     break;
             }
 
-            groupModel.Ext = exts;
+            groupModel.Ext = groupExts;
             await _newRockClient.ConfigExtGroup(
                 new AssginConfigGroupRequest() { Attribute = "Assign", Group = groupModel, },
                 _options.Value.ReceiveKey,

+ 2 - 1
src/CallCenter/Users/UserDomainService.cs

@@ -72,7 +72,8 @@ namespace CallCenter.Users
             //更新分机组
             foreach (var group in tel.Groups)
             {
-                await _deviceManager.ModifyGroupExtAsync(group.No,group.Distribution, group.Voice,"",true, cancellationToken);
+                //await _deviceManager.ModifyGroupExtAsync(group.No,group.Distribution, group.Voice,"",true, cancellationToken);
+                await _deviceManager.AssginConfigGroupAsync(group.No, group.Distribution,new List<string>() { tel.No }, group.Voice, cancellationToken);
             }
         }