瀏覽代碼

telcallmodel

Dun.Jason 1 年之前
父節點
當前提交
e55ec5d5f3

+ 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);
         }
 
 

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

@@ -16,7 +16,7 @@
     }
   },
   "ConnectionStrings": {
-    "Hotline": "PORT=5432;DATABASE=hotline;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;",
+    "Hotline": "PORT=5432;DATABASE=hotline_dev;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;",
     "Redis": "110.188.24.182:50179",
     "MongoDB": "mongodb://192.168.100.121:27017",
     "Wex": "server=222.212.82.225;Port=4509;Database=fs_kft;Uid=root;Pwd=Wex@12345;"
@@ -25,7 +25,7 @@
     "Host": "110.188.24.182",
     "Port": 50179,
     //"Password": "fengwo22@@",
-    "Database": 1
+    "Database": 5
   },
   "Swagger": true,
   "Cors": {
@@ -60,7 +60,7 @@
     }
   },
   "DatabaseConfiguration": {
-    "ApplyDbMigrations": false,
+    "ApplyDbMigrations": true,
     "ApplySeed": false
   },
   "MqConfiguration": {

+ 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);
     }
 }

+ 17 - 8
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>
@@ -83,13 +86,13 @@ 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]);
                 if (IsTelNeedVerify)
                 {
@@ -109,7 +112,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 +125,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 +137,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));

+ 5 - 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; }

+ 17 - 1
src/Hotline/CallCenter/Tels/TelCallModel.cs

@@ -1,4 +1,6 @@
-using SqlSugar;
+using Hotline.Share.Enums.CallCenter;
+using SqlSugar;
+using System.Drawing;
 using XF.Domain.Repository;
 
 namespace Hotline.CallCenter.Tels
@@ -44,6 +46,20 @@ namespace Hotline.CallCenter.Tels
         [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;
+        }
     }
 }