Browse Source

Merge branch 'dev_dss' of Fengwo/hotline into dev

dengshengshuang 1 year ago
parent
commit
45ce68342e

+ 3 - 3
src/Hotline.Api/Controllers/IPPbxController.cs

@@ -190,7 +190,7 @@ namespace Hotline.Api.Controllers
         [HttpGet("tel-state")]
         public async Task<TrOnDutyResponseDto> TelState()
         {
-            return await _trApplication.TelState(_sessionContext.RequiredUserId);
+            return await _trApplication.TelState(_sessionContext.RequiredUserId,HttpContext.RequestAborted);
         }
 
 
@@ -201,9 +201,9 @@ namespace Hotline.Api.Controllers
         /// <param name="isCallOut"></param>
         /// <returns></returns>
         [HttpPost("change-telmodel")]
-        public async Task ChangeTelModel([FromBody]bool isCallOut)
+        public async Task ChangeTelModel([FromBody] ChangeTelModelDto dto)
         {
-            await _trApplication.ChangeTelModel(_sessionContext.RequiredUserId, isCallOut);
+            await _trApplication.ChangeTelModel(_sessionContext.RequiredUserId, dto.isCallOut,HttpContext.RequestAborted);
         }
 
 

+ 1 - 1
src/Hotline.Api/config/appsettings.Development.json

@@ -25,7 +25,7 @@
     "Host": "110.188.24.182",
     "Port": 50179,
     //"Password": "fengwo22@@",
-    "Database": 1
+    "Database": 5
   },
   "Swagger": true,
   "Cors": {

+ 2 - 2
src/Hotline.Application/CallCenter/Calls/ITrApplication.cs

@@ -16,7 +16,7 @@ namespace Hotline.Application.CallCenter.Calls
         /// </summary>
         /// <param name="userId"></param>
         /// <returns></returns>
-        Task<TrOnDutyResponseDto> TelState(string userId);
+        Task<TrOnDutyResponseDto> TelState(string userId, CancellationToken cancellationToken);
 
 
         /// <summary>
@@ -25,6 +25,6 @@ namespace Hotline.Application.CallCenter.Calls
         /// <param name="userId"></param>
         /// <param name="isCallOut"></param>
         /// <returns></returns>
-        Task ChangeTelModel(string userId, bool isCallOut);
+        Task ChangeTelModel(string userId, bool isCallOut, CancellationToken cancellationToken);
     }
 }

+ 24 - 12
src/Hotline.Application/CallCenter/Calls/TrApplication.cs

@@ -4,6 +4,7 @@ using Hotline.Share.Dtos.CallCenter;
 using Hotline.Share.Dtos.TrCallCenter;
 using Hotline.Share.Enums.CallCenter;
 using Hotline.Users;
+using Microsoft.AspNetCore.Http;
 using Tr.Sdk;
 using XF.Domain.Authentications;
 using XF.Domain.Cache;
@@ -23,8 +24,9 @@ namespace Hotline.Application.CallCenter.Calls
         private readonly IUserCacheManager _userCacheManager;
         private readonly ITelRestRepository _telRestRepository;
         private readonly ITypedCache<Work> _cacheWork;
+        private readonly IRepository<TelCallModel> _telCallModelRepository;
 
-        public TrApplication(ITrClient trClient, ISessionContext sessionContext,IWorkRepository workRepository,ISystemSettingCacheManager systemSettingCacheManager,IUserCacheManager userCacheManager, ITelRestRepository telRestRepository, ITypedCache<Work> cacheWork)
+        public TrApplication(ITrClient trClient, ISessionContext sessionContext,IWorkRepository workRepository,ISystemSettingCacheManager systemSettingCacheManager,IUserCacheManager userCacheManager, ITelRestRepository telRestRepository, ITypedCache<Work> cacheWork,IRepository<TelCallModel> telCallModelRepository)
         {
             _trClient = trClient;
             _sessionContext = sessionContext;
@@ -33,6 +35,7 @@ namespace Hotline.Application.CallCenter.Calls
             _userCacheManager = userCacheManager;
             _telRestRepository = telRestRepository;
             _cacheWork = cacheWork;
+            _telCallModelRepository = telCallModelRepository;
         }
 
         /// <summary>
