123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- using Hotline.Application.TimeLimits;
- using Hotline.CallCenter.BlackLists;
- using Hotline.CallCenter.Devices;
- using Hotline.CallCenter.Ivrs;
- 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.Share.Dtos.Settings;
- using Hotline.Share.Enums.Settings;
- using Hotline.Users;
- using MediatR;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.SignalR;
- using Microsoft.Extensions.Options;
- using NewRock.Sdk;
- using NewRock.Sdk.Security;
- using NpgsqlTypes;
- using SqlSugar;
- using Wex.Sdk;
- using Wex.Sdk.Tel;
- 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;
- /// <summary>
- ///
- /// </summary>
- [AllowAnonymous]
- public class TestController : BaseController
- {
- private readonly ILogger<TestController> _logger;
- private readonly IAuthorizeGenerator _authorizeGenerator;
- private readonly IOptionsSnapshot<CallCenterConfiguration> _options;
- private readonly ISessionContext _sessionContext;
- private readonly IRepository<User> _userRepository;
- private readonly ITypedCache<User> _cache;
- private readonly IRealtimeService _realtimeService;
- private readonly IBlacklistDomainService _blacklistDomainService;
- private readonly IIvrDomainService _ivrDomainService;
- private readonly ISugarUnitOfWork<HotlineDbContext> _uow;
- private readonly IRepository<Role> _roleRepository;
- private readonly IMediator _mediator;
- private readonly ITimeLimitApplication _timeLimitApplication;
- private readonly IDistributedLock _distributedLock;
- private readonly IWexClient _wexClient;
- private readonly ISugarUnitOfWork<WexDbContext> _uowWex;
- private readonly IRepository<OrderUrge> _orderUrgeRepository;
- private readonly IRepositoryTextSearch<OrderTs> _repositoryts;
- private readonly IGroupManager _goupManager;
- private readonly ITimeLimitDomainService _timeLimitDomainService;
- //private readonly ITypedCache<List<User>> _cache;
- //private readonly ICacheManager<User> _cache;
- public TestController(
- INewRockClient client,
- ILogger<TestController> logger,
- IAuthorizeGenerator authorizeGenerator,
- IOptionsSnapshot<CallCenterConfiguration> options,
- ISessionContext sessionContext,
- IRepository<User> userRepository,
- //ICacheManager<User> cache
- //ITypedCache<List<User>> cache
- ITypedCache<User> cache,
- IRealtimeService realtimeService,
- IBlacklistDomainService blacklistDomainService,
- IIvrDomainService ivrDomainService,
- ISugarUnitOfWork<HotlineDbContext> uow,
- IRepository<Role> roleRepository,
- IMediator mediator,
- ITimeLimitApplication timeLimitApplication,
- IDistributedLock distributedLock,
- IWexClient wexClient,
- ISugarUnitOfWork<WexDbContext> uowWex,
- IRepository<OrderUrge> orderUrgeRepository,
- IRepositoryTextSearch<OrderTs> repositoryts,
- ITimeLimitDomainService timeLimitDomainService)
- {
- _logger = logger;
- _authorizeGenerator = authorizeGenerator;
- _options = options;
- _sessionContext = sessionContext;
- _userRepository = userRepository;
- _cache = cache;
- _realtimeService = realtimeService;
- _blacklistDomainService = blacklistDomainService;
- _ivrDomainService = ivrDomainService;
- _uow = uow;
- _roleRepository = roleRepository;
- _mediator = mediator;
- _timeLimitApplication = timeLimitApplication;
- _distributedLock = distributedLock;
- _wexClient = wexClient;
- _uowWex = uowWex;
- _orderUrgeRepository = orderUrgeRepository;
- _repositoryts = repositoryts;
- _timeLimitDomainService = timeLimitDomainService;
- }
- [HttpGet("time")]
- public async Task<OpenResponse> GetTime()
- {
- //await _repositoryts.AddVectorAsync("f595e730-909a-45e4-9138-a84bf15f4662", DateTime.Now,
- // new List<string> { "xx", "bb" }, HttpContext.RequestAborted);
- //var result = await _repositoryts.SearchAsync(new List<string> { "bb" }, HttpContext.RequestAborted);
- //await _repositoryts.UpdateVectorAsync("f595e730-909a-45e4-9138-a84bf15f4662",
- // new List<string> { "ss", "bb" }, HttpContext.RequestAborted);
- //_uow.Db.Ado.SqlQueryAsync<OrderUrge>("SELECT to_tsvector('fat cats ate fat rats') @@ to_tsquery('fat & rat')")
- //var tests = _uowWex.Db.Ado.SqlQuery<Test>("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 10:00:00"), true);
- return OpenResponse.Ok(DateTime.Now.ToString("F"));
- //var rsp = await _daprClient.InvokeMethodAsync<ApiResponse<string>>(HttpMethod.Get, "identity", "api/v1/Test/time", HttpContext.RequestAborted);
- //var rsp1 = await _daprClient.InvokeMethodAsync<int, ApiResponse<string>>(HttpMethod.Post, "identity", "api/v1/Test/time1", 222, HttpContext.RequestAborted);
- }
- [HttpGet("pgsql")]
- public async Task<string> 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<List<Role>> 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<Role>().ToListAsync();
- var b = await _roleRepository.Queryable(includeDeleted: true).ToListAsync();
- return a;
- }
- [AllowAnonymous]
- [HttpGet("testtime")]
- public async Task<TimeResult> TestTime(DateTime beginTime, ETimeType timeType, int timeValue)
- {
- return _timeLimitApplication.CalcEndTime(beginTime, timeType, timeValue);
- }
- [AllowAnonymous]
- [HttpGet("timeend")]
- public async Task<DateTime> GetWorkDayEnd(DateTime date, int days)
- {
- return _timeLimitApplication.GetEndDateWork(date, days);
- }
- //[AllowAnonymous]
- [HttpGet("hash")]
- public async Task Hash()
- {
- var s = _sessionContext;
- }
- /// <summary>
- /// signalR测试(method: Ring)
- /// </summary>
- /// <returns></returns>
- [HttpGet("ring")]
- public async Task RingTest()
- {
- await _realtimeService.RingAsync(_sessionContext.RequiredUserId, new RingDto { Id = new Guid().ToString(), From = _sessionContext.Phone ?? "未知号码", To = "12345" }, HttpContext.RequestAborted);
- }
- /// <summary>
- /// signalR测试(method: Answered)
- /// </summary>
- /// <returns></returns>
- [HttpGet("answered")]
- public async Task AnsweredTest()
- {
- await _realtimeService.AnsweredAsync(_sessionContext.RequiredUserId, new AnsweredDto() { Id = new Guid().ToString(), From = _sessionContext.Phone ?? "未知号码", To = "12345" }, HttpContext.RequestAborted);
- }
- /// <summary>
- /// signalR测试(method: Bye)
- /// </summary>
- /// <returns></returns>
- [HttpGet("bye")]
- public async Task ByeTest()
- {
- await _realtimeService.ByeAsync(_sessionContext.RequiredUserId, new ByeDto() { Id = new Guid().ToString() }, HttpContext.RequestAborted);
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- [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<int> TestDaprPubsub(int data)
- {
- _logger.LogDebug("receive dapr event, params: {0}", data);
- return Task.FromResult(data);
- }
- [HttpGet("rsa")]
- public async Task<string> 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; }
- }
|