Dun.Jason před 1 rokem
rodič
revize
0b4db1f34c

+ 25 - 0
src/Hotline.Api/Controllers/IPPbxController.cs

@@ -183,6 +183,31 @@ namespace Hotline.Api.Controllers
             await _telApplication.SignOutAsync(_sessionContext.RequiredUserId, HttpContext.RequestAborted);
         }
 
+        /// <summary>
+        /// 查询当前用户的分机状态
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("tel-state")]
+        public async Task<TrOnDutyResponseDto> TelState()
+        {
+            return await _trApplication.TelState(_sessionContext.RequiredUserId);
+        }
+
+
+        /// <summary>
+        /// 切换状态
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <param name="isCallOut"></param>
+        /// <returns></returns>
+        [HttpPost("change-telmodel")]
+        public async Task ChangeTelModel([FromBody]bool isCallOut)
+        {
+            await _trApplication.ChangeTelModel(_sessionContext.RequiredUserId, isCallOut);
+        }
+
+
+
         /// <summary>
         /// 下班-管理手动操作
         /// </summary>

+ 16 - 0
src/Hotline.Application/CallCenter/Calls/ITrApplication.cs

@@ -10,5 +10,21 @@ namespace Hotline.Application.CallCenter.Calls
         /// <param name="telNo"></param>
         /// <returns></returns>
         Task<TrOnDutyResponseDto> OnSign(string userId,string telNo, CancellationToken cancellationToken);
+
+        /// <summary>
+        /// 查询当前用户的分机状态
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        Task<TrOnDutyResponseDto> TelState(string userId);
+
+
+        /// <summary>
+        /// 切换状态
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <param name="isCallOut"></param>
+        /// <returns></returns>
+        Task ChangeTelModel(string userId, bool isCallOut);
     }
 }

+ 76 - 8
src/Hotline.Application/CallCenter/Calls/TrApplication.cs

@@ -1,9 +1,12 @@
 using Hotline.Caching.Interfaces;
 using Hotline.CallCenter.Tels;
+using Hotline.Share.Dtos.CallCenter;
 using Hotline.Share.Dtos.TrCallCenter;
+using Hotline.Share.Enums.CallCenter;
 using Hotline.Users;
 using Tr.Sdk;
 using XF.Domain.Authentications;
+using XF.Domain.Cache;
 using XF.Domain.Constants;
 using XF.Domain.Dependency;
 using XF.Domain.Exceptions;
@@ -19,7 +22,9 @@ namespace Hotline.Application.CallCenter.Calls
         private readonly ISystemSettingCacheManager _systemSettingCacheManager;
         private readonly IUserCacheManager _userCacheManager;
         private readonly ITelRestRepository _telRestRepository;
-        public TrApplication(ITrClient trClient, ISessionContext sessionContext,IWorkRepository workRepository,ISystemSettingCacheManager systemSettingCacheManager,IUserCacheManager userCacheManager, ITelRestRepository telRestRepository)
+        private readonly ITypedCache<Work> _cacheWork;
+
+        public TrApplication(ITrClient trClient, ISessionContext sessionContext,IWorkRepository workRepository,ISystemSettingCacheManager systemSettingCacheManager,IUserCacheManager userCacheManager, ITelRestRepository telRestRepository, ITypedCache<Work> cacheWork)
         {
             _trClient = trClient;
             _sessionContext = sessionContext;
@@ -27,6 +32,7 @@ namespace Hotline.Application.CallCenter.Calls
             _systemSettingCacheManager = systemSettingCacheManager;
             _userCacheManager = userCacheManager;
             _telRestRepository = telRestRepository;
+            _cacheWork = cacheWork;
         }
 
         /// <summary>
@@ -42,12 +48,7 @@ namespace Hotline.Application.CallCenter.Calls
             if (work is not null)
             {
                 
-                if (work.TelNo == telNo)
-                {
-                    bool isRest = await _telRestRepository.AnyAsync(x => x.TelNo == telNo && x.UserId == userId && !x.EndTime.HasValue);
-                    return new TrOnDutyResponseDto() { TelNo = work.TelNo, TelPwd = work.TelPwd, Description = work.Description, QueueId = work.QueueId,StartTime = work.StartTime, IsRest= isRest };
-                }
-                else
+                if (work.TelNo != telNo)
                 {
                     throw UserFriendlyException.SameMessage("当前用户已签入其他分机");
                 }
@@ -62,7 +63,7 @@ namespace Hotline.Application.CallCenter.Calls
             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, telModel[0].QueueId,_sessionContext.StaffNo);
