TestController.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using Dapr;
  2. using Hotline.CallCenter.BlackLists;
  3. using Hotline.CallCenter.Devices;
  4. using Hotline.CallCenter.Ivrs;
  5. using Hotline.FlowEngine.Definitions;
  6. using Hotline.Identity.Accounts;
  7. using Hotline.Realtimes;
  8. using Hotline.Repository.SqlSugar;
  9. using Hotline.Share.Dtos.Realtime;
  10. using Hotline.Users;
  11. using Microsoft.AspNetCore.Authorization;
  12. using Microsoft.AspNetCore.Mvc;
  13. using Microsoft.Extensions.Options;
  14. using NewRock.Sdk;
  15. using NewRock.Sdk.Security;
  16. using SqlSugar;
  17. using XF.Domain.Authentications;
  18. using XF.Domain.Cache;
  19. using XF.Domain.Entities;
  20. using XF.Domain.Exceptions;
  21. namespace Hotline.Api.Controllers;
  22. /// <summary>
  23. ///
  24. /// </summary>
  25. public class TestController : BaseController
  26. {
  27. private readonly ILogger<TestController> _logger;
  28. private readonly IAuthorizeGenerator _authorizeGenerator;
  29. private readonly IOptionsSnapshot<DeviceConfigs> _options;
  30. private readonly ISessionContext _sessionContext;
  31. private readonly IUserRepository _userRepository;
  32. private readonly ITypedCache<User> _cache;
  33. private readonly IRealtimeService _realtimeService;
  34. private readonly IBlacklistDomainService _blacklistDomainService;
  35. private readonly IIvrDomainService _ivrDomainService;
  36. private readonly ISugarUnitOfWork<HotlineDbContext> _uow;
  37. private readonly IAccountDomainService _accountDomainService;
  38. //private readonly ITypedCache<List<User>> _cache;
  39. //private readonly ICacheManager<User> _cache;
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. /// <param name="client"></param>
  44. /// <param name="logger"></param>
  45. /// <param name="authorizeGenerator"></param>
  46. /// <param name="options"></param>
  47. /// <param name="sessionContext"></param>
  48. /// <param name="userRepository"></param>
  49. /// <param name="cache"></param>
  50. /// <param name="realtimeService"></param>
  51. /// <param name="blacklistDomainService"></param>
  52. /// <param name="ivrDomainService"></param>
  53. public TestController(
  54. INewRockClient client,
  55. ILogger<TestController> logger,
  56. IAuthorizeGenerator authorizeGenerator,
  57. IOptionsSnapshot<DeviceConfigs> options,
  58. ISessionContext sessionContext,
  59. IUserRepository userRepository,
  60. //ICacheManager<User> cache
  61. //ITypedCache<List<User>> cache
  62. ITypedCache<User> cache,
  63. IRealtimeService realtimeService,
  64. IBlacklistDomainService blacklistDomainService,
  65. IIvrDomainService ivrDomainService,
  66. ISugarUnitOfWork<HotlineDbContext> uow,
  67. IAccountDomainService accountDomainService
  68. )
  69. {
  70. _logger = logger;
  71. _authorizeGenerator = authorizeGenerator;
  72. _options = options;
  73. _sessionContext = sessionContext;
  74. _userRepository = userRepository;
  75. _cache = cache;
  76. _realtimeService = realtimeService;
  77. _blacklistDomainService = blacklistDomainService;
  78. _ivrDomainService = ivrDomainService;
  79. _uow = uow;
  80. _accountDomainService = accountDomainService;
  81. }
  82. //[AllowAnonymous]
  83. [HttpGet("hash")]
  84. public async Task Hash()
  85. {
  86. var s = _sessionContext;
  87. }
  88. /// <summary>
  89. /// signalR测试(method: Ring)
  90. /// </summary>
  91. /// <returns></returns>
  92. [HttpGet("ring")]
  93. public async Task RingTest()
  94. {
  95. await _realtimeService.RingAsync(_sessionContext.RequiredUserId, new RingDto { Id = new Guid().ToString(), From = _sessionContext.Phone ?? "未知号码", To = "12345" }, HttpContext.RequestAborted);
  96. }
  97. /// <summary>
  98. /// signalR测试(method: Answered)
  99. /// </summary>
  100. /// <returns></returns>
  101. [HttpGet("answered")]
  102. public async Task AnsweredTest()
  103. {
  104. await _realtimeService.AnsweredAsync(_sessionContext.RequiredUserId, new AnsweredDto() { Id = new Guid().ToString(), From = _sessionContext.Phone ?? "未知号码", To = "12345" }, HttpContext.RequestAborted);
  105. }
  106. /// <summary>
  107. /// signalR测试(method: Bye)
  108. /// </summary>
  109. /// <returns></returns>
  110. [HttpGet("bye")]
  111. public async Task ByeTest()
  112. {
  113. await _realtimeService.ByeAsync(_sessionContext.RequiredUserId, new ByeDto() { Id = new Guid().ToString() }, HttpContext.RequestAborted);
  114. }
  115. /// <summary>
  116. ///
  117. /// </summary>
  118. /// <returns></returns>
  119. [AllowAnonymous]
  120. [HttpGet("t2")]
  121. public async Task GetVoiceEndAnswerAsyncTest()
  122. {
  123. //var answer = await _ivrDomainService.GetVoiceEndAnswerAsync("3", HttpContext.RequestAborted);
  124. //Console.WriteLine(answer.Content);
  125. throw new UserFriendlyException(2001, "test");
  126. }
  127. [AllowAnonymous]
  128. [HttpGet("wfdefine")]
  129. public async Task<IReadOnlyList<Definition>> GetWorkflowDefine()
  130. {
  131. throw new NotImplementedException();
  132. }
  133. [ApiExplorerSettings(IgnoreApi = true)]
  134. [AllowAnonymous]
  135. [HttpGet("cdb")]
  136. public Task CreateTableMultiple()
  137. {
  138. var db = _uow.Db;
  139. db.DbMaintenance.CreateDatabase();
  140. var types = typeof(User).Assembly.GetTypes()
  141. .Where(d => d.GetInterfaces().Any(x => x == typeof(IEntity)))
  142. .Distinct()
  143. .ToArray();
  144. db.CodeFirst.InitTables(types);//根据types创建表
  145. return Task.CompletedTask;
  146. }
  147. [AllowAnonymous]
  148. [Topic("pubsub", "test")]
  149. [HttpPost("t3")]
  150. public Task<int> TestDaprPubsub(int data)
  151. {
  152. _logger.LogDebug("receive dapr event, params: {0}", data);
  153. return Task.FromResult(data);
  154. }
  155. }