123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using Hotline.Caches;
- using Hotline.CallCenter.Devices;
- using Hotline.Realtimes;
- using Hotline.Users;
- using System.Reflection;
- using XF.Domain.Constants;
- using XF.Domain.Dependency;
- using XF.Domain.Exceptions;
- namespace Hotline.CallCenter.Tels;
- public class TelDomainService : ITelDomainService, IScopeDependency
- {
- private readonly IDeviceManager _deviceManager;
- private readonly ITelRepository _telRepository;
- private readonly ITelRestRepository _telRestRepository;
- private readonly ITelHoldRepository _telHoldRepository;
- private readonly IRealtimeService _realtimeService;
- public TelDomainService(
- IDeviceManager deviceManager,
- ITelRepository telRepository,
- ITelRestRepository telRestRepository,
- ITelHoldRepository telHoldRepository,
- IRealtimeService realtimeService)
- {
- _deviceManager = deviceManager;
- _telRepository = telRepository;
- _telRestRepository = telRestRepository;
- _telHoldRepository = telHoldRepository;
- _realtimeService = realtimeService;
- }
- /// <summary>
- /// 查询所有分机
- /// </summary>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public Task<List<Tel>> QueryTelsAsync(CancellationToken cancellationToken)
- => _deviceManager.QueryTelsAsync(cancellationToken);
- /// <summary>
- /// 查询所有分机组
- /// </summary>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public Task<List<TelGroup>> QueryTelGroupsAsync(CancellationToken cancellationToken)
- => _deviceManager.QueryTelGroupsAsync(cancellationToken);
- /// <summary>
- /// 分机休息
- /// </summary>
- /// <param name="currentWork"></param>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public async Task<string> RestAsync(Work currentWork,string reason,bool isApply, CancellationToken cancellationToken)
- {
- var isResting = await _telRepository.IsRestingAsync(currentWork.TelNo, cancellationToken);
- if (!isResting)
- {
- await _deviceManager.TelRestAsync(currentWork.TelNo, cancellationToken);
-
- return await _telRestRepository.AddAsync(new TelRest(currentWork.TelId, currentWork.TelNo, currentWork.UserId, currentWork.UserName,reason, isApply),
- cancellationToken);
- }
- throw new UserFriendlyException("当前坐席正在休息");
- }
- /// <summary>
- /// 分机审批通过
- /// </summary>
- /// <param name="id"></param>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public async Task RestApplyPass(string id, CancellationToken cancellationToken)
- {
- var telrest = await _telRestRepository.GetAsync(id, cancellationToken);
- if(telrest!=null)
- {
- telrest.ApplyStatus = Share.Enums.Order.ERestApplyStatus.Resting;
- telrest.StartTime = DateTime.Now;
- await _telRestRepository.UpdateAsync(telrest, cancellationToken);
- //通知前端休息通过
- await _realtimeService.RestApplyPassAsync(telrest.UserId, cancellationToken);
- }
- }
- /// <summary>
- /// 分机结束休息
- /// </summary>
- /// <param name="telId"></param>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public async Task<TelRest> UnRestAsync(string telId, CancellationToken cancellationToken)
- {
- var tel = await _telRepository.GetAsync(telId, cancellationToken);
- if (tel is null)
- throw new UserFriendlyException("无效分机编号");
- await _deviceManager.TelEndRestAsync(tel.No, cancellationToken);
- var restingTel = await _telRestRepository.GetAsync(d => d.TelId == telId && !d.EndTime.HasValue, cancellationToken);
- if (restingTel is null)
- throw new UserFriendlyException("未查询到分机休息信息");
- restingTel.EndRest();
- await _telRestRepository.UpdateAsync(restingTel, cancellationToken);
- return restingTel;
- }
- /// <summary>
- /// 保持通话
- /// </summary>
- /// <param name="telId"></param>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public async Task HoldAsync(string telId,string userId,string userName,string callId, CancellationToken cancellationToken)
- {
- var isHolding = await _telHoldRepository.IsHoldingAsync(telId, userId, callId, cancellationToken);
- if (!isHolding)
- {
- var tel = await _telRepository.GetAsync(telId, cancellationToken);
- if (tel is null)
- throw new UserFriendlyException("无效分机编号");
- await _deviceManager.HoldAsync(tel.No, cancellationToken);
- await _telHoldRepository.AddAsync(new Calls.TelHold() { TelId = telId, TelNo = tel.No, UserId = userId, UserName = userName, CallId = callId }, cancellationToken);
- }
- }
- /// <summary>
- /// 恢复通话(解除hold状态)
- /// </summary>
- /// <param name="telId"></param>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public async Task UnHoldAsync(string telId,string userId,string callId, CancellationToken cancellationToken)
- {
- var tel = await _telRepository.GetAsync(telId, cancellationToken);
- if (tel is null)
- throw new UserFriendlyException("无效分机编号");
- await _deviceManager.UnHoldAsync(tel.No, cancellationToken);
- var holdingTel = await _telHoldRepository.GetAsync(d => d.TelId == telId && d.TelNo == tel.No && d.UserId == userId && d.CallId == callId && !d.EndTime.HasValue );
- if (holdingTel is null)
- throw new UserFriendlyException("未找到分机保持信息");
- holdingTel.EndHold();
- await _telHoldRepository.UpdateAsync(holdingTel, cancellationToken);
- }
- /// <summary>
- /// 开启静音
- /// </summary>
- /// <param name="telId"></param>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- /// <exception cref="UserFriendlyException"></exception>
- public async Task MuteAsync(string telId, CancellationToken cancellationToken)
- {
- var tel = await _telRepository.GetAsync(telId, cancellationToken);
- if (tel is null)
- throw new UserFriendlyException("无效分机编号");
- await _deviceManager.MuteAsync(tel.No, cancellationToken);
- }
- /// <summary>
- /// 解除静音
- /// </summary>
- /// <param name="telId"></param>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public async Task UnMuteAsync(string telId, CancellationToken cancellationToken)
- {
- var tel = await _telRepository.GetAsync(telId, cancellationToken);
- if (tel is null)
- throw new UserFriendlyException("无效分机编号");
- await _deviceManager.MuteAsync(tel.No, cancellationToken);
- }
- }
|