sozsoft-platform/api/src/Sozsoft.Platform.Application/AiBots/AiBotAppService.cs

77 lines
2.4 KiB
C#
Raw Normal View History

2026-02-24 20:44:16 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
2026-02-24 20:44:16 +00:00
using Microsoft.AspNetCore.Authorization;
using Sozsoft.Platform.Entities;
2026-02-24 20:44:16 +00:00
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace Sozsoft.Platform.AiBots;
[Authorize]
public class AiBotAppService : CrudAppService<
AiBot,
AiBotDto,
Guid,
PagedAndSortedResultRequestDto>
{
public AiBotAppService(IRepository<AiBot, Guid> repo) : base(repo)
{
}
2026-06-23 17:30:19 +00:00
public override async Task<PagedResultDto<AiBotDto>> GetListAsync(PagedAndSortedResultRequestDto input)
{
await CheckGetListPolicyAsync();
if (CurrentTenant.IsAvailable && !string.IsNullOrWhiteSpace(CurrentTenant.Name))
{
var tenantName = CurrentTenant.Name;
List<AiBot> tenantEntities;
using (CurrentTenant.Change(null))
{
var hostQuery = await CreateFilteredQueryAsync(input);
tenantEntities = await AsyncExecuter.ToListAsync(hostQuery);
}
var filteredQuery = tenantEntities
.Where(aiBot => IsAvailableForTenant(aiBot.Tenants, tenantName))
.AsQueryable();
var tenantTotalCount = filteredQuery.LongCount();
filteredQuery = ApplySorting(filteredQuery, input);
filteredQuery = ApplyPaging(filteredQuery, input);
var tenantDtos = await MapToGetListOutputDtosAsync(filteredQuery.ToList());
return new PagedResultDto<AiBotDto>(tenantTotalCount, tenantDtos);
2026-06-23 17:30:19 +00:00
}
var query = await CreateFilteredQueryAsync(input);
2026-06-23 17:30:19 +00:00
var totalCount = await AsyncExecuter.CountAsync(query);
query = ApplySorting(query, input);
query = ApplyPaging(query, input);
var entities = await AsyncExecuter.ToListAsync(query);
var dtos = await MapToGetListOutputDtosAsync(entities);
return new PagedResultDto<AiBotDto>(totalCount, dtos);
}
private static bool IsAvailableForTenant(string tenants, string tenantName)
{
if (string.IsNullOrWhiteSpace(tenants))
{
return true;
}
return tenants
.Split('|', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Any(name => string.Equals(name, tenantName, StringComparison.OrdinalIgnoreCase));
}
2026-02-24 20:44:16 +00:00
}