xf 9 mēneši atpakaļ
vecāks
revīzija
d042bedeb5

+ 7 - 2
src/Hotline.Api/Controllers/OrderController.cs

@@ -56,6 +56,7 @@ using Org.BouncyCastle.Utilities;
 using SqlSugar;
 using StackExchange.Redis;
 using System.Diagnostics.Tracing;
+using Hotline.Application.CallCenter;
 using XF.Domain.Authentications;
 using XF.Domain.Cache;
 using XF.Domain.Constants;
@@ -125,6 +126,7 @@ public class OrderController : BaseController
     private readonly IRepository<OrderCopy> _orderCopyRepository;
     private readonly IRepository<ExternalCitizens> _externalCitizensRepository;
     private readonly IRepository<OrderModifyingRecords> _orderModifyingRecordsRepository;
+    private readonly ICallApplication _callApplication;
 
     public OrderController(
         IOrderDomainService orderDomainService,
@@ -166,7 +168,7 @@ public class OrderController : BaseController
         IRepository<OrderSendBack> orderSendBackRepository,
         IRepository<OrderSpecial> orderSpecialRepository,
         IRepository<WorkflowTrace> workflowTraceRepository,
-        IRepository<TrCallRecord> trCallRecordRepository,
+        //IRepository<TrCallRecord> trCallRecordRepository,
         IOrderApplication orderApplication,
         IEnterpriseService enterpriseService,
         IPushDomainService pushDomainService,
@@ -180,7 +182,8 @@ public class OrderController : BaseController
         IOrderSecondaryHandlingApplication orderSecondaryHandlingApplication,
         IRepository<OrderCopy> orderCopyRepository,
         IRepository<ExternalCitizens> externalCitizensRepository,
-        IRepository<OrderModifyingRecords> orderModifyingRecordsRepository
+        IRepository<OrderModifyingRecords> orderModifyingRecordsRepository,
+        ICallApplication callApplication
         )
     {
         _orderDomainService = orderDomainService;
@@ -237,6 +240,7 @@ public class OrderController : BaseController
         _orderCopyRepository = orderCopyRepository;
         _externalCitizensRepository = externalCitizensRepository;
         _orderModifyingRecordsRepository = orderModifyingRecordsRepository;
+        _callApplication = callApplication;
     }
 
     #region 工单发布
@@ -2570,6 +2574,7 @@ public class OrderController : BaseController
 
         if (!string.IsNullOrEmpty(dto.CallId))
         {
+            
             var exists = await _orderRepository.AnyAsync(d => d.CallId == dto.CallId, HttpContext.RequestAborted);
             if (exists)
                 throw UserFriendlyException.SameMessage("来电已保存工单");

+ 2 - 0
src/Hotline.Api/StartupExtensions.cs

@@ -25,6 +25,7 @@ using Hotline.Share.Dtos.SendSms;
 using Hotline.Wex;
 using Hotline.Application.CallCenter.Calls;
 using Hotline.Application.CallCenter;
+using Hotline.CallCenter.Calls;
 
 namespace Hotline.Api;
 
@@ -124,6 +125,7 @@ internal static class StartupExtensions
             case "XingTang":
                 services.AddXingTangDb(callCenterConfiguration.XingTang)
                     .AddScoped<ICallApplication, XingTangCallApplication>()
+                    .AddScoped<CallIdManager>()
                     ;
                 break;
             default:

+ 5 - 0
src/Hotline.Application/CallCenter/ICallApplication.cs

@@ -60,5 +60,10 @@ namespace Hotline.Application.CallCenter
         /// </summary>
         Task<IReadOnlyList<TelOperation>> QueryTelOperationsAsync(QueryTelOperationsFixedDto dto,
             CancellationToken cancellationToken);
+
+        /// <summary>
+        /// 依据通话记录编号获取映射后的callId
+        /// </summary>
+        Task<string> GetOrSetCallIdAsync(string callNo, CancellationToken cancellationToken);
     }
 }

+ 34 - 2
src/Hotline.Application/CallCenter/XingTangCallApplication.cs

@@ -21,6 +21,7 @@ using Hotline.Share.Enums.CallCenter;
 using Hotline.Users;
 using MapsterMapper;
 using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Logging;
 using XF.Domain.Authentications;
 using XF.Domain.Cache;
 using XF.Domain.Exceptions;