+                work = new Work(_sessionContext.UserId, _sessionContext.UserName, telModel[0].Id, telNo, telModel[0].Password, telModel[0].Description, telModel[0].QueueId,_sessionContext.StaffNo, ETelModel.OrdinaryModel);
                 await _workRepository.AddAsync(work, cancellationToken);
                 bool IsTelNeedVerify = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsTelNeedVerify).SettingValue[0]);
                 if (IsTelNeedVerify)
@@ -76,5 +77,72 @@ namespace Hotline.Application.CallCenter.Calls
             }
             throw UserFriendlyException.SameMessage("签入异常,未查询到对应分机信息");
         }
+
+        /// <summary>
+        /// 查询当前用户的分机状态
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        public async Task<TrOnDutyResponseDto> TelState(string userId)
+        {
+            var work = _userCacheManager.GetWorkByUserNoExp(userId);
+            if (work is not null)
+            {
+                
+                bool isRest = await _telRestRepository.AnyAsync(x => x.TelNo == work.TelNo && x.UserId == userId && !x.EndTime.HasValue);
+                bool IsTelNeedVerify = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsTelNeedVerify).SettingValue[0]);
+                if (IsTelNeedVerify)
+                {
+                    return new TrOnDutyResponseDto() { TelNo = work.TelNo, TelPwd = "", Description = work.Description, QueueId = work.QueueId, StartTime = work.StartTime, IsRest = isRest, TelModel = work.TelModel };
+                }
+                else
+                {
+                    return new TrOnDutyResponseDto() { TelNo = work.TelNo, TelPwd = work.TelPwd, Description = work.Description, QueueId = work.QueueId, StartTime = work.StartTime, IsRest = isRest, TelModel = work.TelModel };
+                }
+               
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// 切换状态
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        public async Task ChangeTelModel(string userId,bool isCallOut)
+        {
+            var work = _userCacheManager.GetWorkByUserNoExp(userId);
+            if (work!=null)
+            {
+                if (isCallOut)
+                {
+                    //切换外呼模式
+                    if (work.TelModel== ETelModel.CallOutModel)
+                    {
+                        throw UserFriendlyException.SameMessage("已是外呼模式,无需切换");
+                    }
+                    work.TelModel = ETelModel.CallOutModel;
+                    await _workRepository.UpdateAsync(work);
+                    _cacheWork.Remove(work.GetKey(KeyMode.UserId));
+                    _cacheWork.Remove(work.GetKey(KeyMode.TelNo));
+                }
+                else
+                {
+                    //切换普通模式
+                    if (work.TelModel == ETelModel.OrdinaryModel)
+                    {
+                        throw UserFriendlyException.SameMessage("已是普通模式,无需切换");
+                    }
+                    work.TelModel = ETelModel.OrdinaryModel;
+                    await _workRepository.UpdateAsync(work);
+                }
+                _cacheWork.Remove(work.GetKey(KeyMode.UserId));
+                _cacheWork.Remove(work.GetKey(KeyMode.TelNo));
+            }
+            else
+            {
+                throw UserFriendlyException.SameMessage("当前用户没有签入,不能切换状态");
+            }
+        }
     }
 }

+ 7 - 3
src/Hotline.Repository.SqlSugar/CallCenter/TrCallRecordRepository.cs

@@ -66,6 +66,10 @@ namespace Hotline.Repository.SqlSugar.CallCenter
             {
                 endDate = beginDate.Date.AddDays(1).AddSeconds(-1);
             }
+            else
+            {
+                endDate = endDate.Value.Date.AddDays(1).AddSeconds(-1);
+            }
             TimeSpan timeDifference = endDate.Value.Subtract(beginDate).Duration();
 
             int hourDiff = (int)(timeDifference.TotalHours);
