|
@@ -1,10 +1,12 @@
|
|
using Hotline.Caching.Interfaces;
|
|
using Hotline.Caching.Interfaces;
|
|
using Hotline.CallCenter.Devices;
|
|
using Hotline.CallCenter.Devices;
|
|
using Hotline.CallCenter.Tels;
|
|
using Hotline.CallCenter.Tels;
|
|
-using Hotline.Share.Dtos.CallCenter;
|
|
|
|
|
|
+using Hotline.Share.Dtos.TrCallCenter;
|
|
using Hotline.Share.Dtos.Users;
|
|
using Hotline.Share.Dtos.Users;
|
|
using MapsterMapper;
|
|
using MapsterMapper;
|
|
|
|
+using Tr.Sdk;
|
|
using XF.Domain.Cache;
|
|
using XF.Domain.Cache;
|
|
|
|
+using XF.Domain.Constants;
|
|
using XF.Domain.Dependency;
|
|
using XF.Domain.Dependency;
|
|
using XF.Domain.Exceptions;
|
|
using XF.Domain.Exceptions;
|
|
using XF.Domain.Repository;
|
|
using XF.Domain.Repository;
|
|
@@ -20,6 +22,8 @@ namespace Hotline.Users
|
|
private readonly ITelCacheManager _telCacheManager;
|
|
private readonly ITelCacheManager _telCacheManager;
|
|
private readonly ITypedCache<Work> _cacheWork;
|
|
private readonly ITypedCache<Work> _cacheWork;
|
|
private readonly IMapper _mapper;
|
|
private readonly IMapper _mapper;
|
|
|
|
+ private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
|
+ private readonly ITrClient _trClient;
|
|
|
|
|
|
public UserDomainService(
|
|
public UserDomainService(
|
|
IRepository<User> userRepository,
|
|
IRepository<User> userRepository,
|
|
@@ -27,7 +31,10 @@ namespace Hotline.Users
|
|
IDeviceManager deviceManager,
|
|
IDeviceManager deviceManager,
|
|
ITypedCache<Work> cacheWork,
|
|
ITypedCache<Work> cacheWork,
|
|
IUserCacheManager userCacheManager,
|
|
IUserCacheManager userCacheManager,
|
|
- IMapper mapper, ITelCacheManager telCacheManager)
|
|
|
|
|
|
+ IMapper mapper,
|
|
|
|
+ ITelCacheManager telCacheManager,
|
|
|
|
+ ISystemSettingCacheManager systemSettingCacheManager,
|
|
|
|
+ ITrClient trClient)
|
|
{
|
|
{
|
|
_userRepository = userRepository;
|
|
_userRepository = userRepository;
|
|
_workRepository = workRepository;
|
|
_workRepository = workRepository;
|
|
@@ -36,6 +43,8 @@ namespace Hotline.Users
|
|
_cacheWork = cacheWork;
|
|
_cacheWork = cacheWork;
|
|
_mapper = mapper;
|
|
_mapper = mapper;
|
|
_telCacheManager = telCacheManager;
|
|
_telCacheManager = telCacheManager;
|
|
|
|
+ _systemSettingCacheManager = systemSettingCacheManager;
|
|
|
|
+ _trClient = trClient;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -114,22 +123,55 @@ namespace Hotline.Users
|
|
/// <param name="TelNo"></param>
|
|
/// <param name="TelNo"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public async Task TrOnDutyAsync(string userId,string TelId,string TelNo,CancellationToken cancellationToken)
|
|
|
|
|
|
+ public async Task<TrOnDutyResponseDto> TrOnDutyAsync(string userId, string? TelId, string? TelNo, string? TelPwd, string? Description,CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
|
|
+ var workingTel = await _workRepository.GetCurrentWorkByUserAsync(userId, cancellationToken);
|
|
|
|
+ if (workingTel is not null)
|
|
|
|
+ {
|
|
|
|
+ return new TrOnDutyResponseDto() { TelNo = workingTel.TelNo, TelPwd = workingTel.TelPwd, Description = workingTel.Description };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //检查配置
|
|
|
|
+ bool IsNeedTelNo = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsNeedTelNo).SettingValue[0]);
|
|
|
|
+ if (IsNeedTelNo && string.IsNullOrEmpty(TelNo))
|
|
|
|
+ {
|
|
|
|
+ throw UserFriendlyException.SameMessage("当前配置需要选择分机号签入");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
var user = await _userRepository.GetAsync(userId, cancellationToken);
|
|
var user = await _userRepository.GetAsync(userId, cancellationToken);
|
|
if (user is null)
|
|
if (user is null)
|
|
throw UserFriendlyException.SameMessage("无效的用户编号");
|
|
throw UserFriendlyException.SameMessage("无效的用户编号");
|
|
|
|
|
|
- var workingTel = await _workRepository.GetCurrentWorkByUserAsync(userId, cancellationToken);
|
|
|
|
- if (workingTel is not null)
|
|
|
|
- throw UserFriendlyException.SameMessage($"当前用户已上班,userId:{userId}");
|
|
|
|
|
|
+ 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);
|
|
var telIsWorking = await _workRepository.AnyAsync(d => d.TelId == TelId && !d.EndTime.HasValue, cancellationToken);
|
|
if (telIsWorking)
|
|
if (telIsWorking)
|
|
throw UserFriendlyException.SameMessage("当前分机已被占用");
|
|
throw UserFriendlyException.SameMessage("当前分机已被占用");
|
|
|
|
|
|
- var work = new Work(userId, user.Name, TelId, TelNo);
|
|
|
|
|
|
+ var work = new Work(userId, user.Name, TelId, TelNo,rsp.TelPwd,rsp.Description);
|
|
await _workRepository.AddAsync(work, cancellationToken);
|
|
await _workRepository.AddAsync(work, cancellationToken);
|
|
|
|
+
|
|
|
|
+ if (IsTelNeedVerify)
|
|
|
|
+ {
|
|
|
|
+ rsp.TelPwd = string.Empty;
|
|
|
|
+ }
|
|
|
|
+ return rsp;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|