@@ -28,7 +29,7 @@ using XF.Domain.Repository;
 
 namespace Hotline.Application.CallCenter
 {
-    public class XingTangCallApplication : DefaultCallApplication, ICallApplication
+    public class XingTangCallApplication : ICallApplication
     {
         private readonly IRepository<Tel> _telRepository;
         private readonly IRepository<TelGroup> _telGroupRepository;
@@ -36,10 +37,12 @@ namespace Hotline.Application.CallCenter
         private readonly ITelRestRepository _telRestRepository;
         private readonly IRepository<CallNative> _callNativeRepository;
         private readonly IRepository<TelOperation> _teloperationRepository;
+        private readonly IRepository<CallidRelation> _callidRelationRepository;
         private readonly ITypedCache<Work> _cacheWork;
         private readonly IUserCacheManager _userCacheManager;
         private readonly ISessionContext _sessionContext;
         private readonly IMapper _mapper;
+        private readonly ILogger<XingTangCallApplication> _logger;
 
         public XingTangCallApplication(
             IRepository<Tel> telRepository,
@@ -48,10 +51,12 @@ namespace Hotline.Application.CallCenter
             ITelRestRepository telRestRepository,
             IRepository<CallNative> callNativeRepository,
             IRepository<TelOperation> teloperationRepository,
+            IRepository<CallidRelation> callidRelationRepository,
             ITypedCache<Work> cacheWork,
             IUserCacheManager userCacheManager,
             ISessionContext sessionContext,
-            IMapper mapper)
+            IMapper mapper,
+            ILogger<XingTangCallApplication> logger)
         {
             _telRepository = telRepository;
             _telGroupRepository = telGroupRepository;
@@ -59,10 +64,12 @@ namespace Hotline.Application.CallCenter
             _telRestRepository = telRestRepository;
             _callNativeRepository = callNativeRepository;
             _teloperationRepository = teloperationRepository;
+            _callidRelationRepository = callidRelationRepository;
             _cacheWork = cacheWork;
             _userCacheManager = userCacheManager;
             _sessionContext = sessionContext;
             _mapper = mapper;
+            _logger = logger;
         }
 
         /// <summary>
@@ -230,6 +237,31 @@ namespace Hotline.Application.CallCenter
                 .WhereIF(dto.OperateState != null, d => d.OperateState == dto.OperateState)
                 .ToFixedListAsync(dto, cancellationToken);
         }
+
+        /// <summary>
+        /// 依据通话记录编号获取映射后的callId
+        /// </summary>
+        public async Task<string> GetOrSetCallIdAsync(string callNo, CancellationToken cancellationToken)
+        {
+            var callOrder = await _callidRelationRepository.GetAsync(callNo, cancellationToken);
+            if (callOrder == null)
+            {
+                callOrder = new CallidRelation
+                {
+                    Id = callNo,
+                    CallId = Ulid.NewUlid().ToString(),
+                };
+                try
+                {
+                    await _callidRelationRepository.AddAsync(callOrder, cancellationToken);
+                }
+                catch (Exception e)
+                {
+                    _logger.LogError($"写入callidRelation失败:{e.Message}");
+                }
+            }
+            return callOrder.CallId;
+        }
     }
 
 }

+ 32 - 2
src/Hotline/CallCenter/Calls/CallIdManager.cs

@@ -3,6 +3,8 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using Microsoft.Extensions.Logging;
+using XF.Domain.Repository;
 
 namespace Hotline.CallCenter.Calls
 {
@@ -11,9 +13,37 @@ namespace Hotline.CallCenter.Calls
     /// </summary>
     public class CallIdManager
     {
-        public async Task<string> GetOrSetAsync(string callNo)
+        private readonly IRepository<CallidRelation> _callorderRepository;
+        private readonly ILogger<CallIdManager> _logger;
+
+        public CallIdManager(
+            IRepository<CallidRelation> callorderRepository,
+            ILogger<CallIdManager> logger)
+        {
+            _callorderRepository = callorderRepository;
+            _logger = logger;
+        }
+
+        public async Task<string> GetOrSetAsync(string callNo, CancellationToken cancellationToken)
         {
-            //1. 查看db 2.t: return f: new ulid() insert return
+            var callOrder = await _callorderRepository.GetAsync(callNo, cancellationToken);
+            if (callOrder == null)
+            {
+                callOrder = new CallidRelation
+                {
+                    Id = callNo,
+                    CallId = Ulid.NewUlid().ToString(),
+                };
+                try
+                {
+                    await _callorderRepository.AddAsync(callOrder, cancellationToken);
+                }
+                catch (Exception e)
+                {
+                    _logger.LogError($"写入callidRelation失败:{e.Message}");
+                }
+            }
+            return callOrder.CallId;
         }
     }
 }

+ 6 - 5
src/Hotline/CallCenter/Calls/CallOrderRelation.cs → src/Hotline/CallCenter/Calls/CallidRelation.cs

@@ -9,7 +9,10 @@ using XF.Domain.Repository;
 
 namespace Hotline.CallCenter.Calls
 {
-    public class CallOrderRelation //: IHasCreationTime, ITable
+    /// <summary>
+    /// callId与callNo关系
+    /// </summary>
+    public class CallidRelation : IEntity<string>, IHasCreationTime, ITable
     {
         /// <summary>
         /// 创建时间
@@ -17,12 +20,10 @@ namespace Hotline.CallCenter.Calls
         public DateTime CreationTime { get; }
 
         /// <summary>
-        /// 呼叫中心通话记录编号
+        /// 呼叫中心通话记录编号(CallNo)
         /// </summary>
+        public string Id { get; set; }
         
-        public string CallNo { get; set; }
-
         public string CallId { get; set; }
-        public string OrderId { get; set; }
     }
 }

+ 0 - 1
src/Hotline/Hotline.csproj

@@ -14,7 +14,6 @@
     <PackageReference Include="MiniExcel" Version="1.31.3" />
     <PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
     <PackageReference Include="RestSharp" Version="110.2.0" />
-    <PackageReference Include="Ulid" Version="1.3.3" />
     <PackageReference Include="XF.Utility.MQ" Version="1.0.9" />
   </ItemGroup>
 

+ 1 - 0
src/XF.Domain/XF.Domain.csproj

@@ -16,6 +16,7 @@
     <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
     <PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
     <PackageReference Include="Serilog.Enrichers.Span" Version="2.3.0" />
+    <PackageReference Include="Ulid" Version="1.3.3" />
     <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.25.1" />
   </ItemGroup>