@@ -66,13 +69,14 @@ namespace Hotline.Application.CallCenter.Calls
                 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]);
+                string callOutQueueId = _systemSettingCacheManager.GetSetting(SettingConstants.CallOutQueueId).SettingValue[0];
                 if (IsTelNeedVerify)
                 {
-                    return new TrOnDutyResponseDto() { TelNo = telNo, TelPwd = "", Description = telModel[0].Description, QueueId = telModel[0].QueueId,StartTime = work.StartTime};
+                    return new TrOnDutyResponseDto() { QueueCallOut = callOutQueueId, TelNo = telNo, TelPwd = "", Description = telModel[0].Description, QueueId = telModel[0].QueueId,StartTime = work.StartTime};
                 }
                 else
                 {
-                    return new TrOnDutyResponseDto() { TelNo = telNo, TelPwd = telModel[0].Password, Description = telModel[0].Description, QueueId = telModel[0].QueueId,StartTime = work.StartTime };
+                    return new TrOnDutyResponseDto() { QueueCallOut = callOutQueueId, TelNo = telNo, TelPwd = telModel[0].Password, Description = telModel[0].Description, QueueId = telModel[0].QueueId,StartTime = work.StartTime };
                 }
             }
             throw UserFriendlyException.SameMessage("签入异常,未查询到对应分机信息");
@@ -83,21 +87,23 @@ namespace Hotline.Application.CallCenter.Calls
         /// </summary>
         /// <param name="userId"></param>
         /// <returns></returns>
-        public async Task<TrOnDutyResponseDto> TelState(string userId)
+        public async Task<TrOnDutyResponseDto> TelState(string userId, CancellationToken cancellationToken)
         {
             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 isRest = await _telRestRepository.AnyAsync(x => x.TelNo == work.TelNo && x.UserId == userId && !x.EndTime.HasValue,cancellationToken);
+                
                 bool IsTelNeedVerify = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsTelNeedVerify).SettingValue[0]);
+                string callOutQueueId = _systemSettingCacheManager.GetSetting(SettingConstants.CallOutQueueId).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 };
+                    return new TrOnDutyResponseDto() { QueueCallOut= callOutQueueId, 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 new TrOnDutyResponseDto() { QueueCallOut = callOutQueueId, TelNo = work.TelNo, TelPwd = work.TelPwd, Description = work.Description, QueueId = work.QueueId, StartTime = work.StartTime, IsRest = isRest, TelModel = work.TelModel };
                 }
                
             }
@@ -109,7 +115,7 @@ namespace Hotline.Application.CallCenter.Calls
         /// </summary>
         /// <param name="userId"></param>
         /// <returns></returns>
-        public async Task ChangeTelModel(string userId,bool isCallOut)
+        public async Task ChangeTelModel(string userId,bool isCallOut, CancellationToken cancellationToken)
         {
             var work = _userCacheManager.GetWorkByUserNoExp(userId);
             if (work!=null)
@@ -122,9 +128,9 @@ namespace Hotline.Application.CallCenter.Calls
                         throw UserFriendlyException.SameMessage("已是外呼模式,无需切换");
                     }
                     work.TelModel = ETelModel.CallOutModel;
-                    await _workRepository.UpdateAsync(work);
-                    _cacheWork.Remove(work.GetKey(KeyMode.UserId));
-                    _cacheWork.Remove(work.GetKey(KeyMode.TelNo));
+                    await _workRepository.UpdateAsync(work, cancellationToken);
+                    var telCallModel = new TelCallModel(work.TelId,work.TelNo,userId,work.UserName);
+                    await _telCallModelRepository.AddAsync(telCallModel,cancellationToken);
                 }
                 else
                 {
@@ -134,7 +140,13 @@ namespace Hotline.Application.CallCenter.Calls
                         throw UserFriendlyException.SameMessage("已是普通模式,无需切换");
                     }
                     work.TelModel = ETelModel.OrdinaryModel;
-                    await _workRepository.UpdateAsync(work);
+                    await _workRepository.UpdateAsync(work, cancellationToken);
+                    var telCallModel = await _telCallModelRepository.GetAsync(x => x.TelNo == work.TelNo && !x.EndTime.HasValue, cancellationToken);
+                    if (telCallModel!=null)
+                    {
+                        telCallModel.EndCallOut();
+                        await _telCallModelRepository.UpdateAsync(telCallModel, cancellationToken);
+                    }
                 }
                 _cacheWork.Remove(work.GetKey(KeyMode.UserId));
                 _cacheWork.Remove(work.GetKey(KeyMode.TelNo));

