|
@@ -0,0 +1,128 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Hotline.Caching.Interfaces;
|
|
|
+using Hotline.CallCenter.BlackLists;
|
|
|
+using Hotline.CallCenter.Tels;
|
|
|
+using Hotline.Repository.SqlSugar.CallCenter;
|
|
|
+using Hotline.Share.Dtos.CallCenter;
|
|
|
+using Hotline.Share.Dtos.TrCallCenter;
|
|
|
+using Hotline.Users;
|
|
|
+using XF.Domain.Authentications;
|
|
|
+using XF.Domain.Cache;
|
|
|
+using XF.Domain.Exceptions;
|
|
|
+using XF.Domain.Repository;
|
|
|
+
|
|
|
+namespace Hotline.Application.CallCenter
|
|
|
+{
|
|
|
+ public class XingTangCallApplication : ICallApplication
|
|
|
+ {
|
|
|
+ private readonly IRepository<Tel> _telRepository;
|
|
|
+ private readonly IRepository<TelGroup> _telGroupRepository;
|
|
|
+ private readonly IWorkRepository _workRepository;
|
|
|
+ private readonly ITelRestRepository _telRestRepository;
|
|
|
+ private readonly ITypedCache<Work> _cacheWork;
|
|
|
+ private readonly IUserCacheManager _userCacheManager;
|
|
|
+ private readonly ISessionContext _sessionContext;
|
|
|
+
|
|
|
+ public XingTangCallApplication(
|
|
|
+ IRepository<Tel> telRepository,
|
|
|
+ IRepository<TelGroup> telGroupRepository,
|
|
|
+ IWorkRepository workRepository,
|
|
|
+ ITelRestRepository telRestRepository,
|
|
|
+ ITypedCache<Work> cacheWork,
|
|
|
+ IUserCacheManager userCacheManager,
|
|
|
+ ISessionContext sessionContext)
|
|
|
+ {
|
|
|
+ _telRepository = telRepository;
|
|
|
+ _telGroupRepository = telGroupRepository;
|
|
|
+ _workRepository = workRepository;
|
|
|
+ _telRestRepository = telRestRepository;
|
|
|
+ _cacheWork = cacheWork;
|
|
|
+ _userCacheManager = userCacheManager;
|
|
|
+ _sessionContext = sessionContext;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<IReadOnlyList<TelDto>> QueryTelsAsync(CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return await _telRepository.Queryable()
|
|
|
+ .Select<TelDto>()
|
|
|
+ .ToListAsync(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<IReadOnlyList<TelGroupDto>> QueryTelGroupsAsync(CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return await _telGroupRepository.Queryable()
|
|
|
+ .Select<TelGroupDto>()
|
|
|
+ .ToListAsync(cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Task<string> AddBlackListAsync(AddBlacklistDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Task RemoveBlackListAsync(string id, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Task<List<Blacklist>> QueryBlackListsAsync(CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<TrOnDutyResponseDto> SignInAsync(SignInDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(dto.TelNo))
|
|
|
+ throw UserFriendlyException.SameMessage("无效分机号");
|
|
|
+ var work = _userCacheManager.GetWorkByUserNoExp(_sessionContext.RequiredUserId);
|
|
|
+ if (work is not null)
|
|
|
+ {
|
|
|
+ //if (work.TelNo != dto.TelNo)
|
|
|
+ //{
|
|
|
+ // throw UserFriendlyException.SameMessage("当前用户已签入其他分机");
|
|
|
+ //}
|
|
|
+ throw UserFriendlyException.SameMessage("当前用户已签入");
|
|
|
+ }
|
|
|
+
|
|
|
+ var telWork = _userCacheManager.GetWorkByTelNoExp(dto.TelNo);
|
|
|
+ if (telWork is not null)
|
|
|
+ {
|
|
|
+ throw UserFriendlyException.SameMessage("当前分机已被占用");
|
|
|
+ }
|
|
|
+
|
|
|
+ work = new Work(_sessionContext.RequiredUserId, _sessionContext.UserName,
|
|
|
+ dto.TelNo, dto.TelNo, null, null,
|
|
|
+ dto.GroupId, _sessionContext.StaffNo, null);
|
|
|
+ await _workRepository.AddAsync(work, cancellationToken);
|
|
|
+
|
|
|
+ return new TrOnDutyResponseDto
|
|
|
+ {
|
|
|
+ TelNo = dto.TelNo,
|
|
|
+ QueueId = dto.GroupId,
|
|
|
+ StartTime = work.StartTime,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task SingOutAsync(CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var work = _userCacheManager.GetWorkByUser(_sessionContext.RequiredUserId);
|
|
|
+ if (work is null) return;
|
|
|
+
|
|
|
+ var telRest = await _telRestRepository.GetAsync(x => x.TelNo == work.TelNo && !x.EndTime.HasValue, cancellationToken);
|
|
|
+ if (telRest is not null)
|
|
|
+ {
|
|
|
+ telRest.EndRest();
|
|
|
+ await _telRestRepository.UpdateAsync(telRest, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ work.OffDuty();
|
|
|
+ await _workRepository.UpdateAsync(work, cancellationToken);
|
|
|
+ _cacheWork.Remove(work.GetKey(KeyMode.UserId));
|
|
|
+ _cacheWork.Remove(work.GetKey(KeyMode.TelNo));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|