|
@@ -27,6 +27,7 @@ using Microsoft.AspNetCore.Authorization;
|
|
|
using Hotline.Share.Dtos.Order;
|
|
|
using Hotline.Tools;
|
|
|
using XF.Domain.Authentications;
|
|
|
+using Hotline.Caching.Services;
|
|
|
|
|
|
namespace Hotline.Api.Controllers
|
|
|
{
|
|
@@ -37,7 +38,10 @@ namespace Hotline.Api.Controllers
|
|
|
private readonly IMapper _mapper;
|
|
|
private readonly IOptionsSnapshot<CallCenterConfiguration> _callcenterOptions;
|
|
|
private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
- private readonly IRepository<TelOperationXthx> _telOperationXthxRepository;
|
|
|
+ private readonly IRepository<TelOperationXthx> _telOperationXthxRepository;
|
|
|
+ private readonly IUserCacheManager _userCacheManager;
|
|
|
+ private readonly ISessionContext _sessionContext;
|
|
|
+ private readonly IRepository<TelActionRecord> _telActionRecordRepository;
|
|
|
|
|
|
public CallController(
|
|
|
ICallApplication callApplication,
|
|
@@ -45,7 +49,10 @@ namespace Hotline.Api.Controllers
|
|
|
IMapper mapper,
|
|
|
IOptionsSnapshot<CallCenterConfiguration> callcenterOptions,
|
|
|
ISystemSettingCacheManager systemSettingCacheManager,
|
|
|
- IRepository<TelOperationXthx> telOperationXthxRepository)
|
|
|
+ IRepository<TelOperationXthx> telOperationXthxRepository,
|
|
|
+ IUserCacheManager userCacheManager,
|
|
|
+ ISessionContext sessionContext,
|
|
|
+ IRepository<TelActionRecord> telActionRecordRepository)
|
|
|
{
|
|
|
_callApplication = callApplication;
|
|
|
_publisher = publisher;
|
|
@@ -53,6 +60,9 @@ namespace Hotline.Api.Controllers
|
|
|
_callcenterOptions = callcenterOptions;
|
|
|
_systemSettingCacheManager = systemSettingCacheManager;
|
|
|
_telOperationXthxRepository = telOperationXthxRepository;
|
|
|
+ _userCacheManager = userCacheManager;
|
|
|
+ _sessionContext = sessionContext;
|
|
|
+ _telActionRecordRepository = telActionRecordRepository;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -115,6 +125,106 @@ namespace Hotline.Api.Controllers
|
|
|
public Task SignOut(string telNo)
|
|
|
=> _callApplication.SingOutAsync(telNo, HttpContext.RequestAborted);
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 分机动作开始
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("call-action-record-begin")]
|
|
|
+ public async Task CallActionRecordBegin(int actionType)
|
|
|
+ {
|
|
|
+ var work = _userCacheManager.GetWorkByUser(_sessionContext.RequiredUserId);
|
|
|
+
|
|
|
+ if (work is null)
|
|
|
+ throw UserFriendlyException.SameMessage("分机未签入,不能操作");
|
|
|
+
|
|
|
+ if (actionType == 0)//小休
|
|
|
+ {
|
|
|
+ var isResting = await _telActionRecordRepository.AnyAsync(x => x.TelNo == work.TelNo && x.ActionType == EActionType.TelRest && !x.EndTime.HasValue, HttpContext.RequestAborted);
|
|
|
+ if (isResting)
|
|
|
+ throw UserFriendlyException.SameMessage("当前坐席正在休息");
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var telAction = new TelActionRecord(work.UserId, work.UserName, work.TelNo, work.QueueId, EActionType.TelRest);
|
|
|
+ await _telActionRecordRepository.AddAsync(telAction, HttpContext.RequestAborted);
|
|
|
+ work.OldExtensionStatus = work.ExtensionStatus;
|
|
|
+ work.ExtensionStatus = EExtensionStatus.TelRest;
|
|
|
+ _userCacheManager.SetWorkByUser(work);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断如果已经存在未结束的该动作就不新增
|
|
|
+ var ishas = await _telActionRecordRepository.AnyAsync(x => x.TelNo == work.TelNo && x.ActionType == (EActionType)actionType && !x.EndTime.HasValue, HttpContext.RequestAborted);
|
|
|
+ if (!ishas)
|
|
|
+ {
|
|
|
+ var telAction = new TelActionRecord(work.UserId, work.UserName, work.TelNo, work.QueueId, (EActionType)actionType);
|
|
|
+ await _telActionRecordRepository.AddAsync(telAction, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+ //动作写入成功,修改话机动作状态
|
|
|
+ work.OldExtensionStatus = work.ExtensionStatus;
|
|
|
+ switch (actionType)
|
|
|
+ {
|
|
|
+ case 1://整理
|
|
|
+ work.ExtensionStatus = EExtensionStatus.Arrange;
|
|
|
+ break;
|
|
|
+ case 2://保持
|
|
|
+ work.ExtensionStatus = EExtensionStatus.Hold;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ _userCacheManager.SetWorkByUser(work);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 分机动作结束
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("call-action-record-end")]
|
|
|
+ public async Task CallActionRecordEnd(int actionType)
|
|
|
+ {
|
|
|
+ var work = _userCacheManager.GetWorkByUser(_sessionContext.RequiredUserId);
|
|
|
+ if (work is null)
|
|
|
+ throw UserFriendlyException.SameMessage("分机未签入,不能操作");
|
|
|
+
|
|
|
+ if (actionType == 0)//小休
|
|
|
+ {
|
|
|
+ var telRest = await _telActionRecordRepository.GetAsync(x => x.TelNo == work.TelNo && x.ActionType == EActionType.TelRest && !x.EndTime.HasValue, HttpContext.RequestAborted);
|
|
|
+ if (telRest is null)
|
|
|
+ throw UserFriendlyException.SameMessage("未查询到分机休息信息");
|
|
|
+ else
|
|
|
+ {
|
|
|
+ telRest.EndAction();
|
|
|
+ await _telActionRecordRepository.UpdateAsync(telRest);
|
|
|
+ work.OldExtensionStatus = work.ExtensionStatus;
|
|
|
+ work.ExtensionStatus = EExtensionStatus.Ready;
|
|
|
+ _userCacheManager.SetWorkByUser(work);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var telAction = await _telActionRecordRepository.GetAsync(x => x.TelNo == work.TelNo && x.ActionType == (EActionType)actionType && !x.EndTime.HasValue, HttpContext.RequestAborted);
|
|
|
+ if (telAction != null)
|
|
|
+ {
|
|
|
+ telAction.EndAction();
|
|
|
+ await _telActionRecordRepository.UpdateAsync(telAction);
|
|
|
+ }
|
|
|
+ //动作结束成功,修改话机动作状态
|
|
|
+ work.OldExtensionStatus = work.ExtensionStatus;
|
|
|
+ switch (actionType)
|
|
|
+ {
|
|
|
+ case 1://整理
|
|
|
+ work.ExtensionStatus = EExtensionStatus.Arrange;
|
|
|
+ break;
|
|
|
+ case 2://保持
|
|
|
+ work.ExtensionStatus = EExtensionStatus.Hold;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ _userCacheManager.SetWorkByUser(work);
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 查询当前用户的分机状态
|
|
|
/// </summary>
|