Dun.Jason 1 year ago
parent
commit
5c0010ad13

+ 7 - 4
src/Hotline.Api/Controllers/IPPbxController.cs

@@ -1,4 +1,5 @@
-using Hotline.CallCenter.Calls;
+using Hotline.Application.CallCenter.Calls;
+using Hotline.CallCenter.Calls;
 using Hotline.Permissions;
 using Hotline.Share.Dtos.TrCallCenter;
 using Hotline.Users;
@@ -20,14 +21,15 @@ namespace Hotline.Api.Controllers
         private readonly IUserDomainService _userDomainService;
         private readonly ISessionContext _sessionContext;
         private readonly IRepository<TrCallRecord> _trCallRecordRepository;
-
-        public IPPbxController(ITrClient trClient,IMapper mapper,IUserDomainService userDomainService,ISessionContext sessionContext,IRepository<TrCallRecord> trCallRecordRepository)
+        private readonly ITrApplication _trApplication;
+        public IPPbxController(ITrClient trClient,IMapper mapper,IUserDomainService userDomainService,ISessionContext sessionContext,IRepository<TrCallRecord> trCallRecordRepository,ITrApplication trApplication)
         {
             _trClient = trClient;
             _mapper = mapper;
             _userDomainService = userDomainService;
             _sessionContext = sessionContext;
             _trCallRecordRepository = trCallRecordRepository;
+            _trApplication = trApplication;
         }
 
         #region 添添呼
@@ -98,7 +100,8 @@ namespace Hotline.Api.Controllers
         [HttpPost("on-duty")]
         public async Task<TrOnDutyResponseDto> OnDuty([FromBody] TrOnDutyDto dto)
         {
-            return await _userDomainService.TrOnDutyAsync(_sessionContext.RequiredUserId,dto.TelNo, HttpContext.RequestAborted);
+            //return await _userDomainService.TrOnDutyAsync(_sessionContext.RequiredUserId,dto.TelNo, HttpContext.RequestAborted);
+            return await _trApplication.OnSign(_sessionContext.RequiredUserId, dto.TelNo, HttpContext.RequestAborted);
         }
 
         /// <summary>

+ 18 - 5
src/Hotline.Api/Controllers/OrderController.cs

@@ -36,6 +36,7 @@ using XF.Utility.EnumExtensions;
 using Microsoft.IdentityModel.Tokens;
 using System.Linq;
 using Hotline.Share.Dtos.FlowEngine.Workflow;
+using System.Transactions;
 
 namespace Hotline.Api.Controllers;
 
@@ -614,12 +615,24 @@ public class OrderController : BaseController
 
     #region 二次回访申请
 
+    /// <summary>
+    /// 可二次回访申请列表
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [Permission(EPermission.OrderVisitAgainList)]
     [HttpGet("visitapply/visitagainlist")]
-    public async Task OrderVisitAgainList([FromQuery]OrderVisitAgainListDto dto)
-    {
-    //    await _orderVisitRepository.Queryable()
-    //        .Includes(x=>x.Order)
-    //        .Where()
+    public async Task<PagedDto<OrderCanVisitAgainDto>> OrderVisitAgainList([FromQuery]OrderVisitAgainListDto dto)
+    {
+        var (total, items) =  await _orderVisitedDetailRepository.Queryable()
+            .Includes(x => x.OrderVisit, x => x.Order)
+            .WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.OrderVisit.Order.No.Contains(dto.Keyword))
+            .Where(x => x.OrderVisit.VisitState == EVisitState.Visited && (x.OrderVisit.VisitType == EVisitType.SmsVisit || x.OrderVisit.VisitType == EVisitType.ChipVoiceVisit))
+            .Where(x => SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "1" || SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "2" )
+            .Where(x => x.VisitTarget == EVisitTarget.Org)
+            .OrderByDescending(x => x.OrderVisit.VisitTime)
+            .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
+        return new PagedDto<OrderCanVisitAgainDto>(total, _mapper.Map<IReadOnlyList<OrderCanVisitAgainDto>>(items));
     }
 
 

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

@@ -0,0 +1,14 @@
+using Hotline.Share.Dtos.TrCallCenter;
+
+namespace Hotline.Application.CallCenter.Calls
+{
+    public interface ITrApplication
+    {
+        /// <summary>
+        /// 签入
+        /// </summary>
+        /// <param name="telNo"></param>
+        /// <returns></returns>
+        Task<TrOnDutyResponseDto> OnSign(string userId,string telNo, CancellationToken cancellationToken);
+    }
+}

+ 79 - 0
src/Hotline.Application/CallCenter/Calls/TrApplication.cs

