using DotNetCore.CAP; using Hotline.CallCenter.BlackLists; using Hotline.CallCenter.Devices; using Hotline.CallCenter.Ivrs; using Hotline.FlowEngine.WorkflowModules; using Hotline.Identity.Roles; using Hotline.Orders; using Hotline.Realtimes; using Hotline.Repository.SqlSugar; using Hotline.Repository.SqlSugar.Ts; using Hotline.Settings.TimeLimits; using Hotline.Share.Dtos.Realtime; using Hotline.Users; using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using NewRock.Sdk; using NewRock.Sdk.Security; using SqlSugar; using Tr.Sdk; using XC.RSAUtil; using XF.Domain.Authentications; using XF.Domain.Cache; using XF.Domain.Exceptions; using XF.Domain.Filters; using XF.Domain.Locks; using XF.Domain.Repository; namespace Hotline.Api.Controllers; /// /// /// [AllowAnonymous] public class TestController : BaseController { private readonly ILogger _logger; private readonly IAuthorizeGenerator _authorizeGenerator; private readonly IOptionsSnapshot _options; private readonly ISessionContext _sessionContext; private readonly IRepository _userRepository; private readonly ITypedCache _cache; private readonly IRealtimeService _realtimeService; private readonly IBlacklistDomainService _blacklistDomainService; private readonly IIvrDomainService _ivrDomainService; private readonly ISugarUnitOfWork _uow; private readonly IRepository _roleRepository; private readonly IMediator _mediator; private readonly IDistributedLock _distributedLock; private readonly IRepository _orderUrgeRepository; private readonly IRepositoryTextSearch _repositoryts; private readonly ITimeLimitDomainService _timeLimitDomainService; private readonly IWfModuleDomainService _wfModuleDomainService; private readonly IDaySettingRepository _daySettingRepository; private readonly ITrClient _trClient; private readonly ICapPublisher _capPublisher; //private readonly ITypedCache> _cache; //private readonly ICacheManager _cache; public TestController( INewRockClient client, ILogger logger, IAuthorizeGenerator authorizeGenerator, IOptionsSnapshot options, ISessionContext sessionContext, IRepository userRepository, //ICacheManager cache //ITypedCache> cache ITypedCache cache, IRealtimeService realtimeService, IBlacklistDomainService blacklistDomainService, IIvrDomainService ivrDomainService, ISugarUnitOfWork uow, IRepository roleRepository, IMediator mediator, IDistributedLock distributedLock, IRepository orderUrgeRepository, IRepositoryTextSearch repositoryts, ITimeLimitDomainService timeLimitDomainService, IWfModuleDomainService wfModuleDomainService, IDaySettingRepository daySettingRepository, ITrClient trClient, ICapPublisher capPublisher ) { _logger = logger; _authorizeGenerator = authorizeGenerator; _options = options; _sessionContext = sessionContext; _userRepository = userRepository; _cache = cache; _realtimeService = realtimeService; _blacklistDomainService = blacklistDomainService; _ivrDomainService = ivrDomainService; _uow = uow; _roleRepository = roleRepository; _mediator = mediator; _distributedLock = distributedLock; _orderUrgeRepository = orderUrgeRepository; _repositoryts = repositoryts; _timeLimitDomainService = timeLimitDomainService; _wfModuleDomainService = wfModuleDomainService; _daySettingRepository = daySettingRepository; _trClient = trClient; _capPublisher = capPublisher; } [HttpGet("testo")] public async Task TestOrigin() { var today = DateTime.Today.ToString(); await _capPublisher.PublishAsync("test.today", today, cancellationToken: HttpContext.RequestAborted); return OpenResponse.Ok(today); } [HttpGet("time")] public async Task GetTime() { //await _repositoryts.AddVectorAsync("f595e730-909a-45e4-9138-a84bf15f4662", DateTime.Now, // new List { "xx", "bb" }, HttpContext.RequestAborted); //var result = await _repositoryts.SearchAsync(new List { "bb" }, HttpContext.RequestAborted); //await _repositoryts.UpdateVectorAsync("f595e730-909a-45e4-9138-a84bf15f4662", // new List { "ss", "bb" }, HttpContext.RequestAborted); //_uow.Db.Ado.SqlQueryAsync("SELECT to_tsvector('fat cats ate fat rats') @@ to_tsquery('fat & rat')") //var tests = _uowWex.Db.Ado.SqlQuery("select * from view_telinfo_full where IsSynch=@IsSynch", new { IsSynch = 0 }); //var a = _uowWex.Db.Ado.ExecuteCommand("update telinfo set IsSynch=1 where GUID=@CallId", new { CallId = "b1f97f3c-88b6-4f42-b8de-83ed448854b0" }); //var rsp = await _wexClient.QueryTelsAsync(new QueryTelRequest { }, HttpContext.RequestAborted); //int a = _timeLimitDomainService.CalcWorkTime(DateTime.Now, DateTime.Parse("2023-09-11 16:21:00")); //int m = _timeLimitDomainService.CalcWorkTime(DateTime.Parse("2023-09-19 12:00:00"), DateTime.Parse("2023-09-20 18:00:00"), false); //var r = _timeLimitDomainService.CalcEndTime(DateTime.Parse("2023-09-19 18:00:00"), "35", false); //await _wfModuleDomainService.PersistenceModulesAsync(HttpContext.RequestAborted); //var rsp = await _daprClient.InvokeMethodAsync>(HttpMethod.Get, "identity", "api/v1/Test/time", HttpContext.RequestAborted); //var rsp1 = await _daprClient.InvokeMethodAsync>(HttpMethod.Post, "identity", "api/v1/Test/time1", 222, HttpContext.RequestAborted); //var a = await _trClient.QueryTelsAsync(new Tr.Sdk.Tels.QueryTelRequest() { }, HttpContext.RequestAborted); await _daySettingRepository.IsWorkDay(DateTime.Now); return OpenResponse.Ok(DateTime.Now.ToString("F")); } [HttpGet("pgsql")] public async Task Pgsql() { var role = new Role { Name = $"test_role_{TimeOnly.FromDateTime(DateTime.Now)}", DisplayName = "test_role_display", ClientId = "test" }; var roleId = await _roleRepository.AddAsync(role, HttpContext.RequestAborted); role.Description = "Description"; await _roleRepository.UpdateAsync(role, HttpContext.RequestAborted); return roleId; } [AllowAnonymous] [HttpGet("roles")] public async Task> GetRoles() { using var lockManager = new LockManager(_distributedLock, $"{nameof(TestController)}.{nameof(GetRoles)}"); lockManager.InvokeInLock(() => { Console.WriteLine("do something"); }, TimeSpan.FromSeconds(10)); await lockManager.InvokeInLockAsync( d => _roleRepository.Queryable(includeDeleted: true).ToListAsync(), TimeSpan.FromSeconds(10), HttpContext.RequestAborted); var a = await _roleRepository.Queryable() //.Where(d => !d.IsDeleted) .ToListAsync(); //var a = await db.Queryable().ToListAsync(); var b = await _roleRepository.Queryable(includeDeleted: true).ToListAsync(); return a; } //[AllowAnonymous] [HttpGet("hash")] public async Task Hash() { var s = _sessionContext; } /// /// signalR测试(method: Ring) /// /// [HttpGet("ring")] public async Task RingTest() { await _realtimeService.RingAsync(_sessionContext.RequiredUserId, new RingDto { Id = new Guid().ToString(), From = _sessionContext.Phone ?? "未知号码", To = "12345" }, HttpContext.RequestAborted); } /// /// signalR测试(method: Answered) /// /// [HttpGet("answered")] public async Task AnsweredTest() { await _realtimeService.AnsweredAsync(_sessionContext.RequiredUserId, new AnsweredDto() { Id = new Guid().ToString(), From = _sessionContext.Phone ?? "未知号码", To = "12345" }, HttpContext.RequestAborted); } /// /// signalR测试(method: Bye) /// /// [HttpGet("bye")] public async Task ByeTest() { await _realtimeService.ByeAsync(_sessionContext.RequiredUserId, new ByeDto() { Id = new Guid().ToString() }, HttpContext.RequestAborted); } /// /// /// /// [AllowAnonymous] [HttpGet("t2")] public async Task GetVoiceEndAnswerAsyncTest() { //var answer = await _ivrDomainService.GetVoiceEndAnswerAsync("3", HttpContext.RequestAborted); //Console.WriteLine(answer.Content); throw new UserFriendlyException(2001, "test"); } [AllowAnonymous] [HttpGet("wfdefine")] public async Task GetWorkflowDefine() { } [AllowAnonymous] [HttpPost("t3")] public Task TestDaprPubsub(int data) { _logger.LogDebug("receive dapr event, params: {0}", data); return Task.FromResult(data); } [HttpGet("rsa")] public async Task Rsa() { var keyList = RsaKeyGenerator.Pkcs1Key(2048, true); var privateKey = keyList[0]; var publicKey = keyList[1]; return $"{publicKey} \r\n {privateKey}"; } } public class Test { [SugarColumn(ColumnName = "CallID")] public string CallId { get; set; } [SugarColumn(ColumnName = "IVR")] public string Ivr { get; set; } }