admin 2 năm trước cách đây
mục cha
commit
3b083fe650

+ 1 - 0
src/CallCenter.Api/CallCenter.Api.csproj

@@ -16,6 +16,7 @@
     <PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="6.0.8" />
     <PackageReference Include="NETCore.Encrypt" Version="2.1.0" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
+    <PackageReference Include="System.Reactive" Version="5.0.0" />
   </ItemGroup>
 
   <ItemGroup>

+ 173 - 6
src/CallCenter.Api/Controllers/TestSdkController.cs

@@ -1,16 +1,18 @@
-using CallCenter.Devices;
+using CallCenter.Caches;
+using CallCenter.Devices;
+using CallCenter.Share.Enums;
+using CallCenter.Tels;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Options;
 using NewRock.Sdk;
 using NewRock.Sdk.Control.Request;
-using NewRock.Sdk.Control.Request.Base;
 using NewRock.Sdk.Control.Response;
 using NewRock.Sdk.Manage.Request;
 using NewRock.Sdk.Transfer.Conference.Request;
 using NewRock.Sdk.Transfer.Connect.Request;
 using NewRock.Sdk.Transfer.Queue.Request;
-using System.Text.RegularExpressions;
-using XF.Domain.Exceptions;
+using System.Diagnostics;
+
 using Ext = NewRock.Sdk.Control.Request.Base.Ext;
 using Group = NewRock.Sdk.Control.Request.Group;
 using VisitorToExtVisitor = NewRock.Sdk.Transfer.Connect.Request.VisitorToExtVisitor;
@@ -25,18 +27,183 @@ namespace CallCenter.Api.Controllers
         private readonly INewRockClient _client;
         private readonly ILogger<TestController> _logger;
         private readonly IOptionsSnapshot<DeviceConfigs> _options;
+        private readonly ITelCacheManager _telCacheManager;
+        private readonly ITelGroupRepository _telGroupRepository;
+        private readonly ITelRestRepository _telRestRepository;
+        private readonly IUserCacheManager _userCacheManager;
 
         public TestSdkController(
             INewRockClient client,
             ILogger<TestController> logger,
-            IOptionsSnapshot<DeviceConfigs> options
-            )
+            IOptionsSnapshot<DeviceConfigs> options,
+            ITelCacheManager telCacheManager,
+            ITelGroupRepository  telGroupRepository,
+            ITelRestRepository telRestRepository,
+            IUserCacheManager userCacheManager)
         {
             _client = client;
             _logger = logger;
             _options = options;
+            _telCacheManager = telCacheManager;
+            _telGroupRepository = telGroupRepository;
+            _telRestRepository = telRestRepository;
+            _userCacheManager = userCacheManager;
         }
 
+        #region 测试加入分机组
+
+        /// <summary>
+        /// 将分机加入到分机组
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("add-exttogroup")]
+        public async Task AddExtToGroup(string extid)
+        {
+            Stopwatch stopwatch = new Stopwatch();
+            var tel = _telCacheManager.GetTel(extid);
+            foreach (var group in tel.Groups)
+            {
+                stopwatch.Start();
+                var groupModel = new Group()
+                {
+                    Id = group.No,
+                    Ext = new List<string>() { extid }
+                };
+
+                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;
+                }
+
+                if (!string.IsNullOrEmpty(group.Voice))
+                    groupModel.Voicefile = group.Voice;
+
+                stopwatch.Stop();
+                _logger.LogInformation("组装数据,分机组号:" + group.No + ",耗时:" + stopwatch.ElapsedMilliseconds + "ms");
+
+                stopwatch.Restart();
+
+                var resp = await _client.ConfigExtGroup(new AssginConfigGroupRequest()
+                {
+                    Attribute = "Assign",
+                    Group = groupModel
+                }, _options.Value.ReceiveKey,
+                    _options.Value.Expired,
+                    HttpContext.RequestAborted);
+                stopwatch.Stop();
+                _logger.LogInformation("更新设备,分机组号:" + group.No + ",耗时:" + stopwatch.ElapsedMilliseconds + "ms");
+            }
+        }
+
+        /// <summary>
+        /// 将分机移除分机组
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("remove-extfromgroup")]
+        public async Task RemoveExtFromGroup(string extid)
+        {
+            Stopwatch stopwatch = new Stopwatch();
+            var tel = _telCacheManager.GetTel(extid);
+            foreach (var group in tel.Groups)
+            {
+                
+
+                stopwatch.Start();
+
+                #region 清除分机组设置
+
+                await _client.ConfigExtGroup(
+                    new AssginConfigGroupRequest() { Attribute = "Assign", Group = new Group() { Id = group.No }, },
+                    _options.Value.ReceiveKey,
+                    _options.Value.Expired,
+                    HttpContext.RequestAborted
+                    );
+
+                #endregion
+
+                stopwatch.Stop();
+                _logger.LogInformation("分机组清空,分机组:" + group.No + ",执行时间:" + stopwatch.ElapsedMilliseconds + "ms");
+
+
+                stopwatch.Restart();
+                var list = await _telGroupRepository.QueryExtAsync(d => d.No == group.No, d => d.Includes(x => x.Tels));
+
+                //检查是否上班
+                List<string> exts = new List<string>();
+                foreach (var ext in list[0].Tels)
+                {
+                    var iswork = await _userCacheManager.IsWorkingByTelAsync(ext.No, HttpContext.RequestAborted);
+                    if (iswork)
+                    {
+                        var teltemp = _telCacheManager.GetTel(ext.No);
+                        if (teltemp.TelStatus == Tels.ETelStatus.Ready)
+                        {
+                            exts.Add(ext.No);
+                        }
+                    }
+                }
+
+                //查询所有正在休息的分机
+                List<string> restexts = (await _telRestRepository.QueryAsync(x => x.EndTime == null)).Select(x => x.TelNo).ToList();
+                if (restexts != null && restexts.Count > 0)
+                {
+                    foreach (var item in restexts)
+                    {
+                        exts.Remove(item);
+                    }
+                }
+
+                //更新
+                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;
+
+                stopwatch.Stop();
+                _logger.LogInformation("分机组组装数据,分机组:" + group.No + ",执行时间:" + stopwatch.ElapsedMilliseconds + "ms");
+
+                stopwatch.Restart();
+                await _client.ConfigExtGroup(
+                    new AssginConfigGroupRequest() { Attribute = "Assign", Group = groupModel, },
+                    _options.Value.ReceiveKey,
+                    _options.Value.Expired,
+                    HttpContext.RequestAborted
+                    );
+                stopwatch.Stop();
+                _logger.LogInformation("更新设备分机组数据,分机组:" + group.No + ",执行时间:" + stopwatch.ElapsedMilliseconds + "ms");
+
+            }
+        }
+
+        #endregion
+
         #region  查询(Query)
 
         /// <summary>