Merge remote-tracking branch 'origin/ai-hub' into ai-hub

This commit is contained in:
Gsh
2025-08-30 22:29:21 +08:00
8 changed files with 68 additions and 8 deletions

View File

@@ -0,0 +1,11 @@
using Yi.Framework.Rbac.Domain.Shared.Dtos;
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
public class AiUserRoleMenuDto:UserRoleMenuDto
{
/// <summary>
/// 是否绑定服务号
/// </summary>
public bool IsBindFuwuhao { get; set; }
}

View File

@@ -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<AiUserExtraInfoEntity> _userRepository;
public AiAccountService(IAccountService accountService, ISqlSugarRepository<AiUserExtraInfoEntity> userRepository)
{
_accountService = accountService;
_userRepository = userRepository;
}
/// <summary>
/// 获取ai用户信息
/// </summary>
/// <returns></returns>
[Authorize]
[HttpGet("account/ai")]
public async Task<AiUserRoleMenuDto> GetAsync()
{
var userId = CurrentUser.GetId();
var userAccount = await _accountService.GetAsync(null, null, userId: CurrentUser.GetId());
var output = userAccount.Adapt<AiUserRoleMenuDto>();
output.IsBindFuwuhao = await _userRepository.IsAnyAsync(x => userId == x.UserId);
return output;
}
}

View File

@@ -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<QrCodeOutput> 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);

View File

@@ -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);

View File

@@ -24,8 +24,9 @@ namespace Yi.Framework.Rbac.Application.Contracts.IServices
/// </summary>
/// <param name="userName"></param>
/// <param name="phone"></param>
/// <param name="userId"></param>
/// <returns></returns>
Task<UserRoleMenuDto?> GetAsync(string? userName, long? phone);
Task<UserRoleMenuDto?> GetAsync(string? userName, long? phone,Guid? userId = null);
/// <summary>
/// 校验电话验证码,需要与电话号码绑定

View File

@@ -284,11 +284,12 @@ namespace Yi.Framework.Rbac.Application.Services
}
[RemoteService(isEnabled: false)]
public async Task<UserRoleMenuDto?> GetAsync(string? userName, long? phone)
public async Task<UserRoleMenuDto?> 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();

View File

@@ -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)
{

View File

@@ -106,7 +106,7 @@ namespace Yi.Abp.Web
//本地开发环境,可以禁用作业执行
if (host.IsDevelopment())
{
Configure<AbpBackgroundWorkerOptions>(options => { options.IsEnabled = true; });
Configure<AbpBackgroundWorkerOptions>(options => { options.IsEnabled = false; });
}
//请求日志