+ 1 - 2
src/Hotline.Repository.SqlSugar/System/SystemOrganizeRepository.cs

@@ -31,10 +31,9 @@ namespace Hotline.Repository.SqlSugar.System
 
         public async Task<IReadOnlyList<SystemOrganize>> GetCanUseOrgByOrgCode(string orgCode)
         {
-            //orgCode = orgCode.Substring(0, orgCode.Length - 3);
             var list = await Db.Queryable<SystemOrganize>()
                  .Where(it => it.Id.StartsWith(orgCode))
-                .ToTreeAsync(it => it.Children, it => it.ParentId, orgCode);
+                .ToTreeAsync(it => it.Children, it => it.ParentId, orgCode.Substring(0, orgCode.Length - 3));
             return list;
         }
 

+ 7 - 0
src/Hotline.Share/Dtos/TrCallCenter/TrTelDao.cs

@@ -168,6 +168,11 @@ namespace Hotline.Share.Dtos.TrCallCenter
         public string? TelNo { get; set; }
     }
 
+    public class ChangeTelModelDto
+    {
+        public bool isCallOut { get; set; }
+    }
+
     public class TrOnDutyResponseDto
     {
         public string? TelNo { get; set; }
@@ -177,6 +182,8 @@ namespace Hotline.Share.Dtos.TrCallCenter
         public string? Description { get; set; }
         public string? QueueId { get; set; }
 
+        public string? QueueCallOut { get; set; }
+
         public DateTime StartTime { get; set; }
 
         public bool? IsRest { get; set; }

+ 65 - 0
src/Hotline/CallCenter/Tels/TelCallModel.cs

@@ -0,0 +1,65 @@
+using Hotline.Share.Enums.CallCenter;
+using SqlSugar;
+using System.Drawing;
+using XF.Domain.Repository;
+
+namespace Hotline.CallCenter.Tels
+{
+    public class TelCallModel: CreationEntity
+    {
+        /// <summary>
+        /// 分机id
+        /// </summary>
+        public string? TelId { get; set; }
+
+        /// <summary>
+        /// 分机号(冗余)
+        /// </summary>
+        public string TelNo { get; set; }
+
+        /// <summary>
+        /// 用户id
+        /// </summary>
+        public string UserId { get; set; }
+
+        /// <summary>
+        /// 用户名称(冗余)
+        /// </summary>
+
+        public string UserName { get; set; }
+
+        /// <summary>
+        /// 开始外呼状态时间
+        /// </summary>
+        [SugarColumn(ColumnDescription = "开始外呼状态时间")]
+        public DateTime? StartTime { get; set; }
+
+        /// <summary>
+        /// 结束外呼状态时间
+        /// </summary>
+        [SugarColumn(ColumnDescription = "结束外呼状态时间")]
+        public DateTime? EndTime { get; private set; }
+
+        /// <summary>
+        /// 外呼状态时长(单位:秒)
+        /// </summary>
+        [SugarColumn(ColumnDescription = "外呼状态时长(单位:秒)")]
+        public double RestDuration { get; private set; }
+
+        public TelCallModel(string telId, string telNo, string userId, string userName)
+        {
+            TelId = telId; TelNo = telNo; UserId = userId; UserName = userName; StartTime = DateTime.Now;
+        }
+
+        public TelCallModel()
+        {
+                
+        }
+
+        public void EndCallOut()
+        {
+            EndTime = DateTime.Now;
+            RestDuration = (EndTime.Value - StartTime.Value).TotalSeconds;
+        }
+    }
+}

+ 5 - 0
src/XF.Domain/Constants/SettingConstants.cs

@@ -211,5 +211,10 @@ namespace XF.Domain.Constants
         /// 行政执法大屏工单数据推送间隔
         /// </summary>
         public const string EnforcementDataOrderChangedTimes = "EnforcementDataOrderChangedTimes";
+
+        /// <summary>
+        /// 外呼分机组号
+        /// </summary>
+        public const string CallOutQueueId = "CallOutQueueId";
     }
 }