diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/AiUserRoleMenuDto.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/AiUserRoleMenuDto.cs new file mode 100644 index 00000000..d3297f59 --- /dev/null +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/AiUserRoleMenuDto.cs @@ -0,0 +1,11 @@ +using Yi.Framework.Rbac.Domain.Shared.Dtos; + +namespace Yi.Framework.AiHub.Application.Contracts.Dtos; + +public class AiUserRoleMenuDto:UserRoleMenuDto +{ + /// + /// 是否绑定服务号 + /// + public bool IsBindFuwuhao { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AiAccountService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AiAccountService.cs new file mode 100644 index 00000000..e5290f0d --- /dev/null +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AiAccountService.cs @@ -0,0 +1,39 @@ +using Mapster; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Application.Services; +using Volo.Abp.Users; +using Yi.Framework.AiHub.Application.Contracts.Dtos; +using Yi.Framework.AiHub.Domain.Entities; +using Yi.Framework.Rbac.Application.Contracts.IServices; +using Yi.Framework.Rbac.Domain.Shared.Dtos; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace Yi.Framework.AiHub.Application.Services; + +public class AiAccountService : ApplicationService +{ + private IAccountService _accountService; + private ISqlSugarRepository _userRepository; + + public AiAccountService(IAccountService accountService, ISqlSugarRepository userRepository) + { + _accountService = accountService; + _userRepository = userRepository; + } + + /// + /// 获取ai用户信息 + /// + /// + [Authorize] + [HttpGet("account/ai")] + public async Task GetAsync() + { + var userId = CurrentUser.GetId(); + var userAccount = await _accountService.GetAsync(null, null, userId: CurrentUser.GetId()); + var output = userAccount.Adapt(); + output.IsBindFuwuhao = await _userRepository.IsAnyAsync(x => userId == x.UserId); + return output; + } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FuwuhaoService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FuwuhaoService.cs index f47eb872..160f3fab 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FuwuhaoService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/FuwuhaoService.cs @@ -95,8 +95,7 @@ public class FuwuhaoService : ApplicationService //制作幂等 await using (var handle = - await DistributedLock.TryAcquireLockAsync($"Yi:fuwuhao:callbacklock:{scene}", - TimeSpan.FromSeconds(60))) + await DistributedLock.TryAcquireLockAsync($"Yi:fuwuhao:callbacklock:{scene}")) { if (handle == null) { @@ -109,6 +108,11 @@ public class FuwuhaoService : ApplicationService return "success"; // 跳过直接返回成功 } + if (cache.SceneResult != SceneResultEnum.Wait) + { + return "success"; // 跳过直接返回成功 + } + //根据操作类型,进行业务处理,返回处理结果,再写入缓存,10s过去,相当于用户10s扫完app后,轮询要在10秒内完成 var scenResult = await _fuwuhaoManager.CallBackHandlerAsync(cache.SceneType, body.FromUserName, cache.UserId); @@ -140,6 +144,11 @@ public class FuwuhaoService : ApplicationService [HttpPost("fuwuhao/qrcode")] public async Task GetQrCodeAsync([FromQuery] SceneTypeEnum sceneType) { + if (sceneType == SceneTypeEnum.Bind && CurrentUser.Id is null) + { + throw new UserFriendlyException("绑定微信,需登录用户,请重新登录后重试"); + } + //生成一个随机场景值 var scene = Guid.NewGuid().ToString("N"); var qrCodeUrl = await _fuwuhaoManager.CreateQrCodeAsync(scene); diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/Fuwuhao/FuwuhaoManager.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/Fuwuhao/FuwuhaoManager.cs index b08e2a2b..e733a6ba 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/Fuwuhao/FuwuhaoManager.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/Fuwuhao/FuwuhaoManager.cs @@ -240,7 +240,7 @@ public class FuwuhaoManager : DomainService //说明没有绑定过,直接绑定 await _userRepository.InsertAsync(new AiUserExtraInfoEntity(bindUserId.Value, openId)); - return (SceneResultEnum.Bind,null); + return (SceneResultEnum.Bind,bindUserId); break; default: throw new ArgumentOutOfRangeException(nameof(sceneType), sceneType, null); diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IAccountService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IAccountService.cs index 1dd7c6e6..d0c21f00 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IAccountService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IAccountService.cs @@ -24,8 +24,9 @@ namespace Yi.Framework.Rbac.Application.Contracts.IServices /// /// /// + /// /// - Task GetAsync(string? userName, long? phone); + Task GetAsync(string? userName, long? phone,Guid? userId = null); /// /// 校验电话验证码,需要与电话号码绑定 diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs index b898feda..5f9c6654 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs @@ -284,11 +284,12 @@ namespace Yi.Framework.Rbac.Application.Services } [RemoteService(isEnabled: false)] - public async Task GetAsync(string? userName, long? phone) + public async Task GetAsync(string? userName, long? phone = null, Guid? userId = null) { var user = await _userRepository._DbQueryable .WhereIF(userName is not null, x => x.UserName == userName) .WhereIF(phone is not null, x => x.Phone == phone) + .WhereIF(userId is not null, x => x.Id == userId) .Where(x => x.State == true) .FirstAsync(); diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs index 2185bcc9..a4f226e4 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Managers/AccountManager.cs @@ -308,8 +308,7 @@ namespace Yi.Framework.Rbac.Domain.Managers //制作幂等 await using (var handle = - await DistributedLock.TryAcquireLockAsync($"{CacheKeyPrefix}Register:Lock:{userName}", - TimeSpan.FromSeconds(60))) + await DistributedLock.TryAcquireLockAsync($"{CacheKeyPrefix}Register:Lock:{userName}")) { if (handle is null) { diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs index 4c55ef9c..9e08520e 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs @@ -106,7 +106,7 @@ namespace Yi.Abp.Web //本地开发环境,可以禁用作业执行 if (host.IsDevelopment()) { - Configure(options => { options.IsEnabled = true; }); + Configure(options => { options.IsEnabled = false; }); } //请求日志