|
@@ -18,6 +18,7 @@ using XF.Domain.Exceptions;
|
|
|
using Group = NewRock.Sdk.Control.Request.Group;
|
|
|
using Hotline.Share.Dtos.CallCenter;
|
|
|
using Hotline.Share.Enums.CallCenter;
|
|
|
+using Hotline.Caches;
|
|
|
|
|
|
namespace Hotline.NewRock
|
|
|
{
|
|
@@ -27,13 +28,19 @@ namespace Hotline.NewRock
|
|
|
private readonly ICallRepository _callRepository;
|
|
|
private readonly IOptionsSnapshot<DeviceConfigs> _options;
|
|
|
private readonly IMapper _mapper;
|
|
|
+ private readonly ITelGroupRepository _telGroupRepository;
|
|
|
+ private readonly IUserCacheManager _userCacheManager;
|
|
|
+ private readonly ITelRestRepository _telRestRepository;
|
|
|
|
|
|
- public DeviceManager(INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options, IMapper mapper, ICallRepository callRepository)
|
|
|
+ public DeviceManager(INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options, IMapper mapper, ICallRepository callRepository, ITelGroupRepository telGroupRepository,IUserCacheManager userCacheManager, ITelRestRepository telRestRepository)
|
|
|
{
|
|
|
_newRockClient = newRockClient;
|
|
|
_options = options;
|
|
|
_mapper = mapper;
|
|
|
_callRepository = callRepository;
|
|
|
+ _telGroupRepository = telGroupRepository;
|
|
|
+ _userCacheManager = userCacheManager;
|
|
|
+ _telRestRepository = telRestRepository;
|
|
|
}
|
|
|
|
|
|
#region 查询
|
|
@@ -328,7 +335,7 @@ namespace Hotline.NewRock
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
/// <param name="isAdd"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task ModifyGroupExtAsync(string groupId,string ext,string voicefile="",bool isAdd=true,CancellationToken cancellationToken = default)
|
|
|
+ public async Task ModifyGroupExtAsync(string groupId, EDistribution distribution, string voicefile = "", string extId = "", bool isAdd = true, CancellationToken cancellationToken = default)
|
|
|
{
|
|
|
if (!int.TryParse(groupId, out int mId))
|
|
|
throw new UserFriendlyException("请输入数字");
|
|
@@ -336,31 +343,53 @@ namespace Hotline.NewRock
|
|
|
if (mId < 1 || mId > 50)
|
|
|
throw new UserFriendlyException("分机组只允许在1-50范围内");
|
|
|
|
|
|
- //查询原设备数据
|
|
|
- var result = await _newRockClient.QueryExtGroup(
|
|
|
- new QueryExtGroupRequest() { Attribute = "Query", Group = new QueryExtGroup() { Id = groupId } },
|
|
|
- _options.Value.ReceiveKey,
|
|
|
- _options.Value.Expired,
|
|
|
- cancellationToken
|
|
|
- );
|
|
|
+ #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)
|
|
|
+ {
|
|
|
+ var iswork = await _userCacheManager.IsWorkingByTelAsync(ext.No, cancellationToken);
|
|
|
+ if (iswork)
|
|
|
+ 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 exts = result.Group[0].Ext;
|
|
|
var groupModel = new Group()
|
|
|
{
|
|
|
Id = groupId,
|
|
|
Voicefile = voicefile
|
|
|
};
|
|
|
-
|
|
|
- if (isAdd)
|
|
|
- {
|
|
|
- exts.Add(new QueryExtGroupExt(){ Id = ext });
|
|
|
- }
|
|
|
- else
|
|
|
+ switch (distribution)
|
|
|
{
|
|
|
- exts.Remove(exts.First(x => x.Id == ext));
|
|
|
+ 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.Select(x => x.Id).ToList(); //Enumerable.Select<QueryExtGroupExt, string>(exts, x=>x.Id).ToList();
|
|
|
+ groupModel.Ext = exts;
|
|
|
await _newRockClient.ConfigExtGroup(
|
|
|
new AssginConfigGroupRequest() { Attribute = "Assign", Group = groupModel, },
|
|
|
_options.Value.ReceiveKey,
|