refactor: 移除AiHub Domain层对Application.Contracts的循环依赖
移除Yi.Framework.AiHub.Domain项目中对Yi.Framework.AiHub.Application.Contracts的项目引用,解决领域层和应用层之间的循环依赖问题,符合DDD架构分层原则。
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||||
|
|
||||||
|
public interface IRechargeService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 移除用户vip及角色
|
||||||
|
/// </summary>
|
||||||
|
Task RemoveVipRoleByExpireAsync();
|
||||||
|
}
|
||||||
@@ -6,8 +6,5 @@
|
|||||||
<ProjectReference Include="..\..\rbac\Yi.Framework.Rbac.Application.Contracts\Yi.Framework.Rbac.Application.Contracts.csproj" />
|
<ProjectReference Include="..\..\rbac\Yi.Framework.Rbac.Application.Contracts\Yi.Framework.Rbac.Application.Contracts.csproj" />
|
||||||
<ProjectReference Include="..\Yi.Framework.AiHub.Domain.Shared\Yi.Framework.AiHub.Domain.Shared.csproj" />
|
<ProjectReference Include="..\Yi.Framework.AiHub.Domain.Shared\Yi.Framework.AiHub.Domain.Shared.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="IServices\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -4,27 +4,33 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Volo.Abp.Application.Services;
|
using Volo.Abp.Application.Services;
|
||||||
using Volo.Abp.Users;
|
using Volo.Abp.Users;
|
||||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.Recharge;
|
using Yi.Framework.AiHub.Application.Contracts.Dtos.Recharge;
|
||||||
|
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||||
using Yi.Framework.AiHub.Domain.Entities;
|
using Yi.Framework.AiHub.Domain.Entities;
|
||||||
|
using Yi.Framework.AiHub.Domain.Managers;
|
||||||
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
||||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
namespace Yi.Framework.AiHub.Application.Services
|
namespace Yi.Framework.AiHub.Application.Services
|
||||||
{
|
{
|
||||||
public class RechargeService : ApplicationService
|
public class RechargeService : ApplicationService,IRechargeService
|
||||||
{
|
{
|
||||||
private readonly ISqlSugarRepository<AiRechargeAggregateRoot> _repository;
|
private readonly ISqlSugarRepository<AiRechargeAggregateRoot> _repository;
|
||||||
private readonly ICurrentUser _currentUser;
|
private readonly ICurrentUser _currentUser;
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
|
private readonly IRoleService _roleService;
|
||||||
|
private readonly AiRechargeManager _aiMessageManager;
|
||||||
|
|
||||||
public RechargeService(
|
public RechargeService(
|
||||||
ISqlSugarRepository<AiRechargeAggregateRoot> repository,
|
ISqlSugarRepository<AiRechargeAggregateRoot> repository,
|
||||||
ICurrentUser currentUser,
|
ICurrentUser currentUser,
|
||||||
IUserService userService)
|
IUserService userService, IRoleService roleService, AiRechargeManager aiMessageManager)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
_currentUser = currentUser;
|
_currentUser = currentUser;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
|
_roleService = roleService;
|
||||||
|
_aiMessageManager = aiMessageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -69,5 +75,18 @@ namespace Yi.Framework.AiHub.Application.Services
|
|||||||
await _userService.AddUserRoleByRoleCodeAsync(input.UserId,
|
await _userService.AddUserRoleByRoleCodeAsync(input.UserId,
|
||||||
new List<string>() { AiHubConst.VipRole, "default" });
|
new List<string>() { AiHubConst.VipRole, "default" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 移除用户vip及角色
|
||||||
|
/// </summary>
|
||||||
|
[RemoteService(isEnabled: false)]
|
||||||
|
public async Task RemoveVipRoleByExpireAsync()
|
||||||
|
{
|
||||||
|
var expiredUserIds = await _aiMessageManager.RemoveVipByExpireAsync();
|
||||||
|
if (expiredUserIds is not null)
|
||||||
|
{
|
||||||
|
await _roleService.RemoveUserRoleByRoleCodeAsync(expiredUserIds, AiHubConst.VipRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
using SqlSugar;
|
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
||||||
using Yi.Framework.AiHub.Domain.Shared.Dtos;
|
|
||||||
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
|
||||||
|
|
||||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos;
|
namespace Yi.Framework.AiHub.Domain.Shared.Dtos;
|
||||||
|
|
||||||
public class MessageInputDto
|
public class MessageInputDto
|
||||||
{
|
{
|
||||||
@@ -9,7 +9,6 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
using Volo.Abp.Domain.Services;
|
using Volo.Abp.Domain.Services;
|
||||||
using Yi.Framework.AiHub.Application.Contracts.Dtos;
|
|
||||||
using Yi.Framework.AiHub.Domain.AiGateWay;
|
using Yi.Framework.AiHub.Domain.AiGateWay;
|
||||||
using Yi.Framework.AiHub.Domain.AiGateWay.Exceptions;
|
using Yi.Framework.AiHub.Domain.AiGateWay.Exceptions;
|
||||||
using Yi.Framework.AiHub.Domain.Entities.Model;
|
using Yi.Framework.AiHub.Domain.Entities.Model;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Volo.Abp.Domain.Services;
|
using Volo.Abp.Domain.Services;
|
||||||
using Volo.Abp.Users;
|
using Volo.Abp.Users;
|
||||||
using Yi.Framework.AiHub.Application.Contracts.Dtos;
|
|
||||||
using Yi.Framework.AiHub.Domain.Entities;
|
using Yi.Framework.AiHub.Domain.Entities;
|
||||||
using Yi.Framework.AiHub.Domain.Entities.Chat;
|
using Yi.Framework.AiHub.Domain.Entities.Chat;
|
||||||
|
using Yi.Framework.AiHub.Domain.Shared.Dtos;
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
namespace Yi.Framework.AiHub.Domain.Managers;
|
namespace Yi.Framework.AiHub.Domain.Managers;
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
using Volo.Abp.Domain.Services;
|
using Volo.Abp.Domain.Services;
|
||||||
using Yi.Framework.AiHub.Domain.Entities;
|
using Yi.Framework.AiHub.Domain.Entities;
|
||||||
using Yi.Framework.AiHub.Domain.Entities.OpenApi;
|
using Yi.Framework.AiHub.Domain.Entities.OpenApi;
|
||||||
using Yi.Framework.AiHub.Domain.Shared.Consts;
|
|
||||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
namespace Yi.Framework.AiHub.Domain.Managers;
|
namespace Yi.Framework.AiHub.Domain.Managers;
|
||||||
@@ -11,21 +9,18 @@ namespace Yi.Framework.AiHub.Domain.Managers;
|
|||||||
public class AiRechargeManager : DomainService
|
public class AiRechargeManager : DomainService
|
||||||
{
|
{
|
||||||
private readonly ISqlSugarRepository<AiRechargeAggregateRoot> _rechargeRepository;
|
private readonly ISqlSugarRepository<AiRechargeAggregateRoot> _rechargeRepository;
|
||||||
private readonly IRoleService _roleService;
|
|
||||||
private readonly ISqlSugarRepository<TokenAggregateRoot> _tokenRepository;
|
private readonly ISqlSugarRepository<TokenAggregateRoot> _tokenRepository;
|
||||||
private readonly ILogger<AiRechargeManager> _logger;
|
private readonly ILogger<AiRechargeManager> _logger;
|
||||||
|
|
||||||
public AiRechargeManager(ISqlSugarRepository<AiRechargeAggregateRoot> rechargeRepository,
|
public AiRechargeManager(ISqlSugarRepository<AiRechargeAggregateRoot> rechargeRepository,
|
||||||
ISqlSugarRepository<TokenAggregateRoot> tokenRepository, ILogger<AiRechargeManager> logger,
|
ISqlSugarRepository<TokenAggregateRoot> tokenRepository, ILogger<AiRechargeManager> logger)
|
||||||
IRoleService roleService)
|
|
||||||
{
|
{
|
||||||
_rechargeRepository = rechargeRepository;
|
_rechargeRepository = rechargeRepository;
|
||||||
_tokenRepository = tokenRepository;
|
_tokenRepository = tokenRepository;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_roleService = roleService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemoveVipRoleByExpireAsync()
|
public async Task<List<Guid>?> RemoveVipByExpireAsync()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("开始执行VIP过期自动卸载任务");
|
_logger.LogInformation("开始执行VIP过期自动卸载任务");
|
||||||
|
|
||||||
@@ -39,7 +34,7 @@ public class AiRechargeManager : DomainService
|
|||||||
if (!allRecharges.Any())
|
if (!allRecharges.Any())
|
||||||
{
|
{
|
||||||
_logger.LogInformation("没有找到任何充值记录");
|
_logger.LogInformation("没有找到任何充值记录");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按用户分组,找出真正过期的用户
|
// 按用户分组,找出真正过期的用户
|
||||||
@@ -63,18 +58,18 @@ public class AiRechargeManager : DomainService
|
|||||||
if (!expiredUserIds.Any())
|
if (!expiredUserIds.Any())
|
||||||
{
|
{
|
||||||
_logger.LogInformation("没有找到过期的VIP用户");
|
_logger.LogInformation("没有找到过期的VIP用户");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation($"找到 {expiredUserIds.Count} 个过期的VIP用户");
|
_logger.LogInformation($"找到 {expiredUserIds.Count} 个过期的VIP用户");
|
||||||
|
|
||||||
// 获取YiXinAi-Vip角色ID
|
|
||||||
await _roleService.RemoveUserRoleByRoleCodeAsync(expiredUserIds, AiHubConst.VipRole);
|
|
||||||
|
|
||||||
// 删除过期用户的Token密钥
|
// 删除过期用户的Token密钥
|
||||||
var removedTokenCount = await _tokenRepository.DeleteAsync(x => expiredUserIds.Contains(x.UserId));
|
var removedTokenCount = await _tokenRepository.DeleteAsync(x => expiredUserIds.Contains(x.UserId));
|
||||||
|
|
||||||
_logger.LogInformation($"成功删除 {removedTokenCount} 个用户的Token密钥");
|
_logger.LogInformation($"成功删除 {removedTokenCount} 个用户的Token密钥");
|
||||||
_logger.LogInformation($"VIP过期自动卸载任务执行完成,共处理 {expiredUserIds.Count} 个过期用户");
|
_logger.LogInformation($"VIP过期自动卸载任务执行完成,共处理 {expiredUserIds.Count} 个过期用户");
|
||||||
|
|
||||||
|
return expiredUserIds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" />
|
<ProjectReference Include="..\..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" />
|
||||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.SqlSugarCore.Abstractions\Yi.Framework.SqlSugarCore.Abstractions.csproj" />
|
<ProjectReference Include="..\..\..\framework\Yi.Framework.SqlSugarCore.Abstractions\Yi.Framework.SqlSugarCore.Abstractions.csproj" />
|
||||||
<ProjectReference Include="..\Yi.Framework.AiHub.Application.Contracts\Yi.Framework.AiHub.Application.Contracts.csproj" />
|
|
||||||
<ProjectReference Include="..\Yi.Framework.AiHub.Domain.Shared\Yi.Framework.AiHub.Domain.Shared.csproj" />
|
<ProjectReference Include="..\Yi.Framework.AiHub.Domain.Shared\Yi.Framework.AiHub.Domain.Shared.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Volo.Abp.BackgroundWorkers.Hangfire;
|
using Volo.Abp.BackgroundWorkers.Hangfire;
|
||||||
|
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||||
using Yi.Framework.AiHub.Domain.Entities;
|
using Yi.Framework.AiHub.Domain.Entities;
|
||||||
using Yi.Framework.AiHub.Domain.Entities.OpenApi;
|
using Yi.Framework.AiHub.Domain.Entities.OpenApi;
|
||||||
using Yi.Framework.AiHub.Domain.Managers;
|
using Yi.Framework.AiHub.Domain.Managers;
|
||||||
@@ -14,11 +15,11 @@ namespace Yi.Abp.Web.Jobs.ai_hub;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class VipExpireJob : HangfireBackgroundWorkerBase
|
public class VipExpireJob : HangfireBackgroundWorkerBase
|
||||||
{
|
{
|
||||||
private readonly AiRechargeManager _aiRechargeManager;
|
private readonly IRechargeService _rechargeService;
|
||||||
|
|
||||||
public VipExpireJob(AiRechargeManager aiRechargeManager)
|
public VipExpireJob(IRechargeService rechargeService)
|
||||||
{
|
{
|
||||||
_aiRechargeManager = aiRechargeManager;
|
_rechargeService = rechargeService;
|
||||||
RecurringJobId = "VIP过期自动卸载";
|
RecurringJobId = "VIP过期自动卸载";
|
||||||
// 每天凌晨0点执行一次
|
// 每天凌晨0点执行一次
|
||||||
CronExpression = "0 0 0 * * ?";
|
CronExpression = "0 0 0 * * ?";
|
||||||
@@ -26,6 +27,6 @@ public class VipExpireJob : HangfireBackgroundWorkerBase
|
|||||||
|
|
||||||
public override async Task DoWorkAsync(CancellationToken cancellationToken = new CancellationToken())
|
public override async Task DoWorkAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||||
{
|
{
|
||||||
await _aiRechargeManager.RemoveVipRoleByExpireAsync();
|
await _rechargeService.RemoveVipRoleByExpireAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user