|
@@ -1,10 +1,13 @@
|
|
|
using Hotline.Caching.Interfaces;
|
|
|
using Hotline.CallCenter.Devices;
|
|
|
using Hotline.CallCenter.Tels;
|
|
|
+using Hotline.Share.Dtos.CallCenter;
|
|
|
using Hotline.Share.Dtos.TrCallCenter;
|
|
|
using Hotline.Share.Dtos.Users;
|
|
|
using MapsterMapper;
|
|
|
+using System.Security.Cryptography;
|
|
|
using Tr.Sdk;
|
|
|
+using XF.Domain.Authentications;
|
|
|
using XF.Domain.Cache;
|
|
|
using XF.Domain.Constants;
|
|
|
using XF.Domain.Dependency;
|
|
@@ -24,6 +27,7 @@ namespace Hotline.Users
|
|
|
private readonly IMapper _mapper;
|
|
|
private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
private readonly ITrClient _trClient;
|
|
|
+ private readonly ISessionContext _sessionContext;
|
|
|
|
|
|
public UserDomainService(
|
|
|
IRepository<User> userRepository,
|
|
@@ -34,7 +38,9 @@ namespace Hotline.Users
|
|
|
IMapper mapper,
|
|
|
ITelCacheManager telCacheManager,
|
|
|
ISystemSettingCacheManager systemSettingCacheManager,
|
|
|
- ITrClient trClient)
|
|
|
+ ITrClient trClient,
|
|
|
+ ISessionContext sessionContext
|
|
|
+ )
|
|
|
{
|
|
|
_userRepository = userRepository;
|
|
|
_workRepository = workRepository;
|
|
@@ -45,6 +51,7 @@ namespace Hotline.Users
|
|
|
_telCacheManager = telCacheManager;
|
|
|
_systemSettingCacheManager = systemSettingCacheManager;
|
|
|
_trClient = trClient;
|
|
|
+ _sessionContext = sessionContext;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -119,63 +126,48 @@ namespace Hotline.Users
|
|
|
/// 上班
|
|
|
/// </summary>
|
|
|
/// <param name="userId"></param>
|
|
|
- /// <param name="TelId"></param>
|
|
|
- /// <param name="TelNo"></param>
|
|
|
+ /// <param name="telNo"></param>
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<TrOnDutyResponseDto> TrOnDutyAsync(string userId, string? TelId, string? TelNo, string? TelPwd, string? Description, CancellationToken cancellationToken)
|
|
|
+ public async Task<TrOnDutyResponseDto> TrOnDutyAsync(string userId, string telNo, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- var workingTel = await _workRepository.GetCurrentWorkByUserAsync(userId, cancellationToken);
|
|
|
- if (workingTel is not null)
|
|
|
+ var work = _userCacheManager.GetWorkByUserNoExp(userId);
|
|
|
+ if(work is not null)
|
|
|
{
|
|
|
- return new TrOnDutyResponseDto() { TelNo = workingTel.TelNo, TelPwd = workingTel.TelPwd, Description = workingTel.Description };
|
|
|
+ if(work.TelNo == telNo)
|
|
|
+ {
|
|
|
+ return new TrOnDutyResponseDto() { TelNo = work.TelNo, TelPwd = work.TelPwd, Description = work.Description };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw UserFriendlyException.SameMessage("当前用户已签入其他分机");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //检查配置
|
|
|
- bool IsNeedTelNo = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsNeedTelNo).SettingValue[0]);
|
|
|
- if (IsNeedTelNo && string.IsNullOrEmpty(TelNo))
|
|
|
+ var telWork = _userCacheManager.GetWorkByTelNoExp(telNo);
|
|
|
+ if (telWork is not null)
|
|
|
{
|
|
|
- throw UserFriendlyException.SameMessage("当前配置需要选择分机号签入");
|
|
|
+ throw UserFriendlyException.SameMessage("当前分机已被占用");
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- var user = await _userRepository.GetAsync(userId, cancellationToken);
|
|
|
- if (user is null)
|
|
|
- throw UserFriendlyException.SameMessage("无效的用户编号");
|
|
|
-
|
|
|
bool IsTelNeedVerify = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsTelNeedVerify).SettingValue[0]);
|
|
|
- var rsp = new TrOnDutyResponseDto();
|
|
|
- if (!IsNeedTelNo)
|
|
|
- {
|
|
|
- TelNo = user.DefaultTelNo;
|
|
|
- var telModel = await _trClient.QueryTelsAsync(new Tr.Sdk.Tels.QueryTelRequest() { TelNo = TelNo }, cancellationToken);
|
|
|
- TelId = telModel[0].Id;
|
|
|
- rsp.TelPwd = telModel[0].Password;
|
|
|
- rsp.Description = telModel[0].Description;
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- rsp.TelNo = TelNo;
|
|
|
-
|
|
|
-
|
|
|
- var telIsWorking = await _workRepository.AnyAsync(d => d.TelId == TelId && !d.EndTime.HasValue, cancellationToken);
|
|
|
- if (telIsWorking)
|
|
|
- throw UserFriendlyException.SameMessage("当前分机已被占用");
|
|
|
-
|
|
|
- var work = new Work(userId, user.Name, TelId, TelNo, rsp.TelPwd, rsp.Description);
|
|
|
- await _workRepository.AddAsync(work, cancellationToken);
|
|
|
-
|
|
|
- if (IsTelNeedVerify)
|
|
|
+ var telModel = await _trClient.QueryTelsAsync(new Tr.Sdk.Tels.QueryTelRequest() { TelNo = telNo }, cancellationToken);
|
|
|
+ if (telModel!=null && telModel.Count>0)
|
|
|
{
|
|
|
- rsp.TelPwd = string.Empty;
|
|
|
+ work = new Work(userId, _sessionContext.UserName, telModel[0].Id, telNo, telModel[0].Password, telModel[0].Description);
|
|
|
+ await _workRepository.AddAsync(work, cancellationToken);
|
|
|
+ if (IsTelNeedVerify)
|
|
|
+ {
|
|
|
+ return new TrOnDutyResponseDto() { TelNo = telNo, TelPwd = "", Description = telModel[0].Description };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return new TrOnDutyResponseDto() { TelNo = telNo, TelPwd = telModel[0].Password, Description = telModel[0].Description };
|
|
|
+ }
|
|
|
}
|
|
|
- return rsp;
|
|
|
- }
|
|
|
-
|
|
|
- public async Task<TrOnDutyResponseDto> TrOnDutyAsync(string userId, string telNo, CancellationToken cancellationToken)
|
|
|
- {
|
|
|
+ throw UserFriendlyException.SameMessage("签入异常,未查询到对应分机信息");
|
|
|
/*
|
|
|
*var work = 缓存.get(userId);
|
|
|
* if(work.TelNo == telNo)
|
|
@@ -192,7 +184,6 @@ namespace Hotline.Users
|
|
|
* 根据配置 return new();
|
|
|
*
|
|
|
*/
|
|
|
- throw new NotImplementedException();
|
|
|
}
|
|
|
|
|
|
|