@@ -82,10 +86,10 @@ namespace Hotline.Repository.SqlSugar.CallCenter
             var list = await Db.Reportable(dts).ToQueryable<DateTime>()
                 .LeftJoin<TrCallRecord>((it, o) => o.CreatedTime >= it.ColumnName && o.CreatedTime < it.ColumnName.AddHours(1))
                 .Where((it, o) => o.CallDirection == ECallDirection.In)
-                .GroupBy(it => it.ColumnName)
-                .OrderBy(it => it.ColumnName)
+                .GroupBy((it,o) => it.ColumnName)
                 .Select((it, o) => new TrCallHourDto()
                 {
+                    DateTimeTo = it.ColumnName, 
                     Hour = it.ColumnName.Hour, //小时段
                     EffectiveCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.Duration >= effectiveTimes, 1, 0)),//有效接通
                     ConnectByeCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.Duration > 0 && o.Duration <= connectByeTimes, 1, 0)), //接通秒挂
@@ -98,7 +102,7 @@ namespace Hotline.Repository.SqlSugar.CallCenter
            var resultList = list.GroupBy(x => x.Hour)
                 .Select(x=> new TrCallHourDto() { 
                     Hour = x.Key,
-                    HourTo = x.Key.ToString().PadLeft(2, '0') + ":00 - " + (x.Key + 1).ToString().PadLeft(2, '0') + ":00",
+                    HourTo = x.Key.ToString().PadLeft(2, '0') + ":00 - " + (x.Key).ToString().PadLeft(2, '0') + ":59",
                     EffectiveCount = x.Sum(d=>d.EffectiveCount),
                     ConnectByeCount = x.Sum(d=>d.ConnectByeCount),
                     NoConnectByeCount = x.Sum(d=>d.NoConnectByeCount),

+ 2 - 0
src/Hotline.Share/Dtos/CallCenter/TrCallDto.cs

@@ -14,6 +14,8 @@ namespace Hotline.Share.Dtos.CallCenter
 
         public string HourTo { get; set; }
 
+        public DateTime DateTimeTo { get; set; }
+
         /// <summary>
         /// 总计
         /// </summary>

+ 1 - 1
src/Hotline.Share/Dtos/TrCallCenter/TrTelDao.cs

@@ -183,7 +183,7 @@ namespace Hotline.Share.Dtos.TrCallCenter
 
         public int Second => CalcSecond();
 
-
+        public ETelModel? TelModel { get; set; }
         public int CalcSecond()
         {
             return (int)(DateTime.Now - StartTime).TotalSeconds;

+ 18 - 0
src/Hotline.Share/Enums/CallCenter/ETelModel.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Share.Enums.CallCenter
+{
+    public enum ETelModel
+    {
+        [Description("普通模式")]
+        OrdinaryModel = 1,
+
+        [Description("呼出模式")]
+        CallOutModel = 2,
+    }
+}

+ 5 - 1
src/Hotline/Users/Work.cs

@@ -1,4 +1,5 @@
 using System.ComponentModel;
+using Hotline.Share.Enums.CallCenter;
 using SqlSugar;
 using XF.Domain.Entities;
 using XF.Domain.Repository;
@@ -49,6 +50,8 @@ public class Work : CreationModificationEntity
 
     public string? StaffNo { get; set; }
 
+    public ETelModel? TelModel {get;set;}
+
     ///// <summary>
     ///// SignalR.ConnectionId
     ///// </summary>
@@ -60,7 +63,7 @@ public class Work : CreationModificationEntity
 
     }
 
-    public Work(string userId, string name, string telId, string telNo, string? telPwd, string? description, string? queueId,string? staffNo)
+    public Work(string userId, string name, string telId, string telNo, string? telPwd, string? description, string? queueId,string? staffNo, ETelModel telModel)
     {
         StartTime = DateTime.Now;
         UserId = userId;
@@ -71,6 +74,7 @@ public class Work : CreationModificationEntity
         Description = description;
         QueueId = queueId;
         StaffNo = staffNo;
+        TelModel = telModel;
     }
 
     public Work(string userId, string name, string telId, string telNo)