@@ -0,0 +1,79 @@
+using Hotline.Caching.Interfaces;
+using Hotline.Caching.Services;
+using Hotline.Share.Dtos.TrCallCenter;
+using Hotline.Users;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tr.Sdk;
+using XF.Domain.Authentications;
+using XF.Domain.Constants;
+using XF.Domain.Exceptions;
+
+namespace Hotline.Application.CallCenter.Calls
+{
+    public class TrApplication : ITrApplication
+    {
+        private readonly ITrClient _trClient;
+        private readonly ISessionContext _sessionContext;
+        private readonly IWorkRepository _workRepository;
+        private readonly ISystemSettingCacheManager _systemSettingCacheManager;
+        private readonly IUserCacheManager _userCacheManager;
+        public TrApplication(ITrClient trClient, ISessionContext sessionContext,IWorkRepository workRepository,ISystemSettingCacheManager systemSettingCacheManager,IUserCacheManager userCacheManager)
+        {
+            _trClient = trClient;
+            _sessionContext = sessionContext;
+            _workRepository = workRepository;
+            _systemSettingCacheManager = systemSettingCacheManager;
+            _userCacheManager = userCacheManager;
+        }
+
+        /// <summary>
+        /// 签入
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <param name="telNo"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public async Task<TrOnDutyResponseDto> OnSign(string userId,string telNo,CancellationToken cancellationToken)
+        {
+            var work = _userCacheManager.GetWorkByUserNoExp(userId);
+            if (work is not null)
+            {
+                if (work.TelNo == telNo)
+                {
+                    return new TrOnDutyResponseDto() { TelNo = work.TelNo, TelPwd = work.TelPwd, Description = work.Description };
+                }
+                else
+                {
+                    throw UserFriendlyException.SameMessage("当前用户已签入其他分机");
+                }
+            }
+
+            var telWork = _userCacheManager.GetWorkByTelNoExp(telNo);
+            if (telWork is not null)
+            {
+                throw UserFriendlyException.SameMessage("当前分机已被占用");
+            }
+
+            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);
+                await _workRepository.AddAsync(work, cancellationToken);
+                bool IsTelNeedVerify = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsTelNeedVerify).SettingValue[0]);
+                if (IsTelNeedVerify)
+                {
+                    return new TrOnDutyResponseDto() { TelNo = telNo, TelPwd = "", Description = telModel[0].Description };
+                }
+                else
+                {
+                    return new TrOnDutyResponseDto() { TelNo = telNo, TelPwd = telModel[0].Password, Description = telModel[0].Description };
+                }
+            }
+            throw UserFriendlyException.SameMessage("签入异常,未查询到对应分机信息");
+        }
+    }
+}

+ 19 - 0
src/Hotline.Share/Dtos/Order/QueryOrderDto.cs

@@ -536,6 +536,25 @@ namespace Hotline.Share.Dtos.Order
         public bool IsPass { get; set; }
     }
 
+    public class OrderCanVisitAgainDto
+    {
+        public OrderVisitDto OrderVisit { get; set; }
+
+        /// <summary>
+        /// 部门办件结果
+        /// </summary>
+        public Kv? OrgProcessingResults { get; set; }
+
+        /// <summary>
+        /// 不满意原因
+        /// </summary>
+        public List<Kv>? OrgNoSatisfiedReason { get; set; }
+
+        /// <summary>
+        /// 回访部门名称
+        /// </summary>
+        public string VisitOrgName { get; set; }
+    }
 
     public class VisitApplyDto
     {

+ 5 - 0
src/Hotline/Orders/OrderVisit.cs

@@ -87,4 +87,9 @@ public class OrderVisit : CreationEntity
     [SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true)]
     public Kv? NowEvaluate { get; set; }
 
+    /// <summary>
+    /// 是否可以处理
+    /// </summary>
+    public bool IsCanHandle { get; set; }
+
 }

+ 11 - 5
src/Hotline/Permissions/EPermission.cs

@@ -1527,13 +1527,19 @@ namespace Hotline.Permissions
         /// </summary>
         [Display(GroupName = "ExaminOrderVisit",Name ="二次回访审核",Description = "二次回访审核")]
         ExaminOrderVisit = 501803,
+
+        /// <summary>
+        /// 可申请二次回访列表
+        /// </summary>
+        [Display(GroupName = "OrderVisitAgainList",Name = "可申请二次回访列表",Description = "可申请二次回访列表")]
+        OrderVisitAgainList = 501804,
         #endregion
 
-		#region 工单退回管理
-		/// <summary>
-		///工单退回列表
-		/// </summary>
-		[Display(GroupName = "OrderSendBack", Name = "工单退回列表", Description = "工单退回列表")]
+        #region 工单退回管理
+        /// <summary>
+        ///工单退回列表
+        /// </summary>
+        [Display(GroupName = "OrderSendBack", Name = "工单退回列表", Description = "工单退回列表")]
 		SendBackOrderList = 501900,
 
 		/// <summary>

+ 2 - 1
src/Hotline/Users/UserDomainService.cs

@@ -26,6 +26,7 @@ namespace Hotline.Users
         private readonly IMapper _mapper;
         private readonly ISystemSettingCacheManager _systemSettingCacheManager;
         private readonly ISessionContext _sessionContext;
+       
 
         public UserDomainService(
             IRepository<User> userRepository,
@@ -150,7 +151,7 @@ namespace Hotline.Users
             bool IsTelNeedVerify = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsTelNeedVerify).SettingValue[0]);
 
             //var telModel = await _trClient.QueryTelsAsync(new Tr.Sdk.Tels.QueryTelRequest() { TelNo = telNo }, cancellationToken);
-            //if (telModel!=null && telModel.Count>0)
+            //if (telModel != null && telModel.Count > 0)
             //{
             //    work = new Work(userId, _sessionContext.UserName, telModel[0].Id, telNo, telModel[0].Password, telModel[0].Description);
             //    await _workRepository.AddAsync(work, cancellationToken);

+ 1 - 0
src/Tr.Sdk/Tr.Sdk.csproj

@@ -8,6 +8,7 @@
 
   <ItemGroup>
     <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
+    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
     <PackageReference Include="RestSharp" Version="110.2.0" />
   </ItemGroup>
 

+ 2 - 0
src/Tr.Sdk/TrClient.cs

@@ -1,5 +1,6 @@
 using System.Net.Http.Json;
 using System.Text.Json;
+using Microsoft.Extensions.Logging;
 using RestSharp;
 
 namespace Tr.Sdk;
@@ -15,6 +16,7 @@ public class TrClient : ITrClient, IDisposable
             Authenticator = new TrAuthenticator(baseUrl, apiKey, apiSecret)
         };
         _client = new RestClient(options);
+       
     }
 
     /// <summary>