|
@@ -0,0 +1,79 @@
|
|
|
+using Hotline.Caching.Interfaces;
|
|
|
+using Hotline.Caching.Services;
|
|
|
+using Hotline.Share.Dtos.TrCallCenter;
|
|
|
+using Hotline.Users;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Tr.Sdk;
|
|
|
+using XF.Domain.Authentications;
|
|
|
+using XF.Domain.Constants;
|
|
|
+using XF.Domain.Exceptions;
|
|
|
+
|
|
|
+namespace Hotline.Application.CallCenter.Calls
|
|
|
+{
|
|
|
+ public class TrApplication : ITrApplication
|
|
|
+ {
|
|
|
+ private readonly ITrClient _trClient;
|
|
|
+ private readonly ISessionContext _sessionContext;
|
|
|
+ private readonly IWorkRepository _workRepository;
|
|
|
+ private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
+ private readonly IUserCacheManager _userCacheManager;
|
|
|
+ public TrApplication(ITrClient trClient, ISessionContext sessionContext,IWorkRepository workRepository,ISystemSettingCacheManager systemSettingCacheManager,IUserCacheManager userCacheManager)
|
|
|
+ {
|
|
|
+ _trClient = trClient;
|
|
|
+ _sessionContext = sessionContext;
|
|
|
+ _workRepository = workRepository;
|
|
|
+ _systemSettingCacheManager = systemSettingCacheManager;
|
|
|
+ _userCacheManager = userCacheManager;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 签入
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="userId"></param>
|
|
|
+ /// <param name="telNo"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<TrOnDutyResponseDto> OnSign(string userId,string telNo,CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var work = _userCacheManager.GetWorkByUserNoExp(userId);
|
|
|
+ if (work is not null)
|
|
|
+ {
|
|
|
+ if (work.TelNo == telNo)
|
|
|
+ {
|
|
|
+ return new TrOnDutyResponseDto() { TelNo = work.TelNo, TelPwd = work.TelPwd, Description = work.Description };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw UserFriendlyException.SameMessage("当前用户已签入其他分机");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var telWork = _userCacheManager.GetWorkByTelNoExp(telNo);
|
|
|
+ if (telWork is not null)
|
|
|
+ {
|
|
|
+ throw UserFriendlyException.SameMessage("当前分机已被占用");
|
|
|
+ }
|
|
|
+
|
|
|
+ var telModel = await _trClient.QueryTelsAsync(new Tr.Sdk.Tels.QueryTelRequest() { TelNo = telNo }, cancellationToken);
|
|
|
+ if (telModel !=null && telModel.Count>0)
|
|
|
+ {
|
|
|
+ work = new Work(_sessionContext.UserId, _sessionContext.UserName, telModel[0].Id, telNo, telModel[0].Password, telModel[0].Description);
|
|
|
+ await _workRepository.AddAsync(work, cancellationToken);
|
|
|
+ bool IsTelNeedVerify = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsTelNeedVerify).SettingValue[0]);
|
|
|
+ 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 };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ throw UserFriendlyException.SameMessage("签入异常,未查询到对应分机信息");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|