123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- using Dapr;
- using Hotline.CallCenter.BlackLists;
- using Hotline.CallCenter.Devices;
- using Hotline.CallCenter.Ivrs;
- using Hotline.FlowEngine.Definitions;
- using Hotline.Identity.Accounts;
- using Hotline.Realtimes;
- using Hotline.Repository.SqlSugar;
- using Hotline.Share.Dtos.Realtime;
- using Hotline.Users;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- using NewRock.Sdk;
- using NewRock.Sdk.Security;
- using SqlSugar;
- using XF.Domain.Authentications;
- using XF.Domain.Cache;
- using XF.Domain.Entities;
- using XF.Domain.Exceptions;
- namespace Hotline.Api.Controllers;
- /// <summary>
- ///
- /// </summary>
- public class TestController : BaseController
- {
- private readonly ILogger<TestController> _logger;
- private readonly IAuthorizeGenerator _authorizeGenerator;
- private readonly IOptionsSnapshot<DeviceConfigs> _options;
- private readonly ISessionContext _sessionContext;
- private readonly IUserRepository _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 IAccountDomainService _accountDomainService;
- //private readonly ITypedCache<List<User>> _cache;
- //private readonly ICacheManager<User> _cache;
- /// <summary>
- ///
- /// </summary>
- /// <param name="client"></param>
- /// <param name="logger"></param>
- /// <param name="authorizeGenerator"></param>
- /// <param name="options"></param>
- /// <param name="sessionContext"></param>
- /// <param name="userRepository"></param>
- /// <param name="cache"></param>
- /// <param name="realtimeService"></param>
- /// <param name="blacklistDomainService"></param>
- /// <param name="ivrDomainService"></param>
- public TestController(
- INewRockClient client,
- ILogger<TestController> logger,
- IAuthorizeGenerator authorizeGenerator,
- IOptionsSnapshot<DeviceConfigs> options,
- ISessionContext sessionContext,
- IUserRepository userRepository,
- //ICacheManager<User> cache
- //ITypedCache<List<User>> cache
- ITypedCache<User> cache,
- IRealtimeService realtimeService,
- IBlacklistDomainService blacklistDomainService,
- IIvrDomainService ivrDomainService,
- ISugarUnitOfWork<HotlineDbContext> uow,
- IAccountDomainService accountDomainService
- )
- {
- _logger = logger;
- _authorizeGenerator = authorizeGenerator;
- _options = options;
- _sessionContext = sessionContext;
- _userRepository = userRepository;
- _cache = cache;
- _realtimeService = realtimeService;
- _blacklistDomainService = blacklistDomainService;
- _ivrDomainService = ivrDomainService;
- _uow = uow;
- _accountDomainService = accountDomainService;
- }
- //[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<IReadOnlyList<Definition>> GetWorkflowDefine()
- {
- throw new NotImplementedException();
- }
- [ApiExplorerSettings(IgnoreApi = true)]
- [AllowAnonymous]
- [HttpGet("cdb")]
- public Task CreateTableMultiple()
- {
- var db = _uow.Db;
- db.DbMaintenance.CreateDatabase();
- var types = typeof(User).Assembly.GetTypes()
- .Where(d => d.GetInterfaces().Any(x => x == typeof(IEntity)))
- .Distinct()
- .ToArray();
- db.CodeFirst.InitTables(types);//根据types创建表
- return Task.CompletedTask;
- }
- [AllowAnonymous]
- [Topic("pubsub", "test")]
- [HttpPost("t3")]
- public Task<int> TestDaprPubsub(int data)
- {
- _logger.LogDebug("receive dapr event, params: {0}", data);
- return Task.FromResult(data);
- }
- }
|